OpenWalnut  1.5.0dev
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | Private Attributes | List of all members
WIGTLinkRemote Class Reference

Common base class for a IGT Link connection. More...

#include <WIGTLinkRemote.h>

+ Inheritance diagram for WIGTLinkRemote:
+ Collaboration diagram for WIGTLinkRemote:

Public Member Functions

void createSocketAndWaitForConnection (uint32_t port)
 Use this as a server that waits for client connections. More...
 
void createSocketAndConnect (std::string server, uint32_t port)
 Use this as a client that connects to a remote server. More...
 
void readDataLoop ()
 main loop for reading More...
 
void receiveTransform (igtl::MessageHeader::Pointer headerMsg)
 Receive a transform. More...
 
WDataSetScalarSPtr receiveImage (igtl::MessageHeader::Pointer headerMsg)
 Receive an image. More...
 
void injectMessage ()
 TODO: inject a message in the send queue. More...
 
void sendImageMetaData (const std::vector< WDataSetScalarSPtr > &dataSets)
 Send metadata of a list of data sets. More...
 
void sendImageData (WDataSetScalarSPtr dataSetScalar)
 Send image data of a single data set. More...
 
void sendTransform (const std::string &name, const WMatrix< double > &matrix)
 send a matrix as an igtl transform More...
 
std::shared_ptr< WValueSetBasecreateValueSet (const igtl::ImageMessage::Pointer &imgMsg)
 Internal helper to create a value set from a message. More...
 
void setCheckCRC (bool doCheckCRC=true)
 Set whether we check the CRC. More...
 
void listenLoop ()
 setup listening socket and listen More...
 
void sendImageMetaData (std::vector< WDataSetScalarSPtr > dataSets)
 Send a message containing the metadata of the data sets. More...
 
- Public Member Functions inherited from WThreadedRunner
 WThreadedRunner ()
 Default constructor. More...
 
virtual ~WThreadedRunner ()
 Destructor. More...
 
virtual void run ()
 Run thread. More...
 
void run (THREADFUNCTION f)
 Run thread. More...
 
void wait (bool requestFinish=false)
 Wait for the thread to be finished. More...
 
virtual void requestStop ()
 This method's purpose is to request a stop without waiting for it. More...
 
virtual boost::signals2::connection subscribeSignal (THREAD_SIGNAL signal, t_ThreadErrorSignalHandlerType notifier)
 Connects a specified notify function with a signal this thread instance is offering. More...
 
const WBoolFlagisCrashed () const
 Checks whether this thread has been crashed. More...
 
const std::string & getCrashMessage () const
 Get the message of the exception finally causing the crash. More...
 
void setThreadName (std::string name)
 Set the name of the thread. More...
 
std::string getThreadName () const
 Returns the current thread name. More...
 

Public Attributes

boost::mutex receiversMutex
 mutex has to be locked during access to receiveQueue More...
 
std::shared_ptr< WConditionreceiversCondition
 condition to notify receivers that new data is waiting More...
 
std::shared_ptr< WConditionstatusCondition
 condition to notify a status change More...
 
std::queue< WDataSetScalarSPtr > receiveQueue
 queue of received data sets that should be read by the module More...
 

Protected Member Functions

virtual void threadMain ()
 the main thread doing passive connections or receiving data More...
 
- Protected Member Functions inherited from WThreadedRunner
virtual void notifyStop ()
 Gets called when the thread should be stopped. More...
 
void yield () const
 Give remaining execution timeslice to another thread. More...
 
void sleep (const int32_t t) const
 Sets thread asleep. More...
 
void msleep (const int32_t t) const
 Sets thread asleep. More...
 
void waitForStop ()
 Let the thread sleep until a stop request was given. More...
 
virtual void onThreadException (const WException &e)
 This method is called if an exception was caught, which came from the custom thread code. More...
 
void handleDeadlyException (const WException &e, std::string sender="WThreadedRunner")
 Handle the specified exception which was not caught in the thread, which basically means the thread has crashed. More...
 

Protected Attributes

