AgentXcpp  Revision:0.1
Internals Documentation
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends
/home/tanjeff/projekte/agentxcpp/src/varbind.hpp
Go to the documentation of this file.
00001 /*
00002  * Copyright 2011-2012 Tanjeff-Nicolai Moos <tanjeff@cccmz.de>
00003  *
00004  * This file is part of the agentXcpp library.
00005  *
00006  * AgentXcpp is free software: you can redistribute it and/or modify
00007  * it under the terms of the AgentXcpp library license, version 1, which 
00008  * consists of the GNU General Public License and some additional 
00009  * permissions.
00010  *
00011  * AgentXcpp is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * See the AgentXcpp library license in the LICENSE file of this package 
00017  * for more details.
00018  */
00019 #ifndef _VARBIND_H_
00020 #define _VARBIND_H_
00021 
00022 #include <istream>
00023 #include <boost/shared_ptr.hpp>
00024 
00025 #include "types.hpp"
00026 #include "oid.hpp"
00027 #include "variable.hpp"
00028 
00029 namespace agentxcpp
00030 {
00031     /**
00032      * \internal
00033      *
00034      * \brief Represents a VarBind according to RFC 2741, section 5.4.
00035      */
00036     class varbind
00037     {
00038         private:
00039             /**
00040              * \brief The name (OID) of the VarBind.
00041              */
00042             oid name;
00043 
00044             /**
00045              * \brief The variable inside the varbind.
00046              *
00047              * This pointer may be 0 if the varbind has a type without a 
00048              * variable (e.g. "NoSuchObject").
00049              */
00050             boost::shared_ptr<variable> var;
00051 
00052             /**
00053              * \brief The type of the varbind.
00054              *
00055              * This field represents the type as described in RFC 2741, section 
00056              * 5.4. The serialize() function will copy it directly into the 
00057              * varbind.
00058              */
00059             uint16_t type;
00060         public:
00061 
00062             /**
00063              * \brief Create a VarBind with an oid and a var.
00064              *
00065              * The variable must be one of the following types:
00066              * - Integer
00067              * - Octet_String
00068              * - oid
00069              * - IpAddress
00070              * - Counter32
00071              * - Gauge32
00072              * - TimeTicks
00073              * - Opaque
00074              * - Counter64
00075              * If the type of the variable cannot be determined, inval_param is 
00076              * thrown.
00077              */
00078             varbind(const oid&, boost::shared_ptr<variable> v);
00079             
00080             /**
00081              * \brief These values can be used to create a VarBind.
00082              */
00083             enum type_t {
00084                 Null = 5,
00085                 noSuchObject = 128,
00086                 noSuchInstance = 129,
00087                 endOfMibView = 130
00088             };
00089 
00090 
00091             /**
00092              * \brief Create VarBind without var, but with a type.
00093              *
00094              * Only the constants defined by varbind::type_t are allowed.  A 
00095              * wrong type will cause an inval_param exception.
00096              */
00097             varbind(const oid&, type_t);
00098 
00099             /**
00100              * \internal
00101              *
00102              * \brief Construct the object from input stream
00103              *
00104              * This constructor parses the serialized form of the object.
00105              * It takes an iterator, starts parsing at the position of the 
00106              * iterator and advances the iterator to the position right behind 
00107              * the object.
00108              * 
00109              * The constructor expects valid data from the stream; if parsing 
00110              * fails, parse_error is thrown. In this case, the iterator 
00111              * position is undefined.
00112              *
00113              * \param pos Iterator pointing to the current stream position.
00114              *            The iterator is advanced while reading the header.
00115              *
00116              * \param end Iterator pointing one element past the end of the
00117              *            current stream. This is needed to mark the end of the 
00118              *            buffer.
00119              *
00120              * \param big_endian Whether the input stream is in big endian
00121              *                   format
00122              */
00123             varbind(data_t::const_iterator& pos,
00124                     const data_t::const_iterator& end,
00125                     bool big_endian=true);
00126 
00127             /**
00128              * \internal
00129              *
00130              * \brief Serialize the varbind.
00131              *
00132              * This creates the binary representation of the varbind.
00133              */
00134             data_t serialize() const;
00135 
00136     };
00137 
00138 }
00139 #endif