Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitk::IGTLDevice Class Referenceabstract

Interface for all OpenIGTLink Devices. More...

#include <mitkIGTLDevice.h>

Inheritance diagram for mitk::IGTLDevice:
Collaboration diagram for mitk::IGTLDevice:

Public Types

enum  IGTLDeviceState { Setup, Ready, Running }
 Type for state variable. The IGTLDevice is always in one of these states. More...
 

Public Member Functions

 mitkClassMacroItkParent (IGTLDevice, itk::Object) IGTLDevice(bool ReadFully)
 
virtual bool OpenConnection ()=0
 Opens a connection to the device. More...
 
virtual bool CloseConnection ()
 Closes the connection to the device. More...
 
virtual bool StopCommunication ()
 Stops the communication between the two devices. More...
 
bool StartCommunication ()
 Starts the communication between the two devices. More...
 
void RunCommunication (void(IGTLDevice::*ComFunction)(void), itk::FastMutexLock *mutex)
 Continuously calls the given function. More...
 
void SendMessage (igtl::MessageBase::Pointer msg)
 Adds the given message to the sending queue. More...
 
void SendMessage (const IGTLMessage *msg)
 Adds the given message to the sending queue. More...
 
IGTLDeviceState GetState () const
 Returns current object state (Setup, Ready or Running) More...
 
igtl::MessageBase::Pointer GetNextCommand ()
 Returns the oldest message in the command queue. More...
 
igtl::ImageMessage::Pointer GetNextImage2dMessage ()
 Returns the oldest message in the receive queue. More...
 
igtl::ImageMessage::Pointer GetNextImage3dMessage ()
 
igtl::TransformMessage::Pointer GetNextTransformMessage ()
 
igtl::TrackingDataMessage::Pointer GetNextTrackingDataMessage ()
 
igtl::StringMessage::Pointer GetNextStringMessage ()
 
igtl::MessageBase::Pointer GetNextMiscMessage ()
 
virtual void SetPortNumber (int _arg)
 Sets the port number of the device. More...
 
virtual int GetPortNumber ()
 Returns the port number of the device. More...
 
virtual void SetHostname (std::string _arg)
 Sets the ip/hostname of the device. More...
 
virtual std::string GetHostname ()
 Returns the ip/hostname of the device. More...
 
virtual std::string GetName () const
 Returns the name of this device. More...
 
virtual void SetName (std::string _arg)
 Sets the name of this device. More...
 
virtual void SetReadFully (bool _arg)
 Advises this IGTL Device to always block until the whole message is read. More...
 
virtual mitk::IGTLMessageQueue::Pointer GetMessageQueue () const
 Returns a const reference to the receive queue. More...
 
virtual mitk::IGTLMessageFactory::Pointer GetMessageFactory ()
 Returns the message factory. More...
 
virtual bool TestConnection ()
 TestConnection() tries to connect to a IGTL device on the current ip and port. More...
 
bool SendRTSMessage (const char *type)
 Send RTS message of given type. More...
 
void EnableInfiniteBufferingMode (mitk::IGTLMessageQueue::Pointer queue, bool enable=true)
 Sets the buffering mode of the given queue. More...
 
virtual unsigned int GetNumberOfConnections ()=0
 Returns the number of connections of this device. More...
 

Static Public Member Functions

static ITK_THREAD_RETURN_TYPE ThreadStartSending (void *data)
 static start method for the sending thread. More...
 
static ITK_THREAD_RETURN_TYPE ThreadStartReceiving (void *data)
 static start method for the receiving thread. More...
 
static ITK_THREAD_RETURN_TYPE ThreadStartConnecting (void *data)
 static start method for the connection thread. More...
 

Protected Member Functions

unsigned int SendMessagePrivate (igtl::MessageBase::Pointer msg, igtl::Socket::Pointer socket)
 Sends a message. More...
 
virtual void Receive ()=0
 Call this method to receive a message. More...
 
unsigned int ReceivePrivate (igtl::Socket *device)
 Call this method to receive a message from the given device. More...
 
virtual void Send ()=0
 Call this method to send a message. The message will be read from the queue. More...
 
virtual void Connect ()
 Call this method to check for other devices that want to connect to this one. More...
 
virtual void StopCommunicationWithSocket (igtl::Socket *socket)=0
 Stops the communication with the given socket. More...
 
void SetState (IGTLDeviceState state)
 change object state More...
 
 IGTLDevice ()
 
virtual ~IGTLDevice ()
 

Protected Attributes

IGTLDeviceState m_State
 
std::string m_Name
 
bool m_StopCommunication
 
itk::FastMutexLock::Pointer m_StopCommunicationMutex
 
itk::FastMutexLock::Pointer m_SendingFinishedMutex
 
itk::FastMutexLock::Pointer m_ReceivingFinishedMutex
 