bool checkCRC
 true if we check CRC sums in incoming packets More...
 
uint32_t port
 the port for listening connections More...
 
- Protected Attributes inherited from WThreadedRunner
boost::thread m_thread
 Thread instance. More...
 
WBoolFlag m_shutdownFlag
 Condition getting fired whenever the thread should quit. More...
 
WBoolFlag m_isCrashed
 True whenever an exception is thrown during threadMain. More...
 
std::string m_crashMessage
 The crash message. More...
 

Private Attributes

igtl::ClientSocket::Pointer socket
 Points to the socket used by this connection. More...
 

Additional Inherited Members

- Public Types inherited from WThreadedRunner
typedef std::shared_ptr< WThreadedRunnerSPtr
 Abbreviation to a shared_ptr to this type. More...
 
typedef std::shared_ptr< const WThreadedRunnerConstSPtr
 Abbreviation to a const shared_ptr to this type. More...
 
typedef boost::function< void(void) > THREADFUNCTION
 Type used for simple thread functions. More...
 
- Static Public Member Functions inherited from WThreadedRunner
static void setThisThreadName (std::string name)
 Static function to set the name of the calling thread. More...
 

Detailed Description

Common base class for a IGT Link connection.

Provides some helper functions to handle and convert OW data.

Definition at line 53 of file WIGTLinkRemote.h.

Member Function Documentation

◆ createSocketAndConnect()

void WIGTLinkRemote::createSocketAndConnect ( std::string  server,
uint32_t  port 
)

Use this as a client that connects to a remote server.

Parameters
serverName of the remote server.
portPort number for the connection.

Definition at line 67 of file WIGTLinkRemote.cpp.

References port, socket, and statusCondition.

◆ createSocketAndWaitForConnection()

void WIGTLinkRemote::createSocketAndWaitForConnection ( uint32_t  port)

Use this as a server that waits for client connections.

Parameters
portPort number for the connection

Definition at line 62 of file WIGTLinkRemote.cpp.

References port.

◆ createValueSet()

std::shared_ptr< WValueSetBase > WIGTLinkRemote::createValueSet ( const igtl::ImageMessage::Pointer &  imgMsg)

Internal helper to create a value set from a message.

Parameters
imgMsgThe image behind this pointer is used to create the dataset
Returns
Created value set.

Definition at line 514 of file WIGTLinkRemote.cpp.

Referenced by receiveImage().

+ Here is the caller graph for this function:

◆ injectMessage()

void WIGTLinkRemote::injectMessage ( )

TODO: inject a message in the send queue.

Definition at line 270 of file WIGTLinkRemote.cpp.

◆ listenLoop()

void WIGTLinkRemote::listenLoop ( )

setup listening socket and listen

Definition at line 86 of file WIGTLinkRemote.cpp.

References WThreadedRunner::m_shutdownFlag, port, socket, and statusCondition.

Referenced by readDataLoop().

+ Here is the caller graph for this function:

◆ readDataLoop()

void WIGTLinkRemote::readDataLoop ( )

main loop for reading

Definition at line 103 of file WIGTLinkRemote.cpp.

References checkCRC, listenLoop(), WThreadedRunner::m_shutdownFlag, port, receiveImage(), receiveQueue, receiversCondition, receiversMutex, receiveTransform(), and socket.

Referenced by threadMain().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ receiveImage()

WDataSetScalarSPtr WIGTLinkRemote::receiveImage ( igtl::MessageHeader::Pointer  headerMsg)

Receive an image.

Parameters
headerMsgThe image in this message is used to create a dataset
Returns
Dataset created from message.

Definition at line 217 of file WIGTLinkRemote.cpp.

References checkCRC, createValueSet(), and socket.

Referenced by readDataLoop().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ receiveTransform()

void WIGTLinkRemote::receiveTransform ( igtl::MessageHeader::Pointer  headerMsg)

Receive a transform.

Parameters
headerMsgThe message conatining the transform.

Definition at line 192 of file WIGTLinkRemote.cpp.

References checkCRC, and socket.

