Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / ACE / ASNMP / asnmp / pdu.h
blob0561bb4cf8ea576950c716764d894f0f134a331e
1 /* -*-C++-*- */
2 #ifndef PDU_CLS_
3 #define PDU_CLS_
4 //=============================================================================
5 /**
6 * @file pdu.h
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 /*===================================================================
17 Copyright (c) 1996
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
35 #define MAX_VBS 25
36 #include "asnmp/vb.h" // include Vb class definition
38 /**
39 * @class Pdu
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
46 public:
47 /// constructor no args
48 Pdu();
50 /// constructor with vbs and count
51 Pdu( Vb* pvbs, const int pvb_count);
53 /// constructor with another Pdu instance
54 Pdu( const Pdu &pdu);
56 /// destructor
57 ~Pdu();
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);
111 /// get the pdu type
112 unsigned short get_type() const;
114 /// set the pdu type
115 void set_type( unsigned short type);
117 /// returns validity of Pdu instance
118 int valid() const;
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();
150 protected:
151 /// pointer to array of Vbs
152 Vb *vbs_[MAX_VBS];
154 /// count of Vbs
155 int vb_count_;
157 /// SMI error status
158 int error_status_;
160 /// SMI error index
161 int error_index_;
163 /// valid boolean status of object construction
164 /// SMI request id
165 int validity_;
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
174 * traps & notifies
176 TimeTicks notify_timestamp_;
178 /// an id
179 Oid notify_id_;
181 Oid notify_enterprise_;
183 private:
184 /// buffer for to_string()
185 char *output_;
190 * @class VbIter
192 * @brief Utility class to iterate once through a PDU varbind list
194 class ASNMP_Export VbIter
196 public:
197 /// default constructor
198 VbIter(Pdu& pdu);
200 /// returns 1 if ok, else 0 if none left
201 int next(Vb& vb);
203 private:
204 /// disallow copy constructor use
205 VbIter(const VbIter&);
207 /// current object in list
208 int idx_;
210 /// ptr to pdu being interated over
211 Pdu *pdu_;
214 #endif //PDU_CLS_