20 #include "igtlTrackingDataMessage.h"
23 #include <itksys/SystemTools.hxx>
24 #include <itkMutexLockHolder.h>
26 #include <igtlClientSocket.h>
27 #include <igtl_status.h>
42 if (this->GetState() !=
Setup)
45 "Can only try to open the connection if in setup mode. State was " << this->GetState();
49 std::string hostname = this->GetHostname();
50 int portNumber = this->GetPortNumber();
52 if (portNumber == -1 || hostname.size() <= 0)
55 MITK_WARN <<
"Port number or hostname was not correct";
63 int response =
dynamic_cast<igtl::ClientSocket*
>(m_Socket.GetPointer())->
64 ConnectToServer(hostname.c_str(), portNumber);
69 MITK_ERROR <<
"The client could not connect to " << hostname <<
" port: " << portNumber;
74 this->SetState(Ready);
77 this->InvokeEvent(NewClientConnectionEvent());
87 unsigned int status = this->ReceivePrivate(this->m_Socket);
88 if (status == IGTL_STATUS_NOT_PRESENT)
90 this->StopCommunicationWithSocket(this->m_Socket);
92 this->InvokeEvent(LostConnectionEvent());
93 MITK_WARN(
"IGTLClient") <<
"Lost connection to server socket.";
102 curMessage = this->m_MessageQueue->PullSendMessage();
105 if (curMessage.IsNull())
108 if (!this->SendMessagePrivate(curMessage.GetPointer(), this->m_Socket))
110 MITK_WARN(
"IGTLDevice") <<
"Could not send the message.";
116 m_StopCommunicationMutex->Lock();
117 m_StopCommunication =
true;
118 m_StopCommunicationMutex->Unlock();
123 return this->m_Socket->GetConnected();
itk::SmartPointer< Self > Pointer
virtual void Send() override
Call this method to send a message.
virtual unsigned int GetNumberOfConnections() override
Returns the number of connections of this device.
virtual void Receive() override
Call this method to receive a message.
itk::MutexLockHolder< itk::FastMutexLock > MutexLockHolder
An object of this class represents an exception of MITK. Please don't instantiate exceptions manually...
virtual void StopCommunicationWithSocket(igtl::Socket *) override
Stops the communication with the given socket.
Interface for all OpenIGTLink Devices.
#define mitkThrowException(classname)
IGTLClient(bool ReadFully)
virtual bool OpenConnection() override
Establishes the connection between this client and the IGTL server.
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.