29 #include <boost/intrusive/list.hpp>
31 namespace RobotRaconteur
34 class ROBOTRACONTEUR_CORE_API ArrayBinaryReader;
35 class ROBOTRACONTEUR_CORE_API ArrayBinaryWriter;
36 class ROBOTRACONTEUR_CORE_API NodeID;
38 class ROBOTRACONTEUR_CORE_API Message;
39 class ROBOTRACONTEUR_CORE_API MessageHeader;
40 class ROBOTRACONTEUR_CORE_API MessageEntry;
41 class ROBOTRACONTEUR_CORE_API MessageElement;
42 class ROBOTRACONTEUR_CORE_API MessageElementNestedElementList;
44 class ROBOTRACONTEUR_CORE_API Message :
public RRValue
47 RR_INTRUSIVE_PTR<MessageHeader> header;
48 std::vector<RR_INTRUSIVE_PTR<MessageEntry> > entries;
52 RR_INTRUSIVE_PTR<MessageEntry> FindEntry(MessageStringRef name);
54 RR_INTRUSIVE_PTR<MessageEntry> AddEntry(MessageEntryType t, MessageStringRef name);
57 uint32_t ComputeSize();
58 void Write(ArrayBinaryWriter& w);
59 void Read(ArrayBinaryReader& r);
62 uint32_t ComputeSize4();
63 void Write4(ArrayBinaryWriter& w);
64 void Read4(ArrayBinaryReader& r);
66 RR_OVIRTUAL std::string RRType() RR_OVERRIDE {
return "RobotRaconteur::Message"; }
69 class ROBOTRACONTEUR_CORE_API MessageHeader :
public RRValue
72 RR_OVIRTUAL ~MessageHeader() RR_OVERRIDE {}
78 uint32_t SenderEndpoint;
80 uint32_t ReceiverEndpoint;
82 MessageStringPtr SenderNodeName;
84 MessageStringPtr ReceiverNodeName;
88 NodeID ReceiverNodeID;
90 MessageStringPtr MetaData;
96 uint16_t MessageResID;
100 std::vector<boost::tuple<uint32_t, MessageStringPtr> > StringTable;
104 std::vector<uint8_t> Extended;
107 uint16_t ComputeSize();
108 void UpdateHeader(uint32_t message_size, uint16_t entry_count);
109 void Write(ArrayBinaryWriter& w);
110 void Read(ArrayBinaryReader& r);
114 uint32_t ComputeSize4();
117 void UpdateHeader4(uint32_t message_entry_size, uint16_t entry_count);
118 void Write4(ArrayBinaryWriter& w);
119 void Read4(ArrayBinaryReader& r);
121 RR_OVIRTUAL std::string RRType() RR_OVERRIDE {
return "RobotRaconteur::MessageHeader"; }
126 class ROBOTRACONTEUR_CORE_API MessageEntry :
public RRValue
129 RR_OVIRTUAL ~MessageEntry() RR_OVERRIDE {}
137 MessageStringPtr ServicePath;
139 uint32_t ServicePathCode;
141 MessageStringPtr MemberName;
143 uint32_t MemberNameCode;
149 MessageStringPtr MetaData;
151 std::vector<uint8_t> Extended;
153 std::vector<RR_INTRUSIVE_PTR<MessageElement> > elements;
157 MessageEntry(MessageEntryType t, MessageStringRef n);
159 RR_INTRUSIVE_PTR<MessageElement> FindElement(MessageStringRef name);
161 bool TryFindElement(MessageStringRef name, RR_INTRUSIVE_PTR<MessageElement>& elem);
163 RR_INTRUSIVE_PTR<MessageElement> AddElement(MessageStringRef name,
164 const RR_INTRUSIVE_PTR<MessageElementData>& data);
166 RR_INTRUSIVE_PTR<MessageElement> AddElement(
const RR_INTRUSIVE_PTR<MessageElement>& m);
169 uint32_t ComputeSize();
171 void Write(ArrayBinaryWriter& w);
172 void Read(ArrayBinaryReader& r);
175 uint32_t ComputeSize4();
177 void Write4(ArrayBinaryWriter& w);
178 void Read4(ArrayBinaryReader& r);
180 RR_OVIRTUAL std::string RRType() RR_OVERRIDE {
return "RobotRaconteur::MessageEntry"; }
183 class ROBOTRACONTEUR_CORE_API MessageElement :
public RRValue
186 RR_OVIRTUAL ~MessageElement() RR_OVERRIDE {}
188 uint32_t ElementSize;
190 uint8_t ElementFlags;
192 MessageStringPtr ElementName;
194 uint32_t ElementNameCode;
196 int32_t ElementNumber;
200 MessageStringPtr ElementTypeName;
202 uint32_t ElementTypeNameCode;
204 MessageStringPtr MetaData;
206 std::vector<uint8_t> Extended;
211 RR_INTRUSIVE_PTR<MessageElementData> dat;
216 MessageElement(MessageStringRef name,
const RR_INTRUSIVE_PTR<MessageElementData>& datin);
218 RR_INTRUSIVE_PTR<MessageElementData> GetData();
219 void SetData(
const RR_INTRUSIVE_PTR<MessageElementData>& value);
222 uint32_t ComputeSize();
224 void Write(ArrayBinaryWriter& w);
225 void Read(ArrayBinaryReader& r);
228 uint32_t ComputeSize4();
230 void Write4(ArrayBinaryWriter& w);
231 void Read4(ArrayBinaryReader& r);
233 static RR_INTRUSIVE_PTR<MessageElement> FindElement(std::vector<RR_INTRUSIVE_PTR<MessageElement> >& m,
234 MessageStringRef name);
236 static bool TryFindElement(std::vector<RR_INTRUSIVE_PTR<MessageElement> >& m, MessageStringRef name,
237 RR_INTRUSIVE_PTR<MessageElement>& elem);
239 static bool ContainsElement(std::vector<RR_INTRUSIVE_PTR<MessageElement> >& m, MessageStringRef name);
241 template <
typename T>
242 RR_INTRUSIVE_PTR<T> CastData()
244 return rr_cast<T>(dat);
247 std::string CastDataToString();
249 RR_INTRUSIVE_PTR<MessageElementNestedElementList> CastDataToNestedList();
251 RR_INTRUSIVE_PTR<MessageElementNestedElementList> CastDataToNestedList(DataTypes expected_type);
253 template <
typename T>
254 static RR_INTRUSIVE_PTR<T> CastData(
const RR_INTRUSIVE_PTR<MessageElementData>& Data)
256 return rr_cast<T>(Data);
259 RR_OVIRTUAL std::string RRType() RR_OVERRIDE {
return "RobotRaconteur::MessageElement"; }
262 class ROBOTRACONTEUR_CORE_API MessageElementNestedElementList :
public MessageElementData
266 MessageStringPtr TypeName;
267 std::vector<RR_INTRUSIVE_PTR<MessageElement> > Elements;
269 MessageElementNestedElementList(DataTypes type_, MessageStringRef type_name_,
270 const std::vector<RR_INTRUSIVE_PTR<MessageElement> >& elements_);
271 #ifndef ROBOTRACONTEUR_NO_CXX11
272 MessageElementNestedElementList(DataTypes type_, MessageStringRef type_name_,
273 std::vector<RR_INTRUSIVE_PTR<MessageElement> >&& elements_);
275 RR_OVIRTUAL MessageStringPtr GetTypeString() RR_OVERRIDE;
276 RR_OVIRTUAL DataTypes GetTypeID() RR_OVERRIDE;
277 RR_OVIRTUAL std::
string RRType() RR_OVERRIDE;
280 ROBOTRACONTEUR_CORE_API RR_INTRUSIVE_PTR<Message> CreateMessage();
281 ROBOTRACONTEUR_CORE_API RR_INTRUSIVE_PTR<MessageHeader> CreateMessageHeader();
282 ROBOTRACONTEUR_CORE_API RR_INTRUSIVE_PTR<MessageEntry> CreateMessageEntry();
283 ROBOTRACONTEUR_CORE_API RR_INTRUSIVE_PTR<MessageEntry> CreateMessageEntry(MessageEntryType t, MessageStringRef n);
284 ROBOTRACONTEUR_CORE_API RR_INTRUSIVE_PTR<MessageElement> CreateMessageElement();
285 ROBOTRACONTEUR_CORE_API RR_INTRUSIVE_PTR<MessageElement> CreateMessageElement(
286 MessageStringRef name, const RR_INTRUSIVE_PTR<MessageElementData>& datin);
287 ROBOTRACONTEUR_CORE_API RR_INTRUSIVE_PTR<MessageElement> CreateMessageElement(
288 int32_t number, const RR_INTRUSIVE_PTR<MessageElementData>& datin);
289 ROBOTRACONTEUR_CORE_API RR_INTRUSIVE_PTR<MessageElementNestedElementList> CreateMessageElementNestedElementList(
290 DataTypes type_, MessageStringRef type_name_, const std::vector<RR_INTRUSIVE_PTR<MessageElement> >& elements_);
291 #ifndef ROBOTRACONTEUR_NO_CXX11
292 ROBOTRACONTEUR_CORE_API RR_INTRUSIVE_PTR<MessageElementNestedElementList> CreateMessageElementNestedElementList(
293 DataTypes type_, MessageStringRef type_name_, std::vector<RR_INTRUSIVE_PTR<MessageElement> >&& elements_);
295 ROBOTRACONTEUR_CORE_API RR_INTRUSIVE_PTR<Message> ShallowCopyMessage(
const RR_INTRUSIVE_PTR<Message>& m);
296 ROBOTRACONTEUR_CORE_API RR_INTRUSIVE_PTR<MessageEntry> ShallowCopyMessageEntry(
297 const RR_INTRUSIVE_PTR<MessageEntry>& mm);
298 ROBOTRACONTEUR_CORE_API RR_INTRUSIVE_PTR<MessageElement> ShallowCopyMessageElement(
299 const RR_INTRUSIVE_PTR<MessageElement>& mm);
302 template <
typename T>
303 RR_INTRUSIVE_PTR<MessageElementData> MessageElement_PackScalar(
const T& value)
305 return RobotRaconteur::ScalarToRRArray<T>(value);
308 template <
typename T>
309 RR_INTRUSIVE_PTR<MessageElement> MessageElement_PackScalarElement(MessageStringRef elementname,
const T& value)
311 return CreateMessageElement(elementname, MessageElement_PackScalar(value));
314 template <
typename T>
315 RR_INTRUSIVE_PTR<MessageElementData> MessageElement_PackArray(
const RR_INTRUSIVE_PTR<RRArray<T> >& value)
318 throw NullValueException(
"Arrays must not be null");
322 template <
typename T>
323 RR_INTRUSIVE_PTR<MessageElement> MessageElement_PackArrayElement(MessageStringRef elementname,
324 const RR_INTRUSIVE_PTR<RRArray<T> >& value)
326 return CreateMessageElement(elementname, MessageElement_PackArray(value));
329 template <
typename T,
typename N>
330 RR_INTRUSIVE_PTR<MessageElementData> MessageElement_PackMultiDimArray(
331 RR_WEAK_PTR<N> node,
const RR_INTRUSIVE_PTR<RRMultiDimArray<T> >& value)
334 throw NullValueException(
"Arrays must not be null");
335 RR_SHARED_PTR<N> node1 = node.lock();
337 throw InvalidOperationException(
"Node has been released");
341 template <
typename T,
typename N>
342 RR_INTRUSIVE_PTR<MessageElement> MessageElement_PackMultiDimArrayElement(
343 RR_WEAK_PTR<N> node, MessageStringRef elementname,
const RR_INTRUSIVE_PTR<RRMultiDimArray<T> >& value)
345 return CreateMessageElement(elementname, MessageElement_PackMultiDimArray(node, value));
348 template <
typename T>
349 RR_INTRUSIVE_PTR<MessageElementData> MessageElement_PackString(
const T& str)
354 template <
typename T>
355 RR_INTRUSIVE_PTR<MessageElement> MessageElement_PackStringElement(MessageStringRef elementname,
const T& str)
357 return CreateMessageElement(elementname, MessageElement_PackString(str));
360 template <
typename T,
typename N>
361 RR_INTRUSIVE_PTR<MessageElementData> MessageElement_PackVarType(RR_WEAK_PTR<N> node,
const RR_INTRUSIVE_PTR<T>& s)
363 RR_SHARED_PTR<N> node1 = node.lock();
365 throw InvalidOperationException(
"Node has been released");
366 return node1->PackVarType(s);
369 template <
typename T,
typename N>
370 RR_INTRUSIVE_PTR<MessageElement> MessageElement_PackVarTypeElement(RR_WEAK_PTR<N> node, MessageStringRef elementname,
371 const RR_INTRUSIVE_PTR<T>& s)
373 return CreateMessageElement(elementname, MessageElement_PackVarType(node, s));
376 template <
typename T,
typename N>
377 RR_INTRUSIVE_PTR<MessageElementData> MessageElement_PackStruct(RR_WEAK_PTR<N> node,
const RR_INTRUSIVE_PTR<T>& s)
379 RR_SHARED_PTR<N> node1 = node.lock();
381 throw InvalidOperationException(
"Node has been released");
382 return node1->PackStructure(RobotRaconteur::rr_cast<RobotRaconteur::RRStructure>(s));
385 template <
typename T,
typename N>
386 RR_INTRUSIVE_PTR<MessageElement> MessageElement_PackStructElement(RR_WEAK_PTR<N> node, MessageStringRef elementname,
387 const RR_INTRUSIVE_PTR<T>& s)
389 return CreateMessageElement(elementname, MessageElement_PackStruct(node, s));
392 template <
typename T>
393 RR_INTRUSIVE_PTR<MessageElementData> MessageElement_PackEnum(
const T& value)
395 return RobotRaconteur::ScalarToRRArray<int32_t>(
static_cast<int32_t
>(value));
398 template <
typename T>
399 RR_INTRUSIVE_PTR<MessageElement> MessageElement_PackEnumElement(MessageStringRef elementname,
const T& value)
401 return CreateMessageElement(elementname, MessageElement_PackEnum(value));
404 template <
typename K,
typename T,
typename N>
405 RR_INTRUSIVE_PTR<MessageElementData> MessageElement_PackMap(RR_WEAK_PTR<N> node,
406 const RR_INTRUSIVE_PTR<RRMap<K, T> >& m)
408 RR_SHARED_PTR<N> node1 = node.lock();
410 throw InvalidOperationException(
"Node has been released");
411 return node1->template PackMapType<K, T>(m);
414 template <
typename K,
typename T,
typename N>
415 RR_INTRUSIVE_PTR<MessageElement> MessageElement_PackMapElement(RR_WEAK_PTR<N> node, MessageStringRef elementname,
416 const RR_INTRUSIVE_PTR<RRMap<K, T> >& m)
418 return CreateMessageElement(elementname, MessageElement_PackMap(node, m));
421 template <
typename T,
typename N>
422 RR_INTRUSIVE_PTR<MessageElementData> MessageElement_PackList(RR_WEAK_PTR<N> node,
const RR_INTRUSIVE_PTR<RRList<T> >& m)
424 RR_SHARED_PTR<N> node1 = node.lock();
426 throw InvalidOperationException(
"Node has been released");
427 return node1->template PackListType<T>(m);
430 template <
typename T,
typename N>
431 RR_INTRUSIVE_PTR<MessageElement> MessageElement_PackListElement(RR_WEAK_PTR<N> node, MessageStringRef elementname,
432 const RR_INTRUSIVE_PTR<RRList<T> >& m)
434 return CreateMessageElement(elementname, MessageElement_PackList(node, m));
438 template <
typename T>
439 T MessageElement_UnpackScalar(
const RR_INTRUSIVE_PTR<MessageElement>& m)
441 return RRArrayToScalar<T>(m->CastData<RRArray<T> >());
444 template <
typename T>
445 RR_INTRUSIVE_PTR<RRArray<T> > MessageElement_UnpackArray(
const RR_INTRUSIVE_PTR<MessageElement>& m)
447 RR_INTRUSIVE_PTR<RRArray<T> > a = (m->CastData<RRArray<T> >());
449 throw NullValueException(
"Arrays must not be null");
453 template <
typename T,
typename N>
454 RR_INTRUSIVE_PTR<RRMultiDimArray<T> > MessageElement_UnpackMultiDimArray(RR_WEAK_PTR<N> node,
455 const RR_INTRUSIVE_PTR<MessageElement>& m)
457 RR_SHARED_PTR<N> node1 = node.lock();
459 throw InvalidOperationException(
"Node has been released");
460 RR_INTRUSIVE_PTR<RRMultiDimArray<T> > a = RobotRaconteur::rr_cast<RRMultiDimArray<T> >(
461 node1->template UnpackMultiDimArray<T>(m->CastDataToNestedList(DataTypes_multidimarray_t)));
463 throw NullValueException(
"Arrays must not be null");
467 static std::string MessageElement_UnpackString(
const RR_INTRUSIVE_PTR<MessageElement>& m)
472 template <
typename T,
typename N>
473 RR_INTRUSIVE_PTR<T> MessageElement_UnpackStructure(RR_WEAK_PTR<N> node,
const RR_INTRUSIVE_PTR<MessageElement>& m)
475 RR_SHARED_PTR<N> node1 = node.lock();
477 throw InvalidOperationException(
"Node has been released");
478 return RobotRaconteur::rr_cast<T>(
479 node1->UnpackStructure(m->CastData<RobotRaconteur::MessageElementNestedElementList>()));
482 template <
typename T>
483 T MessageElement_UnpackEnum(
const RR_INTRUSIVE_PTR<MessageElement>& m)
485 return static_cast<T
>(RRArrayToScalar<int32_t>(m->CastData<RRArray<int32_t> >()));
488 template <
typename N>
489 RR_INTRUSIVE_PTR<RRValue> MessageElement_UnpackVarValue(RR_WEAK_PTR<N> node,
const RR_INTRUSIVE_PTR<MessageElement>& m)
491 RR_SHARED_PTR<N> node1 = node.lock();
493 throw InvalidOperationException(
"Node has been released");
494 return node1->UnpackVarType(m);
497 template <
typename K,
typename T,
typename N>
498 RR_INTRUSIVE_PTR<RRMap<K, T> > MessageElement_UnpackMap(RR_WEAK_PTR<N> node,
const RR_INTRUSIVE_PTR<MessageElement>& m)
500 RR_SHARED_PTR<N> node1 = node.lock();
502 throw InvalidOperationException(
"Node has been released");
503 return node1->template UnpackMapType<K, T>(m->CastData<RobotRaconteur::MessageElementNestedElementList>());
506 template <
typename T,
typename N>
507 RR_INTRUSIVE_PTR<RRList<T> > MessageElement_UnpackList(RR_WEAK_PTR<N> node,
const RR_INTRUSIVE_PTR<MessageElement>& m)
509 RR_SHARED_PTR<N> node1 = node.lock();
511 throw InvalidOperationException(
"Node has been released");
512 return node1->template UnpackListType<T>(m->CastDataToNestedList());
515 ROBOTRACONTEUR_CORE_API
bool MessageElement_GetElementNumber(
const RR_INTRUSIVE_PTR<MessageElement>& m,
517 ROBOTRACONTEUR_CORE_API
void MessageElement_SetElementNumber(
const RR_INTRUSIVE_PTR<MessageElement>& m, int32_t number);
518 ROBOTRACONTEUR_CORE_API
bool MessageElement_GetElementName(
const RR_INTRUSIVE_PTR<MessageElement>& m,
519 MessageStringPtr& name);
521 #ifndef ROBOTRACONTEUR_NO_CXX11_TEMPLATE_ALIASES
522 using MessagePtr = RR_INTRUSIVE_PTR<Message>;
523 using MessageHeaderPtr = RR_INTRUSIVE_PTR<MessageHeader>;
524 using MessageEntryPtr = RR_INTRUSIVE_PTR<MessageEntry>;
525 using MessageElementPtr = RR_INTRUSIVE_PTR<MessageElement>;
526 using MessageElementNestedElementListPtr = RR_INTRUSIVE_PTR<MessageElementNestedElementList>;
boost::intrusive_ptr< RRArray< char > > stringToRRArray(boost::string_ref str)
Convert a string to an array of characters.
std::string RRArrayToString(const boost::intrusive_ptr< RRArray< char > > &arr)
Convert an array of characters into std::string.
MessageErrorType
Message error type codes enum.
Definition: RobotRaconteurConstants.h:396
DataTypes
Type codes for types supported by Robot Raconteur.
Definition: RobotRaconteurConstants.h:41
MessageEntryType
Message entry type codes.
Definition: RobotRaconteurConstants.h:225
Numeric primitive multidimensional array value type.
Definition: DataTypes.h:1600