Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  
igtlMessageBase.h
Go to the documentation of this file.
1/*=========================================================================
2
3 Program: The OpenIGTLink Library
4 Language: C++
5 Web page: http://openigtlink.org/
6
7 Copyright (c) Insight Software Consortium. All rights reserved.
8
9 This software is distributed WITHOUT ANY WARRANTY; without even
10 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11 PURPOSE. See the above copyright notices for more information.
12
13 =========================================================================*/
14
15#ifndef __igtlMessageBase_h
16#define __igtlMessageBase_h
17
18#include "igtlMacro.h"
19#include "igtlMath.h"
20#include "igtlMessageHeader.h"
21#include "igtlObject.h"
22#include "igtlObjectFactory.h"
23#include "igtlTimeStamp.h"
24#include "igtl_header.h"
25#include "igtl_types.h"
26
27#include <string>
28#include <map>
29#include <vector>
30
31namespace igtl
32{
33
77
79 {
80 public:
85
86#if OpenIGTLink_HEADER_VERSION >= 2
87 // Types for managing meta data
88 typedef std::map<std::string, std::pair<IANA_ENCODING_TYPE, std::string> > MetaDataMap;
89#endif
90
93
95 enum
96 {
97 UNPACK_UNDEF = 0x0000,
98 UNPACK_HEADER = 0x0001,
99 UNPACK_BODY = 0x0002
100 };
101
102 public:
105
107 void SetHeaderVersion(unsigned short headerVersion);
108
110 unsigned short GetHeaderVersion() const;
111
113 void SetDeviceName(const char* name);
114
116 void SetDeviceName(const std::string& name);
117
119 void SetDeviceType(const std::string& type);
120
122 const char* GetDeviceName();
123
125 std::string GetDeviceName() const;
126
128 const char* GetDeviceType();
129
130#if OpenIGTLink_HEADER_VERSION >= 2
134 igtlUint32 GetMetaDataSize();
135
137 igtlUint16 GetMetaDataHeaderSize();
138
140 igtlUint32 GetMessageID();
141
143 void SetMessageID(igtlUint32 idValue);
144
146 bool SetMetaDataElement(const std::string& key, IANA_ENCODING_TYPE encodingScheme, std::string value);
147 bool SetMetaDataElement(const std::string& key, igtl_uint8);
148 bool SetMetaDataElement(const std::string& key, igtl_int8);
149 bool SetMetaDataElement(const std::string& key, igtl_uint16);
150 bool SetMetaDataElement(const std::string& key, igtl_int16);
151 bool SetMetaDataElement(const std::string& key, igtl_uint32);
152 bool SetMetaDataElement(const std::string& key, igtl_int32);
153 bool SetMetaDataElement(const std::string& key, igtl_uint64);
154 bool SetMetaDataElement(const std::string& key, igtl_int64);
155 bool SetMetaDataElement(const std::string& key, float);
156 bool SetMetaDataElement(const std::string& key, double);
157
159 bool GetMetaDataElement(const std::string& key, std::string& value) const;
160 bool GetMetaDataElement(const std::string& key, IANA_ENCODING_TYPE& encoding, std::string& value) const;
161
163 const MetaDataMap& GetMetaData() const;
164
166 bool PackExtendedHeader();
167
169 bool PackMetaData();
170
174 bool UnpackExtendedHeader();
175
177 bool UnpackMetaData();
178#endif
179
181 int SetTimeStamp(unsigned int sec, unsigned int frac);
182
184 int GetTimeStamp(unsigned int* sec, unsigned int* frac);
185
188
191
194 virtual int Pack();
195
210 int Unpack(int crccheck = 0);
211
214 void* GetPackPointer() { return GetBufferPointer(); }
215
218 void* GetPackBodyPointer() { return GetBufferBodyPointer(); }
219
222 int GetPackSize() { return GetBufferSize(); }
223
226 int GetPackBodySize() { return GetBufferBodySize(); }
227
232
234 const char* GetBodyType();
235
237 std::string GetMessageType() const;
238
242 void AllocatePack() { AllocateBuffer(); }
243
249 void InitPack() { InitBuffer(); }
250
254 int Copy(const MessageBase* mb);
255
257 virtual int SetMessageHeader(const MessageHeader* mb);
258
262
263 protected:
266
267 protected:
270
272 virtual int PackContent();
274 virtual int UnpackContent();
275
278 virtual void AllocateBuffer(int contentSize);
279
282 virtual void AllocateUnpack(int bodySizeToRead);
283
285 int CopyBody(const MessageBase* mb);
286
288 int CopyHeader(const MessageBase* mb);
289
291 void UnpackHeader(int& r);
292
295 void UnpackBody(int crccheck, int& r);
296
297 protected:
299
303 unsigned char* m_Header;
304
308 unsigned char* m_Body;
309
311 unsigned char* m_Content;
312
316
318 std::string m_SendMessageType;
319
323
325 unsigned short m_HeaderVersion;
326
328 std::string m_DeviceName;
329
332 unsigned int m_TimeStampSec;
333
337
340
343
346
347#if OpenIGTLink_HEADER_VERSION >= 2
348 protected:
350 unsigned char* m_ExtendedHeader;
351
353 bool m_IsExtendedHeaderUnpacked;
354
356 unsigned char* m_MetaData;
357
359 unsigned char* m_MetaDataHeader;
360
362 igtlUint32 m_MessageId;
363
365 MetaDataMap m_MetaDataMap;
366
367#endif // if OpenIGTLink_HEADER_VERSION >= 2
368
369 };
370
373 {
374 public:
379
382
383 protected:
385 {
386 this->m_SendMessageType = "";
387 };
389
390 protected:
392 {
393 return 0;
394 };
395 virtual int PackContent()
396 {
397 AllocateBuffer();
398 return 1;
399 };
400 virtual int UnpackContent()
401 {
402 return 1;
403 };
404 };
405
408 // TODO: Need test.
409#define igtlCreateDefaultQueryMessageClass(name, msgtype) \
410class IGTLCommon_EXPORT name : public HeaderOnlyMessageBase\
411{ \
412public: \
413typedef name Self; \
414typedef HeaderOnlyMessageBase Superclass; \
415typedef SmartPointer<Self> Pointer; \
416typedef SmartPointer<const Self> ConstPointer; \
417\
418igtlTypeMacro(igtl::name, igtl::HeaderOnlyMessageBase); \
419igtlNewMacro(igtl::name); \
420\
421protected: \
422name() : HeaderOnlyMessageBase() { this->m_SendMessageType = msgtype; }; \
423~name() {}; \
424};
425
426} // namespace igtl
427
428#endif // _igtlMessageBase_h
429
430
A class for header-only message types, which are used for querying.
igtlNewMacro(igtl::HeaderOnlyMessageBase)
virtual int UnpackContent()
Unpacks (deserialize) the content. Must be implemented in all child classes.
SmartPointer< const Self > ConstPointer
igtlTypeMacro(igtl::HeaderOnlyMessageBase, igtl::MessageBase)
SmartPointer< Self > Pointer
virtual int PackContent()
Packs (serialize) the content. Must be implemented in all child classes.
virtual int CalculateContentBufferSize()
Gets the size of the serialized content.
HeaderOnlyMessageBase Self
int CopyBody(const MessageBase *mb)
Copies the serialized body data.
unsigned int m_TimeStampSecFraction
virtual igtl::MessageBase::Pointer Clone()
Create a clone of this message, new memory but all internals are preserved.
virtual int Pack()
unsigned short GetHeaderVersion() const
Gets the message version number.
int SetTimeStamp(unsigned int sec, unsigned int frac)
Sets time of message creation. 'sec' and 'frac' are seconds and fractions of a second respectively.
int CopyHeader(const MessageBase *mb)
Copies a header from given message.
virtual int PackContent()
Packs (serialize) the content. Must be implemented in all child classes.
int Unpack(int crccheck=0)
void * GetBufferPointer()
Gets a pointer to the raw byte array for the serialized data including the header and the body.
virtual void AllocateBuffer(int contentSize)
virtual int UnpackContent()
Unpacks (deserialize) the content. Must be implemented in all child classes.
void SetDeviceName(const char *name)
Sets the device name.
unsigned int m_TimeStampSec
void UnpackHeader(int &r)
Unpack the first 58 bytes.
void SetTimeStamp(igtl::TimeStamp::Pointer &ts)
Sets time of message creation.
unsigned char * m_Header
unsigned char * m_Body
const char * GetBodyType()
Gets the type of the body.
std::string m_DeviceName
A character string for the device name (message name).
std::string m_ReceiveMessageType
int CalculateReceiveContentSize()
int Copy(const MessageBase *mb)
const char * GetDeviceType()
Gets the device (message) type.
void SetDeviceName(const std::string &name)
Sets the device name.
bool m_IsBodyUnpacked
Unpacking (deserialization) status for the body.
virtual int CalculateContentBufferSize()
Gets the size of the serialized content.
unsigned char * m_Content
A pointer to the underlying content of a message.
const char * GetDeviceName()
Gets the device name.
void GetTimeStamp(igtl::TimeStamp::Pointer &ts)
Gets time of message creation.
int GetBufferSize()
Gets the size of the serialized message data.
void UnpackBody(int crccheck, int &r)
int GetTimeStamp(unsigned int *sec, unsigned int *frac)
Gets time of message creation. 'sec' and 'frac' are seconds and fractions of a second respectively.
void SetHeaderVersion(unsigned short headerVersion)
Sets the message version number.
std::string m_SendMessageType
A character string for the send device type (message type).
bool m_IsBodyPacked
Packing (serialization) status for the body.
virtual int SetMessageHeader(const MessageHeader *mb)
Sets the message header.
bool m_IsHeaderUnpacked
Unpacking (deserialization) status for the header.
unsigned short m_HeaderVersion
An unsigned short for the message format version.
std::string GetMessageType() const
Gets the message type.
std::string GetDeviceName() const
Gets the device name.
int GetBufferBodySize()
Gets the size of the serialized body data.
void * GetBufferBodyPointer()
Gets a pointer to the raw byte array for the serialized body data.
virtual void AllocateUnpack(int bodySizeToRead)
SmartPointer< Self > Pointer
void SetDeviceType(const std::string &type)
Sets the device (message) type.
SmartPointer< const Self > ConstPointer
Base class for most igtl classes.
Definition igtlObject.h:61
Implements transparent reference counting.
#define igtlTypeMacro(thisClass, superclass)
Definition igtlMacro.h:484
#define igtlNewMacro(x)
Definition igtlMacro.h:431
#define IGTLCommon_EXPORT
IANA_ENCODING_TYPE
Definition igtl_types.h:21
The "igtl" namespace contains all OpenIGTLink classes. There are several nested namespaces within the...
class MessageBase MessageHeader

Generated for OpenIGTLink by Doxygen 1.9.8 written by Dimitri van Heesch, © 1997-2012