SNMPpp  v0.0.3-20-7eeb228
Classes, methods, and functions to use net-snmp from C++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
SNMPpp::Varlist Class Reference

Wrapper for net-snmp's snmp_variable_list pointer. More...

#include <Varlist.hpp>

Collaboration diagram for SNMPpp::Varlist:

Public Member Functions

 Varlist (void)
 Create a new object. The underlying netsnmp_variable_list pointer will be NULL until an OID is added to the Varlist. More...
 
 Varlist (netsnmp_variable_list *vl)
 Create a new object with the given netsnmp_variable_list pointer. More...
 
virtual ~Varlist (void)
 Destructor. More...
 
virtual VarlistaddNullVar (const SNMPpp::OID &o)
 Equivalent to snmp_add_null_var() which adds a placeholder in the PDU for this OID. More...
 
virtual VarlistaddNullVars (const SNMPpp::SetOID &s)
 Same as addNullVar(), but allows multiple OIDs to be added at once by using a std::set of OID objects. More...
 
virtual VarlistaddNullVars (const SNMPpp::VecOID &v)
 Same as addNullVar(), but allows multiple OIDs to be added at at once by using a std::vector of OID objects. More...
 
virtual int asnType (const SNMPpp::OID &o) const
 Return the ASN type for the given OID. More...
 
virtual int asnType (void) const
 Similar to SNMPpp::Varlist::asnType( const SNMPpp::OID &o ) const but if the varlist contains multiple objects, assumes only the first one is of interest. More...
 
virtual std::string asString (const SNMPpp::OID &o) const
 Convert any of the known basic ASN types to a easy-to-use text string. More...
 
virtual std::string asString (void) const
 Similar to SNMPpp::Varlist::asString( const SNMPpp::OID &o ) const but if the varlist contains multiple objects, assumes only the first one is of interest. More...
 
virtual const
netsnmp_variable_list * 
at (const SNMPpp::OID &o) const
 Return the underlying netsnmp_variable_list pointer which describes the given OID object. More...
 
virtual void clear (void)
 If a net-snmp function has been called which we know has already freed the netsmp_varlist pointer, call clear() to ensure this C++ wrapper object doesn't keep the pointer to the old memory location. More...
 
virtual bool contains (const SNMPpp::OID &o) const
 See if the given OID is in the varlist. More...
 
virtual bool empty (void) const
 Return TRUE if the netsnmp_variable_list pointer is NULL. More...
 
virtual SNMPpp::OID firstOID (void) const
 Return the first OID object in the varlist. This will throw if the varlist is empty. More...
 
virtual void free (void)
 Free up the net-snmp structure by calling snmp_free_varbind(). More...
 
virtual bool getBool (const SNMPpp::OID &o) const
 Retrieve the value of the given boolean OID. More...
 
virtual bool getBool (void) const
 Similar to SNMP::Varlist::getBool( const SNMPpp::OID &o ) const but if the varlist contains multiple objects, assumes only the first one is of interest. More...
 
virtual long getLong (const SNMPpp::OID &o) const
 Retrieve the value of the given long OID. More...
 
virtual long getLong (void) const
 Similar to SNMPpp::Varlist::getLong( const SNMPpp::OID &o ) const but if the varlist contains multiple objects, assumes only the first one is of interest. More...
 
virtual MapOidVarList getMap (void) const
 Get a map of OID -> net-snmp's varlist for every OID in this varlist. More...
 
virtual SNMPpp::OID getOID (const SNMPpp::OID &o) const
 Retrieve the value of the given object OID. More...
 
virtual SNMPpp::OID getOID (void) const
 Similar to SNMPpp::Varlist::getOID( const SNMPpp::OID &o ) const but if the varlist contains multiple objects, assumes only the first one is of interest. More...
 
virtual const VarlistgetOids (SNMPpp::VecOID &v) const
 Get a std::vector of all the OIDs in the varlist. More...
 
virtual const VarlistgetOids (SNMPpp::SetOID &s) const
 Get a std::set of all the OIDs in the varlist. More...
 
virtual std::string getString (const SNMPpp::OID &o) const
 Retrieve the value of the given string OID. More...
 
virtual std::string getString (void) const
 Similar to SNMPpp::Varlist::getString( const SNMPpp::OID &o ) const but if the varlist contains multiple objects, assumes only the first one is of interest. More...
 
