AgentXcpp  Revision:0.1.1
Internals Documentation
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Friends Pages
agentxcpp::PDU Class Reference

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

#include <PDU.hpp>

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

List of all members.

Public Member Functions

bool get_new_index ()
 Get new_index flag.
void set_new_index (bool new_index)
 Set new_index flag.
bool get_any_index ()
 Get any_index flag.
void set_any_index (bool any_index)
 Set any_index flag.
uint32_t get_sessionID ()
 Get sessionID.
void set_sessionID (uint32_t id)
 Set sessionID.
uint32_t get_transactionID ()
 Get transactionID.
void set_transactionID (uint32_t id)
 Set transactionID.
uint32_t get_packetID ()
 Get packetID.
void set_packetID (uint32_t packetID)
 Set packetID.
virtual binary serialize () const =0
 Serialize function for concrete PDUs.

Static Public Member Functions

static shared_ptr< PDUparse_pdu (binary buf)
 Parse a PDU from a buffer.

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.
void add_header (type_t type, binary &payload) const
 Construct the PDU header and add it to the payload.
 PDU ()
 Default constructor.
virtual ~PDU ()
 Destructor.

Protected Attributes

bool instance_registration
 the instance_registration flag
bool non_default_context
 Whether the PDU has a non-default context.
uint32_t packetID
 h.packetID field according to RFC 2741, 6.1. "AgentX PDU Header".

Private Attributes

bool new_index
 the new_index flag
bool any_index
 the any_index flag
uint32_t sessionID
 h.sessionID field
uint32_t transactionID
 h.transactionID field

Static Private Attributes

static uint32_t packetID_cnt = 0
 Counter for automatic packetID generator.

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 56 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 123 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 63 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 49 of file PDU.cpp.

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

virtual agentxcpp::PDU::~PDU ( )
inlineprotectedvirtual

Destructor.

Definition at line 225 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.

Reimplemented in agentxcpp::PDUwithContext.

Definition at line 191 of file PDU.cpp.

References any_index, instance_registration, new_index, non_default_context, packetID, sessionID, transactionID, and agentxcpp::write32().

Referenced by agentxcpp::CleanupSetPDU::serialize(), agentxcpp::UndoSetPDU::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 243 of file PDU.hpp.

References any_index.

bool agentxcpp::PDU::get_new_index ( )
inline

Get new_index flag.

Definition at line 234 of file PDU.hpp.

References new_index.

uint32_t agentxcpp::PDU::get_packetID ( )
inline

Get packetID.

Definition at line 271 of file PDU.hpp.

References packetID.

Referenced by agentxcpp::master_proxy::connect(), and agentxcpp::master_proxy::disconnect().

uint32_t agentxcpp::PDU::get_sessionID ( )
inline

Get sessionID.

Definition at line 252 of file PDU.hpp.

References sessionID.

uint32_t agentxcpp::PDU::get_transactionID ( )
inline

Get transactionID.

Definition at line 261 of file PDU.hpp.

References transactionID.

shared_ptr< 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 102 of file PDU.cpp.

References agentxCleanupSetPDU, agentxClosePDU, agentxCommitSetPDU, agentxGetBulkPDU, agentxGetNextPDU, agentxGetPDU, agentxNotifyPDU, agentxOpenPDU, agentxRegisterPDU, agentxResponsePDU, agentxTestSetPDU, agentxUndoSetPDU, agentxUnregisterPDU, and agentxcpp::read32().

Referenced by agentxcpp::connector::receive_callback().

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

Set any_index flag.

Definition at line 247 of file PDU.hpp.

References any_index.

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

Set new_index flag.

Definition at line 238 of file PDU.hpp.

References new_index.

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

Set packetID.

Definition at line 276 of file PDU.hpp.

References packetID.

Referenced by agentxcpp::master_proxy::handle_pdu().

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

Set sessionID.

Definition at line 256 of file PDU.hpp.

References sessionID.

Referenced by agentxcpp::ClosePDU::ClosePDU(), and agentxcpp::master_proxy::handle_pdu().

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

Set transactionID.

Definition at line 266 of file PDU.hpp.

References transactionID.

Referenced by agentxcpp::master_proxy::handle_pdu().


Member Data Documentation

bool agentxcpp::PDU::any_index
private

the any_index flag

Definition at line 68 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 107 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 63 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 116 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().

uint32_t 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 157 of file PDU.hpp.

Referenced by add_header(), get_packetID(), PDU(), and set_packetID().

uint32_t 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 94 of file PDU.hpp.

Referenced by PDU().

uint32_t agentxcpp::PDU::sessionID
private

h.sessionID field

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

Definition at line 75 of file PDU.hpp.

Referenced by add_header(), get_sessionID(), PDU(), and set_sessionID().

uint32_t agentxcpp::PDU::transactionID
private

h.transactionID field

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

Definition at line 82 of file PDU.hpp.

Referenced by add_header(), get_transactionID(), PDU(), and set_transactionID().


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