itk::FastMutexLock::Pointer m_ConnectingFinishedMutex
 
itk::FastMutexLock::Pointer m_StateMutex
 
std::string m_Hostname
 
int m_PortNumber
 
igtl::Socket::Pointer m_Socket
 
mitk::IGTLMessageQueue::Pointer m_MessageQueue
 
mitk::IGTLMessageFactory::Pointer m_MessageFactory
 

Detailed Description

Interface for all OpenIGTLink Devices.

Defines the methods that are common for all devices using OpenIGTLink. It can open/close a connection, start/stop a communication and send/receive messages.

It uses message queues to store the incoming and outgoing mails. They are configurable, you can set buffering on and off.

The device is in one of three different states: Setup, Ready or Running. Setup is the initial state. From this state on you can call OpenConnection() and arrive in the Ready state. From the Ready state you call StartCommunication() to arrive in the Running state. Now the device is continuosly checking for new connections, receiving messages and sending messages. This runs in a seperate thread. To stop the communication call StopCommunication() (to arrive in Ready state) or CloseConnection() (to arrive in the Setup state).

Definition at line 61 of file mitkIGTLDevice.h.

Member Enumeration Documentation

Type for state variable. The IGTLDevice is always in one of these states.

Enumerator
Setup 
Ready 
Running 

Definition at line 73 of file mitkIGTLDevice.h.

Constructor & Destructor Documentation

mitk::IGTLDevice::~IGTLDevice ( )
protectedvirtual

Definition at line 64 of file mitkIGTLDevice.cpp.

Member Function Documentation

bool mitk::IGTLDevice::CloseConnection ( )
virtual

Closes the connection to the device.

This may only be called if there is currently a connection to the device, but device is not running (e.g. object is in Ready state)

Reimplemented in mitk::IGTLServer.

Definition at line 405 of file mitkIGTLDevice.cpp.

References Setup().

Referenced by mitk::IGTLServer::CloseConnection().

void mitk::IGTLDevice::Connect ( )
protectedvirtual

Call this method to check for other devices that want to connect to this one.

In case of a client this method is doing nothing. In case of a server it is checking for other devices and if there is one it establishes a connection.

Reimplemented in mitk::IGTLServer.

Definition at line 448 of file mitkIGTLDevice.cpp.

References MITK_DEBUG.

Referenced by ThreadStartConnecting().

void mitk::IGTLDevice::EnableInfiniteBufferingMode ( mitk::IGTLMessageQueue::Pointer  queue,
bool  enable = true 
)

Sets the buffering mode of the given queue.

Definition at line 489 of file mitkIGTLDevice.cpp.

virtual std::string mitk::IGTLDevice::GetHostname ( )
virtual

Returns the ip/hostname of the device.

virtual mitk::IGTLMessageFactory::Pointer mitk::IGTLDevice::GetMessageFactory ( )
virtual

Returns the message factory.

virtual mitk::IGTLMessageQueue::Pointer mitk::IGTLDevice::GetMessageQueue ( ) const
virtual

Returns a const reference to the receive queue.

virtual std::string mitk::IGTLDevice::GetName ( ) const
virtual

Returns the name of this device.

igtl::MessageBase::Pointer mitk::IGTLDevice::GetNextCommand ( )

Returns the oldest message in the command queue.

Returns
The oldest message from the command queue.

Definition at line 484 of file mitkIGTLDevice.cpp.

igtl::ImageMessage::Pointer mitk::IGTLDevice::GetNextImage2dMessage ( )

Returns the oldest message in the receive queue.

Returns
The oldest message from the receive queue

Definition at line 453 of file mitkIGTLDevice.cpp.

igtl::ImageMessage::Pointer mitk::IGTLDevice::GetNextImage3dMessage ( )

Definition at line 458 of file mitkIGTLDevice.cpp.

igtl::MessageBase::Pointer mitk::IGTLDevice::GetNextMiscMessage ( )

Definition at line 479 of file mitkIGTLDevice.cpp.

igtl::StringMessage::Pointer mitk::IGTLDevice::GetNextStringMessage ( )

Definition at line 474 of file mitkIGTLDevice.cpp.

igtl::TrackingDataMessage::Pointer mitk::IGTLDevice::GetNextTrackingDataMessage ( )

Definition at line 468 of file mitkIGTLDevice.cpp.

igtl::TransformMessage::Pointer mitk::IGTLDevice::GetNextTransformMessage ( )

Definition at line 463 of file mitkIGTLDevice.cpp.

virtual unsigned int mitk::IGTLDevice::GetNumberOfConnections ( )
pure virtual

Returns the number of connections of this device.

Implemented in mitk::IGTLServer, and mitk::IGTLClient.

virtual int mitk::IGTLDevice::GetPortNumber ( )
virtual

Returns the port number of the device.

