Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
igtl::MessageBase Class Reference

#include <igtlMessageBase.h>

Inheritance diagram for igtl::MessageBase:
Inheritance graph
[legend]
Collaboration diagram for igtl::MessageBase:
Collaboration graph
[legend]

Public Types

enum  {
  UNPACK_UNDEF = 0x0000 ,
  UNPACK_HEADER = 0x0001 ,
  UNPACK_BODY = 0x0002
}
 
typedef SmartPointer< const SelfConstPointer
 
typedef SmartPointer< SelfPointer
 
typedef MessageBase Self
 
typedef Object Superclass
 

Public Member Functions

void AllocateBuffer ()
 
void AllocatePack ()
 
int CalculateReceiveContentSize ()
 
virtual igtl::MessageBase::Pointer Clone ()
 
int Copy (const MessageBase *mb)
 
virtual LightObject::Pointer CreateAnother () const
 
virtual void DebugOff () const
 
virtual void DebugOn () const
 
virtual void Delete ()
 
int GetBodySizeToRead ()
 
const charGetBodyType ()
 
voidGetBufferBodyPointer ()
 
int GetBufferBodySize ()
 
voidGetBufferPointer ()
 
int GetBufferSize ()
 
bool GetDebug () const
 
const charGetDeviceName ()
 
std::string GetDeviceName () const
 
const charGetDeviceType ()
 
unsigned short GetHeaderVersion () const
 
std::string GetMessageType () const
 
virtual const charGetNameOfClass () const
 
voidGetPackBodyPointer ()
 
int GetPackBodySize ()
 
voidGetPackPointer ()
 
int GetPackSize ()
 
virtual int GetReferenceCount () const
 
void GetTimeStamp (igtl::TimeStamp::Pointer &ts)
 
int GetTimeStamp (unsigned int *sec, unsigned int *frac)
 
 igtlTypeMacro (Object, LightObject)
 
void InitBuffer ()
 
void InitPack ()
 
virtual int Pack ()
 
void Print (std::ostream &os) const
 
virtual void Register () const
 
void SetDebug (bool debugFlag) const
 
void SetDeviceName (const char *name)
 
void SetDeviceName (const std::string &name)
 
void SetDeviceType (const std::string &type)
 
void SetHeaderVersion (unsigned short headerVersion)
 
virtual int SetMessageHeader (const MessageHeader *mb)
 
virtual void SetReferenceCount (int)
 
void SetTimeStamp (igtl::TimeStamp::Pointer &ts)
 
int SetTimeStamp (unsigned int sec, unsigned int frac)
 
int Unpack (int crccheck=0)
 
virtual void UnRegister () const
 

Static Public Member Functions

static void BreakOnError ()
 
static Pointer New ()
 

Protected Member Functions

virtual void AllocateBuffer (int contentSize)
 
virtual void AllocateUnpack (int bodySizeToRead)
 
virtual int CalculateContentBufferSize ()
 
int CopyBody (const MessageBase *mb)
 
int CopyHeader (const MessageBase *mb)
 
 MessageBase ()
 
virtual int PackContent ()
 
void UnpackBody (int crccheck, int &r)
 
virtual int UnpackContent ()
 
void UnpackHeader (int &r)
 
 ~MessageBase ()
 

Protected Attributes

unsigned charm_Body
 
int m_BodySizeToRead
 
unsigned charm_Content
 
std::string m_DeviceName
 
unsigned charm_Header
 
unsigned short m_HeaderVersion
 
bool m_IsBodyPacked
 
bool m_IsBodyUnpacked
 
bool m_IsHeaderUnpacked
 
int m_MessageSize
 
std::string m_ReceiveMessageType
 
std::string m_SendMessageType
 
unsigned int m_TimeStampSec
 
unsigned int m_TimeStampSecFraction
 
volatile int m_ReferenceCount
 
SimpleFastMutexLock m_ReferenceCountLock
 
virtual void PrintHeader (std::ostream &os) const
 
virtual void PrintTrailer (std::ostream &os) const
 
virtual void PrintSelf (std::ostream &os) const
 
static void SetGlobalWarningDisplay (bool flag)
 
static bool GetGlobalWarningDisplay ()
 
static void GlobalWarningDisplayOn ()
 
static void GlobalWarningDisplayOff ()
 

Detailed Description

The MessageBase class is the base class of all message type classes used in the OpenIGTLink Library. The message classes can be used both for serializing (packing) OpenIGTLink message byte streams. The class can also deserializing (unpacking) OpenIGTLink. For the deserialization example, please refer igtlMessageHeader.h.

