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
PDU.hpp
Go to the documentation of this file.
1 // SNMPpp: https://sourceforge.net/p/snmppp/
2 // SNMPpp project uses the MIT license. See LICENSE for details.
3 // Copyright (C) 2013 Stephane Charette <stephanecharette@gmail.com>
4 
5 #pragma once
6 
7 #include <map>
8 #include <string>
9 #include <SNMPpp/net-snmppp.hpp>
10 #include <SNMPpp/OID.hpp>
11 #include <SNMPpp/Varlist.hpp>
12 
13 
14 namespace SNMPpp
15 {
34  class PDU
35  {
36  public:
37 
41  enum EType
42  {
43  kInvalid = 0 ,
44  kUnknown = 0 , // alias
45  // SNMPv1 and higher:
46  kGet = SNMP_MSG_GET ,
47  kGetNext = SNMP_MSG_GETNEXT ,
48  kResponse = SNMP_MSG_RESPONSE ,
49  kSet = SNMP_MSG_SET ,
50  // SNMPv2 and higher:
51  kGetBulk = SNMP_MSG_GETBULK ,
52  kInform = SNMP_MSG_INFORM ,
53  kTrap2 = SNMP_MSG_TRAP2 ,
54  kReport = SNMP_MSG_REPORT
55  };
56 
58  virtual ~PDU( void );
59 
61  PDU( const EType t );
62 
64  PDU( netsnmp_pdu *p );
65 
67  virtual void free( void );
68 
70  virtual EType getType( void ) const { return type; }
71 
80  virtual void clear( void );
81 
83  virtual bool empty( void ) const;
84 
88  virtual PDU clone( void ) const;
89 
91  virtual operator netsnmp_pdu*( void ) { return pdu; }
92 
94  virtual const SNMPpp::Varlist varlist( void ) const;
95 
97  virtual SNMPpp::Varlist varlist( void );
98 
100  virtual operator netsnmp_variable_list *( void );
101 
103  virtual netsnmp_variable_list * operator[]( const size_t idx );
104 
106  virtual PDU &setVarlist( Varlist &vl );
107 
109  virtual PDU &setVarlist( netsnmp_variable_list *vl );
110 
111  // for convenience, expose a few of the Varlist members we're likely to use in simple cases
112 
114  virtual size_t size( void ) const;
115 
117  virtual bool contains( const SNMPpp::OID &o ) const;
118 
120  virtual SNMPpp::OID firstOID( void ) const;
121 
123  virtual PDU &addNullVar( const SNMPpp::OID &o );
124 
129  virtual PDU &addNullVars( const SNMPpp::SetOID &s );
130 
135  virtual PDU &addNullVars( const SNMPpp::VecOID &v );
136 
137  protected:
138 
140  netsnmp_pdu *pdu; // beware -- this pointer *can* be null if a PDU hasn't been defined or if it has been clear()
141  };
142 };
143 
144 
148 std::ostream &operator<<( std::ostream &os, const SNMPpp::PDU &pdu );