16 #include <itksys/SystemTools.hxx> 17 #include <itkMutexLockHolder.h> 19 #include <igtlServerSocket.h> 20 #include <igtlTrackingDataMessage.h> 21 #include <igtlImageMessage.h> 22 #include <igtl_status.h> 42 "Can only try to create a server if in setup mode";
55 m_Socket = igtl::ServerSocket::New();
58 int response =
dynamic_cast<igtl::ServerSocket*
>(
m_Socket.GetPointer())->
59 CreateServer(portNumber);
65 "The server could not be created. Port: " << portNumber;
90 igtl::Socket::Pointer socket;
93 ((igtl::ServerSocket*)(this->
m_Socket.GetPointer()))->WaitForConnection(1);
95 if (socket.IsNotNull())
104 this->InvokeEvent(NewClientConnectionEvent());
105 MITK_INFO(
"IGTLServer") <<
"Connected to a new client: " << socket;
111 unsigned int status = IGTL_STATUS_OK;
125 if (status == IGTL_STATUS_NOT_PRESENT)
129 socketsToBeRemoved.push_back(*it);
130 MITK_WARN(
"IGTLServer") <<
"Lost connection to a client socket. ";
132 else if (status != 1)
134 MITK_DEBUG(
"IGTLServer") <<
"IGTL Message with status: " << status;
138 if (socketsToBeRemoved.size() > 0)
143 this->InvokeEvent(LostConnectionEvent());
150 mitk::IGTLMessage::Pointer curMessage = this->
m_MessageQueue->PullSendMessage();
153 if (curMessage.IsNull())
171 MITK_DEBUG(
"IGTLServer") <<
"Sent IGTL Message";
179 for (
auto i = toBeRemovedSockets.begin(); i != toBeRemovedSockets.end(); i++)
197 MITK_INFO(
"IGTLServer") <<
"Removed client socket from server client list.";
IGTLDeviceState GetState() const
Returns current object state (Setup, Ready or Running)
void Send() override
Call this method to send a message. The message will be read from the queue. So far the message is se...
std::list< igtl::Socket::Pointer > SocketListType
virtual int GetPortNumber()
Returns the port number of the device.
void SetState(IGTLDeviceState state)
change object state
void Connect() override
Call this method to check for other devices that want to connect to this one.
bool OpenConnection() override
Initialize the connection for the IGTLServer.
itk::FastMutexLock::Pointer m_ReceiveListMutex
IGTLServer(bool ReadFully)
unsigned int ReceivePrivate(igtl::Socket *device)
Call this method to receive a message from the given device.
unsigned int SendMessagePrivate(mitk::IGTLMessage::Pointer msg, igtl::Socket::Pointer socket)
Sends a message.
SocketListType::iterator SocketListIteratorType
An object of this class represents an exception of MITK. Please don't instantiate exceptions manually...
virtual bool CloseConnection()
Closes the connection to the device.
bool CloseConnection() override
Closes the connection to the device.
void Receive() override
Call this method to receive a message.
itk::FastMutexLock::Pointer m_SentListMutex
mitk::IGTLMessageQueue::Pointer m_MessageQueue
Interface for all OpenIGTLink Devices.
#define mitkThrowException(classname)
igtl::Socket::Pointer m_Socket
virtual void StopCommunicationWithSocket(SocketListType &toBeRemovedSockets)
Stops the communication with the given sockets.
unsigned int GetNumberOfConnections() override
Returns the number of client connections of this device.
SocketListType m_RegisteredClients
A list with all registered clients.