PhoenixClock  2.2.0
Library wrapping the usage of system's clock, allowing to use clock mock-ups
Loading...
Searching...
No Matches
PClockMockFile.cpp
Go to the documentation of this file.
1/***************************************
2 Auteur : Pierre Aubert
3 Mail : pierre.aubert@lapp.in2p3.fr
4 Licence : CeCILL-C
5****************************************/
6
7
8#include "PClockMockFile.h"
9
11
15bool phoenix_createMockBackend(PClockMockFile & mock, const std::string & prefix){
16 mock.setMockPrefix(prefix);
17 return true;
18}
19
21
27bool phoenix_createClockMock(const std::string & prefix, size_t nbTime, time_t firstTime, time_t timeIncrement){
28 if(nbTime < 1000lu){ //For small clock we use a vector and a file otherwise
29 PClockMock mock;
30 phoenix_createMockBackend(mock, prefix);
31 phoenix_fillClockMock(mock, nbTime, firstTime, timeIncrement);
32 mock.close();
33 }else{
34 PClockMockFile mock;
35 phoenix_createMockBackend(mock, prefix);
36 phoenix_fillClockMock(mock, nbTime, firstTime, timeIncrement);
37 mock.close();
38 }
39 return true;
40}
41
46
51
53
56 p_mock.setIsRecord(false);
57 time_t currentTime = 0lu;
58 p_mock.getCurrentValue(currentTime);
59 return currentTime;
60}
61
63
65void PClockMockFile::sleep(EllapsedTime ellapsedTime) const {
66 //No real sleep in mock
67}
68
70
72void PClockMockFile::setCurrentTime(time_t currentTime){
73 p_mock.setIsRecord(true);
74 //Let's record the given time
75 p_mock.append(currentTime);
76}
77
79
81void PClockMockFile::setMockPrefix(const std::string & mockPrefix){
82 std::stringstream socketFileName;
83 socketFileName << mockPrefix << "clock.pclockmock";
84 p_mock.setFileName(socketFileName.str());
85}
86
89 p_mock.close();
90}
91
96
97
98
99
100
bool phoenix_createClockMock(const std::string &prefix, size_t nbTime, time_t firstTime, time_t timeIncrement)
Create a clock mock.
bool phoenix_createMockBackend(PClockMockFile &mock, const std::string &prefix)
Create a mock backend for clock.
void phoenix_fillClockMock(_TClockMock &mock, size_t nbTime, time_t firstTime, time_t timeIncrement)
Fill the given clock mock.
Mock of a clock.
virtual ~PClockMockFile()
Destructor of PClockMockFile.
PClockMockFile()
Default constructor of PClockMockFile.
void setCurrentTime(time_t currentTime)
Set the current time to be recorded.
void close()
Close the PClockMockFile.
PGenericFileMock< time_t > p_mock
Mock handler.
void initialisationPClockMockFile()
Initialisation function of the class PClockMockFile.
void setMockPrefix(const std::string &mockPrefix)
Set the mock directory.
time_t now()
Get the mocked current time.
void sleep(EllapsedTime ellapsedTime) const
Sleep for the given ellapsed time.
Mock of a clock.
Definition PClockMock.h:14
void close()
Close the mock.
time_t EllapsedTime