Wrapper for net-snmp's snmp_variable_list pointer. More...
#include <Varlist.hpp>
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 Varlist & | addNullVar (const SNMPpp::OID &o) |
Equivalent to snmp_add_null_var() which adds a placeholder in the PDU for this OID. More... | |
virtual Varlist & | addNullVars (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 Varlist & | addNullVars (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 Varlist & | getOids (SNMPpp::VecOID &v) const |
Get a std::vector of all the OIDs in the varlist. More... | |
virtual const Varlist & | getOids (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... | |
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.
|
virtual |
Destructor.
If you aren't calling a net-snmp function that frees up the varlist pointer, remember to call free() prior to destructing the object.
SNMPpp::Varlist::Varlist | ( | void | ) |
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.
|
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.
std::invalid_argument | if the OID is empty. |
std::runtime_error | if net-snmp failed to add the OID. |
|
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.
|
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.
|
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 |
|
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.
|
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.
|
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.
|
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.
std::invalid_argument | if the varlist does not contain the requested OID. |
|
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.
|
virtual |
See if the given OID is in the varlist.
|
inlinevirtual |
Return TRUE
if the netsnmp_variable_list pointer is NULL.
This normally means no OIDs have been added, or free() has been called.
|
virtual |
Return the first OID object in the varlist. This will throw if the varlist is empty.
std::logic_error | if the varlist is empty. |
|
virtual |
Free up the net-snmp structure by calling snmp_free_varbind().
|
virtual |
|
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.
|
virtual |
|
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.
|
virtual |
|
virtual |
Retrieve the value of the given object OID.
std::invalid_argument | if the requested OID is not ASN_OBJECT_ID . |
|
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.
|
virtual |
Get a std::vector of all the OIDs in the varlist.
netsnmp_variable_list
.
|
virtual |
Get a std::set of all the OIDs in the varlist.
snmp_variable_list
and std::vector, the std::set will not contain duplicate entries.
|
virtual |
|
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.
|
inlinevirtual |
Easily convert Varlist to the base net-snmp type for passing into net-snmp API. Will return NULL if the varlist is empty.
|
inlinevirtual |
Easily convert Varlist to the base net-snmp type for passing into net-snmp API.
|
virtual |
Return the [N]th netsnmp_variable_list pointer.
Runs in O(n) since it needs to walk the linked list of netsnmp_variable_list pointers.
|
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.)
|
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.
|
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.
|
protected |
This is the basic varlist pointer from net-snmp. Beware, this pointer will be NULL when a varlist is empty.