#include <ltkcpp_connection.h>
Public Member Functions | |
CConnection (const CTypeRegistry *pTypeRegistry, unsigned int nBufferSize) | |
Construct a new LLRP connection instance. | |
~CConnection (void) | |
Destruct a LLRP connection instance. | |
int | openConnectionToReader (const char *pReaderHostName) |
Open the connection to the reader. | |
const char * | getConnectError (void) |
Get the string that explains openReaderConnection() error. | |
int | closeConnectionToReader (void) |
Close connection to reader, allow reuse of instance. | |
CMessage * | transact (CMessage *pSendMessage, int nMaxMS) |
Transact a LLRP request and response to a connection. | |
const CErrorDetails * | getTransactError (void) |
Get the details that explains transact() error. | |
EResultCode | sendMessage (CMessage *pMessage) |
Send a LLRP message to a connection. | |
const CErrorDetails * | getSendError (void) |
Get the details that explains sendMessage() error. | |
CMessage * | recvMessage (int nMaxMS) |
Receive a message from a connection. | |
CMessage * | recvResponse (int nMaxMS, const CTypeDescriptor *pResponseType, llrp_u32_t ResponseMessageID) |
Receive a specific message from a connection. | |
const CErrorDetails * | getRecvError (void) |
Get the details that explains recvMessage() or recvResponse() error. |
An LLRP connection consists of:
Definition at line 75 of file ltkcpp_connection.h.
LLRP::CConnection::CConnection | ( | const CTypeRegistry * | pTypeRegistry, | |
unsigned int | nBufferSize | |||
) |
Construct a new LLRP connection instance.
[in] | pTypeRegistry | The LLRP registry of known message/parameter types. Includes standard and custom. Used during decode. |
[in] | nBufferSize | Size of each the receive and send buffers. Use size larger than the largest frame you expect. 0 selects a default value. |
Definition at line 132 of file ltkcpp_connection.cpp.
int LLRP::CConnection::closeConnectionToReader | ( | void | ) |
Close connection to reader, allow reuse of instance.
Definition at line 399 of file ltkcpp_connection.cpp.
Referenced by ~CConnection().
const char * LLRP::CConnection::getConnectError | ( | void | ) |
Get the string that explains openReaderConnection() error.
Definition at line 382 of file ltkcpp_connection.cpp.
const CErrorDetails * LLRP::CConnection::getRecvError | ( | void | ) |
Get the details that explains recvMessage() or recvResponse() error.
Definition at line 713 of file ltkcpp_connection.cpp.
Referenced by getTransactError().
const CErrorDetails * LLRP::CConnection::getSendError | ( | void | ) |
Get the details that explains sendMessage() error.
Definition at line 628 of file ltkcpp_connection.cpp.
Referenced by getTransactError().
const CErrorDetails * LLRP::CConnection::getTransactError | ( | void | ) |
Get the details that explains transact() error.
This is not 100% reliable. It looks at the send error and if that seems OK it uses the recv error. Uses of sendMessage(), recvMessage() or recvResponse() since transact() will distort the error.
Definition at line 509 of file ltkcpp_connection.cpp.
References getRecvError(), getSendError(), LLRP::CErrorDetails::m_eResultCode, and LLRP::RC_OK.
int LLRP::CConnection::openConnectionToReader | ( | const char * | pReaderHostName | ) |
Open the connection to the reader.
The steps:
[in] | pReaderHostName | String containing the reader host name |
Definition at line 255 of file ltkcpp_connection.cpp.
CMessage * LLRP::CConnection::recvMessage | ( | int | nMaxMS | ) |
Receive a message from a connection.
The message could have already arrived and be pending on the input queue.
[in] | nMaxMS | -1 => block indefinitely 0 => just peek at input queue and socket queue, return immediately no matter what >0 => ms to await complete frame |
Definition at line 655 of file ltkcpp_connection.cpp.
References LLRP::RC_MiscError, LLRP::RC_OK, and LLRP::CErrorDetails::resultCodeAndWhatStr().
CMessage * LLRP::CConnection::recvResponse | ( | int | nMaxMS, | |
const CTypeDescriptor * | pResponseType, | |||
llrp_u32_t | ResponseMessageID | |||
) |
Receive a specific message from a connection.
The message is identified by type and message ID.
This is used to receive a response to a request, but could be used for other things, too. A message matches and is returned if the type matches AND if the message ID matches. Either or both can be wildcards.
The sought message could have already arrived and be pending on the input queue. While we are looking for the response notifications might arrive. They are held in the input queue while we continue to look for the sought message.
About timeLimit.... The timeLimit is the last time() we'll try to receive the sought message and prevents "spinning". It is conceivable that a steady stream of messages other than the one sought could arrive, and the time between those messages could be smaller the nMaxMS. When that happens, recvAdvance() would not time out during its poll/select. It could "spin". The time out must be detected by other means and that's the purpose of timeLimit.
[in] | nMaxMS | -1 => block indefinitely 0 => just peek at input queue and socket queue, return immediately no matter what >0 => ms to await complete frame |
[in] | pResponseType | The type descriptor of the sought or NULL to match all messages. If not NULL, ERROR_MESSAGE will also match. |
[in] | ResponseMessageID | The MessageID of sought message or 0 to match all messages. |
Definition at line 766 of file ltkcpp_connection.cpp.
References LLRP::CMessage::getMessageID(), LLRP::CTypeRegistry::lookupMessage(), LLRP::CElement::m_pType, LLRP::RC_MiscError, LLRP::RC_OK, and LLRP::CErrorDetails::resultCodeAndWhatStr().
Referenced by transact().
EResultCode LLRP::CConnection::sendMessage | ( | CMessage * | pMessage | ) |
Send a LLRP message to a connection.
[in] | pMessage | Pointer to the LLRP message to send. |
Definition at line 539 of file ltkcpp_connection.cpp.
References LLRP::CErrorDetails::clear(), LLRP::CErrorDetails::m_eResultCode, LLRP::RC_MiscError, LLRP::RC_OK, LLRP::RC_SendIOError, and LLRP::CErrorDetails::resultCodeAndWhatStr().
Referenced by transact().
Transact a LLRP request and response to a connection.
This is a combination of sendMessage() and recvResponse(). The MessageID is taken from the outgoing messages. It's best to not use MessageID 0.
[in] | pSendMessage | Pointer to the LLRP message to send. |
[in] | nMaxMS | -1 => block indefinitely 0 => just peek at input queue and socket queue, return immediately no matter what >0 => ms to await complete frame |
Definition at line 446 of file ltkcpp_connection.cpp.
References LLRP::CErrorDetails::clear(), LLRP::CMessage::getMessageID(), LLRP::CTypeDescriptor::m_pResponseType, LLRP::CElement::m_pType, LLRP::RC_MissingResponseType, LLRP::RC_OK, recvResponse(), LLRP::CErrorDetails::resultCodeAndWhatStr(), and sendMessage().