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 
29 namespace igtl
30 {
31 
56 {
57 public:
58 
59  typedef MessageBase Self;
60  typedef Object Superclass;
63 
66 
68  enum {
69  UNPACK_UNDEF = 0x0000,
70  UNPACK_HEADER = 0x0001,
71  UNPACK_BODY = 0x0002
72  };
73 
74 public:
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 
92  void SetTimeStamp(igtl::TimeStamp::Pointer& ts);
93 
95  void GetTimeStamp(igtl::TimeStamp::Pointer& ts);
96 
99  virtual int Pack();
100 
115  int Unpack(int crccheck = 0);
116 
118  void* GetPackPointer();
119 
121  void* GetPackBodyPointer();
122 
124  int GetPackSize();
125 
127  int GetPackBodySize();
128 
130  const char* GetBodyType() { return this->m_BodyType.c_str(); };
131 
133  void AllocatePack();
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 
153 protected:
154  MessageBase();
155  ~MessageBase();
156 
157 protected:
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 {
223 public:
228 
231 
232 protected:
233  HeaderOnlyMessageBase() { this->m_DefaultBodyType = ""; };
235 
236 protected:
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) \
249 class IGTLCommon_EXPORT name : public HeaderOnlyMessageBase\
250 { \
251 public: \
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  \
260 protected: \
261  name() : HeaderOnlyMessageBase() { this->m_DefaultBodyType = msgtype; }; \
262  ~name() {}; \
263 };
264 
265 } // namespace igtl
266 
267 #endif // _igtlMessageBase_h
268 
269 
std::string m_DeviceName
A character string for the device name (message name).
A class for header-only message types, which are used for quearying.
HeaderOnlyMessageBase Self
unsigned int m_TimeStampSec
SmartPointer< Self > Pointer
#define igtlTypeMacro(thisClass, superclass)
Definition: igtlMacro.h:486
std::string m_DefaultBodyType
A character string for the default device type (message type).
const char * GetBodyType()
GetBodyType() gets the type of the body.
unsigned char * m_Header
virtual int SetMessageHeader(const MessageHeader *mb)
Sets the message header.
int m_IsBodyUnpacked
Unpacking (desrialization) status for the body (0: – 1: unpacked).
virtual int GetBodyPackSize()
Gets the size of the serialized body.
virtual int GetBodyPackSize()
Gets the size of the serialized body.
SmartPointer< const Self > ConstPointer
virtual int PackBody()
Packs (serialize) the body. Must be implemented in a child class.
#define IGTLCommon_EXPORT
virtual int UnpackBody()
Unpacks (deserialize) the body. Must be implemented in a child class.
unsigned int m_TimeStampSecFraction
std::string m_BodyType
unsigned char * m_Body
int m_IsHeaderUnpacked
Unpacking (desrialization) status for the header (0: – 1: unpacked).
class MessageBase MessageHeader
virtual int UnpackBody()
Unpacks (deserialize) the body. Must be implemented in a child class.
SmartPointer< const Self > ConstPointer
#define igtlNewMacro(x)
Definition: igtlMacro.h:431
virtual int PackBody()
Packs (serialize) the body. Must be implemented in a child class.
SmartPointer< Self > Pointer
Base class for most igtl classes.
Definition: igtlObject.h:60

Generated at Wed Dec 4 2013 11:11:31 for OpenIGTLink by doxygen 1.8.5 written by Dimitri van Heesch, © 1997-2012