Commit 3e72380234f9c41b89a2c92f031dc9f769bfc0ed
1 parent
a0567216
Exists in
SpeasyGet
Improve SpeasyProxyInterface
Showing
12 changed files
with
843 additions
and
348 deletions
Show diff stats
src/ParamGetImpl/SpeasyProxyInterface/FileReaderCDF.cc
@@ -207,6 +207,11 @@ bool FileReaderCDF::getCDFVarInfo(std::string paramName, CDFVarInfo& varInfo) | @@ -207,6 +207,11 @@ bool FileReaderCDF::getCDFVarInfo(std::string paramName, CDFVarInfo& varInfo) | ||
207 | return false; | 207 | return false; |
208 | } | 208 | } |
209 | 209 | ||
210 | + if (_varInfoMap.find(paramName) != _varInfoMap.end()) { | ||
211 | + varInfo = _varInfoMap[paramName]; | ||
212 | + return true; | ||
213 | + } | ||
214 | + | ||
210 | //reset info structure | 215 | //reset info structure |
211 | memset(&varInfo,0,sizeof(CDFVarInfo)); | 216 | memset(&varInfo,0,sizeof(CDFVarInfo)); |
212 | 217 | ||
@@ -222,6 +227,10 @@ bool FileReaderCDF::getCDFVarInfo(std::string paramName, CDFVarInfo& varInfo) | @@ -222,6 +227,10 @@ bool FileReaderCDF::getCDFVarInfo(std::string paramName, CDFVarInfo& varInfo) | ||
222 | return false; | 227 | return false; |
223 | } | 228 | } |
224 | 229 | ||
230 | + long depend1AttNum = CDFattrNum(_cdfid, (char*)"DEPEND_1"); | ||
231 | + long depend2AttNum = CDFattrNum(_cdfid, (char*)"DEPEND_2"); | ||
232 | + | ||
233 | + | ||
225 | //Is it a zVariable? | 234 | //Is it a zVariable? |
226 | CDFstatus status = CDFconfirmzVarExistence(_cdfid,varInfo._name); | 235 | CDFstatus status = CDFconfirmzVarExistence(_cdfid,varInfo._name); |
227 | 236 | ||
@@ -257,6 +266,30 @@ bool FileReaderCDF::getCDFVarInfo(std::string paramName, CDFVarInfo& varInfo) | @@ -257,6 +266,30 @@ bool FileReaderCDF::getCDFVarInfo(std::string paramName, CDFVarInfo& varInfo) | ||
257 | LOG4CXX_ERROR(gLogger, "FileReaderCDF::getCDFVarInfo - Error to call CDFgetDataTypeSize"); | 266 | LOG4CXX_ERROR(gLogger, "FileReaderCDF::getCDFVarInfo - Error to call CDFgetDataTypeSize"); |
258 | return false; | 267 | return false; |
259 | } | 268 | } |
269 | + | ||
270 | + if (depend1AttNum >= 0) { | ||
271 | + long dataType; | ||
272 | + long numElems; | ||
273 | + status = CDFinquireAttrzEntry (_cdfid, depend1AttNum, varInfo._num, &dataType, &numElems); | ||
274 | + | ||
275 | + if (status == CDF_OK) { | ||
276 | + if (dataType == CDF_CHAR) { | ||
277 | + status = CDFgetAttrzEntry (_cdfid, depend1AttNum, varInfo._num, varInfo._depend1); | ||
278 | + } | ||
279 | + } | ||
280 | + } | ||
281 | + | ||
282 | + if (depend2AttNum >= 0) { | ||
283 | + long dataType; | ||
284 | + long numElems; | ||
285 | + status = CDFinquireAttrzEntry (_cdfid, depend2AttNum, varInfo._num, &dataType, &numElems); | ||
286 | + | ||
287 | + if (status == CDF_OK) { | ||
288 | + if (dataType == CDF_CHAR) { | ||
289 | + status = CDFgetAttrzEntry (_cdfid, depend2AttNum, varInfo._num, varInfo._depend2); | ||
290 | + } | ||
291 | + } | ||
292 | + } | ||
260 | } | 293 | } |
261 | else | 294 | else |
262 | { | 295 | { |
@@ -292,8 +325,34 @@ bool FileReaderCDF::getCDFVarInfo(std::string paramName, CDFVarInfo& varInfo) | @@ -292,8 +325,34 @@ bool FileReaderCDF::getCDFVarInfo(std::string paramName, CDFVarInfo& varInfo) | ||
292 | LOG4CXX_ERROR(gLogger, "FileReaderCDF::getCDFVarInfo - Error to call CDFgetDataTypeSize"); | 325 | LOG4CXX_ERROR(gLogger, "FileReaderCDF::getCDFVarInfo - Error to call CDFgetDataTypeSize"); |
293 | return false; | 326 | return false; |
294 | } | 327 | } |
328 | + | ||
329 | + if (depend1AttNum >= 0) { | ||
330 | + long dataType; | ||
331 | + long numElems; | ||
332 | + status = CDFinquireAttrrEntry (_cdfid, depend1AttNum, varInfo._num, &dataType, &numElems); | ||
333 | + | ||
334 | + if (status == CDF_OK) { | ||
335 | + if (dataType == CDF_CHAR) { | ||
336 | + status = CDFgetAttrrEntry (_cdfid, depend1AttNum, varInfo._num, varInfo._depend1); | ||
337 | + } | ||
338 | + } | ||
339 | + } | ||
340 | + | ||
341 | + if (depend2AttNum >= 0) { | ||
342 | + long dataType; | ||
343 | + long numElems; | ||
344 | + status = CDFinquireAttrrEntry (_cdfid, depend2AttNum, varInfo._num, &dataType, &numElems); | ||
345 | + | ||
346 | + if (status == CDF_OK) { | ||
347 | + if (dataType == CDF_CHAR) { | ||
348 | + status = CDFgetAttrrEntry (_cdfid, depend2AttNum, varInfo._num, varInfo._depend2); | ||
349 | + } | ||
350 | + } | ||
351 | + } | ||
295 | } | 352 | } |
296 | - | 353 | + |
354 | + _varInfoMap[paramName] = varInfo; | ||
355 | + | ||
297 | return true; | 356 | return true; |
298 | } | 357 | } |
299 | 358 | ||
@@ -367,7 +426,7 @@ int FileReaderCDF::getRecordIndex(std::string& timeId, double time) | @@ -367,7 +426,7 @@ int FileReaderCDF::getRecordIndex(std::string& timeId, double time) | ||
367 | return -1; | 426 | return -1; |
368 | } | 427 | } |
369 | 428 | ||
370 | -FileReaderStatus FileReaderCDF::getParamPacketData(std::string& timeId, std::string& paramId, int crtIndex, | 429 | +FileReaderStatus FileReaderCDF::getParamPacketData(std::string& timeId, std::string& paramId, int crtIndex, int dependNumber, |
371 | SpeasyProxyParamDataPacket *packet) | 430 | SpeasyProxyParamDataPacket *packet) |
372 | { | 431 | { |
373 | LOG4CXX_DEBUG(gLogger, "FileReaderCDF::getParamPacketData"); | 432 | LOG4CXX_DEBUG(gLogger, "FileReaderCDF::getParamPacketData"); |
@@ -423,11 +482,30 @@ FileReaderStatus FileReaderCDF::getParamPacketData(std::string& timeId, std::str | @@ -423,11 +482,30 @@ FileReaderStatus FileReaderCDF::getParamPacketData(std::string& timeId, std::str | ||
423 | } | 482 | } |
424 | 483 | ||
425 | //get data | 484 | //get data |
485 | + std::string paramToGet = paramId; | ||
486 | + if (dependNumber > 0) { | ||
487 | + paramToGet = ""; | ||
488 | + CDFVarInfo varInfo; | ||
489 | + if (getCDFVarInfo(paramId, varInfo)){ | ||
490 | + if (dependNumber == 1) { | ||
491 | + paramToGet = std::string(varInfo._depend1); | ||
492 | + } | ||
493 | + else if (dependNumber == 2) { | ||
494 | + paramToGet = std::string(varInfo._depend2); | ||
495 | + } | ||
496 | + } | ||
497 | + } | ||
498 | + | ||
499 | + if (paramToGet.empty()) { | ||
500 | + LOG4CXX_ERROR(gLogger, "FileReaderCDF::getParamPacketData - Cannot determine param to get"); | ||
501 | + return FRS_ERROR; | ||
502 | + } | ||
503 | + | ||
426 | long nbRec; | 504 | long nbRec; |
427 | long dimSize; | 505 | long dimSize; |
428 | long dataType; | 506 | long dataType; |
429 | long numBytes; | 507 | long numBytes; |
430 | - if (!getCDFData(paramId, crtIndex, CDFWorkingBuffers::BufferType::BUFFER_DATA, dataType, numBytes, nbRec, dimSize)) | 508 | + if (!getCDFData(paramToGet, crtIndex, CDFWorkingBuffers::BufferType::BUFFER_DATA, dataType, numBytes, nbRec, dimSize)) |
431 | { | 509 | { |
432 | LOG4CXX_ERROR(gLogger, "FileReaderCDF::getParamPacketData - Cannot get var data for " << paramId); | 510 | LOG4CXX_ERROR(gLogger, "FileReaderCDF::getParamPacketData - Cannot get var data for " << paramId); |
433 | return FRS_ERROR; | 511 | return FRS_ERROR; |
@@ -871,7 +949,7 @@ bool FileReaderCDF::getInfo(const char* pInfoName, std::vector<double>& res) | @@ -871,7 +949,7 @@ bool FileReaderCDF::getInfo(const char* pInfoName, std::vector<double>& res) | ||
871 | containerType = CONTAINER_MATRIX; | 949 | containerType = CONTAINER_MATRIX; |
872 | 950 | ||
873 | packet.init(containerType,paramType,dim1Size,dim2Size); | 951 | packet.init(containerType,paramType,dim1Size,dim2Size); |
874 | - getParamPacketData(emptyTimeStr, paramName, 0, &packet); | 952 | + getParamPacketData(emptyTimeStr, paramName, 0, 0, &packet); |
875 | if (packet.getNbData() > 0) { | 953 | if (packet.getNbData() > 0) { |
876 | for (int i = 0; i < dim1Size; ++i) { | 954 | for (int i = 0; i < dim1Size; ++i) { |
877 | for (int j = 0; j < dim2Size; ++j) { | 955 | for (int j = 0; j < dim2Size; ++j) { |
src/ParamGetImpl/SpeasyProxyInterface/FileReaderCDF.hh
@@ -79,7 +79,7 @@ public: | @@ -79,7 +79,7 @@ public: | ||
79 | /* | 79 | /* |
80 | * @brief Get a param packet from the CDF file | 80 | * @brief Get a param packet from the CDF file |
81 | */ | 81 | */ |
82 | - FileReaderStatus getParamPacketData(std::string& timeId, std::string& paramId, int crtIndex, SpeasyProxyParamDataPacket *packet); | 82 | + FileReaderStatus getParamPacketData(std::string& timeId, std::string& paramId, int crtIndex, int dependNumber, SpeasyProxyParamDataPacket *packet); |
83 | 83 | ||
84 | /* | 84 | /* |
85 | * @brief Get an information | 85 | * @brief Get an information |
@@ -141,6 +141,9 @@ private: | @@ -141,6 +141,9 @@ private: | ||
141 | long _dimVarys[CDF_MAX_DIMS]; | 141 | long _dimVarys[CDF_MAX_DIMS]; |
142 | //maximum record number | 142 | //maximum record number |
143 | long _maxRecNum; | 143 | long _maxRecNum; |
144 | + | ||
145 | + char _depend1[CDF_VAR_NAME_LEN256+1]; | ||
146 | + char _depend2[CDF_VAR_NAME_LEN256+1]; | ||
144 | } CDFVarInfo; | 147 | } CDFVarInfo; |
145 | 148 | ||
146 | /* | 149 | /* |
@@ -251,6 +254,8 @@ private: | @@ -251,6 +254,8 @@ private: | ||
251 | */ | 254 | */ |
252 | boost::shared_ptr<CDFWorkingBuffers> _workingBuffers; | 255 | boost::shared_ptr<CDFWorkingBuffers> _workingBuffers; |
253 | 256 | ||
257 | + std::map<std::string, CDFVarInfo> _varInfoMap; | ||
258 | + | ||
254 | /* | 259 | /* |
255 | * @brief Get CDF variable Info from param name | 260 | * @brief Get CDF variable Info from param name |
256 | */ | 261 | */ |
src/ParamGetImpl/SpeasyProxyInterface/GetSpeasyProxyNode.cc
@@ -14,6 +14,7 @@ | @@ -14,6 +14,7 @@ | ||
14 | #include "ParamGet.hh" | 14 | #include "ParamGet.hh" |
15 | #include "ParamGetSpeasyProxy.hh" | 15 | #include "ParamGetSpeasyProxy.hh" |
16 | #include "ParameterManager.hh" | 16 | #include "ParameterManager.hh" |
17 | +#include "ParamMgr.hh" | ||
17 | 18 | ||
18 | #include <boost/algorithm/string.hpp> | 19 | #include <boost/algorithm/string.hpp> |
19 | #include <boost/lexical_cast.hpp> | 20 | #include <boost/lexical_cast.hpp> |
@@ -30,9 +31,152 @@ using namespace AMDA::XMLConfigurator; | @@ -30,9 +31,152 @@ using namespace AMDA::XMLConfigurator; | ||
30 | namespace AMDA { | 31 | namespace AMDA { |
31 | namespace XMLParameterConfigurator { | 32 | namespace XMLParameterConfigurator { |
32 | 33 | ||
34 | +class SpeasyProxyDependValueNode: public AMDA::XMLConfigurator::NodeCfg { | ||
35 | +public: | ||
36 | + void proceed(xmlNodePtr pNode, const AMDA::Parameters::CfgContext& pContext) { | ||
37 | + LOG4CXX_DEBUG(gLogger, "SpeasyProxyDependValueNode::proceed") | ||
38 | + | ||
39 | + Parameter::InfoValues* lInfoValue = pContext.get<Parameter::InfoValues*>(); | ||
40 | + | ||
41 | + try { | ||
42 | + if (pNode->children && pNode->children->content && pNode->children->content[0] != '\0') { | ||
43 | + double value = atof((const char*)pNode->children->content); | ||
44 | + LOG4CXX_DEBUG(gLogger, "SpeasyProxyDependValueNode::proceed - " << value); | ||
45 | + lInfoValue->push_back(value); | ||
46 | + } | ||
47 | + } catch (...) { | ||
48 | + throw; | ||
49 | + } | ||
50 | + | ||
51 | + } | ||
52 | +}; | ||
53 | + | ||
54 | +class SpeasyProxyDependNode: public AMDA::XMLConfigurator::NodeGrpCfg { | ||
55 | +public: | ||
56 | + SpeasyProxyDependNode() : AMDA::XMLConfigurator::NodeGrpCfg() { | ||
57 | + getChildList()["value"]=NodeCfgSPtr(new SpeasyProxyDependValueNode()); | ||
58 | + } | ||
59 | + | ||
60 | + void proceed(xmlNodePtr pNode, const AMDA::Parameters::CfgContext& pContext) { | ||
61 | + LOG4CXX_DEBUG(gLogger, "SpeasyProxyDependNode::proceed") | ||
62 | + | ||
63 | + ServicesServer* lServicesServer = pContext.get<ServicesServer*>(); | ||
64 | + AMDA::SpeasyProxyInterface::ParamGetSpeasyProxy* paramGet = pContext.get<AMDA::SpeasyProxyInterface::ParamGetSpeasyProxy*>(); | ||
65 | + Parameter* lParameter = pContext.get<Parameter*>(); | ||
66 | + AMDA::Info::ParamInfo* paramInfo = pContext.get<AMDA::Info::ParamInfo*>(); | ||
67 | + ParameterManager* lParameterManager = pContext.get<ParameterManager*>(); | ||
68 | + | ||
69 | + try { | ||
70 | + xmlChar* lId = xmlGetProp(pNode, (const xmlChar*)"id"); | ||
71 | + std::string idStr; | ||
72 | + if (lId) { | ||
73 | + idStr = std::string((const char*) lId); | ||
74 | + xmlFree(lId); | ||
75 | + } | ||
76 | + else { | ||
77 | + ERROR_EXCEPTION(ERROR_MANDATORY_ATTRIBUTE_MISSING << pNode->name << "@id") | ||
78 | + } | ||
79 | + | ||
80 | + xmlChar* lDim = xmlGetProp(pNode, (const xmlChar*)"dim"); | ||
81 | + int dim = 0; | ||
82 | + if (lDim) { | ||
83 | + std::string dimStr = std::string((const char*) lDim); | ||
84 | + boost::trim(dimStr); | ||
85 | + dim = boost::lexical_cast<int>(dimStr); | ||
86 | + xmlFree(lDim); | ||
87 | + } | ||
88 | + else { | ||
89 | + ERROR_EXCEPTION(ERROR_MANDATORY_ATTRIBUTE_MISSING << pNode->name << "@dim") | ||
90 | + } | ||
91 | + | ||
92 | + xmlChar* lType = xmlGetProp(pNode, (const xmlChar*)"type"); | ||
93 | + AMDA::SpeasyProxyInterface::SpeasyProxyParamType type; | ||
94 | + if (lType) { | ||
95 | + std::string typeStr; | ||
96 | + typeStr = std::string((const char*) lType); | ||
97 | + type = AMDA::SpeasyProxyInterface::stringToParamType(typeStr); | ||
98 | + if (type == AMDA::SpeasyProxyInterface::SpeasyProxyParamType::TYPE_UNKNOWN) { | ||
99 | + LOG4CXX_ERROR(gLogger, "SpeasyProxyParamNode::proceed - Unknown data type " << ((const char*)lType)) | ||
100 | + } | ||
101 | + xmlFree(lType); | ||
102 | + } | ||
103 | + else { | ||
104 | + ERROR_EXCEPTION(ERROR_MANDATORY_ATTRIBUTE_MISSING << pNode->name << "@type") | ||
105 | + } | ||
106 | + | ||
107 | + xmlChar* lName = xmlGetProp(pNode, (const xmlChar*)"name"); | ||
108 | + std::string nameStr; | ||
109 | + if (lName) { | ||
110 | + nameStr = std::string((const char*) lName); | ||
111 | + xmlFree(lName); | ||
112 | + } | ||
113 | + else { | ||
114 | + ERROR_EXCEPTION(ERROR_MANDATORY_ATTRIBUTE_MISSING << pNode->name << "@name") | ||
115 | + } | ||
116 | + | ||
117 | + xmlChar* lUnits = xmlGetProp(pNode, (const xmlChar*)"units"); | ||
118 | + std::string unitsStr; | ||
119 | + if (lUnits) { | ||
120 | + unitsStr = std::string((const char*) lUnits); | ||
121 | + xmlFree(lUnits); | ||
122 | + } | ||
123 | + | ||
124 | + xmlChar* lIsVariable = xmlGetProp(pNode, (const xmlChar*)"isVariable"); | ||
125 | + bool isVariable = false; | ||
126 | + if (lIsVariable) { | ||
127 | + isVariable = (strcmp((char*) lIsVariable, "True") == 0); | ||
128 | + xmlFree(lIsVariable); | ||
129 | + } | ||
130 | + | ||
131 | + boost::shared_ptr<AMDA::Info::ParamTable> tableDepend(new AMDA::Info::ParamCenterAutoTable( | ||
132 | + lParameter->getId().c_str(), dim, false)); | ||
133 | + tableDepend->setName(nameStr); | ||
134 | + tableDepend->setUnits(unitsStr); | ||
135 | + tableDepend->setIsVariable(isVariable); | ||
136 | + tableDepend->setIsFullVariable(isVariable); | ||
137 | + paramInfo->addTable(dim, tableDepend); | ||
138 | + | ||
139 | + AMDA::Parameters::CfgContext lContext(pContext); | ||
140 | + if (isVariable) { | ||
141 | + std::string paramDependId = paramGet->getParameter()->getId() + "_DEPEND_" + std::to_string(dim+1); | ||
142 | + ParameterSPtr lDependParameter; | ||
143 | + if ( lParameterManager->addParameter(NULL,paramDependId,lDependParameter)) { | ||
144 | + const char *lSouceParamGet = "SPEASY_PROXY"; | ||
145 | + AMDA::SpeasyProxyInterface::ParamGetSpeasyProxySPtr lParamDependGet(dynamic_cast<AMDA::SpeasyProxyInterface::ParamGetSpeasyProxy*>(lServicesServer->getParamGet( lSouceParamGet, *lDependParameter))); | ||
146 | + DataWriterSPtr lDependDataWriter( lParamDependGet); | ||
147 | + //lDependDataWriter->setSignatureTrigger(paramGet->getDataWriterTemplate()->getSignatureTrigger()); | ||
148 | + lParamDependGet->setParamSpeasyId(paramGet->getParamSpeasyId().c_str()); | ||
149 | + lParamDependGet->setDim1(paramGet->getDim1()); | ||
150 | + lParamDependGet->setDim2(paramGet->getDim2()); | ||
151 | + lParamDependGet->setType(paramGet->getType()); | ||
152 | + lParamDependGet->setMinSampling(paramGet->getMinSampling()); | ||
153 | + lParamDependGet->setDepend(dim+1, type); | ||
154 | + lDependParameter->setDataWriter(lDependDataWriter); | ||
155 | + | ||
156 | + tableDepend->addTableParam(AMDA::Info::ParamCenterAutoTable::_centersParamKey, (const char*) paramDependId.c_str()); | ||
157 | + } | ||
158 | + } | ||
159 | + else { | ||
160 | + Parameter::InfoValuesSPtr pInfoValues(new Parameter::InfoValues); | ||
161 | + lParameter->setInfoValues(idStr, pInfoValues); | ||
162 | + tableDepend->addTableParam(AMDA::Info::ParamCenterAutoTable::_centersParamKey, (const char*) idStr.c_str()); | ||
163 | + lContext.push<Parameter::InfoValues*>(pInfoValues.get()); | ||
164 | + } | ||
165 | + | ||
166 | + NodeGrpCfg::proceed(pNode, lContext); | ||
167 | + | ||
168 | + } catch (...) { | ||
169 | + throw; | ||
170 | + } | ||
171 | + | ||
172 | + } | ||
173 | +}; | ||
174 | + | ||
33 | class SpeasyProxyParamNode: public AMDA::XMLConfigurator::NodeGrpCfg { | 175 | class SpeasyProxyParamNode: public AMDA::XMLConfigurator::NodeGrpCfg { |
34 | public: | 176 | public: |
35 | - SpeasyProxyParamNode() : AMDA::XMLConfigurator::NodeGrpCfg() {} | 177 | + SpeasyProxyParamNode() : AMDA::XMLConfigurator::NodeGrpCfg() { |
178 | + getChildList()["depend"]=NodeCfgSPtr(new SpeasyProxyDependNode()); | ||
179 | + } | ||
36 | 180 | ||
37 | void proceed(xmlNodePtr pNode, const AMDA::Parameters::CfgContext& pContext) | 181 | void proceed(xmlNodePtr pNode, const AMDA::Parameters::CfgContext& pContext) |
38 | { | 182 | { |
@@ -70,21 +214,21 @@ public: | @@ -70,21 +214,21 @@ public: | ||
70 | 214 | ||
71 | std::string* xmlFileName = pContext.get<std::string*>(); | 215 | std::string* xmlFileName = pContext.get<std::string*>(); |
72 | lDataWriter->setSignatureTrigger(*xmlFileName); | 216 | lDataWriter->setSignatureTrigger(*xmlFileName); |
73 | - lParamGet->setParamId(paramIdStr.c_str()); | 217 | + lParamGet->setParamSpeasyId(paramIdStr.c_str()); |
74 | lParameter->setDataWriter(lDataWriter); | 218 | lParameter->setDataWriter(lDataWriter); |
75 | 219 | ||
220 | + AMDA::Info::ParamInfoSPtr paramInfo = AMDA::Info::ParamMgr::getInstance()->getParamInfoFromId(lParentParameter->getId(),true); | ||
221 | + lParameter->setInfoId(lParentParameter->getId()); | ||
222 | + | ||
76 | //type | 223 | //type |
77 | xmlChar* value = NULL; | 224 | xmlChar* value = NULL; |
78 | if ((value = xmlGetProp(pNode, (const xmlChar*)"type")) != NULL) | 225 | if ((value = xmlGetProp(pNode, (const xmlChar*)"type")) != NULL) |
79 | { | 226 | { |
80 | - if (strcmp((const char*)value,"float") == 0) | ||
81 | - lParamGet->setType(AMDA::SpeasyProxyInterface::SpeasyProxyParamType::TYPE_FLOAT); | ||
82 | - else if (strcmp((const char*)value,"double") == 0) | ||
83 | - lParamGet->setType(AMDA::SpeasyProxyInterface::SpeasyProxyParamType::TYPE_DOUBLE); | ||
84 | - else if (strcmp((const char*)value,"short") == 0) | ||
85 | - lParamGet->setType(AMDA::SpeasyProxyInterface::SpeasyProxyParamType::TYPE_SHORT); | ||
86 | - else if ((strcmp((const char*)value,"int") == 0) || (strcmp((const char*)value,"integer") == 0)) | ||
87 | - lParamGet->setType(AMDA::SpeasyProxyInterface::SpeasyProxyParamType::TYPE_INT); | 227 | + std::string typeStr = std::string((const char*)value); |
228 | + AMDA::SpeasyProxyInterface::SpeasyProxyParamType type = AMDA::SpeasyProxyInterface::stringToParamType(typeStr); | ||
229 | + if (type != AMDA::SpeasyProxyInterface::SpeasyProxyParamType::TYPE_UNKNOWN) { | ||
230 | + lParamGet->setType(type); | ||
231 | + } | ||
88 | else | 232 | else |
89 | { | 233 | { |
90 | LOG4CXX_ERROR(gLogger, "SpeasyProxyParamNode::proceed - Unknown data type " << ((const char*)value)) | 234 | LOG4CXX_ERROR(gLogger, "SpeasyProxyParamNode::proceed - Unknown data type " << ((const char*)value)) |
@@ -92,44 +236,39 @@ public: | @@ -92,44 +236,39 @@ public: | ||
92 | xmlFree(value); | 236 | xmlFree(value); |
93 | } | 237 | } |
94 | 238 | ||
95 | - //dim1 | 239 | + //minSampling |
240 | + if ((value = xmlGetProp(pNode, (const xmlChar*)"minSampling")) != NULL) | ||
241 | + { | ||
242 | + lParamGet->setMinSampling(atof((const char*)value)); | ||
243 | + xmlFree(value); | ||
244 | + } | ||
96 | 245 | ||
246 | + //dim1 | ||
247 | + int dim1 = 0; | ||
97 | if ((value = xmlGetProp(pNode, (const xmlChar*)"dim1")) != NULL) | 248 | if ((value = xmlGetProp(pNode, (const xmlChar*)"dim1")) != NULL) |
98 | { | 249 | { |
99 | std::string dim1Str = std::string((const char*) value); | 250 | std::string dim1Str = std::string((const char*) value); |
100 | boost::trim(dim1Str); | 251 | boost::trim(dim1Str); |
101 | - int dim1 = boost::lexical_cast<int>(dim1Str); | ||
102 | - if(dim1 > 0) | ||
103 | - lParamGet->setDim1(dim1); | ||
104 | - else | ||
105 | - lParamGet->setDim1(1); | ||
106 | - xmlFree(value); | ||
107 | - | ||
108 | - } | 252 | + dim1 = boost::lexical_cast<int>(dim1Str); |
253 | + lParamGet->setDim1(dim1); | ||
254 | + xmlFree(value); | ||
255 | + } | ||
109 | 256 | ||
110 | - //dim2 | ||
111 | - if ((value = xmlGetProp(pNode, (const xmlChar*)"dim2")) != NULL) | 257 | + //dim2 |
258 | + int dim2 = 0; | ||
259 | + if ((value = xmlGetProp(pNode, (const xmlChar*)"dim2")) != NULL) | ||
112 | { | 260 | { |
113 | std::string dim2Str = std::string((const char*) value); | 261 | std::string dim2Str = std::string((const char*) value); |
114 | boost::trim(dim2Str); | 262 | boost::trim(dim2Str); |
115 | - int dim2 = boost::lexical_cast<int>(dim2Str); | ||
116 | - if(dim2 > 0) | ||
117 | - lParamGet->setDim2(dim2); | ||
118 | - else | ||
119 | - lParamGet->setDim2(1); | ||
120 | - xmlFree(value); | ||
121 | - | ||
122 | - } | ||
123 | - | ||
124 | - //minSampling | ||
125 | - if ((value = xmlGetProp(pNode, (const xmlChar*)"minSampling")) != NULL) | ||
126 | - { | ||
127 | - lParamGet->setMinSampling(atof((const char*)value)); | ||
128 | - xmlFree(value); | ||
129 | - } | 263 | + dim2 = boost::lexical_cast<int>(dim2Str); |
264 | + lParamGet->setDim2(dim2); | ||
265 | + xmlFree(value); | ||
266 | + } | ||
130 | 267 | ||
131 | - AMDA::Parameters::CfgContext lContext(pContext); | ||
132 | - lContext.push<AMDA::SpeasyProxyInterface::ParamGetSpeasyProxy*>(lParamGet.get()); | 268 | + AMDA::Parameters::CfgContext lContext(pContext); |
269 | + lContext.push<AMDA::SpeasyProxyInterface::ParamGetSpeasyProxy*>(lParamGet.get()); | ||
270 | + lContext.push<AMDA::Info::ParamInfo*>(paramInfo.get()); | ||
271 | + lContext.push<AMDA::Info::Parameter*>(lParameter.get()); | ||
133 | NodeGrpCfg::proceed(pNode, lContext); | 272 | NodeGrpCfg::proceed(pNode, lContext); |
134 | } | 273 | } |
135 | } catch (...) { | 274 | } catch (...) { |
src/ParamGetImpl/SpeasyProxyInterface/ParamGetSpeasyProxy.cc
@@ -20,8 +20,9 @@ | @@ -20,8 +20,9 @@ | ||
20 | #include "DicError.hh" | 20 | #include "DicError.hh" |
21 | #include "TimeUtil.hh" | 21 | #include "TimeUtil.hh" |
22 | #include "Properties.hh" | 22 | #include "Properties.hh" |
23 | -#include <fstream> | ||
24 | #include "Helper.hh" | 23 | #include "Helper.hh" |
24 | +#include <fstream> | ||
25 | +#include "SpeasyProxyRequestManager.hh" | ||
25 | 26 | ||
26 | #include <iostream> | 27 | #include <iostream> |
27 | #define CURL_STATICLIB | 28 | #define CURL_STATICLIB |
@@ -36,16 +37,19 @@ namespace SpeasyProxyInterface { | @@ -36,16 +37,19 @@ namespace SpeasyProxyInterface { | ||
36 | 37 | ||
37 | ParamGetSpeasyProxy::ParamGetSpeasyProxy(Parameter ¶meter) : | 38 | ParamGetSpeasyProxy::ParamGetSpeasyProxy(Parameter ¶meter) : |
38 | ParamGet_CRTP<ParamGetSpeasyProxy>(parameter), | 39 | ParamGet_CRTP<ParamGetSpeasyProxy>(parameter), |
39 | - _speasyProxyUrl(""), _paramId(""), _type(TYPE_FLOAT), _dim1(1), _dim2(1), _minSampling(1), _container(CONTAINER_SCALAR),_timeStamp(0) | 40 | + _paramSpeasyId(""), _type(TYPE_FLOAT), _dim1(1), _dim2(1), _dependNumber(0), |
41 | + _dependType(TYPE_FLOAT), _minSampling(1),_timeStamp(0) | ||
40 | { | 42 | { |
41 | 43 | ||
42 | } | 44 | } |
43 | 45 | ||
44 | ParamGetSpeasyProxy::ParamGetSpeasyProxy(const ParamGetSpeasyProxy &pParamGetSpeasyProxy, Parameter ¶meter) : | 46 | ParamGetSpeasyProxy::ParamGetSpeasyProxy(const ParamGetSpeasyProxy &pParamGetSpeasyProxy, Parameter ¶meter) : |
45 | ParamGet_CRTP<ParamGetSpeasyProxy>(pParamGetSpeasyProxy, parameter), | 47 | ParamGet_CRTP<ParamGetSpeasyProxy>(pParamGetSpeasyProxy, parameter), |
46 | - _speasyProxyUrl(pParamGetSpeasyProxy._speasyProxyUrl), _paramId(pParamGetSpeasyProxy._paramId), _type(pParamGetSpeasyProxy._type), | 48 | + _paramSpeasyId(pParamGetSpeasyProxy._paramSpeasyId), _type(pParamGetSpeasyProxy._type), |
47 | _dim1(pParamGetSpeasyProxy._dim1), _dim2(pParamGetSpeasyProxy._dim2), | 49 | _dim1(pParamGetSpeasyProxy._dim1), _dim2(pParamGetSpeasyProxy._dim2), |
48 | - _minSampling(pParamGetSpeasyProxy._minSampling), _container(pParamGetSpeasyProxy._container), | 50 | + _dependNumber(pParamGetSpeasyProxy._dependNumber), |
51 | + _dependType(pParamGetSpeasyProxy._dependType), | ||
52 | + _minSampling(pParamGetSpeasyProxy._minSampling), | ||
49 | _timeStamp(pParamGetSpeasyProxy._timeStamp) | 53 | _timeStamp(pParamGetSpeasyProxy._timeStamp) |
50 | 54 | ||
51 | { | 55 | { |
@@ -54,180 +58,29 @@ ParamGetSpeasyProxy::ParamGetSpeasyProxy(const ParamGetSpeasyProxy &pParamGetSpe | @@ -54,180 +58,29 @@ ParamGetSpeasyProxy::ParamGetSpeasyProxy(const ParamGetSpeasyProxy &pParamGetSpe | ||
54 | 58 | ||
55 | ParamGetSpeasyProxy::~ParamGetSpeasyProxy() | 59 | ParamGetSpeasyProxy::~ParamGetSpeasyProxy() |
56 | { | 60 | { |
57 | - //delete the pusher if needed | ||
58 | - // if (_pusher != NULL) | ||
59 | - // delete _pusher; | ||
60 | -} | ||
61 | - | ||
62 | -std::string ParamGetSpeasyProxy::readFile(const std::string& filename) { | ||
63 | - // Create an input file stream | ||
64 | - std::ifstream file(filename); | ||
65 | - | ||
66 | - // Check if the file stream was successfully opened | ||
67 | - if (!file.is_open()) { | ||
68 | - throw std::runtime_error("Could not open file"); | ||
69 | - } | ||
70 | - | ||
71 | - // Use a stringstream to read the entire file into a string | ||
72 | - std::stringstream buffer; | ||
73 | - buffer << file.rdbuf(); | ||
74 | - | ||
75 | - // Close the file stream | ||
76 | - file.close(); | 61 | + /*if (_pusher != NULL) { |
62 | + delete _pusher; | ||
63 | + _pusher = NULL; | ||
64 | + }*/ | ||
77 | 65 | ||
78 | - // Return the contents of the file as a string | ||
79 | - return buffer.str(); | ||
80 | -} | ||
81 | - | ||
82 | - | ||
83 | -/** | ||
84 | - * Downloads timetable file in tmp directory. | ||
85 | - */ | ||
86 | -std::string ParamGetSpeasyProxy::download(const std::string& pPath) { | ||
87 | - std::string localPath; | ||
88 | - std::string tmpPath(pPath); | ||
89 | - std::transform(tmpPath.begin(), tmpPath.end(), tmpPath.begin(), ::tolower); | ||
90 | - if (!boost::starts_with(tmpPath, "http:") | ||
91 | - && !boost::starts_with(tmpPath, "https:")) { | ||
92 | - return pPath; | ||
93 | - } | ||
94 | - // download file | ||
95 | - CURL *pCurl; | ||
96 | - CURLcode codes; | ||
97 | - const char *url = pPath.c_str(); | ||
98 | - // get tt name to create temp file as tmp_<ttdistantfilename> | ||
99 | - size_t endOfPath = pPath.find_last_of("/"); | ||
100 | - if (endOfPath == std::string::npos) { | ||
101 | - endOfPath = pPath.find_last_of("=/\\"); | ||
102 | - } | ||
103 | - std::string tmpFile = "./tmp_" + pPath.substr(endOfPath + 1); | ||
104 | - // do download | ||
105 | - pCurl = curl_easy_init(); | ||
106 | - if (pCurl) { | ||
107 | - FILE *fptr = fopen(tmpFile.c_str(), "wb"); | ||
108 | - if (fptr) { | ||
109 | - curl_easy_setopt(pCurl, CURLOPT_URL, url); | ||
110 | - curl_easy_setopt(pCurl, CURLOPT_WRITEFUNCTION, write_data); | ||
111 | - curl_easy_setopt(pCurl, CURLOPT_SSL_VERIFYPEER, false); | ||
112 | - curl_easy_setopt(pCurl, CURLOPT_SSL_VERIFYHOST, false); | ||
113 | - curl_easy_setopt(pCurl, CURLOPT_WRITEDATA, fptr); | ||
114 | - // create buffer to get potential error string | ||
115 | - std::vector<char> errBuf(1024); | ||
116 | - curl_easy_setopt(pCurl, CURLOPT_ERRORBUFFER, &errBuf[0]); | ||
117 | - codes = curl_easy_perform(pCurl); | ||
118 | - curl_easy_cleanup(pCurl); | ||
119 | - fclose(fptr); | ||
120 | - if (codes == CURLE_OK) { | ||
121 | - localPath = tmpFile; | ||
122 | - } else { | ||
123 | - | ||
124 | - std::string str(errBuf.begin(), errBuf.end()); | ||
125 | - LOG4CXX_ERROR(_logger, | ||
126 | - "Unable to download " + pPath + " : " << str );// errBuf[0]); | ||
127 | - } | ||
128 | - } else { | ||
129 | - LOG4CXX_ERROR(_logger, | ||
130 | - "Unable to download " + pPath + " : not found."); | ||
131 | - } | ||
132 | - | ||
133 | - } else { | ||
134 | - LOG4CXX_ERROR(_logger, | ||
135 | - "Unable to download " + pPath | ||
136 | - + " : cUrl cannot be initialized."); | ||
137 | - } | ||
138 | - // else, do nothing | ||
139 | - // return local file or empty string if not downloaded | ||
140 | - return localPath; | ||
141 | } | 66 | } |
142 | 67 | ||
143 | - | ||
144 | TimeStamp ParamGetSpeasyProxy::init() | 68 | TimeStamp ParamGetSpeasyProxy::init() |
145 | { | 69 | { |
146 | LOG4CXX_DEBUG(gLogger, "ParamGetSpeasyProxy::init"); | 70 | LOG4CXX_DEBUG(gLogger, "ParamGetSpeasyProxy::init"); |
147 | 71 | ||
148 | - AMDA::helpers::Properties lProperties("app.properties"); | ||
149 | - _speasyProxyUrl = lProperties["app.speasyproxy.url"]; | ||
150 | - LOG4CXX_DEBUG(gLogger, "ParamGetSpeasyProxy::init - speasy proxy URL = " << _speasyProxyUrl); | ||
151 | - | ||
152 | - // Ici, instanciation du Pusher (en fonction du type et des dim définis dans le fichier XML) | ||
153 | - | ||
154 | _currentInterval = _timeIntervalList->begin(); | 72 | _currentInterval = _timeIntervalList->begin(); |
155 | 73 | ||
156 | - // get the right container | ||
157 | - | ||
158 | - if (_dim1 * _dim2 == 1) { | ||
159 | - _container = CONTAINER_SCALAR; | ||
160 | - } | ||
161 | - else if ((_dim1 > 1) && (_dim2 > 1)) { | ||
162 | - _container = CONTAINER_MATRIX; | ||
163 | - } | ||
164 | - else { | ||
165 | - _container = CONTAINER_VECTOR; | ||
166 | - } | ||
167 | - | ||
168 | - //create pusher | ||
169 | - switch (_container) { | ||
170 | - case CONTAINER_SCALAR : | ||
171 | - switch (_type) { | ||
172 | - case TYPE_FLOAT : | ||
173 | - _pusher = new Pusher<TYPE_FLOAT, CONTAINER_SCALAR>(); | ||
174 | - break; | ||
175 | - case TYPE_DOUBLE : | ||
176 | - _pusher = new Pusher<TYPE_DOUBLE, CONTAINER_SCALAR>(); | ||
177 | - break; | ||
178 | - case TYPE_SHORT : | ||
179 | - _pusher = new Pusher<TYPE_SHORT, CONTAINER_SCALAR>(); | ||
180 | - break; | ||
181 | - case TYPE_INT : | ||
182 | - _pusher = new Pusher<TYPE_INT, CONTAINER_SCALAR>(); | ||
183 | - break; | ||
184 | - default: | ||
185 | - LOG4CXX_ERROR(gLogger, "ParamGetSpeasyProxy::init() - Unknown type" << (const char*)_type); | ||
186 | - | ||
187 | - } | ||
188 | - break; | ||
189 | - case CONTAINER_VECTOR : | ||
190 | - switch (_type) { | ||
191 | - case TYPE_FLOAT : | ||
192 | - _pusher = new Pusher<TYPE_FLOAT, CONTAINER_VECTOR>(_dim1); | ||
193 | - break; | ||
194 | - case TYPE_DOUBLE : | ||
195 | - _pusher = new Pusher<TYPE_DOUBLE, CONTAINER_VECTOR>(_dim1); | ||
196 | - break; | ||
197 | - case TYPE_SHORT : | ||
198 | - _pusher = new Pusher<TYPE_SHORT, CONTAINER_VECTOR>(_dim1); | ||
199 | - break; | ||
200 | - case TYPE_INT : | ||
201 | - _pusher = new Pusher<TYPE_INT, CONTAINER_VECTOR>(_dim1); | ||
202 | - break; | ||
203 | - default: | ||
204 | - LOG4CXX_ERROR(gLogger, "ParamGetSpeasyProxy::init() - Unknown type" << (const char*)_type); | ||
205 | - } | ||
206 | - break; | ||
207 | - case CONTAINER_MATRIX : | ||
208 | - switch (_type) { | ||
209 | - case TYPE_FLOAT : | ||
210 | - _pusher = new Pusher<TYPE_FLOAT, CONTAINER_MATRIX>(_dim1, _dim2); | ||
211 | - break; | ||
212 | - case TYPE_DOUBLE : | ||
213 | - _pusher = new Pusher<TYPE_DOUBLE, CONTAINER_MATRIX>(_dim1, _dim2); | ||
214 | - break; | ||
215 | - case TYPE_SHORT : | ||
216 | - _pusher = new Pusher<TYPE_SHORT, CONTAINER_MATRIX>(_dim1, _dim2); | ||
217 | - break; | ||
218 | - case TYPE_INT : | ||
219 | - _pusher = new Pusher<TYPE_INT, CONTAINER_MATRIX>(_dim1, _dim2); | ||
220 | - break; | ||
221 | - default: | ||
222 | - LOG4CXX_ERROR(gLogger, "ParamGetSpeasyProxy::init() - Unknown type" << (const char*)_type); | ||
223 | - } | ||
224 | - break; | ||
225 | - default: | ||
226 | - LOG4CXX_ERROR(gLogger, "ParamGetSpeasyProxy::init() - Unknown container format " << (const char*)_container); | 74 | + _proxyRequestSPtr = SpeasyProxyRequestManager::getInstance()->getSpeasyProxyRequest(_paramSpeasyId, _type, _dim1, _dim2); |
227 | 75 | ||
228 | - } | 76 | + if (_dependNumber == 0) { |
77 | + _pusher = _proxyRequestSPtr->createPusher(); | ||
78 | + } | ||
79 | + else { | ||
80 | + _pusher = _proxyRequestSPtr->createDependPusher(_dependNumber, _dependType); | ||
81 | + } | ||
229 | 82 | ||
230 | - //set link to the param data | 83 | + //set link to the param data |
231 | _paramData = ParamDataSPtr(_pusher->getParamData()); | 84 | _paramData = ParamDataSPtr(_pusher->getParamData()); |
232 | _paramData->setMinSampling(_minSampling); | 85 | _paramData->setMinSampling(_minSampling); |
233 | 86 | ||
@@ -242,43 +95,7 @@ TimeStamp ParamGetSpeasyProxy::init() | @@ -242,43 +95,7 @@ TimeStamp ParamGetSpeasyProxy::init() | ||
242 | return _timeStamp; | 95 | return _timeStamp; |
243 | } | 96 | } |
244 | 97 | ||
245 | -std::string ParamGetSpeasyProxy::getURLTime(double time){ | ||
246 | 98 | ||
247 | - std::string newTime = TimeUtil::DD2ISO_TimeDate(TimeUtil::double2DD_TimeDate(time)); | ||
248 | - std::string delim = ":"; | ||
249 | - std::string toReplaceWith = "%3A"; | ||
250 | - size_t pos = 0; | ||
251 | - | ||
252 | - while ((pos = newTime.find(delim, pos)) != std::string::npos) { | ||
253 | - newTime.replace(pos, delim.length(), toReplaceWith); | ||
254 | - pos += toReplaceWith.length(); | ||
255 | - } | ||
256 | - | ||
257 | - // delim = ".000"; | ||
258 | - // newTime.erase(newTime.find(delim),newTime.find(delim) + delim.length()); | ||
259 | - | ||
260 | - return newTime; | ||
261 | -} | ||
262 | - | ||
263 | -std::string ParamGetSpeasyProxy::getSpeasyProxyLink(){ | ||
264 | - // http://172.200.0.14:6543/get_data?path=amda%2Fc1_b_gsm&start_time=2018-10-24T00%3A00%3A00&stop_time=2018-10-24T02%3A00%3A00&format=cdf&zstd_compression=false&output_format=CDF_ISTP&pickle_proto=3 | ||
265 | - | ||
266 | - std::string path = _speasyProxyUrl + "/get_data?path="; | ||
267 | - std::string delim = "/"; | ||
268 | - std::string toReplaceWith = "%2F"; | ||
269 | - std::string paramId = _paramId; | ||
270 | - size_t pos = 0; | ||
271 | - | ||
272 | - while ((pos = paramId.find(delim, pos)) != std::string::npos) { | ||
273 | - paramId.replace(pos, delim.length(), toReplaceWith); | ||
274 | - pos += toReplaceWith.length(); | ||
275 | - } | ||
276 | - path += paramId + "&start_time=" + getURLTime(_currentInterval->_startTime); | ||
277 | - path += "&stop_time=" + getURLTime(_currentInterval->_stopTime); | ||
278 | - path += "&format=cdf&zstd_compression=false&pickle_proto=3"; | ||
279 | - | ||
280 | - return path; | ||
281 | -} | ||
282 | 99 | ||
283 | unsigned int ParamGetSpeasyProxy::write() | 100 | unsigned int ParamGetSpeasyProxy::write() |
284 | { | 101 | { |
@@ -286,84 +103,92 @@ unsigned int ParamGetSpeasyProxy::write() | @@ -286,84 +103,92 @@ unsigned int ParamGetSpeasyProxy::write() | ||
286 | 103 | ||
287 | // Getting parameter ids | 104 | // Getting parameter ids |
288 | std::string timeParamId = "time"; | 105 | std::string timeParamId = "time"; |
289 | - std::string croptedParamId = _paramId; | 106 | + std::string croptedParamId = _paramSpeasyId; |
290 | std::string delim = "/"; | 107 | std::string delim = "/"; |
291 | croptedParamId.erase(0, croptedParamId.find(delim) + delim.length()); | 108 | croptedParamId.erase(0, croptedParamId.find(delim) + delim.length()); |
292 | croptedParamId.erase(0, croptedParamId.find(delim) + delim.length()); | 109 | croptedParamId.erase(0, croptedParamId.find(delim) + delim.length()); |
293 | 110 | ||
294 | // Downloading and loading FileReader | 111 | // Downloading and loading FileReader |
295 | - std::string localPath = download(getSpeasyProxyLink()); | ||
296 | - FileReaderCDF* fileReaderPtr = new FileReaderCDF(); | ||
297 | - bool isOpen = fileReaderPtr->open(localPath); | ||
298 | - | ||
299 | - | ||
300 | - if(isOpen) | ||
301 | - { | ||
302 | - // Call to getParamPacketData to get CDF data | ||
303 | - | ||
304 | - | ||
305 | - FileReaderStatus status = FRS_ERROR; | ||
306 | - int crtIndex = 0; | ||
307 | - do { | ||
308 | - // Creation of the data packet | ||
309 | - SpeasyProxyParamDataPacket *packet= new SpeasyProxyParamDataPacket(); | ||
310 | - packet->init(_container,_type,_dim1,_dim2); | ||
311 | - status = fileReaderPtr->getParamPacketData(timeParamId, croptedParamId, crtIndex, packet); | ||
312 | - if (status == FRS_ERROR) { | 112 | + std::string cdfFilePath; |
113 | + _proxyRequestSPtr->download(_currentInterval->_startTime, _currentInterval->_stopTime, cdfFilePath); | ||
114 | + | ||
115 | + if (cdfFilePath.empty()) { | ||
116 | + _paramData->getTimeList().push_back(_currentInterval->_startTime); | ||
117 | + _pusher->putNaN(); | ||
118 | + _paramData->getTimeList().push_back(_currentInterval->_stopTime); | ||
119 | + _pusher->putNaN(); | ||
120 | + result += 2; | ||
121 | + } | ||
122 | + else | ||
123 | + { | ||
124 | + FileReaderCDF* fileReaderPtr = new FileReaderCDF(); | ||
125 | + bool isOpen = fileReaderPtr->open(cdfFilePath); | ||
126 | + | ||
127 | + if(isOpen) | ||
128 | + { | ||
129 | + // Call to getParamPacketData to get CDF data | ||
130 | + | ||
131 | + | ||
132 | + FileReaderStatus status = FRS_ERROR; | ||
133 | + int crtIndex = 0; | ||
134 | + do { | ||
135 | + // Creation of the data packet | ||
136 | + SpeasyProxyParamDataPacket *packet= new SpeasyProxyParamDataPacket(); | ||
137 | + packet->init(_pusher->getContainer(), _pusher->getType(), _pusher->getDim1(), | ||
138 | + _pusher->getDim2()); | ||
139 | + status = fileReaderPtr->getParamPacketData(timeParamId, croptedParamId, crtIndex, _dependNumber, packet); | ||
140 | + if (status == FRS_ERROR) { | ||
141 | + delete packet; | ||
142 | + remove(cdfFilePath.c_str()); | ||
143 | + BOOST_THROW_EXCEPTION(AMDA::AMDA_exception() << AMDA::ex_msg("Error to get data from speasy")); | ||
144 | + } | ||
145 | + if (packet->getNbData() == 0) { | ||
146 | + LOG4CXX_DEBUG(gLogger, "ParamGetLocalFile::write => no data packet"); | ||
147 | + _paramData->getTimeList().push_back(_currentInterval->_startTime); | ||
148 | + _pusher->putNaN(); | ||
149 | + _paramData->getTimeList().push_back(_currentInterval->_stopTime); | ||
150 | + _pusher->putNaN(); | ||
151 | + result += 2; | ||
152 | + } | ||
153 | + else { | ||
154 | + LOG4CXX_DEBUG(gLogger, "ParamGetLocalFile::write => nb data in packet: " << packet->getNbData()); | ||
155 | + crtIndex += packet->getNbData(); | ||
156 | + result += _pusher->put(packet); | ||
157 | + } | ||
313 | delete packet; | 158 | delete packet; |
314 | - remove(localPath.c_str()); | ||
315 | - BOOST_THROW_EXCEPTION(AMDA::AMDA_exception() << AMDA::ex_msg("Error to get data from speasy")); | ||
316 | - } | ||
317 | - if (packet->getNbData() == 0) { | ||
318 | - LOG4CXX_DEBUG(gLogger, "ParamGetLocalFile::write => no data packet"); | ||
319 | - _paramData->getTimeList().push_back(_currentInterval->_startTime); | ||
320 | - _pusher->putNaN(); | ||
321 | - _paramData->getTimeList().push_back(_currentInterval->_stopTime); | ||
322 | - _pusher->putNaN(); | ||
323 | - result += 2; | ||
324 | - } | ||
325 | - else { | ||
326 | - LOG4CXX_DEBUG(gLogger, "ParamGetLocalFile::write => nb data in packet: " << packet->getNbData()); | ||
327 | - crtIndex += packet->getNbData(); | ||
328 | - result += _pusher->put(packet); | ||
329 | - } | ||
330 | - delete packet; | ||
331 | - //remove(localPath.c_str()); | ||
332 | - } while (status == FRS_MORE); | ||
333 | - | ||
334 | - | ||
335 | - | ||
336 | - // Push up the information if all time interval was processed. | ||
337 | - _paramData->getIndexInfo()._timeIntToProcessChanged = true; // ATTENTION - valeur forcée pour les tests!!!!! | ||
338 | - if (true) { | ||
339 | - ++_currentInterval; | ||
340 | - _paramData->getIndexInfo()._noMoreTimeInt = (_currentInterval == _timeIntervalList->end()); | ||
341 | - } | ||
342 | - | ||
343 | - _paramData->getIndexInfo()._nbDataToProcess = result; | ||
344 | - | ||
345 | - // if time interval changed store index which delimit the end of the time interval. | ||
346 | - if (_paramData->getIndexInfo()._timeIntToProcessChanged) { | ||
347 | - unsigned int lEndTimeIntIndex = _paramData->getIndexInfo()._nbDataToProcess; | ||
348 | - _paramData->getIndexInfo()._endTimeIntIndexList.push_back(lEndTimeIntIndex); | ||
349 | - } | ||
350 | - else { | ||
351 | - // Nothing to do. | ||
352 | - } | ||
353 | - return result; | ||
354 | - } | ||
355 | - else { | ||
356 | - if (boost::filesystem::exists(localPath)) | ||
357 | - remove(localPath.c_str()); | ||
358 | - BOOST_THROW_EXCEPTION(AMDA::AMDA_exception() << AMDA::ex_msg("Error to get data from speasy")); | 159 | + |
160 | + } while (status == FRS_MORE); | ||
161 | + | ||
162 | + //close the file | ||
163 | + if (!fileReaderPtr->close()) | ||
164 | + { | ||
165 | + LOG4CXX_ERROR(gLogger, "ParamGetSpeasy::init - Cannot close file " << cdfFilePath); | ||
166 | + } | ||
167 | + remove(cdfFilePath.c_str()); | ||
168 | + } | ||
169 | + else { | ||
170 | + remove(cdfFilePath.c_str()); | ||
171 | + BOOST_THROW_EXCEPTION(AMDA::AMDA_exception() << AMDA::ex_msg("Error to load CDF data from speasy")); | ||
172 | + } | ||
359 | } | 173 | } |
360 | - | ||
361 | - //close the file | ||
362 | - if (!fileReaderPtr->close()) | ||
363 | - { | ||
364 | - LOG4CXX_ERROR(gLogger, "ParamGetSpeasy::init - Cannot close file " << localPath); | 174 | + |
175 | + // Push up the information if all time interval was processed. | ||
176 | + _paramData->getIndexInfo()._timeIntToProcessChanged = true; // ATTENTION - valeur forcée pour les tests!!!!! | ||
177 | + if (true) { | ||
178 | + ++_currentInterval; | ||
179 | + _paramData->getIndexInfo()._noMoreTimeInt = (_currentInterval == _timeIntervalList->end()); | ||
365 | } | 180 | } |
366 | 181 | ||
182 | + _paramData->getIndexInfo()._nbDataToProcess = result; | ||
183 | + | ||
184 | + // if time interval changed store index which delimit the end of the time interval. | ||
185 | + if (_paramData->getIndexInfo()._timeIntToProcessChanged) { | ||
186 | + unsigned int lEndTimeIntIndex = _paramData->getIndexInfo()._nbDataToProcess; | ||
187 | + _paramData->getIndexInfo()._endTimeIntIndexList.push_back(lEndTimeIntIndex); | ||
188 | + } | ||
189 | + else { | ||
190 | + // Nothing to do. | ||
191 | + } | ||
367 | return result; | 192 | return result; |
368 | } | 193 | } |
369 | 194 | ||
@@ -375,6 +200,7 @@ void ParamGetSpeasyProxy::updateInfo(Parameter & parameter) | @@ -375,6 +200,7 @@ void ParamGetSpeasyProxy::updateInfo(Parameter & parameter) | ||
375 | 200 | ||
376 | //Param info | 201 | //Param info |
377 | AMDA::Info::ParamInfoSPtr paramInfo = AMDA::Info::ParamMgr::getInstance()->getParamInfoFromId(parameter.getInfoId(),true); | 202 | AMDA::Info::ParamInfoSPtr paramInfo = AMDA::Info::ParamMgr::getInstance()->getParamInfoFromId(parameter.getInfoId(),true); |
203 | + | ||
378 | 204 | ||
379 | if (paramInfo == nullptr) | 205 | if (paramInfo == nullptr) |
380 | return; | 206 | return; |
@@ -382,11 +208,6 @@ void ParamGetSpeasyProxy::updateInfo(Parameter & parameter) | @@ -382,11 +208,6 @@ void ParamGetSpeasyProxy::updateInfo(Parameter & parameter) | ||
382 | _pusher->setFillValue(paramInfo->getFillValue()); | 208 | _pusher->setFillValue(paramInfo->getFillValue()); |
383 | } | 209 | } |
384 | 210 | ||
385 | -size_t write_data(void *ptr, size_t size, size_t nmemb, FILE *stream) { | ||
386 | - size_t written; | ||
387 | - written = fwrite(ptr, size, nmemb, stream); | ||
388 | - return written; | ||
389 | -} | ||
390 | 211 | ||
391 | 212 | ||
392 | } /* namespace SpeasyProxyInterface */ | 213 | } /* namespace SpeasyProxyInterface */ |
src/ParamGetImpl/SpeasyProxyInterface/ParamGetSpeasyProxy.hh
@@ -14,6 +14,8 @@ | @@ -14,6 +14,8 @@ | ||
14 | #include "ParamGet.hh" | 14 | #include "ParamGet.hh" |
15 | #include "TimeStamp.hh" | 15 | #include "TimeStamp.hh" |
16 | #include "Pusher.hh" | 16 | #include "Pusher.hh" |
17 | +#include "SpeasyProxyRequest.hh" | ||
18 | + | ||
17 | 19 | ||
18 | using namespace AMDA::Parameters; | 20 | using namespace AMDA::Parameters; |
19 | 21 | ||
@@ -47,17 +49,17 @@ public: | @@ -47,17 +49,17 @@ public: | ||
47 | /* | 49 | /* |
48 | * @brief Get param id in speasy xml | 50 | * @brief Get param id in speasy xml |
49 | */ | 51 | */ |
50 | - const std::string& getParamId() const | 52 | + const std::string& getParamSpeasyId() const |
51 | { | 53 | { |
52 | - return _paramId; | 54 | + return _paramSpeasyId; |
53 | } | 55 | } |
54 | 56 | ||
55 | /* | 57 | /* |
56 | * @brief Set param id in speasy xml | 58 | * @brief Set param id in speasy xml |
57 | */ | 59 | */ |
58 | - void setParamId(const char* paramId) | 60 | + void setParamSpeasyId(const char* paramSpeasyId) |
59 | { | 61 | { |
60 | - _paramId = paramId; | 62 | + _paramSpeasyId = paramSpeasyId; |
61 | } | 63 | } |
62 | 64 | ||
63 | /** | 65 | /** |
@@ -113,6 +115,11 @@ public: | @@ -113,6 +115,11 @@ public: | ||
113 | _dim2 = size; | 115 | _dim2 = size; |
114 | } | 116 | } |
115 | 117 | ||
118 | + void setDepend(int dependNumber, SpeasyProxyParamType dependType) { | ||
119 | + _dependNumber = dependNumber; | ||
120 | + _dependType = dependType; | ||
121 | + } | ||
122 | + | ||
116 | /* | 123 | /* |
117 | * @brief Get param min sampling in speasy xml | 124 | * @brief Get param min sampling in speasy xml |
118 | */ | 125 | */ |
@@ -162,40 +169,33 @@ public: | @@ -162,40 +169,33 @@ public: | ||
162 | virtual void updateInfo(Parameter & parameter); | 169 | virtual void updateInfo(Parameter & parameter); |
163 | 170 | ||
164 | protected: | 171 | protected: |
165 | - | ||
166 | - std::string readFile(const std::string& filename); | ||
167 | - | ||
168 | - | ||
169 | - std::string download(const std::string& pPath); | ||
170 | - | ||
171 | /* | 172 | /* |
172 | - * @brief Speasy proxy entry point | 173 | + * @brief Speasy Param Id |
173 | */ | 174 | */ |
174 | - std::string _speasyProxyUrl; | 175 | + std::string _paramSpeasyId; |
175 | 176 | ||
176 | /* | 177 | /* |
177 | - * @brief Local Param Id | ||
178 | - */ | ||
179 | - std::string _paramId; | ||
180 | - | ||
181 | - /* | ||
182 | - * @brief Local Param type | 178 | + * @brief Speasy Param type |
183 | */ | 179 | */ |
184 | 180 | ||
185 | SpeasyProxyParamType _type; | 181 | SpeasyProxyParamType _type; |
186 | 182 | ||
187 | /* | 183 | /* |
188 | - * @brief Local Param dim1 size | 184 | + * @brief Speasy Param dim1 size |
189 | */ | 185 | */ |
190 | int _dim1; | 186 | int _dim1; |
191 | 187 | ||
192 | /* | 188 | /* |
193 | - * @brief Local Param dim2 size | 189 | + * @brief Speasy Param dim2 size |
194 | */ | 190 | */ |
195 | int _dim2; | 191 | int _dim2; |
196 | 192 | ||
193 | + int _dependNumber; | ||
194 | + | ||
195 | + SpeasyProxyParamType _dependType; | ||
196 | + | ||
197 | /* | 197 | /* |
198 | - * @brief Local Param min sampling | 198 | + * @brief Speasy Param min sampling |
199 | */ | 199 | */ |
200 | double _minSampling; | 200 | double _minSampling; |
201 | 201 | ||
@@ -204,8 +204,6 @@ protected: | @@ -204,8 +204,6 @@ protected: | ||
204 | // */ | 204 | // */ |
205 | // double _maxSampling; | 205 | // double _maxSampling; |
206 | 206 | ||
207 | - | ||
208 | - SpeasyProxyContainerType _container; | ||
209 | 207 | ||
210 | /* | 208 | /* |
211 | * @brief Time of xml file or 0 | 209 | * @brief Time of xml file or 0 |
@@ -219,10 +217,11 @@ protected: | @@ -219,10 +217,11 @@ protected: | ||
219 | */ | 217 | */ |
220 | PusherBase *_pusher; | 218 | PusherBase *_pusher; |
221 | 219 | ||
220 | + SpeasyProxyRequestSPtr _proxyRequestSPtr; | ||
221 | + | ||
222 | }; | 222 | }; |
223 | 223 | ||
224 | typedef boost::shared_ptr<ParamGetSpeasyProxy> ParamGetSpeasyProxySPtr; | 224 | typedef boost::shared_ptr<ParamGetSpeasyProxy> ParamGetSpeasyProxySPtr; |
225 | -size_t write_data(void *ptr, size_t size, size_t nmemb, FILE *stream); | ||
226 | 225 | ||
227 | } /* namespace SpeasyProxyInterface */ | 226 | } /* namespace SpeasyProxyInterface */ |
228 | } /* namespace AMDA */ | 227 | } /* namespace AMDA */ |
src/ParamGetImpl/SpeasyProxyInterface/Pusher.hh
@@ -29,7 +29,10 @@ public: | @@ -29,7 +29,10 @@ public: | ||
29 | /* | 29 | /* |
30 | * @brief Constructor | 30 | * @brief Constructor |
31 | */ | 31 | */ |
32 | - PusherBase (int dim1 = 1, int dim2 = 1) : _paramData(NULL), _dim1(dim1), _dim2(dim2), _fillValue(NAN) | 32 | + PusherBase (int dim1, int dim2, SpeasyProxyContainerType container, |
33 | + SpeasyProxyParamType type) : | ||
34 | + _paramData(NULL), _dim1(dim1), _dim2(dim2), | ||
35 | + _fillValue(NAN), _container(container), _type(type) | ||
33 | { | 36 | { |
34 | } | 37 | } |
35 | 38 | ||
@@ -48,6 +51,23 @@ public: | @@ -48,6 +51,23 @@ public: | ||
48 | return _paramData; | 51 | return _paramData; |
49 | } | 52 | } |
50 | 53 | ||
54 | + SpeasyProxyContainerType getContainer(void) | ||
55 | + { | ||
56 | + return _container; | ||
57 | + } | ||
58 | + | ||
59 | + int getDim1() { | ||
60 | + return _dim1; | ||
61 | + } | ||
62 | + | ||
63 | + int getDim2() { | ||
64 | + return _dim2; | ||
65 | + } | ||
66 | + | ||
67 | + SpeasyProxyParamType getType() { | ||
68 | + return _type; | ||
69 | + } | ||
70 | + | ||
51 | void setFillValue(double fillValue) { | 71 | void setFillValue(double fillValue) { |
52 | _fillValue = fillValue; | 72 | _fillValue = fillValue; |
53 | } | 73 | } |
@@ -87,6 +107,10 @@ protected: | @@ -87,6 +107,10 @@ protected: | ||
87 | * @brief Fill value | 107 | * @brief Fill value |
88 | */ | 108 | */ |
89 | double _fillValue; | 109 | double _fillValue; |
110 | + | ||
111 | + SpeasyProxyContainerType _container; | ||
112 | + | ||
113 | + SpeasyProxyParamType _type; | ||
90 | }; | 114 | }; |
91 | 115 | ||
92 | 116 | ||
@@ -121,7 +145,7 @@ public: | @@ -121,7 +145,7 @@ public: | ||
121 | /* | 145 | /* |
122 | * @brief Constructor | 146 | * @brief Constructor |
123 | */ | 147 | */ |
124 | - Pusher(int dim1, int dim2) : PusherBase( dim1, dim2) | 148 | + Pusher(int dim1, int dim2) : PusherBase( dim1, dim2, CONTAINER_MATRIX, type) |
125 | { | 149 | { |
126 | _paramData = _specParamData = createParamData(); | 150 | _paramData = _specParamData = createParamData(); |
127 | // _nbDataByPacket = getNbDataByPacket(type, dim1, dim2); | 151 | // _nbDataByPacket = getNbDataByPacket(type, dim1, dim2); |
@@ -212,7 +236,7 @@ public: | @@ -212,7 +236,7 @@ public: | ||
212 | /* | 236 | /* |
213 | * @brief Constructor | 237 | * @brief Constructor |
214 | */ | 238 | */ |
215 | - Pusher(int dim) : PusherBase(dim) | 239 | + Pusher(int dim) : PusherBase(dim, 1, CONTAINER_VECTOR, type) |
216 | { | 240 | { |
217 | _paramData = _specParamData = createParamData(); | 241 | _paramData = _specParamData = createParamData(); |
218 | // _nbDataByPacket = getNbDataByPacket(type, dim, 1); | 242 | // _nbDataByPacket = getNbDataByPacket(type, dim, 1); |
@@ -294,7 +318,7 @@ public: | @@ -294,7 +318,7 @@ public: | ||
294 | /* | 318 | /* |
295 | * @brief Constructor | 319 | * @brief Constructor |
296 | */ | 320 | */ |
297 | - Pusher() : PusherBase() | 321 | + Pusher() : PusherBase(1, 1, CONTAINER_SCALAR, type) |
298 | { | 322 | { |
299 | _paramData = _specParamData = createParamData(); | 323 | _paramData = _specParamData = createParamData(); |
300 | // _nbDataByPacket = getNbDataByPacket(type, 1, 1); | 324 | // _nbDataByPacket = getNbDataByPacket(type, 1, 1); |
src/ParamGetImpl/SpeasyProxyInterface/SpeasyProxyParamData.cc
0 → 100644
@@ -0,0 +1,29 @@ | @@ -0,0 +1,29 @@ | ||
1 | +/* | ||
2 | + * SpeasyProxyParamData.cc | ||
3 | + * | ||
4 | + * Created on: Dec 11, 2024 | ||
5 | + * Author: AKKA | ||
6 | + */ | ||
7 | + | ||
8 | + | ||
9 | +#include "SpeasyProxyParamData.hh" | ||
10 | + | ||
11 | + | ||
12 | +namespace AMDA { | ||
13 | +namespace SpeasyProxyInterface { | ||
14 | + | ||
15 | +SpeasyProxyParamType stringToParamType(std::string& type) { | ||
16 | + if (strcmp(type.c_str(),"float") == 0) | ||
17 | + return AMDA::SpeasyProxyInterface::SpeasyProxyParamType::TYPE_FLOAT; | ||
18 | + else if (strcmp(type.c_str(),"double") == 0) | ||
19 | + return AMDA::SpeasyProxyInterface::SpeasyProxyParamType::TYPE_DOUBLE; | ||
20 | + else if (strcmp(type.c_str(),"short") == 0) | ||
21 | + return AMDA::SpeasyProxyInterface::SpeasyProxyParamType::TYPE_SHORT; | ||
22 | + else if ((strcmp(type.c_str(),"int") == 0) || (strcmp(type.c_str(),"integer") == 0)) | ||
23 | + return AMDA::SpeasyProxyInterface::SpeasyProxyParamType::TYPE_INT; | ||
24 | + return AMDA::SpeasyProxyInterface::SpeasyProxyParamType::TYPE_UNKNOWN; | ||
25 | +} | ||
26 | + | ||
27 | +} /* SpeasyProxyInterface */ | ||
28 | +} /* AMDA */ | ||
29 | + |
src/ParamGetImpl/SpeasyProxyInterface/SpeasyProxyParamData.hh
@@ -473,6 +473,8 @@ private: | @@ -473,6 +473,8 @@ private: | ||
473 | double _stopTime; | 473 | double _stopTime; |
474 | }; | 474 | }; |
475 | 475 | ||
476 | +SpeasyProxyParamType stringToParamType(std::string& type); | ||
477 | + | ||
476 | } /* SpeasyProxyInterface */ | 478 | } /* SpeasyProxyInterface */ |
477 | } /* AMDA */ | 479 | } /* AMDA */ |
478 | 480 |
src/ParamGetImpl/SpeasyProxyInterface/SpeasyProxyRequest.cc
0 → 100644
@@ -0,0 +1,215 @@ | @@ -0,0 +1,215 @@ | ||
1 | +/* | ||
2 | + * SpeasyProxyRequest.cc | ||
3 | + * | ||
4 | + * Created on: Dec 9, 2024 | ||
5 | + * Author: AKKA | ||
6 | + */ | ||
7 | + | ||
8 | +#include "SpeasyProxyRequest.hh" | ||
9 | +#include "SpeasyProxyRequestManager.hh" | ||
10 | + | ||
11 | +#include "TimeUtil.hh" | ||
12 | + | ||
13 | +#include <iostream> | ||
14 | +#include <sstream> | ||
15 | +#include <boost/filesystem.hpp> | ||
16 | + | ||
17 | +#define CURL_STATICLIB | ||
18 | +#include <curl/curl.h> | ||
19 | +#include <curl/easy.h> | ||
20 | + | ||
21 | +namespace AMDA { | ||
22 | +namespace SpeasyProxyInterface { | ||
23 | + | ||
24 | +size_t write_data(void *ptr, size_t size, size_t nmemb, FILE *stream) { | ||
25 | + size_t written; | ||
26 | + written = fwrite(ptr, size, nmemb, stream); | ||
27 | + return written; | ||
28 | +} | ||
29 | + | ||
30 | + | ||
31 | +SpeasyProxyRequest::SpeasyProxyRequest(const std::string& pSpeasyRequestId, SpeasyProxyParamType& paramType, int& dim1Size, int& dim2Size): | ||
32 | + _speasyRequestId(pSpeasyRequestId), _type(paramType), _dim1(dim1Size), _dim2(dim2Size), | ||
33 | + _container(SpeasyProxyContainerType::CONTAINER_SCALAR) { | ||
34 | + if (_dim1 * _dim2 == 1) { | ||
35 | + _container = CONTAINER_SCALAR; | ||
36 | + } | ||
37 | + else if ((_dim1 > 1) && (_dim2 > 1)) { | ||
38 | + _container = CONTAINER_MATRIX; | ||
39 | + } | ||
40 | + else { | ||
41 | + _container = CONTAINER_VECTOR; | ||
42 | + } | ||
43 | +} | ||
44 | + | ||
45 | +SpeasyProxyRequest::~SpeasyProxyRequest(void) { | ||
46 | +} | ||
47 | + | ||
48 | +PusherBase* SpeasyProxyRequest::createPusher(void) { | ||
49 | + //create pusher | ||
50 | + switch (_container) { | ||
51 | + case CONTAINER_SCALAR : | ||
52 | + switch (_type) { | ||
53 | + case TYPE_FLOAT : | ||
54 | + return new Pusher<TYPE_FLOAT, CONTAINER_SCALAR>(); | ||
55 | + case TYPE_DOUBLE : | ||
56 | + return new Pusher<TYPE_DOUBLE, CONTAINER_SCALAR>(); | ||
57 | + case TYPE_SHORT : | ||
58 | + return new Pusher<TYPE_SHORT, CONTAINER_SCALAR>(); | ||
59 | + case TYPE_INT : | ||
60 | + return new Pusher<TYPE_INT, CONTAINER_SCALAR>(); | ||
61 | + default: | ||
62 | + LOG4CXX_ERROR(gLogger, "SpeasyProxyRequest::createPusher - Unknown type" << (const char*)_type); | ||
63 | + | ||
64 | + } | ||
65 | + break; | ||
66 | + case CONTAINER_VECTOR : | ||
67 | + switch (_type) { | ||
68 | + case TYPE_FLOAT : | ||
69 | + return new Pusher<TYPE_FLOAT, CONTAINER_VECTOR>(_dim1); | ||
70 | + case TYPE_DOUBLE : | ||
71 | + return new Pusher<TYPE_DOUBLE, CONTAINER_VECTOR>(_dim1); | ||
72 | + case TYPE_SHORT : | ||
73 | + return new Pusher<TYPE_SHORT, CONTAINER_VECTOR>(_dim1); | ||
74 | + case TYPE_INT : | ||
75 | + return new Pusher<TYPE_INT, CONTAINER_VECTOR>(_dim1); | ||
76 | + default: | ||
77 | + LOG4CXX_ERROR(gLogger, "SpeasyProxyRequest::createPusher - Unknown type" << (const char*)_type); | ||
78 | + } | ||
79 | + break; | ||
80 | + case CONTAINER_MATRIX : | ||
81 | + switch (_type) { | ||
82 | + case TYPE_FLOAT : | ||
83 | + return new Pusher<TYPE_FLOAT, CONTAINER_MATRIX>(_dim1, _dim2); | ||
84 | + case TYPE_DOUBLE : | ||
85 | + return new Pusher<TYPE_DOUBLE, CONTAINER_MATRIX>(_dim1, _dim2); | ||
86 | + case TYPE_SHORT : | ||
87 | + return new Pusher<TYPE_SHORT, CONTAINER_MATRIX>(_dim1, _dim2); | ||
88 | + case TYPE_INT : | ||
89 | + return new Pusher<TYPE_INT, CONTAINER_MATRIX>(_dim1, _dim2); | ||
90 | + default: | ||
91 | + LOG4CXX_ERROR(gLogger, "SpeasyProxyRequest::createPusher - Unknown type" << (const char*)_type); | ||
92 | + } | ||
93 | + break; | ||
94 | + default: | ||
95 | + LOG4CXX_ERROR(gLogger, "SpeasyProxyRequest::createPusher - Unknown container format " << (const char*)_container); | ||
96 | + | ||
97 | + } | ||
98 | + return NULL; | ||
99 | +} | ||
100 | + | ||
101 | +PusherBase* SpeasyProxyRequest::createDependPusher(int dependNumber, SpeasyProxyParamType dependType) { | ||
102 | + int dimSize = 0; | ||
103 | + if (dependNumber == 1) { | ||
104 | + dimSize = _dim1; | ||
105 | + } | ||
106 | + else if (dependNumber == 2) { | ||
107 | + dimSize = _dim2; | ||
108 | + } | ||
109 | + else { | ||
110 | + LOG4CXX_ERROR(gLogger, "SpeasyProxyRequest::createDependPusher - Depend number not supported: " << dependNumber); | ||
111 | + return NULL; | ||
112 | + } | ||
113 | + | ||
114 | + switch (dependType) { | ||
115 | + case TYPE_FLOAT : | ||
116 | + return new Pusher<TYPE_FLOAT, CONTAINER_VECTOR>(dimSize); | ||
117 | + case TYPE_DOUBLE : | ||
118 | + return new Pusher<TYPE_DOUBLE, CONTAINER_VECTOR>(dimSize); | ||
119 | + case TYPE_SHORT : | ||
120 | + return new Pusher<TYPE_SHORT, CONTAINER_VECTOR>(dimSize); | ||
121 | + case TYPE_INT : | ||
122 | + return new Pusher<TYPE_INT, CONTAINER_VECTOR>(dimSize); | ||
123 | + default: | ||
124 | + LOG4CXX_ERROR(gLogger, "SpeasyProxyRequest::createDependPusher - Unknown type" << (const char*)_type); | ||
125 | + } | ||
126 | + return NULL; | ||
127 | +} | ||
128 | + | ||
129 | +std::string SpeasyProxyRequest::getSpeasyProxyLink(double startTime, double stopTime){ | ||
130 | + CURL *pCurl; | ||
131 | + pCurl = curl_easy_init(); | ||
132 | + char *escapedSpeasyRequestId = curl_easy_escape(pCurl, _speasyRequestId.c_str(), 0); | ||
133 | + std::string path = SpeasyProxyRequestManager::getInstance()->getSpeasyProxyUrl() + "/get_data?path="; | ||
134 | + path += std::string(escapedSpeasyRequestId) + "&start_time=" + TimeUtil::formatTimeDateInIso(startTime); | ||
135 | + path += "&stop_time=" + TimeUtil::formatTimeDateInIso(stopTime); | ||
136 | + path += "&format=cdf&zstd_compression=false&pickle_proto=3"; | ||
137 | + curl_free(escapedSpeasyRequestId); | ||
138 | + curl_easy_cleanup(pCurl); | ||
139 | + return path; | ||
140 | +} | ||
141 | + | ||
142 | +/** | ||
143 | + * Downloads timetable file in tmp directory. | ||
144 | + */ | ||
145 | +bool SpeasyProxyRequest::download(double startTime, double stopTime, std::string& outputFilePath) { | ||
146 | + | ||
147 | + | ||
148 | + outputFilePath = ""; | ||
149 | + std::string requestUrl = this->getSpeasyProxyLink(startTime, stopTime); | ||
150 | + // download file | ||
151 | + boost::hash<std::string> string_hash; | ||
152 | + std::stringstream lTmpFile; | ||
153 | + std::stringstream lBuffer; | ||
154 | + lBuffer << requestUrl; | ||
155 | + lTmpFile << "./speasy_proxy_tmp__" << string_hash(lBuffer.str()); | ||
156 | + std::string tmpFile = lTmpFile.str(); | ||
157 | + | ||
158 | + // do download | ||
159 | + FILE *fptr = fopen(tmpFile.c_str(), "wb"); | ||
160 | + if (fptr) { | ||
161 | + CURL *pCurl; | ||
162 | + CURLcode codes; | ||
163 | + pCurl = curl_easy_init(); | ||
164 | + if (pCurl) { | ||
165 | + curl_easy_setopt(pCurl, CURLOPT_URL, requestUrl.c_str()); | ||
166 | + curl_easy_setopt(pCurl, CURLOPT_WRITEFUNCTION, write_data); | ||
167 | + curl_easy_setopt(pCurl, CURLOPT_SSL_VERIFYPEER, false); | ||
168 | + curl_easy_setopt(pCurl, CURLOPT_SSL_VERIFYHOST, false); | ||
169 | + curl_easy_setopt(pCurl, CURLOPT_WRITEDATA, fptr); | ||
170 | + // create buffer to get potential error string | ||
171 | + std::vector<char> errBuf(1024); | ||
172 | + curl_easy_setopt(pCurl, CURLOPT_ERRORBUFFER, &errBuf[0]); | ||
173 | + codes = curl_easy_perform(pCurl); | ||
174 | + bool isCDF = false; | ||
175 | + if (codes == CURLE_OK) { | ||
176 | + char *contentType = NULL; | ||
177 | + CURLcode c = curl_easy_getinfo(pCurl, CURLINFO_CONTENT_TYPE, &contentType); | ||
178 | + isCDF = (c == CURLE_OK) && (strcmp(contentType, "application/x-cdf") == 0); | ||
179 | + } | ||
180 | + curl_easy_cleanup(pCurl); | ||
181 | + fclose(fptr); | ||
182 | + | ||
183 | + if (codes != CURLE_OK) { | ||
184 | + if (boost::filesystem::exists(tmpFile)) | ||
185 | + remove(tmpFile.c_str()); | ||
186 | + std::string str(errBuf.begin(), errBuf.end()); | ||
187 | + LOG4CXX_ERROR(gLogger, "SpeasyProxyRequest::download: Unable to download " << requestUrl << " : " << str ); | ||
188 | + return false; | ||
189 | + } | ||
190 | + else if (!isCDF) { | ||
191 | + LOG4CXX_DEBUG(gLogger, "SpeasyProxyRequest::download: Result is not a CDF file"); | ||
192 | + if (boost::filesystem::exists(tmpFile)) | ||
193 | + remove(tmpFile.c_str()); | ||
194 | + } | ||
195 | + else { | ||
196 | + outputFilePath = tmpFile; | ||
197 | + } | ||
198 | + } else { | ||
199 | + LOG4CXX_ERROR(gLogger, "SpeasyProxyRequest::download: Unable to download " << requestUrl << " : cUrl cannot be initialized."); | ||
200 | + fclose(fptr); | ||
201 | + if (boost::filesystem::exists(tmpFile)) | ||
202 | + remove(tmpFile.c_str()); | ||
203 | + return false; | ||
204 | + } | ||
205 | + } else { | ||
206 | + LOG4CXX_ERROR(gLogger, "SpeasyProxyRequest::download: Cannot write temporary file " << tmpFile); | ||
207 | + } | ||
208 | + return true; | ||
209 | +} | ||
210 | + | ||
211 | + | ||
212 | + | ||
213 | +} /* namespace SpeasyProxyInterface */ | ||
214 | +} /* namespace AMDA */ | ||
215 | + |
src/ParamGetImpl/SpeasyProxyInterface/SpeasyProxyRequest.hh
0 → 100644
@@ -0,0 +1,73 @@ | @@ -0,0 +1,73 @@ | ||
1 | +/* | ||
2 | + * SpeasyProxyRequest.hh | ||
3 | + * | ||
4 | + * Created on: Dec 9, 2024 | ||
5 | + * Author: AKKA | ||
6 | + */ | ||
7 | + | ||
8 | +#ifndef SPEASYPROXYREQUEST_HH_ | ||
9 | +#define SPEASYPROXYREQUEST_HH_ | ||
10 | + | ||
11 | +#include <string> | ||
12 | + | ||
13 | +#include <boost/shared_ptr.hpp> | ||
14 | +#include <boost/weak_ptr.hpp> | ||
15 | + | ||
16 | +#include "Pusher.hh" | ||
17 | +#include "SpeasyProxyParamData.hh" | ||
18 | + | ||
19 | + | ||
20 | +namespace AMDA { | ||
21 | +namespace SpeasyProxyInterface { | ||
22 | + | ||
23 | +class SpeasyProxyRequest{ | ||
24 | +public: | ||
25 | + SpeasyProxyRequest(const std::string& pSpeasyRequestId, SpeasyProxyParamType& paramType, int& dim1Size, int& dim2Size); | ||
26 | + | ||
27 | + ~SpeasyProxyRequest(void); | ||
28 | + | ||
29 | + /* | ||
30 | + * @brief Create pusher associated to the paramId | ||
31 | + */ | ||
32 | + PusherBase* createPusher(); | ||
33 | + | ||
34 | + PusherBase* createDependPusher(int dependNumber, SpeasyProxyParamType dependType); | ||
35 | + | ||
36 | + bool download(double startTime, double stopTime, std::string& outputFilePath); | ||
37 | + | ||
38 | + | ||
39 | +private: | ||
40 | + std::string getSpeasyProxyLink(double startTime, double stopTime); | ||
41 | + | ||
42 | + | ||
43 | + | ||
44 | + std::string _speasyRequestId; | ||
45 | + | ||
46 | + | ||
47 | + /* | ||
48 | + * @brief Local Param type | ||
49 | + */ | ||
50 | + | ||
51 | + SpeasyProxyParamType _type; | ||
52 | + | ||
53 | + /* | ||
54 | + * @brief Local Param dim1 size | ||
55 | + */ | ||
56 | + int _dim1; | ||
57 | + | ||
58 | + /* | ||
59 | + * @brief Local Param dim2 size | ||
60 | + */ | ||
61 | + int _dim2; | ||
62 | + | ||
63 | + SpeasyProxyContainerType _container; | ||
64 | +}; | ||
65 | + | ||
66 | +typedef boost::weak_ptr<SpeasyProxyRequest> SpeasyProxyRequestWPtr; | ||
67 | + | ||
68 | +typedef boost::shared_ptr<SpeasyProxyRequest> SpeasyProxyRequestSPtr; | ||
69 | + | ||
70 | +} /* namespace SpeasyProxyInterface */ | ||
71 | +} /* namespace AMDA */ | ||
72 | + | ||
73 | +#endif /* SPEASYPROXYREQUEST_HH_ */ | ||
0 | \ No newline at end of file | 74 | \ No newline at end of file |
src/ParamGetImpl/SpeasyProxyInterface/SpeasyProxyRequestManager.cc
0 → 100644
@@ -0,0 +1,48 @@ | @@ -0,0 +1,48 @@ | ||
1 | +/* | ||
2 | + * SpeasyProxyRequestManager.cc | ||
3 | + * | ||
4 | + * Created on: Dec 9, 2024 | ||
5 | + * Author: AKKA | ||
6 | + */ | ||
7 | + | ||
8 | +#include "SpeasyProxyRequestManager.hh" | ||
9 | + | ||
10 | +#include "Properties.hh" | ||
11 | + | ||
12 | + | ||
13 | +namespace AMDA { | ||
14 | +namespace SpeasyProxyInterface { | ||
15 | + | ||
16 | +SpeasyProxyRequestManager::SpeasyProxyRequestManager() { | ||
17 | + AMDA::helpers::Properties lProperties("app.properties"); | ||
18 | + _speasyProxyUrl = lProperties["app.speasyproxy.url"]; | ||
19 | + LOG4CXX_DEBUG(gLogger, "SpeasyProxyRequestManager::init - speasy proxy URL = " << _speasyProxyUrl); | ||
20 | +} | ||
21 | + | ||
22 | +SpeasyProxyRequestManager::~SpeasyProxyRequestManager() { | ||
23 | +} | ||
24 | + | ||
25 | +SpeasyProxyRequestSPtr SpeasyProxyRequestManager::getSpeasyProxyRequest(const std::string& pSpeasyRequestId, SpeasyProxyParamType& paramType, int& dim1Size, int& dim2Size) { | ||
26 | + SpeasyProxyRequestSPtr lResult; | ||
27 | + auto lIt = _speasyProxyRequestMap.find(pSpeasyRequestId); | ||
28 | + if (lIt == _speasyProxyRequestMap.end()) | ||
29 | + { | ||
30 | + lResult = SpeasyProxyRequestSPtr(new SpeasyProxyRequest(pSpeasyRequestId, paramType, dim1Size, dim2Size)); | ||
31 | + _speasyProxyRequestMap[pSpeasyRequestId] = lResult; | ||
32 | + } else { | ||
33 | + lResult = lIt->second.lock(); | ||
34 | + if ( ! lResult) { | ||
35 | + _speasyProxyRequestMap.erase(lIt); | ||
36 | + lResult = SpeasyProxyRequestSPtr(new SpeasyProxyRequest(pSpeasyRequestId, paramType, dim1Size, dim2Size)); | ||
37 | + _speasyProxyRequestMap[pSpeasyRequestId] = lResult; | ||
38 | + } | ||
39 | + } | ||
40 | + return lResult; | ||
41 | +} | ||
42 | + | ||
43 | +std::string& SpeasyProxyRequestManager::getSpeasyProxyUrl(void) { | ||
44 | + return _speasyProxyUrl; | ||
45 | +} | ||
46 | + | ||
47 | +} /* namespace SpeasyProxyInterface */ | ||
48 | +} /* namespace AMDA */ |
src/ParamGetImpl/SpeasyProxyInterface/SpeasyProxyRequestManager.hh
0 → 100644
@@ -0,0 +1,62 @@ | @@ -0,0 +1,62 @@ | ||
1 | +/* | ||
2 | + * SpeasyProxyRequestManager.hh | ||
3 | + * | ||
4 | + * Created on: Dec 9, 2024 | ||
5 | + * Author: AKKA | ||
6 | + */ | ||
7 | + | ||
8 | +#ifndef SPEASYPROXYREQUESTMANAGER_HH_ | ||
9 | +#define SPEASYPROXYREQUESTMANAGER_HH_ | ||
10 | + | ||
11 | +#include <string> | ||
12 | +#include <map> | ||
13 | + | ||
14 | +#include "dsgpatt_Singleton.hh" | ||
15 | +#include "SpeasyProxyRequest.hh" | ||
16 | + | ||
17 | + | ||
18 | +namespace AMDA { | ||
19 | +namespace SpeasyProxyInterface { | ||
20 | + | ||
21 | +/** | ||
22 | + * @class SpeasyProxyRequestManager | ||
23 | + * @brief This Singleton contains and maintain a set of SpeasyProxyRequest object with key as speasyRequestId. | ||
24 | + */ | ||
25 | +class SpeasyProxyRequestManager : public ::Singleton<SpeasyProxyRequestManager> | ||
26 | +{ | ||
27 | +public: | ||
28 | + | ||
29 | + typedef std::map<std::string,SpeasyProxyRequestWPtr> SpeasyProxyRequestMap; | ||
30 | + | ||
31 | + // Design pattern | ||
32 | + friend class Singleton<SpeasyProxyRequestManager>; | ||
33 | + | ||
34 | + /** | ||
35 | + * @brief If the VI not exist, create it. | ||
36 | + * @return a SharedPtr on a VirtualInstrument. | ||
37 | + */ | ||
38 | + SpeasyProxyRequestSPtr getSpeasyProxyRequest(const std::string& pSpeasyRequestId, SpeasyProxyParamType& paramType, int& dim1Size, int& dim2Size); | ||
39 | + | ||
40 | + std::string& getSpeasyProxyUrl(void); | ||
41 | + | ||
42 | + | ||
43 | +private: | ||
44 | + SpeasyProxyRequestManager(); | ||
45 | + | ||
46 | + virtual ~SpeasyProxyRequestManager(); | ||
47 | + | ||
48 | + /* | ||
49 | + * @brief SpeasyProxyRequest map | ||
50 | + */ | ||
51 | + SpeasyProxyRequestMap _speasyProxyRequestMap; | ||
52 | + | ||
53 | + /* | ||
54 | + * @brief Speasy proxy entry point | ||
55 | + */ | ||
56 | + std::string _speasyProxyUrl; | ||
57 | +}; | ||
58 | + | ||
59 | +} /* namespace SpeasyProxyInterface */ | ||
60 | +} /* namespace AMDA */ | ||
61 | + | ||
62 | +#endif /* SPEASYPROXYREQUESTMANAGER_HH_*/ | ||
0 | \ No newline at end of file | 63 | \ No newline at end of file |