AgentXcpp  Version:0.3
Internals Documentation
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Friends Pages
agentxcpp::PDU Class Referenceabstract

The base class of all PDU's. More...

#include <PDU.hpp>

Inheritance diagram for agentxcpp::PDU:
Collaboration diagram for agentxcpp::PDU:

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< PDUparse_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...
 

Detailed Description

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 parse contructor fills the packetID from the received PDU
  • The ResponsePDU class overwrites the packetID

The mechanism uses a static class member packetID_cnt to store the last used packetID. The counter wraps at its limit.

Definition at line 54 of file PDU.hpp.

Member Enumeration Documentation

enum agentxcpp::PDU::type_t
protected

The PDU types.

According to RFC 2741, section 6.1 "AgentX PDU Header".

Enumerator
agentxOpenPDU 
agentxClosePDU 
agentxRegisterPDU 
agentxUnregisterPDU 
agentxGetPDU 
agentxGetNextPDU 
agentxGetBulkPDU 
agentxTestSetPDU 
agentxCommitSetPDU 
agentxUndoSetPDU 
agentxCleanupSetPDU 
agentxNotifyPDU 
agentxPingPDU 
agentxIndexAllocatePDU 
agentxIndexDeallocatePDU 
agentxAddAgentCapsPDU 
agentxRemoveAgentCapsPDU 
agentxResponsePDU 

Definition at line 121 of file PDU.hpp.

Constructor & Destructor Documentation

PDU::PDU ( binary::const_iterator &  pos,
const binary::const_iterator &  end,
bool  big_endian 
)
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.

Parameters
posIterator pointing to the current stream position. The iterator is advanced while reading the header.
endIterator pointing one element past the end of the current stream. This is needed to mark the end of the buffer.
big_endianWhether the serialized form of the PDU is in big_endian format.
Exceptions
parse_errorIf 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.

PDU::PDU ( )
protected

Default constructor.

The members are set as follows:

  • packetID_cnt is incremented and the packetID is set to the new packetID_cnt value.
  • sessionID = 0
  • transactionID = 0
  • instance_registration = false
  • new_index = false
  • any_index = false
  • non_default_context = false

Definition at line 45 of file PDU.cpp.

References any_index, instance_registration, new_index, non_default_context, packetID, packetID_cnt, sessionID, and transactionID.

virtual agentxcpp::PDU::~PDU ( )
inlinevirtual

Destructor.

Definition at line 224 of file PDU.hpp.

Member Function Documentation

void PDU::add_header ( type_t  type,
binary payload 
) const
protected

Construct the PDU header and add it to the payload.

Add the PDU header to the payload. Called by derived classes during serialization.

Warning
The payload must not grow or shrink after a call to this function as its size is encoded into the header.
The function must not be called twice for the same PDU, because this would add two headers and thus generate a malformed PDU.

The header is encoded in big endian format.

Parameters
typeThe PDU type, according to RFC 2741, 6.1. "AgentX PDU Header".
payloadThe 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().

bool agentxcpp::PDU::get_any_index ( )
inline

Get any_index flag.

Definition at line 240 of file PDU.hpp.

References any_index.

bool agentxcpp::PDU::get_new_index ( )
inline

Get new_index flag.

Definition at line 231 of file PDU.hpp.

References new_index.

quint32 agentxcpp::PDU::get_packetID ( )
inline

Get packetID.

Definition at line 268 of file PDU.hpp.

References packetID.

quint32 agentxcpp::PDU::get_sessionID ( )
inline

Get sessionID.

Definition at line 249 of file PDU.hpp.

References sessionID.

quint32 agentxcpp::PDU::get_transactionID ( )
inline

Get transactionID.

Definition at line 258 of file PDU.hpp.

References transactionID.

QSharedPointer< PDU > PDU::parse_pdu ( binary  buf)
static

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.

Parameters
bufThe buffer containing exactly one PDU in serialized form.
Exceptions
parse_errorIf parsing fails, because the PDU is malformed.
version_mismatchIf 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().

void agentxcpp::PDU::set_any_index ( bool  any_index)
inline

Set any_index flag.

Definition at line 244 of file PDU.hpp.

References any_index.

void agentxcpp::PDU::set_new_index ( bool  new_index)
inline

Set new_index flag.

Definition at line 235 of file PDU.hpp.

References new_index.

void agentxcpp::PDU::set_packetID ( quint32  packetID)
inline

Set packetID.

Definition at line 273 of file PDU.hpp.

References packetID.

void agentxcpp::PDU::set_sessionID ( quint32  id)
inline

Set sessionID.

Definition at line 253 of file PDU.hpp.

Referenced by agentxcpp::ClosePDU::ClosePDU().

void agentxcpp::PDU::set_transactionID ( quint32  id)
inline

Set transactionID.

Definition at line 263 of file PDU.hpp.

Member Data Documentation

bool agentxcpp::PDU::any_index
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().

bool agentxcpp::PDU::instance_registration
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().

bool agentxcpp::PDU::new_index
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().

bool agentxcpp::PDU::non_default_context
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().

quint32 agentxcpp::PDU::packetID
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().

quint32 PDU::packetID_cnt = 0
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().

quint32 agentxcpp::PDU::sessionID
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().

quint32 agentxcpp::PDU::transactionID
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().


The documentation for this class was generated from the following files: