#include <UnixDomainConnector.hpp>
Inherits QObject.
Signals | |
void | pduArrived (QSharedPointer< PDU >) |
Emitted when a PDU arrived. More... | |
Public Member Functions | |
UnixDomainConnector (const std::string &unix_domain_socket="/var/agentx/master", unsigned timeout=1000) | |
Standard constructor. More... | |
virtual | ~UnixDomainConnector () |
Destructor. More... | |
bool | connect () |
Connect to the remote entity. More... | |
void | disconnect () |
Disconnect from the remote entity. More... | |
bool | is_connected () |
Find out whether the object is currently connected. More... | |
void | send (QSharedPointer< PDU > pdu) |
Send a PDU. More... | |
QSharedPointer< ResponsePDU > | request (QSharedPointer< PDU > pdu) |
Send a PDU and wait for the response. More... | |
AgentX is a protocol based on a request-response model. A subagent can send a request and wait for a response, while the master can also send requests and expect a response. Furthermore, a subagent or a master can send multiple requests, then wait for all the responses. All those PDU's can be interleaved.
The UnixDomainConnector class handles sending and receiving PDU's separately. Sending is done using the do_send() slot, which works for all types of PDU: all request-PDU's (such as OpenPDU) can be send without considering special cases, and ResponsePDU's also are no exception. Received PDU's are forwarded using the pduArrived() signal to whoever is listening, which works for PDU's except ResponsePDU's: these are the answer to a sent request-PDU and must be routed differently.
Received ResponsePDU's are transmitted via the m_responses map. This map assigns a packetID a ResponsePDU. Each time a request is sent, do_send() adds an entry to the map with the packetID of the request and a NULL ResponsePDU (i.e. a NULL pointer). This entry indicates that a ResponsePDU with the same packetID is awaited. The do_receive() slot then adds the ResponsePDU to the map, when it arrived. However, when a ResponsePDU arrives which is not awaited, it is discarded.
UnixDomainConnector::UnixDomainConnector | ( | const std::string & | unix_domain_socket = "/var/agentx/master" , |
unsigned | timeout = 1000 |
||
) |
Standard constructor.
This constructor initializes the connector object to be in disconnected state.
unix_domain_socket | The path to the unix_domain_socket. |
timeout | The timeout, in milliseconds, used for for connecting, disconnecting, sending and receiving PDU's. See the documentation of the respective methods for details. |
|
virtual |
Destructor.
bool UnixDomainConnector::connect | ( | ) |
Connect to the remote entity.
This function connects to the remote entity and starts receiving PDU's. If the object is already connected, the function does nothing.
For the attempt to connect, the configured timeout is used.
This function invokes the do_connect() slot and then wait until m_connection_waitcondition is triggered (or a timeout is detected).
void UnixDomainConnector::disconnect | ( | ) |
Disconnect from the remote entity.
Stops receiving PDU's and disconnects the remote entity.
For the attempt to disconnect, the configured timeout is used.
This function invokes the do_disconnect() slot and then waits until m_connection_waitcondition is triggered (or a timeout is detected).
The object will be in disconnected state after this method, no matter whether disconnecting times out or not.
bool UnixDomainConnector::is_connected | ( | ) |
Find out whether the object is currently connected.
|
signal |
Emitted when a PDU arrived.
This signal is emitted once for every arrived PDU, except for ResponsePDU's.
QSharedPointer< ResponsePDU > UnixDomainConnector::request | ( | QSharedPointer< PDU > | pdu | ) |
Send a PDU and wait for the response.
This method sends a PDU. Then, it adds an entry to m_responses to indicate that a ResponsePDU is awaited. Finally, it waits until that ResponsePDU arrives and returns it (it is removed from m_responses).
void UnixDomainConnector::send | ( | QSharedPointer< PDU > | pdu | ) |
Send a PDU.
This function enqueues a PDU for sending, by invoking do_send(). This means the this function returns before the PDU is actually sent.