AgentXcpp  Revision:0.1.1
Internals Documentation
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Friends Pages
varbind.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2011-2012 Tanjeff-Nicolai Moos <tanjeff@cccmz.de>
3  *
4  * This file is part of the agentXcpp library.
5  *
6  * AgentXcpp is free software: you can redistribute it and/or modify
7  * it under the terms of the AgentXcpp library license, version 1, which
8  * consists of the GNU General Public License and some additional
9  * permissions.
10  *
11  * AgentXcpp is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * See the AgentXcpp library license in the LICENSE file of this package
17  * for more details.
18  */
19 #ifndef _VARBIND_H_
20 #define _VARBIND_H_
21 
22 #include <istream>
23 
24 #include <boost/shared_ptr.hpp>
25 #include <boost/cstdint.hpp>
26 
27 #include "oid.hpp"
28 #include "variable.hpp"
29 
30 using boost::uint16_t;
31 
32 namespace agentxcpp
33 {
34  /**
35  * \internal
36  *
37  * \brief Represents a VarBind according to RFC 2741, section 5.4.
38  */
39  class varbind
40  {
41  private:
42  /**
43  * \brief The name (OID) of the VarBind.
44  */
46 
47  /**
48  * \brief The variable inside the varbind.
49  *
50  * This pointer may be 0 if the varbind has a type without a
51  * variable (e.g. "NoSuchObject").
52  */
53  boost::shared_ptr<variable> var;
54 
55  /**
56  * \brief The type of the varbind.
57  *
58  * This field represents the type as described in RFC 2741, section
59  * 5.4. The serialize() function will copy it directly into the
60  * varbind.
61  */
62  uint16_t type;
63  public:
64 
65  /**
66  * \brief Create a VarBind with an oid and a var.
67  *
68  * The variable must be one of the following types:
69  * - Integer
70  * - Octet_String
71  * - oid
72  * - IpAddress
73  * - Counter32
74  * - Gauge32
75  * - TimeTicks
76  * - Opaque
77  * - Counter64
78  * If the type of the variable cannot be determined, inval_param is
79  * thrown.
80  */
81  varbind(const oid&, boost::shared_ptr<variable> v);
82 
83  /**
84  * \brief These values can be used to create a VarBind.
85  */
86  enum type_t {
87  Null = 5,
88  noSuchObject = 128,
91  };
92 
93 
94  /**
95  * \brief Create VarBind without var, but with a type.
96  *
97  * Only the constants defined by varbind::type_t are allowed. A
98  * wrong type will cause an inval_param exception.
99  */
100  varbind(const oid&, type_t);
101 
102  /**
103  * \internal
104  *
105  * \brief Construct the object from input stream
106  *
107  * This constructor parses the serialized form of the object.
108  * It takes an iterator, starts parsing at the position of the
109  * iterator and advances the iterator to the position right behind
110  * the object.
111  *
112  * The constructor expects valid data from the stream; if parsing
113  * fails, parse_error is thrown. In this case, the iterator
114  * position is undefined.
115  *
116  * \param pos Iterator pointing to the current stream position.
117  * The iterator is advanced while reading the header.
118  *
119  * \param end Iterator pointing one element past the end of the
120  * current stream. This is needed to mark the end of the
121  * buffer.
122  *
123  * \param big_endian Whether the input stream is in big endian
124  * format
125  */
126  varbind(binary::const_iterator& pos,
127  const binary::const_iterator& end,
128  bool big_endian=true);
129 
130  /**
131  * \internal
132  *
133  * \brief Serialize the varbind.
134  *
135  * This creates the binary representation of the varbind.
136  */
137  binary serialize() const;
138 
139  };
140 
141 }
142 #endif