AgentXcpp  Revision:0.2
Internals Documentation
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Friends Pages
agentxcpp::Variable< T > Class Template Reference

Class template to implement primitive SNMP variables. More...

#include <Variable.hpp>

Inheritance diagram for agentxcpp::Variable< T >:
Collaboration diagram for agentxcpp::Variable< T >:

Public Member Functions

virtual shared_ptr< AbstractValuehandle_get ()
 Handle a Get Request.
virtual T get ()=0
 Handle a Get request.
virtual testset_result_t handle_testset (shared_ptr< AbstractValue > v)
 Handle a TestSet request.
virtual testset_result_t testset (shared_ptr< T > v)
 Handle a TestSet request.
virtual void handle_cleanupset ()
 Handle a CleanupSet request.
virtual void cleanupset (shared_ptr< T > v)
 Handle a CleanupSet request.
virtual bool handle_commitset ()
 Handle a CommitSet request.
virtual bool commitset (shared_ptr< T > v)
 Handle a CommitSet request.
virtual bool handle_undoset ()
 Handle a UndoSet request.
virtual bool undoset (shared_ptr< T > v)
 Handle an UndoSet request.
- Public Member Functions inherited from agentxcpp::AbstractVariable
virtual ~AbstractVariable ()
 Destructor.

Private Attributes

shared_ptr< T > new_value
 The new value for the variable in a Set operation.

Additional Inherited Members

- Public Types inherited from agentxcpp::AbstractVariable
enum  testset_result_t {
  noError = 0, genErr = 5, noAccess = 6, wrongType = 7,
  wrongLength = 8, wrongValue = 10, noCreation = 11, inconsistentValue = 12,
  resourceUnavailable = 13, notWritable = 17, inconsistentName = 18
}
 Result type for the TestSet validation. More...

Detailed Description

template<class T>
class agentxcpp::Variable< T >

Class template to implement primitive SNMP variables.

This class template is used as base class for primitive SNMP variable implementations. It is instanciated with the value type the variable provides. Then, some functions are overriden to provide the functionality. Example:

// An IntegerValue variable
class simpleCounter : public Variable<IntegerValue>
{
private:
// The internal counter
IntegerValue counter;
public:
// Handle SNMP get request
virtual IntegerValue get()
{
return counter;
}
// Increment the internal counter
void increment()
{
// Increment counter somehow
}
};

The get() method must be implemented. It is not allowed (and not possible) to implement write-only SNMP variables.

To support write access (which is optional), the methods testset() and commitset() must be implemented. The undoset() method should also be implemented in this case. The cleanupset() methon may be implemented if needed.

This class template implements the methods of agentxcpp::variable in such a way that they call methods for the more specific value types. Example:

virtual testset_result_t handle_testset(shared_ptr<value> v)
{
shared_ptr<V> new_value = boost::dynamic_pointer_cast<V>(v);
if (new_value)
{
return this->testset(new_value);
}
else
{
return wrongType;
}
}

As can be seen, handle_testset() receives a pointer to a 'value' object. This pointer is casted to 'V' (the template parameter) before giving it to the testset() method. The testset() method is the one which is implemented by the agentXcpp user.

This class template remembers the new value and gives it to the functions testset(), commitset(), cleanupset() and undoset(). Also, type conversion is done (see the example) and an error is generated on type mismatch.

Definition at line 101 of file Variable.hpp.

Member Function Documentation

template<class T >
virtual void agentxcpp::Variable< T >::cleanupset ( shared_ptr< T >  v)
inlinevirtual

Handle a CleanupSet request.

This method is called to handle an SNMP CleanupSet request. It shall release any ressources allocated by testset().

The default implementation does nothing. If no action is required to perform the CleanupSet operaiton, this method need not be overridden.

Parameters
vThe new value for the object.

Definition at line 224 of file Variable.hpp.

Referenced by agentxcpp::Variable< T >::handle_cleanupset().

template<class T >
virtual bool agentxcpp::Variable< T >::commitset ( shared_ptr< T >  v)
inlinevirtual

Handle a CommitSet request.

This method is called to handle an SNMP CommitSet request. It shall perform the actual write operation.

The default implementation returns false to indicate that the operation failed. To implement a writable SNMP variable this method must be overridden.

Parameters
vThe new value for the object.
Returns
True if the operation succeeded, false otherwise.

Definition at line 256 of file Variable.hpp.

Referenced by agentxcpp::Variable< T >::handle_commitset().

