OpenWalnut
1.5.0dev
|
Common base class for a IGT Link connection. More...
#include <WIGTLinkRemote.h>
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< WValueSetBase > | createValueSet (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 WBoolFlag & | isCrashed () 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< WCondition > | receiversCondition |
condition to notify receivers that new data is waiting More... | |
std::shared_ptr< WCondition > | statusCondition |
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< WThreadedRunner > | SPtr |
Abbreviation to a shared_ptr to this type. More... | |
typedef std::shared_ptr< const WThreadedRunner > | ConstSPtr |
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... | |
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.
void WIGTLinkRemote::createSocketAndConnect | ( | std::string | server, |
uint32_t | port | ||
) |
Use this as a client that connects to a remote server.
server | Name of the remote server. |
port | Port number for the connection. |
Definition at line 67 of file WIGTLinkRemote.cpp.
References port, socket, and statusCondition.
void WIGTLinkRemote::createSocketAndWaitForConnection | ( | uint32_t | port | ) |
Use this as a server that waits for client connections.
port | Port number for the connection |
Definition at line 62 of file WIGTLinkRemote.cpp.
References port.
std::shared_ptr< WValueSetBase > WIGTLinkRemote::createValueSet | ( | const igtl::ImageMessage::Pointer & | imgMsg | ) |
Internal helper to create a value set from a message.
imgMsg | The image behind this pointer is used to create the dataset |
Definition at line 514 of file WIGTLinkRemote.cpp.
Referenced by receiveImage().
void WIGTLinkRemote::injectMessage | ( | ) |
TODO: inject a message in the send queue.
Definition at line 270 of file WIGTLinkRemote.cpp.
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().
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().
WDataSetScalarSPtr WIGTLinkRemote::receiveImage | ( | igtl::MessageHeader::Pointer | headerMsg | ) |
Receive an image.
headerMsg | The image in this message is used to create a dataset |
Definition at line 217 of file WIGTLinkRemote.cpp.
References checkCRC, createValueSet(), and socket.
Referenced by readDataLoop().
void WIGTLinkRemote::receiveTransform | ( | igtl::MessageHeader::Pointer | headerMsg | ) |
Receive a transform.
headerMsg | The message conatining the transform. |
Definition at line 192 of file WIGTLinkRemote.cpp.
References checkCRC, and socket.
Referenced by readDataLoop().
void WIGTLinkRemote::sendImageData | ( | WDataSetScalarSPtr | dataSetScalar | ) |
Send image data of a single data set.
dataSetScalar | Pointer to the dataset we want to send |
Definition at line 425 of file WIGTLinkRemote.cpp.
void WIGTLinkRemote::sendImageMetaData | ( | const std::vector< WDataSetScalarSPtr > & | dataSets | ) |
Send metadata of a list of data sets.
dataSets | A vector containing pointer to the datasets whose metadata we want to send. |
Definition at line 322 of file WIGTLinkRemote.cpp.
References socket.
void WIGTLinkRemote::sendImageMetaData | ( | std::vector< WDataSetScalarSPtr > | dataSets | ) |
Send a message containing the metadata of the data sets.
dataSets | A vector containing pointers to the datasets whose metadata we want to send. |
void WIGTLinkRemote::sendTransform | ( | const std::string & | name, |
const WMatrix< double > & | matrix | ||
) |
send a matrix as an igtl transform
name | the name to use for the transform |
matrix | the matrix that will be send |
Definition at line 274 of file WIGTLinkRemote.cpp.
References socket.
|
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.
doCheckCRC | Should CRC of the data be checked? |
Definition at line 137 of file WIGTLinkRemote.h.
References checkCRC.
|
protectedvirtual |
the main thread doing passive connections or receiving data
Reimplemented from WThreadedRunner.
Definition at line 81 of file WIGTLinkRemote.cpp.
References readDataLoop().
|
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().
|
protected |
the port for listening connections
Definition at line 184 of file WIGTLinkRemote.h.
Referenced by createSocketAndConnect(), createSocketAndWaitForConnection(), listenLoop(), and readDataLoop().
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().
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().
boost::mutex WIGTLinkRemote::receiversMutex |
mutex has to be locked during access to receiveQueue
Definition at line 157 of file WIGTLinkRemote.h.
Referenced by readDataLoop().
|
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().
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().