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> 103 #define DDS_TOOLS_DECLARE_DATA_CLASS(theBaseClass, theClass, theTag) \ 104 struct theClass : theBaseClass<theClass> \ 109 theClass(const boost::property_tree::ptree& _pt) \ 115 friend SBaseData<theClass>; \ 116 friend theBaseClass<theClass>; \ 117 void _fromPT(const boost::property_tree::ptree& ) \ 120 void _toPT(boost::property_tree::ptree& ) const \ 123 static constexpr const char* _protocolTag = theTag; \ 126 bool operator==(const theClass& _val) const \ 128 return SBaseData::operator==(_val); \ 147 boost::property_tree::ptree pt;
151 boost::property_tree::ptree ptParent;
153 auto parentPtr = static_cast<const T*>(
this);
154 ptParent.put_child(
"dds.tools-api." + std::string(parentPtr->_protocolTag), pt);
156 std::stringstream json;
157 boost::property_tree::write_json(json, ptParent);
164 void toPT(boost::property_tree::ptree& _pt)
const 166 auto parentPtr{ static_cast<const T*>(
this) };
168 parentPtr->_toPT(_pt);
173 void fromPT(
const boost::property_tree::ptree& _pt)
175 auto parentPtr{ static_cast<T*>(
this) };
177 parentPtr->_fromPT(_pt);
189 auto parentPtr = static_cast<const T*>(_data);
190 return _os <<
"requestID: " << _data.
m_requestID <<
"; protocolTag: " << parentPtr->_protocolTag;
196 std::stringstream ss;
197 auto parentPtr = static_cast<const T*>(
this);
198 ss <<
"requestID: " <<
m_requestID <<
"; protocolTag: " << parentPtr->_protocolTag;
217 void _fromPT(
const boost::property_tree::ptree& )
219 throw std::runtime_error(
"DDS Tools API: bad usage of SEmptyResponseData");
222 void _toPT(boost::property_tree::ptree& )
const 224 throw std::runtime_error(
"DDS Tools API: bad usage of SEmptyResponseData");
226 static std::string _protocolTag()
228 throw std::runtime_error(
"DDS Tools API: bad usage of SEmptyResponseData");
235 throw std::runtime_error(
"DDS Tools API: bad usage of SEmptyRequestData");
240 struct SDoneResponseData;
241 struct SMessageResponseData;
242 struct SProgressResponseData;
244 template <
class TRequest,
class TResponse>
251 typedef std::shared_ptr<SBaseRequestImpl>
ptr_t;
267 requestID_t requestID = ptr->m_request.m_requestID;
268 ptr->m_request = _request;
269 ptr->m_request.m_requestID = requestID;
275 m_callbackResponse = _callbackResponse;
280 m_callbackProgress = _callbackProgress;
285 m_callbackMessage = _callbackMessage;
290 m_callbackDone = _callbackDone;
298 if (m_callbackResponse)
299 m_callbackResponse(_arg);
301 catch (
const std::exception& e)
303 throw std::runtime_error(std::string(
"ResponseCallback: ") + e.what());
311 if (m_callbackProgress)
312 m_callbackProgress(_arg);
314 catch (
const std::exception& e)
316 throw std::runtime_error(std::string(
"ProgressCallback: ") + e.what());
324 if (m_callbackMessage)
325 m_callbackMessage(_arg);
327 catch (
const std::exception& e)
329 throw std::runtime_error(std::string(
"MessageCallback: ") + e.what());
340 catch (
const std::exception& e)
342 throw std::runtime_error(std::string(
"DoneCallback: ") + e.what());
354 const boost::uuids::uuid
id = boost::uuids::random_generator()();
355 std::stringstream strid;
358 m_request.m_requestID =
crc64(strid.str());
362 uint64_t
crc64(
const std::string& _str)
364 boost::crc_optimal<64, 0x04C11DB7, 0, 0, false, false>
crc;
365 crc.process_bytes(_str.data(), _str.size());
366 return crc.checksum();
ret_t crc(const std::string &_str)
Definition: CRC.h:19
Miscellaneous functions and helpers are located here.
Definition: AgentConnectionManager.h:13