The base class of all PDU's. More...
#include <PDU.hpp>
Public Member Functions | |
virtual | ~PDU () |
Destructor. More... | |
bool | get_new_index () |
Get new_index flag. More... | |
void | set_new_index (bool new_index) |
Set new_index flag. More... | |
bool | get_any_index () |
Get any_index flag. More... | |
void | set_any_index (bool any_index) |
Set any_index flag. More... | |
quint32 | get_sessionID () |
Get sessionID. More... | |
void | set_sessionID (quint32 id) |
Set sessionID. More... | |
quint32 | get_transactionID () |
Get transactionID. More... | |
void | set_transactionID (quint32 id) |
Set transactionID. More... | |
quint32 | get_packetID () |
Get packetID. More... | |
void | set_packetID (quint32 packetID) |
Set packetID. More... | |
virtual binary | serialize () const =0 |
Serialize function for concrete PDUs. More... | |
Static Public Member Functions | |
static QSharedPointer< PDU > | parse_pdu (binary buf) |
Parse a PDU from a buffer. More... | |
Protected Types | |
enum | type_t { agentxOpenPDU = 1, agentxClosePDU = 2, agentxRegisterPDU = 3, agentxUnregisterPDU = 4, agentxGetPDU = 5, agentxGetNextPDU = 6, agentxGetBulkPDU = 7, agentxTestSetPDU = 8, agentxCommitSetPDU = 9, agentxUndoSetPDU = 10, agentxCleanupSetPDU = 11, agentxNotifyPDU = 12, agentxPingPDU = 13, agentxIndexAllocatePDU = 14, agentxIndexDeallocatePDU = 15, agentxAddAgentCapsPDU = 16, agentxRemoveAgentCapsPDU = 17, agentxResponsePDU = 18 } |
The PDU types. More... | |
Protected Member Functions | |
PDU (binary::const_iterator &pos, const binary::const_iterator &end, bool big_endian) | |
Parse constructor. More... | |
void | add_header (type_t type, binary &payload) const |
Construct the PDU header and add it to the payload. More... | |
PDU () | |
Default constructor. More... | |
Protected Attributes | |
bool | instance_registration |
the instance_registration flag More... | |
bool | non_default_context |
Whether the PDU has a non-default context. More... | |
quint32 | packetID |
h.packetID field according to RFC 2741, 6.1. "AgentX PDU
Header". More... | |
Private Attributes | |
bool | new_index |
the new_index flag More... | |
bool | any_index |
the any_index flag More... | |
quint32 | sessionID |
h.sessionID field More... | |
quint32 | transactionID |
h.transactionID field More... | |
Static Private Attributes | |
static quint32 | packetID_cnt = 0 |
Counter for automatic packetID generator. More... | |
The base class of all PDU's.
This class is never instantiated itself, but serves as the base class for concrete PDU classes which don't have a context field (e.g. OpenPDU). For concrete PDU's with context field, the class PDUwithContext is used.
This class represents the PDU header and contains data and functionality common to all PDU types. It provides an automatic packetID generator. Whenever a PDU object is created, the packetID is automatically incremented. The two exceptions are:
The mechanism uses a static class member packetID_cnt to store the last used packetID. The counter wraps at its limit.
|
protected |
The PDU types.
According to RFC 2741, section 6.1 "AgentX PDU Header".
|
protected |
Parse constructor.
Read the PDU header from a buffer and initialize part of the PDU object. Is called by the parse constructors of derived classes. See Parsing incoming PDUs for details about PDU parsing.
pos | Iterator pointing to the current stream position. The iterator is advanced while reading the header. |
end | Iterator pointing one element past the end of the current stream. This is needed to mark the end of the buffer. |
big_endian | Whether the serialized form of the PDU is in big_endian format. |
parse_error | If parsing fails, for example because reading the stream fails or the PDU is malformed. |
Definition at line 59 of file PDU.cpp.
References any_index, instance_registration, new_index, non_default_context, packetID, agentxcpp::read32(), sessionID, and transactionID.
|
protected |
Default constructor.
The members are set as follows:
Definition at line 45 of file PDU.cpp.
References any_index, instance_registration, new_index, non_default_context, packetID, packetID_cnt, sessionID, and transactionID.
Construct the PDU header and add it to the payload.
Add the PDU header to the payload. Called by derived classes during serialization.
The header is encoded in big endian format.
type | The PDU type, according to RFC 2741, 6.1. "AgentX PDU Header". |
payload | The payload of the PDU. The header is added to the payload, i.e. payload is altered by this function. |
Definition at line 187 of file PDU.cpp.
References any_index, instance_registration, new_index, non_default_context, packetID, sessionID, transactionID, and agentxcpp::write32().
Referenced by agentxcpp::PDUwithContext::add_header(), agentxcpp::UndoSetPDU::serialize(), agentxcpp::CleanupSetPDU::serialize(), agentxcpp::CommitSetPDU::serialize(), agentxcpp::ClosePDU::serialize(), agentxcpp::OpenPDU::serialize(), and agentxcpp::ResponsePDU::serialize().
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
Parse a PDU from a buffer.
Create a PDU of the according type (e.g. ResponsePDU) from the given buffer. See Parsing incoming PDUs for details about PDU parsing.
buf | The buffer containing exactly one PDU in serialized form. |
parse_error | If parsing fails, because the PDU is malformed. |
version_mismatch | If the AgentX version of the PDU is not 1. |
Definition at line 98 of file PDU.cpp.
References agentxCleanupSetPDU, agentxClosePDU, agentxCommitSetPDU, agentxGetBulkPDU, agentxGetNextPDU, agentxGetPDU, agentxNotifyPDU, agentxOpenPDU, agentxRegisterPDU, agentxResponsePDU, agentxTestSetPDU, agentxUndoSetPDU, agentxUnregisterPDU, agentxcpp::read32(), and version.
Referenced by agentxcpp::UnixDomainConnector::do_receive().
|
pure virtual |
Serialize function for concrete PDUs.
Implemented in agentxcpp::ResponsePDU, agentxcpp::GetBulkPDU, agentxcpp::RegisterPDU, agentxcpp::OpenPDU, agentxcpp::UnregisterPDU, agentxcpp::ClosePDU, agentxcpp::NotifyPDU, agentxcpp::GetNextPDU, agentxcpp::GetPDU, agentxcpp::TestSetPDU, agentxcpp::CleanupSetPDU, agentxcpp::CommitSetPDU, and agentxcpp::UndoSetPDU.
|
inline |
|
inline |
|
inline |
|
inline |
Set sessionID.
Definition at line 253 of file PDU.hpp.
Referenced by agentxcpp::ClosePDU::ClosePDU().
|
inline |
|
private |
the any_index flag
Definition at line 66 of file PDU.hpp.
Referenced by add_header(), get_any_index(), PDU(), and set_any_index().
|
protected |
the instance_registration flag
This flag is used only in the RegisterPDU. It is located here, because it is part of the PDU header. It is parsed by the parse constructor of this class and serialized by the add_header() function.
Definition at line 105 of file PDU.hpp.
Referenced by add_header(), agentxcpp::RegisterPDU::get_instance_registration(), PDU(), and agentxcpp::RegisterPDU::set_instance_registration().
|
private |
the new_index flag
Definition at line 61 of file PDU.hpp.
Referenced by add_header(), get_new_index(), PDU(), and set_new_index().
|
protected |
Whether the PDU has a non-default context.
This field is only meaningful for certain PDU's (see RFC 2741, section 6.1.1 "Context" for a description).
Definition at line 114 of file PDU.hpp.
Referenced by agentxcpp::PDUwithContext::add_header(), add_header(), agentxcpp::PDUwithContext::has_context(), PDU(), agentxcpp::PDUwithContext::PDUwithContext(), agentxcpp::PDUwithContext::remove_context(), and agentxcpp::PDUwithContext::set_context().
|
protected |
h.packetID field according to RFC 2741, 6.1. "AgentX PDU Header".
Is automatically filled by constructors, is set to another value by ResponsePDU. The PDU class has no setter for this member.
The ResponsePDU is a special case in resepect of packetIDs, therefore this member is protected to allow the ResponsePDU to alter it.
Definition at line 155 of file PDU.hpp.
Referenced by add_header(), get_packetID(), PDU(), and set_packetID().
|
staticprivate |
Counter for automatic packetID generator.
The packetID member is set automatically by the constructors; each new PDU gets a new packetID. This member contains the last used packetID.
The parse constructor does not use this member, because it reads the packetID from a stream.
Definition at line 92 of file PDU.hpp.
Referenced by PDU().
|
private |
h.sessionID field
According to RFC 2741, 6.1. "AgentX PDU Header"
Definition at line 73 of file PDU.hpp.
Referenced by add_header(), get_sessionID(), and PDU().
|
private |
h.transactionID field
According to RFC 2741, 6.1. "AgentX PDU Header"
Definition at line 80 of file PDU.hpp.
Referenced by add_header(), get_transactionID(), and PDU().