MITK-IGT
IGT Extension of MITK
Loading...
Searching...
No Matches
mitk::IGTLDevice Class Referenceabstract

Interface for all OpenIGTLink Devices. More...

#include <mitkIGTLDevice.h>

Inheritance diagram for mitk::IGTLDevice:
mitk::IGTLClient mitk::IGTLServer

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.
 
virtual bool CloseConnection ()
 Closes the connection to the device.
 
virtual bool StopCommunication ()
 Stops the communication between the two devices.
 
bool StartCommunication ()
 Starts the communication between the two devices.
 
void RunCommunication (void(IGTLDevice::*ComFunction)(void), std::mutex &mutex)
 Continuously calls the given function.
 
void SendMessage (mitk::IGTLMessage::Pointer msg)
 Adds the given message to the sending queue.
 
IGTLDeviceState GetState () const
 Returns current object state (Setup, Ready or Running)
 
igtl::MessageBase::Pointer GetNextCommand ()
 Returns the oldest message in the command queue.
 
igtl::ImageMessage::Pointer GetNextImage2dMessage ()
 Returns the oldest message in the receive queue.
 
igtl::ImageMessage::Pointer GetNextImage3dMessage ()
 
igtl::TransformMessage::Pointer GetNextTransformMessage ()
 
igtl::TrackingDataMessage::Pointer GetNextTrackingDataMessage ()
 
igtl::StringMessage::Pointer GetNextStringMessage ()
 
igtl::MessageBase::Pointer GetNextMiscMessage ()
 
 itkSetMacro (PortNumber, int)
 Sets the port number of the device.
 
 itkGetMacro (PortNumber, int)
 Returns the port number of the device.
 
 itkSetMacro (Hostname, std::string)
 Sets the ip/hostname of the device.
 
 itkGetMacro (Hostname, std::string)
 Returns the ip/hostname of the device.
 
 itkGetConstMacro (Name, std::string)
 Returns the name of this device.
 
 itkSetMacro (Name, std::string)
 Sets the name of this device.
 
 itkSetMacro (ReadFully, bool)
 Advises this IGTL Device to always block until the whole message is read.
 
 itkGetConstMacro (MessageQueue, mitk::IGTLMessageQueue::Pointer)
 Returns a const reference to the receive queue.
 
 itkGetMacro (MessageFactory, mitk::IGTLMessageFactory::Pointer)
 Returns the message factory.
 
void ThreadStartSending ()
 start method for the sending thread.
 
void ThreadStartReceiving ()
 start method for the receiving thread.
 
void ThreadStartConnecting ()
 start method for the connection thread.
 
virtual bool TestConnection ()
 TestConnection() tries to connect to a IGTL device on the current ip and port.
 
bool SendRTSMessage (const char *type)
 Send RTS message of given type.
 
void EnableNoBufferingMode (mitk::IGTLMessageQueue::Pointer queue, bool enable=true)
 Sets the buffering mode of the given queue.
 
void EnableNoBufferingMode (bool enable=true)
 
virtual unsigned int GetNumberOfConnections ()=0
 Returns the number of connections of this device.
 
 itkGetMacro (LogMessages, bool)
 
 itkSetMacro (LogMessages, bool)
 

Protected Member Functions

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

Protected Attributes

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

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 62 of file mitkIGTLDevice.h.

Member Enumeration Documentation

◆ IGTLDeviceState

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

Enumerator
Setup 
Ready 
Running 

Definition at line 74 of file mitkIGTLDevice.h.

Constructor & Destructor Documentation

◆ IGTLDevice() [1/2]

mitk::IGTLDevice::IGTLDevice ( bool ReadFully)

Definition at line 41 of file mitkIGTLDevice.cpp.

◆ IGTLDevice() [2/2]

mitk::IGTLDevice::IGTLDevice ( )
protected

◆ ~IGTLDevice()

mitk::IGTLDevice::~IGTLDevice ( )
overrideprotected