The typical packing procedures using sub-classes of MessageBase look like the followings

// Create instance and set Device Name
igtl::TransformMessage::Pointer transMsg;
transMsg = igtl::TransformMessage::New();
transMsg->SetDeviceName("Tracker");

// Create matrix and substitute values
igtl::Matrix4x4 matrix;
GetRandomTestMatrix(matrix);

// Set matrix data, serialize, and send it.
transMsg->SetMatrix(matrix);
transMsg->AllocatePack(); // optional
transMsg->Pack();
socket->Send(transMsg->GetBufferPointer(), transMsg->GetBufferSize());

V1/V2 message structure:
                               GetBodySize()
          /-------------------------/\----------------------------------------------------------\
                               GetPackContentSize() (subclassed)
          /-------------------------------------/\----------------------------------------------\

|____________|_____________________________________________________________________________________| m_Header m_Body

V3 message structure:
                                 GetBodySize()
          /-------------------------/\------------------------------------------------------------\
                                     GetPackContentSize() (subclassed)
                                        /\                (sending after setters are called, receiving after extended header has been parsed)
                              /--------/  \-----------\

|____________|___________________|________________________|___________________|_______________________| m_Header m_ExtendedHeader m_Content (old m_Body) m_MetaDataHeader m_MetaData m_Body

Definition at line 78 of file igtlMessageBase.h.

Member Typedef Documentation

◆ ConstPointer

Definition at line 84 of file igtlMessageBase.h.

◆ Pointer

Definition at line 83 of file igtlMessageBase.h.

◆ Self

Definition at line 81 of file igtlMessageBase.h.

◆ Superclass

Definition at line 82 of file igtlMessageBase.h.

Member Enumeration Documentation

◆ anonymous enum

Unpack status. They are returned by the Unpack() function.

Enumerator
UNPACK_UNDEF 
UNPACK_HEADER 
UNPACK_BODY 

Definition at line 95 of file igtlMessageBase.h.

Constructor & Destructor Documentation

◆ MessageBase()

igtl::MessageBase::MessageBase ( )
protected

◆ ~MessageBase()

igtl::MessageBase::~MessageBase ( )
protected

Member Function Documentation

◆ AllocateBuffer() [1/2]

void igtl::MessageBase::AllocateBuffer ( )

AllocatePack() allocates memory for underlying buffer If m_BodySizeToRead > 0, we are allocating for receiving a message

◆ AllocateBuffer() [2/2]

virtual void igtl::MessageBase::AllocateBuffer ( int  contentSize)
protectedvirtual

Allocates memory specifying the content size. Implicitly allocates extended header, metadata header and metadata in addition to content

Reimplemented in igtl::ImageMessage2.

◆ AllocatePack()

void igtl::MessageBase::AllocatePack ( )
inline

Definition at line 242 of file igtlMessageBase.h.

◆ AllocateUnpack()

virtual void igtl::MessageBase::AllocateUnpack ( int  bodySizeToRead)
protectedvirtual

Allocates memory specifying the unpack content size Size of body to allocate is determined from v1 message header field 'body_size'

◆ BreakOnError()

static void igtl::LightObject::BreakOnError ( )
staticinherited

This method is called when igtlExceptionMacro executes. It allows the debugger to break on error.

◆ CalculateContentBufferSize()

virtual int igtl::MessageBase::CalculateContentBufferSize ( )
protectedvirtual

◆ CalculateReceiveContentSize()

int igtl::MessageBase::CalculateReceiveContentSize ( )

Calculate the size of the received content data Returns -1 if the extended header has not been properly initialized (meta data size, meta data header size, etc...) Used when receiving data, not sending

◆ Clone()

virtual igtl::MessageBase::Pointer igtl::MessageBase::Clone ( )
virtual

Create a clone of this message, new memory but all internals are preserved.

◆ Copy()

int igtl::MessageBase::Copy ( const MessageBase mb)

Copy() copies contents from the specified Massage class. If the type of the specified class is the same as this class, general header and body are copied.

◆ CopyBody()

int igtl::MessageBase::CopyBody ( const MessageBase mb)
protected

Copies the serialized body data.

◆ CopyHeader()

int igtl::MessageBase::CopyHeader ( const MessageBase mb)
protected

Copies a header from given message.

◆ CreateAnother()

virtual LightObject::Pointer igtl::Object::CreateAnother ( ) const
virtualinherited

Create an object from an instance, potentially deferring to a factory. This method allows you to create an instance of an object that is exactly the same type as the referring object. This is useful in cases where an object has been cast back to a base class.

