diff --git a/config/xsd/parameter/getspeasyproxy.xsd b/config/xsd/parameter/getspeasyproxy.xsd index c69ab2d..2e7a059 100644 --- a/config/xsd/parameter/getspeasyproxy.xsd +++ b/config/xsd/parameter/getspeasyproxy.xsd @@ -7,6 +7,8 @@ + + diff --git a/src/ParamGetImpl/SpeasyProxyInterface/ParamGetSpeasyProxy.cc b/src/ParamGetImpl/SpeasyProxyInterface/ParamGetSpeasyProxy.cc index ba00cc2..4a3deb1 100644 --- a/src/ParamGetImpl/SpeasyProxyInterface/ParamGetSpeasyProxy.cc +++ b/src/ParamGetImpl/SpeasyProxyInterface/ParamGetSpeasyProxy.cc @@ -17,6 +17,7 @@ #include "DataSetMgr.hh" #include "DicError.hh" #include "TimeUtil.hh" +#include #include "Helper.hh" #define CURL_STATICLIB #include @@ -28,14 +29,15 @@ namespace SpeasyProxyInterface { ParamGetSpeasyProxy::ParamGetSpeasyProxy(Parameter ¶meter) : ParamGet_CRTP(parameter), - _paramId(""),_timeStamp(0) + _paramId(""),_timeStamp(0),_type(TYPE_FLOAT), _container(CONTAINER_SCALAR) { } ParamGetSpeasyProxy::ParamGetSpeasyProxy(const ParamGetSpeasyProxy &pParamGetSpeasyProxy, Parameter ¶meter) : ParamGet_CRTP(pParamGetSpeasyProxy, parameter), - _paramId(pParamGetSpeasyProxy._paramId), _timeStamp(pParamGetSpeasyProxy._timeStamp) + _paramId(pParamGetSpeasyProxy._paramId), _timeStamp(pParamGetSpeasyProxy._timeStamp), + _type(pParamGetSpeasyProxy._type), _container(pParamGetSpeasyProxy._container) { } @@ -55,6 +57,27 @@ double ParamGetSpeasyProxy::getMinSampling() return 0; } +std::string ParamGetSpeasyProxy::readFile(const std::string& filename) { + // Create an input file stream + std::ifstream file(filename); + + // Check if the file stream was successfully opened + if (!file.is_open()) { + throw std::runtime_error("Could not open file"); + } + + // Use a stringstream to read the entire file into a string + std::stringstream buffer; + buffer << file.rdbuf(); + + // Close the file stream + file.close(); + + // Return the contents of the file as a string + return buffer.str(); +} + + /** * Downloads timetable file in tmp directory. */ @@ -95,8 +118,10 @@ std::string ParamGetSpeasyProxy::download(const std::string& pPath) { if (codes == CURLE_OK) { localPath = tmpFile; } else { + + std::string str(errBuf.begin(), errBuf.end()); LOG4CXX_ERROR(_logger, - "Unable to download " + pPath + " : " + errBuf[0]); + "Unable to download " + pPath + " : " << str );// errBuf[0]); } } else { LOG4CXX_ERROR(_logger, @@ -118,6 +143,15 @@ TimeStamp ParamGetSpeasyProxy::init() { LOG4CXX_DEBUG(gLogger, "ParamGetSpeasyProxy::init"); // Test si proxy accessible + // A Faire + + + std::string link = "http://172.200.0.14:6543/get_data?path=amda%2Fimf&start_time=2008-01-01T00%3A00%3A00&stop_time=2008-01-02T00%3A00%3A00&format=json&zstd_compression=false&pickle_proto=3"; + std::string localPath = download(link); + + std::string value = readFile(localPath); + + _container = CONTAINER_VECTOR; // For now return _timeStamp; } @@ -142,5 +176,12 @@ void ParamGetSpeasyProxy::updateInfo(Parameter & parameter) return; } +size_t write_data(void *ptr, size_t size, size_t nmemb, FILE *stream) { + size_t written; + written = fwrite(ptr, size, nmemb, stream); + return written; +} + + } /* namespace SpeasyProxyInterface */ } /* namespace AMDA */ diff --git a/src/ParamGetImpl/SpeasyProxyInterface/ParamGetSpeasyProxy.hh b/src/ParamGetImpl/SpeasyProxyInterface/ParamGetSpeasyProxy.hh index 151d526..9af7433 100644 --- a/src/ParamGetImpl/SpeasyProxyInterface/ParamGetSpeasyProxy.hh +++ b/src/ParamGetImpl/SpeasyProxyInterface/ParamGetSpeasyProxy.hh @@ -13,7 +13,7 @@ #include #include "ParamGet.hh" #include "TimeStamp.hh" -// #include "Pusher.hh" +#include "Pusher.hh" using namespace AMDA::Parameters; @@ -82,6 +82,8 @@ public: protected: + std::string readFile(const std::string& filename); + std::string download(const std::string& pPath); @@ -91,6 +93,9 @@ protected: */ std::string _paramId; + SpeasyProxyParamType _type; + + SpeasyProxyContainerType _container; /* * @brief Time of xml file or 0 @@ -100,11 +105,12 @@ protected: /* * @brief Data pusher */ - // PusherBase *_pusher; + PusherBase *_pusher; }; typedef boost::shared_ptr ParamGetSpeasyProxySPtr; +size_t write_data(void *ptr, size_t size, size_t nmemb, FILE *stream); } /* namespace SpeasyProxyInterface */ } /* namespace AMDA */ diff --git a/src/ParamGetImpl/SpeasyProxyInterface/Pusher.hh b/src/ParamGetImpl/SpeasyProxyInterface/Pusher.hh new file mode 100644 index 0000000..10cb5ac --- /dev/null +++ b/src/ParamGetImpl/SpeasyProxyInterface/Pusher.hh @@ -0,0 +1,295 @@ +/* + * Pusher.hh + * + * Created on: Jan 30, 2019 + * Author: AKKA + */ + +#ifndef PUSHER_H_ +#define PUSHER_H_ + +#include +#include "ParamData.hh" + + +#include "SpeasyProxyParamData.hh" + +namespace AMDA { +namespace SpeasyProxyInterface { + +// int getNbDataByPacket(ConstantParamType paramType, int dim1, int dim2); + +/** + * @class PusherBase + * @details This class is the operation responsible to transform raw data from local file into a ParamData + * of the corresponding type ( scalar or vector of short or int or float or double or ... type). + */ +struct PusherBase { +public: + /* + * @brief Constructor + */ + PusherBase (double sampling, double value, int dim1 = 1, int dim2 = 1) : _paramData(NULL), _sampling(sampling), _value(value), _dim1(dim1), _dim2(dim2) + { + } + + /* + * @brief Destructor + */ + virtual ~PusherBase() + { + } + + /* + * @brief Get the ParamData + */ + AMDA::Parameters::ParamData* getParamData(void) + { + return _paramData; + } + + /* + * @brief Virtual method to put a packet in the ParamData + */ + virtual int put(double startTime, double stopTime, int lastIndex) = 0; + +protected: + /* + * @brief Pointer to the paramData + */ + AMDA::Parameters::ParamData* _paramData; + + /* + * @brief Sampling value + */ + double _sampling; + + /* + * @brief Constant value + */ + double _value; + + /* + * @brief For Vector and Tab2D dimension + */ + int _dim1; + + /* + * @brief For Tab2D dimension + */ + int _dim2; + + /* + * @brief Nb data returned by one packet + */ + // int _nbDataByPacket; +}; + + +template +struct MapType { typedef void Type; }; + +template <> struct MapType { typedef short Type; }; +template <> struct MapType { typedef int Type; }; +template <> struct MapType { typedef float Type; }; +template <> struct MapType { typedef double Type; }; + + +template +class Pusher; + +/** + * @brief Pusher implementation for the Tab2D. + */ +template +class Pusher : public PusherBase +{ +public: + /* + * @brief Define some usefull types + */ + typedef typename MapType::Type BaseElemenType; + typedef AMDA::Parameters::Tab2DData ElemenType; + typedef AMDA::Parameters::ParamDataSpec SpecParamData; + + SpecParamData* _specParamData; + + /* + * @brief Constructor + */ + Pusher(double sampling, double value, int dim1, int dim2) : PusherBase(sampling, value, dim1, dim2) + { + _paramData = _specParamData = createParamData(); + // _nbDataByPacket = getNbDataByPacket(type, dim1, dim2); + } + + /* + * @brief Put packet in a "vector" ParamData + */ + virtual int put(double startTime, double stopTime, int lastIndex) + { + // _specParamData->getDataList().resize(_nbDataByPacket); + + // for (int index = 0; index < _nbDataByPacket; ++index) + // { + // //get time + // double time = startTime + (lastIndex + index) * _sampling; + // if (time > stopTime) { + // return index; + // } + // //this element will be deleted by the Container designed by "_specParamData->getDataList()" + // ElemenType elem = ElemenType(_dim1,_dim2); + // for (int dim1Index = 0; dim1Index < _dim1; ++dim1Index) + // { + // for (int dim2Index = 0; dim2Index < _dim2; ++dim2Index) + // { + // BaseElemenType baseElem = _value; + // elem[dim1Index][dim2Index] = baseElem; + // } + // } + + // //push time and element in the ParamData + // _specParamData->getDataList().push_back(elem); + // _specParamData->getTimeList().push_back(time); + // } + + // //return nb of processed records + // return _nbDataByPacket; + + return 0; + } + + /* + * @brief ParamData creation + */ + SpecParamData* createParamData() + { + return new AMDA::Parameters::ParamDataSpec::Type> >(_dim1,_dim2); + } +}; + +/** + * @brief Pusher implementation for the vector. + */ +template +class Pusher : public PusherBase +{ +public: + /* + * @brief Define some usefull types + */ + typedef typename MapType::Type BaseElemenType; + typedef std::vector ElemenType; + typedef AMDA::Parameters::ParamDataSpec SpecParamData; + + SpecParamData* _specParamData; + + /* + * @brief Constructor + */ + Pusher(double sampling, double value, int dim) : PusherBase(sampling, value, dim) + { + _paramData = _specParamData = createParamData(); + // _nbDataByPacket = getNbDataByPacket(type, dim, 1); + } + + /* + * @brief Put packet in a "vector" ParamData + */ + virtual int put(double startTime, double stopTime, int lastIndex) + { + // _specParamData->getDataList().resize(_nbDataByPacket); + + // for (int index = 0; index < _nbDataByPacket; ++index) + // { + // //get time + // double time = startTime + (lastIndex + index) * _sampling; + // if (time > stopTime) { + // return index; + // }; + + // ElemenType elem; + // for (int dimIndex = 0; dimIndex < _dim1; ++dimIndex) + // { + // BaseElemenType baseElem = _value; + // elem.push_back(baseElem); + // } + + // //push time and element in the ParamData + // _specParamData->getDataList().push_back(elem); + // _specParamData->getTimeList().push_back(time); + // } + + // //return nb of processed records + // return _nbDataByPacket; + return 0; + } + + /* + * @brief ParamData creation + */ + SpecParamData* createParamData() + { + return new AMDA::Parameters::ParamDataSpec< std::vector::Type> >(_dim1); + } +}; + +/** + * @brief Pusher implementation for the scalar. + */ +template +class Pusher : public PusherBase { +public: + /* + * @brief Define some usefull types + */ + typedef typename MapType::Type BaseElemenType; + typedef BaseElemenType ElemenType; + typedef AMDA::Parameters::ParamDataSpec SpecParamData; + + SpecParamData* _specParamData; + + /* + * @brief Constructor + */ + Pusher(double sampling, double value) : PusherBase(sampling, value) + { + _paramData = _specParamData = createParamData(); + // _nbDataByPacket = getNbDataByPacket(type, 1, 1); + } + + /* + * @brief Put packet in a "scalar" ParamData + */ + virtual int put(double startTime, double stopTime, int lastIndex) + { + // //ParamData is created, add data + // _specParamData->getDataList().resize(_nbDataByPacket); + + // for (int index = 0; index < _nbDataByPacket; ++index) + // { + // //get time + // double time = startTime + (lastIndex + index) * _sampling; + // if (time > stopTime) { + // return index; + // } + + // BaseElemenType baseElem = _value; + + // //push time and element in the ParamData + // _specParamData->getDataList().push_back(baseElem); + // _specParamData->getTimeList().push_back(time); + // } + + // return _nbDataByPacket; + return 0; + } + + SpecParamData* createParamData() { + return new SpecParamData(); + } +}; + +} /* namespace SpeasyProxyInterface */ +} /* namespace AMDA */ +#endif /* PUSHER_H_ */ diff --git a/src/ParamGetImpl/SpeasyProxyInterface/SpeasyProxyParamData.hh b/src/ParamGetImpl/SpeasyProxyInterface/SpeasyProxyParamData.hh new file mode 100644 index 0000000..81dccca --- /dev/null +++ b/src/ParamGetImpl/SpeasyProxyInterface/SpeasyProxyParamData.hh @@ -0,0 +1,48 @@ +/* + * SpeasyProxyParamData.hh + * + * Created on: Jan 30, 2019 + * Author: AKKA + */ + + +#ifndef SPEASYPROXYPARAMDATA_HH_ +#define SPEASYPROXYPARAMDATA_HH_ + +namespace AMDA { +namespace SpeasyProxyInterface { + +/* + * @brief Container type + */ +enum SpeasyProxyContainerType +{ + CONTAINER_SCALAR, + CONTAINER_VECTOR, + CONTAINER_MATRIX +}; + +/* + * @brief Param type + */ +enum SpeasyProxyParamType +{ + TYPE_UNKNOWN, + TYPE_FLOAT, + TYPE_DOUBLE, + TYPE_EPOCH16, + TYPE_SHORT, + TYPE_INT, + TYPE_TT2000 +}; + +/* + * @brief Define the maximum bytes available for one packet + */ +// #define PARAMPACKET_MAX_DATABYTES 80000 +// #define PARAMPACKET_MIN_NBDATABYPACKET 1000 + +} /* SpeasyProxyInterface */ +} /* AMDA */ + +#endif /* SPEASYPROXYPARAMDATA_HH_ */ -- libgit2 0.21.2