6 #ifndef DDS_TOOLSPROTOCOLCORE_H 7 #define DDS_TOOLSPROTOCOLCORE_H 12 #include <boost/crc.hpp> 13 #include <boost/property_tree/json_parser.hpp> 14 #include <boost/uuid/uuid.hpp> 15 #include <boost/uuid/uuid_generators.hpp> 16 #include <boost/uuid/uuid_io.hpp> 86 #define DDS_TOOLS_DECLARE_DATA_CLASS(theBaseClass, theClass, theTag) \ 87 struct theClass : theBaseClass<theClass> \ 90 friend SBaseData<theClass>; \ 91 friend theBaseClass<theClass>; \ 92 void _fromPT(const boost::property_tree::ptree& _pt) \ 95 void _toPT(boost::property_tree::ptree& _pt) const \ 98 static constexpr const char* _protocolTag = theTag; \ 101 bool operator==(const theClass& _val) const \ 103 return SBaseData::operator==(_val); \ 122 boost::property_tree::ptree pt;
126 boost::property_tree::ptree ptParent;
128 auto parentPtr = static_cast<const T*>(
this);
129 ptParent.put_child(
"dds.tools-api." + std::string(parentPtr->_protocolTag), pt);
131 std::stringstream json;
132 boost::property_tree::write_json(json, ptParent);
139 void toPT(boost::property_tree::ptree& _pt)
const 141 auto parentPtr = static_cast<const T*>(
this);
145 return parentPtr->_toPT(_pt);
150 void fromPT(
const boost::property_tree::ptree& _pt)
152 auto parentPtr = static_cast<T*>(
this);
156 return parentPtr->_fromPT(_pt);
168 auto parentPtr = static_cast<const T*>(_data);
169 return _os <<
"requestID: " << _data.
m_requestID <<
"; protocolTag: " << parentPtr->_protocolTag;
175 std::stringstream ss;
176 auto parentPtr = static_cast<const T*>(
this);
177 ss <<
"requestID: " <<
m_requestID <<
"; protocolTag: " << parentPtr->_protocolTag;
196 void _fromPT(
const boost::property_tree::ptree& _pt)
198 throw std::runtime_error(
"DDS Tools API: bad usage of SEmptyResponseData");
201 void _toPT(boost::property_tree::ptree& _pt)
const 203 throw std::runtime_error(
"DDS Tools API: bad usage of SEmptyResponseData");
205 static std::string _protocolTag()
207 throw std::runtime_error(
"DDS Tools API: bad usage of SEmptyResponseData");
214 throw std::runtime_error(
"DDS Tools API: bad usage of SEmptyRequestData");
219 struct SDoneResponseData;
220 struct SMessageResponseData;
221 struct SProgressResponseData;
223 template <
class TRequest,
class TResponse>
230 typedef std::shared_ptr<SBaseRequestImpl>
ptr_t;
246 requestID_t requestID = ptr->m_request.m_requestID;
247 ptr->m_request = _request;
248 ptr->m_request.m_requestID = requestID;
254 m_callbackResponse = _callbackResponse;
259 m_callbackProgress = _callbackProgress;
264 m_callbackMessage = _callbackMessage;
269 m_callbackDone = _callbackDone;
277 if (m_callbackResponse)
278 m_callbackResponse(_arg);
280 catch (
const std::exception& e)
282 throw std::runtime_error(std::string(
"ResponseCallback: ") + e.what());
290 if (m_callbackProgress)
291 m_callbackProgress(_arg);
293 catch (
const std::exception& e)
295 throw std::runtime_error(std::string(
"ProgressCallback: ") + e.what());
303 if (m_callbackMessage)
304 m_callbackMessage(_arg);
306 catch (
const std::exception& e)
308 throw std::runtime_error(std::string(
"MessageCallback: ") + e.what());
319 catch (
const std::exception& e)
321 throw std::runtime_error(std::string(
"DoneCallback: ") + e.what());
333 const boost::uuids::uuid
id = boost::uuids::random_generator()();
334 std::stringstream strid;
337 m_request.m_requestID =
crc64(strid.str());
341 uint64_t
crc64(
const std::string& _str)
343 boost::crc_optimal<64, 0x04C11DB7, 0, 0, false, false>
crc;
344 crc.process_bytes(_str.data(), _str.size());
345 return crc.checksum();
Definition: AgentConnectionManager.h:13
ret_t crc(const std::string &_str)
Definition: CRC.h:19