Blame view

src/ParamGetImpl/LocalFileInterface/ParamFlow.hh 3.91 KB
fbe3c2bb   Benjamin Renard   First commit
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/*
 * ParamFlow.hh
 *
 *  Created on: Nov 25, 2014
 *      Author: AKKA
 */

#ifndef PARAMFLOW_HH_
#define PARAMFLOW_HH_

#include "LocalParamData.hh"

#include <boost/shared_ptr.hpp>

#include <CThreadDeque.hh>

namespace AMDA {

namespace LocalFileInterface {

class VirtualInstrumentInterval;

/**
 * @class ParamFlow.
 * @brief Represent a flow of a couple time and data asked for one Parameter of a Virtual Instrument.
 * @details This flow is implement with a thread safe dequeue of Packet.
 * This class is a listener of the class VirtualInstrumentInterval.
 */
class ParamFlow {
public:
	/*
	 * @ brief Param info associated to a ParamFlow
	 */
	class ParamInfo
	{
	public:
		ParamInfo(LocalParamType paramType, int paramDim1Size, int paramDim2Size) :
			_paramType(paramType), _paramDim1Size(paramDim1Size), _paramDim2Size(paramDim2Size)
		{

		}

		~ParamInfo()
		{
			//remove not treated packets (this can occured after an exception)
			while (!_packetList.empty())
			{
				LocalParamDataPacket* packet = _packetList.pop();
				if (packet != NULL)
					delete packet;
			}
		}

		LocalParamType getType()
		{
			return _paramType;
		}

		int getDim1Size()
		{
			return _paramDim1Size;
		}

		int getDim2Size()
		{
			return _paramDim2Size;
		}

		CThreadDeque<LocalParamDataPacket*>& getPacketList()
		{
			return _packetList;
		}

	private:
		/*
		 * @brief Param type
		 */
		LocalParamType _paramType;

		/*
		 * @brief Param dim1 size
		 */
		int _paramDim1Size;

		/*
		 * @brief Param dim2 size
		 */
		int _paramDim2Size;

		/*
		 * @brief List of Packet for this param
		 */
		CThreadDeque<LocalParamDataPacket*> _packetList;
	};

	/**
	 * @brief Constructor.
	 */
	ParamFlow(VirtualInstrumentInterval&);

	/*
	 * @brief Destructor.
	 */
	virtual ~ParamFlow();

	/*
	 * @brief Add associated param to this param flow
	 */
	void addAssociatedParam(std::string paramId, LocalParamType paramType, int dim1Size, int dim2Size)
	{
		//try to find param
		auto lIt = _paramInfoMap.find(paramId);
		if (lIt == _paramInfoMap.end())
			_paramInfoMap[paramId].reset(new ParamInfo(paramType,dim1Size,dim2Size));
	}

	/**
	 * @brief This method waits for the arrival of a new pack.
	 * @return Packet or null.
	 */
	LocalParamDataPacket* get(std::string paramId);

	/**
	 * @return the Packet already in the dequeue or null.
	 */
	LocalParamDataPacket* tryGet(std::string pParamId)
	{
		//try to find param
		auto lIt = _paramInfoMap.find(pParamId);
		if (lIt == _paramInfoMap.end())
			return NULL;
		if (_paramInfoMap[pParamId] == nullptr)
			return NULL;
		return _paramInfoMap[pParamId]->getPacketList().tryToPop(nullptr);
	}

	/**
	 * @brief Push Packet to the internal dequeue.
	 */
	void push(std::string pParamId, LocalParamDataPacket* pPacket)
	{
		//try to find param
		auto lIt = _paramInfoMap.find(pParamId);
		if (lIt == _paramInfoMap.end())
			return;
		if (_paramInfoMap[pParamId] == nullptr)
			return;
		return _paramInfoMap[pParamId]->getPacketList().push(pPacket);
	}

	/**
	 * @brief Identify at any time if a TimeInterval is not processed.
	 * @note This value must be retrieved from VirtualInstrumentInterval instance.
	 */
	bool isTimeIntToProcessChanged (std::string pParamId);

fa4b7852   Benjamin Renard   Fix bug around ti...
157
158
159
160
161
162
	/**
	 * @brief Identify at any time if the lat insterval is reached.
	 * @note This value must be retrieved from VirtualInstrumentInterval instance.
	 */
	bool isNoMoreTimeInt(std::string pParamId);

fbe3c2bb   Benjamin Renard   First commit
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
	/*
	 * @brief Get list of param info associated to this param flow
	 */
	std::map<std::string,std::shared_ptr<ParamInfo> >& getParamInfoMap()
	{
		return _paramInfoMap;
	}

	private:

	/*
	 * @brief Reference to the VirtualInstrumentInterval
	 */
	VirtualInstrumentInterval&      _vi;

	/*
	 * @brief Map of ParamInfo associaited to this ParamFlow. The key is the param Id
	 */
	std::map<std::string,std::shared_ptr<ParamInfo>> _paramInfoMap;
};

typedef boost::shared_ptr<ParamFlow>  ParamFlowSPtr;

} /* namespace LocalFileInterface */

} /* namespace AMDA */
#endif /* PARAMFLOW_HH_ */