AgentXcpp  Revision:4ac4848
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 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 
00024 #include "types.hpp"
00025 #include "oid.hpp"
00026 #include "variable.hpp"
00027 
00028 namespace agentxcpp
00029 {
00030     /**
00031      * \internal
00032      *
00033      * \brief Represents a VarBind according to RFC 2741, section 5.4.
00034      */
00035     class varbind
00036     {
00037         private:
00038             /**
00039              * \brief The name (OID) of the VarBind.
00040              */
00041             oid* name;
00042 
00043             /**
00044              * \brief The variable inside the varbind.
00045              *
00046              * This pointer may be 0 if the varbind has a type without a 
00047              * variable (e.g. "NoSuchObject").
00048              */
00049             variable* var;
00050 
00051             /**
00052              * \brief The type of the varbind.
00053              *
00054              * This field represents the type as described in RFC 2741, section 
00055              * 5.4. The serialize() function will copy it directly into the 
00056              * varbind.
00057              */
00058             uint16_t type;
00059         public:
00060 
00061             /**
00062              * \brief Create a VarBind with an oid and a var.
00063              *
00064              * The variable must be one of the following types:
00065              * - Integer
00066              * - Octet_String
00067              * - oid
00068              * - IpAddress
00069              * - Counter32
00070              * - Gauge32
00071              * - TimeTicks
00072              * - Opaque
00073              * - Counter64
00074              * If the type of the variable cannot be determined, inval_param is 
00075              * thrown.
00076              */
00077             varbind(oid*, variable* v);
00078             
00079             /**
00080              * \brief These values can be used to create a VarBind.
00081              */
00082             enum type_t {
00083                 Null = 5,
00084                 noSuchObject = 128,
00085                 noSuchInstance = 129,
00086                 endOfMibView = 130
00087             };
00088 
00089 
00090             /**
00091              * \brief Create VarBind without var, but with a type.
00092              *
00093              * Only the constants defined by varbind::type_t are allowed.  A 
00094              * wrong type will cause an inval_param exception.
00095              */
00096             varbind(oid*, type_t);
00097 
00098             /**
00099              * \internal
00100              *
00101              * \brief Construct the object from input stream
00102              *
00103              * This constructor parses the serialized form of the object.
00104              * It takes an iterator, starts parsing at the position of the 
00105              * iterator and advances the iterator to the position right behind 
00106              * the object.
00107              * 
00108              * The constructor expects valid data from the stream; if parsing 
00109              * fails, parse_error is thrown. In this case, the iterator 
00110              * position is undefined.
00111              *
00112              * \param pos Iterator pointing to the current stream position.
00113              *            The iterator is advanced while reading the header.
00114              *
00115              * \param end Iterator pointing one element past the end of the
00116              *            current stream. This is needed to mark the end of the 
00117              *            buffer.
00118              *
00119              * \param big_endian Whether the input stream is in big endian
00120              *                   format
00121              */
00122             varbind(data_t::const_iterator& pos,
00123                     const data_t::const_iterator& end,
00124                     bool big_endian=true);
00125 
00126             /**
00127              * \internal
00128              *
00129              * \brief Serialize the varbind.
00130              *
00131              * This creates the binary representation of the varbind.
00132              */
00133             data_t serialize() const;
00134 
00135     };
00136 
00137 }
00138 #endif