TestCenter Reference
TestCenterAdvanced.IPC.Communicator Class Reference

The Communicator is the superclass for the communicating entities. More...

Inheritance diagram for TestCenterAdvanced.IPC.Communicator:
TestCenterAdvanced.IPC.ComMaster TestCenterAdvanced.IPC.ComSlave

Public Member Functions

 __init__ (self)
 getPort (self)
 Get the port used for connections.
 isConnected (self)
 Get the connection status of the IPC client.
 send (self, data, timeout)
 Send the data via the socket using the given timeout.
 recv (self, timeout)
 Receive data via the socket using the given timeout.
 getLastError (self)
 Get a tuple describing the last error.
 getLastErrorWithMessage (self)
 Get a tuple describing the last error.

Protected Member Functions

 _send (self, data, length, timeout)
 Send's little helper.
 _recv (self, length, timeout)
 Receive's little helper.
 _handleError (self, errorCode, errorMsg, silent=False)
 Set the error code and message and disconnect from network.

Protected Attributes

str _mHost = "localhost"
 IP to connect to.
int _mPort = 21319 if not "MeVisLabTestCenterPort" in os.environ else int(os.environ["MeVisLabTestCenterPort"])
 Port to use for the connection.
bool _mConnected = False
 Status of the connection.
 _msocket = None
 Main socket of the server.
 _csocket = None
 Connection socket.
 _mErrorCode = Error.OK
 Internal error code used to track the last error.
str _mErrorMsg = ""
 Internal error messages.

Static Protected Attributes

int _mMsgLength = 8192
 Length of the messages sent between the two entities.

Detailed Description

The Communicator is the superclass for the communicating entities.

This class contains the fundamental routines for sending messages between the two entities master and slave. The communication protocol consists of two parts. First the length of the message is sent via a string with exactly 16 bytes. This fixed length is essential as with asynchronous communication many non obvious things can happen (like only parts of messages being transmitted or concatenation of successivly sent messages). The second part of the communication protocol sends the actual data in junks of a given size.

Definition at line 55 of file IPC.py.

Constructor & Destructor Documentation

◆ __init__()

TestCenterAdvanced.IPC.Communicator.__init__ ( self)

Definition at line 60 of file IPC.py.

Member Function Documentation

◆ _handleError()

TestCenterAdvanced.IPC.Communicator._handleError ( self,
errorCode,
errorMsg,
silent = False )
protected

Set the error code and message and disconnect from network.

This method is just used to simplify the code as it combines all the actions required to handle the error case.

Definition at line 230 of file IPC.py.

References _mErrorCode, _mErrorMsg, TestCenterAdvanced.IPC.ComMaster.disconnect(), and TestCenterAdvanced.IPC.ComSlave.disconnect().

Referenced by _recv(), _send(), TestCenterAdvanced.IPC.ComMaster.disconnect(), TestCenterAdvanced.IPC.ComSlave.disconnect(), recv(), and send().

◆ _recv()

TestCenterAdvanced.IPC.Communicator._recv ( self,
length,
timeout )
protected

Receive's little helper.

This method first waits for the socket to get ready for receiving. This is done using the timeout to assure this operation doesn't block everything. Afterwards data is received in junks of a size specified in _mMsgLength via the socket. The length of the data expected must be given.

Definition at line 183 of file IPC.py.

References _csocket, _handleError(), and recv().

Referenced by recv().

◆ _send()

TestCenterAdvanced.IPC.Communicator._send ( self,
data,
length,
timeout )
protected

Send's little helper.

This method first waits for the socket to get ready for sending. This is done using the timeout to assure this operation doesn't block everything. Afterwards all data is send in junks of a size specified in _mMsgLength via the socket.

Definition at line 121 of file IPC.py.

References _csocket, _handleError(), _mMsgLength, and send().

Referenced by send().

◆ getLastError()

TestCenterAdvanced.IPC.Communicator.getLastError ( self)

Get a tuple describing the last error.

Each failure event sets an internal error code which can be read using this method.

Definition at line 213 of file IPC.py.

References _mErrorCode.

◆ getLastErrorWithMessage()

TestCenterAdvanced.IPC.Communicator.getLastErrorWithMessage ( self)

Get a tuple describing the last error.

Each failure event sets an internal error code which can be read using this method.

Definition at line 221 of file IPC.py.

References _mErrorCode, and _mErrorMsg.

◆ getPort()

TestCenterAdvanced.IPC.Communicator.getPort ( self)

Get the port used for connections.

Definition at line 82 of file IPC.py.

References _mPort.

◆ isConnected()

TestCenterAdvanced.IPC.Communicator.isConnected ( self)

Get the connection status of the IPC client.

Definition at line 89 of file IPC.py.

References _mConnected.

◆ recv()

TestCenterAdvanced.IPC.Communicator.recv ( self,
timeout )

Receive data via the socket using the given timeout.

This method implements the receiving part of the protocol specified in the description of send. This method returns True if it succeeded sending the data, False otherwise.

Definition at line 155 of file IPC.py.

References _handleError(), _mConnected, and _recv().

Referenced by _recv().

◆ send()

TestCenterAdvanced.IPC.Communicator.send ( self,
data,
timeout )

Send the data via the socket using the given timeout.

This method returns True if it succeeded sending the data, False otherwise.

Definition at line 97 of file IPC.py.

References _handleError(), _mConnected, and _send().

Referenced by _send().

Member Data Documentation

◆ _csocket

TestCenterAdvanced.IPC.Communicator._csocket = None
protected

◆ _mConnected

bool TestCenterAdvanced.IPC.Communicator._mConnected = False
protected

Status of the connection.

Definition at line 67 of file IPC.py.

Referenced by TestCenterAdvanced.IPC.ComMaster.disconnect(), TestCenterAdvanced.IPC.ComSlave.disconnect(), isConnected(), recv(), and send().

◆ _mErrorCode

TestCenterAdvanced.IPC.Communicator._mErrorCode = Error.OK
protected

Internal error code used to track the last error.

Definition at line 75 of file IPC.py.

Referenced by _handleError(), getLastError(), and getLastErrorWithMessage().

◆ _mErrorMsg

TestCenterAdvanced.IPC.Communicator._mErrorMsg = ""
protected

Internal error messages.

Definition at line 77 of file IPC.py.

Referenced by _handleError(), and getLastErrorWithMessage().

◆ _mHost

str TestCenterAdvanced.IPC.Communicator._mHost = "localhost"
protected

IP to connect to.

Definition at line 63 of file IPC.py.

◆ _mMsgLength

int TestCenterAdvanced.IPC.Communicator._mMsgLength = 8192
staticprotected

Length of the messages sent between the two entities.

Definition at line 58 of file IPC.py.

Referenced by _send().

◆ _mPort

int TestCenterAdvanced.IPC.Communicator._mPort = 21319 if not "MeVisLabTestCenterPort" in os.environ else int(os.environ["MeVisLabTestCenterPort"])
protected

Port to use for the connection.

Definition at line 65 of file IPC.py.

Referenced by getPort().

◆ _msocket

TestCenterAdvanced.IPC.Communicator._msocket = None
protected

Main socket of the server.

Definition at line 70 of file IPC.py.


The documentation for this class was generated from the following file:
  • MeVisLab/Standard/Modules/Macros/Tests/TestCenterAdvanced/IPC.py