Reimplemented from igtl::LightObject.

◆ DebugOff()

virtual void igtl::Object::DebugOff ( ) const
virtualinherited

Turn debugging output off.

◆ DebugOn()

virtual void igtl::Object::DebugOn ( ) const
virtualinherited

Turn debugging output on.

◆ Delete()

virtual void igtl::LightObject::Delete ( )
virtualinherited

Delete an igtl object. This method should always be used to delete an object when the new operator was used to create it. Using the C delete method will not work with reference counting.

◆ GetBodySizeToRead()

int igtl::MessageBase::GetBodySizeToRead ( )

GetBodySizeToRead() returns the size of the body to be read. This function must be called after the message header is set.

◆ GetBodyType()

const char * igtl::MessageBase::GetBodyType ( )

Gets the type of the body.

◆ GetBufferBodyPointer()

void * igtl::MessageBase::GetBufferBodyPointer ( )

Gets a pointer to the raw byte array for the serialized body data.

◆ GetBufferBodySize()

int igtl::MessageBase::GetBufferBodySize ( )

Gets the size of the serialized body data.

◆ GetBufferPointer()

void * igtl::MessageBase::GetBufferPointer ( )

Gets a pointer to the raw byte array for the serialized data including the header and the body.

◆ GetBufferSize()

int igtl::MessageBase::GetBufferSize ( )

Gets the size of the serialized message data.

◆ GetDebug()

bool igtl::Object::GetDebug ( ) const
inherited

Get the value of the debug flag.

◆ GetDeviceName() [1/2]

const char * igtl::MessageBase::GetDeviceName ( )

Gets the device name.

◆ GetDeviceName() [2/2]

std::string igtl::MessageBase::GetDeviceName ( ) const

Gets the device name.

◆ GetDeviceType()

const char * igtl::MessageBase::GetDeviceType ( )

Gets the device (message) type.

◆ GetGlobalWarningDisplay()

static bool igtl::Object::GetGlobalWarningDisplay ( )
staticinherited

Methods invoked by Print() to print information about the object including superclasses. Typically not called by the user (use Print() instead) but used in the hierarchical print process to combine the output of several classes.

◆ GetHeaderVersion()

unsigned short igtl::MessageBase::GetHeaderVersion ( ) const

Gets the message version number.

◆ GetMessageType()

std::string igtl::MessageBase::GetMessageType ( ) const

Gets the message type.

◆ GetNameOfClass()

virtual const char * igtl::LightObject::GetNameOfClass ( ) const
inlinevirtualinherited

Return the name of this class as a string. Used by the object factory (implemented in New()) to instantiate objects of a named type. Also used for debugging and other output information.

Definition at line 84 of file igtlLightObject.h.

◆ GetPackBodyPointer()

void * igtl::MessageBase::GetPackBodyPointer ( )
inline

Definition at line 218 of file igtlMessageBase.h.

◆ GetPackBodySize()

int igtl::MessageBase::GetPackBodySize ( )
inline

Definition at line 226 of file igtlMessageBase.h.

◆ GetPackPointer()

void * igtl::MessageBase::GetPackPointer ( )
inline

Definition at line 214 of file igtlMessageBase.h.

◆ GetPackSize()

int igtl::MessageBase::GetPackSize ( )
inline

Definition at line 222 of file igtlMessageBase.h.

◆ GetReferenceCount()

virtual int igtl::LightObject::GetReferenceCount ( ) const
inlinevirtualinherited

Gets the reference count on this object.

Definition at line 110 of file igtlLightObject.h.

◆ GetTimeStamp() [1/2]

void igtl::MessageBase::GetTimeStamp ( igtl::TimeStamp::Pointer ts)

Gets time of message creation.

◆ GetTimeStamp() [2/2]

int igtl::MessageBase::GetTimeStamp ( unsigned int sec,
unsigned int frac 
)

Gets time of message creation. 'sec' and 'frac' are seconds and fractions of a second respectively.

◆ GlobalWarningDisplayOff()

static void igtl::Object::GlobalWarningDisplayOff ( )
inlinestaticinherited

Methods invoked by Print() to print information about the object including superclasses. Typically not called by the user (use Print() instead) but used in the hierarchical print process to combine the output of several classes.

Definition at line 116 of file igtlObject.h.

◆ GlobalWarningDisplayOn()

static void igtl::Object::GlobalWarningDisplayOn ( )
inlinestaticinherited