virtual operator netsnmp_variable_list * (void)
 Easily convert Varlist to the base net-snmp type for passing into net-snmp API. Will return NULL if the varlist is empty. More...
 
virtual operator netsnmp_variable_list ** (void)
 Easily convert Varlist to the base net-snmp type for passing into net-snmp API. More...
 
virtual netsnmp_variable_list * operator[] (const size_t idx)
 Return the [N]th netsnmp_variable_list pointer. More...
 
virtual size_t size (void) const
 Return the number of variables in this object. More...
 
virtual const netsnmp_vardata & value (void) const
 Similar to SNMPpp::Varlist::valueAt( const SNMPpp::OID &o ) const but if the varlist contains multiple objects, assumes only the first one is of interest. More...
 
virtual const netsnmp_vardata & valueAt (const SNMPpp::OID &o) const
 Retrieve the net-snmp value structure associated with an OID. More...
 

Protected Attributes

netsnmp_variable_list * varlist
 This is the basic varlist pointer from net-snmp. Beware, this pointer will be NULL when a varlist is empty. More...
 

Detailed Description

Wrapper for net-snmp's snmp_variable_list pointer.

These objects are extremely small (just a pointer) and can easily be created on the stack or as a member of another class.

Many other parts of SNMPpp can accept Varlist objects by reference, and Varlist includes the necessary operators so they can be used wherever snmp_variable_list* pointers are typically used.

Constructor & Destructor Documentation

SNMPpp::Varlist::~Varlist ( void  )
virtual

Destructor.

Note
The destructor does not free up the underlying netsnmp_variable_list pointer! This isn't done automatically since many of the net-snmp APIs that act on variable lists already free up or take ownership of varlists.

If you aren't calling a net-snmp function that frees up the varlist pointer, remember to call free() prior to destructing the object.

See Also
clear();
free();
SNMPpp::Varlist::Varlist ( void  )

Create a new object. The underlying netsnmp_variable_list pointer will be NULL until an OID is added to the Varlist.

SNMPpp::Varlist::Varlist ( netsnmp_variable_list *  vl)

Create a new object with the given netsnmp_variable_list pointer.

Using a NULL pointer is valid, it creates an empty object just like the other Varlist() constructor.

Member Function Documentation

SNMPpp::Varlist & SNMPpp::Varlist::addNullVar ( const SNMPpp::OID o)
virtual

Equivalent to snmp_add_null_var() which adds a placeholder in the PDU for this OID.

The "null" refers to how a type and value value aren't specified, just the OID. This is typically used when retrieving values from a SNMP server.

Exceptions
std::invalid_argumentif the OID is empty.
std::runtime_errorif net-snmp failed to add the OID.

Here is the call graph for this function:

Here is the caller graph for this function:

SNMPpp::Varlist & SNMPpp::Varlist::addNullVars ( const SNMPpp::SetOID s)
virtual

Same as addNullVar(), but allows multiple OIDs to be added at once by using a std::set of OID objects.

Calling with an empty set is perfectly valid.

Here is the caller graph for this function:

SNMPpp::Varlist & SNMPpp::Varlist::addNullVars ( const SNMPpp::VecOID v)
virtual

Same as addNullVar(), but allows multiple OIDs to be added at at once by using a std::vector of OID objects.

Calling with an empty vector is perfectly valid.

virtual int SNMPpp::Varlist::asnType ( const SNMPpp::OID o) const
inlinevirtual

Return the ASN type for the given OID.

This will throw if the varlist object does not contain the specified OID. The ASN types are defined in net-snmp. For example, see net-snmp/library/asn1.h:

NET-SNMP TYPE NAME NET-SNMP TYPE VALUE
ASN_BOOLEAN 1
ASN_INTEGER 2
ASN_BIT_STR 3
ASN_OCTET_STR 4
ASN_NULL 5
ASN_OBJECT_ID 6
ASN_SEQUENCE 16
ASN_SET 17
ASN_IPADDRESS 64
ASN_COUNTER 65
ASN_GAUGE 66
ASN_TIMETICKS 67
See Also
asnType( void ) const

Here is the call graph for this function:

Here is the caller graph for this function:

virtual int SNMPpp::Varlist::asnType ( void  ) const
inlinevirtual

Similar to SNMPpp::Varlist::asnType( const SNMPpp::OID &o ) const but if the varlist contains multiple objects, assumes only the first one is of interest.

See Also
SNMPpp::Varlist::asnType( const SNMPpp::OID &o ) const
SNMPpp::Varlist::asString( void ) const

