4 //=============================================================================
8 * Pdu class definition. Encapsulation of an SMI Protocol
9 * Data Unit (PDU) aka Packet in C++.
11 * @author Peter E Mellquist original code Michael MacFaden mrm@cisco.com ACE port
12 * @author add iterator class for pdus
14 //=============================================================================
16 /*===================================================================
18 Hewlett-Packard Company
20 ATTENTION: USE OF THIS SOFTWARE IS SUBJECT TO THE FOLLOWING TERMS.
21 Permission to use, copy, modify, distribute and/or sell this software
22 and/or its documentation is hereby granted without fee. User agrees
23 to display the above copyright notice and this license notice in all
24 copies of the software and any documentation of the software. User
25 agrees to assume all liability for the use of the software; Hewlett-Packard
26 makes no representations about the suitability of this software for any
27 purpose. It is provided "AS-IS without warranty of any kind,either express
28 or implied. User hereby grants a royalty-free license to any and all
29 derivatives based upon this software code base.
30 =====================================================================*/
32 // TODO: this needs to be moved into the CLASS and modifyable at runtime
33 // TODO: define an iterator object to traverse the vbs in a pdu
36 #include "asnmp/vb.h" // include Vb class definition
41 * @brief Protocol Data Unit (PDU) concrete class. An abstraction of the
42 * data packet used to by two SNMP sessions to communicate.
44 class ASNMP_Export Pdu
47 /// constructor no args
50 /// constructor with vbs and count
51 Pdu( Vb
* pvbs
, const int pvb_count
);
53 /// constructor with another Pdu instance
59 /// assignment to another Pdu object overloaded
60 Pdu
& operator=( const Pdu
&pdu
);
62 /// append a vb to the pdu
63 Pdu
& operator+=( Vb
&vb
);
65 // TODO: add Pdu& operator-=(const Vb &vb);
67 /// extract all Vbs from Pdu
68 int get_vblist( Vb
* pvbs
, const int pvb_count
);
70 /// deposit all Vbs to Pdu
71 int set_vblist( Vb
* pvbs
, const int pvb_count
);
73 /// get a particular vb
74 /// where 0 is the first vb
75 int get_vb( Vb
&vb
, const int index
= 0) const;
77 /// set a particular vb
78 /// where 0 is the first vb
79 int set_vb( Vb
&vb
, const int index
);
81 /// return number of vbs
82 int get_vb_count() const;
84 /// return the error status
85 int get_error_status() const;
87 /// return the complete error info from this pdu
88 const char *agent_error_reason();
90 /// set the error status
91 friend ASNMP_Export
void set_error_status( Pdu
*pdu
, const int status
);
93 /// return the error index
94 int get_error_index() const;
96 /// set the error index
97 friend ASNMP_Export
void set_error_index( Pdu
*pdu
, const int index
);
99 /// clear error status
100 friend ASNMP_Export
void clear_error_status( Pdu
*pdu
);
102 /// clear error index
103 friend ASNMP_Export
void clear_error_index( Pdu
*pdu
);
105 /// return the request id
106 unsigned long get_request_id() const;
108 /// set the request id
109 friend void set_request_id( Pdu
*pdu
, const unsigned long rid
);
112 unsigned short get_type() const;
115 void set_type( unsigned short type
);
117 /// returns validity of Pdu instance
120 /// trim off count vbs from the end of the vb list
121 int trim(const int count
=1);
123 /// delete a Vb anywhere within the Pdu
124 int delete_vb( const int position
);
126 /// delete_all vbs in pdu
127 void delete_all_vbs();
129 /// set notify timestamp
130 void set_notify_timestamp( const TimeTicks
& timestamp
);
132 /// get notify timestamp
133 void get_notify_timestamp( TimeTicks
& timestamp
) const;
135 /// set the notify id
136 void set_notify_id( const Oid id
);
138 /// get the notify id
139 void get_notify_id( Oid
&id
) const;
141 /// set the notify enterprise
142 void set_notify_enterprise( const Oid
&enterprise
);
144 /// get the notify enterprise
145 void get_notify_enterprise( Oid
& enterprise
) const;
147 /// return fomatted version of this object
148 const char *to_string();
151 /// pointer to array of Vbs
163 /// valid boolean status of object construction
166 unsigned long request_id_
;
168 /// derived at run time based on request type
169 unsigned short pdu_type_
;
172 * a timestamp associated with an infor
173 * for notify Pdu objects only
176 TimeTicks notify_timestamp_
;
181 Oid notify_enterprise_
;
184 /// buffer for to_string()
192 * @brief Utility class to iterate once through a PDU varbind list
194 class ASNMP_Export VbIter
197 /// default constructor
200 /// returns 1 if ok, else 0 if none left
204 /// disallow copy constructor use
205 VbIter(const VbIter
&);
207 /// current object in list
210 /// ptr to pdu being interated over