SNMP and AgentX are all about variables, and how to obtain or alter their values. In agentXcpp, variables are represented by objects which implement the AbstractVariable interface. The library provides some classes such as IntegerVariable and OctetStringVariable, all implementing AbstractVariable. These classes can directly be instantiated to serve as read-only variables (they do not support SNMP Set requests), and their value can be obtained with value() and altered with setValue().
However, it is normally more useful to derive from these classes and reimplement perform_get(), so that the value can be obtained in the moment a Get request occurs. Also, the perform_testset()
, perform_commitset()
, perform_undoset()
and perform_cleanupset()
methods can be reimplemented to add write support.
Each variable has an internal member to store its value, e.g. IntegerVariable::v. This value can be read with value()
and set with setValue()
. The perform_get()
method is called by the library when an SNMP Get is requested for the variable. This method should then update the value to reflect the current state. The default perform_get()
implementation does nothing and thus allows to read the value as set by the last call to setValue(). This makes it possible to use the Variable class without inheriting.
Each variable provides the functions perform_testset()
, perform_commitset()
, perform_cleanupset()
and perform_undoset()
, which are called while processing an SNMP Set request for the variable (see also The anatomy of a Set request). Each of these functions takes the new value as parameter (e.g. an qint32 value for IntegerVariable). The functions should then act as described in The anatomy of a Set request, returning success or failure. It is not required that the functions update the internal member, because on Set request a subagent does not send the new state back to the master agent.
The default implementation of the Set-supporting methods is to fail with AbstractVariable::noAccess, indicating that the variable is read-only. It is required to reimplement the methods in a derived class to enable write support.