Definition at line 62 of file mitkIGTLDevice.cpp.

Member Function Documentation

◆ CloseConnection()

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 388 of file mitkIGTLDevice.cpp.

◆ Connect()

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 431 of file mitkIGTLDevice.cpp.

◆ EnableNoBufferingMode() [1/2]

void mitk::IGTLDevice::EnableNoBufferingMode ( bool enable = true)

Definition at line 471 of file mitkIGTLDevice.cpp.

◆ EnableNoBufferingMode() [2/2]

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

Sets the buffering mode of the given queue.

Definition at line 476 of file mitkIGTLDevice.cpp.

◆ GetNextCommand()

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 467 of file mitkIGTLDevice.cpp.

◆ GetNextImage2dMessage()

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 436 of file mitkIGTLDevice.cpp.

◆ GetNextImage3dMessage()

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

Definition at line 441 of file mitkIGTLDevice.cpp.

◆ GetNextMiscMessage()

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

Definition at line 462 of file mitkIGTLDevice.cpp.

◆ GetNextStringMessage()

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

Definition at line 457 of file mitkIGTLDevice.cpp.

◆ GetNextTrackingDataMessage()

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

Definition at line 451 of file mitkIGTLDevice.cpp.

◆ GetNextTransformMessage()

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

Definition at line 446 of file mitkIGTLDevice.cpp.

◆ GetNumberOfConnections()

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

Returns the number of connections of this device.

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

◆ GetState()

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

Returns current object state (Setup, Ready or Running)

Definition at line 85 of file mitkIGTLDevice.cpp.

◆ itkGetConstMacro() [1/2]

mitk::IGTLDevice::itkGetConstMacro ( MessageQueue ,
mitk::IGTLMessageQueue::Pointer  )

Returns a const reference to the receive queue.

◆ itkGetConstMacro() [2/2]

mitk::IGTLDevice::itkGetConstMacro ( Name ,
std::string  )

Returns the name of this device.

◆ itkGetMacro() [1/4]

mitk::IGTLDevice::itkGetMacro ( Hostname ,
std::string  )

Returns the ip/hostname of the device.

◆ itkGetMacro() [2/4]

mitk::IGTLDevice::itkGetMacro ( LogMessages ,
bool  )

◆ itkGetMacro() [3/4]

mitk::IGTLDevice::itkGetMacro ( MessageFactory ,
mitk::IGTLMessageFactory::Pointer  )

Returns the message factory.

◆ itkGetMacro() [4/4]

mitk::IGTLDevice::itkGetMacro ( PortNumber ,
int  )

Returns the port number of the device.

◆ itkSetMacro() [1/5]

mitk::IGTLDevice::itkSetMacro ( Hostname ,
std::string  )

Sets the ip/hostname of the device.

◆ itkSetMacro() [2/5]

mitk::IGTLDevice::itkSetMacro ( LogMessages ,
bool  )

◆ itkSetMacro() [3/5]

mitk::IGTLDevice::itkSetMacro ( Name ,
std::string  )

Sets the name of this device.

◆ itkSetMacro() [4/5]

mitk::IGTLDevice::itkSetMacro ( PortNumber ,
int  )

Sets the port number of the device.

◆ itkSetMacro() [5/5]

mitk::IGTLDevice::itkSetMacro ( ReadFully ,
bool  )

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

◆ mitkClassMacroItkParent()

mitk::IGTLDevice::mitkClassMacroItkParent ( IGTLDevice ,
itk::Object  )

◆ OpenConnection()

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::IGTLClient, and mitk::IGTLServer.

◆ Receive()

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::IGTLClient, and mitk::IGTLServer.

◆ ReceivePrivate()

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 113 of file mitkIGTLDevice.cpp.

◆ RunCommunication()