Here is the call graph for this function:

Here is the caller graph for this function:

std::string SNMPpp::Varlist::asString ( const SNMPpp::OID o) const
virtual

Convert any of the known basic ASN types to a easy-to-use text string.

E.g., booleans are converted to the text strings "true" and "false", etc.

See Also
SNMPpp::Varlist::asString( void ) const

Here is the caller graph for this function:

virtual std::string SNMPpp::Varlist::asString ( void  ) const
inlinevirtual

Similar to SNMPpp::Varlist::asString( const SNMPpp::OID &o ) const but if the varlist contains multiple objects, assumes only the first one is of interest.

See Also
SNMPpp::Varlist::asString( const SNMPpp::OID &o ) const

Here is the call graph for this function:

Here is the caller graph for this function:

const netsnmp_variable_list * SNMPpp::Varlist::at ( const SNMPpp::OID o) const
virtual

Return the underlying netsnmp_variable_list pointer which describes the given OID object.

The net-snmp type contains everything net-snmp currently knows about an OID, including a pointer to the next variable which is how net-snmp uses this structure to describe both specific OIDs and vectors of OIDs. This method will throw if the requested OID does not exist in the varlist.

Exceptions
std::invalid_argumentif the varlist does not contain the requested OID.

Here is the call graph for this function:

Here is the caller graph for this function:

virtual void SNMPpp::Varlist::clear ( void  )
inlinevirtual

If a net-snmp function has been called which we know has already freed the netsmp_varlist pointer, call clear() to ensure this C++ wrapper object doesn't keep the pointer to the old memory location.

Note
Don't miss the difference between clear() and free(). This one will leak memory if snmp_free_varbind() hasn't yet been called.
See Also
free();

Here is the caller graph for this function:

bool SNMPpp::Varlist::contains ( const SNMPpp::OID o) const
virtual

See if the given OID is in the varlist.

virtual bool SNMPpp::Varlist::empty ( void  ) const
inlinevirtual

Return TRUE if the netsnmp_variable_list pointer is NULL.

This normally means no OIDs have been added, or free() has been called.

Here is the caller graph for this function:

SNMPpp::OID SNMPpp::Varlist::firstOID ( void  ) const
virtual

Return the first OID object in the varlist. This will throw if the varlist is empty.

Exceptions
std::logic_errorif the varlist is empty.

Here is the caller graph for this function:

void SNMPpp::Varlist::free ( void  )
virtual

Free up the net-snmp structure by calling snmp_free_varbind().

See Also
clear();

Here is the caller graph for this function:

bool SNMPpp::Varlist::getBool ( const SNMPpp::OID o) const
virtual

Retrieve the value of the given boolean OID.

See Also
SNMPpp::Varlist::getBool( void ) const
SNMPpp::Varlist::asString()
Exceptions
std::invalid_argumentif the requested OID is not ASN_BOOLEAN.

Here is the call graph for this function:

virtual bool SNMPpp::Varlist::getBool ( void  ) const
inlinevirtual

Similar to SNMP::Varlist::getBool( const SNMPpp::OID &o ) const but if the varlist contains multiple objects, assumes only the first one is of interest.

See Also
SNMPpp::Varlist::getBool( const SNMPpp::OID &o ) const
SNMPpp::Varlist::asString( void ) const

Here is the call graph for this function:

Here is the caller graph for this function:

long SNMPpp::Varlist::getLong ( const SNMPpp::OID o) const
virtual

Retrieve the value of the given long OID.

See Also
SNMPpp::Varlist::getLong() const
SNMPpp::Varlist::asString()
Exceptions
std::invalid_argumentif the requested OID is not ASN_INTEGER.

Here is the call graph for this function:

virtual long SNMPpp::Varlist::getLong ( void  ) const
inlinevirtual

Similar to SNMPpp::Varlist::getLong( const SNMPpp::OID &o ) const but if the varlist contains multiple objects, assumes only the first one is of interest.

See Also
SNMPpp::Varlist::getLong( const SNMPpp::OID &o ) const
SNMPpp::Varlist::asString( void ) const

Here is the call graph for this function:

Here is the caller graph for this function:

SNMPpp::MapOidVarList SNMPpp::Varlist::getMap ( void  ) const
virtual

Get a map of OID -> net-snmp's varlist for every OID in this varlist.