template<class T >
virtual T agentxcpp::Variable< T >::get ( )
pure virtual

Handle a Get request.

This method is called to handle an SNMP Get request. It shall return the current value of the variable.

Note
This method is pure virtual and thus must be implemented. It is not possible to implement write-only SNMP variables.
Returns
The value of the variable.
template<class T >
virtual void agentxcpp::Variable< T >::handle_cleanupset ( )
inlinevirtual

Handle a CleanupSet request.

This function calls cleanupset() with the value from the last handle_testset() invokation.

Implements agentxcpp::AbstractVariable.

Definition at line 207 of file Variable.hpp.

References agentxcpp::Variable< T >::cleanupset(), and agentxcpp::Variable< T >::new_value.

template<class T >
virtual bool agentxcpp::Variable< T >::handle_commitset ( )
inlinevirtual

Handle a CommitSet request.

This function calls commitset() with the value from the last handle_testset() Invocation and returns its return value.

Implements agentxcpp::AbstractVariable.

Definition at line 237 of file Variable.hpp.

References agentxcpp::Variable< T >::commitset(), and agentxcpp::Variable< T >::new_value.

template<class T >
virtual shared_ptr<AbstractValue> agentxcpp::Variable< T >::handle_get ( )
inlinevirtual

Handle a Get Request.

This function calls this->get() to obtain the new value, converts it to shared_ptr<value> and returns it.

Implements agentxcpp::AbstractVariable.

Definition at line 124 of file Variable.hpp.

template<class T >
virtual testset_result_t agentxcpp::Variable< T >::handle_testset ( shared_ptr< AbstractValue v)
inlinevirtual

Handle a TestSet request.

This function converts the argument to shared_ptr<V>() and calls testset() with the converted value. If conversion fails, testset() is not called. This function also stores the given value to the new_value member.

Parameters
vThe new value for the variable.
Returns
wrongType if the conversion fails. Otherwise, the result of testset() is returned.

Implements agentxcpp::AbstractVariable.

Definition at line 162 of file Variable.hpp.

References agentxcpp::Variable< T >::new_value, agentxcpp::Variable< T >::testset(), and agentxcpp::AbstractVariable::wrongType.

template<class T >
virtual bool agentxcpp::Variable< T >::handle_undoset ( )
inlinevirtual

Handle a UndoSet request.

This function calls undoset() with the value from the last handle_testset() invocation and returns its return value.

Implements agentxcpp::AbstractVariable.

Definition at line 270 of file Variable.hpp.

References agentxcpp::Variable< T >::new_value, and agentxcpp::Variable< T >::undoset().

template<class T >
virtual testset_result_t agentxcpp::Variable< T >::testset ( shared_ptr< T >  v)
inlinevirtual

Handle a TestSet request.

This method is called to handle an SNMP TestSet request. It shall check whether a Set operation is possible for the variable. It shall acquire the resources needed to perform the Set operation (but the Set shall not yet performed).

The default implementation returns noAccess to indicate that this is a read-only variable. Thus, for read-only variables this method need not be overridden.

Parameters
vThe new value for the object.
Returns
The result of the check.

Definition at line 194 of file Variable.hpp.

References agentxcpp::AbstractVariable::noAccess.

Referenced by agentxcpp::Variable< T >::handle_testset().

template<class T >
virtual bool agentxcpp::Variable< T >::undoset ( shared_ptr< T >  v)
inlinevirtual

Handle an UndoSet request.

This method is called to handle an SNMP UndoSet request. It shall undo whatever commitset() performed. It shall also release all resources allocated by testset().

The default implementation returns false to indicate that the operation failed. It is strongly recommended that writable variables override this method.

A default implementation is provided to allow implementing read-only variables.

Parameters
vThe new value for the object.
Returns
True on success, false otherwise.

Definition at line 297 of file Variable.hpp.

Referenced by agentxcpp::Variable< T >::handle_undoset().

Member Data Documentation

template<class T >
shared_ptr<T> agentxcpp::Variable< T >::new_value
private

The new value for the variable in a Set operation.

The Set operation is performed in up to four steps (testset, commitset, cleanupset, undoset). Only the testset step actually receives the new value. This value is stored here so that it can be delivered to commitset(), undoset() and cleanupset().

Definition at line 112 of file Variable.hpp.

Referenced by agentxcpp::Variable< T >::handle_cleanupset(), agentxcpp::Variable< T >::handle_commitset(), agentxcpp::Variable< T >::handle_testset(), and agentxcpp::Variable< T >::handle_undoset().


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