ParamInterval.hh
3.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/*
* ParamInterval.hh
*
* Created on: Dec 11, 2012
* Author: f.casimir
*/
#ifndef PARAMINTERVAL_HH_
#define PARAMINTERVAL_HH_
#include <map>
#include <boost/shared_ptr.hpp>
#include "Worker.hh"
#include "ParamDataIndexInfo.hh"
#include "DataWriter.hh"
#include "TimeStamp.hh"
namespace AMDA {
namespace Parameters {
class DataClient;
/**
* @brief Synchronize DataClient and get new Data via a DataWriter if necessary
*/
class ParamInterval : public AMDA::Helpers::Worker {
public:
typedef std::map<DataClient *,ParamDataIndexInfo> DataClientInfoList;
ParamInterval(TimeIntervalListSPtr pTimeIntervalList, DataWriter* dataWriter);
~ParamInterval();
/**
* @brief compare two time interval list
* @return true if both are equal
*/
bool getIsEqual(TimeIntervalList* pTimeIntervalList) {
if (_timeIntervalList->size() != pTimeIntervalList->size()) {
return false;
} else {
TimeIntervalList::const_iterator itA = _timeIntervalList->begin();
TimeIntervalList::const_iterator itB = pTimeIntervalList->begin();
while (itA != _timeIntervalList->end()) {
if ( (itA->_startTime != itB->_startTime) || (itA->_stopTime != itB->_stopTime) ) {
return false;
} else {
++itA;
++itB;
}
}
return true;
}
}
/**
* @brief paramData of _dataWriter getter
*/
ParamDataSPtr& getParamData() { return _dataWriter->getParamData();}
/**
* @brief Place interval on existing or creates
* @return the last time of all file object which can modify the type of ParamData of Parameter
*/
TimeStamp init() {return _dataWriter->init(_timeIntervalList) ;};
// Others methods
/**
* @brief add a new data consumer
*/
void addClient(DataClient *pDataClient) { _dataClient.insert( std::make_pair(pDataClient,ParamDataIndexInfo())); }
/**
* @brief Remove a new data consumer
*/
void removeClient(DataClient *pDataClient) { auto it = _dataClient.find(pDataClient); if ( it != _dataClient.end()) { _dataClient.erase(it); } }
/**
* @brief call by a client for get more data
* @details call in a thread the this->get() method
* @return in a future object, the nbData Available or 0 if no Data
* get of future object is a blocking operation
* the client must consume this new data
*/
boost::shared_future<ParamDataIndexInfo> getAsync(DataClient * pClient) {
AMDA::Helpers::Task<ParamDataIndexInfo>* task = new AMDA::Helpers::Task<ParamDataIndexInfo>(
boost::bind(&ParamInterval::get, this, pClient));
boost::shared_future<ParamDataIndexInfo> future(task->getFuture());
_taskList.push(task); // assuming internal_queue member
return future;
}
/**
* @brief _dataWriter setter
*/
void setDataWriter(DataWriter* dataWriter) {
_dataWriter = dataWriter;
}
protected:
/**
* @brief return index of available data for a data client
* @details ask to dataWriter to update new data if necessary and synchronize all dataClient
*/
ParamDataIndexInfo get( DataClient *);
static log4cxx::LoggerPtr _logger;
private:
TimeIntervalListSPtr _timeIntervalList;
/**
* @brief DataWriter can write data in _paramData
*/
DataWriter* _dataWriter;
/**
* @brief map of ParamDataIndexInfo, with DataClient key
*/
DataClientInfoList _dataClient;
};
} /* namespace Parameters */
} /* namespace AMDA */
#endif /* PARAMINTERVAL_HH_ */