Methods invoked by Print() to print information about the object including superclasses. Typically not called by the user (use Print() instead) but used in the hierarchical print process to combine the output of several classes.

Definition at line 114 of file igtlObject.h.

◆ igtlTypeMacro()

igtl::Object::igtlTypeMacro ( Object  ,
LightObject   
)
inherited

Standard part of all igtl objects.

◆ InitBuffer()

void igtl::MessageBase::InitBuffer ( )

Call InitPack() before receive header. This function simply resets the Unpacked flag for both the header and body pack Only allocate the original 58 byte header

◆ InitPack()

void igtl::MessageBase::InitPack ( )
inline

Definition at line 249 of file igtlMessageBase.h.

◆ New()

static Pointer igtl::Object::New ( )
staticinherited

Method for creation through the object factory.

◆ Pack()

virtual int igtl::MessageBase::Pack ( )
virtual

Pack() serializes the header and body based on the member variables. PackContent() must be implemented in the child class.

Reimplemented in igtl::ImageMessage2.

◆ PackContent()

virtual int igtl::MessageBase::PackContent ( )
protectedvirtual

◆ Print()

void igtl::LightObject::Print ( std::ostream &  os) const
inherited

Cause the object to print itself out.

◆ PrintHeader()

virtual void igtl::LightObject::PrintHeader ( std::ostream &  os) const
protectedvirtualinherited

Number of uses of this object by other objects.

◆ PrintSelf()

virtual void igtl::Object::PrintSelf ( std::ostream &  os) const
protectedvirtualinherited

Methods invoked by Print() to print information about the object including superclasses. Typically not called by the user (use Print() instead) but used in the hierarchical print process to combine the output of several classes.

Reimplemented from igtl::LightObject.

Reimplemented in igtl::ClientSocket, igtl::FastMutexLock, igtl::MultiThreader, igtl::MutexLock, igtl::ObjectFactoryBase, igtl::ServerSocket, igtl::Socket, and igtl::TimeStamp.

◆ PrintTrailer()

virtual void igtl::LightObject::PrintTrailer ( std::ostream &  os) const
protectedvirtualinherited

Number of uses of this object by other objects.

◆ Register()

virtual void igtl::Object::Register ( ) const
virtualinherited

Return this objects modified time.
Update the modification time for this object. Many filters rely on the modification time to determine if they need to recompute their data.
Increase the reference count (mark as used by another object).

Reimplemented from igtl::LightObject.

◆ SetDebug()

void igtl::Object::SetDebug ( bool  debugFlag) const
inherited

Set the value of the debug flag. A non-zero value turns debugging on.

◆ SetDeviceName() [1/2]

void igtl::MessageBase::SetDeviceName ( const char name)

Sets the device name.

◆ SetDeviceName() [2/2]

void igtl::MessageBase::SetDeviceName ( const std::string &  name)

Sets the device name.

◆ SetDeviceType()

void igtl::MessageBase::SetDeviceType ( const std::string &  type)

Sets the device (message) type.

◆ SetGlobalWarningDisplay()

static void igtl::Object::SetGlobalWarningDisplay ( bool  flag)
staticinherited

This is a global flag that controls whether any debug, warning or error messages are displayed.

◆ SetHeaderVersion()

void igtl::MessageBase::SetHeaderVersion ( unsigned short  headerVersion)

Sets the message version number.

◆ SetMessageHeader()

virtual int igtl::MessageBase::SetMessageHeader ( const MessageHeader mb)
virtual

Sets the message header.

Reimplemented in igtl::PositionMessage.

◆ SetReferenceCount()

virtual void igtl::Object::SetReferenceCount ( int  )
virtualinherited

Sets the reference count (use with care)

Reimplemented from igtl::LightObject.

◆ SetTimeStamp() [1/2]

void igtl::MessageBase::SetTimeStamp ( igtl::TimeStamp::Pointer ts)

Sets time of message creation.

◆ SetTimeStamp() [2/2]

int igtl::MessageBase::SetTimeStamp ( unsigned int  sec,
unsigned int  frac 
)

Sets time of message creation. 'sec' and 'frac' are seconds and fractions of a second respectively.

◆ Unpack()

int igtl::MessageBase::Unpack ( int  crccheck = 0)

Unpack() deserializes the header and/or body, extracting data from the byte stream. If the header has already been deserilized, Unpack() deserializes only the body part. UnpackBody() must be implemented to deserialize the body part. Unpack() performs 64-bit CRC check, when crccheck = 1. It returns:

