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 "igtlObject.h"
19#include "igtlObjectFactory.h"
20//#include "igtlMacros.h"
21#include "igtlMacro.h"
22#include "igtlMath.h"
23#include "igtlTimeStamp.h"
24
25#include "igtlMessageHeader.h"
26
27#include <string>
28
29namespace igtl
30{
31
56{
57public:
58
63
66
68 enum {
69 UNPACK_UNDEF = 0x0000,
70 UNPACK_HEADER = 0x0001,
71 UNPACK_BODY = 0x0002
72 };
73
74public:
75
77 void SetDeviceName(const char* name);
78
80 const char* GetDeviceName();
81
83 const char* GetDeviceType();
84
86 int SetTimeStamp(unsigned int sec, unsigned int frac);
87
89 int GetTimeStamp(unsigned int* sec, unsigned int* frac);
90
93
96
99 virtual int Pack();
100
115 int Unpack(int crccheck = 0);
116
119
122
125
128
130 const char* GetBodyType() { return this->m_BodyType.c_str(); };
131
134
138 void InitPack();
139
144 int Copy(const MessageBase* mb);
145
147 virtual int SetMessageHeader(const MessageHeader* mb) { return Copy(mb); };
148
151 int GetBodySizeToRead() { return m_BodySizeToRead; };
152
153protected:
156
157protected:
158
160 virtual int GetBodyPackSize() { return 0; };
161
163 virtual int PackBody() { return 0; };
165 virtual int UnpackBody() { return 0; };
166
169 virtual void AllocatePack(int bodySize);
170
172 int CopyHeader(const MessageBase *mb);
173
175 int CopyBody(const MessageBase *mb);
176
178
182 unsigned char* m_Header;
183
187 unsigned char* m_Body;
188
192
194 std::string m_DefaultBodyType;
195
198 std::string m_BodyType;
199
201 std::string m_DeviceName;
202
205 unsigned int m_TimeStampSec;
206
210
213
216
217};
218
219
222{
223public:
228
231
232protected:
233 HeaderOnlyMessageBase() { this->m_DefaultBodyType = ""; };
235
236protected:
237
238 virtual int GetBodyPackSize() { return 0; };
239 virtual int PackBody() { AllocatePack(); return 1; };
240 virtual int UnpackBody() { return 1; };
241
242};
243
244
247// TODO: Need test.
248#define igtlCreateDefaultQueryMessageClass(name, msgtype) \
249class IGTLCommon_EXPORT name : public HeaderOnlyMessageBase\
250{ \
251public: \
252 typedef name Self; \
253 typedef HeaderOnlyMessageBase Superclass; \
254 typedef SmartPointer<Self> Pointer; \
255 typedef SmartPointer<const Self> ConstPointer; \
256 \
257 igtlTypeMacro(igtl::name, igtl::HeaderOnlyMessageBase); \
258 igtlNewMacro(igtl::name); \
259 \
260protected: \
261 name() : HeaderOnlyMessageBase() { this->m_DefaultBodyType = msgtype; }; \
262 ~name() {}; \
263};
264
265} // namespace igtl
266
267#endif // _igtlMessageBase_h
268
269
A class for header-only message types, which are used for quearying.
igtlNewMacro(igtl::HeaderOnlyMessageBase)
SmartPointer< const Self > ConstPointer
igtlTypeMacro(igtl::HeaderOnlyMessageBase, igtl::MessageBase)
SmartPointer< Self > Pointer
virtual int GetBodyPackSize()
Gets the size of the serialized body.
virtual int UnpackBody()
Unpacks (deserialize) the body. Must be implemented in a child class.
virtual int PackBody()
Packs (serialize) the body. Must be implemented in a child class.
HeaderOnlyMessageBase Self
int CopyBody(const MessageBase *mb)
Copies the serialized body data.
unsigned int m_TimeStampSecFraction
int m_IsHeaderUnpacked
Unpacking (desrialization) status for the header (0: – 1: unpacked).
virtual int Pack()
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.
int Unpack(int crccheck=0)
int GetPackBodySize()
Gets the size of the serialized body data.
void SetDeviceName(const char *name)
Sets the device (message) name.
unsigned int m_TimeStampSec
void SetTimeStamp(igtl::TimeStamp::Pointer &ts)
Sets time of message creation.
virtual int GetBodyPackSize()
Gets the size of the serialized body.
unsigned char * m_Header
unsigned char * m_Body
virtual void AllocatePack(int bodySize)
const char * GetBodyType()
GetBodyType() gets the type of the body.
std::string m_DeviceName
A character string for the device name (message name).
void * GetPackBodyPointer()
Gets a pointer to the raw byte array for the serialized body data.
virtual int PackBody()
Packs (serialize) the body. Must be implemented in a child class.
int Copy(const MessageBase *mb)
const char * GetDeviceType()
Gets the device (message) type.
int GetPackSize()
Gets the size of the serialized data.
void AllocatePack()
AllocatePack() allocates memory for packing / receiving buffer.
const char * GetDeviceName()
Gets the device (message) name.
void GetTimeStamp(igtl::TimeStamp::Pointer &ts)
Gets time of message creation.
int GetTimeStamp(unsigned int *sec, unsigned int *frac)
Gets time of message creation. 'sec' and 'frac' are seconds and fractions of a second respectively.
virtual int SetMessageHeader(const MessageHeader *mb)
Sets the message header.
int m_IsBodyUnpacked
Unpacking (desrialization) status for the body (0: – 1: unpacked).
void * GetPackPointer()
Gets a pointer to the raw byte array for the serialized data including the header and the body.
virtual int UnpackBody()
Unpacks (deserialize) the body. Must be implemented in a child class.
SmartPointer< Self > Pointer
SmartPointer< const Self > ConstPointer
std::string m_DefaultBodyType
A character string for the default device type (message type).
Base class for most igtl classes.
Definition igtlObject.h:61
Implements transparent reference counting.
#define igtlTypeMacro(thisClass, superclass)
Definition igtlMacro.h:486
#define igtlNewMacro(x)
Definition igtlMacro.h:431
#define IGTLCommon_EXPORT
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