AgentXcpp  Revision:0.1.1
Internals Documentation
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Friends Pages
The Variable Objects

Introduction

SNMP and AgentX are all about variables, and how to obtain or alter their values. In agentXcpp, variables are represented by classes which implement the agentxcpp::variables interface. The library provides some classes such as agentxcpp::Integer and agentxcpp::Octet_String, which have an internal value and can be serialized and deserialized to be included in PDU messages. To actually provide an SNMP variable, one of these classes must be derived.

Serializing and Parsing Variables

The agentxcpp::variable interface provides the serialize function to serialize a variable object. Parsing is done using parse constructors. This is the same mechanism as used by the PDU classes. See The PDU Objects for an explanation.

GET Requests

When the agentxcpp::master_proxy object receives a GET request, it looks up the variable registered with the requested OID. Then it invokes the variable's update() function (found in the agentxcpp::variable interface) to update the internal state of the variable. Finally the variable is serialized and embedded within a agentxcpp::ResponsePDU and sent to the master agent.

The agentxcpp::variable::update() method is implemented in the variable classes such as agentxcpp::Integer, agentxcpp::Octet_String, agentxcpp::Counter32 , and so on. The implementation just calls the get() method of the respective object, which returns the new value of the object. Then, update() stores the new value within the variable.

When implementing an SNMP variable, the user of the agentXcpp library derives one of the variable classes (e.g. agentxcpp::Octet_String) and overrides the get() method. The get() method may throw agentxcpp::generic_error, in which case a generic error is reported to the master agent. Note that any other exception also results in a generic error reported to the master agent.

The variable classes provide default implementations of get() which throws agentxcpp::generic_error. As a side effect, a generic error is reported if a derived class does not override get(). The main reason for providing a default implementations is that get() cannot be pure virtual, because the variable classes are created while parsing PDU contents. Abstract classes would not allow that mechanism.