UNPACK_UNDEF : Nothing deserialized UNPACK_HEADER : The header has been deserialized. UNPACK_BODY : The body has been deserialized. If CRC check fails, Unpack() doesn't deserialize the body, thus it doesn't return UNPACK_BODY flag. UNPACK_HEADER|UNPACK_BODY: Both the header and body have been deserialized

◆ UnpackBody()

void igtl::MessageBase::UnpackBody ( int  crccheck,
int r 
)
protected

Unpack the body If it's a v3 message, body is ext header + content + metadataheader + metadata<optional>

◆ UnpackContent()

virtual int igtl::MessageBase::UnpackContent ( )
protectedvirtual

◆ UnpackHeader()

void igtl::MessageBase::UnpackHeader ( int r)
protected

Unpack the first 58 bytes.

◆ UnRegister()

virtual void igtl::Object::UnRegister ( ) const
virtualinherited

Decrease the reference count (release by another object).

Reimplemented from igtl::LightObject.

Member Data Documentation

◆ m_Body

unsigned char* igtl::MessageBase::m_Body
protected

A pointer to the byte array for the serialized body. To prevent large copy of the byte array in the Pack() function, header byte array is concatenated to the byte array for the header.

Definition at line 308 of file igtlMessageBase.h.

◆ m_BodySizeToRead

int igtl::MessageBase::m_BodySizeToRead
protected

The size of the body to be read. This function must be called after the message header is set.

Definition at line 315 of file igtlMessageBase.h.

◆ m_Content

unsigned char* igtl::MessageBase::m_Content
protected

A pointer to the underlying content of a message.

Definition at line 311 of file igtlMessageBase.h.

◆ m_DeviceName

std::string igtl::MessageBase::m_DeviceName
protected

A character string for the device name (message name).

Definition at line 328 of file igtlMessageBase.h.

◆ m_Header

unsigned char* igtl::MessageBase::m_Header
protected

A pointer to the byte array for the serialized header. To prevent large copy of the byte array in the Pack() function, header byte array is concatenated to the byte array for the body.

Definition at line 303 of file igtlMessageBase.h.

◆ m_HeaderVersion

unsigned short igtl::MessageBase::m_HeaderVersion
protected

An unsigned short for the message format version.

Definition at line 325 of file igtlMessageBase.h.

◆ m_IsBodyPacked

bool igtl::MessageBase::m_IsBodyPacked
protected

Packing (serialization) status for the body.

Definition at line 345 of file igtlMessageBase.h.

◆ m_IsBodyUnpacked

bool igtl::MessageBase::m_IsBodyUnpacked
protected

Unpacking (deserialization) status for the body.

Definition at line 342 of file igtlMessageBase.h.

◆ m_IsHeaderUnpacked

bool igtl::MessageBase::m_IsHeaderUnpacked
protected

Unpacking (deserialization) status for the header.

Definition at line 339 of file igtlMessageBase.h.

◆ m_MessageSize

int igtl::MessageBase::m_MessageSize
protected

Definition at line 298 of file igtlMessageBase.h.

◆ m_ReceiveMessageType

std::string igtl::MessageBase::m_ReceiveMessageType
protected

A character string for the device type (message type). This will be used when the header is deserialized from a byte stream received from the network.

Definition at line 322 of file igtlMessageBase.h.

◆ m_ReferenceCount

volatile int igtl::LightObject::m_ReferenceCount
mutableprotectedinherited

Number of uses of this object by other objects.

Definition at line 131 of file igtlLightObject.h.

◆ m_ReferenceCountLock

SimpleFastMutexLock igtl::LightObject::m_ReferenceCountLock
mutableprotectedinherited

Mutex lock to protect modification to the reference count

Definition at line 134 of file igtlLightObject.h.

◆ m_SendMessageType

std::string igtl::MessageBase::m_SendMessageType
protected

A character string for the send device type (message type).

Definition at line 318 of file igtlMessageBase.h.

◆ m_TimeStampSec

unsigned int igtl::MessageBase::m_TimeStampSec
protected

A time stamp (second) for message creation. It consists of fields for seconds (m_TimeStampSec)and fractions of a second (m_TimeStampSecFraction).

Definition at line 332 of file igtlMessageBase.h.

◆ m_TimeStampSecFraction

unsigned int igtl::MessageBase::m_TimeStampSecFraction
protected

A time stamp (second) for message creation. It consists of fields for seconds (m_TimeStampSec)and fractions of a second (m_TimeStampSecFraction).

Definition at line 336 of file igtlMessageBase.h.


The documentation for this class was generated from the following file:

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