Medical Imaging Interaction Toolkit  2018.4.99-bd7b41ba
Medical Imaging Interaction Toolkit
mitk::IGTLServer Class Reference

Superclass for OpenIGTLink server. More...

#include <mitkIGTLServer.h>

Inheritance diagram for mitk::IGTLServer:
Collaboration diagram for mitk::IGTLServer:

Public Types

typedef std::list< igtl::Socket::Pointer > SocketListType
 
typedef SocketListType::iterator SocketListIteratorType
 
- Public Types inherited from mitk::IGTLDevice
enum  IGTLDeviceState { Setup, Ready, Running }
 Type for state variable. The IGTLDevice is always in one of these states. More...
 

Public Member Functions

 mitkClassMacro (IGTLServer, IGTLDevice)
 
 mitkNewMacro1Param (Self, bool)
 
Pointer Clone () const
 
bool OpenConnection () override
 Initialize the connection for the IGTLServer. More...
 
bool CloseConnection () override
 Closes the connection to the device. More...
 
unsigned int GetNumberOfConnections () override
 Returns the number of client connections of this device. More...
 
- Public Member Functions inherited from mitk::IGTLDevice
 mitkClassMacroItkParent (IGTLDevice, itk::Object)
 
 IGTLDevice (bool ReadFully)
 
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 (mitk::IGTLMessage::Pointer 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 EnableNoBufferingMode (mitk::IGTLMessageQueue::Pointer queue, bool enable=true)
 Sets the buffering mode of the given queue. More...
 
void EnableNoBufferingMode (bool enable=true)
 
virtual bool GetLogMessages ()
 
virtual void SetLogMessages (bool _arg)
 

Protected Member Functions

 IGTLServer (bool ReadFully)
 
 ~IGTLServer () override
 
void Connect () override
 Call this method to check for other devices that want to connect to this one. More...
 
void Receive () override
 Call this method to receive a message. More...
 
void Send () override
 Call this method to send a message. The message will be read from the queue. So far the message is send to all connected sockets (broadcast). More...
 
virtual void StopCommunicationWithSocket (SocketListType &toBeRemovedSockets)
 Stops the communication with the given sockets. More...
 
void StopCommunicationWithSocket (igtl::Socket *client) override
 Stops the communication with the given socket. More...
 
- Protected Member Functions inherited from mitk::IGTLDevice
unsigned int SendMessagePrivate (mitk::IGTLMessage::Pointer msg, igtl::Socket::Pointer socket)
 Sends a message. More...
 
unsigned int ReceivePrivate (igtl::Socket *device)
 Call this method to receive a message from the given device. More...
 
void SetState (IGTLDeviceState state)
 change object state More...
 
 IGTLDevice ()
 
 ~IGTLDevice () override
 

Protected Attributes

SocketListType m_RegisteredClients
 A list with all registered clients. More...
 
itk::FastMutexLock::Pointer m_ReceiveListMutex
 
itk::FastMutexLock::Pointer m_SentListMutex
 
- Protected Attributes inherited from mitk::IGTLDevice
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
 
bool m_LogMessages
 

Additional Inherited Members

- Static Public Member Functions inherited from mitk::IGTLDevice
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...
 

Detailed Description

Superclass for OpenIGTLink server.

Implements the IGTLDevice interface for IGTLServers. In certain points it behaves different than the IGTLClient. The client connects directly to a server (it cannot connect to two different servers) while the server can connect to several clients. Therefore, it is necessary for the server to have a list with registered sockets.

Definition at line 33 of file mitkIGTLServer.h.

Member Typedef Documentation

◆ SocketListIteratorType

typedef SocketListType::iterator mitk::IGTLServer::SocketListIteratorType

Definition at line 41 of file mitkIGTLServer.h.

◆ SocketListType

typedef std::list<igtl::Socket::Pointer> mitk::IGTLServer::SocketListType

Definition at line 38 of file mitkIGTLServer.h.

Constructor & Destructor Documentation

◆ IGTLServer()

mitk::IGTLServer::IGTLServer ( bool  ReadFully)
protected

Constructor

Definition at line 24 of file mitkIGTLServer.cpp.

References m_ReceiveListMutex, and m_SentListMutex.

◆ ~IGTLServer()

mitk::IGTLServer::~IGTLServer ( )
overrideprotected

Destructor

Definition at line 31 of file mitkIGTLServer.cpp.

References m_ReceiveListMutex, and m_SentListMutex.

Member Function Documentation

◆ Clone()

Pointer mitk::IGTLServer::Clone ( ) const

◆ CloseConnection()

bool mitk::IGTLServer::CloseConnection ( )
overridevirtual

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 from mitk::IGTLDevice.

Definition at line 75 of file mitkIGTLServer.cpp.

References mitk::IGTLDevice::CloseConnection(), m_ReceiveListMutex, m_RegisteredClients, m_SentListMutex, and StopCommunicationWithSocket().

◆ Connect()

void mitk::IGTLServer::Connect ( )
overrideprotectedvirtual

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 and adds the socket to m_RegisteredClients.

Reimplemented from mitk::IGTLDevice.

Definition at line 88 of file mitkIGTLServer.cpp.

References m_ReceiveListMutex, m_RegisteredClients, m_SentListMutex, mitk::IGTLDevice::m_Socket, and MITK_INFO.

◆ GetNumberOfConnections()

unsigned int mitk::IGTLServer::GetNumberOfConnections ( )
overridevirtual

Returns the number of client connections of this device.

Implements mitk::IGTLDevice.

Definition at line 209 of file mitkIGTLServer.cpp.

References m_RegisteredClients.

◆ mitkClassMacro()

mitk::IGTLServer::mitkClassMacro ( IGTLServer  ,
IGTLDevice   
)

◆ mitkNewMacro1Param()

mitk::IGTLServer::mitkNewMacro1Param ( Self  ,
bool   
)

◆ OpenConnection()

bool mitk::IGTLServer::OpenConnection ( )
overridevirtual

Initialize the connection for the IGTLServer.

OpenConnection() starts the IGTLServer socket so that clients can connect to it.

Exceptions
mitk::ExceptionThrows an exception if the given port is occupied.

Implements mitk::IGTLDevice.

Definition at line 37 of file mitkIGTLServer.cpp.

References mitk::IGTLDevice::GetPortNumber(), mitk::IGTLDevice::GetState(), mitk::IGTLDevice::m_Socket, mitkThrowException, mitk::IGTLDevice::Ready, mitk::IGTLDevice::SetState(), and mitk::IGTLDevice::Setup.

◆ Receive()

void mitk::IGTLServer::Receive ( )
overrideprotectedvirtual

Call this method to receive a message.

The message will be saved in the receive queue.

Implements mitk::IGTLDevice.

Definition at line 109 of file mitkIGTLServer.cpp.

References m_ReceiveListMutex, m_RegisteredClients, MITK_DEBUG, MITK_WARN, mitk::IGTLDevice::ReceivePrivate(), and StopCommunicationWithSocket().

◆ Send()

void mitk::IGTLServer::Send ( )
overrideprotectedvirtual

Call this method to send a message. The message will be read from the queue. So far the message is send to all connected sockets (broadcast).

Implements mitk::IGTLDevice.

Definition at line 147 of file mitkIGTLServer.cpp.

References mitk::IGTLDevice::m_MessageQueue, m_RegisteredClients, m_SentListMutex, MITK_DEBUG, and mitk::IGTLDevice::SendMessagePrivate().

◆ StopCommunicationWithSocket() [1/2]

void mitk::IGTLServer::StopCommunicationWithSocket ( SocketListType toBeRemovedSockets)
protectedvirtual

Stops the communication with the given sockets.

This method removes the given sockets from the registered clients list

Definition at line 176 of file mitkIGTLServer.cpp.

Referenced by CloseConnection(), and Receive().

◆ StopCommunicationWithSocket() [2/2]

void mitk::IGTLServer::StopCommunicationWithSocket ( igtl::Socket *  client)
overrideprotectedvirtual

Stops the communication with the given socket.

This method removes the given socket from the registered clients list

Implements mitk::IGTLDevice.

Definition at line 183 of file mitkIGTLServer.cpp.

References m_ReceiveListMutex, m_RegisteredClients, m_SentListMutex, and MITK_INFO.

Member Data Documentation

◆ m_ReceiveListMutex

itk::FastMutexLock::Pointer mitk::IGTLServer::m_ReceiveListMutex
protected

mutex to control access to m_RegisteredClients

Definition at line 118 of file mitkIGTLServer.h.

Referenced by CloseConnection(), Connect(), IGTLServer(), Receive(), StopCommunicationWithSocket(), and ~IGTLServer().

◆ m_RegisteredClients

SocketListType mitk::IGTLServer::m_RegisteredClients
protected

A list with all registered clients.

Definition at line 115 of file mitkIGTLServer.h.

Referenced by CloseConnection(), Connect(), GetNumberOfConnections(), Receive(), Send(), and StopCommunicationWithSocket().

◆ m_SentListMutex

itk::FastMutexLock::Pointer mitk::IGTLServer::m_SentListMutex
protected

mutex to control access to m_RegisteredClients

Definition at line 121 of file mitkIGTLServer.h.

Referenced by CloseConnection(), Connect(), IGTLServer(), Send(), StopCommunicationWithSocket(), and ~IGTLServer().


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