mitk::IGTLDevice::IGTLDeviceState mitk::IGTLDevice::GetState ( ) const

Returns current object state (Setup, Ready or Running)

Definition at line 95 of file mitkIGTLDevice.cpp.

mitk::IGTLDevice::mitkClassMacroItkParent ( IGTLDevice  ,
itk::Object   
)
virtual bool mitk::IGTLDevice::OpenConnection ( )
pure virtual

Opens a connection to the device.

This may only be called if there is currently no connection to the device. If OpenConnection() is successful, the object will change from Setup state to Ready state.

Implemented in mitk::IGTLServer, and mitk::IGTLClient.

virtual void mitk::IGTLDevice::Receive ( )
protectedpure virtual

Call this method to receive a message.

The message will be saved in the receive queue.

Implemented in mitk::IGTLServer, and mitk::IGTLClient.

Referenced by ThreadStartReceiving().

unsigned int mitk::IGTLDevice::ReceivePrivate ( igtl::Socket *  device)
protected

Call this method to receive a message from the given device.

The message will be saved in the receive queue.

Parameters
devicethe socket that connects this device with the other one.
Return values
IGTL_STATUS_OKa message or a command was received
IGTL_STATUS_NOT_PRESENTthe socket is not connected anymore
IGTL_STATUS_TIME_OUTthe socket timed out
IGTL_STATUS_CHECKSUM_ERRORthe checksum of the received msg was incorrect
IGTL_STATUS_UNKNOWN_ERRORan unknown error occurred

Definition at line 123 of file mitkIGTLDevice.cpp.

References MITK_ERROR, MITK_INFO, and mitk::New().

void mitk::IGTLDevice::RunCommunication ( void(IGTLDevice::*)(void)  ComFunction,
itk::FastMutexLock *  mutex 
)

Continuously calls the given function.

This may only be called if the device is in Running state and only from a seperate thread.

Parameters
ComFunctionfunction pointer that specifies the method to be executed
mutexthe mutex that corresponds to the function pointer

Definition at line 304 of file mitkIGTLDevice.cpp.

References MITK_DEBUG, and MITK_ERROR.

Referenced by ThreadStartConnecting(), ThreadStartReceiving(), and ThreadStartSending().

virtual void mitk::IGTLDevice::Send ( )
protectedpure virtual

Call this method to send a message. The message will be read from the queue.

Implemented in mitk::IGTLServer, and mitk::IGTLClient.

Referenced by ThreadStartSending().

void mitk::IGTLDevice::SendMessage ( igtl::MessageBase::Pointer  msg)

Adds the given message to the sending queue.

This may only be called after the connection to the device has been established with a call to OpenConnection(). Note that the message is not send directly. This method just adds it to the send queue.

Parameters
msgThe message to be added to the sending queue

Definition at line 268 of file mitkIGTLDevice.cpp.

void mitk::IGTLDevice::SendMessage ( const IGTLMessage msg)

Adds the given message to the sending queue.

Convenience function to work with mitk::IGTLMessage directly.

Parameters
msgThe message to be added to the sending queue

Definition at line 263 of file mitkIGTLDevice.cpp.

References mitk::IGTLMessage::GetMessage().

unsigned int mitk::IGTLDevice::SendMessagePrivate ( igtl::MessageBase::Pointer  msg,
igtl::Socket::Pointer  socket 
)
protected

Sends a message.

This may only be called after the connection to the device has been established with a call to OpenConnection(). This method uses the given socket to send the given MessageReceivedEvent

Parameters
msgthe message to be sent
socketthe socket used to communicate with the other device
Return values
IGTL_STATUS_OKthe message was sent
IGTL_STATUS_UNKONWN_ERRORthe message was not sent because an unknown error occurred

Definition at line 274 of file mitkIGTLDevice.cpp.

References GetName(), and MITK_ERROR.

bool mitk::IGTLDevice::SendRTSMessage ( const char *  type)

Send RTS message of given type.

Definition at line 426 of file mitkIGTLDevice.cpp.

virtual void mitk::IGTLDevice::SetHostname ( std::string  _arg)
virtual

Sets the ip/hostname of the device.

virtual void mitk::IGTLDevice::SetName ( std::string  _arg)
virtual

Sets the name of this device.

virtual void mitk::IGTLDevice::SetPortNumber ( int  _arg)
virtual

Sets the port number of the device.

virtual void mitk::IGTLDevice::SetReadFully ( bool  _arg)
virtual

Advises this IGTL Device to always block until the whole message is read.

void mitk::IGTLDevice::SetState ( IGTLDeviceState  state)
protected

change object state

Definition at line 101 of file mitkIGTLDevice.cpp.

bool mitk::IGTLDevice::StartCommunication ( )

Starts the communication between the two devices.

This may only be called if the device is in Ready state.

Definition at line 351 of file mitkIGTLDevice.cpp.