Referenced by readDataLoop().

+ Here is the caller graph for this function:

◆ sendImageData()

void WIGTLinkRemote::sendImageData ( WDataSetScalarSPtr  dataSetScalar)

Send image data of a single data set.

Parameters
dataSetScalarPointer to the dataset we want to send

Definition at line 425 of file WIGTLinkRemote.cpp.

◆ sendImageMetaData() [1/2]

void WIGTLinkRemote::sendImageMetaData ( const std::vector< WDataSetScalarSPtr > &  dataSets)

Send metadata of a list of data sets.

Parameters
dataSetsA vector containing pointer to the datasets whose metadata we want to send.

Definition at line 322 of file WIGTLinkRemote.cpp.

References socket.

◆ sendImageMetaData() [2/2]

void WIGTLinkRemote::sendImageMetaData ( std::vector< WDataSetScalarSPtr >  dataSets)

Send a message containing the metadata of the data sets.

Parameters
dataSetsA vector containing pointers to the datasets whose metadata we want to send.

◆ sendTransform()

void WIGTLinkRemote::sendTransform ( const std::string &  name,
const WMatrix< double > &  matrix 
)

send a matrix as an igtl transform

Parameters
namethe name to use for the transform
matrixthe matrix that will be send
Precondition
: socket is valid. If not, nothing will be sent and no error will be reported.

Definition at line 274 of file WIGTLinkRemote.cpp.

References socket.

◆ setCheckCRC()

void WIGTLinkRemote::setCheckCRC ( bool  doCheckCRC = true)
inline

Set whether we check the CRC.

Otherwise, we just ignore it while unpacking the data. The default for checkCRC is false, so there is no CRC checking when this function has not been called.

Parameters
doCheckCRCShould CRC of the data be checked?

Definition at line 137 of file WIGTLinkRemote.h.

References checkCRC.

◆ threadMain()

void WIGTLinkRemote::threadMain ( )
protectedvirtual

the main thread doing passive connections or receiving data

Reimplemented from WThreadedRunner.

Definition at line 81 of file WIGTLinkRemote.cpp.

References readDataLoop().

+ Here is the call graph for this function:

Member Data Documentation

◆ checkCRC

bool WIGTLinkRemote::checkCRC
protected

true if we check CRC sums in incoming packets

Definition at line 181 of file WIGTLinkRemote.h.

Referenced by readDataLoop(), receiveImage(), receiveTransform(), and setCheckCRC().

◆ port

uint32_t WIGTLinkRemote::port
protected

the port for listening connections

Definition at line 184 of file WIGTLinkRemote.h.

Referenced by createSocketAndConnect(), createSocketAndWaitForConnection(), listenLoop(), and readDataLoop().

◆ receiveQueue

std::queue< WDataSetScalarSPtr > WIGTLinkRemote::receiveQueue

queue of received data sets that should be read by the module

Definition at line 172 of file WIGTLinkRemote.h.

Referenced by readDataLoop().

◆ receiversCondition

std::shared_ptr< WCondition > WIGTLinkRemote::receiversCondition

condition to notify receivers that new data is waiting

Definition at line 162 of file WIGTLinkRemote.h.

Referenced by readDataLoop().

◆ receiversMutex

boost::mutex WIGTLinkRemote::receiversMutex

mutex has to be locked during access to receiveQueue

Definition at line 157 of file WIGTLinkRemote.h.

Referenced by readDataLoop().

◆ socket

igtl::ClientSocket::Pointer WIGTLinkRemote::socket
private

Points to the socket used by this connection.

Definition at line 189 of file WIGTLinkRemote.h.

Referenced by createSocketAndConnect(), listenLoop(), readDataLoop(), receiveImage(), receiveTransform(), sendImageMetaData(), and sendTransform().

◆ statusCondition

std::shared_ptr< WCondition > WIGTLinkRemote::statusCondition

condition to notify a status change

Definition at line 167 of file WIGTLinkRemote.h.

Referenced by createSocketAndConnect(), and listenLoop().


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