void mitk::IGTLDevice::RunCommunication ( void(IGTLDevice::* ComFunction )(void),
std::mutex & 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 290 of file mitkIGTLDevice.cpp.

◆ Send()

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::IGTLClient, and mitk::IGTLServer.

◆ SendMessage()

void mitk::IGTLDevice::SendMessage ( mitk::IGTLMessage::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 255 of file mitkIGTLDevice.cpp.

◆ SendMessagePrivate()

unsigned int mitk::IGTLDevice::SendMessagePrivate ( mitk::IGTLMessage::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 260 of file mitkIGTLDevice.cpp.

◆ SendRTSMessage()

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

Send RTS message of given type.

Definition at line 409 of file mitkIGTLDevice.cpp.

◆ SetState()

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

change object state

Definition at line 91 of file mitkIGTLDevice.cpp.

◆ StartCommunication()

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 337 of file mitkIGTLDevice.cpp.

◆ StopCommunication()

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 366 of file mitkIGTLDevice.cpp.

◆ StopCommunicationWithSocket()

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

Stops the communication with the given socket.

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

◆ TestConnection()

bool mitk::IGTLDevice::TestConnection ( )
virtual

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

Todo
Implement this method. Send a status message and check the answer.

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 108 of file mitkIGTLDevice.cpp.

◆ ThreadStartConnecting()

void mitk::IGTLDevice::ThreadStartConnecting ( )

start method for the connection thread.

Definition at line 493 of file mitkIGTLDevice.cpp.

◆ ThreadStartReceiving()

void mitk::IGTLDevice::ThreadStartReceiving ( )

start method for the receiving thread.

Definition at line 488 of file mitkIGTLDevice.cpp.

◆ ThreadStartSending()

void mitk::IGTLDevice::ThreadStartSending ( )

start method for the sending thread.

Definition at line 483 of file mitkIGTLDevice.cpp.

Member Data Documentation

◆ m_ConnectingFinishedMutex

std::mutex mitk::IGTLDevice::m_ConnectingFinishedMutex
protected

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

Definition at line 338 of file mitkIGTLDevice.h.

◆ m_Hostname

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

the hostname or ip of the device

Definition at line 343 of file mitkIGTLDevice.h.

◆ m_LogMessages

bool mitk::IGTLDevice::m_LogMessages
protected

Definition at line 355 of file mitkIGTLDevice.h.

◆ m_MessageFactory

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

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

Definition at line 353 of file mitkIGTLDevice.h.

◆ m_MessageQueue

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

The message receive queue

Definition at line 350 of file mitkIGTLDevice.h.

◆ m_Name

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

the name of this device

Definition at line 327 of file mitkIGTLDevice.h.

◆ m_PortNumber

int mitk::IGTLDevice::m_PortNumber
protected

the port number of the device

Definition at line 345 of file mitkIGTLDevice.h.

◆ m_ReceivingFinishedMutex

std::mutex mitk::IGTLDevice::m_ReceivingFinishedMutex
protected

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

Definition at line 336 of file mitkIGTLDevice.h.

◆ m_SendingFinishedMutex

std::mutex mitk::IGTLDevice::m_SendingFinishedMutex
protected

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

Definition at line 334 of file mitkIGTLDevice.h.

◆ m_Socket

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

the socket used to communicate with other IGTL devices

Definition at line 347 of file mitkIGTLDevice.h.

◆ m_State

IGTLDeviceState mitk::IGTLDevice::m_State
protected

current object state (Setup, Ready or Running)

Definition at line 325 of file mitkIGTLDevice.h.

◆ m_StateMutex

std::mutex mitk::IGTLDevice::m_StateMutex
mutableprotected

mutex to control access to m_State

Definition at line 340 of file mitkIGTLDevice.h.

◆ m_StopCommunication

bool mitk::IGTLDevice::m_StopCommunication
protected

signal used to stop the thread

Definition at line 330 of file mitkIGTLDevice.h.

◆ m_StopCommunicationMutex

std::mutex mitk::IGTLDevice::m_StopCommunicationMutex
protected

mutex to control access to m_StopCommunication

Definition at line 332 of file mitkIGTLDevice.h.


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