References SOCKET_SEND_RECEIVE_TIMEOUT_MSEC.

bool mitk::IGTLDevice::StopCommunication ( )
virtual

Stops the communication between the two devices.

This may only be called if the device is in Running state.

Definition at line 383 of file mitkIGTLDevice.cpp.

virtual void mitk::IGTLDevice::StopCommunicationWithSocket ( igtl::Socket *  socket)
protectedpure virtual

Stops the communication with the given socket.

Implemented in mitk::IGTLServer, and mitk::IGTLClient.

bool mitk::IGTLDevice::TestConnection ( )
virtual

TestConnection() tries to connect to a IGTL device on the current ip and port.

TestConnection() tries to connect to a IGTL server on the current ip and port and returns which device it has found.

Returns
It returns the type of the device that answers. Throws an exception if no device is available on that ip/port.
Exceptions
mitk::ExceptionThrows an exception if there are errors while connecting to the device.

Definition at line 118 of file mitkIGTLDevice.cpp.

ITK_THREAD_RETURN_TYPE mitk::IGTLDevice::ThreadStartConnecting ( void *  data)
static

static start method for the connection thread.

Parameters
dataa void pointer to the IGTLDevice object.

Definition at line 541 of file mitkIGTLDevice.cpp.

References Connect(), m_ConnectingFinishedMutex, and RunCommunication().

ITK_THREAD_RETURN_TYPE mitk::IGTLDevice::ThreadStartReceiving ( void *  data)
static

static start method for the receiving thread.

Parameters
dataa void pointer to the IGTLDevice object.

Definition at line 518 of file mitkIGTLDevice.cpp.

References m_ReceivingFinishedMutex, Receive(), and RunCommunication().

ITK_THREAD_RETURN_TYPE mitk::IGTLDevice::ThreadStartSending ( void *  data)
static

static start method for the sending thread.

Parameters
dataa void pointer to the IGTLDevice object.

Definition at line 496 of file mitkIGTLDevice.cpp.

References m_SendingFinishedMutex, RunCommunication(), and Send().

Member Data Documentation

itk::FastMutexLock::Pointer mitk::IGTLDevice::m_ConnectingFinishedMutex
protected

mutex used to make sure that the connect thread is just started once

Definition at line 342 of file mitkIGTLDevice.h.

Referenced by IGTLDevice(), and ThreadStartConnecting().

std::string mitk::IGTLDevice::m_Hostname
protected

the hostname or ip of the device

Definition at line 347 of file mitkIGTLDevice.h.

mitk::IGTLMessageFactory::Pointer mitk::IGTLDevice::m_MessageFactory
protected

A message factory that provides the New() method for all msg types

Definition at line 357 of file mitkIGTLDevice.h.

Referenced by IGTLDevice().

mitk::IGTLMessageQueue::Pointer mitk::IGTLDevice::m_MessageQueue
protected

The message receive queue

Definition at line 354 of file mitkIGTLDevice.h.

Referenced by IGTLDevice().

std::string mitk::IGTLDevice::m_Name
protected

the name of this device

Definition at line 331 of file mitkIGTLDevice.h.

int mitk::IGTLDevice::m_PortNumber
protected

the port number of the device

Definition at line 349 of file mitkIGTLDevice.h.

itk::FastMutexLock::Pointer mitk::IGTLDevice::m_ReceivingFinishedMutex
protected

mutex used to make sure that the receive thread is just started once

Definition at line 340 of file mitkIGTLDevice.h.

Referenced by IGTLDevice(), and ThreadStartReceiving().

itk::FastMutexLock::Pointer mitk::IGTLDevice::m_SendingFinishedMutex
protected

mutex used to make sure that the send thread is just started once

Definition at line 338 of file mitkIGTLDevice.h.

Referenced by IGTLDevice(), and ThreadStartSending().

igtl::Socket::Pointer mitk::IGTLDevice::m_Socket
protected

the socket used to communicate with other IGTL devices

Definition at line 351 of file mitkIGTLDevice.h.

IGTLDeviceState mitk::IGTLDevice::m_State
protected

current object state (Setup, Ready or Running)

Definition at line 329 of file mitkIGTLDevice.h.

itk::FastMutexLock::Pointer mitk::IGTLDevice::m_StateMutex
protected

mutex to control access to m_State

Definition at line 344 of file mitkIGTLDevice.h.

Referenced by IGTLDevice().

bool mitk::IGTLDevice::m_StopCommunication
protected

signal used to stop the thread

Definition at line 334 of file mitkIGTLDevice.h.

itk::FastMutexLock::Pointer mitk::IGTLDevice::m_StopCommunicationMutex
protected

mutex to control access to m_StopCommunication

Definition at line 336 of file mitkIGTLDevice.h.

Referenced by IGTLDevice().


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