SNMPpp::OID SNMPpp::Varlist::getOID ( const SNMPpp::OID o) const
virtual

Retrieve the value of the given object OID.

See Also
SNMPpp::Varlist::getOid( void ) const
SNMPpp::Varlist::asString()
Exceptions
std::invalid_argumentif the requested OID is not ASN_OBJECT_ID.

Here is the call graph for this function:

virtual SNMPpp::OID SNMPpp::Varlist::getOID ( void  ) const
inlinevirtual

Similar to SNMPpp::Varlist::getOID( const SNMPpp::OID &o ) const but if the varlist contains multiple objects, assumes only the first one is of interest.

See Also
SNMPpp::Varlist::getOID( const SNMPpp::OID &o ) const
SNMPpp::Varlist::asString( void ) const

Here is the call graph for this function:

Here is the caller graph for this function:

const SNMPpp::Varlist & SNMPpp::Varlist::getOids ( SNMPpp::VecOID v) const
virtual

Get a std::vector of all the OIDs in the varlist.

Note
The vector will retain the same position and duplicates as netsnmp_variable_list.
See Also
SNMPpp::Varlist::getOids( SNMPpp::SetOID &s ) const;

Here is the call graph for this function:

Here is the caller graph for this function:

const SNMPpp::Varlist & SNMPpp::Varlist::getOids ( SNMPpp::SetOID s) const
virtual

Get a std::set of all the OIDs in the varlist.

Note
Unlike snmp_variable_list and std::vector, the std::set will not contain duplicate entries.
See Also
SNMPpp::Varlist::getOids( SNMPpp::VecOID &v ) const;

Here is the call graph for this function:

std::string SNMPpp::Varlist::getString ( const SNMPpp::OID o) const
virtual

Retrieve the value of the given string OID.

See Also
SNMPpp::Varlist::getString( void ) const
Exceptions
std::invalid_argumentif the requested OID is not ASN_OCTET_STR.

Here is the call graph for this function:

Here is the caller graph for this function:

virtual std::string SNMPpp::Varlist::getString ( void  ) const
inlinevirtual

Similar to SNMPpp::Varlist::getString( const SNMPpp::OID &o ) const but if the varlist contains multiple objects, assumes only the first one is of interest.

See Also
SNMPpp::Varlist::getString( const SNMPpp::OID &o ) const

Here is the call graph for this function:

Here is the caller graph for this function:

virtual SNMPpp::Varlist::operator netsnmp_variable_list * ( void  )
inlinevirtual

Easily convert Varlist to the base net-snmp type for passing into net-snmp API. Will return NULL if the varlist is empty.

virtual SNMPpp::Varlist::operator netsnmp_variable_list ** ( void  )
inlinevirtual

Easily convert Varlist to the base net-snmp type for passing into net-snmp API.

netsnmp_variable_list * SNMPpp::Varlist::operator[] ( const size_t  idx)
virtual

Return the [N]th netsnmp_variable_list pointer.

Returns
Returns a NULL pointer if the index is larger than the number of items in the variable list.

Runs in O(n) since it needs to walk the linked list of netsnmp_variable_list pointers.

virtual size_t SNMPpp::Varlist::size ( void  ) const
inlinevirtual

Return the number of variables in this object.

Runs in O(n) as it needs to traverse the entire linked list every time it is called. (The size is not cached anywhere in Varlist.)

Here is the caller graph for this function:

virtual const netsnmp_vardata& SNMPpp::Varlist::value ( void  ) const
inlinevirtual

Similar to SNMPpp::Varlist::valueAt( const SNMPpp::OID &o ) const but if the varlist contains multiple objects, assumes only the first one is of interest.

See Also
SNMPpp::Varlist::valueAt( const SNMPpp::OID &o ) const
SNMPpp::Varlist::asString( void ) const

Here is the call graph for this function:

virtual const netsnmp_vardata& SNMPpp::Varlist::valueAt ( const SNMPpp::OID o) const
inlinevirtual

Retrieve the net-snmp value structure associated with an OID.

Also see at().val_len which may be required to properly interpret some values, such as strings and OIDs.

See Also
SNMPpp::Varlist::at() const
SNMPpp::Varlist::value( void ) const

Here is the call graph for this function:

Here is the caller graph for this function:

Member Data Documentation

netsnmp_variable_list* SNMPpp::Varlist::varlist
protected

This is the basic varlist pointer from net-snmp. Beware, this pointer will be NULL when a varlist is empty.


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