From fda9fbca853e2757ed4640fff1cd892e1cf7c364 Mon Sep 17 00:00:00 2001 From: "Tanjeff-N. Moos" Date: Thu, 19 Jul 2012 20:31:02 +0200 Subject: [PATCH 01/89] Add script to create packages for a release. --- create-release.sh | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100755 create-release.sh diff --git a/create-release.sh b/create-release.sh new file mode 100755 index 0000000..e1ec2e6 --- /dev/null +++ b/create-release.sh @@ -0,0 +1,26 @@ +#!/bin/sh + +if [ -z "$1" ] +then + echo "Usage:" + echo "$0 " +fi + + +git archive --format=tar "--prefix=agentXcpp-$1/" "$1" \ + | gzip > "agentXcpp-$1.tar.gz" + +if [ $? -ne 0 ] +then + echo "Error." + exit +fi + +git archive --format=zip "--prefix=agentXcpp-$1/" "$1" \ + -o "agentXcpp-$1.zip" + +if [ $? -ne 0 ] +then + echo "Error." + exit +fi From 4ece21fd5ad27e8697be0bf1dfe4e4024541c9eb Mon Sep 17 00:00:00 2001 From: "Tanjeff-N. Moos" Date: Thu, 19 Jul 2012 21:05:33 +0200 Subject: [PATCH 02/89] Document how to make a release. --- doc/release_howto.dox | 54 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 doc/release_howto.dox diff --git a/doc/release_howto.dox b/doc/release_howto.dox new file mode 100644 index 0000000..84615c4 --- /dev/null +++ b/doc/release_howto.dox @@ -0,0 +1,54 @@ +/* + * Copyright 2011-2012 Tanjeff-Nicolai Moos + * + * This file is part of the agentXcpp library. + * + * AgentXcpp is free software: you can redistribute it and/or modify + * it under the terms of the AgentXcpp library license, version 1, which + * consists of the GNU General Public License and some additional + * permissions. + * + * AgentXcpp is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * See the AgentXcpp library license in the LICENSE file of this package + * for more details. + */ + +/*! + + +\page release_howto How to create an agentXcpp release + +Creating releases should be a process which creates packages reproducible, +consistent packages of the software. + +-# Update the ChangeLog. Check it in. +-# Choose a git commit which shall be released. +-# Test the chosen commit:
+ -# Clone the repo to a fresh directory, avoid having untracked files. + Alternatively, remove ALL untracked files from your working copy. + -# Checkout the chosen commit + -# Build the software + -# Perform the howto (\ref subagent_howto). + -# If the test fails: no release possible; fix it and re-start from the + beginning. If the test succeeds: continue. +-# Create a git tag for the release.
+ Each release shall have a tag to uniqely identify it. +-# Create the packages, preferably using the create-release.sh script.
+ The packages shall have the names agentXcpp-<version>.tar.gz and + agentXcpp-<version>.zip respectively, where <version> is the + tag name. The contents shall be a single directory named + agentXcpp-<version>. This directory shall contain the source code. + This is all ensured by the create_release.sh script. +-# Test one of the packages.
+ -# Unpack it + -# Build the contained software + -# Perform the howto (\ref subagent_howto). + -# If the test fails: no release possible; fix it and re-start from the + beginning. +-# If the test succeeds, the release can be published. + +*/ From c3d1baa3c686d81beb1b885c24cf529968a31548 Mon Sep 17 00:00:00 2001 From: "Tanjeff-N. Moos" Date: Thu, 18 Apr 2013 22:57:00 +0200 Subject: [PATCH 03/89] Improve the create-release.sh script. --- create-release.sh | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/create-release.sh b/create-release.sh index e1ec2e6..a401327 100755 --- a/create-release.sh +++ b/create-release.sh @@ -4,21 +4,37 @@ if [ -z "$1" ] then echo "Usage:" echo "$0 " + exit 0 fi +git describe "$1" > /dev/null +if [ $? -ne 0 ] +then + echo "Error: $1 is not a value specifier." + exit +fi -git archive --format=tar "--prefix=agentXcpp-$1/" "$1" \ - | gzip > "agentXcpp-$1.tar.gz" - +git archive --format=tar \ + "--prefix=agentXcpp-$1/" \ + "$1" \ + -o "agentXcpp-$1.tar" if [ $? -ne 0 ] then - echo "Error." + echo "Error: git was not able to create an archive." + exit +fi + +gzip "agentXcpp-$1.tar" +if [ $? -ne 0 ] +then + echo "Error: gzip was not able to compress the archive." exit fi -git archive --format=zip "--prefix=agentXcpp-$1/" "$1" \ +git archive --format=zip \ + "--prefix=agentXcpp-$1/" \ + "$1" \ -o "agentXcpp-$1.zip" - if [ $? -ne 0 ] then echo "Error." From f79b877d3306fb2f3c87762a9c0dd9a5551f3250 Mon Sep 17 00:00:00 2001 From: "Tanjeff-N. Moos" Date: Thu, 18 Apr 2013 23:21:38 +0200 Subject: [PATCH 04/89] Improve release howto. --- doc/release_howto.dox | 41 ++++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/doc/release_howto.dox b/doc/release_howto.dox index 84615c4..ae03218 100644 --- a/doc/release_howto.dox +++ b/doc/release_howto.dox @@ -22,33 +22,32 @@ \page release_howto How to create an agentXcpp release -Creating releases should be a process which creates packages reproducible, -consistent packages of the software. +AgentXcpp releases are provided as tarball as well as as zip file. Both +packages contain exactly the same data. + +Releases are published once and cannot be revoked thereafter. Therefore, the +process by which a release is created must ensure that the package maintains +high quality. Each release shall be reproducible and allocatable to a commit in +the source code repository. Further, an up-to-date ChangeLog shall be provided, +and the released packages shall follow consistent naming conventions. To +comply with these requirements, the following procedure shall be applied +whenever an official release is created: -# Update the ChangeLog. Check it in. --# Choose a git commit which shall be released. --# Test the chosen commit:
- -# Clone the repo to a fresh directory, avoid having untracked files. - Alternatively, remove ALL untracked files from your working copy. - -# Checkout the chosen commit - -# Build the software - -# Perform the howto (\ref subagent_howto). - -# If the test fails: no release possible; fix it and re-start from the - beginning. If the test succeeds: continue. --# Create a git tag for the release.
- Each release shall have a tag to uniqely identify it. --# Create the packages, preferably using the create-release.sh script.
+-# Create an annotated git tag for the release.
+ Each release shall have a tag to uniqely identify it. Do not push the + tag yet. +-# Create the packages using the create-release.sh script.
The packages shall have the names agentXcpp-<version>.tar.gz and agentXcpp-<version>.zip respectively, where <version> is the tag name. The contents shall be a single directory named agentXcpp-<version>. This directory shall contain the source code. This is all ensured by the create_release.sh script. --# Test one of the packages.
- -# Unpack it - -# Build the contained software - -# Perform the howto (\ref subagent_howto). - -# If the test fails: no release possible; fix it and re-start from the - beginning. --# If the test succeeds, the release can be published. +-# Test one of the packages:
+ -# Unpack it. + -# Build and install the contained software. + -# If the test fails: no release possible; remove the tag, fix the problem + and re-start from step 1. +-# If the test succeeds, the packages and the tag can be published. */ From b2fa955536035c13c1986565b75b57e5fa1ec879 Mon Sep 17 00:00:00 2001 From: "Tanjeff-N. Moos" Date: Thu, 18 Apr 2013 23:22:27 +0200 Subject: [PATCH 05/89] Rename a dox file. --- doc/{release_howto.dox => how_to_create_releases.dox} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename doc/{release_howto.dox => how_to_create_releases.dox} (100%) diff --git a/doc/release_howto.dox b/doc/how_to_create_releases.dox similarity index 100% rename from doc/release_howto.dox rename to doc/how_to_create_releases.dox From e707cb349c84792cc0a7e716c058a0fc64c7e5f5 Mon Sep 17 00:00:00 2001 From: "Tanjeff-N. Moos" Date: Thu, 18 Apr 2013 23:34:41 +0200 Subject: [PATCH 06/89] Improve release howto. --- doc/how_to_create_releases.dox | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/doc/how_to_create_releases.dox b/doc/how_to_create_releases.dox index ae03218..6cfc81a 100644 --- a/doc/how_to_create_releases.dox +++ b/doc/how_to_create_releases.dox @@ -34,6 +34,7 @@ comply with these requirements, the following procedure shall be applied whenever an official release is created: -# Update the ChangeLog. Check it in. +-# Update the README. Check it in. -# Create an annotated git tag for the release.
Each release shall have a tag to uniqely identify it. Do not push the tag yet. @@ -45,7 +46,12 @@ whenever an official release is created: This is all ensured by the create_release.sh script. -# Test one of the packages:
-# Unpack it. - -# Build and install the contained software. + -# Build and install the contained software.
+ There should be no warnings during build. + -# Perform the howtos to ensure that they work. + -# This is the time to browse the documentation (API and internals) and + check whether it is in good shape. This step cannot be formalized, but + eye-catching errors might be found by simply looking around a bit. -# If the test fails: no release possible; remove the tag, fix the problem and re-start from step 1. -# If the test succeeds, the packages and the tag can be published. From 150f21ffe48d2906f03fcaa61767623736233d94 Mon Sep 17 00:00:00 2001 From: "Tanjeff-N. Moos" Date: Fri, 19 Apr 2013 00:46:38 +0200 Subject: [PATCH 07/89] Switch from boost::cstdint to QtGlobal. Affect the uint*_t and int*_t types. --- src/ClosePDU.cpp | 2 +- src/ClosePDU.hpp | 6 ++--- src/Counter32Value.hpp | 6 ++--- src/Counter64Value.cpp | 1 - src/Counter64Value.hpp | 6 ++--- src/Gauge32Value.hpp | 6 ++--- src/GetBulkPDU.hpp | 15 +++++------ src/IntegerValue.hpp | 8 +++--- src/IpAddressValue.cpp | 2 +- src/IpAddressValue.hpp | 24 ++++++++--------- src/MasterProxy.cpp | 24 ++++++++--------- src/MasterProxy.hpp | 18 ++++++------- src/NotifyPDU.hpp | 3 +-- src/OctetStringValue.cpp | 4 +-- src/OidValue.cpp | 6 ++--- src/OidValue.hpp | 7 +++-- src/OpenPDU.hpp | 6 ++--- src/PDU.cpp | 14 +++++----- src/PDU.hpp | 24 ++++++++--------- src/RegisterPDU.hpp | 26 +++++++++--------- src/ResponsePDU.cpp | 2 +- src/ResponsePDU.hpp | 17 ++++++------ src/TimeTicksValue.hpp | 7 +++-- src/UnixDomainConnector.cpp | 11 ++++---- src/UnixDomainConnector.hpp | 2 +- src/UnregisterPDU.hpp | 21 +++++++-------- src/binary.hpp | 4 +-- src/helpers.cpp | 2 +- src/helpers.hpp | 2 +- src/util.hpp | 54 ++++++++++++++++++------------------- src/varbind.cpp | 4 +-- src/varbind.hpp | 6 ++--- unit_tests/IntegerTest.cpp | 4 +-- 33 files changed, 158 insertions(+), 186 deletions(-) diff --git a/src/ClosePDU.cpp b/src/ClosePDU.cpp index 1106d15..5aa6eed 100644 --- a/src/ClosePDU.cpp +++ b/src/ClosePDU.cpp @@ -27,7 +27,7 @@ ClosePDU::ClosePDU() { } -ClosePDU::ClosePDU(uint32_t _sessionID, +ClosePDU::ClosePDU(quint32 _sessionID, reason_t _reason) { // Set sessionID diff --git a/src/ClosePDU.hpp b/src/ClosePDU.hpp index 5c28705..9d65acb 100644 --- a/src/ClosePDU.hpp +++ b/src/ClosePDU.hpp @@ -20,13 +20,11 @@ #ifndef _CLOSEPDU_H_ #define _CLOSEPDU_H_ -#include +#include #include "exceptions.hpp" #include "PDU.hpp" -using boost::uint32_t; - namespace agentxcpp { /** @@ -74,7 +72,7 @@ namespace agentxcpp * * \exception inval_param If the reason value is invalid. */ - ClosePDU(uint32_t sessionID, + ClosePDU(quint32 sessionID, reason_t reason); /** diff --git a/src/Counter32Value.hpp b/src/Counter32Value.hpp index 9865280..8af2a10 100644 --- a/src/Counter32Value.hpp +++ b/src/Counter32Value.hpp @@ -20,13 +20,11 @@ #ifndef _COUNTER32_H_ #define _COUNTER32_H_ -#include +#include #include "AbstractValue.hpp" #include "exceptions.hpp" -using boost::uint32_t; - namespace agentxcpp { /** @@ -42,7 +40,7 @@ namespace agentxcpp * According to RFC 2578, Counter32 is a non-negative 32-bit * number. */ - uint32_t value; + quint32 value; /** * \internal diff --git a/src/Counter64Value.cpp b/src/Counter64Value.cpp index dacc3b9..ed68c38 100644 --- a/src/Counter64Value.cpp +++ b/src/Counter64Value.cpp @@ -23,7 +23,6 @@ #include "util.hpp" using namespace agentxcpp; -using boost::uint64_t; binary Counter64Value::serialize() const { diff --git a/src/Counter64Value.hpp b/src/Counter64Value.hpp index f424d99..bdaeafe 100644 --- a/src/Counter64Value.hpp +++ b/src/Counter64Value.hpp @@ -20,13 +20,11 @@ #ifndef _COUNTER64_H_ #define _COUNTER64_H_ -#include +#include #include "AbstractValue.hpp" #include "exceptions.hpp" -using boost::uint64_t; - namespace agentxcpp { /** @@ -41,7 +39,7 @@ namespace agentxcpp * According to RFC 2578, Counter64 is a non-negative 64-bit * number. */ - uint64_t value; + quint64 value; /** * \internal diff --git a/src/Gauge32Value.hpp b/src/Gauge32Value.hpp index e74a695..e2a2f2b 100644 --- a/src/Gauge32Value.hpp +++ b/src/Gauge32Value.hpp @@ -20,13 +20,11 @@ #ifndef _GAUGE32_H_ #define _GAUGE32_H_ -#include +#include #include "AbstractValue.hpp" #include "exceptions.hpp" -using boost::uint32_t; - namespace agentxcpp { /** @@ -41,7 +39,7 @@ namespace agentxcpp * According to RFC 2578, Gauge32 is a non-negative 32-bit * number. */ - uint32_t value; + quint32 value; public: /** diff --git a/src/GetBulkPDU.hpp b/src/GetBulkPDU.hpp index 53eb349..ad6530b 100644 --- a/src/GetBulkPDU.hpp +++ b/src/GetBulkPDU.hpp @@ -22,14 +22,13 @@ #include #include -#include +#include #include "PDUwithContext.hpp" #include "OidValue.hpp" using std::vector; using std::pair; -using boost::uint16_t; namespace agentxcpp { @@ -54,13 +53,13 @@ namespace agentxcpp * \brief The number of variables in the SearchRangeList that are * not repeaters. */ - uint16_t non_repeaters; + quint16 non_repeaters; /** * \brief The maximum number of repetitions requested for repeating * variables. */ - uint16_t max_repititions; + quint16 max_repititions; public: /** @@ -116,7 +115,7 @@ namespace agentxcpp /** * \brief Get non_repeaters field */ - uint16_t get_non_repeaters() + quint16 get_non_repeaters() { return non_repeaters; } @@ -124,7 +123,7 @@ namespace agentxcpp /** * \brief Set non_repeaters field */ - void set_non_repeaters(uint16_t value) + void set_non_repeaters(quint16 value) { non_repeaters = value; } @@ -132,7 +131,7 @@ namespace agentxcpp /** * \brief Get max_repititions field */ - uint16_t get_max_repititions() + quint16 get_max_repititions() { return max_repititions; } @@ -140,7 +139,7 @@ namespace agentxcpp /** * \brief Set max_repititions field */ - void set_max_repititions(uint16_t value) + void set_max_repititions(quint16 value) { max_repititions = value; } diff --git a/src/IntegerValue.hpp b/src/IntegerValue.hpp index 6cc866a..a5bd5ad 100644 --- a/src/IntegerValue.hpp +++ b/src/IntegerValue.hpp @@ -20,13 +20,11 @@ #ifndef _INTEGER_H_ #define _INTEGER_H_ -#include +#include #include "AbstractValue.hpp" #include "exceptions.hpp" -using boost::int32_t; - namespace agentxcpp { /** @@ -40,7 +38,7 @@ namespace agentxcpp * * According to RFC 2578, INTEGER is a signed 32-bit number. */ - int32_t value; + qint32 value; /** * \internal @@ -51,7 +49,7 @@ namespace agentxcpp * * \exception None. */ - IntegerValue(int32_t _value=0) :value(_value) {} + IntegerValue(qint32 _value=0) :value(_value) {} /** * \internal diff --git a/src/IpAddressValue.cpp b/src/IpAddressValue.cpp index 8043a4c..2b8c273 100644 --- a/src/IpAddressValue.cpp +++ b/src/IpAddressValue.cpp @@ -46,7 +46,7 @@ IpAddressValue::IpAddressValue(binary::const_iterator& pos, const binary::const_iterator& end, bool big_endian) { - uint32_t size; + quint32 size; // Are there at least 8 bytes in the buffer? if(end - pos < 8) diff --git a/src/IpAddressValue.hpp b/src/IpAddressValue.hpp index c5e8774..12abb8d 100644 --- a/src/IpAddressValue.hpp +++ b/src/IpAddressValue.hpp @@ -20,13 +20,11 @@ #ifndef _IPADDRESS_H_ #define _IPADDRESS_H_ -#include +#include #include "AbstractValue.hpp" #include "exceptions.hpp" -using boost::uint32_t; - namespace agentxcpp { /** @@ -45,7 +43,7 @@ namespace agentxcpp * * According to RFC 2578, IpAddress is a 32-bit number. */ - uint8_t address[4]; // only IPv4 + quint8 address[4]; // only IPv4 public: /** @@ -94,10 +92,10 @@ namespace agentxcpp * * \exception None. */ - IpAddressValue(uint8_t a, - uint8_t b, - uint8_t c, - uint8_t d) + IpAddressValue(quint8 a, + quint8 b, + quint8 c, + quint8 d) { address[0] = a; address[1] = b; @@ -112,10 +110,10 @@ namespace agentxcpp * * \exception None. */ - void set_value(uint8_t a, - uint8_t b, - uint8_t c, - uint8_t d) + void set_value(quint8 a, + quint8 b, + quint8 c, + quint8 d) { address[0] = a; address[1] = b; @@ -138,7 +136,7 @@ namespace agentxcpp * * \exception inval_param If the index is out of bound. */ - uint8_t& operator[](unsigned index) + quint8& operator[](unsigned index) { if(index > 3) { diff --git a/src/MasterProxy.cpp b/src/MasterProxy.cpp index f11359d..8bf0661 100644 --- a/src/MasterProxy.cpp +++ b/src/MasterProxy.cpp @@ -16,7 +16,7 @@ * See the AgentXcpp library license in the LICENSE file of this package * for more details. */ -#include +#include #include "MasterProxy.hpp" #include "OpenPDU.hpp" @@ -31,7 +31,7 @@ using namespace std; using namespace agentxcpp; -using namespace boost; // Beside other things, this pulls boost::uint16_t +using namespace boost; // Beside other things, this pulls boost::quint16 using boost::optional; @@ -42,7 +42,7 @@ using boost::optional; MasterProxy::MasterProxy(std::string _description, - uint8_t _default_timeout, + quint8 _default_timeout, OidValue _id, std::string _filename) : socket_file(_filename.c_str()), @@ -52,7 +52,7 @@ MasterProxy::MasterProxy(std::string _description, id(_id) { // Initialize connector (never use timeout=0) - uint8_t timeout; + quint8 timeout; timeout = (this->default_timeout == 0) ? 1 : this->default_timeout; connection = new UnixDomainConnector( _filename.c_str(), @@ -276,8 +276,8 @@ void MasterProxy::do_registration(boost::shared_ptr pdu) void MasterProxy::register_subtree(OidValue subtree, - uint8_t priority, - uint8_t timeout) + quint8 priority, + quint8 timeout) { // Build PDU boost::shared_ptr pdu(new RegisterPDU); @@ -311,7 +311,7 @@ void MasterProxy::register_subtree(OidValue subtree, void MasterProxy::unregister_subtree(OidValue subtree, - uint8_t priority) + quint8 priority) { // The UnregisterPDU boost::shared_ptr pdu; @@ -448,7 +448,7 @@ void MasterProxy::handle_getpdu(shared_ptr response, shared_ptr::const_iterator i; - uint16_t index = 1; // Index is 1-based (RFC 2741, + quint16 index = 1; // Index is 1-based (RFC 2741, // 5.4. "Value Representation"): for(i = sr.begin(); i != sr.end(); i++) { @@ -517,7 +517,7 @@ void MasterProxy::handle_getnextpdu(shared_ptr response, shared_ptr // Iterate over list and handle each SearchRange separately vector< pair >::const_iterator i; - uint16_t index = 1; // Index is 1-based (RFC 2741, + quint16 index = 1; // Index is 1-based (RFC 2741, // 5.4. "Value Representation"): for(i = sr.begin(); i != sr.end(); i++) { @@ -596,7 +596,7 @@ void MasterProxy::handle_testsetpdu(boost::shared_ptr response, sha // Iterate over list and handle each Varbind separately. Return on the // first varbind which doesn't validate correctly. vector::const_iterator i; - uint16_t index; + quint16 index; for(i = vb.begin(), index = 1; i != vb.end(); i++, index++) { // Find the associated variable @@ -666,7 +666,7 @@ void MasterProxy::handle_commitsetpdu(boost::shared_ptr response, s // Iterate over list and handle each Varbind separately. list< shared_ptr >::iterator i; - uint16_t index = 1; // Index is 1-based (RFC 2741, 5.4. "Value Representation") + quint16 index = 1; // Index is 1-based (RFC 2741, 5.4. "Value Representation") for(i = setlist.begin(); i != setlist.end(); i++) { if( (*i)->handle_commitset() ) @@ -696,7 +696,7 @@ void MasterProxy::handle_undosetpdu(boost::shared_ptr response, sha // Iterate over list and handle each Varbind separately. list< shared_ptr >::iterator i; - uint16_t index = 1; // Index is 1-based (RFC 2741, 5.4. "Value Representation") + quint16 index = 1; // Index is 1-based (RFC 2741, 5.4. "Value Representation") for(i = setlist.begin(); i != setlist.end(); i++) { if( (*i)->handle_undoset() ) diff --git a/src/MasterProxy.hpp b/src/MasterProxy.hpp index 6690c19..fa94382 100644 --- a/src/MasterProxy.hpp +++ b/src/MasterProxy.hpp @@ -24,7 +24,7 @@ #include #include -#include +#include #include #include @@ -45,8 +45,6 @@ #include "UndoSetPDU.hpp" #include "UnixDomainConnector.hpp" -using boost::uint8_t; -using boost::uint32_t; namespace agentxcpp { @@ -223,7 +221,7 @@ namespace agentxcpp * * If disconnected, the value is undefined. */ - uint32_t sessionID; + quint32 sessionID; /** * \brief A string describing the subagent. @@ -237,7 +235,7 @@ namespace agentxcpp * * A value of 0 indicates that there is no session-wide default. */ - uint8_t default_timeout; + quint8 default_timeout; /** * \brief An Object Identifier that identifies the subagent. May be @@ -565,7 +563,7 @@ namespace agentxcpp * "Well-known Values". */ MasterProxy(std::string description="", - uint8_t default_timeout=0, + quint8 default_timeout=0, OidValue ID=OidValue(), std::string unix_domain_socket="/var/agentx/master"); @@ -624,8 +622,8 @@ namespace agentxcpp * duplicate_registration error. */ void register_subtree(OidValue subtree, - uint8_t priority=127, - uint8_t timeout=0); + quint8 priority=127, + quint8 timeout=0); /** * \brief Unregister a subtree with the master agent @@ -669,7 +667,7 @@ namespace agentxcpp // TODO: the 'priority' parameter can possibly be omitted: the // value can be stored by master_agent upon subtree registration. void unregister_subtree(OidValue subtree, - uint8_t priority=127); + quint8 priority=127); /** * \brief Check whether the session is in state connected @@ -734,7 +732,7 @@ namespace agentxcpp * object was never connected to the master, 0 is * returned. */ - uint32_t get_sessionID() + quint32 get_sessionID() { return this->sessionID; } diff --git a/src/NotifyPDU.hpp b/src/NotifyPDU.hpp index e362e19..d68c5c1 100644 --- a/src/NotifyPDU.hpp +++ b/src/NotifyPDU.hpp @@ -21,12 +21,11 @@ #include -#include +#include #include "PDUwithContext.hpp" #include "varbind.hpp" -using boost::uint32_t; using std::vector; namespace agentxcpp diff --git a/src/OctetStringValue.cpp b/src/OctetStringValue.cpp index 4bfd5c6..282d120 100644 --- a/src/OctetStringValue.cpp +++ b/src/OctetStringValue.cpp @@ -43,7 +43,7 @@ void OctetStringValue::set_value(std::string v) // // This seems to be goofy, but it ensures that our code works even on a // machine where a char is not 8 bit wide, i.e. when char has another size - // than uint8_t. + // than quint8. value.assign( reinterpret_cast( v.data() ), v.size() * sizeof( binary::value_type ) @@ -64,7 +64,7 @@ std::string OctetStringValue::str() const // // This seems to be goofy, but it ensures that our code works even on a // machine where a char is not 8 bit wide, i.e. when char has another size - // than uint8_t. + // than quint8. std::string retval( reinterpret_cast( value.data() ), value.size() * sizeof( std::string::value_type ) diff --git a/src/OidValue.cpp b/src/OidValue.cpp index c83bb6b..94a49cc 100644 --- a/src/OidValue.cpp +++ b/src/OidValue.cpp @@ -34,7 +34,7 @@ void OidValue::parse_string(std::string s) // Parse the string std::istringstream ss(s); - uint32_t subid; + quint32 subid; char ch; while(ss) { @@ -231,7 +231,7 @@ OidValue::OidValue(binary::const_iterator& pos, { throw(parse_error()); } - uint32_t subid; + quint32 subid; for( int i = 0; i < n_subid; i++) { if(big_endian) @@ -338,7 +338,7 @@ OidValue& OidValue::operator=(const OidValue& other) this->include = other.include; // copy inherited stuff - vector::operator=(other); + vector::operator=(other); AbstractValue::operator=(other); // Return reference to us diff --git a/src/OidValue.hpp b/src/OidValue.hpp index 43022c4..e140660 100644 --- a/src/OidValue.hpp +++ b/src/OidValue.hpp @@ -24,12 +24,11 @@ #include #include -#include +#include #include "AbstractValue.hpp" #include "exceptions.hpp" -using boost::uint32_t; namespace agentxcpp { @@ -80,7 +79,7 @@ namespace agentxcpp * "" // empty string is ok * \endcode * - * This class inherits from std:vector, which means that an OidValue + * This class inherits from std:vector, which means that an OidValue * object can be manipulated the same way as a std::vector<> can be * manipulated: * @@ -90,7 +89,7 @@ namespace agentxcpp * \endcode * */ - class OidValue: public AbstractValue, public std::vector + class OidValue: public AbstractValue, public std::vector { private: diff --git a/src/OpenPDU.hpp b/src/OpenPDU.hpp index e624716..1a9653f 100644 --- a/src/OpenPDU.hpp +++ b/src/OpenPDU.hpp @@ -33,7 +33,7 @@ namespace agentxcpp class OpenPDU : public PDU { private: - uint8_t timeout; + quint8 timeout; OidValue id; OctetStringValue descr; @@ -76,7 +76,7 @@ namespace agentxcpp /** * \brief Get timeout */ - uint8_t get_timeout() + quint8 get_timeout() { return this->timeout; } @@ -93,7 +93,7 @@ namespace agentxcpp * regions. The default value of 0 indicates that * there is no session-wide default value. */ - void set_timeout(uint8_t timeout) + void set_timeout(quint8 timeout) { this->timeout = timeout; } diff --git a/src/PDU.cpp b/src/PDU.cpp index f7f9e85..df0687b 100644 --- a/src/PDU.cpp +++ b/src/PDU.cpp @@ -42,7 +42,7 @@ using namespace agentxcpp; using boost::shared_ptr; -uint32_t PDU::packetID_cnt = 0; +quint32 PDU::packetID_cnt = 0; @@ -74,7 +74,7 @@ PDU::PDU(binary::const_iterator& pos, pos += 2; // read flags - uint8_t flags = *pos++; + quint8 flags = *pos++; instance_registration = ( flags & (1<<0) ) ? true : false; new_index = ( flags & (1<<1) ) ? true : false; any_index = ( flags & (1<<2) ) ? true : false; @@ -105,7 +105,7 @@ shared_ptr PDU::parse_pdu(binary buf) binary::const_iterator pos; // check protocol version - uint8_t version = buf[0]; + quint8 version = buf[0]; if( version != 1 ) { // Wrong protocol: @@ -114,11 +114,11 @@ shared_ptr PDU::parse_pdu(binary buf) } // read endianess flag - uint8_t flags = buf[2]; + quint8 flags = buf[2]; bool big_endian = ( flags & (1<<4) ) ? true : false; // read payload length - uint32_t payload_length; + quint32 payload_length; pos = buf.begin() + 16; payload_length = read32(pos, big_endian); if( payload_length % 4 != 0 ) @@ -130,7 +130,7 @@ shared_ptr PDU::parse_pdu(binary buf) } // read PDU type - uint8_t type = buf[1]; + quint8 type = buf[1]; // create PDU (TODO: complete the list!) shared_ptr pdu; @@ -200,7 +200,7 @@ void PDU::add_header(type_t type, binary& payload) const header.push_back(type); // flags - uint8_t flags = 0; + quint8 flags = 0; if(instance_registration) flags |= (1<<0); if(new_index) flags |= (1<<1); if(any_index) flags |= (1<<2); diff --git a/src/PDU.hpp b/src/PDU.hpp index d633958..9a4402f 100644 --- a/src/PDU.hpp +++ b/src/PDU.hpp @@ -23,13 +23,13 @@ #include #include -#include + +#include #include "exceptions.hpp" #include "binary.hpp" using boost::shared_ptr; -using boost::uint32_t; namespace agentxcpp { @@ -72,14 +72,14 @@ namespace agentxcpp * * According to RFC 2741, 6.1. "AgentX PDU Header" */ - uint32_t sessionID; + quint32 sessionID; /** * \brief h.transactionID field * * According to RFC 2741, 6.1. "AgentX PDU Header" */ - uint32_t transactionID; + quint32 transactionID; /** * \brief Counter for automatic packetID generator @@ -91,7 +91,7 @@ namespace agentxcpp * The parse constructor does not use this member, because it reads * the packetID from a stream. */ - static uint32_t packetID_cnt; + static quint32 packetID_cnt; protected: @@ -154,7 +154,7 @@ namespace agentxcpp * therefore this member is protected to allow the ResponsePDU to * alter it. */ - uint32_t packetID; + quint32 packetID; /** * \brief Parse constructor @@ -249,31 +249,31 @@ namespace agentxcpp /** * \brief Get sessionID */ - uint32_t get_sessionID() { return sessionID; } + quint32 get_sessionID() { return sessionID; } /** * \brief Set sessionID */ - void set_sessionID(uint32_t id) { this->sessionID = id; } + void set_sessionID(quint32 id) { this->sessionID = id; } /** * \brief Get transactionID */ - uint32_t get_transactionID() { return transactionID; } + quint32 get_transactionID() { return transactionID; } /** * \brief Set transactionID */ - void set_transactionID(uint32_t id) { transactionID = id; } + void set_transactionID(quint32 id) { transactionID = id; } /** * \brief Get packetID */ - uint32_t get_packetID() { return packetID; } + quint32 get_packetID() { return packetID; } /** * \brief Set packetID */ - void set_packetID(uint32_t packetID) { this->packetID = packetID; } + void set_packetID(quint32 packetID) { this->packetID = packetID; } /** * \brief Parse a %PDU from a buffer diff --git a/src/RegisterPDU.hpp b/src/RegisterPDU.hpp index 82cf585..f262168 100644 --- a/src/RegisterPDU.hpp +++ b/src/RegisterPDU.hpp @@ -24,8 +24,6 @@ #include "OidValue.hpp" #include "PDUwithContext.hpp" -using boost::uint32_t; - namespace agentxcpp { /** @@ -36,24 +34,24 @@ namespace agentxcpp class RegisterPDU : public PDUwithContext { private: - uint8_t timeout; - uint8_t priority; + quint8 timeout; + quint8 priority; OidValue subtree; - uint8_t range_subid; - uint32_t upper_bound; + quint8 range_subid; + quint32 upper_bound; public: /** * \brief Set the upper_bound. */ - void set_upper_bound(uint32_t upper_bound) + void set_upper_bound(quint32 upper_bound) { this->upper_bound = upper_bound; } /** * \brief Get the upper_bound. */ - uint32_t get_upper_bound() + quint32 get_upper_bound() { return this->upper_bound; } @@ -76,14 +74,14 @@ namespace agentxcpp /** * \brief Set the range_subid. */ - void set_range_subid(uint8_t range_subid) + void set_range_subid(quint8 range_subid) { this->range_subid = range_subid; } /** * \brief Get the range_subid. */ - uint8_t get_range_subid() + quint8 get_range_subid() { return this->range_subid; } @@ -91,14 +89,14 @@ namespace agentxcpp /** * \brief Set the priority. */ - void set_priority(uint8_t priority) + void set_priority(quint8 priority) { this->priority = priority; } /** * \brief Get the priority. */ - uint8_t get_priority() + quint8 get_priority() { return this->priority; } @@ -106,14 +104,14 @@ namespace agentxcpp /** * \brief Set the timeout. */ - void set_timeout(uint8_t timeout) + void set_timeout(quint8 timeout) { this->timeout = timeout; } /** * \brief Get the timeout. */ - uint8_t get_timeout() + quint8 get_timeout() { return this->timeout; } diff --git a/src/ResponsePDU.cpp b/src/ResponsePDU.cpp index 1c2d012..56d7c87 100644 --- a/src/ResponsePDU.cpp +++ b/src/ResponsePDU.cpp @@ -22,7 +22,7 @@ ResponsePDU::ResponsePDU(binary::const_iterator& pos, { // header is parsed by base class constructor - uint16_t err; + quint16 err; // read simple fields this->sysUpTime = read32(pos, big_endian); diff --git a/src/ResponsePDU.hpp b/src/ResponsePDU.hpp index 3254c89..c7f8708 100644 --- a/src/ResponsePDU.hpp +++ b/src/ResponsePDU.hpp @@ -22,7 +22,7 @@ #include -#include +#include #include "PDU.hpp" #include "OidValue.hpp" @@ -30,8 +30,7 @@ #include "varbind.hpp" using std::vector; -using boost::uint16_t; -using boost::uint32_t; + namespace agentxcpp { @@ -97,7 +96,7 @@ namespace agentxcpp * See RFC 2741, section 6.2.16 "The agentx-Response-PDU" for an * explanation. */ - uint32_t sysUpTime; + quint32 sysUpTime; /** * \brief the index field. @@ -105,7 +104,7 @@ namespace agentxcpp * See RFC 2741, section 6.2.16 "The agentx-Response-PDU" for an * explanation. */ - uint16_t index; + quint16 index; /** * \brief the error field. @@ -182,14 +181,14 @@ namespace agentxcpp /** * \brief Set the sysUpTime. */ - void set_sysUpTime(uint32_t time) + void set_sysUpTime(quint32 time) { this->sysUpTime = time; } /** * \brief Get the sysUpTime. */ - uint32_t get_sysUpTime() + quint32 get_sysUpTime() { return sysUpTime; } @@ -197,7 +196,7 @@ namespace agentxcpp /** * \brief set the index value. */ - void set_index(uint16_t i) + void set_index(quint16 i) { this->index = i; } @@ -205,7 +204,7 @@ namespace agentxcpp /** * \brief Get the index value */ - uint16_t get_index() + quint16 get_index() { return index; } diff --git a/src/TimeTicksValue.hpp b/src/TimeTicksValue.hpp index 1606828..d0e3b4d 100644 --- a/src/TimeTicksValue.hpp +++ b/src/TimeTicksValue.hpp @@ -19,12 +19,11 @@ #ifndef _TIMETICKS_H_ #define _TIMETICKS_H_ -#include +#include #include "AbstractValue.hpp" #include "exceptions.hpp" -using boost::uint32_t; namespace agentxcpp { @@ -40,14 +39,14 @@ namespace agentxcpp * According to RFC 2578, TimeTicks is a non-negative 32-bit * number. */ - uint32_t value; + quint32 value; /** * \brief Create an TimeTicksValue without initialization. * * \param initial_value The initial value of the object. */ - TimeTicksValue(uint32_t initial_value = 0) + TimeTicksValue(quint32 initial_value = 0) : value(initial_value) { } diff --git a/src/UnixDomainConnector.cpp b/src/UnixDomainConnector.cpp index cd95bcb..9dcc632 100644 --- a/src/UnixDomainConnector.cpp +++ b/src/UnixDomainConnector.cpp @@ -181,14 +181,14 @@ void UnixDomainConnector::do_receive() disconnect(); // error! break; // Stop reading PDUs } - buf.append(reinterpret_cast(header), 20); + buf.append(reinterpret_cast(header), 20); } // Extract endianness flag bool big_endian = ( buf[2] & (1<<4) ) ? true : false; // Extract payload length - uint32_t payload_length; + quint32 payload_length; binary::const_iterator pos = buf.begin() + 16; payload_length = read32(pos, big_endian); if( payload_length % 4 != 0 ) @@ -217,7 +217,7 @@ void UnixDomainConnector::do_receive() disconnect(); return; } - buf.append(reinterpret_cast(payload.data()), payload_length); + buf.append(reinterpret_cast(payload.data()), payload_length); queue.push_back(buf); } @@ -248,7 +248,7 @@ void UnixDomainConnector::do_receive() { m_response_mutex.lock(); // Was a response - std::map< uint32_t, boost::shared_ptr >::iterator i; + std::map< quint32, boost::shared_ptr >::iterator i; i = this->m_responses.find( response->get_packetID() ); if(i != this->m_responses.end()) { @@ -279,7 +279,8 @@ boost::shared_ptr UnixDomainConnector::request(boost::shared_ptrget_packetID()] = shared_ptr(); QMetaObject::invokeMethod(this, "do_send", Q_ARG(boost::shared_ptr, pdu)); - std::map >::iterator i; + std::map >::iterator i; + m_responses[pdu->get_packetID()] = shared_ptr(); do { m_response_arrived.wait(&m_response_mutex); diff --git a/src/UnixDomainConnector.hpp b/src/UnixDomainConnector.hpp index 1571c4a..ce47bfc 100644 --- a/src/UnixDomainConnector.hpp +++ b/src/UnixDomainConnector.hpp @@ -167,7 +167,7 @@ namespace agentxcpp * * This member is protected by m_response_mutex. */ - std::map< uint32_t, boost::shared_ptr > m_responses; + std::map< quint32, boost::shared_ptr > m_responses; /** * \brief Used to protect m_responses and for m_response_arrived. diff --git a/src/UnregisterPDU.hpp b/src/UnregisterPDU.hpp index 7d5b31e..2e36963 100644 --- a/src/UnregisterPDU.hpp +++ b/src/UnregisterPDU.hpp @@ -19,12 +19,11 @@ #ifndef _UNREGISTERPDU_H_ #define _UNREGISTERPDU_H_ -#include +#include #include "PDUwithContext.hpp" #include "OidValue.hpp" -using boost::uint32_t; namespace agentxcpp { @@ -36,23 +35,23 @@ namespace agentxcpp class UnregisterPDU : public PDUwithContext { private: - uint8_t priority; - uint8_t range_subid; + quint8 priority; + quint8 range_subid; OidValue subtree; - uint32_t upper_bound; + quint32 upper_bound; public: /** * \brief Set the upper_bound. */ - void set_upper_bound(uint32_t upper_bound) + void set_upper_bound(quint32 upper_bound) { this->upper_bound = upper_bound; } /** * \brief Get the upper_bound. */ - uint32_t get_upper_bound() + quint32 get_upper_bound() { return this->upper_bound; } @@ -75,14 +74,14 @@ namespace agentxcpp /** * \brief Set the range_subid. */ - void set_range_subid(uint8_t range_subid) + void set_range_subid(quint8 range_subid) { this->range_subid = range_subid; } /** * \brief Get the range_subid. */ - uint8_t get_range_subid() + quint8 get_range_subid() { return this->range_subid; } @@ -90,14 +89,14 @@ namespace agentxcpp /** * \brief Set the priority. */ - void set_priority(uint8_t priority) + void set_priority(quint8 priority) { this->priority = priority; } /** * \brief Get the priority. */ - uint8_t get_priority() + quint8 get_priority() { return this->priority; } diff --git a/src/binary.hpp b/src/binary.hpp index de07d7f..d57236f 100644 --- a/src/binary.hpp +++ b/src/binary.hpp @@ -22,7 +22,7 @@ #include #include -#include +#include namespace agentxcpp { @@ -32,7 +32,7 @@ namespace agentxcpp * * This class is used as container for binary data. */ - class binary : public std::basic_string + class binary : public std::basic_string { }; diff --git a/src/helpers.cpp b/src/helpers.cpp index 56d8c26..6fe49e5 100644 --- a/src/helpers.cpp +++ b/src/helpers.cpp @@ -54,7 +54,7 @@ namespace agentxcpp } OidValue agentxcpp::generate_v1_snmpTrapOID(generic_trap_t generic_trap, - boost::optional specific_trap) + boost::optional specific_trap) { // We need the OID of the SNMPv1 traps. These are defined here. // diff --git a/src/helpers.hpp b/src/helpers.hpp index 1872790..e9c8597 100644 --- a/src/helpers.hpp +++ b/src/helpers.hpp @@ -91,7 +91,7 @@ namespace agentxcpp * specific_trap was not given. */ OidValue generate_v1_snmpTrapOID(generic_trap_t generic_trap, - boost::optional specific_trap = boost::optional()); + boost::optional specific_trap = boost::optional()); } // namespace agentxcpp diff --git a/src/util.hpp b/src/util.hpp index 0696006..db8791f 100644 --- a/src/util.hpp +++ b/src/util.hpp @@ -20,40 +20,38 @@ #ifndef _HELPER_H_ #define _HELPER_H_ -#include +#include #include "binary.hpp" -using boost::uint16_t; -using boost::uint32_t; namespace agentxcpp { - inline uint64_t read64(binary::const_iterator& pos, bool big_endian) + inline quint64 read64(binary::const_iterator& pos, bool big_endian) { - uint64_t value; + quint64 value; if( big_endian ) { - value = static_cast(*pos++) << 56; - value |= static_cast(*pos++) << 48; - value |= static_cast(*pos++) << 40; - value |= static_cast(*pos++) << 32; - value |= static_cast(*pos++) << 24; - value |= static_cast(*pos++) << 16; - value |= static_cast(*pos++) << 8; - value |= static_cast(*pos++) << 0; + value = static_cast(*pos++) << 56; + value |= static_cast(*pos++) << 48; + value |= static_cast(*pos++) << 40; + value |= static_cast(*pos++) << 32; + value |= static_cast(*pos++) << 24; + value |= static_cast(*pos++) << 16; + value |= static_cast(*pos++) << 8; + value |= static_cast(*pos++) << 0; } else { - value = static_cast(*pos++) << 0; - value |= static_cast(*pos++) << 8; - value |= static_cast(*pos++) << 16; - value |= static_cast(*pos++) << 24; - value |= static_cast(*pos++) << 32; - value |= static_cast(*pos++) << 40; - value |= static_cast(*pos++) << 48; - value |= static_cast(*pos++) << 56; + value = static_cast(*pos++) << 0; + value |= static_cast(*pos++) << 8; + value |= static_cast(*pos++) << 16; + value |= static_cast(*pos++) << 24; + value |= static_cast(*pos++) << 32; + value |= static_cast(*pos++) << 40; + value |= static_cast(*pos++) << 48; + value |= static_cast(*pos++) << 56; } return value; } @@ -66,7 +64,7 @@ namespace agentxcpp * * \param value The value which is appended to the string. */ - inline void write64(binary& serialized, uint64_t value) + inline void write64(binary& serialized, quint64 value) { // always big endian serialized.push_back(value >> 56 & 0xff); @@ -80,9 +78,9 @@ namespace agentxcpp } - inline uint32_t read32(binary::const_iterator& pos, bool big_endian) + inline quint32 read32(binary::const_iterator& pos, bool big_endian) { - uint32_t value; + quint32 value; if( big_endian ) { value = *pos++ << 24; @@ -108,7 +106,7 @@ namespace agentxcpp * * \param value The value which is appended to the string. */ - inline void write32(binary& serialized, uint32_t value) + inline void write32(binary& serialized, quint32 value) { // always big endian serialized.push_back(value >> 24 & 0xff); @@ -117,9 +115,9 @@ namespace agentxcpp serialized.push_back(value >> 0 & 0xff); } - inline uint16_t read16(binary::const_iterator& pos, bool big_endian) + inline quint16 read16(binary::const_iterator& pos, bool big_endian) { - uint16_t value = 0; + quint16 value = 0; if( big_endian ) { value |= *pos++ << 8; @@ -142,7 +140,7 @@ namespace agentxcpp * * \param value The value which is appended to the string. */ - inline void write16(binary& serialized, uint16_t value) + inline void write16(binary& serialized, quint16 value) { // always big endian serialized.push_back(value >> 8 & 0xff); diff --git a/src/varbind.cpp b/src/varbind.cpp index 9fb1fa0..ab76a68 100644 --- a/src/varbind.cpp +++ b/src/varbind.cpp @@ -30,8 +30,6 @@ #include "util.hpp" using namespace agentxcpp; -using boost::uint16_t; - binary varbind::serialize() const { @@ -102,7 +100,7 @@ varbind::varbind(binary::const_iterator& pos, const binary::const_iterator& end, bool big_endian) { - uint16_t type; + quint16 type; // Type and reserved field if(end - pos < 4) diff --git a/src/varbind.hpp b/src/varbind.hpp index 5e5cb16..86f7a7b 100644 --- a/src/varbind.hpp +++ b/src/varbind.hpp @@ -22,13 +22,11 @@ #include #include -#include +#include #include "OidValue.hpp" #include "AbstractValue.hpp" -using boost::uint16_t; - namespace agentxcpp { /** @@ -59,7 +57,7 @@ namespace agentxcpp * 5.4. The serialize() function will copy it directly into the * varbind. */ - uint16_t type; + quint16 type; public: /** diff --git a/unit_tests/IntegerTest.cpp b/unit_tests/IntegerTest.cpp index 78c5818..ca472ab 100644 --- a/unit_tests/IntegerTest.cpp +++ b/unit_tests/IntegerTest.cpp @@ -36,7 +36,7 @@ BOOST_AUTO_TEST_CASE( init_constructor_and_get_value ) agentxcpp::IntegerValue object_2(0); BOOST_CHECK_EQUAL( object_2.get_value(), 0 ); - long long max = std::pow(2,32)-1; // maximum value for uint32_t + long long max = std::pow(2,32)-1; // maximum value for quint32 agentxcpp::IntegerValue object_3(max); BOOST_CHECK_EQUAL( object_3.get_value(), max); @@ -115,7 +115,7 @@ BOOST_AUTO_TEST_CASE( set_value ) object.set_value(0); BOOST_CHECK_EQUAL( object.get_value(), 0 ); - long long max = std::pow(2,32)-1; // maximum value for uint32_t + long long max = std::pow(2,32)-1; // maximum value for quint32 object.set_value(max); BOOST_CHECK_EQUAL( object.get_value(), max); From 8d0873d1f020f8cb1796e832def77fa67c2b0da0 Mon Sep 17 00:00:00 2001 From: "Tanjeff-N. Moos" Date: Fri, 19 Apr 2013 23:58:24 +0200 Subject: [PATCH 08/89] Remove use of boost::optional in MasterProxy. --- src/MasterProxy.cpp | 7 ++--- src/MasterProxy.hpp | 71 ++++++++++++++++++++------------------------- 2 files changed, 34 insertions(+), 44 deletions(-) diff --git a/src/MasterProxy.cpp b/src/MasterProxy.cpp index 8bf0661..a6b3123 100644 --- a/src/MasterProxy.cpp +++ b/src/MasterProxy.cpp @@ -32,7 +32,6 @@ using namespace std; using namespace agentxcpp; using namespace boost; // Beside other things, this pulls boost::quint16 -using boost::optional; @@ -904,9 +903,9 @@ void MasterProxy::remove_variable(const OidValue& id) -void MasterProxy::send_notification(const boost::optional& sysUpTime, - const OidValue& snmpTrapOID, - const vector& varbinds) +void MasterProxy::send_notification(const OidValue& snmpTrapOID, + const TimeTicksValue* sysUpTime, + const vector& varbinds) { shared_ptr pdu(new NotifyPDU); pdu->set_sessionID(this->sessionID); diff --git a/src/MasterProxy.hpp b/src/MasterProxy.hpp index fa94382..374ddc9 100644 --- a/src/MasterProxy.hpp +++ b/src/MasterProxy.hpp @@ -25,7 +25,6 @@ #include #include -#include #include #include @@ -460,35 +459,35 @@ namespace agentxcpp * turn sends an SNMP notification or trap, depending on its * configuration. * - * Each notification contains the sysUpTime.0 object (optional) - * and the snmpTrapOID.0 object (mandatory). The values of both + * Each notification contains the snmpTrapOID.0 object (mandatory) + * and the sysUpTime.0 object (optional). The values of both * objects are given as parameters. * - * \param sysUpTime The value of the sysUpTime.0 object according - * to RFC 1907, which says: "The time (in - * hundredths of a second) since the network - * management portion of the system was last - * re-initialized." This parameter is - * optional. You can use You can use - * agentxcpp::processUpTime() to get the uptime of - * the current process. If the parameter is not - * provided, the sysUpTime.0 will not be included - * in the notification, and the master agent will - * insert an sysUpTime.0 value (e.g. the uptime of - * the OS, depending on the master agent). - * * \param snmpTrapOID The value of snmpTrapOID.0 according to * RFC 1907, which says: "The authoritative * identification of the notification currently - * being sent." This is normally the Trap OID as - * specified in the corresponding MIB. However, - * if the notification shall be converted to an SNMPv1 - * trap (this conversion is done by the master agent), - * the snmpTrapOID.0 value must - * meet certain requirements. You can use - * generate_v1_snmpTrapOID() - * to construct a valid value in that case. - * + * being sent." This is normally the Trap + * OID as specified in the corresponding MIB. + * However, if the notification shall be + * converted to an SNMPv1 trap (this conversion + * is done by the master agent), the + * snmpTrapOID.0 value must meet certain + * requirements. You can use + * generate_v1_snmpTrapOID() to construct a + * valid value in that case. + * + * \param sysUpTime The value of the sysUpTime.0 object according + * to RFC 1907, which says: "The time (in + * hundreths of a second) since the network + * management portion of the system was last + * re-initialized.". You can use You can use + * agentxcpp::processUpTime() to get the uptime of + * the current process. If the NULL pointer + * is given, the sysUpTime.0 will not be included + * in the notification, and the master agent will + * insert an sysUpTime.0 value (e.g. the uptime of + * the OS, depending on the master agent). + * * \param varbinds Additional varbinds which are included in the * notification. * @@ -502,8 +501,8 @@ namespace agentxcpp * * \todo Document exceptions. */ - void send_notification(const boost::optional& sysUpTime, - const OidValue& snmpTrapOID, + void send_notification(const OidValue& snmpTrapOID, + const TimeTicksValue* sysUpTime, const std::vector& varbinds=vector()); /** @@ -511,25 +510,17 @@ namespace agentxcpp * * This calls \ref send_notification( * const boost::optional&, - * const OidValue&, const vector&) with an empty sysUpTime.0 - * parameter. Without the writing aid it would be necessary to - * construct an empty parameter, like so: - * \code - * master.send_notification(optional(), - * mySubagentOid); - * \endcode + * const OidValue&, const vector&) with a NULL pointer + * for the sysUpTime.0 parameter. * * For the documentation of the parameters and exceptions go to - * \ref send_notification( - * const boost::optional&, - * const OidValue&, const vector&) + * \ref send_notification(const OidValue&, TimeTicksValue>&, + * const vector&) */ void send_notification(const OidValue& snmpTrapOID, const std::vector& varbinds=vector()) { - send_notification(boost::optional(), - snmpTrapOID, - varbinds); + send_notification(snmpTrapOID, 0, varbinds); } public: From 1d7056a8b2eb40540dfd16bb790ee0df909309bf Mon Sep 17 00:00:00 2001 From: "Tanjeff-N. Moos" Date: Sat, 20 Apr 2013 00:04:43 +0200 Subject: [PATCH 09/89] Remove use of boost::optional in helpers. --- src/helpers.cpp | 8 ++------ src/helpers.hpp | 8 ++------ 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/src/helpers.cpp b/src/helpers.cpp index 6fe49e5..372237a 100644 --- a/src/helpers.cpp +++ b/src/helpers.cpp @@ -54,7 +54,7 @@ namespace agentxcpp } OidValue agentxcpp::generate_v1_snmpTrapOID(generic_trap_t generic_trap, - boost::optional specific_trap) + quint32 specific_trap) { // We need the OID of the SNMPv1 traps. These are defined here. // @@ -101,13 +101,9 @@ namespace agentxcpp value = snmpTraps_egpNeighborLoss_oid; break; case enterpriseSpecific: - if(!specific_trap) - { - throw(inval_param()); - } value = enterprises_oid; value.push_back(0); - value.push_back(*specific_trap); + value.push_back(specific_trap); break; default: // invalid generic_trap value! diff --git a/src/helpers.hpp b/src/helpers.hpp index e9c8597..c7d682f 100644 --- a/src/helpers.hpp +++ b/src/helpers.hpp @@ -19,8 +19,6 @@ #ifndef _UPTIME_HPP_ #define _UPTIME_HPP_ -#include - #include "TimeTicksValue.hpp" #include "OidValue.hpp" @@ -86,12 +84,10 @@ namespace agentxcpp * \return The value of the snmpTrapOID.0 object. * * \exception inval_param If the generic_trap parameter has an - * invalid value or if generic_trap is - * enterpriseSpecific and - * specific_trap was not given. + * invalid value. */ OidValue generate_v1_snmpTrapOID(generic_trap_t generic_trap, - boost::optional specific_trap = boost::optional()); + quint32 specific_trap=0); } // namespace agentxcpp From e146c2f31b98018207aa3b676568ea26aea918fc Mon Sep 17 00:00:00 2001 From: "Tanjeff-N. Moos" Date: Sat, 20 Apr 2013 00:29:22 +0200 Subject: [PATCH 10/89] Switch to QT for time calculations. --- src/helpers.cpp | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/helpers.cpp b/src/helpers.cpp index 372237a..1556751 100644 --- a/src/helpers.cpp +++ b/src/helpers.cpp @@ -16,14 +16,10 @@ * See the AgentXcpp library license in the LICENSE file of this package * for more details. */ -#include +#include #include "helpers.hpp" -using boost::date_time::microsec_clock; -using boost::posix_time::ptime; -using boost::posix_time::time_duration; - using namespace agentxcpp; namespace agentxcpp @@ -37,17 +33,16 @@ namespace agentxcpp * and holds the time at which this happened. Afterwards, * the uptime of the process can be calculated. */ - static ptime process_start_time(microsec_clock::universal_time()); + static QDateTime process_start_time(QDateTime::currentDateTime()); } TimeTicksValue agentxcpp::processUpTime() { // Calculate uptime - time_duration uptime = microsec_clock::universal_time() - - process_start_time; + qint64 uptime = process_start_time.msecsTo(QDateTime::currentDateTime()); // Convert uptime to hundreths of seconds - TimeTicksValue sysuptime( uptime.total_milliseconds()/10 ); + TimeTicksValue sysuptime( uptime/10 ); // Return result return sysuptime; From bf7c70b5a457f3aa8ada0c7bf4c20c710dbede6f Mon Sep 17 00:00:00 2001 From: "Tanjeff-N. Moos" Date: Sat, 20 Apr 2013 00:32:49 +0200 Subject: [PATCH 11/89] Fix references in doxygen comments. --- src/MasterProxy.hpp | 4 ++-- src/helpers.hpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/MasterProxy.hpp b/src/MasterProxy.hpp index 374ddc9..a43c50f 100644 --- a/src/MasterProxy.hpp +++ b/src/MasterProxy.hpp @@ -509,8 +509,8 @@ namespace agentxcpp * \brief Writing aid: Send notification without sysUpTime.0. * * This calls \ref send_notification( - * const boost::optional&, - * const OidValue&, const vector&) with a NULL pointer + * const OidValue&, const TimeTicksValue*, + * const vector&) with a NULL pointer * for the sysUpTime.0 parameter. * * For the documentation of the parameters and exceptions go to diff --git a/src/helpers.hpp b/src/helpers.hpp index c7d682f..e9cb4bb 100644 --- a/src/helpers.hpp +++ b/src/helpers.hpp @@ -30,8 +30,8 @@ namespace agentxcpp * This function calculates the uptime of the current process, in * hundreths of a second. The result may be given as sysUpTime.0. * parameter to \ref agentxcpp::MasterProxy::send_notification( - * const boost::optional&, - * const OidValue&, const vector&). + * const OidValue&, TimeTicksValue*, + * const vector&). * * \internal * The time is measured using a global variable which is From 17ce0480be0dff242991d013fa34eaef0029362a Mon Sep 17 00:00:00 2001 From: "Tanjeff-N. Moos" Date: Fri, 20 Jul 2012 21:08:06 +0200 Subject: [PATCH 12/89] Add a logo (SVG + 160x160 PNG for twitter) --- logo.svg | 322 +++++++++++++++++++++++++++++++++++++++++++++++ twitter_logo.png | Bin 0 -> 7848 bytes 2 files changed, 322 insertions(+) create mode 100644 logo.svg create mode 100644 twitter_logo.png diff --git a/logo.svg b/logo.svg new file mode 100644 index 0000000..f3b6492 --- /dev/null +++ b/logo.svg @@ -0,0 +1,322 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/twitter_logo.png b/twitter_logo.png new file mode 100644 index 0000000000000000000000000000000000000000..424c0e548cffa0c936dc10d3eb333c6b227ac76f GIT binary patch literal 7848 zcmV;Z9#`RsP)005u}1^@s6i_d2*00004b3#c}2nYxW zd?8f zvMoz{%-cWq(CqHa?9A-DJEP;L&udvbGw=Jn&-=W;_j#Z9eP=YSi5N+*T(qT8XFh#@{B zgjj3qNg;%#1k?eW0MVOzlS$eH)LFJG3x?MZc)rGuNJqJ{!voF&jSW%RTz)E1G z;Z42hg)tg{g+hp(MmHEv78FHU3~Z&>_Y=O-(q1lTUk-goaxsx zZuCg1`&Tire-)*D`eY(>7lQHV(H(K_`~^;(ZsJ5^6Cdq6$jh(2L37JlE03zc%|eKm zk}sqfV075s3Y41VIQzO!@z-CvgDF=}!sqLay7WYZ!zx?<^gcg)^eHyH{>OB;p9iK0 zAwJZ8m|%d4qVxma!erPTH@b!g|KUDnUOU;j;16%S#RCsM%t!kUnB8^& zm@I@i9s3~J0ABz;WAyamxwClWp>I)KR3t&bTX#U)#fyC9@BWolue@q@+cQFl zWwAfv2B;`X9g(3|7hn70ZT#!kzlx$LlEm#H=wbax2*J1h<0t(1@uv-M0j?H8ya$N} zxQWQpS_&4=oy8Lmf7f;6^KM&uS2DM7*M0xUigg=|F25p#m;+G*R21b#V71OD1JXM4Jg;U<8Qw5dFS=?Bs?ov*N1`2^A}%O#-=yl(YsU$O!Wi0%OsT*V*1$|=eEL)LDJkJXTbthH1$jg^lcr$q%&GYOJ`_cijZuCeinu=wN! z3E7SV_JGMs_phN%*dQG<-FbWxk`2h?vOm1Ol~wCEP(N!rb7tzE=jy(&MLLecFs9FS zVaTb}&mLdS*T4N;0Dk_&GptztbFQC$os_)Oq8oWUChyd6e>0<((~E1?Cur;O<OBP?!V*_sLUN(&DV!Re?`dBVtz4V-!YC4g6z+}u3 zoGrzfKbUivSeX~3bic!T7iN0tI-3!^-ny>4EFOj<1|+Ib54vLBg_jM`n+=&h4(O^* zy{R-qc-j8!2$w^(dwdA?bc^bstI2Bs>D6#D3zoDax{Gm`b@cjsQXpwJjLBC$SeK>C zqxT3y1S!_wJPc#CNEa3F8H(*`ffzZY~B-v?4JSTS?kGDjR}7rI`T39 z{)305%t-oNd@fRv0h`%=7GTUt-tpz0A07O7;u0iF|*e>Iw=97}&qR zOVa4$)z`Q3!b`v7Z@+f0+oBl4IRoa19P1`u%{_PBo}0pK;L#_4&C%m0;(rgS9w1Rp zIla3*&_R29KwevAfpjDe!Jcu(x&dTajFR+QQg*hVa}^;vn^w3d_EYuwD^fL>^KxBG$RPVTm#W^h|B zrv~T=!Ch`x!=iOAc+FLaePe;5;Hr<_HFre!LN2`7mfqfs5TC?(Q+X-yqMTmXSnOyP ztTTJcHI(S^>$V(LAw$ZZ7R>Vgu}rVXp~0cUM>uyO@laCB*|U6n>^MU%9h_0#QmY#E z0WF1xvS|4ZXTe@-dH3Zwc<3;XJ^3`N*S^fI-Fs55Z{M+t(N|8U_KM3{IKQ5IK7Tva z#&3tuF=G02>0phsNeCYC9b`_1?055~re+@e!NdIg@h1obf@$ynVEYa}*uI1R`q5AM z>b>`H|9yW!dEYYGVmX9c?P*-D$-(sQ2*p-I+4}Z** zne}|MXPjnE4*PZwbNY7Top*41mL8M2XYJQ>*KyYGL%?RS5Lwu={?YgU8SbLaT%9e4B5 z-o2R#<|xU|&uM4ZhxrgJqct6{PmawnAvHEO@tI|Jak0JKR5fkfWPvv2NQK8IAxchV`RSvN6AFb4RU!iy+uM2c zmrvzLe{}x#DAF*X_j*h=v1-k_9F?;+C*{Q9Hj$V#r^Fr6_F*1>jS8L%L4fTa?&QeF zA7{NBfbBbWa^&Nq3>`8g%OxpEzukgy`K~U-rOQ3GhM0@Z2>bT!&w3eJ?A^DYVMDWQ zfL&k|_SR+u7q@~OKY22z<()WrirgsJJ(ng?27MSBpb!EPeHFjl!!{;)>0Zjs5Zu(% zob@uaINj8ogL-M)n69=XS_A{A0cXKjSq3Y@Aw)QY8tlkCvotbQl&9G+AQ_ib^hJb& zph%2_rPNV?5D1|<$SOCaV`zYCupPCd%^<&QDorCpID{Gw5H^w{B`fDjtL}G+<7b_g z=ct3*sG|r45TRgB+R;q+B4kV;CI%QF?2rMI;nXlhIGC!yEGeyKNM;*J?PBDRYU7S2 zsg7zWI)cb(#|&gr1C9*PgaP%C1;Y^GP{aV8D$s`EUp{&mgR2K{?8GT&W!b>^F{2nd zpepNzAwogaaFB3^#Z46whh1&wRvj^5pd&$WsXl?lyhJF78VZ^Z!4eIB-i%N4*#EsK zEkDC@W?pOAtpHFQ)=`9YhG41fXiY9P7%;qM!hjv9fef}INiYmGHUvv@1pwm)5P~n> zT+gqbdx@}W-)Xms!u)(bzjzL6dt0I`vJ69`cQq734Tl`NQnEz;##Z-Z>6~dSU-xR(in?dXTrMpyjm+$`yvh^zp)(;8J1`&} zHRON+(Zm6bk>%Ku5D4_b2of7DYJ5sCgwo!@H*cEH`YrF!c<#KsGNKq#S;5~fxE|Wu zK@=kLeTGITrG`Sq8j;w61JW@WQA`X_bs)Ix-YlXlm~7~h3||OP1xheTUV8_5XU{V@ z7~=nKSwQ_0&k>Y36c_vbJb%j~s?N6&KGRCLybLHr`1OrYMhyj6Bof=X+I+%+0Y=*0 zZeem6F;c#jK&k`7*BGDD9zZ#J9$#ZK{!`5qU+AEsuz;41fD|Jv@cF1LETF0*i0@=` zL`^~v7G+RWU}%I1aMHJ<`jg9m$*>@piCLKVfKC`N84?&V+F0ptvXf_oRh3|fyo(X$ z^EaNs*VxSayBoM|-3DG-SkJlQ0+zk7nx+dj!cj>WR9?pOH{VEe;~5sd^gC8Bp2y&5 zrxFOlltE#B)CluTCP_96Rw55MBN98Xkhh5)88e_N5Ni6&&3)($D;}MMIO_<;v)#Dy zwFk&Mdk+8U7JQA(Y}?boZEH91^t{>Bj;$fwzk=63c_sh$;#!{D_y($thRpZ-xP8tv zzOmqX1_eU+Pd4+A5G;6UEo&CfXOIwa<%Ro}Mwrki(a6|2Qgb*x< zGGR4Q7b6^s_=LrU2w$GY2s5(`5z9ZF{%oq(KIu3%z${R=ojhYQ$nasJLwTI}S})*l zJcGaS4BPe`VACXF3Qs9y!)eiekvOHrdf+W4AbJaqp(JoHz0v+IM8IQ;%D z8uuRJAGf~EgHt|9zp*12an%IIUO5i(l(_S+78lYvnSwdB;}H;L!g<i5Q50un;;% zm`R-_>Mto&lz%OcDd zs_IL)ZwYE)KEj_Dl|&HP8Y{Sb{4@Cdo8I-!k33yR0!oFes6v4cvK-+u;O>DSu&3SLVyCHXohN0su2nYlP%$J zJC;m148!Dz0aKu{GLbZkv+Jv%HNF78a~JS6w%|VoMfHy)RZ zm9He}LBxNO<&N(n*HfDkVM0+-7{5;l!Te85KmZF@u4DC*diq5>oIs$6K8SdT#>fbb z+ek#)&~*lMYJiytE@vsJbI7v)T$K4b0{B|n@Ha(<-5vW5@ws&ydFqB4)Q*ZWUsXBb zvOW>!%ZoCf8V!jgm#wOir0t*y?5D$kF(?9&r=XS;fQT|7f(4VtqY9M;E7q}QNj+6j z<_!q}rNx>~VP#^Xy&iKFx*`K+D7cI&$3if+I)cXd;>_37im$PS9s3Wnblpatx?wt# z#tbLeuWy9;%8F5o{NT$&DA9T=ihd>HZb9hJ$-F$mC54?VstOiPx*Q>3 z!HRXPUR+OAoK2&_l(bB!)moxVxnjU{(@8x@UJI5C!=)s%ATyCrOGf}->jnHxt@uy3 zuyg+rmaf~#lQ&Ff(&*s?tNLn&-F)!*BE%IpKCO?ZEko7UO*#e?+W!g^CE^o?G>p2a zc07WJPq=3BTq?C?#+lHsIcQ`>f28)7EWxl8M`0MP^Y0pBK1`~=m3nK`_(CC+_F#nh znp^QVwy?9|2us)ffhTX6M(yZfapnt^6{8mFF`rSrH8Wv4^&?^|74zS$s7(PSFAuf2 zkWlPl1r|@5fT{`>tX$9PMfFr_Vu+v+^oQAV>=YGceW>nV8PCgDg?b%0$8fR~hfq_O zaB_Z5*oXlmxY!Y3$NnR1-*bp#jm?Z3Hi$_>2Xk3jDgHC($Ul8H$@qrHXS)&OGh#kN zfs$sy+DjT{H1Yuxb3!NrB~Kw-oDXVobnBVmrmH3(5G-7|p4E%zQXvE@-rK<=Ti<2- z;bUCvi0rQ$SXIH~%g6A*-8VCAkj_`dM&%SK?U>t!G*hXibHSY-+AKNKK)yzf^}!=4&z@{*Vb!L$+4%N0zIo5B+;QXdq|7xkC46o} zKq5v*88i$S%POp@eD!;ev3m2L3?KX8=n1C&>Uqiw^7&2uENVv$>-71` zisSJ$>&%xZQ`|e$+Fw*(k@%^-R*N%XQ9go_$fQ9CZu-OozW3gCUE|Z@!o?0A`0;Xz z3iG*Tc3o$_v7d}~w%e$PK~~O|;-bn-yZmEEK-;}3H4O8=FT7%Ed@%%6m6kw|f{Idt zm1Tq~O9}TWL@mlk$GHavtCQ*|S_% zdl}VL712xux(t|Fx;2! z(OzCcsI-`HaUp7+f~sgI4#H7N)^zL>$GSnFDgxD~5H9o+C@bPSuWYegSAfKl#Og~jV?M1+ zhD&jJlMuVZG2qK%f72OSFWNuN_U=aqI_uThE9}W2C5ju*%-Il(Zumo!YYvd?!))Jg z?h6^=-NVP3FmY5w>evd0(>f$DVO&r;jWBr#wqK4=1ltZcdspGEgGUJj0u$p6f)+eH$M~2dLlMrjV>IgeK z)+$s%Fcc==?@MqoGDik^INFk*hB}k(wkwj2d^;Jiy0V;Ojc07aZ)AEV-&*-s)LiOF%+W&!Qc~zobQ7`?h?YY-Svr&?i4l{0n29w*cz5?f+u2+> zdT1vDW-L?8sZW}O#D`@Sq1vp!PGETS&}s?`{B#8D`MkAbhG}FIX?-x~u%4$`7%1&5 z*jZBLBs4u(sMJlYv7w*{`V!X)II}B%(S8P34ll%(YyJVKFx)$d9`SRlF z8XYF;FS{vC9SvZ9Doz@8J7dJeum{YmyMpPTxQy4{+if|I2kyL)vXVl1brCVWB<2_0 zP#^UJGaUgU&wurn*}U@hhwMCX%+gc$FRf?P-~sW|j3PFAWQ75fVN!-k`6k|qOt#2? z0h6Bp-k*JjiqaBGDw#HEEVs?6%MSa+QcU+!^N-ZkpQrH1*YD)2vBOR4>C4OG-X$~m z;=-vZIut_Ki@!RJW2Picw7|)BtXSYU0ogu3nj!@81^O5UUecE}|9KyO|I-(EecN8$ z$6^igm$%NA$l@`X1cw`&dGnp^Z2#yG7eZmaw)GvZXcDror6waML$GcD(~fXyTfjl%f#3$GQ|L$n}#X`kFDIy z51xIQK&UfJ^4RYEuzNoxYd7jPlZA#to~E z#QQ+Eqlu{Q60X@bFd1j$orPgCJd|X!qPp**i**2l9<=bbM`b1&}GDyc61Ln$k zjTM(#R=fx6y;>s2?!cp~Hk%rs7VF>I!P77Qk!3eb&QvfHSZEtzbvKM881{K52AH(~ zrd7mxI0k-={j7{(p4p)j&HVTC8*LN_4?ew)*;il2z)N!V^$!Lo=5kCVx^T*X?rzB! z@_MjszbCOVUwwa%?M)DE?E&80(ZHfl8@LD#VBU|6CLeAS2~G_#la&xzNS=h`a2JjS z+x9!#81UhNV=TIMq6~=uyZuPfM2FmEK!;%%4+tI|J`$FeTtLII(~h1yc)Tg~y(l?5 zjv+k6fR480dxQZ!urIM@P!-!6tgS|9F=F5)sqRBA!yxevoZ}HhM+_sFydBHA4=Amg z+7$-F8?uipMh;@dmhHBmn>b=n<`aO7CR?!%?CuESkO7@jx4dfForGkkhflkrh62AY zA^4mQB}D~H9ye5e2*k#DjP!3tkf$%(6Qn3S69+Vw0UL5;N8aHB%K6KiuH!$Sf6ekU zfB)H;3@Gm-Ux#+GOB2YKOBH5f$XW|FLl(%V^A)q1u!tPN?w&iDH+CH4jh%E96@&n$~O+YMlI2$pny)M`D``hZq5$s9ff9{ZbHczpdkJpAJ8 zy2EjCVLpF%>vWdRn3S{8!?cvR3usXmyE0pDM`?j*NlLXmqRM}}QzrXV@_>8hUPJxW zW7xXuFgp&NljvvmT$}$oie-{zo(w3zW#6~+BA;U0Cwx{*chP3c? z5eYEWS>}duX;m4wTz5IQTz7eD{w{}%w1^BKnXYJMt}lnXVIsmio!v-*VIbAbw>3D0 z3yheRK(qseIf(X#fRn6py(u>%2zx$Y6!J;OaU9TYVX{LGc6xBG z)`@N0D`it|2GDNtxAT~-yDhwm&RG~nhV!4PQ3$qvbcA-BM-#g$WJf{X-G7{`MoCzW zF@=S^-P@3w+4G;7GLEw1f(&Koxv0DBQtGcBox2UGfF9{&^m;b=u-?rFR`lVH8COWi zsf$7uCFV3Fq*s;`281jLo}1;LRCGae%~oJI*Kovus_{~sTwf(uTJu0)SPHWHHq)%Y z`ED5f8rddB(~7!j7+$3eGq@9i%7}DaKa^xEbdgJ==nkxy8+~O$I*zvFyLKqaRlg@! z`{QK7qn$`Amb0&G^}?3?7;@$JxHUnN3GcZT4#P0^mvFKN>vBk4e8}+^y2yc7+DwZs zdnm~W#)ctP{oN%D;<8|l4kdYJPn#~>lB+B3!U5M=(b;w^_rK`aIy@Rn%;vX9WdM0E zkF$ub@N%Ne;L%v3M+3uBzX!x(iAL}f@eotqlzP5B(1jRK4{}=5!e%2W<=D>3qv0n# zbQr%^r^64N00t*tIo;Y8IZf3iXM!NhFzn~z!F`F~>T1-fv#H-`8pR1ea1S3;8|f=s9c7Z|*xmoAHr~HGW_da26;}zWU3}d%0$KW!8j~gB-uD zK?-`#n)C8E4BxBW3~crbA%cpctOq`ue8<*(jl8-46rZZ;mlfgUKvEOfb$hy`J0KJ3 z6}EL>BX1ute7WZuAw)1TL`gHiS2k%6lD`IRqxJO;|B83t&=ipkDM?6o00h}&X+BpYBA z@D^bB#k@8B`|ww@$1tVFN_fVL@Mc4H^$~n)LlZyz{T><`FPPod08AD_G{rtpl6O5T ziZX%7P~6unr%w*Qgr$>*@~IJ*P~bQHj(UsmreSy&?oYM?VU<4~Xy%!>4)gZGGwE(` z1*Qlgb|w_9x9vVUD_(`^_X$T(QsAR*WF=z;l+wSnfB|KN_iQ!eMB90ER=b&X8P3 zWZl?pO7BhHPMd%_t9E5N1nWUjlzLzpa3f%4r$R5fKbnaw0000 Date: Fri, 20 Jul 2012 21:46:10 +0200 Subject: [PATCH 13/89] Export the logo in a variant suitable for the blog. --- blog_logo.png | Bin 0 -> 6577 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 blog_logo.png diff --git a/blog_logo.png b/blog_logo.png new file mode 100644 index 0000000000000000000000000000000000000000..b1e8b270da308808a5e5f7e1cc927da0832fc89b GIT binary patch literal 6577 zcmbt(c|6qL_y5?EJs%`wDV4HjUk9OtNcLT2WEsZ3Z%INmDnfSNb{et{W0_R8Y-1e; zGa^H#v9DwMzUKXTJbu5&_wVmx9(R^I=XLKn_nh-Q%S|#h(Pv}kX9j^lYzFuB%s?QT z9pHPx`E$TKr6Z33e4Kk~q^}1$qrM8-%Tj?ECg1zE0U!_y7j@8pvT`l~lZ=4|#&;QK z8M(Rmc)xwM#{pC41Mk`d>iT$lyTSrNdjsic5QtCQK<|!4D2_ZA7HYBE-m^KJnJFpx zi0&Hw^lPstoFiWn&o>uZvsg4t&RD&%;$~>WSw)2(X?SlwTAi%iw~BZZftah-lw$Zy z>nUN+WBZbYmbOmUhULZux&FgBExFWzYw~@PZa0{=qc<-L%MT2wE-UM5E+46*x7E{S zyU&9_4W80j0Bf{@Akc*s5a_u!BM3yV_TM3bp#gzn*{O{GcW4*T{eRN`MNTFCf8?Wm zx?CXmOlwHZMM;~2yKgRfEDz=4kUshB!kUsUtnk!(>8=&!<@X(1gDq>E+7+UYLybS( zzB7jkD)M{oe)fzNo%XzZ5@BEVXRHj`^_oZF9*f+wflDW=*67js&NvTN5mv`FZE!T& z`JKjA;wuhelTS!(qYPtyytJK;# zD$P?+1QV+!)4r4PY~a(C8mz#!YL}pTIW*%bPsm>pWKR@PQHO=%J&sS69+PjW?-#w8QJrJSu_?z0Shaui;4r=+x|gkOdXg49mcv5R1ira z^1$~n^21#7S=f3mbsab_e9*jdtB?V_dE6iV7w!BuR8m>lIzMtN=@l!V4qdD^V_o0M zNRfa;mQtW^1wLlmGVE#aTvJMnoZA7~D@LS10)}!VDZ!FLBL_ao+SNgroMBWsrvNiR zg{%v0+C)25rw>HM1rQNGN)gWPv%lBN)x2&Ox!U5;F=#_WLw6Af&rqQ#RLbT{L8r?; zLGgM=08z3}hCL4}j6otx38#qOWF{8{AG}7#JfK0ZTHjya&b>44fVI`RJhzu;FAq3C zpf!K3Hf!3?Kj;~>ecu>N#_?{wQhm~bMACKp0PAq0C;@AaMFK*W} zoDZC5ZSo;>B<8mU-(m`8DwDU&ma#w(J9Z@DC~n@n^pwsx#={qJz!7x)`kp|tToGI> zzh=$~>Hp`~SV6gYPhx(5f4>JeRowEJ*o2JJ7aC$n~U+)zjmVaNSzn!6e z;X40N+tMKV)Of7pOf;&EGDcK4H6*b)gG>wQem%+C^X-ikJAIv26?D|jVVGi7?N~D* zJdn}fRjUCk<`(FeN33w>B3}*`IYUo1mhGJ(VT8ihKh4#SKEIIP_)Z6)f?v;ziBYAS z$;ZeP72hkv0AKDCofuSV=WCY?Nr^7L%{rKlAb=@$PcGZJtwgKV=07N>1Av1kyuZRC zRTJjX=dC+WN3V8)GtiGd&cl1VLfx{E4$!UD$3F=4YoEw6GtGpx3#pqN?7*a?;f_@n zYw51#3gkAxp~u@#JKY0}M(LzJw|uNEUmJVmaK{O!7D4kQV(a&B2xLyoB(fs^c;kp4 z?0?Bw2H;~ThdGK6>p$2`3N~)rTYXC&^*K98FP+wvk`9P*?1)8|r`?a_rn=tiqg0)RZYXe;oA~H_Z*i8#GOXETwElZ$_pcm} za<1^96Og*G_|+TZG{Bb7ssN)*Rc!Wg_=8cBS9+Y_xh@)dHH^Q+4!8J(O89K<+vT6B zV!MZXGFOF;y!w~96lg9;_zK#6rYsMVz{GhozpdiZ znDr~hZGUDcXm~dN%dp;xN^z;skPp)QQSnYuiyR&^c>_|B0W{))A{ql@QPo&OLP4|l z3>p)Z>NB|pj#!K~zUx}D*0N3`73%ikbRSs*X%G+s5c+-h{fFzq@h8|mt!|~P@Zl(? z_^@Uq!Lhh3<}i}~jk`qQ^*c_2o}@%Rg(>q(CeUTTgozwXofT_BnF| z_cFn(aF`jRArPtxsx{t;241%R;L^WrkAzPC?J>uT*I>)k*G@U6n;zkkH5LS+?>A!U zKtqLeNmd&sFI(cS>|`AJRH1OB-Ux&v(#gIFHuikE|CnM^lE1@ zPH<8{K*Va-@cEO0xI1JPvNI)1#@F{uYda&WrG*6^yiOgUF{`VgI&t3@?`eFcikx^~ zvQ&Qx(}64Faoq`?-sz$`YXBJ5;!ypGtM{6ymX`C4K7m?=smbQ;oUee5e!bGY*Y9kZ z>05roAM`k)$~B^jJFzxTFM?&u(Tsp^Z*V0A_uzhg+h*)WM)@_s$zUmiT7t}UFe1j( zmGOW!PP>fh`Qrk{V`d9W6*G7bv+9iX^%;^!a~}7ka-eBNQEc=bkNl~bjQOT>FJgtF z3qJ02J`$~wr_pkLd|?GJ8KIT5Axropx@x=F)tqx+nu?dRm{B|>HID3ihme8vVq{gX(;Sr&tpgmfaJYzO-D>El2OOZhrJgxp!04-xvk#Az3eU2+v<~9(} zL5VlVxE@Sg!xNeowR{t!AR^QEtQxJW7kRSA8{fc$rkrCaUPhxnht62Xk_FFvTAnmH z^33E*RINGc<1oFz&mUveOvnn$b!{df8KT#f^TgPhRDbL3{lV*N{IaDACxK03ZrK-3 zZ-?ernpk>-E?~iaX$Mbe)(yGRR z6sWSi$we`TJ zzfEDQ{#NSX-TB3*vMK9{sqnoHbQPTHq``E8bzO42LQ zU`+1)D~-(!AWV42QJ@c|ABPQ-Ex3r@TM&op`A&nuSltdW{USBq3TSrZ?z%;}__QL{ zoAHhJVl4!>)E_AQv6e1;waR)G*xOa=NRMy{{6KMW%Xm;*^_^JZHleW7^S?eY5Z~ef zd6Dv4-|z08nScS4L*2!T#5Jz8t;;InmMD*%+kH(-GD?bcOaEco#RRK37TVLR z0g}Qk!`NO-8miv@)&u36q32ca;C*FHT+%NAGX`PX?q3_aZa(Ah%Ah2K%poc(@0d6&U~RHR~iTLI*I(2M(KR950P>%5zx;tklV@x6x<{y z6q2LvQ&y&Rf2>96&J|#y>zS?HYru{NymP{S{BlVz=yGR z=|5MY#!dA8{;e&#jzJ>Oyj8h#?R0|~eEj^o_brU3^Qyy514`G+s-2U=^}fc)#v9K5 zg^;(A-RX0hL#84B=pYx4Hvl)${>u#R{NW*Pz0l$%#ZA=ApA|C^FFXF!u>QVu(EhW% z(UIrhyKyhl!d7xxEU{_$`GZb&(lZW*&rDY25oBkmPFlFJ;@QqiiQRUF^?u5Vxns;` zyj-WLvfoRT=rRVbJ4_AG_FEbsDx6cR7P50}Zd@X69YRsl9H&OOi2GwibeX;3k-NjR zHefV2oqOsb$i5`U%mm97PLf<@c187vpV($c06BWOc@4W)GHaX)k9gZ;GK!N#rQgdo zC0pfn68OZ2qNnoT{%{6Nrwb9KKz1GUXy>I4YRpQ*e(h(_IURr9o<^^JF`Ts!g zu^CtEJiMN&n#2yIq>gzi;M%u5i_Z&TVEtrkcidl9yOt+VvN`(+$;cbm@-W7!!)}@P z;%d)#8BB8_oyA;9T%_O(_GMUVT8pQIi@CsRq0{*>NW73!MU{6)TP}<1+Yx!JV|Ay@ zu~US&0G@rfcawQemZS>yA65>UDef12F{z@kD*QE?SrQg zc03y%{T*A)d9Bf;p?RBF1!GArpFh;Izi7SU;WA;l-Gm@VEU@%E_l9B%T~@L6MhlMp zPb`BE?ii&mV~UO)zfSoH8y(PfuG&60VFsS-W(iEq%TBcUWf?iB>gD3KtA@N;ozW_3 z?XNnpuoY*UE;W`>O>aXECn%-+p=I;x;=g8k1N*k2(AR~F6iRTaqex>7U~ zgpP8;y}!hx3gY4xUhSS4I@nL3-FO=ZcgG|0RWfki6)Xq1J7Ju|Nj{m8wzgxIFJ?*% zTmU1dF$mrO-MG-C;)~b#85aGVSy0<1ugu24&KPl3;l5;nAMf6TD{tDWFjPs|E>}xq zm-4&ya}gUqi!megsr6#*tg6RnynV}^Dy8+ehdG(fXv4S;f7op=-3&x#cmG+ano1UB z10)^@Dm18&wQ^T%?G*KDkIWea_1Az6q86e2c(mInPvcvunWn}+2TX#M z)sv^MQ*Z5RG(&c>g$ac|aN+645i`Uk&%FkLK!UOLtGT7Y;@NFZ?EUDi%YZ6Zts4xu z_cpb#pXNWVD&DaUG*NFq>{U1+=JJHcOx*CEZE+SH_N=)Qh5EBr12;bty3SS=z;%Xl zI-6kzpOoFLR3WEbV+-AUw~8!CefF^Rjw@Zn^$9(1e~s{+AyN>wSQfX@6;0OicZg~Y znS76*v#`M^J&iCX&rQ-+g!llJ9N-5bQ>7KN9qt|ymUoA|1b`J z=&l>rqow7mr>u4SPhL)R5$saLlhJiTQL`!dHH!euM{hk`BLh(q{l;$VGLV<`THN1X zvb^C{+N4rB0bz_d37STgKM{H=P?X;x=PYU%Q3)*zNFfMI_7ROzo#&D%;)VS|{izobB zCO7zZ z&5GO54EI$uytlVJ`qoK^{bHRWP)uHR=`0T8AK946xZ#-8v)_=+a7bC&Ny2^EE|?^% z6wv8QSl|%%zf*$DGuRp6)K5zzFlzEi%yk5z*lN z&n0d*MXZ#Dd=u(ggm~7{^Ef>~$^z-Z#bz(5w*Hoq1P6J`%^USqblL@?{kG{mvfn=u zn#OM5_3*!vvH98aZa}xbeJ++aEa*kg_ZlTYyvdv5;-iJS37#>Uc7C|b>_nB@<l7#L&O zA#b47E%ySJhv1=qb9W;Y7JrT^lsG62{79eGv@`7RxL8f#+O21(gS$4bi`0$d+ao60 zBlZ(}{O6?GWyxl{(w;UY$e&>&+1GpJu?p(!)~ng*Q&T6j;GQbAW2ZH@20(?ET<~8T zDMysTLhb2ww?DfT8NG{!*S)jE=7&}`YQ!E37>9YZC<&@?ZXUR1IF_Q%PSzt^?iA2X zL%zRa6PJ)k#ggEmk*lBZsG~YfzPHU*DZj1i+nZx~HD^mzg<g(EL)9+X8S8+E(8BkPw^JnvPjx9iwK8id4mQt%hfKp8FXE4GnPw zf3b;rGvlUP*;IZZqu4t^qVb?UF5G2lEs@6eiZ`xd1lI_iK*z*%3{cN)|EENad-q#D zwJ1v9z;d8_M%55Q*eXU^x$91VyWv+QweZoZIGzc$;8B6?FzVAessVu{1aj0JFo<&n z-NeCcMQUf;p(O?AY*QI)-@`#Ih|ewL@r>H=(NQymO|4G7+prZ3Ce1dgv$VAIXR}8b zTj$z;J^%=}?z5C#l41by0ac!3d5 Date: Sat, 21 Jul 2012 23:48:53 +0200 Subject: [PATCH 14/89] Add the logo to the HTML docu, change html colors. --- doc/api.doxyfile | 8 ++++---- doc/html_logo.png | Bin 0 -> 1838 bytes doc/internals.doxyfile | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) create mode 100644 doc/html_logo.png diff --git a/doc/api.doxyfile b/doc/api.doxyfile index 39743e7..f5ef656 100644 --- a/doc/api.doxyfile +++ b/doc/api.doxyfile @@ -65,7 +65,7 @@ PROJECT_BRIEF = "API Documentation" # exceed 55 pixels and the maximum width should not exceed 200 pixels. # Doxygen will copy the logo to the output directory. -PROJECT_LOGO = +PROJECT_LOGO = html_logo.png # The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) # base path where the generated documentation will be put. @@ -980,13 +980,13 @@ HTML_EXTRA_FILES = # 180 is cyan, 240 is blue, 300 purple, and 360 is red again. # The allowed range is 0 to 359. -HTML_COLORSTYLE_HUE = 220 +HTML_COLORSTYLE_HUE = 17 # The HTML_COLORSTYLE_SAT tag controls the purity (or saturation) of # the colors in the HTML output. For a value of 0 the output will use # grayscales only. A value of 255 will produce the most vivid colors. -HTML_COLORSTYLE_SAT = 100 +HTML_COLORSTYLE_SAT = 0 # The HTML_COLORSTYLE_GAMMA tag controls the gamma correction applied to # the luminance component of the colors in the HTML output. Values below @@ -995,7 +995,7 @@ HTML_COLORSTYLE_SAT = 100 # so 80 represents a gamma of 0.8, The value 220 represents a gamma of 2.2, # and 100 does not change the gamma. -HTML_COLORSTYLE_GAMMA = 80 +HTML_COLORSTYLE_GAMMA = 120 # If the HTML_TIMESTAMP tag is set to YES then the footer of each generated HTML # page will contain the date and time when the page was generated. Setting diff --git a/doc/html_logo.png b/doc/html_logo.png new file mode 100644 index 0000000000000000000000000000000000000000..b266b50436550e42ed9c68e80d2be26451b69c6f GIT binary patch literal 1838 zcmV+}2hsS6P)!H1u+$|5k#v9WrrfPv{RUwzU}&9+D>Qs=DpX~De$2uIZ6B8 zUCurKbI$+1I~VLF2&@FQ2qC%vdA_yJjxBw51?`L%Ht%KvYk?Xe1eMb!GpS@E=T_v9 zC+#OYXghcWDJ8&e;BMgW;Vdo){07uKuw)T0Jh_abf+!b?bar*~%qy$;=!>uW7gz_V z+3kEe`mX@)eXwycZ@%<2;ZO)6guNo1+vG{Zp%AytyP2cMPq3?XPbrWDwz@@bix6UN z+xE>a5R>N>!OP|>KuY-?(2)J!ZyBpX)K*qZrMRdt4{0-ci!UxLq_ScP`wkqgl@{~( zt?iM~veJnll#yE?@>581Nm*$Ld-or*3@^W(RYFnDXJK^NIJfuwb{-clkjq=piTw9d zYD4sX<=##`g{8n9 ziKqF-T3%cI7Au~9e&GLDEXJ#=-)7I=HrB8CAZNj_q@rQ6!U&M-*WB&SBoaLP;>(u9 zZ`{gRd4X)C|{xSd&7&1A`<2Cj-F`1#X~Tzk*0Xyqk?7T7ngVLk5905QEF zCy|Ec!gD$@%L%^IJ^b_K76L&(moB&ty`+$5Cr@H$(xCSK+tA8OP?9QFmXPE>pnDH z=i$XSyF||Pf}CktP(*f!8agelZRz9gvvH0X8fChc;bf_6sS0d?$XP?Bt2h1Z*nb@` z2w|^bsn`}2T^pjNu4byCaqs*&`1*>${Q7E23&WU3Ry$pzS2r+qy)W<58uBYFyL&$4 zg8_=86Ij+b57W?x&ZQ3>(_2_#O$FJ6DouksuD_BwGpBOAqnp~Qsg@pJ{?0nS+_sb1 zZToor$p&@!B`+$>@4YnyiS z% Date: Tue, 7 May 2013 09:21:47 +0200 Subject: [PATCH 15/89] Replace boost::shared_ptr by QSharedPointer. --- SConstruct | 7 -- doc/how_to_add_rw_support.dox | 8 +-- doc/how_to_send_notifications.dox | 8 +-- doc/how_to_write_a_subagent.dox | 2 +- src/AbstractVariable.hpp | 8 +-- src/MasterProxy.cpp | 107 +++++++++++++++--------------- src/MasterProxy.hpp | 32 ++++----- src/PDU.cpp | 31 +++++---- src/PDU.hpp | 13 ++-- src/RegisterPDU.hpp | 2 +- src/UnixDomainConnector.cpp | 30 ++++----- src/UnixDomainConnector.hpp | 12 ++-- src/Variable.hpp | 28 ++++---- src/varbind.cpp | 42 ++++++------ src/varbind.hpp | 8 +-- 15 files changed, 162 insertions(+), 176 deletions(-) diff --git a/SConstruct b/SConstruct index 0bf02d4..5689447 100644 --- a/SConstruct +++ b/SConstruct @@ -184,13 +184,6 @@ The boost::bind library is required to build agentXcpp. Note: For Linux, install a package named 'libboost-dev' or 'boost'.""" Exit(1) -# Check for boost::smart_ptr (header-only lib) -if not conf.CheckHeader('boost/shared_ptr.hpp', '<>', 'C++'): - print """ -The boost::smart_ptr library is required to build agentXcpp. -Note: For Linux, install a package named 'libboost-dev' or 'boost'.""" - Exit(1) - # Check for boost::test if not conf.CheckLibWithHeader('boost_unit_test_framework', 'boost/test/unit_test.hpp', 'C++', autoadd=0): diff --git a/doc/how_to_add_rw_support.dox b/doc/how_to_add_rw_support.dox index 1e0ea43..5c4a7eb 100644 --- a/doc/how_to_add_rw_support.dox +++ b/doc/how_to_add_rw_support.dox @@ -113,7 +113,7 @@ by adding the following code to it: IntegerValue* old_value; public: - virtual testset_result_t testset(shared_ptr new_value) + virtual testset_result_t testset(QSharedPointer new_value) { try { @@ -146,7 +146,7 @@ also be implemented for writeable variables. In the SimpleCounter class, this method sets the internal value and stores the old one, in case \ref agentxcpp::Variable::undoset "undoset()" is called: \code - virtual bool commitset(shared_ptr new_value) + virtual bool commitset(QSharedPointer new_value) { // Remember old value for rollback *old_value = counter; @@ -165,7 +165,7 @@ The \ref agentxcpp::Variable::cleanupset "cleanupset()" method releases old_value again: \code - virtual void cleanupset(shared_ptr new_value) + virtual void cleanupset(QSharedPointer new_value) { // Release old value delete old_value; @@ -188,7 +188,7 @@ reported to the master agent if it is missing. For simpleCounter implementation is easy: \code - virtual bool undoset(shared_ptr new_value) + virtual bool undoset(QSharedPointer new_value) { // Restore old value counter = *old_value; diff --git a/doc/how_to_send_notifications.dox b/doc/how_to_send_notifications.dox index 6768abb..3596352 100644 --- a/doc/how_to_send_notifications.dox +++ b/doc/how_to_send_notifications.dox @@ -103,12 +103,12 @@ class NotificationSender : public QObject private: MasterProxy* master; OidValue simpleCounter_oid; - shared_ptr counter; + QSharedPointer counter; public: NotificationSender(MasterProxy* _master, OidValue _oid, - shared_ptr _counter) + QSharedPointer _counter) : master(_master), simpleCounter_oid(_oid), counter(_counter) { } @@ -119,7 +119,7 @@ class NotificationSender : public QObject std::cout << "notification!" << std::endl; std::vector objects; - shared_ptr counter_value(new IntegerValue(counter->value())); + QSharedPointer counter_value(new IntegerValue(counter->value())); objects.push_back(varbind(simpleCounter_oid, counter_value)); QMetaObject::invokeMethod(master, "send_notification", @@ -176,7 +176,7 @@ int main(int argc, char** argv) OidValue simpleagent_oid = OidValue(enterprises_oid, "42.1"); master.register_subtree(simpleagent_oid); - boost::shared_ptr counter(new SimpleCounter); + QSharedPointer counter(new SimpleCounter); OidValue simpleCounter_oid(simpleagent_oid, "0"); master.add_variable(simpleCounter_oid, counter); diff --git a/doc/how_to_write_a_subagent.dox b/doc/how_to_write_a_subagent.dox index 42792db..8c3f28b 100644 --- a/doc/how_to_write_a_subagent.dox +++ b/doc/how_to_write_a_subagent.dox @@ -213,7 +213,7 @@ and an additional string with further subids. Next, we create a SimpleCounter variable and register it with agentXcpp: \code - boost::shared_ptr counter(new SimpleCounter); + QSharedPointer counter(new SimpleCounter); OidValue simpleCounter_oid(simpleagent_oid, "0"); diff --git a/src/AbstractVariable.hpp b/src/AbstractVariable.hpp index 2354c7e..f9e069b 100644 --- a/src/AbstractVariable.hpp +++ b/src/AbstractVariable.hpp @@ -19,12 +19,10 @@ #ifndef _VARIABLE_H_ #define _VARIABLE_H_ -#include +#include #include "AbstractValue.hpp" -using boost::shared_ptr; - namespace agentxcpp { /** @@ -57,7 +55,7 @@ namespace agentxcpp * \exception generic_error If obtaining the current value fails. * No other exception shall be thrown. */ - virtual shared_ptr handle_get() = 0; + virtual QSharedPointer handle_get() = 0; /** @@ -166,7 +164,7 @@ namespace agentxcpp * * \return The result of the validation. */ - virtual testset_result_t handle_testset(shared_ptr) = 0; + virtual testset_result_t handle_testset(QSharedPointer) = 0; /** * \brief Release resources after a Set operation. diff --git a/src/MasterProxy.cpp b/src/MasterProxy.cpp index a6b3123..8ac0ce3 100644 --- a/src/MasterProxy.cpp +++ b/src/MasterProxy.cpp @@ -31,7 +31,6 @@ using namespace std; using namespace agentxcpp; -using namespace boost; // Beside other things, this pulls boost::quint16 @@ -97,12 +96,12 @@ void MasterProxy::connect() this->connection->connect(); // The response we expect from the master - boost::shared_ptr response; + QSharedPointer response; try { // Send OpenPDU - boost::shared_ptr openpdu(new OpenPDU); + QSharedPointer openpdu(new OpenPDU); openpdu->set_timeout(default_timeout); openpdu->set_id(id); // throws disconnected and timeout_error: @@ -133,9 +132,9 @@ void MasterProxy::connect() this->sessionID = response->get_sessionID(); QObject::connect(connection, - SIGNAL(pduArrived(shared_ptr)), + SIGNAL(pduArrived(QSharedPointer)), this, - SLOT(handle_pdu(shared_ptr))); + SLOT(handle_pdu(QSharedPointer))); } @@ -154,13 +153,13 @@ void MasterProxy::disconnect(ClosePDU::reason_t reason) // sysORID are removed. Thus no need to clean up before ClosePDU is sent. // The response we expect from the master - boost::shared_ptr response; + QSharedPointer response; // Try clean shutdown (ignore errors) try { // Unregister stuff if any - std::list< boost::shared_ptr >::const_iterator r; + std::list< QSharedPointer >::const_iterator r; r = this->registrations.begin(); while (r != this->registrations.end()) { @@ -169,7 +168,7 @@ void MasterProxy::disconnect(ClosePDU::reason_t reason) } // Send ClosePDU - boost::shared_ptr closepdu(new ClosePDU(this->sessionID, reason)); + QSharedPointer closepdu(new ClosePDU(this->sessionID, reason)); // throws disconnected and timeout_error: response = this->connection->request(closepdu); @@ -206,7 +205,7 @@ MasterProxy::~MasterProxy() } -void MasterProxy::do_registration(boost::shared_ptr pdu) +void MasterProxy::do_registration(QSharedPointer pdu) { // Are we connected? // if( ! is_connected()) @@ -216,7 +215,7 @@ void MasterProxy::do_registration(boost::shared_ptr pdu) // Send RegisterPDU // (forward exceptions timeout_error and disconnected) - boost::shared_ptr response; + QSharedPointer response; response = this->connection->request(pdu); // // Wait for response @@ -279,7 +278,7 @@ void MasterProxy::register_subtree(OidValue subtree, quint8 timeout) { // Build PDU - boost::shared_ptr pdu(new RegisterPDU); + QSharedPointer pdu(new RegisterPDU); pdu->set_subtree(subtree); pdu->set_priority(priority); pdu->set_timeout(timeout); @@ -313,10 +312,10 @@ void MasterProxy::unregister_subtree(OidValue subtree, quint8 priority) { // The UnregisterPDU - boost::shared_ptr pdu; + QSharedPointer pdu; // Remove the registration from registrations list - std::list< boost::shared_ptr >::iterator r; + std::list< QSharedPointer >::iterator r; r = this->registrations.begin(); while (r != this->registrations.end()) { @@ -360,7 +359,7 @@ void MasterProxy::unregister_subtree(OidValue subtree, -void MasterProxy::undo_registration(boost::shared_ptr pdu) +void MasterProxy::undo_registration(QSharedPointer pdu) { // Are we connected? // if( ! is_connected()) @@ -370,12 +369,12 @@ void MasterProxy::undo_registration(boost::shared_ptr pdu) // Send UnregisterPDU // (forward exceptions timeout_error and disconnected) - boost::shared_ptr response; + QSharedPointer response; response = this->connection->request(pdu); // // Wait for response // // (forward exceptions timeout_error and disconnected) -// boost::shared_ptr response; +// QSharedPointer response; // response = this->connection->wait_for_response(pdu->get_packetID()); // Check Response @@ -424,10 +423,10 @@ void MasterProxy::undo_registration(boost::shared_ptr pdu) -boost::shared_ptr MasterProxy::create_unregister_pdu( - boost::shared_ptr pdu) +QSharedPointer MasterProxy::create_unregister_pdu( + QSharedPointer pdu) { - boost::shared_ptr new_pdu(new UnregisterPDU()); + QSharedPointer new_pdu(new UnregisterPDU()); new_pdu->set_subtree( pdu->get_subtree() ); new_pdu->set_range_subid( pdu->get_range_subid() ); new_pdu->set_upper_bound( pdu->get_upper_bound() ); @@ -437,7 +436,7 @@ boost::shared_ptr MasterProxy::create_unregister_pdu( } -void MasterProxy::handle_getpdu(shared_ptr response, shared_ptr get_pdu) +void MasterProxy::handle_getpdu(QSharedPointer response, QSharedPointer get_pdu) { // Handling according to // RFC 2741, 7.2.3.1 "Subagent Processing of the agentx-Get-PDU" @@ -455,7 +454,7 @@ void MasterProxy::handle_getpdu(shared_ptr response, shared_ptr >::const_iterator var; + map< OidValue, QSharedPointer >::const_iterator var; var = variables.find(name); if(var != variables.end()) { @@ -506,7 +505,7 @@ void MasterProxy::handle_getpdu(shared_ptr response, shared_ptr response, shared_ptr getnext_pdu) +void MasterProxy::handle_getnextpdu(QSharedPointer response, QSharedPointer getnext_pdu) { // Handling according to // RFC 2741, 7.2.3.2 "Subagent Processing of the agentx-GetNext-PDU" @@ -525,7 +524,7 @@ void MasterProxy::handle_getnextpdu(shared_ptr response, shared_ptr const OidValue& ending_oid = i->second; // Find "next" variable - map< OidValue, shared_ptr >::const_iterator next_var; + map< OidValue, QSharedPointer >::const_iterator next_var; if( ! starting_oid.get_include()) { // Find the closest lexicographical successor to the starting @@ -581,7 +580,7 @@ void MasterProxy::handle_getnextpdu(shared_ptr response, shared_ptr -void MasterProxy::handle_testsetpdu(boost::shared_ptr response, shared_ptr testset_pdu) +void MasterProxy::handle_testsetpdu(QSharedPointer response, QSharedPointer testset_pdu) { // Handling according to // RFC 2741, 7.2.4.1 "Subagent Processing of the agentx-TestSet-PDU" @@ -599,7 +598,7 @@ void MasterProxy::handle_testsetpdu(boost::shared_ptr response, sha for(i = vb.begin(), index = 1; i != vb.end(); i++, index++) { // Find the associated variable - map< OidValue, shared_ptr >::const_iterator var; + map< OidValue, QSharedPointer >::const_iterator var; var = variables.find(i->get_name()); if(var == variables.end()) { @@ -648,7 +647,7 @@ void MasterProxy::handle_cleanupsetpdu() // Iterate over list and handle each Varbind separately. We iterate // backwards, so that resources are released in the reverse order of their // allocation. - list< shared_ptr >::const_reverse_iterator i; + list< QSharedPointer >::const_reverse_iterator i; for(i = setlist.rbegin(); i != setlist.rend(); i++) { (*i)->handle_cleanupset(); @@ -658,13 +657,13 @@ void MasterProxy::handle_cleanupsetpdu() setlist.clear(); } -void MasterProxy::handle_commitsetpdu(boost::shared_ptr response, shared_ptr commitset_pdu) +void MasterProxy::handle_commitsetpdu(QSharedPointer response, QSharedPointer commitset_pdu) { // Handling according to RFC 2741, 7.2.4.2 "Subagent Processing of the // agentx-CommitSet-PDU" // Iterate over list and handle each Varbind separately. - list< shared_ptr >::iterator i; + list< QSharedPointer >::iterator i; quint16 index = 1; // Index is 1-based (RFC 2741, 5.4. "Value Representation") for(i = setlist.begin(); i != setlist.end(); i++) { @@ -686,7 +685,7 @@ void MasterProxy::handle_commitsetpdu(boost::shared_ptr response, s } -void MasterProxy::handle_undosetpdu(boost::shared_ptr response, shared_ptr undoset_pdu) +void MasterProxy::handle_undosetpdu(QSharedPointer response, QSharedPointer undoset_pdu) { // Handling according to RFC 2741, 7.2.4.3 "Subagent Processing of the // agentx-UndoSet-PDU" @@ -694,7 +693,7 @@ void MasterProxy::handle_undosetpdu(boost::shared_ptr response, sha bool failed = false; // Iterate over list and handle each Varbind separately. - list< shared_ptr >::iterator i; + list< QSharedPointer >::iterator i; quint16 index = 1; // Index is 1-based (RFC 2741, 5.4. "Value Representation") for(i = setlist.begin(); i != setlist.end(); i++) { @@ -725,7 +724,7 @@ void MasterProxy::handle_undosetpdu(boost::shared_ptr response, sha } -void MasterProxy::handle_pdu(shared_ptr pdu) +void MasterProxy::handle_pdu(QSharedPointer pdu) { int error = 0; // 0 is "success" if(error == -2) @@ -761,7 +760,7 @@ void MasterProxy::handle_pdu(shared_ptr pdu) // - The flags are not copied, because they have // other meanings in ResponsePDU's. // - TODO: Context is not yet supported. - shared_ptr response(new ResponsePDU); + QSharedPointer response(new ResponsePDU); response->set_sessionID( pdu->get_sessionID() ); response->set_transactionID( pdu->get_transactionID() ); response->set_packetID( pdu->get_packetID() ); @@ -778,7 +777,7 @@ void MasterProxy::handle_pdu(shared_ptr pdu) { // this->connection->send(response); connection->send(response); - //QMetaObject::invokeMethod(connection, "do_send", Q_ARG(boost::shared_ptr, response)); + //QMetaObject::invokeMethod(connection, "do_send", Q_ARG(QSharedPointer, response)); } catch(timeout_error) { /* connection loss. Ignore.*/ } catch(disconnected) { /* connection loss. Ignore.*/ } @@ -791,32 +790,32 @@ void MasterProxy::handle_pdu(shared_ptr pdu) // // Is it a GetPDU? - shared_ptr get_pdu; - if( (get_pdu = dynamic_pointer_cast(pdu)) != 0 ) + QSharedPointer get_pdu; + if( (get_pdu = qSharedPointerDynamicCast(pdu)) != 0 ) { // (response is modified in-place) this->handle_getpdu(response, get_pdu); } // Is it a GetNextPDU? - shared_ptr getnext_pdu; - if( (getnext_pdu = dynamic_pointer_cast(pdu)) != 0 ) + QSharedPointer getnext_pdu; + if( (getnext_pdu = qSharedPointerDynamicCast(pdu)) != 0 ) { // (response is modified in-place) this->handle_getnextpdu(response, getnext_pdu); } // Is it a TestSetPDU? - shared_ptr testset_pdu; - if( (testset_pdu = dynamic_pointer_cast(pdu)) != 0 ) + QSharedPointer testset_pdu; + if( (testset_pdu = qSharedPointerDynamicCast(pdu)) != 0 ) { // (response is modified in-place) this->handle_testsetpdu(response, testset_pdu); } // Is it a CleanupSetPDU? - shared_ptr cleanupset_pdu; - if( (cleanupset_pdu = dynamic_pointer_cast(pdu)) != 0 ) + QSharedPointer cleanupset_pdu; + if( (cleanupset_pdu = qSharedPointerDynamicCast(pdu)) != 0 ) { this->handle_cleanupsetpdu(); @@ -825,16 +824,16 @@ void MasterProxy::handle_pdu(shared_ptr pdu) } // Is it a CommitSetPDU? - shared_ptr commitset_pdu; - if( (commitset_pdu = dynamic_pointer_cast(pdu)) != 0 ) + QSharedPointer commitset_pdu; + if( (commitset_pdu = qSharedPointerDynamicCast(pdu)) != 0 ) { // (response is modified in-place) this->handle_commitsetpdu(response, commitset_pdu); } // Is it an UndoSetPDU? - shared_ptr undoset_pdu; - if( (undoset_pdu = dynamic_pointer_cast(pdu)) != 0 ) + QSharedPointer undoset_pdu; + if( (undoset_pdu = qSharedPointerDynamicCast(pdu)) != 0 ) { // (response is modified in-place) this->handle_undosetpdu(response, undoset_pdu); @@ -846,7 +845,7 @@ void MasterProxy::handle_pdu(shared_ptr pdu) try { connection->send(response); - //QMetaObject::invokeMethod(connection, "do_send", Q_ARG(boost::shared_ptr, response)); + //QMetaObject::invokeMethod(connection, "do_send", Q_ARG(QSharedPointer, response)); //this->connection->send(response); } catch(timeout_error) { /* connection loss. Ignore.*/ } @@ -854,11 +853,11 @@ void MasterProxy::handle_pdu(shared_ptr pdu) } -void MasterProxy::add_variable(const OidValue& id, shared_ptr v) +void MasterProxy::add_variable(const OidValue& id, QSharedPointer v) { // Check whether id is contained in a registration bool is_registered = false; - std::list< boost::shared_ptr >::const_iterator r; + std::list< QSharedPointer >::const_iterator r; for(r = registrations.begin(); r != registrations.end(); r++) { if((*r)->get_instance_registration() == false && @@ -888,7 +887,7 @@ void MasterProxy::add_variable(const OidValue& id, shared_ptr void MasterProxy::remove_variable(const OidValue& id) { // Find variable - map >::iterator i = variables.find(id); + map >::iterator i = variables.find(id); if(i == variables.end()) { @@ -907,7 +906,7 @@ void MasterProxy::send_notification(const OidValue& snmpTrapOID, const TimeTicksValue* sysUpTime, const vector& varbinds) { - shared_ptr pdu(new NotifyPDU); + QSharedPointer pdu(new NotifyPDU); pdu->set_sessionID(this->sessionID); vector& vb = pdu->get_vb(); @@ -915,12 +914,12 @@ void MasterProxy::send_notification(const OidValue& snmpTrapOID, // First of all: add mandatory sysUpTime (if given) if(sysUpTime) { - shared_ptr value(new TimeTicksValue(*sysUpTime)); + QSharedPointer value(new TimeTicksValue(*sysUpTime)); vb.push_back(varbind(OidValue(sysUpTime_oid, "0"), value)); } // Second: add mandatory snmpTrapOID - shared_ptr trapoid(new OidValue(snmpTrapOID)); + QSharedPointer trapoid(new OidValue(snmpTrapOID)); vb.push_back(varbind(OidValue(snmpTrapOID_oid, "0"), trapoid)); // Append given varbinds @@ -928,12 +927,12 @@ void MasterProxy::send_notification(const OidValue& snmpTrapOID, // Send notification // Note: timeout_error and disconnected exceptions are forwarded. - shared_ptr response; + QSharedPointer response; response = connection->request(pdu); // // Wait for response // // Note: timeout_error and disconnected exceptions are forwarded. -// shared_ptr response; +// QSharedPointer response; // response = connection->wait_for_response(pdu.get_packetID()); // Handle response diff --git a/src/MasterProxy.hpp b/src/MasterProxy.hpp index a43c50f..89736d0 100644 --- a/src/MasterProxy.hpp +++ b/src/MasterProxy.hpp @@ -23,7 +23,7 @@ #include #include -#include +#include #include #include @@ -159,7 +159,7 @@ namespace agentxcpp * \internal * * The variables are stored in the member variables, which is a - * std::map >. The key is the OID for which the + * std::map >. The key is the OID for which the * variable was added. This allows easy lookup for the request * dispatcher. * @@ -249,12 +249,12 @@ namespace agentxcpp * stored in this list. This allows to automatically re-register * these subtrees on reconnect. */ - std::list< boost::shared_ptr > registrations; + std::list< QSharedPointer > registrations; /** * \brief Storage for all SNMP variables known to the MasterProxy. */ - std::map< OidValue, shared_ptr > variables; + std::map< OidValue, QSharedPointer > variables; /** * \brief The variables affected by the Set operation currently @@ -266,7 +266,7 @@ namespace agentxcpp * * These are the variables denominated in that TestSet PDU. */ - std::list< shared_ptr > setlist; + std::list< QSharedPointer > setlist; /** * \brief Send a RegisterPDU to the master agent. @@ -308,7 +308,7 @@ namespace agentxcpp * registration and that a retry will result * in a duplicate_registration error. */ - void do_registration(boost::shared_ptr pdu); + void do_registration(QSharedPointer pdu); /** * \brief Send a UnregisterPDU to the master agent. @@ -345,7 +345,7 @@ namespace agentxcpp * registration and that a retry will result * in a duplicate_registration error. */ - void undo_registration(boost::shared_ptr pdu); + void undo_registration(QSharedPointer pdu); /** * \brief Create UnregisterPDU for undoing a registration. @@ -359,8 +359,8 @@ namespace agentxcpp * * \exception None. */ - boost::shared_ptr create_unregister_pdu( - boost::shared_ptr pdu); + QSharedPointer create_unregister_pdu( + QSharedPointer pdu); /** * \brief Handle incoming GetPDU's. @@ -374,7 +374,7 @@ namespace agentxcpp * * \param get_pdu The GetPDU to be processed. */ - void handle_getpdu(shared_ptr response, shared_ptr get_pdu); + void handle_getpdu(QSharedPointer response, QSharedPointer get_pdu); /** * \brief Handle incoming GetNextPDU's. @@ -388,7 +388,7 @@ namespace agentxcpp * * \param getnext_pdu The GetNextPDU to be processed. */ - void handle_getnextpdu(shared_ptr response, shared_ptr getnext_pdu); + void handle_getnextpdu(QSharedPointer response, QSharedPointer getnext_pdu); /** * \brief Handle incoming TestSetPDU's. @@ -400,7 +400,7 @@ namespace agentxcpp * * \param testset_pdu The TestSetPDU to be processed. */ - void handle_testsetpdu(boost::shared_ptr response, shared_ptr testset_pdu); + void handle_testsetpdu(QSharedPointer response, QSharedPointer testset_pdu); /** * \brief Handle incoming CleanupSetPDU's. @@ -420,7 +420,7 @@ namespace agentxcpp * * \param commitset_pdu The CommitSetPDU to be processed. */ - void handle_commitsetpdu(boost::shared_ptr response, shared_ptr commitset_pdu); + void handle_commitsetpdu(QSharedPointer response, QSharedPointer commitset_pdu); /** * \brief Handle incoming UndoSetPDU's. @@ -432,7 +432,7 @@ namespace agentxcpp * * \param undoset_pdu The UndoSetPDU to be processed. */ - void handle_undosetpdu(boost::shared_ptr response, shared_ptr undoset_pdu); + void handle_undosetpdu(QSharedPointer response, QSharedPointer undoset_pdu); public slots: /** @@ -450,7 +450,7 @@ namespace agentxcpp * given to the specialized methods to add their results. Finally * handle_pdu() sends the response. */ - virtual void handle_pdu(shared_ptr); + virtual void handle_pdu(QSharedPointer); /** * \brief Send a notification or trap. @@ -758,7 +758,7 @@ namespace agentxcpp * within a registered MIB * region. */ - void add_variable(const OidValue& id, shared_ptr v); + void add_variable(const OidValue& id, QSharedPointer v); /** * \brief Remove an SNMP variable so that is not longer accessible. diff --git a/src/PDU.cpp b/src/PDU.cpp index df0687b..fe0e510 100644 --- a/src/PDU.cpp +++ b/src/PDU.cpp @@ -39,7 +39,6 @@ #include "util.hpp" using namespace agentxcpp; -using boost::shared_ptr; quint32 PDU::packetID_cnt = 0; @@ -99,7 +98,7 @@ PDU::PDU(binary::const_iterator& pos, -shared_ptr PDU::parse_pdu(binary buf) +QSharedPointer PDU::parse_pdu(binary buf) { // needed for parsing binary::const_iterator pos; @@ -133,49 +132,49 @@ shared_ptr PDU::parse_pdu(binary buf) quint8 type = buf[1]; // create PDU (TODO: complete the list!) - shared_ptr pdu; + QSharedPointer pdu; pos = buf.begin(); const binary::const_iterator end = buf.end(); switch(type) { case agentxOpenPDU: - pdu.reset(new OpenPDU(pos, end, big_endian)); + pdu = QSharedPointer(new OpenPDU(pos, end, big_endian)); break; case agentxClosePDU: - pdu.reset(new ClosePDU(pos, end, big_endian)); + pdu = QSharedPointer(new ClosePDU(pos, end, big_endian)); break; case agentxRegisterPDU: - pdu.reset(new RegisterPDU(pos, end, big_endian)); + pdu = QSharedPointer(new RegisterPDU(pos, end, big_endian)); break; case agentxUnregisterPDU: - pdu.reset(new UnregisterPDU(pos, end, big_endian)); + pdu = QSharedPointer(new UnregisterPDU(pos, end, big_endian)); break; case agentxResponsePDU: - pdu.reset(new ResponsePDU(pos, end, big_endian)); + pdu = QSharedPointer(new ResponsePDU(pos, end, big_endian)); break; case agentxCommitSetPDU: - pdu.reset(new CommitSetPDU(pos, end, big_endian)); + pdu = QSharedPointer(new CommitSetPDU(pos, end, big_endian)); break; case agentxUndoSetPDU: - pdu.reset(new UndoSetPDU(pos, end, big_endian)); + pdu = QSharedPointer(new UndoSetPDU(pos, end, big_endian)); break; case agentxTestSetPDU: - pdu.reset(new TestSetPDU(pos, end, big_endian)); + pdu = QSharedPointer(new TestSetPDU(pos, end, big_endian)); break; case agentxCleanupSetPDU: - pdu.reset(new CleanupSetPDU(pos, end, big_endian)); + pdu = QSharedPointer(new CleanupSetPDU(pos, end, big_endian)); break; case agentxGetPDU: - pdu.reset(new GetPDU(pos, end, big_endian)); + pdu = QSharedPointer(new GetPDU(pos, end, big_endian)); break; case agentxGetNextPDU: - pdu.reset(new GetNextPDU(pos, end, big_endian)); + pdu = QSharedPointer(new GetNextPDU(pos, end, big_endian)); break; case agentxGetBulkPDU: - pdu.reset(new GetBulkPDU(pos, end, big_endian)); + pdu = QSharedPointer(new GetBulkPDU(pos, end, big_endian)); break; case agentxNotifyPDU: - pdu.reset(new NotifyPDU(pos, end, big_endian)); + pdu = QSharedPointer(new NotifyPDU(pos, end, big_endian)); break; default: // type is invalid diff --git a/src/PDU.hpp b/src/PDU.hpp index 9a4402f..ae79d25 100644 --- a/src/PDU.hpp +++ b/src/PDU.hpp @@ -22,15 +22,13 @@ #include -#include +#include #include #include "exceptions.hpp" #include "binary.hpp" -using boost::shared_ptr; - namespace agentxcpp { /** @@ -219,14 +217,13 @@ namespace agentxcpp */ PDU(); + public: /** * \brief Destructor. */ virtual ~PDU() - { - } - - public: + { + } /** * \brief Get new_index flag @@ -290,7 +287,7 @@ namespace agentxcpp * \exception version_mismatch If the AgentX version of the %PDU * is not 1. */ - static shared_ptr parse_pdu(binary buf); + static QSharedPointer parse_pdu(binary buf); /** * \brief Serialize function for concrete PDUs. diff --git a/src/RegisterPDU.hpp b/src/RegisterPDU.hpp index f262168..310b6e0 100644 --- a/src/RegisterPDU.hpp +++ b/src/RegisterPDU.hpp @@ -19,7 +19,7 @@ #ifndef _REGISTERPDU_H_ #define _REGISTERPDU_H_ -#include +#include #include "OidValue.hpp" #include "PDUwithContext.hpp" diff --git a/src/UnixDomainConnector.cpp b/src/UnixDomainConnector.cpp index 9dcc632..ba589e2 100644 --- a/src/UnixDomainConnector.cpp +++ b/src/UnixDomainConnector.cpp @@ -41,8 +41,8 @@ UnixDomainConnector::UnixDomainConnector( m_is_connected(false) { // We want to deliver this types within a signal: - qRegisterMetaType< boost::shared_ptr >("boost::shared_ptr"); - qRegisterMetaType< boost::shared_ptr >("shared_ptr"); + qRegisterMetaType< QSharedPointer >("QSharedPointer"); + qRegisterMetaType< QSharedPointer >("QSharedPointer"); QObject::connect(&m_socket, SIGNAL(readyRead()), this, SLOT(do_receive())); } @@ -227,7 +227,7 @@ void UnixDomainConnector::do_receive() for(list::const_iterator i = queue.begin(); i != queue.end(); i++) { // Parse PDU - shared_ptr pdu; + QSharedPointer pdu; try { pdu = PDU::parse_pdu(*i); @@ -242,13 +242,13 @@ void UnixDomainConnector::do_receive() } // Special case: ResponsePDU's - shared_ptr response; - response = boost::dynamic_pointer_cast(pdu); + QSharedPointer response; + response = qSharedPointerDynamicCast(pdu); if(response) { m_response_mutex.lock(); // Was a response - std::map< quint32, boost::shared_ptr >::iterator i; + std::map< quint32, QSharedPointer >::iterator i; i = this->m_responses.find( response->get_packetID() ); if(i != this->m_responses.end()) { @@ -273,21 +273,21 @@ void UnixDomainConnector::do_receive() } } -boost::shared_ptr UnixDomainConnector::request(boost::shared_ptr pdu) +QSharedPointer UnixDomainConnector::request(QSharedPointer pdu) { m_response_mutex.lock(); - m_responses[pdu->get_packetID()] = shared_ptr(); - QMetaObject::invokeMethod(this, "do_send", Q_ARG(boost::shared_ptr, pdu)); + m_responses[pdu->get_packetID()] = QSharedPointer(); + QMetaObject::invokeMethod(this, "do_send", Q_ARG(QSharedPointer, pdu)); - std::map >::iterator i; - m_responses[pdu->get_packetID()] = shared_ptr(); + std::map >::iterator i; + m_responses[pdu->get_packetID()] = QSharedPointer(); do { m_response_arrived.wait(&m_response_mutex); } while ( ! (m_responses[pdu->get_packetID()]) ); - shared_ptr response = m_responses[pdu->get_packetID()]; + QSharedPointer response = m_responses[pdu->get_packetID()]; m_responses.erase(m_responses.find(pdu->get_packetID())); m_response_mutex.unlock(); @@ -296,7 +296,7 @@ boost::shared_ptr UnixDomainConnector::request(boost::shared_ptr pdu) +void UnixDomainConnector::do_send(QSharedPointer pdu) { binary data = pdu->serialize(); @@ -305,8 +305,8 @@ void UnixDomainConnector::do_send(boost::shared_ptr pdu) } -void UnixDomainConnector::send(boost::shared_ptr pdu) +void UnixDomainConnector::send(QSharedPointer pdu) { // Start do_disconnect() - QMetaObject::invokeMethod(this, "do_send", Q_ARG(boost::shared_ptr, pdu)); + QMetaObject::invokeMethod(this, "do_send", Q_ARG(QSharedPointer, pdu)); } diff --git a/src/UnixDomainConnector.hpp b/src/UnixDomainConnector.hpp index ce47bfc..2583a13 100644 --- a/src/UnixDomainConnector.hpp +++ b/src/UnixDomainConnector.hpp @@ -21,7 +21,7 @@ #include -#include +#include #include #include @@ -167,7 +167,7 @@ namespace agentxcpp * * This member is protected by m_response_mutex. */ - std::map< quint32, boost::shared_ptr > m_responses; + std::map< quint32, QSharedPointer > m_responses; /** * \brief Used to protect m_responses and for m_response_arrived. @@ -213,7 +213,7 @@ namespace agentxcpp * * \note Don't invoke this slot from outside the object! */ - void do_send(boost::shared_ptr pdu); + void do_send(QSharedPointer pdu); /** * \brief Connect to the remote entity. @@ -264,7 +264,7 @@ namespace agentxcpp * This signal is emitted once for every arrived PDU, except for * %ResponsePDU's. */ - void pduArrived(shared_ptr); + void pduArrived(QSharedPointer); public: /** @@ -339,7 +339,7 @@ namespace agentxcpp * * \note Don't invoke do_send() yourself. */ - void send(boost::shared_ptr pdu); + void send(QSharedPointer pdu); /** * \brief Send a PDU and wait for the response. @@ -351,7 +351,7 @@ namespace agentxcpp * * \todo Add timeout. Currently, the method does not time out. */ - boost::shared_ptr request(boost::shared_ptr pdu); + QSharedPointer request(QSharedPointer pdu); }; diff --git a/src/Variable.hpp b/src/Variable.hpp index 3503476..132e7df 100644 --- a/src/Variable.hpp +++ b/src/Variable.hpp @@ -19,7 +19,7 @@ #ifndef _PRIMITIVE_VARIABLE_H_ #define _PRIMITIVE_VARIABLE_H_ -#include +#include #include "AbstractVariable.hpp" @@ -72,9 +72,9 @@ namespace agentxcpp * Example: * * \code - * virtual testset_result_t handle_testset(shared_ptr v) + * virtual testset_result_t handle_testset(QSharedPointer v) * { - * shared_ptr new_value = boost::dynamic_pointer_cast(v); + * QSharedPointer new_value = qSharedPointerDynamicCast(v); * * if (new_value) * { @@ -109,7 +109,7 @@ namespace agentxcpp * receives the new value. This value is stored here so that it can * be delivered to commitset(), undoset() and cleanupset(). */ - shared_ptr new_value; + QSharedPointer new_value; public: @@ -119,13 +119,13 @@ namespace agentxcpp * \brief Handle a Get Request. * * This function calls this->get() to obtain the new value, - * converts it to shared_ptr and returns it. + * converts it to QSharedPointer and returns it. */ - virtual shared_ptr handle_get() + virtual QSharedPointer handle_get() { // Get new value by calling this->get(), then allocate a new // variable, initializing it with the new value: - shared_ptr retval( new T(this->get()) ); + QSharedPointer retval( new T(this->get()) ); return retval; } @@ -149,7 +149,7 @@ namespace agentxcpp * * \brief Handle a TestSet request. * - * This function converts the argument to shared_ptr() and calls + * This function converts the argument to QSharedPointer() and calls * testset() with the converted value. If conversion fails, * testset() is not called. This function also stores the given * value to the new_value member. @@ -159,9 +159,9 @@ namespace agentxcpp * \return wrongType if the conversion fails. Otherwise, the * result of testset() is returned. */ - virtual testset_result_t handle_testset(shared_ptr v) + virtual testset_result_t handle_testset(QSharedPointer v) { - new_value = boost::dynamic_pointer_cast(v); + new_value = qSharedPointerDynamicCast(v); if (new_value) { // Type matches variable @@ -191,7 +191,7 @@ namespace agentxcpp * * \return The result of the check. */ - virtual testset_result_t testset(shared_ptr v) + virtual testset_result_t testset(QSharedPointer v) { return noAccess; } @@ -221,7 +221,7 @@ namespace agentxcpp * * \param v The new value for the object. */ - virtual void cleanupset(shared_ptr v) + virtual void cleanupset(QSharedPointer v) { return; } @@ -253,7 +253,7 @@ namespace agentxcpp * * \return True if the operation succeeded, false otherwise. */ - virtual bool commitset(shared_ptr v) + virtual bool commitset(QSharedPointer v) { return false; } @@ -294,7 +294,7 @@ namespace agentxcpp * * \return True on success, false otherwise. */ - virtual bool undoset(shared_ptr v) + virtual bool undoset(QSharedPointer v) { return false; } diff --git a/src/varbind.cpp b/src/varbind.cpp index ab76a68..c9c54e1 100644 --- a/src/varbind.cpp +++ b/src/varbind.cpp @@ -47,27 +47,27 @@ binary varbind::serialize() const serialized += name.serialize(); // encode data if needed - if (var.get()) serialized += var->serialize(); + if (var) serialized += var->serialize(); return serialized; } -varbind::varbind(const OidValue& o, boost::shared_ptr v) +varbind::varbind(const OidValue& o, QSharedPointer v) { name = o; var = v; // Determine type of variable and fill type field. - if( dynamic_cast(var.get()) ) type = 2; - else if( dynamic_cast(var.get()) ) type = 4; - else if( dynamic_cast(var.get()) ) type = 6; - else if( dynamic_cast(var.get()) ) type = 64; - else if( dynamic_cast(var.get()) ) type = 65; - else if( dynamic_cast(var.get()) ) type = 66; - else if( dynamic_cast(var.get()) ) type = 67; - else if( dynamic_cast(var.get()) ) type = 68; - else if( dynamic_cast(var.get()) ) type = 70; + if( qSharedPointerDynamicCast(var) ) type = 2; + else if( qSharedPointerDynamicCast(var) ) type = 4; + else if( qSharedPointerDynamicCast(var) ) type = 6; + else if( qSharedPointerDynamicCast(var) ) type = 64; + else if( qSharedPointerDynamicCast(var) ) type = 65; + else if( qSharedPointerDynamicCast(var) ) type = 66; + else if( qSharedPointerDynamicCast(var) ) type = 67; + else if( qSharedPointerDynamicCast(var) ) type = 68; + else if( qSharedPointerDynamicCast(var) ) type = 70; else { // Type could not be determined -> invalid parameter. @@ -121,37 +121,37 @@ varbind::varbind(binary::const_iterator& pos, switch(type) { case 2: - var.reset(new IntegerValue(pos, end, big_endian)); + var = QSharedPointer(new IntegerValue(pos, end, big_endian)); break; case 4: - var.reset(new OctetStringValue(pos, end, big_endian)); + var = QSharedPointer(new OctetStringValue(pos, end, big_endian)); break; case 6: - var.reset(new OidValue(pos, end, big_endian)); + var = QSharedPointer(new OidValue(pos, end, big_endian)); break; case 64: - var.reset(new IpAddressValue(pos, end, big_endian)); + var = QSharedPointer(new IpAddressValue(pos, end, big_endian)); break; case 65: - var.reset(new Counter32Value(pos, end, big_endian)); + var = QSharedPointer(new Counter32Value(pos, end, big_endian)); break; case 66: - var.reset(new Gauge32Value(pos, end, big_endian)); + var = QSharedPointer(new Gauge32Value(pos, end, big_endian)); break; case 67: - var.reset(new TimeTicksValue(pos, end, big_endian)); + var = QSharedPointer(new TimeTicksValue(pos, end, big_endian)); break; case 68: - var.reset(new OpaqueValue(pos, end, big_endian)); + var = QSharedPointer(new OpaqueValue(pos, end, big_endian)); break; case 70: - var.reset(new Counter64Value(pos, end, big_endian)); + var = QSharedPointer(new Counter64Value(pos, end, big_endian)); break; case 5: // Null case 128: // noSuchObject case 129: // noSuchInstance case 130: // endOfMibView - var.reset(); + var.clear(); break; default: // invalid type diff --git a/src/varbind.hpp b/src/varbind.hpp index 86f7a7b..45e9e62 100644 --- a/src/varbind.hpp +++ b/src/varbind.hpp @@ -21,7 +21,7 @@ #include -#include +#include #include #include "OidValue.hpp" @@ -48,7 +48,7 @@ namespace agentxcpp * This pointer may be 0 if the varbind has a type without a * variable (e.g. "NoSuchObject"). */ - boost::shared_ptr var; + QSharedPointer var; /** * \brief The type of the varbind. @@ -76,7 +76,7 @@ namespace agentxcpp * If the type of the variable cannot be determined, inval_param is * thrown. */ - varbind(const OidValue&, boost::shared_ptr v); + varbind(const OidValue&, QSharedPointer v); /** * \brief These values can be used to create a VarBind. @@ -139,7 +139,7 @@ namespace agentxcpp * \note This returns a smart pointer to the variable, i.e. the * variable can be modified in-place. */ - boost::shared_ptr get_var() const + QSharedPointer get_var() const { return var; } From 5c3e06180f05a1e0d83943b92237b5811e9cc8e0 Mon Sep 17 00:00:00 2001 From: "Tanjeff-N. Moos" Date: Tue, 7 May 2013 19:18:27 +0200 Subject: [PATCH 16/89] Remove remaining boost stuff, update ChangeLog. --- ChangeLog | 4 ++++ README | 5 ----- SConstruct | 19 +------------------ doc/buildsystem.dox | 1 - doc/how_to_write_a_subagent.dox | 7 +++---- doc/installing.dox | 5 ----- src/Counter64Value.cpp | 2 -- src/PDU.cpp | 3 --- src/varbind.cpp | 1 - unit_tests/main.cpp | 28 ---------------------------- 10 files changed, 8 insertions(+), 67 deletions(-) delete mode 100644 unit_tests/main.cpp diff --git a/ChangeLog b/ChangeLog index 76152bb..5b42983 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ += ? = + + - Remove boost dependencies. + = Version 0.2 = - Implemented GetNext handling. diff --git a/README b/README index 047503a..8e5c7f8 100644 --- a/README +++ b/README @@ -132,11 +132,6 @@ To build agentXcpp, the following is needed: generate diagrams - SCons, to control the build process - The QT4 library -- The following boost libraries: - - Bind - - Smart Ptr - - Test - - Integer Documentation diff --git a/SConstruct b/SConstruct index 5689447..c07ae1d 100644 --- a/SConstruct +++ b/SConstruct @@ -177,22 +177,6 @@ Scons didn't find a usable C++ compiler. Note: For Linux, install a package named 'build-essential' or 'g++'.""" Exit(1) -# Check for boost::bind (header-only lib) -if not conf.CheckHeader('boost/bind.hpp', '<>', 'C++'): - print """ -The boost::bind library is required to build agentXcpp. -Note: For Linux, install a package named 'libboost-dev' or 'boost'.""" - Exit(1) - -# Check for boost::test -if not conf.CheckLibWithHeader('boost_unit_test_framework', - 'boost/test/unit_test.hpp', 'C++', autoadd=0): - print """ -The boost::test library is required to build agentXcpp. -Note: For Linux, install packages named 'libboost-dev' and 'libboost-test-dev' - or a package named 'boost'.""" - Exit(1) - # Check for doxygen executable # Note: we call 'doxygen --version' so no input file is required if not conf.CheckExe(['doxygen', '--version']): @@ -217,6 +201,5 @@ env = conf.Finish() # (export env to them): env.SConscript(['src/SConscript', - 'doc/SConscript', - 'unit_tests/SConscript'], 'env') + 'doc/SConscript'], 'env') diff --git a/doc/buildsystem.dox b/doc/buildsystem.dox index b7c5e47..360965a 100644 --- a/doc/buildsystem.dox +++ b/doc/buildsystem.dox @@ -50,7 +50,6 @@ which are easily available for your system: - Standard build environment (compiler, linker, etc.) - Doxygen, to build the documentation - SCons, to control the build process -- The boost libraries diff --git a/doc/how_to_write_a_subagent.dox b/doc/how_to_write_a_subagent.dox index 8c3f28b..02ddf3f 100644 --- a/doc/how_to_write_a_subagent.dox +++ b/doc/how_to_write_a_subagent.dox @@ -239,10 +239,9 @@ This function blocks forever. \section compiling Compiling the Subagent -When compiling the subagent, we need to link against the boost libraries -'system_error' and 'pthread', the needed Qt libraries and, of course, against -the agentXcpp library. On a GNU/Linux system, you can type the following -command: +When compiling the subagent, we need to link against the needed Qt libraries +and, against the agentXcpp library. On a GNU/Linux system, you can type the +following command: \code g++ simpleagent.cpp -o simpleagent -lagentxcpp \ diff --git a/doc/installing.dox b/doc/installing.dox index 61144a7..523836a 100644 --- a/doc/installing.dox +++ b/doc/installing.dox @@ -36,11 +36,6 @@ which are easily available for your system: - The dot tool from the graphviz package, which is used by doxygen to generate diagrams - SCons, to control the build process -- The following boost libraries: - - Bind - - Smart Ptr - - Test - - Integer - The following QT4 libraries: - QtCore - QNetwork diff --git a/src/Counter64Value.cpp b/src/Counter64Value.cpp index ed68c38..390f642 100644 --- a/src/Counter64Value.cpp +++ b/src/Counter64Value.cpp @@ -17,8 +17,6 @@ * for more details. */ -#include - #include "Counter64Value.hpp" #include "util.hpp" diff --git a/src/PDU.cpp b/src/PDU.cpp index fe0e510..e8e7461 100644 --- a/src/PDU.cpp +++ b/src/PDU.cpp @@ -18,9 +18,6 @@ */ -#include - - #include "PDU.hpp" #include "OpenPDU.hpp" #include "ClosePDU.hpp" diff --git a/src/varbind.cpp b/src/varbind.cpp index c9c54e1..243e21d 100644 --- a/src/varbind.cpp +++ b/src/varbind.cpp @@ -16,7 +16,6 @@ * See the AgentXcpp library license in the LICENSE file of this package * for more details. */ -#include #include "varbind.hpp" #include "OctetStringValue.hpp" diff --git a/unit_tests/main.cpp b/unit_tests/main.cpp deleted file mode 100644 index e1bd814..0000000 --- a/unit_tests/main.cpp +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright 2011-2012 Tanjeff-Nicolai Moos - * - * This file is part of the agentXcpp library. - * - * AgentXcpp is free software: you can redistribute it and/or modify - * it under the terms of the AgentXcpp library license, version 1, which - * consists of the GNU General Public License and some additional - * permissions. - * - * AgentXcpp is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * See the AgentXcpp library license in the LICENSE file of this package - * for more details. - */ - - -// we link the testsuite dynamically -#define BOOST_TEST_DYN_LINK - -// generate a main() function for us -#define BOOST_TEST_MAIN - -// this happens to do all we need :-) -#include From 53f0816578b8ac1240c23517a8c2c12b335cc2e3 Mon Sep 17 00:00:00 2001 From: "Tanjeff-N. Moos" Date: Thu, 9 May 2013 22:11:53 +0200 Subject: [PATCH 17/89] Update docs, which still referenced boost. --- doc/parsing.dox | 56 ++++++++++++++++++++++++------------------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/doc/parsing.dox b/doc/parsing.dox index 9995df2..db02480 100644 --- a/doc/parsing.dox +++ b/doc/parsing.dox @@ -33,19 +33,18 @@ constructor uses the iterator to read the serialized form of the object and construct the C++ object accordingly. Along the way, the iterator is modified to point behind the object which was just deserialized. -An example of such a constructor is -agentxcpp::varbind::varbind(binary::const_iterator& pos, -binary::const_iterator& end, bool big_endian). It takes an iterator ('pos') -and begins parsing at where 'pos' points to. While reading, the varbind object -is constructed. A varbind always contains (at least) an OidValue. The varbind -constructor therefore creates an OidValue object by passing the 'pos' iterator to -the constructor of the OidValue class, which reads the serialized OidValue and constructs -the OidValue object. If needed, another variable is created the same way (e.g. -an IntegerValue or an OctetStringValue). When the varbind object is fully -constructed, the 'pos' iterator points to the position behind the varbind and -the constructor returns. Note that the iterator is modified by the constructor. -The caller may then use 'pos' to create the next object, until the buffer is -completely parsed. +An example of such a constructor is varbind::varbind(binary::const_iterator&, +const binary::const_iterator&, bool). It takes an iterator ('pos') and begins +parsing at where 'pos' points to. While reading, the varbind object is +constructed. A varbind always contains (at least) an OidValue. The varbind +constructor therefore creates an OidValue object by passing the 'pos' iterator +to the constructor of the OidValue class, which reads the serialized OidValue +and constructs the OidValue object. If needed, another variable is created the +same way (e.g. an IntegerValue or an OctetStringValue). When the varbind +object is fully constructed, the 'pos' iterator points to the position behind +the varbind and the constructor returns. Note that the iterator is modified by +the constructor. The caller may then use 'pos' to create the next object, +until the buffer is completely parsed. The 'end' iterator seen in the above constructor prototype is needed to know the end of the buffer. Parse constructors use it to detect missing data at the @@ -53,14 +52,12 @@ end of the buffer. For example, the serialized form of an Integer is 4 bytes in size; if pos points to the last byte in the buffer, the integer is corrupted. This can be detected using the 'end' iterator. -Reading a PDU is initiated by calling the static class function -agentxcpp::PDU::get_pdu(boost::asio::local::stream_protocol::socket& in, -unsigned timeout=1000). The function first reads the PDU from the socket into a -buffer. It then interprets the PDU header and creates a concrete PDU object -(e.g. OpenPDU) corresponding to the type field found in the header. The PDU -and its subobjects are created as described above. Finally, a pointer to the -created object is returned, and the caller is responsible for deleting it when -it is not longer needed. +Parsing a PDU is initiated by calling the static class function +agentxcpp::PDU::parse_pdu(agentxcpp::binary). The function reads the PDU header +from the given buffer and creates a concrete PDU object (e.g. OpenPDU) +corresponding to the type field found in the header. The PDU and its +subobjects are created as described above, by using their parse constructors. +Finally, a shared pointer to the created object is returned. The agentxcpp::PDU class cannot be instantiated itself, as it does not represent a PDU type defined in RFC 2741. It serves as base class for the @@ -69,20 +66,23 @@ inherits from PDU. The constructor of such a concrete class must call the constructor of the PDU class, which parses the header. Example: \code -OpenPDU::OpenPDU(binary::const_iterator& pos, bool big_endian) +OpenPDU::OpenPDU(binary::const_iterator& pos, + const binary::const_iterator& end, + bool big_endian) : PDU(pos, big_endian) // parse header + : PDU(pos, end, big_endian) { - timeout = *pos++; // parse timeout field - pos += 3; // skip reserved fields - id = OidValue(pos, big_endian); // parse OidValue - descr = OctetStringValue(pos, big_endian); // parse desciption + timeout = *pos++; // parse timeout field + pos += 3; // skip reserved fields + id = OidValue(pos, end, big_endian); // parse OidValue + descr = OctetStringValue(pos, end, big_endian); // parse description } \endcode Note that the header is parsed two times. The first time is in the -agentxcpp::PDU::get_pdu() function (described above), where the header is +agentxcpp::PDU::parse_pdu() function (described above), where the header is inspected to determine the payload length, the PDU type and the endianess of -the PDU. The protocol version is also checked in PDU::get_pdu(). The second +the PDU. The protocol version is also checked in PDU::parse_pdu(). The second time is in the agentxcpp::PDU::PDU() constructor, where the sessionID, transactionID, packetID and some flags are picked up. From aabe2e674bf4b33f5bcd29febb7919df003de919 Mon Sep 17 00:00:00 2001 From: "Tanjeff-N. Moos" Date: Thu, 16 May 2013 08:11:19 +0200 Subject: [PATCH 18/89] Remove unit tests, as they still use boost. --- unit_tests/IntegerTest.cpp | 125 ------------------------------------- unit_tests/SConscript | 38 ----------- 2 files changed, 163 deletions(-) delete mode 100644 unit_tests/IntegerTest.cpp delete mode 100644 unit_tests/SConscript diff --git a/unit_tests/IntegerTest.cpp b/unit_tests/IntegerTest.cpp deleted file mode 100644 index ca472ab..0000000 --- a/unit_tests/IntegerTest.cpp +++ /dev/null @@ -1,125 +0,0 @@ -/* - * Copyright 2011-2012 Tanjeff-Nicolai Moos - * - * This file is part of the agentXcpp library. - * - * AgentXcpp is free software: you can redistribute it and/or modify - * it under the terms of the AgentXcpp library license, version 1, which - * consists of the GNU General Public License and some additional - * permissions. - * - * AgentXcpp is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * See the AgentXcpp library license in the LICENSE file of this package - * for more details. - */ - -// we link the testsuite dynamically (must come before the #include) -#define BOOST_TEST_DYN_LINK - -#include -#include - -#include - - - - -BOOST_AUTO_TEST_CASE( init_constructor_and_get_value ) -{ - agentxcpp::IntegerValue object_1(13); - BOOST_CHECK_EQUAL( object_1.get_value(), 13 ); - - agentxcpp::IntegerValue object_2(0); - BOOST_CHECK_EQUAL( object_2.get_value(), 0 ); - - long long max = std::pow(2,32)-1; // maximum value for quint32 - - agentxcpp::IntegerValue object_3(max); - BOOST_CHECK_EQUAL( object_3.get_value(), max); - - agentxcpp::IntegerValue object_4(-1); // -1 should wrap to max! - BOOST_CHECK_EQUAL( object_4.get_value(), max ); -} - -BOOST_AUTO_TEST_CASE( serialize ) -{ - agentxcpp::IntegerValue object(0x11223344); - binary blob = object.serialize(); - - // We expect big endian! - BOOST_CHECK_EQUAL(blob.size(), 4); - BOOST_CHECK_EQUAL(blob[0], 0x11); - BOOST_CHECK_EQUAL(blob[1], 0x22); - BOOST_CHECK_EQUAL(blob[2], 0x33); - BOOST_CHECK_EQUAL(blob[3], 0x44); -} - -BOOST_AUTO_TEST_CASE( parse_constructor ) -{ - // Create some serialized data - binary blob; - blob.push_back(0x11); - blob.push_back(0x22); - blob.push_back(0x33); - blob.push_back(0x44); - blob.push_back(0x55); - blob.push_back(0x66); - blob.push_back(0x77); - - binary::const_iterator begin; - binary::const_iterator end = blob.end(); - - // Create Integer from beginning, little endian - begin = blob.begin(); - agentxcpp::IntegerValue object_1(begin, end, false); - BOOST_CHECK_EQUAL(object_1.get_value(), 0x44332211); - BOOST_CHECK_EQUAL(*begin, *(blob.begin()+4)); - - // Create Integer from beginning, big endian - begin = blob.begin(); - agentxcpp::IntegerValue object_2(begin, end); - BOOST_CHECK_EQUAL(object_2.get_value(), 0x11223344); - BOOST_CHECK_EQUAL(*begin, *(blob.begin()+4)); - - // Create Integer starting at a position where offset%4 != 0 - begin = blob.begin() + 1; - agentxcpp::IntegerValue object_3(begin, end); - BOOST_CHECK_EQUAL(object_3.get_value(), 0x22334455); - BOOST_CHECK_EQUAL(*begin, *(blob.begin()+5)); - - // Create Integer starting at the last possible position - begin = blob.begin() + 3; - agentxcpp::IntegerValue object_4(begin, end); - BOOST_CHECK_EQUAL(object_4.get_value(), 0x44556677); - BOOST_CHECK_EQUAL(*begin, *(blob.begin()+7)); - - // Create Integer starting near the end, so less than 4 bytes are available - // for parsing. The constructor should throw a parse_error excection. - begin = blob.begin() + 5; - BOOST_CHECK_THROW( agentxcpp::IntegerValue object_5(begin, end), - parse_error ) -} - -BOOST_AUTO_TEST_CASE( set_value ) -{ - // We use this object for the tests - agentxcpp::IntegerValue object(0); - - object.set_value(13); - BOOST_CHECK_EQUAL( object.get_value(), 13 ); - - object.set_value(0); - BOOST_CHECK_EQUAL( object.get_value(), 0 ); - - long long max = std::pow(2,32)-1; // maximum value for quint32 - - object.set_value(max); - BOOST_CHECK_EQUAL( object.get_value(), max); - - object.set_value(-1); // -1 should wrap to max! - BOOST_CHECK_EQUAL( object.get_value(), max ); -} diff --git a/unit_tests/SConscript b/unit_tests/SConscript deleted file mode 100644 index e0cebda..0000000 --- a/unit_tests/SConscript +++ /dev/null @@ -1,38 +0,0 @@ -# -# Copyright 2011 Tanjeff-Nicolai Moos -# -# This file is part of the agentXcpp library. -# -# AgentXcpp is free software: you can redistribute it and/or modify -# it under the terms of the AgentXcpp library license, version 1, which -# consists of the GNU General Public License and some additional -# permissions. -# -# AgentXcpp is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# See the AgentXcpp library license in the LICENSE file of this package -# for more details. -# - -# Get the environment from the SConscript above -Import('env') - -test_env = env.Clone() - -# Only for gcc: make executable usable in this directory -if(test_env["CXX"] == "g++"): - test_env.Append(LINKFLAGS = ['-Wl,-rpath,../src/']) - -testsuite = test_env.Program('testsuite', - Glob('*.cpp'), - LIBS=['boost_unit_test_framework', - 'agentxcpp', - 'boost_system'], - LIBPATH=['../src/'], - CPPPATH=['../src/']) -env.Alias('testsuite', testsuite) - -# Note: testsuite is not built by default From 3bd28867628d88171aed1a58ca1a936ad5cef71c Mon Sep 17 00:00:00 2001 From: "Tanjeff-N. Moos" Date: Thu, 16 May 2013 08:24:03 +0200 Subject: [PATCH 19/89] Update README and docs: no more unit tests. --- README | 5 ----- doc/buildsystem.dox | 17 ----------------- 2 files changed, 22 deletions(-) diff --git a/README b/README index 8e5c7f8..b9f9e04 100644 --- a/README +++ b/README @@ -115,11 +115,6 @@ src/ This directory contains the source code of the library. -unit_tests/ - This directory contains the unit tests for the agentXcpp components. - Note that this is currently rather a skeleton, and no tests are - available yet. - Prerequisites ------------- diff --git a/doc/buildsystem.dox b/doc/buildsystem.dox index 360965a..4558ba8 100644 --- a/doc/buildsystem.dox +++ b/doc/buildsystem.dox @@ -94,12 +94,6 @@ the example) as includedir and PREFIX/share/doc (which is /usr/share/doc in the example) as docdir. The default directories can be shown with scons -h. -\subsection unit_tests Building the Unit Tests - -The unit tests can be build with - -scons testsuite - \subsection cleaning Cleaning To clean the project directory, type: @@ -190,15 +184,4 @@ dependencies. However, the current implementation will work until a good Doxygen builder becomes available. -\subsection unit_tests_sconscript unit_tests/SConscript - -The \c SConscript in unit_tests/ builds the unit tests for agentXcpp. When -using the g++ compiler, the -rpath ../src/ parameter is added so that -the unit tests can find the agentXcpp shared library although it is not -installed in a well-known place (like /usr/lib). - -An install target is not provided, as unit tests are of course not installed on -the target system. Also, the unit tests are not defined as a default target. - - */ From 7c4b7b780bd180f21f4a295b44bab7fb3d6d8e9f Mon Sep 17 00:00:00 2001 From: "Tanjeff-N. Moos" Date: Fri, 26 Jul 2013 00:29:44 +0200 Subject: [PATCH 20/89] Add toOid() method to some classes. This method supports building OID's for objects within tables. --- src/Counter32Value.hpp | 5 +++++ src/Counter64Value.hpp | 4 ++++ src/Gauge32Value.hpp | 5 +++++ src/IntegerValue.hpp | 21 +++++++++++++++++++++ src/IpAddressValue.hpp | 19 +++++++++++++++++++ src/OctetStringValue.hpp | 34 ++++++++++++++++++++++++++++++++++ src/OidValue.hpp | 29 +++++++++++++++++++++++++++++ src/TimeTicksValue.hpp | 4 ++++ 8 files changed, 121 insertions(+) diff --git a/src/Counter32Value.hpp b/src/Counter32Value.hpp index 8af2a10..117a1fb 100644 --- a/src/Counter32Value.hpp +++ b/src/Counter32Value.hpp @@ -29,6 +29,11 @@ namespace agentxcpp { /** * \brief Represents an Counter32 as described in RFC 2741 + * + * \note This class has no toOid() method, because Counter32 + * objects are not allowed in INDEX clauses according to + * RFC 2578, 7.7. "Mapping of the INDEX clause". + * */ // TODO: RFC2578? class Counter32Value : public AbstractValue diff --git a/src/Counter64Value.hpp b/src/Counter64Value.hpp index bdaeafe..35a9d00 100644 --- a/src/Counter64Value.hpp +++ b/src/Counter64Value.hpp @@ -29,6 +29,10 @@ namespace agentxcpp { /** * \brief Represents an Counter64 as descibed in RFC 2741 + * + * \note This class has no toOid() method, because Counter64 + * objects are not allowed in INDEX clauses according to + * RFC 2578, 7.7. "Mapping of the INDEX clause". */ class Counter64Value : public AbstractValue { diff --git a/src/Gauge32Value.hpp b/src/Gauge32Value.hpp index e2a2f2b..c16a98a 100644 --- a/src/Gauge32Value.hpp +++ b/src/Gauge32Value.hpp @@ -29,6 +29,11 @@ namespace agentxcpp { /** * \brief Represents a Gauge32 as descibed in RFC 2741 + * + * \note This class has no toOid() method, because RFC 2578, + * 7.7. "Mapping of the INDEX clause" does not describe + * how to convert Gauge32 to an OID. + * */ class Gauge32Value : public AbstractValue { diff --git a/src/IntegerValue.hpp b/src/IntegerValue.hpp index a5bd5ad..0185cfa 100644 --- a/src/IntegerValue.hpp +++ b/src/IntegerValue.hpp @@ -24,6 +24,7 @@ #include "AbstractValue.hpp" #include "exceptions.hpp" +#include "OidValue.hpp" namespace agentxcpp { @@ -88,6 +89,26 @@ namespace agentxcpp const binary::const_iterator& end, bool big_endian=true); + /** + * \brief Convert the value to an OID. + * + * The conversion is done according to RFC 2578, + * 7.7. "Mapping of the INDEX clause". The value is + * converted to an Oid with a single subid. Note that + * INTEGER values are signed, while subids are not. + * A negative value with be converted to big unsigned + * subid. + * + * \note If an INTEGER is used in an INDEX clause, the + * value 0 should be avoided according to + * RFC 2578, 7.7. "Mapping of the INDEX clause". + */ + OidValue toOid() const + { + OidValue oid; + oid.push_back(value); + return oid; + } }; } diff --git a/src/IpAddressValue.hpp b/src/IpAddressValue.hpp index 12abb8d..8b51e38 100644 --- a/src/IpAddressValue.hpp +++ b/src/IpAddressValue.hpp @@ -24,6 +24,7 @@ #include "AbstractValue.hpp" #include "exceptions.hpp" +#include "OidValue.hpp" namespace agentxcpp { @@ -144,6 +145,24 @@ namespace agentxcpp } return address[index]; } + + /** + * \brief Convert the value to an OID. + * + * The conversion is done according to RFC 2578, + * 7.7. "Mapping of the INDEX clause". The created OID + * has exactly 4 subids which corresponds to the 4 + * integers of the IP address. + */ + OidValue toOid() const + { + OidValue oid; + oid.push_back(address[0]); + oid.push_back(address[1]); + oid.push_back(address[2]); + oid.push_back(address[3]); + return oid; + } }; } diff --git a/src/OctetStringValue.hpp b/src/OctetStringValue.hpp index 273b20f..30743a9 100644 --- a/src/OctetStringValue.hpp +++ b/src/OctetStringValue.hpp @@ -22,6 +22,7 @@ #include "AbstractValue.hpp" #include "exceptions.hpp" +#include "OidValue.hpp" namespace agentxcpp { @@ -114,6 +115,39 @@ namespace agentxcpp * \brief Get the current value as string. */ std::string str() const; + + /** + * \brief Convert the value to an OID. + * + * The conversion is done according to RFC 2578, + * 7.7. "Mapping of the INDEX clause". First, the + * string length is converted to a subid. Then, each + * octet of the value is converted into a separate subid. + * + * Note that the length subid is omitted for fixed-length strings. + * + * \param fixedLength Whether the string is fixed-length. + */ + OidValue toOid(bool fixedLength = false) const + { + OidValue oid; + + // Store string length if needed + if(!fixedLength) + { + oid.push_back(value.size()); + } + + // Store string + for(binary::const_iterator i = value.begin(); + i != value.end(); + ++i) + { + oid.push_back(*i); + } + return oid; + } + }; } diff --git a/src/OidValue.hpp b/src/OidValue.hpp index e140660..cf80bda 100644 --- a/src/OidValue.hpp +++ b/src/OidValue.hpp @@ -365,6 +365,35 @@ namespace agentxcpp friend std::ostream& operator<<(std::ostream& out, const agentxcpp::OidValue& o); + /** + * \brief Convert the value to an OID. + * + * The conversion is done according to RFC 2578, + * 7.7. "Mapping of the INDEX clause". First, the + * length is converted to a subid. Then, each + * subid of the value is appended. + * + * Note that the length subid is omitted for fixed-length OIDs. + * + * \param fixedLength Whether the OID is fixed-length. + */ + OidValue toOid(bool fixedLength = false) const + { + OidValue oid; + + // Store length if needed + if(!fixedLength) + { + oid.push_back(this->size()); + } + + // Store value + oid.insert(oid.end(), this->begin(), this->end()); + + return oid; + } + + }; /** diff --git a/src/TimeTicksValue.hpp b/src/TimeTicksValue.hpp index d0e3b4d..7706e88 100644 --- a/src/TimeTicksValue.hpp +++ b/src/TimeTicksValue.hpp @@ -29,6 +29,10 @@ namespace agentxcpp { /** * \brief Represents an TimeTicks as described in RFC 2741 + * + * \note This class has no toOid() method, because RFC 2578, + * 7.7. "Mapping of the INDEX clause" does not describe + * how to convert TimeTicks to an OID. */ class TimeTicksValue : public AbstractValue { From 6a978bfce51d80e2df5195b573005721846bd2d3 Mon Sep 17 00:00:00 2001 From: "Tanjeff-N. Moos" Date: Tue, 17 Sep 2013 21:28:27 +0200 Subject: [PATCH 21/89] Fix typos. --- src/MasterProxy.hpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/MasterProxy.hpp b/src/MasterProxy.hpp index 89736d0..60b95d4 100644 --- a/src/MasterProxy.hpp +++ b/src/MasterProxy.hpp @@ -101,7 +101,7 @@ namespace agentxcpp * 1.3.6.1.4.1.42.1.1 and 1.3.6.1.4.1.42.1.2, then a subtree * with OID 1.3.6.1.4.1.42.1 should be registered, which includes * both objects. The master agent will then forward all requests - * conecerning objects in this subtree to this subagent. Requests to + * concerning objects in this subtree to this subagent. Requests to * non-existing objects (e.g. 1.3.6.1.4.1.42.1.3) are also * forwarded, and the agentXcpp library will take care of them and return * an appropriate error to the master agent. @@ -130,13 +130,14 @@ namespace agentxcpp * * The MasterProxy object generates a RegisterPDU object each time a * registration is performed. These RegisterPDU objects are stored in the - * registrations member. + * MasterProxy::registrations member. * * When unregistering, the matching RegisterPDU is removed from the * registration member. * - * The registration member becomes invalid on connection loss. Since a - * connection loss is not signalled, the member cannot be cleared in such + * The MasterProxy::registration member becomes invalid on connection loss. + * Since a + * connection loss is not signaled, the member cannot be cleared in such * situations. Therefore, it is cleared in the connect() method if the * object is currently disconnected. If connect() is called on a connected * MasterProxy object, the registrations member is not cleared. @@ -166,7 +167,7 @@ namespace agentxcpp * When removing a variable, it is removed from the variables member. * * The variables member becomes invalid on connection loss. Since a - * connection loss is not signalled, the member cannot be cleared in such + * connection loss is not signaled, the member cannot be cleared in such * situations. Therefore, it is cleared in the connect() method if the * object is currently disconnected. If connect() is called on a connected * MasterProxy object, the variables member is not cleared. From 8c1d5276d978724bf5da7d88b852982ecccc257f Mon Sep 17 00:00:00 2001 From: "Tanjeff-N. Moos" Date: Tue, 17 Sep 2013 21:55:31 +0200 Subject: [PATCH 22/89] Tables can now be registered/unregistered. This commit adds the empty Table class and implements MasterProxy::addTable() and MasterProxy::removeTable(). --- src/MasterProxy.cpp | 43 ++++++++++++++++++++++++++++++++--------- src/MasterProxy.hpp | 47 ++++++++++++++++++++++++++++++++++++++++++++- src/Table.cpp | 22 +++++++++++++++++++++ src/Table.hpp | 33 +++++++++++++++++++++++++++++++ 4 files changed, 135 insertions(+), 10 deletions(-) create mode 100644 src/Table.cpp create mode 100644 src/Table.hpp diff --git a/src/MasterProxy.cpp b/src/MasterProxy.cpp index 8ac0ce3..a88a6b8 100644 --- a/src/MasterProxy.cpp +++ b/src/MasterProxy.cpp @@ -883,23 +883,48 @@ void MasterProxy::add_variable(const OidValue& id, QSharedPointer t) { - // Find variable - map >::iterator i = variables.find(id); + // Check whether id is contained in a registration + bool is_registered = false; + std::list< QSharedPointer >::const_iterator r; + for(r = registrations.begin(); r != registrations.end(); r++) + { + if((*r)->get_instance_registration() == false && + (*r)->get_range_subid() == 0) + { + // Registration is a simple subtree + if( (*r)->get_subtree().contains(id) ) + { + // The ID lies within a registered area + is_registered = true; + break; // stop search + } + } + // TODO: handle other registrations (e.g. instance registration) + } - if(i == variables.end()) + if( ! is_registered ) { - // Variable was not added in advance - // -> ignore - return; + // Not in a registered area + throw(unknown_registration()); } + tables[id] = t; +} + + +void MasterProxy::remove_variable(const OidValue& id) +{ // Remove variable - variables.erase(i); + variables.erase(id); // If variable was not registered: ignore } +void MasterProxy::removeTable(const OidValue& id) +{ + // Remove variable + tables.remove(id); // If table was not registered: ignore +} void MasterProxy::send_notification(const OidValue& snmpTrapOID, diff --git a/src/MasterProxy.hpp b/src/MasterProxy.hpp index 60b95d4..ff992e5 100644 --- a/src/MasterProxy.hpp +++ b/src/MasterProxy.hpp @@ -28,6 +28,7 @@ #include #include +#include #include "OidValue.hpp" #include "AbstractVariable.hpp" @@ -43,7 +44,7 @@ #include "CommitSetPDU.hpp" #include "UndoSetPDU.hpp" #include "UnixDomainConnector.hpp" - +#include "Table.hpp" namespace agentxcpp { @@ -257,6 +258,11 @@ namespace agentxcpp */ std::map< OidValue, QSharedPointer > variables; + /** + * \brief Storage for all SNMP tables known to the MasterProxy. + */ + QMap< OidValue, QSharedPointer > tables; + /** * \brief The variables affected by the Set operation currently * in progress. @@ -761,6 +767,30 @@ namespace agentxcpp */ void add_variable(const OidValue& id, QSharedPointer v); + /** + * \brief Add an SNMP table for serving. + * + * This adds an SNMP table which can then be read and/or + * written. + * + * Tables can only be added to MIB regions which were registered + * in advance. + * + * If adding a table with an id for which another table is + * already registered, it replaces the old one. + * + * \param subtree The OID of the table. + * + * \param t The table. + * + * \exception unknown_registration If trying to add a table + * with an id which does not reside + * within a registered MIB + * region. + */ + void addTable(const OidValue& subtree, + QSharedPointer
t); + /** * \brief Remove an SNMP variable so that is not longer accessible. * @@ -775,6 +805,21 @@ namespace agentxcpp * \exception None. */ void remove_variable(const OidValue& id); + + /** + * \brief Remove an SNMP table so that is not longer accessible. + * + * This removes a table previously added using addTable(). + * The table will no longer receive SNMP requests. + * + * If no table is known for the given id, nothing happens. + * + * \param id The OID of the table to remove. This is the OID + * which was given to addTable(). + * + * \exception None. + */ + void removeTable(const OidValue& id); }; } diff --git a/src/Table.cpp b/src/Table.cpp new file mode 100644 index 0000000..08e0bf0 --- /dev/null +++ b/src/Table.cpp @@ -0,0 +1,22 @@ +/* + * Copyright 2011-2013 Tanjeff-Nicolai Moos + * + * This file is part of the agentXcpp library. + * + * AgentXcpp is free software: you can redistribute it and/or modify + * it under the terms of the AgentXcpp library license, version 1, which + * consists of the GNU General Public License and some additional + * permissions. + * + * AgentXcpp is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * See the AgentXcpp library license in the LICENSE file of this package + * for more details. + */ + +#include "Table.hpp" + +using namespace agentxcpp; diff --git a/src/Table.hpp b/src/Table.hpp new file mode 100644 index 0000000..3718ec9 --- /dev/null +++ b/src/Table.hpp @@ -0,0 +1,33 @@ +/* + * Copyright 2011-2012 Tanjeff-Nicolai Moos + * + * This file is part of the agentXcpp library. + * + * AgentXcpp is free software: you can redistribute it and/or modify + * it under the terms of the AgentXcpp library license, version 1, which + * consists of the GNU General Public License and some additional + * permissions. + * + * AgentXcpp is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * See the AgentXcpp library license in the LICENSE file of this package + * for more details. + */ + +#ifndef TABLE_HPP_ +#define TABLE_HPP_ + +#include "AbstractVariable.hpp" + +namespace agentxcpp +{ + + class Table : public AbstractVariable + { + }; + +} /* namespace agentxcpp */ +#endif /* TABLE_HPP_ */ From 60c39a5d439f6c7f7c95a7a91f1f8687f4897985 Mon Sep 17 00:00:00 2001 From: "Tanjeff-N. Moos" Date: Thu, 26 Sep 2013 22:20:41 +0200 Subject: [PATCH 23/89] Let OidValue inherit from QVector & add operators. OidValue used to inherit from std::vector. This was changed, so that it now inherits from QVector. The reason is that a concatenation function is needed, which is provided by QVector (but not by std::vector). In addition, operator<=() and operator>=() are added. --- src/OidValue.cpp | 2 +- src/OidValue.hpp | 50 +++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 46 insertions(+), 6 deletions(-) diff --git a/src/OidValue.cpp b/src/OidValue.cpp index 94a49cc..aead46b 100644 --- a/src/OidValue.cpp +++ b/src/OidValue.cpp @@ -338,7 +338,7 @@ OidValue& OidValue::operator=(const OidValue& other) this->include = other.include; // copy inherited stuff - vector::operator=(other); + QVector::operator=(other); AbstractValue::operator=(other); // Return reference to us diff --git a/src/OidValue.hpp b/src/OidValue.hpp index cf80bda..1d9427e 100644 --- a/src/OidValue.hpp +++ b/src/OidValue.hpp @@ -20,11 +20,11 @@ #ifndef _OID_H_ #define _OID_H_ -#include #include #include #include +#include #include "AbstractValue.hpp" #include "exceptions.hpp" @@ -89,7 +89,7 @@ namespace agentxcpp * \endcode * */ - class OidValue: public AbstractValue, public std::vector + class OidValue: public AbstractValue, public QVector { private: @@ -275,12 +275,35 @@ namespace agentxcpp * because the 9th number is greater (although the first OID has * less numbers than the second). * - * \param o The OID tocompare to. + * \param o The OID to compare to. * * \return True if the OID is less than 'o', false otherwise. */ bool operator<(const OidValue& o) const; + /** + * \brief The less-than-or-equal operator + * + * See operator<() for a more detailed description about comparing + * OIDs. + * + * \param o The OID to compare to. + * + * \return True if the OID is less than or equal 'o', + * false otherwise. + */ + bool operator<=(const OidValue& o) const + { + if(*this == o || *this < o) + { + return true; + } + else + { + return false; + } + } + /** * \brief The equal-operator * @@ -324,7 +347,24 @@ namespace agentxcpp return o < *this; } - /** + /** + * \brief The greater-than-or-equal operator + * + * See operator<() for a more detailed description about comparing + * OIDs. + * + * \param o The OID to compare to. + * + * \return True if the OID is greater than or equal 'o', + * false otherwise. + */ + bool operator>=(const OidValue& o) const + { + // a >= b is the same as b <= a :-) + return o <= *this; + } + + /** * \brief Checks whether the given OidValue is in the subtree of this * OidValue. * @@ -388,7 +428,7 @@ namespace agentxcpp } // Store value - oid.insert(oid.end(), this->begin(), this->end()); + oid += *this; return oid; } From 3c2b812a73b2d8e2f597735deee0415af5a4ea11 Mon Sep 17 00:00:00 2001 From: "Tanjeff-N. Moos" Date: Sat, 15 Feb 2014 16:24:03 +0100 Subject: [PATCH 24/89] Add Variable classes for default types. It is desirable to have default implementations for SNMP variables representing Integer, OctetString and so on. These can be used for simple purposes, where no extra functionality is needed. --- src/Counter32Variable.hpp | 40 +++++++++++++++++++++++++++++++++++ src/Counter64Variable.hpp | 40 +++++++++++++++++++++++++++++++++++ src/Gauge32Variable.hpp | 40 +++++++++++++++++++++++++++++++++++ src/IntegerValue.hpp | 4 ++-- src/IntegerVariable.hpp | 42 +++++++++++++++++++++++++++++++++++++ src/IpAddressVariable.hpp | 40 +++++++++++++++++++++++++++++++++++ src/OctetStringVariable.hpp | 40 +++++++++++++++++++++++++++++++++++ src/OidVariable.hpp | 40 +++++++++++++++++++++++++++++++++++ src/OpaqueValue.hpp | 7 +++++++ src/OpaqueVariable.hpp | 40 +++++++++++++++++++++++++++++++++++ src/TimeTicksVariable.hpp | 40 +++++++++++++++++++++++++++++++++++ 11 files changed, 371 insertions(+), 2 deletions(-) create mode 100644 src/Counter32Variable.hpp create mode 100644 src/Counter64Variable.hpp create mode 100644 src/Gauge32Variable.hpp create mode 100644 src/IntegerVariable.hpp create mode 100644 src/IpAddressVariable.hpp create mode 100644 src/OctetStringVariable.hpp create mode 100644 src/OidVariable.hpp create mode 100644 src/OpaqueVariable.hpp create mode 100644 src/TimeTicksVariable.hpp diff --git a/src/Counter32Variable.hpp b/src/Counter32Variable.hpp new file mode 100644 index 0000000..673d16b --- /dev/null +++ b/src/Counter32Variable.hpp @@ -0,0 +1,40 @@ +#ifndef _COUNTER32VARIABLE_H_ +#define _COUNTER32VARIABLE_H_ + +#include "Counter32Value.hpp" +#include "Variable.hpp" + +namespace agentxcpp +{ + + class Counter32Variable : public Variable + { + private: + + Counter32Value v; + + public: + + Counter32Variable(Counter32Value _value = Counter32Value()) + { + v = _value; + } + + void setValue(Counter32Value _value) + { + v = _value; + } + + virtual Counter32Value get() + { + return v; + } + + virtual Counter32Value value() + { + return v; + } + + }; +} +#endif // _COUNTER32VARIABLE_H_ diff --git a/src/Counter64Variable.hpp b/src/Counter64Variable.hpp new file mode 100644 index 0000000..6e5dcd0 --- /dev/null +++ b/src/Counter64Variable.hpp @@ -0,0 +1,40 @@ +#ifndef _COUNTER64VARIABLE_H_ +#define _COUNTER64VARIABLE_H_ + +#include "Counter64Value.hpp" +#include "Variable.hpp" + +namespace agentxcpp +{ + + class Counter64Variable : public Variable + { + private: + + Counter64Value v; + + public: + + Counter64Variable(Counter64Value _value = Counter64Value()) + { + v = _value; + } + + void setValue(Counter64Value _value) + { + v = _value; + } + + virtual Counter64Value get() + { + return v; + } + + virtual Counter64Value value() + { + return v; + } + + }; +} +#endif // _COUNTER64VARIABLE_H_ diff --git a/src/Gauge32Variable.hpp b/src/Gauge32Variable.hpp new file mode 100644 index 0000000..fb51c42 --- /dev/null +++ b/src/Gauge32Variable.hpp @@ -0,0 +1,40 @@ +#ifndef _GAUGE32VARIABLE_H_ +#define _GAUGE32VARIABLE_H_ + +#include "Gauge32Value.hpp" +#include "Variable.hpp" + +namespace agentxcpp +{ + + class Gauge32Variable : public Variable + { + private: + + Gauge32Value v; + + public: + + Gauge32Variable(Gauge32Value _value = Gauge32Value()) + { + v = _value; + } + + void setValue(Gauge32Value _value) + { + v = _value; + } + + virtual Gauge32Value get() + { + return v; + } + + virtual Gauge32Value value() + { + return v; + } + + }; +} +#endif // _GAUGE32VARIABLE_H_ diff --git a/src/IntegerValue.hpp b/src/IntegerValue.hpp index 0185cfa..81b0253 100644 --- a/src/IntegerValue.hpp +++ b/src/IntegerValue.hpp @@ -17,8 +17,8 @@ * for more details. */ -#ifndef _INTEGER_H_ -#define _INTEGER_H_ +#ifndef _INTEGERVALUE_H_ +#define _INTEGERVALUE_H_ #include diff --git a/src/IntegerVariable.hpp b/src/IntegerVariable.hpp new file mode 100644 index 0000000..45db4f0 --- /dev/null +++ b/src/IntegerVariable.hpp @@ -0,0 +1,42 @@ +#ifndef _INTEGERVARIABLE_H_ +#define _INTEGERVARIABLE_H_ + +#include "IntegerValue.hpp" +#include "Variable.hpp" + +namespace agentxcpp +{ + + class IntegerVariable : public Variable + { + private: + + IntegerValue v; + + public: + + IntegerVariable(IntegerValue _value = IntegerValue()) + { + v = _value; + } + + void setValue(IntegerValue _value) + { + v = _value; + } + + virtual IntegerValue get() + { + return v; + } + + virtual IntegerValue value() + { + return v; + } + + }; + +} + +#endif // _INTEGER_H_ diff --git a/src/IpAddressVariable.hpp b/src/IpAddressVariable.hpp new file mode 100644 index 0000000..7b90166 --- /dev/null +++ b/src/IpAddressVariable.hpp @@ -0,0 +1,40 @@ +#ifndef _IPADDRESSVARIABLE_H_ +#define _IPADDRESSVARIABLE_H_ + +#include "IpAddressValue.hpp" +#include "Variable.hpp" + +namespace agentxcpp +{ + + class IpAddressVariable : public Variable + { + private: + + IpAddressValue v; + + public: + + IpAddressVariable(IpAddressValue _value) + : v(_value) + { + } + + void setValue(IpAddressValue _value) + { + v = _value; + } + + virtual IpAddressValue get() + { + return v; + } + + virtual IpAddressValue value() + { + return v; + } + + }; +} +#endif // _IPADDRESSVARIABLE_H_ diff --git a/src/OctetStringVariable.hpp b/src/OctetStringVariable.hpp new file mode 100644 index 0000000..ddb09f2 --- /dev/null +++ b/src/OctetStringVariable.hpp @@ -0,0 +1,40 @@ +#ifndef _OCTETSTRINGVARIABLE_H_ +#define _OCTETSTRINGVARIABLE_H_ + +#include "OctetStringValue.hpp" +#include "Variable.hpp" + +namespace agentxcpp +{ + + class OctetStringVariable : public Variable + { + private: + + OctetStringValue v; + + public: + + OctetStringVariable(binary _value = binary()) + : v(_value) + { + } + + void setValue(binary _value) + { + v.set_value(_value); + } + + virtual OctetStringValue get() + { + return v; + } + + virtual binary value() + { + return v.get_value(); + } + + }; +} +#endif // _OCTETSTRINGVARIABLE_H_ diff --git a/src/OidVariable.hpp b/src/OidVariable.hpp new file mode 100644 index 0000000..d75e8f4 --- /dev/null +++ b/src/OidVariable.hpp @@ -0,0 +1,40 @@ +#ifndef _OIDVARIABLE_H_ +#define _OIDVARIABLE_H_ + +#include "OidValue.hpp" +#include "Variable.hpp" + +namespace agentxcpp +{ + + class OidVariable : public Variable + { + private: + + OidValue v; + + public: + + OidVariable(OidValue _value = OidValue()) + : v(_value) + { + } + + void setValue(OidValue _value) + { + v = _value; + } + + virtual OidValue get() + { + return v; + } + + virtual OidValue value() + { + return v; + } + + }; +} +#endif // _OIDVARIABLE_H_ diff --git a/src/OpaqueValue.hpp b/src/OpaqueValue.hpp index 5169d41..af543fc 100644 --- a/src/OpaqueValue.hpp +++ b/src/OpaqueValue.hpp @@ -87,6 +87,13 @@ namespace agentxcpp * \brief Constructor for initializing with data. */ OpaqueValue(binary initial_value) : value(initial_value) {} + + /** + * \brief Standard constructor. + */ + OpaqueValue() + { + } }; } diff --git a/src/OpaqueVariable.hpp b/src/OpaqueVariable.hpp new file mode 100644 index 0000000..a55c295 --- /dev/null +++ b/src/OpaqueVariable.hpp @@ -0,0 +1,40 @@ +#ifndef _OPAQUEVARIABLE_H_ +#define _OPAQUEVARIABLE_H_ + +#include "OpaqueValue.hpp" +#include "Variable.hpp" + +namespace agentxcpp +{ + + class OpaqueVariable : public Variable + { + private: + + OpaqueValue v; + + public: + + OpaqueVariable(OpaqueValue _value = OpaqueValue()) + { + v = _value; + } + + void setValue(OpaqueValue _value) + { + v = _value; + } + + virtual OpaqueValue get() + { + return v; + } + + virtual OpaqueValue value() + { + return v; + } + + }; +} +#endif // _OPAQUEVARIABLE_H_ diff --git a/src/TimeTicksVariable.hpp b/src/TimeTicksVariable.hpp new file mode 100644 index 0000000..bfe2d56 --- /dev/null +++ b/src/TimeTicksVariable.hpp @@ -0,0 +1,40 @@ +#ifndef _TIMETICKSVARIABLE_H_ +#define _TIMETICKSVARIABLE_H_ + +#include "TimeTicksValue.hpp" +#include "Variable.hpp" + +namespace agentxcpp +{ + + class TimeTicksVariable : public Variable + { + private: + + TimeTicksValue v; + + public: + + TimeTicksVariable(TimeTicksValue _value = TimeTicksValue()) + { + v = _value; + } + + void setValue(TimeTicksValue _value) + { + v = _value; + } + + virtual TimeTicksValue get() + { + return v; + } + + virtual TimeTicksValue value() + { + return v; + } + + }; +} +#endif // _TIMETICKSVARIABLE_H_ From 37c88e49b19b25340b6209a7f37e1cddc5a39ee6 Mon Sep 17 00:00:00 2001 From: "Tanjeff-N. Moos" Date: Sun, 16 Feb 2014 19:35:11 +0100 Subject: [PATCH 25/89] Update documentation of Variables and Values. I updated the documentation of the AbstractVariable and the AbstractValue classes. Also I started updating the documentation about how variable and value classes work together to provide SNMP variables (this part is unfinished). --- doc/{request_handling.dox => variables.dox} | 16 ++-- src/AbstractVariable.hpp | 30 ++++--- src/Variable.hpp | 96 ++++++++++++--------- 3 files changed, 83 insertions(+), 59 deletions(-) rename doc/{request_handling.dox => variables.dox} (87%) diff --git a/doc/request_handling.dox b/doc/variables.dox similarity index 87% rename from doc/request_handling.dox rename to doc/variables.dox index c4c8926..028bc69 100644 --- a/doc/request_handling.dox +++ b/doc/variables.dox @@ -24,18 +24,20 @@ \page variables The Variable Objects -\todo This page needs an update, because we now distinguish between Variables -and Values. \section introduction Introduction SNMP and AgentX are all about variables, and how to obtain or alter their values. In agentXcpp, variables are represented by classes which implement the -agentxcpp::AbstractVariables interface. The library provides some classes such -as agentxcpp::IntegerValue and agentxcpp::OctetStringValue, which have an -internal value and can be serialized and deserialized to be included in PDU -messages. To actually provide an SNMP variable, one of these classes must be -derived. +agentxcpp::AbstractVariable interface. Values are represented by classes +implementing agentxcpp::AbstractValue. + +SNMP variables + +The library provides some classes such as agentxcpp::IntegerValue and +agentxcpp::OctetStringValue, which have an internal value and can be +serialized and deserialized to be included in PDU messages. To actually +provide an SNMP variable, one of these classes must be derived. \section serializing_parsing Serializing and Parsing Variables diff --git a/src/AbstractVariable.hpp b/src/AbstractVariable.hpp index f9e069b..fa86b00 100644 --- a/src/AbstractVariable.hpp +++ b/src/AbstractVariable.hpp @@ -16,8 +16,8 @@ * See the AgentXcpp library license in the LICENSE file of this package * for more details. */ -#ifndef _VARIABLE_H_ -#define _VARIABLE_H_ +#ifndef _ABSTRACTVARIABLE_H_ +#define _ABSTRACTVARIABLE_H_ #include @@ -29,7 +29,7 @@ namespace agentxcpp * \brief Base class for SNMP variables. * * This class is the base class for SNMP variable implementations. It - * provides the interface which is used internally by agentXcpp to perform + * provides the interface which is used by agentXcpp to perform * operations on variables. */ class AbstractVariable @@ -47,7 +47,8 @@ namespace agentxcpp /** * \brief Handle AgentX Get request. * - * This method is called when a get request is received for the + * This method is called when the SNMP request "Get" is received + * for the * variable. It shall return the current value of the variable. * * \return The current value of the variable. @@ -153,10 +154,11 @@ namespace agentxcpp /** * \brief Validate whether a Set operation would be successful. * - * This method is called when a TestSet request is received. It + * This method is called when the SNMP request "TestSet" is + * received. It * shall check whether a Set operation is possible for the * variable. It shall acquire the resources needed to perform the - * Set operation (but the Set shall not yet performed). + * Set operation (but the Set shall not yet be performed). * * \note This is the only method which receives the new value to be * set. An implementation must save the new value for @@ -169,17 +171,18 @@ namespace agentxcpp /** * \brief Release resources after a Set operation. * - * This method is called when a CleanupSet request is received. It - * shall release all resources previously allocated by - * handle_testset() (if any). If no resources were allocated, this - * method is not required to do anything. + * This method is called when the SNMP request "CleanupSet" + * is received. It shall release all resources previously allocated + * by handle_testset() (if any). If no resources were allocated, + * this method is not required to do anything. */ virtual void handle_cleanupset() = 0; /** * \brief Actually perform the Set operation. * - * This method is called when a CommitSet request is received for + * This method is called when the SNMP request "CommitSet" + * is received for * the variable. It shall perform the Set operation. It shall * report whether the operation succeeded. * @@ -193,7 +196,8 @@ namespace agentxcpp /** * \brief Undo a Set operation which was already performed. * - * This method is called when an UndoSet request is received. It + * This method is called when the SNMP request "UndoSet" is + * received. It * shall undo the operation performed by handle_commitset(). * * \return True on success, false otherwise. @@ -204,4 +208,4 @@ namespace agentxcpp -#endif /* _VARIABLE_H_ */ +#endif /* _ABSTRACTVARIABLE_H_ */ diff --git a/src/Variable.hpp b/src/Variable.hpp index 132e7df..78fb176 100644 --- a/src/Variable.hpp +++ b/src/Variable.hpp @@ -16,8 +16,8 @@ * See the AgentXcpp library license in the LICENSE file of this package * for more details. */ -#ifndef _PRIMITIVE_VARIABLE_H_ -#define _PRIMITIVE_VARIABLE_H_ +#ifndef _VARIABLE_H_ +#define _VARIABLE_H_ #include @@ -26,11 +26,16 @@ namespace agentxcpp { /** - * \brief Class template to implement primitive SNMP variables. + * \brief Class template to help implement SNMP variables. * - * This class template is used as base class for primitive SNMP variable - * implementations. It is instanciated with the value type the variable - * provides. Then, some functions are overriden to provide the + * This class template can be used as base class for SNMP variable + * implementations. It implements the agentxcpp::AbstractVariable + * interface and tailors it for a concrete type (in contrast, + * agentxcpp::AbstractVariable deals with agentxcpp::AbstractValue). + * + * It shall be instantiated with the value type the variable + * provides (which should be a class derived from agentxcpp::AbstractValue). + * Then, some functions shall be overridden to provide the * functionality. Example: * * \code @@ -43,7 +48,7 @@ namespace agentxcpp * * public: * - * // Handle SNMP get request + * // Handle SNMP get request, overrides Variable::get() * virtual IntegerValue get() * { * return counter; @@ -52,7 +57,7 @@ namespace agentxcpp * // Increment the internal counter * void increment() * { - * // Increment counter somehow + * counter.value++; * } * }; * \endcode @@ -62,35 +67,38 @@ namespace agentxcpp * * To support write access (which is optional), the methods testset() and * commitset() must be implemented. The undoset() method should also be - * implemented in this case. The cleanupset() methon may be implemented if + * implemented in this case. The cleanupset() method may be implemented if * needed. * * \internal * - * This class template implements the methods of agentxcpp::variable in - * such a way that they call methods for the more specific value types. + * This class template implements the methods of agentxcpp::AbstractVariable + * in such a way that they call methods for the more specific value types. * Example: * * \code - * virtual testset_result_t handle_testset(QSharedPointer v) - * { - * QSharedPointer new_value = qSharedPointerDynamicCast(v); - * - * if (new_value) - * { - * return this->testset(new_value); - * } - * else + * virtual testset_result_t handle_testset(QSharedPointer v) * { - * return wrongType; + * new_value = qSharedPointerDynamicCast(v); + * if (new_value) + * { + * // Type matches variable + * return this->testset(new_value); + * } + * else + * { + * // Wrong type + * return wrongType; + * } * } - * } * \endcode * - * As can be seen, handle_testset() receives a pointer to a 'value' object. - * This pointer is casted to 'V' (the template parameter) before giving it - * to the testset() method. The testset() method is the one which is - * implemented by the agentXcpp user. + * As can be seen, handle_testset() receives a pointer to an + * agentxcpp::AbstractValue object. + * This pointer is casted to 'T' (the template parameter) before giving it + * to the testset() method. The testset() method is the one which can be + * implemented in derived classes (while handle_testset() should not be + * re-implemented). * * This class template remembers the new value and gives it to the * functions testset(), commitset(), cleanupset() and undoset(). Also, type @@ -118,8 +126,8 @@ namespace agentxcpp * * \brief Handle a Get Request. * - * This function calls this->get() to obtain the new value, - * converts it to QSharedPointer and returns it. + * This function calls get() to obtain the new value, + * converts it to QSharedPointer and returns it. */ virtual QSharedPointer handle_get() { @@ -133,7 +141,8 @@ namespace agentxcpp /** * \brief Handle a Get request. * - * This method is called to handle an SNMP Get request. It shall + * This method is called when an SNMP Get request is received. + * It shall * return the current value of the variable. * * \note This method is pure virtual and thus \e must be @@ -149,15 +158,19 @@ namespace agentxcpp * * \brief Handle a TestSet request. * - * This function converts the argument to QSharedPointer() and calls + * This function converts the argument to QSharedPointer() and + * calls * testset() with the converted value. If conversion fails, * testset() is not called. This function also stores the given * value to the new_value member. * * \param v The new value for the variable. * - * \return wrongType if the conversion fails. Otherwise, the - * result of testset() is returned. + * \return agentxcpp::AbstractVariable::wrongType if the conversion + * fails. Otherwise, + * the result of + * testset() is + * returned. */ virtual testset_result_t handle_testset(QSharedPointer v) { @@ -178,12 +191,14 @@ namespace agentxcpp /** * \brief Handle a TestSet request. * - * This method is called to handle an SNMP TestSet request. It + * This method is called when an SNMP TestSet request is received. + * It * shall check whether a Set operation is possible for the * variable. It shall acquire the resources needed to perform the - * Set operation (but the Set shall not yet performed). + * Set operation (but the Set shall not yet be performed). * - * The default implementation returns noAccess to indicate that + * The default implementation returns + * agentxcpp::AbstractVariable::noAccess to indicate that * this is a read-only variable. Thus, for read-only variables this * method need not be overridden. * @@ -212,7 +227,8 @@ namespace agentxcpp /** * \brief Handle a CleanupSet request. * - * This method is called to handle an SNMP CleanupSet request. It + * This method is called when an SNMP CleanupSet request is + * received. It * shall release any ressources allocated by testset(). * * The default implementation does nothing. If no action is @@ -242,7 +258,8 @@ namespace agentxcpp /** * \brief Handle a CommitSet request. * - * This method is called to handle an SNMP CommitSet request. It + * This method is called when an SNMP CommitSet request is + * received. It * shall perform the actual write operation. * * The default implementation returns false to indicate that the @@ -275,7 +292,8 @@ namespace agentxcpp /** * \brief Handle an UndoSet request. * - * This method is called to handle an SNMP UndoSet request. It + * This method is called when an SNMP UndoSet request is received. + * It * shall undo whatever commitset() performed. It shall also release * all resources allocated by testset(). * @@ -305,4 +323,4 @@ namespace agentxcpp -#endif /* _PRIMITIVE_VARIABLE_H_ */ +#endif /* _VARIABLE_H_ */ From fe789d5d40117251821ceb2de1311e6bc5b241b9 Mon Sep 17 00:00:00 2001 From: "Tanjeff-N. Moos" Date: Thu, 20 Feb 2014 23:33:51 +0100 Subject: [PATCH 26/89] Merge *Value into *Variable. After rethinking the design, I think that distinguishing between values and variables makes no sense. E.g. IntegerValue is a class representing an SNMP Integer "value", while IntegerVariable represents an SNMP Integer variable. In a sense, IntegerValue is the type of the variable, while the class IntegerVariable is - well, the type of the variable. I decided to merge IntegerValue into IntegerVariable. I removed the AbstractValue and Value<> classes. The IntegerVariable class now inherits from AbstractVariable and is not abstract, i.e. it can be used as SNMP variable without deriving a new class from it (for simple cases). The same is of course true for the other *Value / *Variable classes. --- src/AbstractValue.hpp | 61 -- src/AbstractVariable.hpp | 41 +- src/Counter32Value.hpp | 98 --- ...unter32Value.cpp => Counter32Variable.cpp} | 11 +- src/Counter32Variable.hpp | 274 +++++- src/Counter64Value.hpp | 96 --- ...unter64Value.cpp => Counter64Variable.cpp} | 17 +- src/Counter64Variable.hpp | 274 +++++- src/Gauge32Value.hpp | 98 --- src/{Gauge32Value.cpp => Gauge32Variable.cpp} | 10 +- src/Gauge32Variable.hpp | 314 ++++++- src/IntegerValue.hpp | 115 --- src/{IntegerValue.cpp => IntegerVariable.cpp} | 10 +- src/IntegerVariable.hpp | 325 ++++++- src/IpAddressValue.hpp | 169 ---- ...AddressValue.cpp => IpAddressVariable.cpp} | 6 +- src/IpAddressVariable.hpp | 370 +++++++- src/OctetStringValue.hpp | 154 ---- ...tringValue.cpp => OctetStringVariable.cpp} | 63 +- src/OctetStringVariable.hpp | 303 ++++++- src/OidValue.hpp | 609 ------------- src/{OidValue.cpp => OidVariable.cpp} | 38 +- src/OidVariable.hpp | 808 +++++++++++++++++- src/OpaqueValue.hpp | 100 --- src/{OpaqueValue.cpp => OpaqueVariable.cpp} | 12 +- src/OpaqueVariable.hpp | 313 ++++++- src/TimeTicksValue.hpp | 97 --- ...meTicksValue.cpp => TimeTicksVariable.cpp} | 10 +- src/TimeTicksVariable.hpp | 311 ++++++- src/Variable.hpp | 326 ------- 30 files changed, 3283 insertions(+), 2150 deletions(-) delete mode 100644 src/AbstractValue.hpp delete mode 100644 src/Counter32Value.hpp rename src/{Counter32Value.cpp => Counter32Variable.cpp} (81%) delete mode 100644 src/Counter64Value.hpp rename src/{Counter64Value.cpp => Counter64Variable.cpp} (72%) delete mode 100644 src/Gauge32Value.hpp rename src/{Gauge32Value.cpp => Gauge32Variable.cpp} (83%) delete mode 100644 src/IntegerValue.hpp rename src/{IntegerValue.cpp => IntegerVariable.cpp} (83%) delete mode 100644 src/IpAddressValue.hpp rename src/{IpAddressValue.cpp => IpAddressVariable.cpp} (92%) delete mode 100644 src/OctetStringValue.hpp rename src/{OctetStringValue.cpp => OctetStringVariable.cpp} (67%) delete mode 100644 src/OidValue.hpp rename src/{OidValue.cpp => OidVariable.cpp} (90%) delete mode 100644 src/OpaqueValue.hpp rename src/{OpaqueValue.cpp => OpaqueVariable.cpp} (90%) delete mode 100644 src/TimeTicksValue.hpp rename src/{TimeTicksValue.cpp => TimeTicksVariable.cpp} (83%) delete mode 100644 src/Variable.hpp diff --git a/src/AbstractValue.hpp b/src/AbstractValue.hpp deleted file mode 100644 index 29a9970..0000000 --- a/src/AbstractValue.hpp +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright 2011-2012 Tanjeff-Nicolai Moos - * - * This file is part of the agentXcpp library. - * - * AgentXcpp is free software: you can redistribute it and/or modify - * it under the terms of the AgentXcpp library license, version 1, which - * consists of the GNU General Public License and some additional - * permissions. - * - * AgentXcpp is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * See the AgentXcpp library license in the LICENSE file of this package - * for more details. - */ -#ifndef _VALUE_H_ -#define _VALUE_H_ - -#include "binary.hpp" - -namespace agentxcpp -{ - /** - * \brief This class represents a value. - * - * This class is used as base class for the specific value types (such as - * OctetStringValue or IntegerValue). - */ - class AbstractValue - { - public: - /** - * \internal - * - * \brief Serialize the value. - * - * This function must be implemented by all derived classes. The - * function shall generate a serialized form of the value. - * - * \return The serialized form of the value. - * - * \exception None: The function shall not throw. - */ - virtual binary serialize() const = 0; - - /** - * \brief Destructor. - * - * The default implementation of this desctructor is empty. - */ - virtual ~AbstractValue() - { - } - }; -} - - -#endif diff --git a/src/AbstractVariable.hpp b/src/AbstractVariable.hpp index fa86b00..03408c0 100644 --- a/src/AbstractVariable.hpp +++ b/src/AbstractVariable.hpp @@ -21,7 +21,7 @@ #include -#include "AbstractValue.hpp" +#include "binary.hpp" namespace agentxcpp { @@ -31,6 +31,8 @@ namespace agentxcpp * This class is the base class for SNMP variable implementations. It * provides the interface which is used by agentXcpp to perform * operations on variables. + * + * \todo Explain how Variables work in general. */ class AbstractVariable { @@ -49,14 +51,12 @@ namespace agentxcpp * * This method is called when the SNMP request "Get" is received * for the - * variable. It shall return the current value of the variable. - * - * \return The current value of the variable. + * variable. It shall update the internal state. * * \exception generic_error If obtaining the current value fails. * No other exception shall be thrown. */ - virtual QSharedPointer handle_get() = 0; + virtual void handle_get() = 0; /** @@ -73,8 +73,10 @@ namespace agentxcpp * \internal * * The numeric values are given in RFC 2741, 7.2.4.1. "Subagent - * Processing of the agentx-TestSet-PDU" and must be in sync with - * the corresponding errors defined in ResponsePDU::error_t. + * Processing of the agentx-TestSet-PDU". + * + * \note These values must be in sync with the corresponding + * errors defined in agentxcpp::ResponsePDU::error_t. */ enum testset_result_t { @@ -165,8 +167,10 @@ namespace agentxcpp * subsequent operations (i.e. handle_commitset()). * * \return The result of the validation. + * + * \exception None: The function shall not throw. */ - virtual testset_result_t handle_testset(QSharedPointer) = 0; + virtual testset_result_t handle_testset(QSharedPointer) = 0; /** * \brief Release resources after a Set operation. @@ -175,6 +179,8 @@ namespace agentxcpp * is received. It shall release all resources previously allocated * by handle_testset() (if any). If no resources were allocated, * this method is not required to do anything. + * + * \exception None: The function shall not throw. */ virtual void handle_cleanupset() = 0; @@ -190,6 +196,8 @@ namespace agentxcpp * calling handle_commitset(). * * \return True on success, false otherwise. + * + * \exception None: The function shall not throw. */ virtual bool handle_commitset()= 0; @@ -201,8 +209,25 @@ namespace agentxcpp * shall undo the operation performed by handle_commitset(). * * \return True on success, false otherwise. + * + * \exception None: The function shall not throw. */ virtual bool handle_undoset() = 0; + + /** + * \internal + * + * \brief Serialize the value. + * + * This function must be implemented by all derived classes. The + * function shall generate a serialized form of the internal value. + * + * \return The serialized form of the value. + * + * \exception None: The function shall not throw. + */ + virtual binary serialize() const = 0; + }; } diff --git a/src/Counter32Value.hpp b/src/Counter32Value.hpp deleted file mode 100644 index 117a1fb..0000000 --- a/src/Counter32Value.hpp +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Copyright 2011-2012 Tanjeff-Nicolai Moos - * - * This file is part of the agentXcpp library. - * - * AgentXcpp is free software: you can redistribute it and/or modify - * it under the terms of the AgentXcpp library license, version 1, which - * consists of the GNU General Public License and some additional - * permissions. - * - * AgentXcpp is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * See the AgentXcpp library license in the LICENSE file of this package - * for more details. - */ - -#ifndef _COUNTER32_H_ -#define _COUNTER32_H_ - -#include - -#include "AbstractValue.hpp" -#include "exceptions.hpp" - -namespace agentxcpp -{ - /** - * \brief Represents an Counter32 as described in RFC 2741 - * - * \note This class has no toOid() method, because Counter32 - * objects are not allowed in INDEX clauses according to - * RFC 2578, 7.7. "Mapping of the INDEX clause". - * - */ - // TODO: RFC2578? - class Counter32Value : public AbstractValue - { - public: - /** - * \brief The counter value. - * - * According to RFC 2578, Counter32 is a non-negative 32-bit - * number. - */ - quint32 value; - - /** - * \internal - * - * \brief Create a counter without initialization. - * - * The value after creation is undefined. - */ - Counter32Value() {} - - /** - * \internal - * - * \brief Parse Constructor. - * - * This constructor parses the serialized form of the object. - * It takes an iterator, starts parsing at the position of the - * iterator and advances the iterator to the position right behind - * the object. - * - * The constructor expects valid data from the stream; if parsing - * fails, parse_error is thrown. In this case, the iterator - * position is undefined. - * - * \param pos Iterator pointing to the current stream position. - * The iterator is advanced while reading the header. - * - * \param end Iterator pointing one element past the end of the - * current stream. This is needed to mark the end of the - * buffer. - * - * \param big_endian Whether the input stream is in big endian - * format - */ - Counter32Value(binary::const_iterator& pos, - const binary::const_iterator& end, - bool big_endian=true); - - /** - * \internal - * - * \brief Encode the object as described in RFC 2741, section 5.4 - * - * This function uses big endian. - */ - virtual binary serialize() const; - }; -} - -#endif diff --git a/src/Counter32Value.cpp b/src/Counter32Variable.cpp similarity index 81% rename from src/Counter32Value.cpp rename to src/Counter32Variable.cpp index 8fa28e5..828d58e 100644 --- a/src/Counter32Value.cpp +++ b/src/Counter32Variable.cpp @@ -17,23 +17,24 @@ * for more details. */ -#include "Counter32Value.hpp" +#include "Counter32Variable.hpp" #include "util.hpp" +#include "exceptions.hpp" using namespace agentxcpp; -binary Counter32Value::serialize() const +binary Counter32Variable::serialize() const { binary serialized; // encode value (big endian) - write32(serialized, value); + write32(serialized, v); return serialized; } -Counter32Value::Counter32Value(binary::const_iterator& pos, +Counter32Variable::Counter32Variable(binary::const_iterator& pos, const binary::const_iterator& end, bool big_endian) { @@ -44,5 +45,5 @@ Counter32Value::Counter32Value(binary::const_iterator& pos, } // Get value - value = read32(pos, big_endian); + v = read32(pos, big_endian); } diff --git a/src/Counter32Variable.hpp b/src/Counter32Variable.hpp index 673d16b..dc1fe89 100644 --- a/src/Counter32Variable.hpp +++ b/src/Counter32Variable.hpp @@ -1,40 +1,288 @@ #ifndef _COUNTER32VARIABLE_H_ #define _COUNTER32VARIABLE_H_ -#include "Counter32Value.hpp" -#include "Variable.hpp" +#include "AbstractVariable.hpp" namespace agentxcpp { - - class Counter32Variable : public Variable + /** + * \brief Represents an Counter32 as described in RFC 2741. + * + * \note This class has no toOid() method, because Counter32 + * objects are not allowed in INDEX clauses according to + * RFC 2578, 7.7. "Mapping of the INDEX clause". + */ + class Counter32Variable : public AbstractVariable { + protected: + + /** + * \brief The counter value. + * + * According to RFC 2578, Counter32 is a non-negative 32-bit + * number. + */ + quint32 v; + private: - Counter32Value v; + /** + * \brief The new value for the variable in a Set operation. + * + * The Set operation is performed in up to four steps (testset, + * commitset, cleanupset, undoset). Only the testset step actually + * receives the new value. This value is stored here so that it can + * be delivered to commitset(), undoset() and cleanupset(). + */ + QSharedPointer new_value; public: - Counter32Variable(Counter32Value _value = Counter32Value()) - { - v = _value; - } + Counter32Variable(quint32 _value = 0) + : v(_value) + { + } + + /** + * \internal + * + * \brief Parse Constructor. + * + * This constructor parses the serialized form of the object. + * It takes an iterator, starts parsing at the position of the + * iterator and advances the iterator to the position right behind + * the object. + * + * The constructor expects valid data from the stream; if parsing + * fails, parse_error is thrown. In this case, the iterator + * position is undefined. + * + * \param pos Iterator pointing to the current stream position. + * The iterator is advanced while reading the header. + * + * \param end Iterator pointing one element past the end of the + * current stream. This is needed to mark the end of the + * buffer. + * + * \param big_endian Whether the input stream is in big endian + * format + */ + Counter32Variable(binary::const_iterator& pos, + const binary::const_iterator& end, + bool big_endian=true); - void setValue(Counter32Value _value) + /** + * \internal + * + * \brief Encode the object as described in RFC 2741, section 5.4 + * + * This function uses big endian. + */ + virtual binary serialize() const; + + void setValue(quint32 _value) { v = _value; } - virtual Counter32Value get() + virtual quint32 value() { return v; } - virtual Counter32Value value() + /** + * \internal + * + * \brief Handle a Get Request. + * + * This function calls get() to obtain the new value, + * converts it to QSharedPointer and returns it. + */ + virtual void handle_get() { - return v; + this->get(); + } + + /** + * \brief Handle a Get request. + * + * This method is called when an SNMP Get request is received. + * It shall + * return the current value of the variable. + * + * \note This method is pure virtual and thus \e must be + * implemented. It is not possible to implement write-only + * SNMP variables. + * + * \return The value of the variable. + */ + virtual void get() + { + } + + /** + * \internal + * + * \brief Handle a TestSet request. + * + * This function converts the argument to QSharedPointer() and + * calls + * testset() with the converted value. If conversion fails, + * testset() is not called. This function also stores the given + * value to the new_value member. + * + * \param v The new value for the variable. + * + * \return agentxcpp::AbstractVariable::wrongType if the conversion + * fails. Otherwise, + * the result of + * testset() is + * returned. + */ + virtual testset_result_t handle_testset(QSharedPointer _v) + { + new_value = qSharedPointerDynamicCast(_v); + if (new_value) + { + // Type matches variable + return testset(new_value); + } + else + { + // Wrong type + return wrongType; + } + + } + + /** + * \brief Handle a TestSet request. + * + * This method is called when an SNMP TestSet request is received. + * It + * shall check whether a Set operation is possible for the + * variable. It shall acquire the resources needed to perform the + * Set operation (but the Set shall not yet be performed). + * + * The default implementation returns + * agentxcpp::AbstractVariable::noAccess to indicate that + * this is a read-only variable. Thus, for read-only variables this + * method need not be overridden. + * + * \param v The new value for the object. + * + * \return The result of the check. + */ + virtual testset_result_t testset(QSharedPointer _v) + { + return noAccess; + } + + /** + * \internal + * + * \brief Handle a CleanupSet request. + * + * This function calls cleanupset() with the value from the last + * handle_testset() invokation. + */ + virtual void handle_cleanupset() + { + cleanupset(new_value); + } + + /** + * \brief Handle a CleanupSet request. + * + * This method is called when an SNMP CleanupSet request is + * received. It + * shall release any ressources allocated by testset(). + * + * The default implementation does nothing. If no action is + * required to perform the CleanupSet operaiton, this method need + * not be overridden. + * + * \param v The new value for the object. + */ + virtual void cleanupset(QSharedPointer _v) + { + return; + } + + /** + * \internal + * + * \brief Handle a CommitSet request. + * + * This function calls commitset() with the value from the last + * handle_testset() Invocation and returns its return value. + */ + virtual bool handle_commitset() + { + return commitset(new_value); } + /** + * \brief Handle a CommitSet request. + * + * This method is called when an SNMP CommitSet request is + * received. It + * shall perform the actual write operation. + * + * The default implementation returns false to indicate that the + * operation failed. To implement a writable SNMP variable this + * method must be overridden. + * + * \param v The new value for the object. + * + * \return True if the operation succeeded, false otherwise. + */ + virtual bool commitset(QSharedPointer _v) + { + return false; + } + + /** + * \internal + * + * \brief Handle a UndoSet request. + * + * This function calls undoset() with the value from the last + * handle_testset() invocation and returns its return value. + * + */ + virtual bool handle_undoset() + { + return undoset(new_value); + } + + /** + * \brief Handle an UndoSet request. + * + * This method is called when an SNMP UndoSet request is received. + * It + * shall undo whatever commitset() performed. It shall also release + * all resources allocated by testset(). + * + * The default implementation returns false to indicate that + * the operation failed. It is strongly recommended that writable + * variables override this method. + * + * \internal + * + * A default implementation is provided to allow implementing + * read-only variables. + * + * \endinternal + * + * \param v The new value for the object. + * + * \return True on success, false otherwise. + */ + virtual bool undoset(QSharedPointer _v) + { + return false; + } }; } #endif // _COUNTER32VARIABLE_H_ diff --git a/src/Counter64Value.hpp b/src/Counter64Value.hpp deleted file mode 100644 index 35a9d00..0000000 --- a/src/Counter64Value.hpp +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright 2011-2012 Tanjeff-Nicolai Moos - * - * This file is part of the agentXcpp library. - * - * AgentXcpp is free software: you can redistribute it and/or modify - * it under the terms of the AgentXcpp library license, version 1, which - * consists of the GNU General Public License and some additional - * permissions. - * - * AgentXcpp is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * See the AgentXcpp library license in the LICENSE file of this package - * for more details. - */ - -#ifndef _COUNTER64_H_ -#define _COUNTER64_H_ - -#include - -#include "AbstractValue.hpp" -#include "exceptions.hpp" - -namespace agentxcpp -{ - /** - * \brief Represents an Counter64 as descibed in RFC 2741 - * - * \note This class has no toOid() method, because Counter64 - * objects are not allowed in INDEX clauses according to - * RFC 2578, 7.7. "Mapping of the INDEX clause". - */ - class Counter64Value : public AbstractValue - { - public: - /** - * \brief The counter value. - * - * According to RFC 2578, Counter64 is a non-negative 64-bit - * number. - */ - quint64 value; - - /** - * \internal - * - * \brief Create a counter without initialization. - * - * The value after creation is undefined. - */ - Counter64Value() {} - - /** - * \internal - * - * \brief Parse Constructor. - * - * This constructor parses the serialized form of the object. - * It takes an iterator, starts parsing at the position of the - * iterator and advances the iterator to the position right behind - * the object. - * - * The constructor expects valid data from the stream; if parsing - * fails, parse_error is thrown. In this case, the iterator - * position is undefined. - * - * \param pos Iterator pointing to the current stream position. - * The iterator is advanced while reading the header. - * - * \param end Iterator pointing one element past the end of the - * current stream. This is needed to mark the end of the - * buffer. - * - * \param big_endian Whether the input stream is in big endian - * format - */ - Counter64Value(binary::const_iterator& pos, - const binary::const_iterator& end, - bool big_endian=true); - - /** - * \internal - * - * \brief Encode the object as described in RFC 2741, section 5.4 - * - * This function uses big endian. - */ - virtual binary serialize() const; - }; -} - -#endif diff --git a/src/Counter64Value.cpp b/src/Counter64Variable.cpp similarity index 72% rename from src/Counter64Value.cpp rename to src/Counter64Variable.cpp index 390f642..4110228 100644 --- a/src/Counter64Value.cpp +++ b/src/Counter64Variable.cpp @@ -17,33 +17,34 @@ * for more details. */ -#include "Counter64Value.hpp" +#include "Counter64Variable.hpp" #include "util.hpp" +#include "exceptions.hpp" using namespace agentxcpp; -binary Counter64Value::serialize() const +binary Counter64Variable::serialize() const { binary serialized; // encode value (big endian) - write64(serialized, value); + write64(serialized, v); return serialized; } -Counter64Value::Counter64Value(binary::const_iterator& pos, - const binary::const_iterator& end, - bool big_endian) +Counter64Variable::Counter64Variable(binary::const_iterator& pos, + const binary::const_iterator& end, + bool big_endian) { // Are there at least 8 bytes in the buffer? if(end - pos < 8) { - throw(parse_error()); + throw(parse_error()); } // Get value - value = read64(pos, big_endian); + v = read64(pos, big_endian); } diff --git a/src/Counter64Variable.hpp b/src/Counter64Variable.hpp index 6e5dcd0..9dcd6a5 100644 --- a/src/Counter64Variable.hpp +++ b/src/Counter64Variable.hpp @@ -1,40 +1,288 @@ #ifndef _COUNTER64VARIABLE_H_ #define _COUNTER64VARIABLE_H_ -#include "Counter64Value.hpp" -#include "Variable.hpp" +#include "AbstractVariable.hpp" namespace agentxcpp { - - class Counter64Variable : public Variable + /** + * \brief Represents an Counter64 as described in RFC 2741. + * + * \note This class has no toOid() method, because Counter64 + * objects are not allowed in INDEX clauses according to + * RFC 2578, 7.7. "Mapping of the INDEX clause". + */ + class Counter64Variable : public AbstractVariable { + protected: + + /** + * \brief The counter value. + * + * According to RFC 2578, Counter64 is a non-negative 64-bit + * number. + */ + quint64 v; + private: - Counter64Value v; + /** + * \brief The new value for the variable in a Set operation. + * + * The Set operation is performed in up to four steps (testset, + * commitset, cleanupset, undoset). Only the testset step actually + * receives the new value. This value is stored here so that it can + * be delivered to commitset(), undoset() and cleanupset(). + */ + QSharedPointer new_value; public: - Counter64Variable(Counter64Value _value = Counter64Value()) - { - v = _value; - } + Counter64Variable(quint64 _value = 0) + : v(_value) + { + } + + /** + * \internal + * + * \brief Parse Constructor. + * + * This constructor parses the serialized form of the object. + * It takes an iterator, starts parsing at the position of the + * iterator and advances the iterator to the position right behind + * the object. + * + * The constructor expects valid data from the stream; if parsing + * fails, parse_error is thrown. In this case, the iterator + * position is undefined. + * + * \param pos Iterator pointing to the current stream position. + * The iterator is advanced while reading the header. + * + * \param end Iterator pointing one element past the end of the + * current stream. This is needed to mark the end of the + * buffer. + * + * \param big_endian Whether the input stream is in big endian + * format + */ + Counter64Variable(binary::const_iterator& pos, + const binary::const_iterator& end, + bool big_endian=true); - void setValue(Counter64Value _value) + /** + * \internal + * + * \brief Encode the object as described in RFC 2741, section 5.4 + * + * This function uses big endian. + */ + virtual binary serialize() const; + + void setValue(quint64 _value) { v = _value; } - virtual Counter64Value get() + virtual quint64 value() { return v; } - virtual Counter64Value value() + /** + * \internal + * + * \brief Handle a Get Request. + * + * This function calls get() to obtain the new value, + * converts it to QSharedPointer and returns it. + */ + virtual void handle_get() { - return v; + this->get(); + } + + /** + * \brief Handle a Get request. + * + * This method is called when an SNMP Get request is received. + * It shall + * return the current value of the variable. + * + * \note This method is pure virtual and thus \e must be + * implemented. It is not possible to implement write-only + * SNMP variables. + * + * \return The value of the variable. + */ + virtual void get() + { + } + + /** + * \internal + * + * \brief Handle a TestSet request. + * + * This function converts the argument to QSharedPointer() and + * calls + * testset() with the converted value. If conversion fails, + * testset() is not called. This function also stores the given + * value to the new_value member. + * + * \param v The new value for the variable. + * + * \return agentxcpp::AbstractVariable::wrongType if the conversion + * fails. Otherwise, + * the result of + * testset() is + * returned. + */ + virtual testset_result_t handle_testset(QSharedPointer _v) + { + new_value = qSharedPointerDynamicCast(_v); + if (new_value) + { + // Type matches variable + return testset(new_value); + } + else + { + // Wrong type + return wrongType; + } + + } + + /** + * \brief Handle a TestSet request. + * + * This method is called when an SNMP TestSet request is received. + * It + * shall check whether a Set operation is possible for the + * variable. It shall acquire the resources needed to perform the + * Set operation (but the Set shall not yet be performed). + * + * The default implementation returns + * agentxcpp::AbstractVariable::noAccess to indicate that + * this is a read-only variable. Thus, for read-only variables this + * method need not be overridden. + * + * \param v The new value for the object. + * + * \return The result of the check. + */ + virtual testset_result_t testset(QSharedPointer _v) + { + return noAccess; + } + + /** + * \internal + * + * \brief Handle a CleanupSet request. + * + * This function calls cleanupset() with the value from the last + * handle_testset() invokation. + */ + virtual void handle_cleanupset() + { + cleanupset(new_value); + } + + /** + * \brief Handle a CleanupSet request. + * + * This method is called when an SNMP CleanupSet request is + * received. It + * shall release any ressources allocated by testset(). + * + * The default implementation does nothing. If no action is + * required to perform the CleanupSet operaiton, this method need + * not be overridden. + * + * \param v The new value for the object. + */ + virtual void cleanupset(QSharedPointer _v) + { + return; + } + + /** + * \internal + * + * \brief Handle a CommitSet request. + * + * This function calls commitset() with the value from the last + * handle_testset() Invocation and returns its return value. + */ + virtual bool handle_commitset() + { + return commitset(new_value); } + /** + * \brief Handle a CommitSet request. + * + * This method is called when an SNMP CommitSet request is + * received. It + * shall perform the actual write operation. + * + * The default implementation returns false to indicate that the + * operation failed. To implement a writable SNMP variable this + * method must be overridden. + * + * \param v The new value for the object. + * + * \return True if the operation succeeded, false otherwise. + */ + virtual bool commitset(QSharedPointer _v) + { + return false; + } + + /** + * \internal + * + * \brief Handle a UndoSet request. + * + * This function calls undoset() with the value from the last + * handle_testset() invocation and returns its return value. + * + */ + virtual bool handle_undoset() + { + return undoset(new_value); + } + + /** + * \brief Handle an UndoSet request. + * + * This method is called when an SNMP UndoSet request is received. + * It + * shall undo whatever commitset() performed. It shall also release + * all resources allocated by testset(). + * + * The default implementation returns false to indicate that + * the operation failed. It is strongly recommended that writable + * variables override this method. + * + * \internal + * + * A default implementation is provided to allow implementing + * read-only variables. + * + * \endinternal + * + * \param v The new value for the object. + * + * \return True on success, false otherwise. + */ + virtual bool undoset(QSharedPointer _v) + { + return false; + } }; } #endif // _COUNTER64VARIABLE_H_ diff --git a/src/Gauge32Value.hpp b/src/Gauge32Value.hpp deleted file mode 100644 index c16a98a..0000000 --- a/src/Gauge32Value.hpp +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Copyright 2011-2012 Tanjeff-Nicolai Moos - * - * This file is part of the agentXcpp library. - * - * AgentXcpp is free software: you can redistribute it and/or modify - * it under the terms of the AgentXcpp library license, version 1, which - * consists of the GNU General Public License and some additional - * permissions. - * - * AgentXcpp is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * See the AgentXcpp library license in the LICENSE file of this package - * for more details. - */ - -#ifndef _GAUGE32_H_ -#define _GAUGE32_H_ - -#include - -#include "AbstractValue.hpp" -#include "exceptions.hpp" - -namespace agentxcpp -{ - /** - * \brief Represents a Gauge32 as descibed in RFC 2741 - * - * \note This class has no toOid() method, because RFC 2578, - * 7.7. "Mapping of the INDEX clause" does not describe - * how to convert Gauge32 to an OID. - * - */ - class Gauge32Value : public AbstractValue - { - public: - /** - * \brief The value. - * - * According to RFC 2578, Gauge32 is a non-negative 32-bit - * number. - */ - quint32 value; - - public: - /** - * \internal - * - * \brief Create a Gauge32Value without initialization. - * - * The value after creation is undefined. - */ - Gauge32Value() {} - - /** - * \internal - * - * \brief Parse Constructor. - * - * This constructor parses the serialized form of the object. - * It takes an iterator, starts parsing at the position of the - * iterator and advances the iterator to the position right behind - * the object. - * - * The constructor expects valid data from the stream; if parsing - * fails, parse_error is thrown. In this case, the iterator - * position is undefined. - * - * \param pos Iterator pointing to the current stream position. - * The iterator is advanced while reading the header. - * - * \param end Iterator pointing one element past the end of the - * current stream. This is needed to mark the end of the - * buffer. - * - * \param big_endian Whether the input stream is in big endian - * format - */ - Gauge32Value(binary::const_iterator& pos, - const binary::const_iterator& end, - bool big_endian=true); - - /** - * \internal - * - * \brief Encode the object as described in RFC 2741, section 5.4 - * - * This function uses big endian. - */ - virtual binary serialize() const; - }; -} - -#endif diff --git a/src/Gauge32Value.cpp b/src/Gauge32Variable.cpp similarity index 83% rename from src/Gauge32Value.cpp rename to src/Gauge32Variable.cpp index a22a931..4cb4a6a 100644 --- a/src/Gauge32Value.cpp +++ b/src/Gauge32Variable.cpp @@ -17,23 +17,23 @@ * for more details. */ -#include "Gauge32Value.hpp" +#include "Gauge32Variable.hpp" #include "util.hpp" using namespace agentxcpp; -binary Gauge32Value::serialize() const +binary Gauge32Variable::serialize() const { binary serialized; // encode value (big endian) - write32(serialized, value); + write32(serialized, v); return serialized; } -Gauge32Value::Gauge32Value(binary::const_iterator& pos, +Gauge32Variable::Gauge32Variable(binary::const_iterator& pos, const binary::const_iterator& end, bool big_endian) { @@ -44,5 +44,5 @@ Gauge32Value::Gauge32Value(binary::const_iterator& pos, } // Get value - value = read32(pos, big_endian); + v = read32(pos, big_endian); } diff --git a/src/Gauge32Variable.hpp b/src/Gauge32Variable.hpp index fb51c42..ec405d5 100644 --- a/src/Gauge32Variable.hpp +++ b/src/Gauge32Variable.hpp @@ -1,40 +1,320 @@ +/* + * Copyright 2011-2012 Tanjeff-Nicolai Moos + * + * This file is part of the agentXcpp library. + * + * AgentXcpp is free software: you can redistribute it and/or modify + * it under the terms of the AgentXcpp library license, version 1, which + * consists of the GNU General Public License and some additional + * permissions. + * + * AgentXcpp is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * See the AgentXcpp library license in the LICENSE file of this package + * for more details. + */ + #ifndef _GAUGE32VARIABLE_H_ #define _GAUGE32VARIABLE_H_ -#include "Gauge32Value.hpp" -#include "Variable.hpp" +#include + +#include "AbstractVariable.hpp" +#include "exceptions.hpp" namespace agentxcpp { - - class Gauge32Variable : public Variable + /** + * \brief Represents a Gauge32 as described in RFC 2741 + * + * \note This class has no toOid() method, because RFC 2578, + * 7.7. "Mapping of the INDEX clause" does not describe + * how to convert Gauge32 to an OID. + * + */ + class Gauge32Variable : public AbstractVariable { - private: + protected: + /** + * \brief The value. + * + * According to RFC 2578, Gauge32 is a non-negative 32-bit + * number. + */ + quint32 v; + + private: + + /** + * \brief The new value for the variable in a Set operation. + * + * The Set operation is performed in up to four steps (testset, + * commitset, cleanupset, undoset). Only the testset step actually + * receives the new value. This value is stored here so that it can + * be delivered to commitset(), undoset() and cleanupset(). + */ + QSharedPointer new_value; - Gauge32Value v; - public: + public: - Gauge32Variable(Gauge32Value _value = Gauge32Value()) - { - v = _value; - } + /** + * \internal + * + * \brief Create a Gauge32Value without initialization. + * + * The value after creation is 0. + */ + Gauge32Variable() + : v(0) + { + } - void setValue(Gauge32Value _value) + /** + * \internal + * + * \brief Parse Constructor. + * + * This constructor parses the serialized form of the object. + * It takes an iterator, starts parsing at the position of the + * iterator and advances the iterator to the position right behind + * the object. + * + * The constructor expects valid data from the stream; if parsing + * fails, parse_error is thrown. In this case, the iterator + * position is undefined. + * + * \param pos Iterator pointing to the current stream position. + * The iterator is advanced while reading the header. + * + * \param end Iterator pointing one element past the end of the + * current stream. This is needed to mark the end of the + * buffer. + * + * \param big_endian Whether the input stream is in big endian + * format + */ + Gauge32Variable(binary::const_iterator& pos, + const binary::const_iterator& end, + bool big_endian=true); + + /** + * \internal + * + * \brief Encode the object as described in RFC 2741, section 5.4 + * + * This function uses big endian. + */ + virtual binary serialize() const; + + void setValue(quint32 _v) { - v = _value; + v = _v; } - virtual Gauge32Value get() + quint32 value() { return v; } - virtual Gauge32Value value() + /** + * \internal + * + * \brief Handle a Get Request. + * + * This function calls get() to obtain the new value, + * converts it to QSharedPointer and returns it. + */ + virtual void handle_get() { - return v; + this->get(); + } + + /** + * \brief Handle a Get request. + * + * This method is called when an SNMP Get request is received. + * It shall + * return the current value of the variable. + * + * \note This method is pure virtual and thus \e must be + * implemented. It is not possible to implement write-only + * SNMP variables. + * + * \return The value of the variable. + */ + virtual void get() + { + } + + /** + * \internal + * + * \brief Handle a TestSet request. + * + * This function converts the argument to QSharedPointer() and + * calls + * testset() with the converted value. If conversion fails, + * testset() is not called. This function also stores the given + * value to the new_value member. + * + * \param v The new value for the variable. + * + * \return agentxcpp::AbstractVariable::wrongType if the conversion + * fails. Otherwise, + * the result of + * testset() is + * returned. + */ + virtual testset_result_t handle_testset(QSharedPointer _v) + { + new_value = qSharedPointerDynamicCast(_v); + if (new_value) + { + // Type matches variable + return testset(new_value); + } + else + { + // Wrong type + return wrongType; + } + + } + + /** + * \brief Handle a TestSet request. + * + * This method is called when an SNMP TestSet request is received. + * It + * shall check whether a Set operation is possible for the + * variable. It shall acquire the resources needed to perform the + * Set operation (but the Set shall not yet be performed). + * + * The default implementation returns + * agentxcpp::AbstractVariable::noAccess to indicate that + * this is a read-only variable. Thus, for read-only variables this + * method need not be overridden. + * + * \param v The new value for the object. + * + * \return The result of the check. + */ + virtual testset_result_t testset(QSharedPointer _v) + { + return noAccess; + } + + /** + * \internal + * + * \brief Handle a CleanupSet request. + * + * This function calls cleanupset() with the value from the last + * handle_testset() invokation. + */ + virtual void handle_cleanupset() + { + cleanupset(new_value); + } + + /** + * \brief Handle a CleanupSet request. + * + * This method is called when an SNMP CleanupSet request is + * received. It + * shall release any ressources allocated by testset(). + * + * The default implementation does nothing. If no action is + * required to perform the CleanupSet operaiton, this method need + * not be overridden. + * + * \param v The new value for the object. + */ + virtual void cleanupset(QSharedPointer _v) + { + return; + } + + /** + * \internal + * + * \brief Handle a CommitSet request. + * + * This function calls commitset() with the value from the last + * handle_testset() Invocation and returns its return value. + */ + virtual bool handle_commitset() + { + return commitset(new_value); + } + + /** + * \brief Handle a CommitSet request. + * + * This method is called when an SNMP CommitSet request is + * received. It + * shall perform the actual write operation. + * + * The default implementation returns false to indicate that the + * operation failed. To implement a writable SNMP variable this + * method must be overridden. + * + * \param v The new value for the object. + * + * \return True if the operation succeeded, false otherwise. + */ + virtual bool commitset(QSharedPointer _v) + { + return false; + } + + /** + * \internal + * + * \brief Handle a UndoSet request. + * + * This function calls undoset() with the value from the last + * handle_testset() invocation and returns its return value. + * + */ + virtual bool handle_undoset() + { + return undoset(new_value); + } + + /** + * \brief Handle an UndoSet request. + * + * This method is called when an SNMP UndoSet request is received. + * It + * shall undo whatever commitset() performed. It shall also release + * all resources allocated by testset(). + * + * The default implementation returns false to indicate that + * the operation failed. It is strongly recommended that writable + * variables override this method. + * + * \internal + * + * A default implementation is provided to allow implementing + * read-only variables. + * + * \endinternal + * + * \param v The new value for the object. + * + * \return True on success, false otherwise. + */ + virtual bool undoset(QSharedPointer _v) + { + return false; } }; } -#endif // _GAUGE32VARIABLE_H_ + +#endif // _GAUGE32VARIABLE_H_ diff --git a/src/IntegerValue.hpp b/src/IntegerValue.hpp deleted file mode 100644 index 81b0253..0000000 --- a/src/IntegerValue.hpp +++ /dev/null @@ -1,115 +0,0 @@ -/* - * Copyright 2011-2012 Tanjeff-Nicolai Moos - * - * This file is part of the agentXcpp library. - * - * AgentXcpp is free software: you can redistribute it and/or modify - * it under the terms of the AgentXcpp library license, version 1, which - * consists of the GNU General Public License and some additional - * permissions. - * - * AgentXcpp is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * See the AgentXcpp library license in the LICENSE file of this package - * for more details. - */ - -#ifndef _INTEGERVALUE_H_ -#define _INTEGERVALUE_H_ - -#include - -#include "AbstractValue.hpp" -#include "exceptions.hpp" -#include "OidValue.hpp" - -namespace agentxcpp -{ - /** - * \brief Represents an Integer as described in RFC 2741 - */ - class IntegerValue : public AbstractValue - { - public: - /** - * \brief The Integer value. - * - * According to RFC 2578, INTEGER is a signed 32-bit number. - */ - qint32 value; - - /** - * \internal - * - * \brief Create an IntegerValue object. - * - * The default value of the new object is 0. - * - * \exception None. - */ - IntegerValue(qint32 _value=0) :value(_value) {} - - /** - * \internal - * - * \brief Encode the object as described in RFC 2741, section 5.4 - * - * This function uses big endian. - */ - virtual binary serialize() const; - - /** - * \internal - * - * \brief Parse Constructor. - * - * This constructor parses the serialized form of the object. - * It takes an iterator, starts parsing at the position of the - * iterator and advances the iterator to the position right behind - * the object. - * - * The constructor expects valid data from the stream; if parsing - * fails, parse_error is thrown. In this case, the iterator - * position is undefined. - * - * \param pos Iterator pointing to the current stream position. - * The iterator is advanced while reading the header. - * - * \param end Iterator pointing one element past the end of the - * current stream. This is needed to mark the end of the - * buffer. - * - * \param big_endian Whether the input stream is in big endian - * format - */ - IntegerValue(binary::const_iterator& pos, - const binary::const_iterator& end, - bool big_endian=true); - - /** - * \brief Convert the value to an OID. - * - * The conversion is done according to RFC 2578, - * 7.7. "Mapping of the INDEX clause". The value is - * converted to an Oid with a single subid. Note that - * INTEGER values are signed, while subids are not. - * A negative value with be converted to big unsigned - * subid. - * - * \note If an INTEGER is used in an INDEX clause, the - * value 0 should be avoided according to - * RFC 2578, 7.7. "Mapping of the INDEX clause". - */ - OidValue toOid() const - { - OidValue oid; - oid.push_back(value); - return oid; - } - }; -} - -#endif diff --git a/src/IntegerValue.cpp b/src/IntegerVariable.cpp similarity index 83% rename from src/IntegerValue.cpp rename to src/IntegerVariable.cpp index c6d2385..056962a 100644 --- a/src/IntegerValue.cpp +++ b/src/IntegerVariable.cpp @@ -17,23 +17,23 @@ * for more details. */ -#include "IntegerValue.hpp" +#include "IntegerVariable.hpp" #include "util.hpp" using namespace agentxcpp; -binary IntegerValue::serialize() const +binary IntegerVariable::serialize() const { binary serialized; // encode value (big endian) - write32(serialized, value); + write32(serialized, v); return serialized; } -IntegerValue::IntegerValue(binary::const_iterator& pos, +IntegerVariable::IntegerVariable(binary::const_iterator& pos, const binary::const_iterator& end, bool big_endian) { @@ -44,5 +44,5 @@ IntegerValue::IntegerValue(binary::const_iterator& pos, } // Get value - value = read32(pos, big_endian); + v = read32(pos, big_endian); } diff --git a/src/IntegerVariable.hpp b/src/IntegerVariable.hpp index 45db4f0..d8b00ff 100644 --- a/src/IntegerVariable.hpp +++ b/src/IntegerVariable.hpp @@ -1,42 +1,335 @@ +/* + * Copyright 2011-2012 Tanjeff-Nicolai Moos + * + * This file is part of the agentXcpp library. + * + * AgentXcpp is free software: you can redistribute it and/or modify + * it under the terms of the AgentXcpp library license, version 1, which + * consists of the GNU General Public License and some additional + * permissions. + * + * AgentXcpp is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * See the AgentXcpp library license in the LICENSE file of this package + * for more details. + */ + #ifndef _INTEGERVARIABLE_H_ #define _INTEGERVARIABLE_H_ -#include "IntegerValue.hpp" -#include "Variable.hpp" +#include + +#include "AbstractVariable.hpp" +#include "exceptions.hpp" +#include "OidVariable.hpp" namespace agentxcpp { - - class IntegerVariable : public Variable + /** + * \brief Represents an Integer as described in RFC 2741 + */ + class IntegerVariable : public AbstractVariable { + protected: + /** + * \brief The Integer value. + * + * According to RFC 2578, INTEGER is a signed 32-bit number. + */ + qint32 v; + private: - IntegerValue v; + /** + * \brief The new value for the variable in a Set operation. + * + * The Set operation is performed in up to four steps (testset, + * commitset, cleanupset, undoset). Only the testset step actually + * receives the new value. This value is stored here so that it can + * be delivered to commitset(), undoset() and cleanupset(). + */ + QSharedPointer new_value; - public: + public: - IntegerVariable(IntegerValue _value = IntegerValue()) - { - v = _value; - } + /** + * \internal + * + * \brief Create an IntegerValue object. + * + * The default value of the new object is 0. + * + * \exception None. + */ + IntegerVariable(qint32 _value=0) :v(_value) {} - void setValue(IntegerValue _value) + /** + * \internal + * + * \brief Encode the object as described in RFC 2741, section 5.4 + * + * This function uses big endian. + */ + virtual binary serialize() const; + + /** + * \internal + * + * \brief Parse Constructor. + * + * This constructor parses the serialized form of the object. + * It takes an iterator, starts parsing at the position of the + * iterator and advances the iterator to the position right behind + * the object. + * + * The constructor expects valid data from the stream; if parsing + * fails, parse_error is thrown. In this case, the iterator + * position is undefined. + * + * \param pos Iterator pointing to the current stream position. + * The iterator is advanced while reading the header. + * + * \param end Iterator pointing one element past the end of the + * current stream. This is needed to mark the end of the + * buffer. + * + * \param big_endian Whether the input stream is in big endian + * format + */ + IntegerVariable(binary::const_iterator& pos, + const binary::const_iterator& end, + bool big_endian=true); + + /** + * \brief Convert the value to an OID. + * + * The conversion is done according to RFC 2578, + * 7.7. "Mapping of the INDEX clause". The value is + * converted to an Oid with a single subid. Note that + * INTEGER values are signed, while subids are not. + * A negative value with be converted to big unsigned + * subid. + * + * \note If an INTEGER is used in an INDEX clause, the + * value 0 should be avoided according to + * RFC 2578, 7.7. "Mapping of the INDEX clause". + */ + OidVariable toOid() const + { + OidVariable oid; + oid.push_back(v); + return oid; + } + + void setValue(qint32 _value) { v = _value; } - virtual IntegerValue get() + qint32 value() { return v; } - virtual IntegerValue value() + /** + * \internal + * + * \brief Handle a Get Request. + * + * This function calls get() to obtain the new value, + * converts it to QSharedPointer and returns it. + */ + virtual void handle_get() { - return v; + this->get(); } - }; + /** + * \brief Handle a Get request. + * + * This method is called when an SNMP Get request is received. + * It shall + * return the current value of the variable. + * + * \note This method is pure virtual and thus \e must be + * implemented. It is not possible to implement write-only + * SNMP variables. + * + * \return The value of the variable. + */ + virtual void get() + { + } + + /** + * \internal + * + * \brief Handle a TestSet request. + * + * This function converts the argument to QSharedPointer() and + * calls + * testset() with the converted value. If conversion fails, + * testset() is not called. This function also stores the given + * value to the new_value member. + * + * \param v The new value for the variable. + * + * \return agentxcpp::AbstractVariable::wrongType if the conversion + * fails. Otherwise, + * the result of + * testset() is + * returned. + */ + virtual testset_result_t handle_testset(QSharedPointer _v) + { + new_value = qSharedPointerDynamicCast(_v); + if (new_value) + { + // Type matches variable + return testset(new_value); + } + else + { + // Wrong type + return wrongType; + } + + } + + /** + * \brief Handle a TestSet request. + * + * This method is called when an SNMP TestSet request is received. + * It + * shall check whether a Set operation is possible for the + * variable. It shall acquire the resources needed to perform the + * Set operation (but the Set shall not yet be performed). + * + * The default implementation returns + * agentxcpp::AbstractVariable::noAccess to indicate that + * this is a read-only variable. Thus, for read-only variables this + * method need not be overridden. + * + * \param v The new value for the object. + * + * \return The result of the check. + */ + virtual testset_result_t testset(QSharedPointer _v) + { + return noAccess; + } + + /** + * \internal + * + * \brief Handle a CleanupSet request. + * + * This function calls cleanupset() with the value from the last + * handle_testset() invokation. + */ + virtual void handle_cleanupset() + { + cleanupset(new_value); + } + + /** + * \brief Handle a CleanupSet request. + * + * This method is called when an SNMP CleanupSet request is + * received. It + * shall release any ressources allocated by testset(). + * + * The default implementation does nothing. If no action is + * required to perform the CleanupSet operaiton, this method need + * not be overridden. + * + * \param v The new value for the object. + */ + virtual void cleanupset(QSharedPointer _v) + { + return; + } + /** + * \internal + * + * \brief Handle a CommitSet request. + * + * This function calls commitset() with the value from the last + * handle_testset() Invocation and returns its return value. + */ + virtual bool handle_commitset() + { + return commitset(new_value); + } + + /** + * \brief Handle a CommitSet request. + * + * This method is called when an SNMP CommitSet request is + * received. It + * shall perform the actual write operation. + * + * The default implementation returns false to indicate that the + * operation failed. To implement a writable SNMP variable this + * method must be overridden. + * + * \param v The new value for the object. + * + * \return True if the operation succeeded, false otherwise. + */ + virtual bool commitset(QSharedPointer _v) + { + return false; + } + + /** + * \internal + * + * \brief Handle a UndoSet request. + * + * This function calls undoset() with the value from the last + * handle_testset() invocation and returns its return value. + * + */ + virtual bool handle_undoset() + { + return undoset(new_value); + } + + /** + * \brief Handle an UndoSet request. + * + * This method is called when an SNMP UndoSet request is received. + * It + * shall undo whatever commitset() performed. It shall also release + * all resources allocated by testset(). + * + * The default implementation returns false to indicate that + * the operation failed. It is strongly recommended that writable + * variables override this method. + * + * \internal + * + * A default implementation is provided to allow implementing + * read-only variables. + * + * \endinternal + * + * \param v The new value for the object. + * + * \return True on success, false otherwise. + */ + virtual bool undoset(QSharedPointer _v) + { + return false; + } + + + }; } -#endif // _INTEGER_H_ +#endif // _INTEGERVARIABLE_H_ diff --git a/src/IpAddressValue.hpp b/src/IpAddressValue.hpp deleted file mode 100644 index 8b51e38..0000000 --- a/src/IpAddressValue.hpp +++ /dev/null @@ -1,169 +0,0 @@ -/* - * Copyright 2011-2012 Tanjeff-Nicolai Moos - * - * This file is part of the agentXcpp library. - * - * AgentXcpp is free software: you can redistribute it and/or modify - * it under the terms of the AgentXcpp library license, version 1, which - * consists of the GNU General Public License and some additional - * permissions. - * - * AgentXcpp is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * See the AgentXcpp library license in the LICENSE file of this package - * for more details. - */ - -#ifndef _IPADDRESS_H_ -#define _IPADDRESS_H_ - -#include - -#include "AbstractValue.hpp" -#include "exceptions.hpp" -#include "OidValue.hpp" - -namespace agentxcpp -{ - /** - * \brief Represents an IP address as described in RFC 2741, section 5.4 - */ - class IpAddressValue : public AbstractValue - { - private: - /** - * \brief Hide default constructor - */ - IpAddressValue(); - - /** - * \brief The IP address. - * - * According to RFC 2578, IpAddress is a 32-bit number. - */ - quint8 address[4]; // only IPv4 - - public: - /** - * \internal - * - * \brief Parse Constructor. - * - * This constructor parses the serialized form of the object. - * It takes an iterator, starts parsing at the position of the - * iterator and advances the iterator to the position right behind - * the object. - * - * The constructor expects valid data from the stream; if parsing - * fails, parse_error is thrown. In this case, the iterator - * position is undefined. - * - * \param pos Iterator pointing to the current stream position. - * The iterator is advanced while reading the header. - * - * \param end Iterator pointing one element past the end of the - * current stream. This is needed to mark the end of the - * buffer. - * - * \param big_endian Whether the input stream is in big endian - * format - */ - IpAddressValue(binary::const_iterator& pos, - const binary::const_iterator& end, - bool big_endian=true); - - /** - * \internal - * - * \brief Encode the object as described in RFC 2741, section 5.4 / - * 5.3 - * - * Note: - * We always use big endian. - */ - binary serialize() const; - - /** - * \brief Construct an IpAddressValue object. - * - * The stored IpAddress is initialized to "a.b.c.d". - * - * \exception None. - */ - IpAddressValue(quint8 a, - quint8 b, - quint8 c, - quint8 d) - { - address[0] = a; - address[1] = b; - address[2] = c; - address[3] = d; - } - - /** - * \brief Set the IpAddress. - * - * The stored IpAddress is updated to "a.b.c.d". - * - * \exception None. - */ - void set_value(quint8 a, - quint8 b, - quint8 c, - quint8 d) - { - address[0] = a; - address[1] = b; - address[2] = c; - address[3] = d; - } - - /** - * \brief Access a component of the stored IpAddress. - * - * This function returns the component with the given index. Note - * that exactly 4 components are stored. The return value is a - * reference to the component, so that it can be read/written, in - * other words, the IpAddressValue object can be accessed like an - * ordinary array. - * - * \param index The index (value in the range 0...3). - * - * \return A reference to the component. - * - * \exception inval_param If the index is out of bound. - */ - quint8& operator[](unsigned index) - { - if(index > 3) - { - throw(inval_param()); - } - return address[index]; - } - - /** - * \brief Convert the value to an OID. - * - * The conversion is done according to RFC 2578, - * 7.7. "Mapping of the INDEX clause". The created OID - * has exactly 4 subids which corresponds to the 4 - * integers of the IP address. - */ - OidValue toOid() const - { - OidValue oid; - oid.push_back(address[0]); - oid.push_back(address[1]); - oid.push_back(address[2]); - oid.push_back(address[3]); - return oid; - } - }; -} - -#endif diff --git a/src/IpAddressValue.cpp b/src/IpAddressVariable.cpp similarity index 92% rename from src/IpAddressValue.cpp rename to src/IpAddressVariable.cpp index 2b8c273..4c946df 100644 --- a/src/IpAddressValue.cpp +++ b/src/IpAddressVariable.cpp @@ -17,12 +17,12 @@ * for more details. */ -#include "IpAddressValue.hpp" +#include "IpAddressVariable.hpp" #include "util.hpp" using namespace agentxcpp; -binary IpAddressValue::serialize() const +binary IpAddressVariable::serialize() const { binary serialized; @@ -42,7 +42,7 @@ binary IpAddressValue::serialize() const } -IpAddressValue::IpAddressValue(binary::const_iterator& pos, +IpAddressVariable::IpAddressVariable(binary::const_iterator& pos, const binary::const_iterator& end, bool big_endian) { diff --git a/src/IpAddressVariable.hpp b/src/IpAddressVariable.hpp index 7b90166..3410a0c 100644 --- a/src/IpAddressVariable.hpp +++ b/src/IpAddressVariable.hpp @@ -1,40 +1,374 @@ +/* + * Copyright 2011-2012 Tanjeff-Nicolai Moos + * + * This file is part of the agentXcpp library. + * + * AgentXcpp is free software: you can redistribute it and/or modify + * it under the terms of the AgentXcpp library license, version 1, which + * consists of the GNU General Public License and some additional + * permissions. + * + * AgentXcpp is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * See the AgentXcpp library license in the LICENSE file of this package + * for more details. + */ + #ifndef _IPADDRESSVARIABLE_H_ #define _IPADDRESSVARIABLE_H_ -#include "IpAddressValue.hpp" -#include "Variable.hpp" +#include + +#include "AbstractVariable.hpp" +#include "exceptions.hpp" +#include "OidVariable.hpp" namespace agentxcpp { - - class IpAddressVariable : public Variable + /** + * \brief Represents an IP address as described in RFC 2741, section 5.4 + */ + class IpAddressVariable : public AbstractVariable { - private: + private: + /** + * \brief Hide default constructor + */ + IpAddressVariable(); + + /** + * \brief The IP address. + * + * According to RFC 2578, IpAddress is a 32-bit number. + */ + quint8 address[4]; // only IPv4 + + /** + * \brief The new value for the variable in a Set operation. + * + * The Set operation is performed in up to four steps (testset, + * commitset, cleanupset, undoset). Only the testset step actually + * receives the new value. This value is stored here so that it can + * be delivered to commitset(), undoset() and cleanupset(). + */ + QSharedPointer new_value; - IpAddressValue v; + public: + /** + * \internal + * + * \brief Parse Constructor. + * + * This constructor parses the serialized form of the object. + * It takes an iterator, starts parsing at the position of the + * iterator and advances the iterator to the position right behind + * the object. + * + * The constructor expects valid data from the stream; if parsing + * fails, parse_error is thrown. In this case, the iterator + * position is undefined. + * + * \param pos Iterator pointing to the current stream position. + * The iterator is advanced while reading the header. + * + * \param end Iterator pointing one element past the end of the + * current stream. This is needed to mark the end of the + * buffer. + * + * \param big_endian Whether the input stream is in big endian + * format + */ + IpAddressVariable(binary::const_iterator& pos, + const binary::const_iterator& end, + bool big_endian=true); - public: + /** + * \internal + * + * \brief Encode the object as described in RFC 2741, section 5.4 / + * 5.3 + * + * Note: + * We always use big endian. + */ + binary serialize() const; - IpAddressVariable(IpAddressValue _value) - : v(_value) - { - } + /** + * \brief Construct an IpAddressValue object. + * + * The stored IpAddress is initialized to "a.b.c.d". + * + * \exception None. + */ + IpAddressVariable(quint8 a, + quint8 b, + quint8 c, + quint8 d) + { + address[0] = a; + address[1] = b; + address[2] = c; + address[3] = d; + } - void setValue(IpAddressValue _value) + /** + * \brief Set the IpAddress. + * + * The stored IpAddress is updated to "a.b.c.d". + * + * \exception None. + */ + void set_value(quint8 a, + quint8 b, + quint8 c, + quint8 d) { - v = _value; + address[0] = a; + address[1] = b; + address[2] = c; + address[3] = d; + } + + /** + * \brief Access a component of the stored IpAddress. + * + * This function returns the component with the given index. Note + * that exactly 4 components are stored. The return value is a + * reference to the component, so that it can be read/written, in + * other words, the IpAddressValue object can be accessed like an + * ordinary array. + * + * \param index The index (value in the range 0...3). + * + * \return A reference to the component. + * + * \exception inval_param If the index is out of bound. + */ + quint8& operator[](unsigned index) + { + if(index > 3) + { + throw(inval_param()); + } + return address[index]; + } + + /** + * \brief Convert the value to an OID. + * + * The conversion is done according to RFC 2578, + * 7.7. "Mapping of the INDEX clause". The created OID + * has exactly 4 subids which corresponds to the 4 + * integers of the IP address. + */ + OidVariable toOid() const + { + OidVariable oid; + oid.push_back(address[0]); + oid.push_back(address[1]); + oid.push_back(address[2]); + oid.push_back(address[3]); + return oid; + } + + /** + * \internal + * + * \brief Handle a Get Request. + * + * This function calls get() to obtain the new value, + * converts it to QSharedPointer and returns it. + */ + virtual void handle_get() + { + this->get(); + } + + /** + * \brief Handle a Get request. + * + * This method is called when an SNMP Get request is received. + * It shall + * return the current value of the variable. + * + * \note This method is pure virtual and thus \e must be + * implemented. It is not possible to implement write-only + * SNMP variables. + * + * \return The value of the variable. + */ + virtual void get() + { + } + + /** + * \internal + * + * \brief Handle a TestSet request. + * + * This function converts the argument to QSharedPointer() and + * calls + * testset() with the converted value. If conversion fails, + * testset() is not called. This function also stores the given + * value to the new_value member. + * + * \param v The new value for the variable. + * + * \return agentxcpp::AbstractVariable::wrongType if the conversion + * fails. Otherwise, + * the result of + * testset() is + * returned. + */ + virtual testset_result_t handle_testset(QSharedPointer _v) + { + new_value = qSharedPointerDynamicCast(_v); + if (new_value) + { + // Type matches variable + return testset(new_value); + } + else + { + // Wrong type + return wrongType; + } + } - virtual IpAddressValue get() + /** + * \brief Handle a TestSet request. + * + * This method is called when an SNMP TestSet request is received. + * It + * shall check whether a Set operation is possible for the + * variable. It shall acquire the resources needed to perform the + * Set operation (but the Set shall not yet be performed). + * + * The default implementation returns + * agentxcpp::AbstractVariable::noAccess to indicate that + * this is a read-only variable. Thus, for read-only variables this + * method need not be overridden. + * + * \param v The new value for the object. + * + * \return The result of the check. + */ + virtual testset_result_t testset(QSharedPointer _v) { - return v; + return noAccess; } - virtual IpAddressValue value() + /** + * \internal + * + * \brief Handle a CleanupSet request. + * + * This function calls cleanupset() with the value from the last + * handle_testset() invokation. + */ + virtual void handle_cleanupset() { - return v; + cleanupset(new_value); + } + + /** + * \brief Handle a CleanupSet request. + * + * This method is called when an SNMP CleanupSet request is + * received. It + * shall release any ressources allocated by testset(). + * + * The default implementation does nothing. If no action is + * required to perform the CleanupSet operaiton, this method need + * not be overridden. + * + * \param v The new value for the object. + */ + virtual void cleanupset(QSharedPointer _v) + { + return; + } + + /** + * \internal + * + * \brief Handle a CommitSet request. + * + * This function calls commitset() with the value from the last + * handle_testset() Invocation and returns its return value. + */ + virtual bool handle_commitset() + { + return commitset(new_value); + } + + /** + * \brief Handle a CommitSet request. + * + * This method is called when an SNMP CommitSet request is + * received. It + * shall perform the actual write operation. + * + * The default implementation returns false to indicate that the + * operation failed. To implement a writable SNMP variable this + * method must be overridden. + * + * \param v The new value for the object. + * + * \return True if the operation succeeded, false otherwise. + */ + virtual bool commitset(QSharedPointer _v) + { + return false; + } + + /** + * \internal + * + * \brief Handle a UndoSet request. + * + * This function calls undoset() with the value from the last + * handle_testset() invocation and returns its return value. + * + */ + virtual bool handle_undoset() + { + return undoset(new_value); + } + + /** + * \brief Handle an UndoSet request. + * + * This method is called when an SNMP UndoSet request is received. + * It + * shall undo whatever commitset() performed. It shall also release + * all resources allocated by testset(). + * + * The default implementation returns false to indicate that + * the operation failed. It is strongly recommended that writable + * variables override this method. + * + * \internal + * + * A default implementation is provided to allow implementing + * read-only variables. + * + * \endinternal + * + * \param v The new value for the object. + * + * \return True on success, false otherwise. + */ + virtual bool undoset(QSharedPointer _v) + { + return false; } }; } -#endif // _IPADDRESSVARIABLE_H_ + +#endif // _IPADDRESSVARIABLE_H_ diff --git a/src/OctetStringValue.hpp b/src/OctetStringValue.hpp deleted file mode 100644 index 30743a9..0000000 --- a/src/OctetStringValue.hpp +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Copyright 2011-2012 Tanjeff-Nicolai Moos - * - * This file is part of the agentXcpp library. - * - * AgentXcpp is free software: you can redistribute it and/or modify - * it under the terms of the AgentXcpp library license, version 1, which - * consists of the GNU General Public License and some additional - * permissions. - * - * AgentXcpp is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * See the AgentXcpp library license in the LICENSE file of this package - * for more details. - */ - -#ifndef _OCTET_STRING_H_ -#define _OCTET_STRING_H_ - -#include "AbstractValue.hpp" -#include "exceptions.hpp" -#include "OidValue.hpp" - -namespace agentxcpp -{ - /** - * \brief Represents an Octet String as described in RFC 2741, section 5.3 - */ - class OctetStringValue : public AbstractValue - { - private: - /** - * \brief The string. - * - * According to RFC 2578, Octet_String represents arbitrary binary - * or textual data. - */ - binary value; - - public: - /** - * \internal - * - * \brief Encode the object as described in RFC 2741, section 5.3 - * - * \note We always use big endian. - */ - binary serialize() const; - - /** - * \brief Construct object from binary data. - */ - OctetStringValue(binary initial_value) : value(initial_value) {} - - /** - * \brief Construct object from a string. - */ - OctetStringValue(std::string initial_value); - - /** - * \brief Create empty OctetStringValue object. - */ - OctetStringValue() { } - - /** - * \internal - * - * \brief Parse Constructor. - * - * This constructor parses the serialized form of the object. - * It takes an iterator, starts parsing at the position of the - * iterator and advances the iterator to the position right behind - * the object. - * - * The constructor expects valid data from the stream; if parsing - * fails, parse_error is thrown. In this case, the iterator - * position is undefined. - * - * \param pos Iterator pointing to the current stream position. - * The iterator is advanced while reading the header. - * - * \param end Iterator pointing one element past the end of the - * current stream. This is needed to mark the end of the - * buffer. - * - * \param big_endian Whether the input stream is in big endian - * format - */ - OctetStringValue(binary::const_iterator& pos, - const binary::const_iterator& end, - bool big_endian=true); - - /** - * \brief Set the current value. - */ - void set_value(binary new_value) { value = new_value; } - - /** - * \brief Set the current value. - */ - void set_value(std::string new_value); - - /** - * \brief Get the current value - */ - binary get_value() const - { - return value; - } - - /** - * \brief Get the current value as string. - */ - std::string str() const; - - /** - * \brief Convert the value to an OID. - * - * The conversion is done according to RFC 2578, - * 7.7. "Mapping of the INDEX clause". First, the - * string length is converted to a subid. Then, each - * octet of the value is converted into a separate subid. - * - * Note that the length subid is omitted for fixed-length strings. - * - * \param fixedLength Whether the string is fixed-length. - */ - OidValue toOid(bool fixedLength = false) const - { - OidValue oid; - - // Store string length if needed - if(!fixedLength) - { - oid.push_back(value.size()); - } - - // Store string - for(binary::const_iterator i = value.begin(); - i != value.end(); - ++i) - { - oid.push_back(*i); - } - return oid; - } - - }; -} - -#endif diff --git a/src/OctetStringValue.cpp b/src/OctetStringVariable.cpp similarity index 67% rename from src/OctetStringValue.cpp rename to src/OctetStringVariable.cpp index 282d120..59ded1e 100644 --- a/src/OctetStringValue.cpp +++ b/src/OctetStringVariable.cpp @@ -19,38 +19,38 @@ #include -#include "OctetStringValue.hpp" +#include "OctetStringVariable.hpp" #include "util.hpp" using namespace agentxcpp; -OctetStringValue::OctetStringValue(std::string v) +OctetStringVariable::OctetStringVariable(QString v) { // Delegate ;-) - this->set_value(v); + this->setValue(v); } -void OctetStringValue::set_value(std::string v) +void OctetStringVariable::setValue(QString _value) { // Here we convert initial value to a binary string. We do this in three // steps: - // 1. get the bare data: v.data() + // 1. get the bare data: v.toStdString().data() // 2. cast the data to the value type of binary // 3. calculate the size of the data - // - v.size() gives us the number of characters + // - v.toStdString().size() gives us the number of characters // - sizeof(binary::value_type) gives us the size of an character // 4. Assign v to value, giving it the bare data and its size // // This seems to be goofy, but it ensures that our code works even on a // machine where a char is not 8 bit wide, i.e. when char has another size // than quint8. - value.assign( - reinterpret_cast( v.data() ), - v.size() * sizeof( binary::value_type ) + v.assign( + reinterpret_cast( _value.toStdString().data() ), + _value.toStdString().size() * sizeof( binary::value_type ) ); } -std::string OctetStringValue::str() const +QString OctetStringVariable::toString() const { // Here we convert the stored value to a string. We do this in three // steps: @@ -66,24 +66,24 @@ std::string OctetStringValue::str() const // machine where a char is not 8 bit wide, i.e. when char has another size // than quint8. std::string retval( - reinterpret_cast( value.data() ), - value.size() * sizeof( std::string::value_type ) + reinterpret_cast( v.data() ), + v.size() * sizeof( std::string::value_type ) ); - return retval; + return QString::fromStdString(retval); } -binary OctetStringValue::serialize() const +binary OctetStringVariable::serialize() const { binary serialized; // encode size (big endian) - write32(serialized, value.size()); + write32(serialized, v.size()); // encode value - serialized += value; + serialized += v; // Padding bytes - int padsize = 4 - (value.size() % 4); + int padsize = 4 - (v.size() % 4); if( padsize == 4 ) padsize = 0; // avoid adding 4 padding bytes while( padsize-- ) { @@ -94,9 +94,9 @@ binary OctetStringValue::serialize() const } -OctetStringValue::OctetStringValue(binary::const_iterator& pos, - const binary::const_iterator& end, - bool big_endian) +OctetStringVariable::OctetStringVariable(binary::const_iterator& pos, + const binary::const_iterator& end, + bool big_endian) { int size; @@ -123,7 +123,7 @@ OctetStringValue::OctetStringValue(binary::const_iterator& pos, } // Get value - value.assign(pos, pos+size); + v.assign(pos, pos+size); pos += size; // Eat padding bytes @@ -138,3 +138,24 @@ OctetStringValue::OctetStringValue(binary::const_iterator& pos, pos++; } } + + +OidVariable OctetStringVariable::toOid(bool fixedLength) const +{ + OidVariable oid; + + // Store string length if needed + if(!fixedLength) + { + oid.push_back(v.size()); + } + + // Store string + for(binary::const_iterator i = v.begin(); + i != v.end(); + ++i) + { + oid.push_back(*i); + } + return oid; +} diff --git a/src/OctetStringVariable.hpp b/src/OctetStringVariable.hpp index ddb09f2..40b0713 100644 --- a/src/OctetStringVariable.hpp +++ b/src/OctetStringVariable.hpp @@ -1,38 +1,317 @@ #ifndef _OCTETSTRINGVARIABLE_H_ #define _OCTETSTRINGVARIABLE_H_ -#include "OctetStringValue.hpp" -#include "Variable.hpp" +#include +#include "AbstractVariable.hpp" +#include "OidVariable.hpp" namespace agentxcpp { - class OctetStringVariable : public Variable + class OctetStringVariable : public AbstractVariable { + protected: + + /** + * \brief The string. + * + * According to RFC 2578, Octet_String represents arbitrary binary + * or textual data. + */ + binary v; + private: - OctetStringValue v; + QSharedPointer new_value; public: + /** + * \internal + * + * \brief Encode the object as described in RFC 2741, section 5.3 + * + * \note We always use big endian. + */ + binary serialize() const; + + /** + * \brief Construct object from binary data. + */ OctetStringVariable(binary _value = binary()) - : v(_value) - { - } + : v(_value) + { + } + + /** + * \brief Construct object from a string. + */ + OctetStringVariable(QString initial_value); - void setValue(binary _value) + /** + * \brief Create empty OctetStringValue object. + */ + OctetStringVariable() { - v.set_value(_value); } - virtual OctetStringValue get() + /** + * \internal + * + * \brief Parse Constructor. + * + * This constructor parses the serialized form of the object. + * It takes an iterator, starts parsing at the position of the + * iterator and advances the iterator to the position right behind + * the object. + * + * The constructor expects valid data from the stream; if parsing + * fails, parse_error is thrown. In this case, the iterator + * position is undefined. + * + * \param pos Iterator pointing to the current stream position. + * The iterator is advanced while reading the header. + * + * \param end Iterator pointing one element past the end of the + * current stream. This is needed to mark the end of the + * buffer. + * + * \param big_endian Whether the input stream is in big endian + * format + */ + OctetStringVariable(binary::const_iterator& pos, + const binary::const_iterator& end, + bool big_endian=true); + + /** + * \brief Set the current value. + */ + void setValue(binary new_value) + { + v = new_value; + } + + /** + * \brief Set the current value. + */ + void setValue(QString new_value); + + /** + * \brief Get the current value + */ + binary value() const { return v; } - virtual binary value() + /** + * \brief Get the current value as string. + */ + QString toString() const; + + /** + * \brief Convert the value to an OID. + * + * The conversion is done according to RFC 2578, + * 7.7. "Mapping of the INDEX clause". First, the + * string length is converted to a subid. Then, each + * octet of the value is converted into a separate subid. + * + * Note that the length subid is omitted for fixed-length strings. + * + * \param fixedLength Whether the string is fixed-length. + */ + OidVariable toOid(bool fixedLength = false) const; + + /** + * \internal + * + * \brief Handle a Get Request. + */ + virtual void handle_get() + { + this->get(); + } + + /** + * \brief Handle a Get request. + * + * This method is called when an SNMP Get request is received. + * It shall + * return the current value of the variable. + * + * \note This method is pure virtual and thus \e must be + * implemented. It is not possible to implement write-only + * SNMP variables. + * + * \return The value of the variable. + */ + virtual void get() + { + } + + /** + * \internal + * + * \brief Handle a TestSet request. + * + * This function converts the argument to QSharedPointer() and + * calls + * testset() with the converted value. If conversion fails, + * testset() is not called. This function also stores the given + * value to the new_value member. + * + * \param v The new value for the variable. + * + * \return agentxcpp::AbstractVariable::wrongType if the conversion + * fails. Otherwise, + * the result of + * testset() is + * returned. + */ + virtual testset_result_t handle_testset(QSharedPointer _v) + { + new_value = qSharedPointerDynamicCast(_v); + if (new_value) + { + // Type matches variable + return testset(new_value); + } + else + { + // Wrong type + return wrongType; + } + + } + + /** + * \brief Handle a TestSet request. + * + * This method is called when an SNMP TestSet request is received. + * It + * shall check whether a Set operation is possible for the + * variable. It shall acquire the resources needed to perform the + * Set operation (but the Set shall not yet be performed). + * + * The default implementation returns + * agentxcpp::AbstractVariable::noAccess to indicate that + * this is a read-only variable. Thus, for read-only variables this + * method need not be overridden. + * + * \param v The new value for the object. + * + * \return The result of the check. + */ + virtual testset_result_t testset(QSharedPointer _v) + { + return noAccess; + } + + /** + * \internal + * + * \brief Handle a CleanupSet request. + * + * This function calls cleanupset() with the value from the last + * handle_testset() invokation. + */ + virtual void handle_cleanupset() + { + cleanupset(new_value); + } + + /** + * \brief Handle a CleanupSet request. + * + * This method is called when an SNMP CleanupSet request is + * received. It + * shall release any ressources allocated by testset(). + * + * The default implementation does nothing. If no action is + * required to perform the CleanupSet operaiton, this method need + * not be overridden. + * + * \param v The new value for the object. + */ + virtual void cleanupset(QSharedPointer _v) + { + return; + } + + /** + * \internal + * + * \brief Handle a CommitSet request. + * + * This function calls commitset() with the value from the last + * handle_testset() Invocation and returns its return value. + */ + virtual bool handle_commitset() + { + return commitset(new_value); + } + + /** + * \brief Handle a CommitSet request. + * + * This method is called when an SNMP CommitSet request is + * received. It + * shall perform the actual write operation. + * + * The default implementation returns false to indicate that the + * operation failed. To implement a writable SNMP variable this + * method must be overridden. + * + * \param v The new value for the object. + * + * \return True if the operation succeeded, false otherwise. + */ + virtual bool commitset(QSharedPointer _v) + { + return false; + } + + /** + * \internal + * + * \brief Handle a UndoSet request. + * + * This function calls undoset() with the value from the last + * handle_testset() invocation and returns its return value. + * + */ + virtual bool handle_undoset() + { + return undoset(new_value); + } + + /** + * \brief Handle an UndoSet request. + * + * This method is called when an SNMP UndoSet request is received. + * It + * shall undo whatever commitset() performed. It shall also release + * all resources allocated by testset(). + * + * The default implementation returns false to indicate that + * the operation failed. It is strongly recommended that writable + * variables override this method. + * + * \internal + * + * A default implementation is provided to allow implementing + * read-only variables. + * + * \endinternal + * + * \param v The new value for the object. + * + * \return True on success, false otherwise. + */ + virtual bool undoset(QSharedPointer _v) { - return v.get_value(); + return false; } }; diff --git a/src/OidValue.hpp b/src/OidValue.hpp deleted file mode 100644 index 1d9427e..0000000 --- a/src/OidValue.hpp +++ /dev/null @@ -1,609 +0,0 @@ -/* - * Copyright 2011-2012 Tanjeff-Nicolai Moos - * - * This file is part of the agentXcpp library. - * - * AgentXcpp is free software: you can redistribute it and/or modify - * it under the terms of the AgentXcpp library license, version 1, which - * consists of the GNU General Public License and some additional - * permissions. - * - * AgentXcpp is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * See the AgentXcpp library license in the LICENSE file of this package - * for more details. - */ - -#ifndef _OID_H_ -#define _OID_H_ - -#include -#include - -#include -#include - -#include "AbstractValue.hpp" -#include "exceptions.hpp" - - -namespace agentxcpp -{ - /** - * \brief Represents an SNMP object identifier (OID). - * - * This class represents an OID. OID's are sequences of sub-identifiers, - * which are integers. - * - * This class provides constructors taking a string which contains an OID. - * For example, this works: - * - * \code - * OidValue myCompany = OidValue("1.3.6.1.4.1.355"); - * \endcode - * - * Also a constructor is provided which takes an OidValue and a string and - * concatenates them, so this works also: - * - * \code - * OidValue myObject = OidValue(myCompany, "1.1.3.0"); - * \endcode - * - * In addition, some common OidValue's are provided as constants, e.g. - * 'enterprises_oid', so the following will also work (note that the second - * argument is a string, not an integer!): - * - * \code - * OidValue yourCompany = OidValue(enterprises_oid, "42"); // second param is a string! - * \endcode - * - * The string given to the constructors must have a valid syntax. If a - * malformed string is provided, inval_param is thrown and the object is - * not constructed. For example, the following strings are malformed: - * - * \code - * "1,3,6" // wrong separator (must be a period) - * "1.3.6." // trailing character at the end - * "1.3.6.1.4.1.123456789123" // last subid is too big (must fit in a 32 bit unsigned integer) - * \endcode - * - * However, the following strings are accepted: - * - * \code - * "1.3.6" - * "1" // a single subid is ok - * "1.3.6.1.4.1.42.1.0" // 0 as subid is ok - * "" // empty string is ok - * \endcode - * - * This class inherits from std:vector, which means that an OidValue - * object can be manipulated the same way as a std::vector<> can be - * manipulated: - * - * \code - * OidValue theirCompany = enterprises_oid; - * theirCompany.push_back(23); // Don't use a string here! - * \endcode - * - */ - class OidValue: public AbstractValue, public QVector - { - private: - - /** - * \brief the 'include' field. - */ - bool include; - - /** - * \brief Parse an OID from a string and append it. - * - * The OID contained within the string 's' is parsed and appended to - * this object. The format of the string is described above. - * - * \param s The OID to be parsed. - * - * \exception inval_param If the string is malformed. - */ - void parse_string(std::string s); - - public: - - /** - * \brief Default Constructor - * - * This constructs an empty OidValue (the null OidValue). - * - * \internal - * The 'include' field is initialized to 'false'. - * \endinternal - * - * \exception None. - */ - OidValue() - { - include = false; - } - - - /** - * \brief Initialize an OidValue object with an OID in string format. - * - * This constructor takes a string and initializes the OidValue object - * with the OID contained within this string. The format of the - * string is described above. - * - * \internal - * The 'include' field is initialized to 'false'. - * \endinternal - * - * \param id The initial object identifier. - * - * \exception inval_param If the string is malformed. - */ - OidValue(std::string id); - - /** - * \brief Initialize an OidValue object with another OidValue plus an OID in - * string format. - * - * All subid's are copied from 'o'. Then, the OID contained within - * the string 'id' is appended. The format of the string is - * described in the documentation of this class. - * - * \internal - * The 'include' field is copied from 'o'. - * \endinternal - * - * \param o The starting OID. - * - * \param id The OID to append. - * - * \exception inval_param If the string is malformed. - */ - OidValue(const OidValue& o, std::string id); - - /** - * \brief Assignment operator - * - * Copies all data from 'o' into this OID. - * - * \param o The OID to copy from. - * - * \return A reference to this OID. - */ - OidValue& operator=(const OidValue& o); - - /** - * \internal - * - * \brief Get the current include value. - * - * The include value is present in the serialized form of an OID. - * If an OID object is created by parsing a AgentX message, the - * 'include' member is set accordingly. - * - * See RFC 2741, sections 5.1 and 5.2 for details. - */ - bool get_include() const - { - return include; - } - - /** - * \internal - * - * \brief set the include value - * - * The include value is present in the serialized form of an OID. - * If an OID object is serialized, the include field is encoded - * into the stream. - * - * See RFC 2741, sections 5.1 and 5.2 for details. - */ - void set_include(bool i) - { - include = i; - } - - /** - * \internal - * - * \brief Encode an OID object as described in RFC 2741, - * section 5.1. - */ - binary serialize() const; - - /** - * \internal - * - * \brief Parse Constructor. - * - * This constructor parses the serialized form of the object. - * It takes an iterator, starts parsing at the position of the - * iterator and advances the iterator to the position right behind - * the object. - * - * The constructor expects valid data from the stream; if parsing - * fails, parse_error is thrown. In this case, the iterator is left - * at an undefined position. - * - * \param pos Iterator pointing to the current stream position. - * The iterator is advanced while reading the header. - * - * \param end Iterator pointing one element past the end of the - * current stream. This is needed to mark the end of the - * buffer. - * - * \param big_endian Whether the input stream is in big endian - * format - * - * \exception parse_error If parsing fails. In this case, the - * iterator is left at an undefined - * position. - */ - OidValue(binary::const_iterator& pos, - const binary::const_iterator& end, - bool big_endian=true); - - /** - * \brief The less-than operator - * - * An OID is less than another OID if either the first - * not-identical part is lesser or if all parts are identical and - * it has lesser parts. - * - * Example:\n - * 1.3.6.1.4.1.42.3.3.1 \n - * is less than \n - * 1.3.6.1.4.1.42.3.4.1 \n - * Note the next to last number. - * - * Also,\n - * 1.3.6.1.4.1.42.3.3.1 \n - * is less than \n - * 1.3.6.1.4.1.42.3.3.1.1 \n - * because it is shorter. - * - * However, \n - * 1.3.6.1.4.1.42.3.3.1 \n - * is greater than \n - * 1.3.6.1.4.1.42.3.2.1.1 \n - * because the 9th number is greater (although the first OID has - * less numbers than the second). - * - * \param o The OID to compare to. - * - * \return True if the OID is less than 'o', false otherwise. - */ - bool operator<(const OidValue& o) const; - - /** - * \brief The less-than-or-equal operator - * - * See operator<() for a more detailed description about comparing - * OIDs. - * - * \param o The OID to compare to. - * - * \return True if the OID is less than or equal 'o', - * false otherwise. - */ - bool operator<=(const OidValue& o) const - { - if(*this == o || *this < o) - { - return true; - } - else - { - return false; - } - } - - /** - * \brief The equal-operator - * - * See operator<() for a more detailed description about comparing - * OIDs. - * - * \param o The OID tocompare to. - * - * \return True if the OIDs are equal, false otherwise. - */ - bool operator==(const OidValue& o) const; - - /** - * \brief The not-equal-operator for OidValues - * - * See operator<() for a more detailed description about comparing - * OIDs. - * - * \param o The OID tocompare to. - * - * \return False if the OIDs are equal, true otherwise. - */ - bool operator!=(const OidValue& o) const - { - return ! (*this == o); - } - - /** - * \brief The greater-than operator - * - * See operator<() for a more detailed description about comparing - * OIDs. - * - * \param o The OID tocompare to. - * - * \return True if the OID is greater than 'o', false otherwise. - */ - bool operator>(const OidValue& o) const - { - // a > b is the same as b < a :-) - return o < *this; - } - - /** - * \brief The greater-than-or-equal operator - * - * See operator<() for a more detailed description about comparing - * OIDs. - * - * \param o The OID to compare to. - * - * \return True if the OID is greater than or equal 'o', - * false otherwise. - */ - bool operator>=(const OidValue& o) const - { - // a >= b is the same as b <= a :-) - return o <= *this; - } - - /** - * \brief Checks whether the given OidValue is in the subtree of this - * OidValue. - * - * This method checks whether the given OID is included in the - * subtree which has this OidValue as root. - * - * Examples:\n - * \code - * OidValue id("1.3.6.1.4.1.42.3"); - * id.contains( OidValue(1.3.6.1.4.1.42.3) ); // true - * id.contains( OidValue(1.3.6.1.4.1.42) ); // false - * id.contains( OidValue(1.3.6.1.4.1.43.3) ); // false - * id.contains( OidValue(1.3.6.1.4.1.42.3.3.1) ); // true - * \endcode - * - * \param id The OID to check. - * - * \return True if id is contained in the subtree, false - * otherwise. - */ - bool contains(const OidValue& id); - - /** - * \internal - * - * \brief Whether it is the null Object Identifier - * - * According to RFC 2741, 5.1 "Object Identifier", a null object - * identifier has serial representation of 4 bytes which are - * all set to 0. An OID with no subid's and the index field set to - * 0 results in that representation and is thus considered to be - * the null OID. - * - * \return True if the object is the null OID, false otherwise. - */ - bool is_null() const; - - friend std::ostream& operator<<(std::ostream& out, - const agentxcpp::OidValue& o); - - /** - * \brief Convert the value to an OID. - * - * The conversion is done according to RFC 2578, - * 7.7. "Mapping of the INDEX clause". First, the - * length is converted to a subid. Then, each - * subid of the value is appended. - * - * Note that the length subid is omitted for fixed-length OIDs. - * - * \param fixedLength Whether the OID is fixed-length. - */ - OidValue toOid(bool fixedLength = false) const - { - OidValue oid; - - // Store length if needed - if(!fixedLength) - { - oid.push_back(this->size()); - } - - // Store value - oid += *this; - - return oid; - } - - - }; - - /** - * \brief The output operator for the OidValue class. - * - * Object identifiers (OidValue objects) can be output as follows: - * - * \code - * OidValue led_state(enterprises_oid, "1.3.3.1"); - * cout << "LED state OID: " << led_state << endl; - * \endcode - * - * The last line will output "LED state OID: .1.3.6.1.4.1.3.3.1". - * - * \param out The stream to which to write the output. - * - * \param o The OID to output. - * - * \return The 'out' parameter. - */ - std::ostream& operator<<(std::ostream& out, const agentxcpp::OidValue& o); - - - // TODO: Possibly these should be put into the agentxcpp::OidValue namespace? - // The use of \memberof is not elegant. - - /** - * \memberof OidValue - * - * \brief The 'iso' OID according to RFC 1155. - */ - const OidValue iso_oid("1"); - - /** - * \memberof OidValue - * - * \brief The 'ccitt' OID according to RFC 1155. - */ - const OidValue ccitt_oid("0"); - - /** - * \memberof OidValue - * - * \brief The 'joint.iso.ccitt' OID according to RFC 1155. - */ - const OidValue joint_iso_ccitt_oid("2"); - - /** - * \memberof OidValue - * - * \brief The 'iso.org' OID according to RFC 1155. - */ - const OidValue org_oid(iso_oid,"3"); - - /** - * \memberof OidValue - * - * \brief The 'iso.org.dod' OID according to RFC 1155. - */ - const OidValue dod_oid(org_oid,"6"); - - /** - * \memberof OidValue - * - * \brief The 'iso.org.dod.internet' OID according to RFC 1155. - */ - const OidValue internet_oid(dod_oid,"1"); - - /** - * \memberof OidValue - * - * \brief The 'iso.org.dod.internet.directory' OID according to RFC 1155. - */ - const OidValue directory_oid(internet_oid,"1"); - - /** - * \memberof OidValue - * - * \brief The 'iso.org.dod.internet.mgmt' OID according to RFC 1155. - */ - const OidValue mgmt_oid(internet_oid,"2"); - - /** - * \memberof OidValue - * - * \brief The 'iso.org.dod.internet.experimental' OID according to - * RFC 1155. - */ - const OidValue experimental_oid(internet_oid,"3"); - - /** - * \memberof OidValue - * - * \brief The 'iso.org.dod.internet.private' OID according to RFC 1155. - */ - const OidValue private_oid(internet_oid,"4"); - - /** - * \memberof OidValue - * - * \brief The 'iso.org.dod.internet.private.enterprises' OID according to - * RFC 1155. - */ - const OidValue enterprises_oid(private_oid, "1"); - - /** - * \memberof OidValue - * - * \brief The 'snmpMIBObjects' OID according to RFC 1907. - * - * \internal - * - * This OID is used in the context of notifications. - * - * According to RFC 1907:
- * snmpTrapOID ::= snmpTrap.1
- * snmpTrap ::= snmpMIBObjects.4
- * snmpMIBObjects ::= snmpMIB.1
- * snmpMIB ::= snmpModules.1
- * - * According to RFC 2578 (SNMPv2-SMI):
- * snmpModules ::= snmpV2.3
- * snmpV2 ::= internet.6 - * - * Conclusion:
- * snmpMIBObjects ::= internet.6.3.1.1 - */ - const OidValue snmpMIBObjects_oid(internet_oid, "6.3.1.1"); - - /** - * \memberof OidValue - * - * \brief The 'snmpTrapOID' OID according to RFC 1907. - * - * \internal - * - * This OID is used in the context of notifications. - * - * According to RFC 1907:
- * snmpTrapOID ::= snmpTrap.1
- * snmpTrap ::= snmpMIBObjects.4
- * - * Conclusion:
- * snmpTrapOID ::= snmpMIBObjects.4.1 - */ - const OidValue snmpTrapOID_oid(snmpMIBObjects_oid, "4.1"); - - /** - * - * \memberof OidValue - * - * \brief The sysUpTime_oid OID according to RFC 1907. - * - * \internal - * - * This OID is used in the context of notifications. - * - * According to RFC 1907:
- * sysUpTime = system.3
- * system = mib-2.1 - * - * According to RFC 1902:
- * mib-2 = mgmt.1 - * - * Conclusion: - * sysUpTime = mgmt.1.1.3 - */ - const OidValue sysUpTime_oid(mgmt_oid, "1.1.3"); - -} - - -#endif diff --git a/src/OidValue.cpp b/src/OidVariable.cpp similarity index 90% rename from src/OidValue.cpp rename to src/OidVariable.cpp index aead46b..d201e80 100644 --- a/src/OidValue.cpp +++ b/src/OidVariable.cpp @@ -19,7 +19,7 @@ //#include #include -#include "OidValue.hpp" +#include "OidVariable.hpp" #include "exceptions.hpp" @@ -27,7 +27,7 @@ using namespace agentxcpp; using namespace std; -void OidValue::parse_string(std::string s) +void OidVariable::parseString(std::string s) { // Do not parse empty string if(s.empty()) return; @@ -65,26 +65,26 @@ void OidValue::parse_string(std::string s) -OidValue::OidValue(std::string s) +OidVariable::OidVariable(std::string s) { include = false; // parse the string. Forward all exceptions. - parse_string(s); + parseString(s); } -OidValue::OidValue(const OidValue& o, std::string id) +OidVariable::OidVariable(const OidVariable& o, std::string id) { // start with o *this = o; // add OID from string. Forward all exceptions. - parse_string(id); + parseString(id); } -std::ostream& agentxcpp::operator<<(std::ostream& out, const OidValue& o) +std::ostream& agentxcpp::operator<<(std::ostream& out, const OidVariable& o) { // Leading dot out << "."; @@ -96,7 +96,7 @@ std::ostream& agentxcpp::operator<<(std::ostream& out, const OidValue& o) } // Get iterator to first subidentifier - OidValue::const_iterator it = o.begin(); + OidVariable::const_iterator it = o.begin(); // Print first subidentifier out << *it; @@ -115,7 +115,7 @@ std::ostream& agentxcpp::operator<<(std::ostream& out, const OidValue& o) -binary OidValue::serialize() const +binary OidVariable::serialize() const { // The serial representation of an OID is as follows (RFC 2741, section // 5.1): @@ -147,7 +147,7 @@ binary OidValue::serialize() const serialized[include_idx] = include ? 1 : 0; // Iterator for the subid's - OidValue::const_iterator subid = this->begin(); + OidVariable::const_iterator subid = this->begin(); // Check whether we can use the prefix (RFC 2741, section 5.1) if( this->size() >= 5 && @@ -186,7 +186,7 @@ binary OidValue::serialize() const return serialized; } -OidValue::OidValue(binary::const_iterator& pos, +OidVariable::OidVariable(binary::const_iterator& pos, const binary::const_iterator& end, bool big_endian) { @@ -255,9 +255,9 @@ OidValue::OidValue(binary::const_iterator& pos, } -bool OidValue::operator<(const OidValue& o) const +bool OidVariable::operator<(const OidVariable& o) const { - OidValue::const_iterator mine, yours; + OidVariable::const_iterator mine, yours; mine = this->begin(); yours = o.begin(); @@ -298,7 +298,7 @@ bool OidValue::operator<(const OidValue& o) const -bool OidValue::operator==(const OidValue& o) const +bool OidVariable::operator==(const OidVariable& o) const { // Quick test: if the OidValues have different number of parts, they are not // equal: @@ -308,7 +308,7 @@ bool OidValue::operator==(const OidValue& o) const } // Test all parts: - OidValue::const_iterator mine, yours; + OidVariable::const_iterator mine, yours; mine = this->begin(); yours = o.begin(); @@ -332,21 +332,21 @@ bool OidValue::operator==(const OidValue& o) const } -OidValue& OidValue::operator=(const OidValue& other) +OidVariable& OidVariable::operator=(const OidVariable& other) { // copy our own members this->include = other.include; // copy inherited stuff QVector::operator=(other); - AbstractValue::operator=(other); + AbstractVariable::operator=(other); // Return reference to us return *this; } -bool OidValue::contains(const OidValue& id) +bool OidVariable::contains(const OidVariable& id) { // If id has fewer subids than this: not contained if(this->size() > id.size()) @@ -372,7 +372,7 @@ bool OidValue::contains(const OidValue& id) } -bool OidValue::is_null() const +bool OidVariable::is_null() const { if( this->size() == 0 && ! this->include) diff --git a/src/OidVariable.hpp b/src/OidVariable.hpp index d75e8f4..c2071f9 100644 --- a/src/OidVariable.hpp +++ b/src/OidVariable.hpp @@ -1,40 +1,812 @@ +/* + * Copyright 2011-2012 Tanjeff-Nicolai Moos + * + * This file is part of the agentXcpp library. + * + * AgentXcpp is free software: you can redistribute it and/or modify + * it under the terms of the AgentXcpp library license, version 1, which + * consists of the GNU General Public License and some additional + * permissions. + * + * AgentXcpp is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * See the AgentXcpp library license in the LICENSE file of this package + * for more details. + */ + #ifndef _OIDVARIABLE_H_ #define _OIDVARIABLE_H_ -#include "OidValue.hpp" -#include "Variable.hpp" +#include +#include + +#include +#include + +#include "AbstractVariable.hpp" +#include "exceptions.hpp" + namespace agentxcpp { - - class OidVariable : public Variable + /** + * \brief Represents an SNMP object identifier (OID). + * + * This class represents an OID. OID's are sequences of sub-identifiers, + * which are integers. + * + * This class provides constructors taking a string which contains an OID. + * For example, this works: + * + * \code + * OidValue myCompany = OidValue("1.3.6.1.4.1.355"); + * \endcode + * + * Also a constructor is provided which takes an OidValue and a string and + * concatenates them, so this works also: + * + * \code + * OidValue myObject = OidValue(myCompany, "1.1.3.0"); + * \endcode + * + * In addition, some common OidValue's are provided as constants, e.g. + * 'enterprises_oid', so the following will also work (note that the second + * argument is a string, not an integer!): + * + * \code + * OidValue yourCompany = OidValue(enterprises_oid, "42"); // second param is a string! + * \endcode + * + * The string given to the constructors must have a valid syntax. If a + * malformed string is provided, inval_param is thrown and the object is + * not constructed. For example, the following strings are malformed: + * + * \code + * "1,3,6" // wrong separator (must be a period) + * "1.3.6." // trailing character at the end + * "1.3.6.1.4.1.123456789123" // last subid is too big (must fit in a 32 bit unsigned integer) + * \endcode + * + * However, the following strings are accepted: + * + * \code + * "1.3.6" + * "1" // a single subid is ok + * "1.3.6.1.4.1.42.1.0" // 0 as subid is ok + * "" // empty string is ok + * \endcode + * + * This class inherits from std:vector, which means that an OidValue + * object can be manipulated the same way as a std::vector<> can be + * manipulated: + * + * \code + * OidValue theirCompany = enterprises_oid; + * theirCompany.push_back(23); // Don't use a string here! + * \endcode + * + */ + class OidVariable: public AbstractVariable, public QVector { - private: + private: + + /** + * \brief the 'include' field. + */ + bool include; + + /** + * \brief Parse an OID from a string and append it. + * + * The OID contained within the string 's' is parsed and appended to + * this object. The format of the string is described above. + * + * \param s The OID to be parsed. + * + * \exception inval_param If the string is malformed. + */ + void parseString(std::string s); + + /** + * \brief The new value for the variable in a Set operation. + * + * The Set operation is performed in up to four steps (testset, + * commitset, cleanupset, undoset). Only the testset step actually + * receives the new value. This value is stored here so that it can + * be delivered to commitset(), undoset() and cleanupset(). + */ + QSharedPointer new_value; + + public: + + /** + * \brief Default Constructor + * + * This constructs an empty OidValue (the null OidValue). + * + * \internal + * The 'include' field is initialized to 'false'. + * \endinternal + * + * \exception None. + */ + OidVariable() + { + include = false; + } + + + /** + * \brief Initialize an OidValue object with an OID in string format. + * + * This constructor takes a string and initializes the OidValue object + * with the OID contained within this string. The format of the + * string is described above. + * + * \internal + * The 'include' field is initialized to 'false'. + * \endinternal + * + * \param id The initial object identifier. + * + * \exception inval_param If the string is malformed. + */ + OidVariable(std::string id); + + /** + * \brief Initialize an OidValue object with another OidValue plus an OID in + * string format. + * + * All subid's are copied from 'o'. Then, the OID contained within + * the string 'id' is appended. The format of the string is + * described in the documentation of this class. + * + * \internal + * The 'include' field is copied from 'o'. + * \endinternal + * + * \param o The starting OID. + * + * \param id The OID to append. + * + * \exception inval_param If the string is malformed. + */ + OidVariable(const OidVariable& o, std::string id); + + /** + * \brief Assignment operator + * + * Copies all data from 'o' into this OID. + * + * \param o The OID to copy from. + * + * \return A reference to this OID. + */ + OidVariable& operator=(const OidVariable& o); + + /** + * \internal + * + * \brief Get the current include value. + * + * The include value is present in the serialized form of an OID. + * If an OID object is created by parsing a AgentX message, the + * 'include' member is set accordingly. + * + * See RFC 2741, sections 5.1 and 5.2 for details. + */ + bool get_include() const + { + return include; + } + + /** + * \internal + * + * \brief set the include value + * + * The include value is present in the serialized form of an OID. + * If an OID object is serialized, the include field is encoded + * into the stream. + * + * See RFC 2741, sections 5.1 and 5.2 for details. + */ + void set_include(bool i) + { + include = i; + } + + /** + * \internal + * + * \brief Encode an OID object as described in RFC 2741, + * section 5.1. + */ + binary serialize() const; + + /** + * \internal + * + * \brief Parse Constructor. + * + * This constructor parses the serialized form of the object. + * It takes an iterator, starts parsing at the position of the + * iterator and advances the iterator to the position right behind + * the object. + * + * The constructor expects valid data from the stream; if parsing + * fails, parse_error is thrown. In this case, the iterator is left + * at an undefined position. + * + * \param pos Iterator pointing to the current stream position. + * The iterator is advanced while reading the header. + * + * \param end Iterator pointing one element past the end of the + * current stream. This is needed to mark the end of the + * buffer. + * + * \param big_endian Whether the input stream is in big endian + * format + * + * \exception parse_error If parsing fails. In this case, the + * iterator is left at an undefined + * position. + */ + OidVariable(binary::const_iterator& pos, + const binary::const_iterator& end, + bool big_endian=true); + + /** + * \brief The less-than operator + * + * An OID is less than another OID if either the first + * not-identical part is lesser or if all parts are identical and + * it has lesser parts. + * + * Example:\n + * 1.3.6.1.4.1.42.3.3.1 \n + * is less than \n + * 1.3.6.1.4.1.42.3.4.1 \n + * Note the next to last number. + * + * Also,\n + * 1.3.6.1.4.1.42.3.3.1 \n + * is less than \n + * 1.3.6.1.4.1.42.3.3.1.1 \n + * because it is shorter. + * + * However, \n + * 1.3.6.1.4.1.42.3.3.1 \n + * is greater than \n + * 1.3.6.1.4.1.42.3.2.1.1 \n + * because the 9th number is greater (although the first OID has + * less numbers than the second). + * + * \param o The OID to compare to. + * + * \return True if the OID is less than 'o', false otherwise. + */ + bool operator<(const OidVariable& o) const; + + /** + * \brief The less-than-or-equal operator + * + * See operator<() for a more detailed description about comparing + * OIDs. + * + * \param o The OID to compare to. + * + * \return True if the OID is less than or equal 'o', + * false otherwise. + */ + bool operator<=(const OidVariable& o) const + { + if(*this == o || *this < o) + { + return true; + } + else + { + return false; + } + } + + /** + * \brief The equal-operator + * + * See operator<() for a more detailed description about comparing + * OIDs. + * + * \param o The OID tocompare to. + * + * \return True if the OIDs are equal, false otherwise. + */ + bool operator==(const OidVariable& o) const; + + /** + * \brief The not-equal-operator for OidValues + * + * See operator<() for a more detailed description about comparing + * OIDs. + * + * \param o The OID tocompare to. + * + * \return False if the OIDs are equal, true otherwise. + */ + bool operator!=(const OidVariable& o) const + { + return ! (*this == o); + } + + /** + * \brief The greater-than operator + * + * See operator<() for a more detailed description about comparing + * OIDs. + * + * \param o The OID tocompare to. + * + * \return True if the OID is greater than 'o', false otherwise. + */ + bool operator>(const OidVariable& o) const + { + // a > b is the same as b < a :-) + return o < *this; + } + + /** + * \brief The greater-than-or-equal operator + * + * See operator<() for a more detailed description about comparing + * OIDs. + * + * \param o The OID to compare to. + * + * \return True if the OID is greater than or equal 'o', + * false otherwise. + */ + bool operator>=(const OidVariable& o) const + { + // a >= b is the same as b <= a :-) + return o <= *this; + } + + /** + * \brief Checks whether the given OidValue is in the subtree of this + * OidValue. + * + * This method checks whether the given OID is included in the + * subtree which has this OidValue as root. + * + * Examples:\n + * \code + * OidValue id("1.3.6.1.4.1.42.3"); + * id.contains( OidValue(1.3.6.1.4.1.42.3) ); // true + * id.contains( OidValue(1.3.6.1.4.1.42) ); // false + * id.contains( OidValue(1.3.6.1.4.1.43.3) ); // false + * id.contains( OidValue(1.3.6.1.4.1.42.3.3.1) ); // true + * \endcode + * + * \param id The OID to check. + * + * \return True if id is contained in the subtree, false + * otherwise. + */ + bool contains(const OidVariable& id); + + /** + * \internal + * + * \brief Whether it is the null Object Identifier + * + * According to RFC 2741, 5.1 "Object Identifier", a null object + * identifier has serial representation of 4 bytes which are + * all set to 0. An OID with no subid's and the index field set to + * 0 results in that representation and is thus considered to be + * the null OID. + * + * \return True if the object is the null OID, false otherwise. + */ + bool is_null() const; + + friend std::ostream& operator<<(std::ostream& out, + const OidVariable& o); + + /** + * \brief Convert the value to an OID. + * + * The conversion is done according to RFC 2578, + * 7.7. "Mapping of the INDEX clause". First, the + * length is converted to a subid. Then, each + * subid of the value is appended. + * + * Note that the length subid is omitted for fixed-length OIDs. + * + * \param fixedLength Whether the OID is fixed-length. + */ + OidVariable toOid(bool fixedLength = false) const + { + OidVariable oid; + + // Store length if needed + if(!fixedLength) + { + oid.push_back(this->size()); + } + + // Store value + oid += *this; + + return oid; + } + + /** + * \internal + * + * \brief Handle a Get Request. + * + * This function calls get() to obtain the new value, + * converts it to QSharedPointer and returns it. + */ + virtual void handle_get() + { + this->get(); + } - OidValue v; + /** + * \brief Handle a Get request. + * + * This method is called when an SNMP Get request is received. + * It shall + * return the current value of the variable. + * + * \note This method is pure virtual and thus \e must be + * implemented. It is not possible to implement write-only + * SNMP variables. + * + * \return The value of the variable. + */ + virtual void get() + { + } + + /** + * \internal + * + * \brief Handle a TestSet request. + * + * This function converts the argument to QSharedPointer() and + * calls + * testset() with the converted value. If conversion fails, + * testset() is not called. This function also stores the given + * value to the new_value member. + * + * \param v The new value for the variable. + * + * \return agentxcpp::AbstractVariable::wrongType if the conversion + * fails. Otherwise, + * the result of + * testset() is + * returned. + */ + virtual testset_result_t handle_testset(QSharedPointer _v) + { + new_value = qSharedPointerDynamicCast(_v); + if (new_value) + { + // Type matches variable + return testset(new_value); + } + else + { + // Wrong type + return wrongType; + } - public: + } - OidVariable(OidValue _value = OidValue()) - : v(_value) - { - } + /** + * \brief Handle a TestSet request. + * + * This method is called when an SNMP TestSet request is received. + * It + * shall check whether a Set operation is possible for the + * variable. It shall acquire the resources needed to perform the + * Set operation (but the Set shall not yet be performed). + * + * The default implementation returns + * agentxcpp::AbstractVariable::noAccess to indicate that + * this is a read-only variable. Thus, for read-only variables this + * method need not be overridden. + * + * \param v The new value for the object. + * + * \return The result of the check. + */ + virtual testset_result_t testset(QSharedPointer _v) + { + return noAccess; + } - void setValue(OidValue _value) + /** + * \internal + * + * \brief Handle a CleanupSet request. + * + * This function calls cleanupset() with the value from the last + * handle_testset() invokation. + */ + virtual void handle_cleanupset() { - v = _value; + cleanupset(new_value); } - virtual OidValue get() + /** + * \brief Handle a CleanupSet request. + * + * This method is called when an SNMP CleanupSet request is + * received. It + * shall release any ressources allocated by testset(). + * + * The default implementation does nothing. If no action is + * required to perform the CleanupSet operaiton, this method need + * not be overridden. + * + * \param v The new value for the object. + */ + virtual void cleanupset(QSharedPointer _v) { - return v; + return; } - virtual OidValue value() + /** + * \internal + * + * \brief Handle a CommitSet request. + * + * This function calls commitset() with the value from the last + * handle_testset() Invocation and returns its return value. + */ + virtual bool handle_commitset() { - return v; + return commitset(new_value); + } + + /** + * \brief Handle a CommitSet request. + * + * This method is called when an SNMP CommitSet request is + * received. It + * shall perform the actual write operation. + * + * The default implementation returns false to indicate that the + * operation failed. To implement a writable SNMP variable this + * method must be overridden. + * + * \param v The new value for the object. + * + * \return True if the operation succeeded, false otherwise. + */ + virtual bool commitset(QSharedPointer _v) + { + return false; + } + + /** + * \internal + * + * \brief Handle a UndoSet request. + * + * This function calls undoset() with the value from the last + * handle_testset() invocation and returns its return value. + * + */ + virtual bool handle_undoset() + { + return undoset(new_value); + } + + /** + * \brief Handle an UndoSet request. + * + * This method is called when an SNMP UndoSet request is received. + * It + * shall undo whatever commitset() performed. It shall also release + * all resources allocated by testset(). + * + * The default implementation returns false to indicate that + * the operation failed. It is strongly recommended that writable + * variables override this method. + * + * \internal + * + * A default implementation is provided to allow implementing + * read-only variables. + * + * \endinternal + * + * \param v The new value for the object. + * + * \return True on success, false otherwise. + */ + virtual bool undoset(QSharedPointer _v) + { + return false; } }; + + /** + * \brief The output operator for the OidValue class. + * + * Object identifiers (OidValue objects) can be output as follows: + * + * \code + * OidValue led_state(enterprises_oid, "1.3.3.1"); + * cout << "LED state OID: " << led_state << endl; + * \endcode + * + * The last line will output "LED state OID: .1.3.6.1.4.1.3.3.1". + * + * \param out The stream to which to write the output. + * + * \param o The OID to output. + * + * \return The 'out' parameter. + */ + std::ostream& operator<<(std::ostream& out, const agentxcpp::OidVariable& o); + + + // TODO: Possibly these should be put into the agentxcpp::OidValue namespace? + // The use of \memberof is not elegant. + + /** + * \memberof OidValue + * + * \brief The 'iso' OID according to RFC 1155. + */ + const OidVariable iso_oid("1"); + + /** + * \memberof OidValue + * + * \brief The 'ccitt' OID according to RFC 1155. + */ + const OidVariable ccitt_oid("0"); + + /** + * \memberof OidValue + * + * \brief The 'joint.iso.ccitt' OID according to RFC 1155. + */ + const OidVariable joint_iso_ccitt_oid("2"); + + /** + * \memberof OidValue + * + * \brief The 'iso.org' OID according to RFC 1155. + */ + const OidVariable org_oid(iso_oid,"3"); + + /** + * \memberof OidValue + * + * \brief The 'iso.org.dod' OID according to RFC 1155. + */ + const OidVariable dod_oid(org_oid,"6"); + + /** + * \memberof OidValue + * + * \brief The 'iso.org.dod.internet' OID according to RFC 1155. + */ + const OidVariable internet_oid(dod_oid,"1"); + + /** + * \memberof OidValue + * + * \brief The 'iso.org.dod.internet.directory' OID according to RFC 1155. + */ + const OidVariable directory_oid(internet_oid,"1"); + + /** + * \memberof OidValue + * + * \brief The 'iso.org.dod.internet.mgmt' OID according to RFC 1155. + */ + const OidVariable mgmt_oid(internet_oid,"2"); + + /** + * \memberof OidValue + * + * \brief The 'iso.org.dod.internet.experimental' OID according to + * RFC 1155. + */ + const OidVariable experimental_oid(internet_oid,"3"); + + /** + * \memberof OidValue + * + * \brief The 'iso.org.dod.internet.private' OID according to RFC 1155. + */ + const OidVariable private_oid(internet_oid,"4"); + + /** + * \memberof OidValue + * + * \brief The 'iso.org.dod.internet.private.enterprises' OID according to + * RFC 1155. + */ + const OidVariable enterprises_oid(private_oid, "1"); + + /** + * \memberof OidValue + * + * \brief The 'snmpMIBObjects' OID according to RFC 1907. + * + * \internal + * + * This OID is used in the context of notifications. + * + * According to RFC 1907:
+ * snmpTrapOID ::= snmpTrap.1
+ * snmpTrap ::= snmpMIBObjects.4
+ * snmpMIBObjects ::= snmpMIB.1
+ * snmpMIB ::= snmpModules.1
+ * + * According to RFC 2578 (SNMPv2-SMI):
+ * snmpModules ::= snmpV2.3
+ * snmpV2 ::= internet.6 + * + * Conclusion:
+ * snmpMIBObjects ::= internet.6.3.1.1 + */ + const OidVariable snmpMIBObjects_oid(internet_oid, "6.3.1.1"); + + /** + * \memberof OidValue + * + * \brief The 'snmpTrapOID' OID according to RFC 1907. + * + * \internal + * + * This OID is used in the context of notifications. + * + * According to RFC 1907:
+ * snmpTrapOID ::= snmpTrap.1
+ * snmpTrap ::= snmpMIBObjects.4
+ * + * Conclusion:
+ * snmpTrapOID ::= snmpMIBObjects.4.1 + */ + const OidVariable snmpTrapOID_oid(snmpMIBObjects_oid, "4.1"); + + /** + * + * \memberof OidValue + * + * \brief The sysUpTime_oid OID according to RFC 1907. + * + * \internal + * + * This OID is used in the context of notifications. + * + * According to RFC 1907:
+ * sysUpTime = system.3
+ * system = mib-2.1 + * + * According to RFC 1902:
+ * mib-2 = mgmt.1OidValue + * + * Conclusion: + * sysUpTime = mgmt.1.1.3 + */ + const OidVariable sysUpTime_oid(mgmt_oid, "1.1.3"); + } -#endif // _OIDVARIABLE_H_ + + +#endif // _OIDVARIABLE_H_ diff --git a/src/OpaqueValue.hpp b/src/OpaqueValue.hpp deleted file mode 100644 index af543fc..0000000 --- a/src/OpaqueValue.hpp +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright 2011-2012 Tanjeff-Nicolai Moos - * - * This file is part of the agentXcpp library. - * - * AgentXcpp is free software: you can redistribute it and/or modify - * it under the terms of the AgentXcpp library license, version 1, which - * consists of the GNU General Public License and some additional - * permissions. - * - * AgentXcpp is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * See the AgentXcpp library license in the LICENSE file of this package - * for more details. - */ -#ifndef _OPAQUE_H_ -#define _OPAQUE_H_ - -#include "AbstractValue.hpp" -#include "exceptions.hpp" - -namespace agentxcpp -{ - /** - * \brief Represents an Opaque object as described in RFC 2741, section - * 5.4. - * - * This class represent binary data. - * - * \note There are no functions to convert the binary data to/from - * std::string. If that is needed, OctetStringValue might be a better - * choice. - */ - class OpaqueValue : public AbstractValue - { - public: - /** - * \brief The string. - * - * According to RFC 2578, Opaque is used to wrap any ASN.1-type. - */ - binary value; - - /** - * \internal - * - * \brief Encode the object as described in RFC 2741, section 5.4 / - * 5.3 - * - * Note: - * We always use big endian. - */ - binary serialize() const; - - /** - * \internal - * - * \brief Parse Constructor. - * - * This constructor parses the serialized form of the object. - * It takes an iterator, starts parsing at the position of the - * iterator and advances the iterator to the position right behind - * the object. - * - * The constructor expects valid data from the stream; if parsing - * fails, parse_error is thrown. In this case, the iterator - * position is undefined. - * - * \param pos Iterator pointing to the current stream position. - * The iterator is advanced while reading the header. - * - * \param end Iterator pointing one element past the end of the - * current stream. This is needed to mark the end of the - * buffer. - * - * \param big_endian Whether the input stream is in big endian - * format - */ - OpaqueValue(binary::const_iterator& pos, - const binary::const_iterator& end, - bool big_endian=true); - - /** - * \brief Constructor for initializing with data. - */ - OpaqueValue(binary initial_value) : value(initial_value) {} - - /** - * \brief Standard constructor. - */ - OpaqueValue() - { - } - }; -} - -#endif diff --git a/src/OpaqueValue.cpp b/src/OpaqueVariable.cpp similarity index 90% rename from src/OpaqueValue.cpp rename to src/OpaqueVariable.cpp index 9022005..f1a080d 100644 --- a/src/OpaqueValue.cpp +++ b/src/OpaqueVariable.cpp @@ -17,23 +17,23 @@ * for more details. */ -#include "OpaqueValue.hpp" +#include "OpaqueVariable.hpp" using namespace agentxcpp; -binary OpaqueValue::serialize() const +binary OpaqueVariable::serialize() const { binary serialized; // encode size (big endian) - int size = value.size(); + int size = v.size(); serialized.push_back(size >> 24 & 0xff); serialized.push_back(size >> 16 & 0xff); serialized.push_back(size >> 8 & 0xff); serialized.push_back(size >> 0 & 0xff); // encode value - serialized += value; + serialized += v; // Padding bytes int padsize = 4 - (size % 4); @@ -46,7 +46,7 @@ binary OpaqueValue::serialize() const } -OpaqueValue::OpaqueValue(binary::const_iterator& pos, +OpaqueVariable::OpaqueVariable(binary::const_iterator& pos, const binary::const_iterator& end, bool big_endian) { @@ -88,7 +88,7 @@ OpaqueValue::OpaqueValue(binary::const_iterator& pos, } // Get value - value.assign(pos, pos+size); + v.assign(pos, pos+size); pos += size; // Eat padding bytes diff --git a/src/OpaqueVariable.hpp b/src/OpaqueVariable.hpp index a55c295..0cc0f27 100644 --- a/src/OpaqueVariable.hpp +++ b/src/OpaqueVariable.hpp @@ -1,40 +1,319 @@ +/* + * Copyright 2011-2012 Tanjeff-Nicolai Moos + * + * This file is part of the agentXcpp library. + * + * AgentXcpp is free software: you can redistribute it and/or modify + * it under the terms of the AgentXcpp library license, version 1, which + * consists of the GNU General Public License and some additional + * permissions. + * + * AgentXcpp is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * See the AgentXcpp library license in the LICENSE file of this package + * for more details. + */ #ifndef _OPAQUEVARIABLE_H_ #define _OPAQUEVARIABLE_H_ -#include "OpaqueValue.hpp" -#include "Variable.hpp" +#include "AbstractVariable.hpp" +#include "exceptions.hpp" namespace agentxcpp { - - class OpaqueVariable : public Variable + /** + * \brief Represents an Opaque object as described in RFC 2741, section + * 5.4. + * + * This class represent binary data. + * + * \note There are no functions to convert the binary data to/from + * std::string. If that is needed, OctetStringValue might be a better + * choice. + */ + class OpaqueVariable : public AbstractVariable { + protected: + /** + * \brief The string. + * + * According to RFC 2578, Opaque is used to wrap any ASN.1-type. + */ + binary v; + private: - OpaqueValue v; + /** + * \brief The new value for the variable in a Set operation. + * + * The Set operation is performed in up to four steps (testset, + * commitset, cleanupset, undoset). Only the testset step actually + * receives the new value. This value is stored here so that it can + * be delivered to commitset(), undoset() and cleanupset(). + */ + QSharedPointer new_value; + + public: + + /** + * \internal + * + * \brief Encode the object as described in RFC 2741, section 5.4 / + * 5.3 + * + * Note: + * We always use big endian. + */ + binary serialize() const; + + /** + * \internal + * + * \brief Parse Constructor. + * + * This constructor parses the serialized form of the object. + * It takes an iterator, starts parsing at the position of the + * iterator and advances the iterator to the position right behind + * the object. + * + * The constructor expects valid data from the stream; if parsing + * fails, parse_error is thrown. In this case, the iterator + * position is undefined. + * + * \param pos Iterator pointing to the current stream position. + * The iterator is advanced while reading the header. + * + * \param end Iterator pointing one element past the end of the + * current stream. This is needed to mark the end of the + * buffer. + * + * \param big_endian Whether the input stream is in big endian + * format + */ + OpaqueVariable(binary::const_iterator& pos, + const binary::const_iterator& end, + bool big_endian=true); - public: + /** + * \brief Constructor for initializing with data. + */ + OpaqueVariable(binary initial_value) : v(initial_value) {} - OpaqueVariable(OpaqueValue _value = OpaqueValue()) - { - v = _value; - } + /** + * \brief Standard constructor. + */ + OpaqueVariable() + { + } - void setValue(OpaqueValue _value) + void setValue(binary _v) + { + v = _v; + } + + binary value() + { + return v; + } + + /** + * \internal + * + * \brief Handle a Get Request. + * + * This function calls get() to obtain the new value, + * converts it to QSharedPointer and returns it. + */ + virtual void handle_get() { - v = _value; + this->get(); } - virtual OpaqueValue get() + /** + * \brief Handle a Get request. + * + * This method is called when an SNMP Get request is received. + * It shall + * return the current value of the variable. + * + * \note This method is pure virtual and thus \e must be + * implemented. It is not possible to implement write-only + * SNMP variables. + * + * \return The value of the variable. + */ + virtual void get() { - return v; } - virtual OpaqueValue value() + /** + * \internal + * + * \brief Handle a TestSet request. + * + * This function converts the argument to QSharedPointer() and + * calls + * testset() with the converted value. If conversion fails, + * testset() is not called. This function also stores the given + * value to the new_value member. + * + * \param v The new value for the variable. + * + * \return agentxcpp::AbstractVariable::wrongType if the conversion + * fails. Otherwise, + * the result of + * testset() is + * returned. + */ + virtual testset_result_t handle_testset(QSharedPointer _v) { - return v; + new_value = qSharedPointerDynamicCast(_v); + if (new_value) + { + // Type matches variable + return testset(new_value); + } + else + { + // Wrong type + return wrongType; + } + + } + + /** + * \brief Handle a TestSet request. + * + * This method is called when an SNMP TestSet request is received. + * It + * shall check whether a Set operation is possible for the + * variable. It shall acquire the resources needed to perform the + * Set operation (but the Set shall not yet be performed). + * + * The default implementation returns + * agentxcpp::AbstractVariable::noAccess to indicate that + * this is a read-only variable. Thus, for read-only variables this + * method need not be overridden. + * + * \param v The new value for the object. + * + * \return The result of the check. + */ + virtual testset_result_t testset(QSharedPointer _v) + { + return noAccess; + } + + /** + * \internal + * + * \brief Handle a CleanupSet request. + * + * This function calls cleanupset() with the value from the last + * handle_testset() invokation. + */ + virtual void handle_cleanupset() + { + cleanupset(new_value); + } + + /** + * \brief Handle a CleanupSet request. + * + * This method is called when an SNMP CleanupSet request is + * received. It + * shall release any ressources allocated by testset(). + * + * The default implementation does nothing. If no action is + * required to perform the CleanupSet operaiton, this method need + * not be overridden. + * + * \param v The new value for the object. + */ + virtual void cleanupset(QSharedPointer _v) + { + return; + } + + /** + * \internal + * + * \brief Handle a CommitSet request. + * + * This function calls commitset() with the value from the last + * handle_testset() Invocation and returns its return value. + */ + virtual bool handle_commitset() + { + return commitset(new_value); + } + + /** + * \brief Handle a CommitSet request. + * + * This method is called when an SNMP CommitSet request is + * received. It + * shall perform the actual write operation. + * + * The default implementation returns false to indicate that the + * operation failed. To implement a writable SNMP variable this + * method must be overridden. + * + * \param v The new value for the object. + * + * \return True if the operation succeeded, false otherwise. + */ + virtual bool commitset(QSharedPointer _v) + { + return false; + } + + /** + * \internal + * + * \brief Handle a UndoSet request. + * + * This function calls undoset() with the value from the last + * handle_testset() invocation and returns its return value. + * + */ + virtual bool handle_undoset() + { + return undoset(new_value); + } + + /** + * \brief Handle an UndoSet request. + * + * This method is called when an SNMP UndoSet request is received. + * It + * shall undo whatever commitset() performed. It shall also release + * all resources allocated by testset(). + * + * The default implementation returns false to indicate that + * the operation failed. It is strongly recommended that writable + * variables override this method. + * + * \internal + * + * A default implementation is provided to allow implementing + * read-only variables. + * + * \endinternal + * + * \param v The new value for the object. + * + * \return True on success, false otherwise. + */ + virtual bool undoset(QSharedPointer _v) + { + return false; } }; } -#endif // _OPAQUEVARIABLE_H_ + +#endif // _OPAQUEVARIABLE_H_ diff --git a/src/TimeTicksValue.hpp b/src/TimeTicksValue.hpp deleted file mode 100644 index 7706e88..0000000 --- a/src/TimeTicksValue.hpp +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright 2011-2012 Tanjeff-Nicolai Moos - * - * This file is part of the agentXcpp library. - * - * AgentXcpp is free software: you can redistribute it and/or modify - * it under the terms of the AgentXcpp library license, version 1, which - * consists of the GNU General Public License and some additional - * permissions. - * - * AgentXcpp is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * See the AgentXcpp library license in the LICENSE file of this package - * for more details. - */ -#ifndef _TIMETICKS_H_ -#define _TIMETICKS_H_ - -#include - -#include "AbstractValue.hpp" -#include "exceptions.hpp" - - -namespace agentxcpp -{ - /** - * \brief Represents an TimeTicks as described in RFC 2741 - * - * \note This class has no toOid() method, because RFC 2578, - * 7.7. "Mapping of the INDEX clause" does not describe - * how to convert TimeTicks to an OID. - */ - class TimeTicksValue : public AbstractValue - { - public: - /** - * \brief The TimeTicks value. - * - * According to RFC 2578, TimeTicks is a non-negative 32-bit - * number. - */ - quint32 value; - - /** - * \brief Create an TimeTicksValue without initialization. - * - * \param initial_value The initial value of the object. - */ - TimeTicksValue(quint32 initial_value = 0) - : value(initial_value) - { - } - - /** - * \internal - * - * \brief Parse Constructor. - * - * This constructor parses the serialized form of the object. - * It takes an iterator, starts parsing at the position of the - * iterator and advances the iterator to the position right behind - * the object. - * - * The constructor expects valid data from the stream; if parsing - * fails, parse_error is thrown. In this case, the iterator - * position is undefined. - * - * \param pos Iterator pointing to the current stream position. - * The iterator is advanced while reading the header. - * - * \param end Iterator pointing one element past the end of the - * current stream. This is needed to mark the end of the - * buffer. - * - * \param big_endian Whether the input stream is in big endian - * format - */ - TimeTicksValue(binary::const_iterator& pos, - const binary::const_iterator& end, - bool big_endian=true); - - /** - * \internal - * - * \brief Encode the object as described in RFC 2741, section 5.4 - * - * This function uses big endian. - */ - virtual binary serialize() const; - }; -} - -#endif diff --git a/src/TimeTicksValue.cpp b/src/TimeTicksVariable.cpp similarity index 83% rename from src/TimeTicksValue.cpp rename to src/TimeTicksVariable.cpp index 6ccc601..b497b79 100644 --- a/src/TimeTicksValue.cpp +++ b/src/TimeTicksVariable.cpp @@ -17,23 +17,23 @@ * for more details. */ -#include "TimeTicksValue.hpp" +#include "TimeTicksVariable.hpp" #include "util.hpp" using namespace agentxcpp; -binary TimeTicksValue::serialize() const +binary TimeTicksVariable::serialize() const { binary serialized; // encode value (big endian) - write32(serialized, value); + write32(serialized, v); return serialized; } -TimeTicksValue::TimeTicksValue(binary::const_iterator& pos, +TimeTicksVariable::TimeTicksVariable(binary::const_iterator& pos, const binary::const_iterator& end, bool big_endian) { @@ -44,5 +44,5 @@ TimeTicksValue::TimeTicksValue(binary::const_iterator& pos, } // Get value - value = read32(pos, big_endian); + v = read32(pos, big_endian); } diff --git a/src/TimeTicksVariable.hpp b/src/TimeTicksVariable.hpp index bfe2d56..f6905a9 100644 --- a/src/TimeTicksVariable.hpp +++ b/src/TimeTicksVariable.hpp @@ -1,40 +1,315 @@ +/* + * Copyright 2011-2012 Tanjeff-Nicolai Moos + * + * This file is part of the agentXcpp library. + * + * AgentXcpp is free software: you can redistribute it and/or modify + * it under the terms of the AgentXcpp library license, version 1, which + * consists of the GNU General Public License and some additional + * permissions. + * + * AgentXcpp is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * See the AgentXcpp library license in the LICENSE file of this package + * for more details. + */ #ifndef _TIMETICKSVARIABLE_H_ #define _TIMETICKSVARIABLE_H_ -#include "TimeTicksValue.hpp" -#include "Variable.hpp" +#include + +#include "AbstractVariable.hpp" +#include "exceptions.hpp" + namespace agentxcpp { - - class TimeTicksVariable : public Variable + /** + * \brief Represents an TimeTicks as described in RFC 2741 + * + * \note This class has no toOid() method, because RFC 2578, + * 7.7. "Mapping of the INDEX clause" does not describe + * how to convert TimeTicks to an OID. + */ + class TimeTicksVariable : public AbstractVariable { - private: + protected: + /** + * \brief The TimeTicks value. + * + * According to RFC 2578, TimeTicks is a non-negative 32-bit + * number. + */ + quint32 v; + + private: - TimeTicksValue v; + /** + * \brief The new value for the variable in a Set operation. + * + * The Set operation is performed in up to four steps (testset, + * commitset, cleanupset, undoset). Only the testset step actually + * receives the new value. This value is stored here so that it can + * be delivered to commitset(), undoset() and cleanupset(). + */ + QSharedPointer new_value; - public: + public: - TimeTicksVariable(TimeTicksValue _value = TimeTicksValue()) - { - v = _value; - } + /** + * \brief Create an TimeTicksValue without initialization. + * + * \param initial_value The initial value of the object. + */ + TimeTicksVariable(quint32 initial_value = 0) + : v(initial_value) + { + } - void setValue(TimeTicksValue _value) + /** + * \internal + * + * \brief Parse Constructor. + * + * This constructor parses the serialized form of the object. + * It takes an iterator, starts parsing at the position of the + * iterator and advances the iterator to the position right behind + * the object. + * + * The constructor expects valid data from the stream; if parsing + * fails, parse_error is thrown. In this case, the iterator + * position is undefined. + * + * \param pos Iterator pointing to the current stream position. + * The iterator is advanced while reading the header. + * + * \param end Iterator pointing one element past the end of the + * current stream. This is needed to mark the end of the + * buffer. + * + * \param big_endian Whether the input stream is in big endian + * format + */ + TimeTicksVariable(binary::const_iterator& pos, + const binary::const_iterator& end, + bool big_endian=true); + + /** + * \internal + * + * \brief Encode the object as described in RFC 2741, section 5.4 + * + * This function uses big endian. + */ + virtual binary serialize() const; + + void setValue(quint32 _v) + { + v = _v; + } + + quint32 value() + { + return v; + } + + /** + * \internal + * + * \brief Handle a Get Request. + * + * This function calls get() to obtain the new value, + * converts it to QSharedPointer and returns it. + */ + virtual void handle_get() { - v = _value; + this->get(); } - virtual TimeTicksValue get() + /** + * \brief Handle a Get request. + * + * This method is called when an SNMP Get request is received. + * It shall + * return the current value of the variable. + * + * \note This method is pure virtual and thus \e must be + * implemented. It is not possible to implement write-only + * SNMP variables. + * + * \return The value of the variable. + */ + virtual void get() { - return v; } - virtual TimeTicksValue value() + /** + * \internal + * + * \brief Handle a TestSet request. + * + * This function converts the argument to QSharedPointer() and + * calls + * testset() with the converted value. If conversion fails, + * testset() is not called. This function also stores the given + * value to the new_value member. + * + * \param v The new value for the variable. + * + * \return agentxcpp::AbstractVariable::wrongType if the conversion + * fails. Otherwise, + * the result of + * testset() is + * returned. + */ + virtual testset_result_t handle_testset(QSharedPointer _v) { - return v; + new_value = qSharedPointerDynamicCast(_v); + if (new_value) + { + // Type matches variable + return testset(new_value); + } + else + { + // Wrong type + return wrongType; + } + } + /** + * \brief Handle a TestSet request. + * + * This method is called when an SNMP TestSet request is received. + * It + * shall check whether a Set operation is possible for the + * variable. It shall acquire the resources needed to perform the + * Set operation (but the Set shall not yet be performed). + * + * The default implementation returns + * agentxcpp::AbstractVariable::noAccess to indicate that + * this is a read-only variable. Thus, for read-only variables this + * method need not be overridden. + * + * \param v The new value for the object. + * + * \return The result of the check. + */ + virtual testset_result_t testset(QSharedPointer _v) + { + return noAccess; + } + + /** + * \internal + * + * \brief Handle a CleanupSet request. + * + * This function calls cleanupset() with the value from the last + * handle_testset() invokation. + */ + virtual void handle_cleanupset() + { + cleanupset(new_value); + } + + /** + * \brief Handle a CleanupSet request. + * + * This method is called when an SNMP CleanupSet request is + * received. It + * shall release any ressources allocated by testset(). + * + * The default implementation does nothing. If no action is + * required to perform the CleanupSet operaiton, this method need + * not be overridden. + * + * \param v The new value for the object. + */ + virtual void cleanupset(QSharedPointer _v) + { + return; + } + + /** + * \internal + * + * \brief Handle a CommitSet request. + * + * This function calls commitset() with the value from the last + * handle_testset() Invocation and returns its return value. + */ + virtual bool handle_commitset() + { + return commitset(new_value); + } + + /** + * \brief Handle a CommitSet request. + * + * This method is called when an SNMP CommitSet request is + * received. It + * shall perform the actual write operation. + * + * The default implementation returns false to indicate that the + * operation failed. To implement a writable SNMP variable this + * method must be overridden. + * + * \param v The new value for the object. + * + * \return True if the operation succeeded, false otherwise. + */ + virtual bool commitset(QSharedPointer _v) + { + return false; + } + + /** + * \internal + * + * \brief Handle a UndoSet request. + * + * This function calls undoset() with the value from the last + * handle_testset() invocation and returns its return value. + * + */ + virtual bool handle_undoset() + { + return undoset(new_value); + } + + /** + * \brief Handle an UndoSet request. + * + * This method is called when an SNMP UndoSet request is received. + * It + * shall undo whatever commitset() performed. It shall also release + * all resources allocated by testset(). + * + * The default implementation returns false to indicate that + * the operation failed. It is strongly recommended that writable + * variables override this method. + * + * \internal + * + * A default implementation is provided to allow implementing + * read-only variables. + * + * \endinternal + * + * \param v The new value for the object. + * + * \return True on success, false otherwise. + */ + virtual bool undoset(QSharedPointer _v) + { + return false; + } }; } -#endif // _TIMETICKSVARIABLE_H_ + +#endif // _TIMETICKSVARIABLE_H_ diff --git a/src/Variable.hpp b/src/Variable.hpp deleted file mode 100644 index 78fb176..0000000 --- a/src/Variable.hpp +++ /dev/null @@ -1,326 +0,0 @@ -/* - * Copyright 2011-2012 Tanjeff-Nicolai Moos - * - * This file is part of the agentXcpp library. - * - * AgentXcpp is free software: you can redistribute it and/or modify - * it under the terms of the AgentXcpp library license, version 1, which - * consists of the GNU General Public License and some additional - * permissions. - * - * AgentXcpp is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * See the AgentXcpp library license in the LICENSE file of this package - * for more details. - */ -#ifndef _VARIABLE_H_ -#define _VARIABLE_H_ - -#include - -#include "AbstractVariable.hpp" - -namespace agentxcpp -{ - /** - * \brief Class template to help implement SNMP variables. - * - * This class template can be used as base class for SNMP variable - * implementations. It implements the agentxcpp::AbstractVariable - * interface and tailors it for a concrete type (in contrast, - * agentxcpp::AbstractVariable deals with agentxcpp::AbstractValue). - * - * It shall be instantiated with the value type the variable - * provides (which should be a class derived from agentxcpp::AbstractValue). - * Then, some functions shall be overridden to provide the - * functionality. Example: - * - * \code - * // An IntegerValue variable - * class simpleCounter : public Variable - * { - * private: - * // The internal counter - * IntegerValue counter; - * - * public: - * - * // Handle SNMP get request, overrides Variable::get() - * virtual IntegerValue get() - * { - * return counter; - * } - * - * // Increment the internal counter - * void increment() - * { - * counter.value++; - * } - * }; - * \endcode - * - * The get() method \e must be implemented. It is not allowed (and not - * possible) to implement write-only SNMP variables. - * - * To support write access (which is optional), the methods testset() and - * commitset() must be implemented. The undoset() method should also be - * implemented in this case. The cleanupset() method may be implemented if - * needed. - * - * \internal - * - * This class template implements the methods of agentxcpp::AbstractVariable - * in such a way that they call methods for the more specific value types. - * Example: - * - * \code - * virtual testset_result_t handle_testset(QSharedPointer v) - * { - * new_value = qSharedPointerDynamicCast(v); - * if (new_value) - * { - * // Type matches variable - * return this->testset(new_value); - * } - * else - * { - * // Wrong type - * return wrongType; - * } - * } - * \endcode - * - * As can be seen, handle_testset() receives a pointer to an - * agentxcpp::AbstractValue object. - * This pointer is casted to 'T' (the template parameter) before giving it - * to the testset() method. The testset() method is the one which can be - * implemented in derived classes (while handle_testset() should not be - * re-implemented). - * - * This class template remembers the new value and gives it to the - * functions testset(), commitset(), cleanupset() and undoset(). Also, type - * conversion is done (see the example) and an error is generated on type - * mismatch. - */ - template< class T > - class Variable : public AbstractVariable - { - private: - /** - * \brief The new value for the variable in a Set operation. - * - * The Set operation is performed in up to four steps (testset, - * commitset, cleanupset, undoset). Only the testset step actually - * receives the new value. This value is stored here so that it can - * be delivered to commitset(), undoset() and cleanupset(). - */ - QSharedPointer new_value; - - public: - - /** - * \internal - * - * \brief Handle a Get Request. - * - * This function calls get() to obtain the new value, - * converts it to QSharedPointer and returns it. - */ - virtual QSharedPointer handle_get() - { - // Get new value by calling this->get(), then allocate a new - // variable, initializing it with the new value: - QSharedPointer retval( new T(this->get()) ); - - return retval; - } - - /** - * \brief Handle a Get request. - * - * This method is called when an SNMP Get request is received. - * It shall - * return the current value of the variable. - * - * \note This method is pure virtual and thus \e must be - * implemented. It is not possible to implement write-only - * SNMP variables. - * - * \return The value of the variable. - */ - virtual T get()= 0; - - /** - * \internal - * - * \brief Handle a TestSet request. - * - * This function converts the argument to QSharedPointer() and - * calls - * testset() with the converted value. If conversion fails, - * testset() is not called. This function also stores the given - * value to the new_value member. - * - * \param v The new value for the variable. - * - * \return agentxcpp::AbstractVariable::wrongType if the conversion - * fails. Otherwise, - * the result of - * testset() is - * returned. - */ - virtual testset_result_t handle_testset(QSharedPointer v) - { - new_value = qSharedPointerDynamicCast(v); - if (new_value) - { - // Type matches variable - return testset(new_value); - } - else - { - // Wrong type - return wrongType; - } - - } - - /** - * \brief Handle a TestSet request. - * - * This method is called when an SNMP TestSet request is received. - * It - * shall check whether a Set operation is possible for the - * variable. It shall acquire the resources needed to perform the - * Set operation (but the Set shall not yet be performed). - * - * The default implementation returns - * agentxcpp::AbstractVariable::noAccess to indicate that - * this is a read-only variable. Thus, for read-only variables this - * method need not be overridden. - * - * \param v The new value for the object. - * - * \return The result of the check. - */ - virtual testset_result_t testset(QSharedPointer v) - { - return noAccess; - } - - /** - * \internal - * - * \brief Handle a CleanupSet request. - * - * This function calls cleanupset() with the value from the last - * handle_testset() invokation. - */ - virtual void handle_cleanupset() - { - cleanupset(new_value); - } - - /** - * \brief Handle a CleanupSet request. - * - * This method is called when an SNMP CleanupSet request is - * received. It - * shall release any ressources allocated by testset(). - * - * The default implementation does nothing. If no action is - * required to perform the CleanupSet operaiton, this method need - * not be overridden. - * - * \param v The new value for the object. - */ - virtual void cleanupset(QSharedPointer v) - { - return; - } - - /** - * \internal - * - * \brief Handle a CommitSet request. - * - * This function calls commitset() with the value from the last - * handle_testset() Invocation and returns its return value. - */ - virtual bool handle_commitset() - { - return commitset(new_value); - } - - /** - * \brief Handle a CommitSet request. - * - * This method is called when an SNMP CommitSet request is - * received. It - * shall perform the actual write operation. - * - * The default implementation returns false to indicate that the - * operation failed. To implement a writable SNMP variable this - * method must be overridden. - * - * \param v The new value for the object. - * - * \return True if the operation succeeded, false otherwise. - */ - virtual bool commitset(QSharedPointer v) - { - return false; - } - - /** - * \internal - * - * \brief Handle a UndoSet request. - * - * This function calls undoset() with the value from the last - * handle_testset() invocation and returns its return value. - * - */ - virtual bool handle_undoset() - { - return undoset(new_value); - } - - /** - * \brief Handle an UndoSet request. - * - * This method is called when an SNMP UndoSet request is received. - * It - * shall undo whatever commitset() performed. It shall also release - * all resources allocated by testset(). - * - * The default implementation returns false to indicate that - * the operation failed. It is strongly recommended that writable - * variables override this method. - * - * \internal - * - * A default implementation is provided to allow implementing - * read-only variables. - * - * \endinternal - * - * \param v The new value for the object. - * - * \return True on success, false otherwise. - */ - virtual bool undoset(QSharedPointer v) - { - return false; - } - - }; - -} - - - -#endif /* _VARIABLE_H_ */ From 16770e767919b31387c548de143ec6f07a80703d Mon Sep 17 00:00:00 2001 From: "Tanjeff-N. Moos" Date: Fri, 21 Feb 2014 07:56:19 +0100 Subject: [PATCH 27/89] Make it compile again. --- src/AddAgentCapsPDU.cpp | 6 ++-- src/AddAgentCapsPDU.hpp | 18 ++++++------ src/GetBulkPDU.cpp | 8 ++--- src/GetBulkPDU.hpp | 8 ++--- src/GetNextPDU.cpp | 8 ++--- src/GetNextPDU.hpp | 8 ++--- src/GetPDU.cpp | 12 ++++---- src/GetPDU.hpp | 6 ++-- src/MasterProxy.cpp | 58 +++++++++++++++++++------------------ src/MasterProxy.hpp | 36 +++++++++++------------ src/OctetStringVariable.hpp | 7 ----- src/OpenPDU.cpp | 4 +-- src/OpenPDU.hpp | 16 +++++----- src/PDUwithContext.hpp | 10 +++---- src/RegisterPDU.cpp | 2 +- src/RegisterPDU.hpp | 8 ++--- src/RemoveAgentCapsPDU.cpp | 4 +-- src/RemoveAgentCapsPDU.hpp | 10 +++---- src/ResponsePDU.hpp | 4 +-- src/UnregisterPDU.cpp | 2 +- src/UnregisterPDU.hpp | 8 ++--- src/helpers.cpp | 22 +++++++------- src/helpers.hpp | 10 +++---- src/varbind.cpp | 58 ++++++++++++++++++------------------- src/varbind.hpp | 18 ++++++------ 25 files changed, 173 insertions(+), 178 deletions(-) diff --git a/src/AddAgentCapsPDU.cpp b/src/AddAgentCapsPDU.cpp index 20ddcaa..86effcc 100644 --- a/src/AddAgentCapsPDU.cpp +++ b/src/AddAgentCapsPDU.cpp @@ -28,10 +28,10 @@ AddAgentCapsPDU::AddAgentCapsPDU(binary::const_iterator& pos, : PDUwithContext(pos, end, big_endian) { // parse ID - id = OidValue(pos, end, big_endian); + id = OidVariable(pos, end, big_endian); // parse descr - descr = OctetStringValue(pos, end, big_endian); + descr = OctetStringVariable(pos, end, big_endian); } @@ -53,7 +53,7 @@ binary AddAgentCapsPDU::serialize() } -AddAgentCapsPDU::AddAgentCapsPDU(OidValue id, OctetStringValue descr) +AddAgentCapsPDU::AddAgentCapsPDU(OidVariable id, OctetStringVariable descr) { this->id = id; this->descr = descr; diff --git a/src/AddAgentCapsPDU.hpp b/src/AddAgentCapsPDU.hpp index 1f1028e..e78f9cd 100644 --- a/src/AddAgentCapsPDU.hpp +++ b/src/AddAgentCapsPDU.hpp @@ -20,8 +20,8 @@ #define _ADDAGENTCAPSPDU_H_ #include "PDUwithContext.hpp" -#include "OidValue.hpp" -#include "OctetStringValue.hpp" +#include "OidVariable.hpp" +#include "OctetStringVariable.hpp" namespace agentxcpp { @@ -40,7 +40,7 @@ namespace agentxcpp * See RFC 2741, 6.2.14. "The agentx-AddAgentCaps-PDU" for * details. */ - OidValue id; + OidVariable id; /** * \brief An Octet String containing a DisplayString to be used as @@ -49,7 +49,7 @@ namespace agentxcpp * * See RFC 2741, 6.2.14. "The agentx-AddAgentCaps-PDU" for details. */ - OctetStringValue descr; + OctetStringVariable descr; public: @@ -97,14 +97,14 @@ namespace agentxcpp * * \param descr The value of the descr field. */ - AddAgentCapsPDU(OidValue id, OctetStringValue descr); + AddAgentCapsPDU(OidVariable id, OctetStringVariable descr); /** * \brief Set the id field * * \param id The new id value. */ - void set_id(OidValue id) + void set_id(OidVariable id) { this->id = id; } @@ -114,7 +114,7 @@ namespace agentxcpp * * \return The id value. */ - OidValue get_id() + OidVariable get_id() { return this->id; } @@ -124,7 +124,7 @@ namespace agentxcpp * * \param descr The new descr value. */ - void set_descr(OctetStringValue descr) + void set_descr(OctetStringVariable descr) { this->descr = descr; } @@ -134,7 +134,7 @@ namespace agentxcpp * * \return The descr value. */ - OctetStringValue get_descr() + OctetStringVariable get_descr() { return this->descr; } diff --git a/src/GetBulkPDU.cpp b/src/GetBulkPDU.cpp index 4885c64..462a263 100644 --- a/src/GetBulkPDU.cpp +++ b/src/GetBulkPDU.cpp @@ -37,10 +37,10 @@ GetBulkPDU::GetBulkPDU(binary::const_iterator& pos, // Get SearchRanges until the PDU is completely parsed while( pos < end ) { - pair p; + pair p; - p.first = OidValue(pos, end, big_endian); - p.second = OidValue(pos, end, big_endian); + p.first = OidVariable(pos, end, big_endian); + p.second = OidVariable(pos, end, big_endian); if(p.second.get_include() == true) { @@ -67,7 +67,7 @@ binary GetBulkPDU::serialize() const write16(serialized, this->max_repititions); // Add OID's - vector< pair >::const_iterator i; + vector< pair >::const_iterator i; for(i = sr.begin(); i < sr.end(); i++) { serialized += i->first.serialize(); diff --git a/src/GetBulkPDU.hpp b/src/GetBulkPDU.hpp index ad6530b..493dfda 100644 --- a/src/GetBulkPDU.hpp +++ b/src/GetBulkPDU.hpp @@ -25,7 +25,7 @@ #include #include "PDUwithContext.hpp" -#include "OidValue.hpp" +#include "OidVariable.hpp" using std::vector; using std::pair; @@ -44,10 +44,10 @@ namespace agentxcpp * \brief The SearchRange list * * A GetBulk %PDU can have multiple SearchRanges. A SearchRange - * consists of two OidValue's. We store them in a pair<>, and store the + * consists of two OidVariable's. We store them in a pair<>, and store the * pais<>'s in a vector< pair<> >. */ - vector< pair > sr; + vector< pair > sr; /** * \brief The number of variables in the SearchRangeList that are @@ -107,7 +107,7 @@ namespace agentxcpp * \note There is no set_sr() function, because the SearchRange * list can be modified in place. */ - vector< pair >& get_sr() + vector< pair >& get_sr() { return this->sr; } diff --git a/src/GetNextPDU.cpp b/src/GetNextPDU.cpp index 3e63459..1dfae11 100644 --- a/src/GetNextPDU.cpp +++ b/src/GetNextPDU.cpp @@ -30,10 +30,10 @@ GetNextPDU::GetNextPDU(binary::const_iterator& pos, // Get SearchRanges until the PDU is completely parsed while( pos < end ) { - pair p; + pair p; - p.first = OidValue(pos, end, big_endian); // starting oid - p.second = OidValue(pos, end, big_endian); // ending oid + p.first = OidVariable(pos, end, big_endian); // starting oid + p.second = OidVariable(pos, end, big_endian); // ending oid if(p.second.get_include() == true) { @@ -54,7 +54,7 @@ binary GetNextPDU::serialize() const binary serialized; // Add OID's - vector< pair >::const_iterator i; + vector< pair >::const_iterator i; for(i = sr.begin(); i < sr.end(); i++) { serialized += i->first.serialize(); diff --git a/src/GetNextPDU.hpp b/src/GetNextPDU.hpp index 4ef0e56..18aba45 100644 --- a/src/GetNextPDU.hpp +++ b/src/GetNextPDU.hpp @@ -23,7 +23,7 @@ #include #include "PDUwithContext.hpp" -#include "OidValue.hpp" +#include "OidVariable.hpp" using std::vector; using std::pair; @@ -42,10 +42,10 @@ namespace agentxcpp * \brief The SearchRange list * * A GetNext %PDU can have multiple SearchRanges. A SearchRange - * consists of two OidValue's. We store them in a pair<>, and store the + * consists of two OidVariable's. We store them in a pair<>, and store the * pais<>'s in a vector< pair<> >. */ - vector< pair > sr; + vector< pair > sr; public: /** @@ -89,7 +89,7 @@ namespace agentxcpp * \note There is no set_sr() function, because the SearchRange * list can be modified in place. */ - vector< pair >& get_sr() + vector< pair >& get_sr() { return this->sr; } diff --git a/src/GetPDU.cpp b/src/GetPDU.cpp index ee3a76f..853d611 100644 --- a/src/GetPDU.cpp +++ b/src/GetPDU.cpp @@ -30,11 +30,11 @@ GetPDU::GetPDU(binary::const_iterator& pos, // Get SearchRanges until the PDU is completely parsed while( pos < end ) { - // read starting OidValue - sr.push_back(OidValue(pos, end, big_endian)); + // read starting OidVariable + sr.push_back(OidVariable(pos, end, big_endian)); - // read and forget ending OidValue (but check its include field) - OidValue ending(pos, end, big_endian); + // read and forget ending OidVariable (but check its include field) + OidVariable ending(pos, end, big_endian); if(ending.get_include() == true) { // Parse error according to RFC 2741, 5.2 "SearchRange": @@ -44,7 +44,7 @@ GetPDU::GetPDU(binary::const_iterator& pos, - pos += 4; // ignore empty "end" OidValue + pos += 4; // ignore empty "end" OidVariable } } @@ -56,7 +56,7 @@ binary GetPDU::serialize() const binary serialized; // Add OID's - vector::const_iterator i; + vector::const_iterator i; for(i = sr.begin(); i < sr.end(); i++) { serialized += i->serialize(); diff --git a/src/GetPDU.hpp b/src/GetPDU.hpp index 7617c64..ec124d5 100644 --- a/src/GetPDU.hpp +++ b/src/GetPDU.hpp @@ -22,7 +22,7 @@ #include #include "PDUwithContext.hpp" -#include "OidValue.hpp" +#include "OidVariable.hpp" using std::vector; @@ -43,7 +43,7 @@ namespace agentxcpp * OID is always the null OID. We simply store the OID's for the * getPDU into a vector<>. */ - vector sr; + vector sr; public: /** @@ -87,7 +87,7 @@ namespace agentxcpp * \note There is no set_sr() function, because the SearchRange * list can be modified in place. */ - vector& get_sr() + vector& get_sr() { return this->sr; } diff --git a/src/MasterProxy.cpp b/src/MasterProxy.cpp index a88a6b8..140992f 100644 --- a/src/MasterProxy.cpp +++ b/src/MasterProxy.cpp @@ -41,7 +41,7 @@ using namespace agentxcpp; MasterProxy::MasterProxy(std::string _description, quint8 _default_timeout, - OidValue _id, + OidVariable _id, std::string _filename) : socket_file(_filename.c_str()), sessionID(0), @@ -273,7 +273,7 @@ void MasterProxy::do_registration(QSharedPointer pdu) -void MasterProxy::register_subtree(OidValue subtree, +void MasterProxy::register_subtree(OidVariable subtree, quint8 priority, quint8 timeout) { @@ -308,7 +308,7 @@ void MasterProxy::register_subtree(OidValue subtree, -void MasterProxy::unregister_subtree(OidValue subtree, +void MasterProxy::unregister_subtree(OidVariable subtree, quint8 priority) { // The UnregisterPDU @@ -442,29 +442,30 @@ void MasterProxy::handle_getpdu(QSharedPointer response, QSharedPoi // RFC 2741, 7.2.3.1 "Subagent Processing of the agentx-Get-PDU" // Extract searchRange list - vector sr = get_pdu->get_sr(); + vector sr = get_pdu->get_sr(); - // Iterate over list and handle each OidValue separately - vector::const_iterator i; + // Iterate over list and handle each OidVariable separately + vector::const_iterator i; quint16 index = 1; // Index is 1-based (RFC 2741, // 5.4. "Value Representation"): for(i = sr.begin(); i != sr.end(); i++) { // The name - const OidValue& name = *i; + const OidVariable& name = *i; // Find variable for current OID - map< OidValue, QSharedPointer >::const_iterator var; + map< OidVariable, QSharedPointer >::const_iterator var; var = variables.find(name); if(var != variables.end()) { - // Step (2): We have a variable for this OidValue + // Step (2): We have a variable for this OidVariable // update variable try { // Add variable to response (Step (1): include name) - response->varbindlist.push_back( varbind(name, var->second->handle_get()) ); + var->second->handle_get(); + response->varbindlist.push_back( varbind(name, var->second) ); } catch(...) { @@ -480,7 +481,7 @@ void MasterProxy::handle_getpdu(QSharedPointer response, QSharedPoi // Interpret 'name' as prefix: // append .0 and check whether we have a variable // with this name - OidValue name_copy(name, 0); + OidVariable name_copy(name, 0); var = variables.find(name_copy); if(var != variables.end()) @@ -511,20 +512,20 @@ void MasterProxy::handle_getnextpdu(QSharedPointer response, QShare // RFC 2741, 7.2.3.2 "Subagent Processing of the agentx-GetNext-PDU" // Extract searchRange list - vector< pair >& sr = getnext_pdu->get_sr(); + vector< pair >& sr = getnext_pdu->get_sr(); // Iterate over list and handle each SearchRange separately - vector< pair >::const_iterator i; + vector< pair >::const_iterator i; quint16 index = 1; // Index is 1-based (RFC 2741, // 5.4. "Value Representation"): for(i = sr.begin(); i != sr.end(); i++) { // The names - const OidValue& starting_oid = i->first; - const OidValue& ending_oid = i->second; + const OidVariable& starting_oid = i->first; + const OidVariable& ending_oid = i->second; // Find "next" variable - map< OidValue, QSharedPointer >::const_iterator next_var; + map< OidVariable, QSharedPointer >::const_iterator next_var; if( ! starting_oid.get_include()) { // Find the closest lexicographical successor to the starting @@ -557,7 +558,8 @@ void MasterProxy::handle_getnextpdu(QSharedPointer response, QShare // update variable try { - response->varbindlist.push_back( varbind(next_var->first, next_var->second->handle_get()) ); + next_var->second->handle_get(); + response->varbindlist.push_back( varbind(next_var->first, next_var->second) ); } catch(...) { @@ -598,7 +600,7 @@ void MasterProxy::handle_testsetpdu(QSharedPointer response, QShare for(i = vb.begin(), index = 1; i != vb.end(); i++, index++) { // Find the associated variable - map< OidValue, QSharedPointer >::const_iterator var; + map< OidVariable, QSharedPointer >::const_iterator var; var = variables.find(i->get_name()); if(var == variables.end()) { @@ -853,7 +855,7 @@ void MasterProxy::handle_pdu(QSharedPointer pdu) } -void MasterProxy::add_variable(const OidValue& id, QSharedPointer v) +void MasterProxy::add_variable(const OidVariable& id, QSharedPointer v) { // Check whether id is contained in a registration bool is_registered = false; @@ -883,7 +885,7 @@ void MasterProxy::add_variable(const OidValue& id, QSharedPointer t) +void MasterProxy::addTable(const OidVariable& id, QSharedPointer
t) { // Check whether id is contained in a registration bool is_registered = false; @@ -914,21 +916,21 @@ void MasterProxy::addTable(const OidValue& id, QSharedPointer
t) -void MasterProxy::remove_variable(const OidValue& id) +void MasterProxy::remove_variable(const OidVariable& id) { // Remove variable variables.erase(id); // If variable was not registered: ignore } -void MasterProxy::removeTable(const OidValue& id) +void MasterProxy::removeTable(const OidVariable& id) { // Remove variable tables.remove(id); // If table was not registered: ignore } -void MasterProxy::send_notification(const OidValue& snmpTrapOID, - const TimeTicksValue* sysUpTime, +void MasterProxy::send_notification(const OidVariable& snmpTrapOID, + const TimeTicksVariable* sysUpTime, const vector& varbinds) { QSharedPointer pdu(new NotifyPDU); @@ -939,13 +941,13 @@ void MasterProxy::send_notification(const OidValue& snmpTrapOID, // First of all: add mandatory sysUpTime (if given) if(sysUpTime) { - QSharedPointer value(new TimeTicksValue(*sysUpTime)); - vb.push_back(varbind(OidValue(sysUpTime_oid, "0"), value)); + QSharedPointer value(new TimeTicksVariable(*sysUpTime)); + vb.push_back(varbind(OidVariable(sysUpTime_oid, "0"), value)); } // Second: add mandatory snmpTrapOID - QSharedPointer trapoid(new OidValue(snmpTrapOID)); - vb.push_back(varbind(OidValue(snmpTrapOID_oid, "0"), trapoid)); + QSharedPointer trapoid(new OidVariable(snmpTrapOID)); + vb.push_back(varbind(OidVariable(snmpTrapOID_oid, "0"), trapoid)); // Append given varbinds vb.insert(vb.end(), varbinds.begin(), varbinds.end()); diff --git a/src/MasterProxy.hpp b/src/MasterProxy.hpp index ff992e5..7ab2e5c 100644 --- a/src/MasterProxy.hpp +++ b/src/MasterProxy.hpp @@ -30,9 +30,9 @@ #include #include -#include "OidValue.hpp" +#include "OidVariable.hpp" #include "AbstractVariable.hpp" -#include "TimeTicksValue.hpp" +#include "TimeTicksVariable.hpp" #include "ClosePDU.hpp" #include "ResponsePDU.hpp" #include "RegisterPDU.hpp" @@ -161,7 +161,7 @@ namespace agentxcpp * \internal * * The variables are stored in the member variables, which is a - * std::map >. The key is the OID for which the + * std::map >. The key is the OID for which the * variable was added. This allows easy lookup for the request * dispatcher. * @@ -242,7 +242,7 @@ namespace agentxcpp * \brief An Object Identifier that identifies the subagent. May be * the null OID. */ - OidValue id; + OidVariable id; /** * \brief The registrations. @@ -256,12 +256,12 @@ namespace agentxcpp /** * \brief Storage for all SNMP variables known to the MasterProxy. */ - std::map< OidValue, QSharedPointer > variables; + std::map< OidVariable, QSharedPointer > variables; /** * \brief Storage for all SNMP tables known to the MasterProxy. */ - QMap< OidValue, QSharedPointer
> tables; + QMap< OidVariable, QSharedPointer
> tables; /** * \brief The variables affected by the Set operation currently @@ -508,23 +508,23 @@ namespace agentxcpp * * \todo Document exceptions. */ - void send_notification(const OidValue& snmpTrapOID, - const TimeTicksValue* sysUpTime, + void send_notification(const OidVariable& snmpTrapOID, + const TimeTicksVariable* sysUpTime, const std::vector& varbinds=vector()); /** * \brief Writing aid: Send notification without sysUpTime.0. * * This calls \ref send_notification( - * const OidValue&, const TimeTicksValue*, + * const OidVariable&, const TimeTicksVariable*, * const vector&) with a NULL pointer * for the sysUpTime.0 parameter. * * For the documentation of the parameters and exceptions go to - * \ref send_notification(const OidValue&, TimeTicksValue>&, + * \ref send_notification(const OidVariable&, TimeTicksVariable>&, * const vector&) */ - void send_notification(const OidValue& snmpTrapOID, + void send_notification(const OidVariable& snmpTrapOID, const std::vector& varbinds=vector()) { send_notification(snmpTrapOID, 0, varbinds); @@ -562,7 +562,7 @@ namespace agentxcpp */ MasterProxy(std::string description="", quint8 default_timeout=0, - OidValue ID=OidValue(), + OidVariable ID=OidVariable(), std::string unix_domain_socket="/var/agentx/master"); /** @@ -619,7 +619,7 @@ namespace agentxcpp * that a retry will result in a * duplicate_registration error. */ - void register_subtree(OidValue subtree, + void register_subtree(OidVariable subtree, quint8 priority=127, quint8 timeout=0); @@ -664,7 +664,7 @@ namespace agentxcpp */ // TODO: the 'priority' parameter can possibly be omitted: the // value can be stored by master_agent upon subtree registration. - void unregister_subtree(OidValue subtree, + void unregister_subtree(OidVariable subtree, quint8 priority=127); /** @@ -765,7 +765,7 @@ namespace agentxcpp * within a registered MIB * region. */ - void add_variable(const OidValue& id, QSharedPointer v); + void add_variable(const OidVariable& id, QSharedPointer v); /** * \brief Add an SNMP table for serving. @@ -788,7 +788,7 @@ namespace agentxcpp * within a registered MIB * region. */ - void addTable(const OidValue& subtree, + void addTable(const OidVariable& subtree, QSharedPointer
t); /** @@ -804,7 +804,7 @@ namespace agentxcpp * * \exception None. */ - void remove_variable(const OidValue& id); + void remove_variable(const OidVariable& id); /** * \brief Remove an SNMP table so that is not longer accessible. @@ -819,7 +819,7 @@ namespace agentxcpp * * \exception None. */ - void removeTable(const OidValue& id); + void removeTable(const OidVariable& id); }; } diff --git a/src/OctetStringVariable.hpp b/src/OctetStringVariable.hpp index 40b0713..117336e 100644 --- a/src/OctetStringVariable.hpp +++ b/src/OctetStringVariable.hpp @@ -48,13 +48,6 @@ namespace agentxcpp */ OctetStringVariable(QString initial_value); - /** - * \brief Create empty OctetStringValue object. - */ - OctetStringVariable() - { - } - /** * \internal * diff --git a/src/OpenPDU.cpp b/src/OpenPDU.cpp index a708b9a..849158b 100644 --- a/src/OpenPDU.cpp +++ b/src/OpenPDU.cpp @@ -37,9 +37,9 @@ OpenPDU::OpenPDU(binary::const_iterator& pos, timeout = *pos++; pos += 3; // skip reserved fields - id = OidValue(pos, end, big_endian); + id = OidVariable(pos, end, big_endian); - descr = OctetStringValue(pos, end, big_endian); + descr = OctetStringVariable(pos, end, big_endian); } diff --git a/src/OpenPDU.hpp b/src/OpenPDU.hpp index 1a9653f..d130758 100644 --- a/src/OpenPDU.hpp +++ b/src/OpenPDU.hpp @@ -20,8 +20,8 @@ #define _OPENPDU_H_ #include "PDU.hpp" -#include "OidValue.hpp" -#include "OctetStringValue.hpp" +#include "OidVariable.hpp" +#include "OctetStringVariable.hpp" namespace agentxcpp { @@ -34,8 +34,8 @@ namespace agentxcpp { private: quint8 timeout; - OidValue id; - OctetStringValue descr; + OidVariable id; + OctetStringVariable descr; public: /** @@ -101,7 +101,7 @@ namespace agentxcpp /** * \brief Get ID */ - OidValue get_id() + OidVariable get_id() { return this->id; } @@ -109,7 +109,7 @@ namespace agentxcpp /** * \brief Set ID */ - void set_id(OidValue id) + void set_id(OidVariable id) { this->id = id; } @@ -117,7 +117,7 @@ namespace agentxcpp /** * \brief Get descr */ - OctetStringValue get_descr() + OctetStringVariable get_descr() { return this->descr; } @@ -125,7 +125,7 @@ namespace agentxcpp /** * \brief Set descr */ - void set_descr(OctetStringValue descr) + void set_descr(OctetStringVariable descr) { this->descr = descr; } diff --git a/src/PDUwithContext.hpp b/src/PDUwithContext.hpp index eaa1596..d3a764c 100644 --- a/src/PDUwithContext.hpp +++ b/src/PDUwithContext.hpp @@ -22,7 +22,7 @@ #include "PDU.hpp" -#include "OctetStringValue.hpp" +#include "OctetStringVariable.hpp" namespace agentxcpp @@ -47,7 +47,7 @@ namespace agentxcpp /** * \brief The context */ - OctetStringValue context; + OctetStringVariable context; protected: /** @@ -80,7 +80,7 @@ namespace agentxcpp // read the context (if present) if( non_default_context ) { - this->context = OctetStringValue(pos, end, big_endian); + this->context = OctetStringVariable(pos, end, big_endian); } } @@ -144,7 +144,7 @@ namespace agentxcpp * has a context. This can be determined using * has_context(). */ - OctetStringValue get_context() + OctetStringVariable get_context() { return this->context; } @@ -157,7 +157,7 @@ namespace agentxcpp * set the empty string as context. To remove the * context from the PDU, use remove_context(). */ - void set_context(OctetStringValue value) + void set_context(OctetStringVariable value) { this->context = value; this->non_default_context = true; diff --git a/src/RegisterPDU.cpp b/src/RegisterPDU.cpp index a0d25af..093f1bc 100644 --- a/src/RegisterPDU.cpp +++ b/src/RegisterPDU.cpp @@ -36,7 +36,7 @@ RegisterPDU::RegisterPDU(binary::const_iterator& pos, range_subid = *pos++; pos++; // skip reserved field - subtree = OidValue(pos, end, big_endian); + subtree = OidVariable(pos, end, big_endian); // read r.upper_bound only if r.range_subid is not 0 if(end - pos < 4) diff --git a/src/RegisterPDU.hpp b/src/RegisterPDU.hpp index 310b6e0..ea8924b 100644 --- a/src/RegisterPDU.hpp +++ b/src/RegisterPDU.hpp @@ -21,7 +21,7 @@ #include -#include "OidValue.hpp" +#include "OidVariable.hpp" #include "PDUwithContext.hpp" namespace agentxcpp @@ -36,7 +36,7 @@ namespace agentxcpp private: quint8 timeout; quint8 priority; - OidValue subtree; + OidVariable subtree; quint8 range_subid; quint32 upper_bound; @@ -59,14 +59,14 @@ namespace agentxcpp /** * \brief Set the subtree. */ - void set_subtree(OidValue subtree) + void set_subtree(OidVariable subtree) { this->subtree = subtree; } /** * \brief Get the subtree. */ - OidValue get_subtree() + OidVariable get_subtree() { return this->subtree; } diff --git a/src/RemoveAgentCapsPDU.cpp b/src/RemoveAgentCapsPDU.cpp index 8cac219..4b8a419 100644 --- a/src/RemoveAgentCapsPDU.cpp +++ b/src/RemoveAgentCapsPDU.cpp @@ -28,7 +28,7 @@ RemoveAgentCapsPDU::RemoveAgentCapsPDU(binary::const_iterator& pos, : PDUwithContext(pos, end, big_endian) { // parse ID - id = OidValue(pos, end, big_endian); + id = OidVariable(pos, end, big_endian); } @@ -49,7 +49,7 @@ binary RemoveAgentCapsPDU::serialize() } -RemoveAgentCapsPDU::RemoveAgentCapsPDU(OidValue id) +RemoveAgentCapsPDU::RemoveAgentCapsPDU(OidVariable id) { this->id = id; } diff --git a/src/RemoveAgentCapsPDU.hpp b/src/RemoveAgentCapsPDU.hpp index e7d6a70..698fa39 100644 --- a/src/RemoveAgentCapsPDU.hpp +++ b/src/RemoveAgentCapsPDU.hpp @@ -20,7 +20,7 @@ #define _REMOVEAGENTCAPSPDU_H_ #include "PDUwithContext.hpp" -#include "OidValue.hpp" +#include "OidVariable.hpp" namespace agentxcpp { @@ -39,7 +39,7 @@ namespace agentxcpp * See RFC 2741, 6.2.15. "The agentx-RemoveAgentCaps-PDU" for * details. */ - OidValue id; + OidVariable id; public: @@ -85,14 +85,14 @@ namespace agentxcpp * * \param id The value of the id field. */ - RemoveAgentCapsPDU(OidValue id); + RemoveAgentCapsPDU(OidVariable id); /** * \brief Set the id field * * \param id The new id value. */ - void set_id(OidValue id) + void set_id(OidVariable id) { this->id = id; } @@ -102,7 +102,7 @@ namespace agentxcpp * * \return The id value. */ - OidValue get_id() + OidVariable get_id() { return this->id; } diff --git a/src/ResponsePDU.hpp b/src/ResponsePDU.hpp index c7f8708..a45b274 100644 --- a/src/ResponsePDU.hpp +++ b/src/ResponsePDU.hpp @@ -25,8 +25,8 @@ #include #include "PDU.hpp" -#include "OidValue.hpp" -#include "OctetStringValue.hpp" +#include "OidVariable.hpp" +#include "OctetStringVariable.hpp" #include "varbind.hpp" using std::vector; diff --git a/src/UnregisterPDU.cpp b/src/UnregisterPDU.cpp index d063f1d..05a029c 100644 --- a/src/UnregisterPDU.cpp +++ b/src/UnregisterPDU.cpp @@ -35,7 +35,7 @@ UnregisterPDU::UnregisterPDU(binary::const_iterator& pos, range_subid = *pos++; pos++; // skip reserved field - subtree = OidValue(pos, end, big_endian); + subtree = OidVariable(pos, end, big_endian); // read r.upper_bound only if r.range_subid is not 0 if( range_subid ) diff --git a/src/UnregisterPDU.hpp b/src/UnregisterPDU.hpp index 2e36963..354f53a 100644 --- a/src/UnregisterPDU.hpp +++ b/src/UnregisterPDU.hpp @@ -22,7 +22,7 @@ #include #include "PDUwithContext.hpp" -#include "OidValue.hpp" +#include "OidVariable.hpp" namespace agentxcpp @@ -37,7 +37,7 @@ namespace agentxcpp private: quint8 priority; quint8 range_subid; - OidValue subtree; + OidVariable subtree; quint32 upper_bound; public: @@ -59,14 +59,14 @@ namespace agentxcpp /** * \brief Set the subtree. */ - void set_subtree(OidValue subtree) + void set_subtree(OidVariable subtree) { this->subtree = subtree; } /** * \brief Get the subtree. */ - OidValue get_subtree() + OidVariable get_subtree() { return this->subtree; } diff --git a/src/helpers.cpp b/src/helpers.cpp index 1556751..8267924 100644 --- a/src/helpers.cpp +++ b/src/helpers.cpp @@ -36,44 +36,44 @@ namespace agentxcpp static QDateTime process_start_time(QDateTime::currentDateTime()); } - TimeTicksValue agentxcpp::processUpTime() + TimeTicksVariable agentxcpp::processUpTime() { // Calculate uptime qint64 uptime = process_start_time.msecsTo(QDateTime::currentDateTime()); // Convert uptime to hundreths of seconds - TimeTicksValue sysuptime( uptime/10 ); + TimeTicksVariable sysuptime( uptime/10 ); // Return result return sysuptime; } - OidValue agentxcpp::generate_v1_snmpTrapOID(generic_trap_t generic_trap, + OidVariable agentxcpp::generate_v1_snmpTrapOID(generic_trap_t generic_trap, quint32 specific_trap) { // We need the OID of the SNMPv1 traps. These are defined here. // // First we define a "helper" OID: - static const OidValue snmpTraps_oid(snmpMIBObjects_oid, "5"); + static const OidVariable snmpTraps_oid(snmpMIBObjects_oid, "5"); // // Some traps according to RFC 1907: - static const OidValue snmpTraps_coldStart_oid(snmpTraps_oid, "1"); - static const OidValue snmpTraps_warmStart_oid(snmpTraps_oid, "2"); - static const OidValue snmpTraps_authenticationFailure_oid(snmpTraps_oid, "5"); + static const OidVariable snmpTraps_coldStart_oid(snmpTraps_oid, "1"); + static const OidVariable snmpTraps_warmStart_oid(snmpTraps_oid, "2"); + static const OidVariable snmpTraps_authenticationFailure_oid(snmpTraps_oid, "5"); // // Some traps according to RFC 1573: - static const OidValue snmpTraps_linkDown_oid(snmpTraps_oid, "3"); - static const OidValue snmpTraps_linkUp_oid(snmpTraps_oid, "4"); + static const OidVariable snmpTraps_linkDown_oid(snmpTraps_oid, "3"); + static const OidVariable snmpTraps_linkUp_oid(snmpTraps_oid, "4"); // Finally, egpNeighborLoss. According to RC 1907 it is defined in RFC // 1213, however, the latter doesn't define it. On the other hand, // RFC 2089 defines egpNeighborLoss as 1.3.6.1.6.3.1.1.5.6, which is // snmpTraps.6 and corresponds to the comment in RFC 1907, so we use this // one: - static const OidValue snmpTraps_egpNeighborLoss_oid(snmpTraps_oid, "6"); + static const OidVariable snmpTraps_egpNeighborLoss_oid(snmpTraps_oid, "6"); // calculate the value of snmpTrapOID.0 according to RFC 1908: - OidValue value; + OidVariable value; switch(generic_trap) { diff --git a/src/helpers.hpp b/src/helpers.hpp index e9cb4bb..f80327f 100644 --- a/src/helpers.hpp +++ b/src/helpers.hpp @@ -19,8 +19,8 @@ #ifndef _UPTIME_HPP_ #define _UPTIME_HPP_ -#include "TimeTicksValue.hpp" -#include "OidValue.hpp" +#include "TimeTicksVariable.hpp" +#include "OidVariable.hpp" namespace agentxcpp { @@ -30,7 +30,7 @@ namespace agentxcpp * This function calculates the uptime of the current process, in * hundreths of a second. The result may be given as sysUpTime.0. * parameter to \ref agentxcpp::MasterProxy::send_notification( - * const OidValue&, TimeTicksValue*, + * const OidVariable&, TimeTicksVariable*, * const vector&). * * \internal @@ -40,7 +40,7 @@ namespace agentxcpp * * \return The current uptime, in hundreths of a second. */ - TimeTicksValue processUpTime(); + TimeTicksVariable processUpTime(); /** * \brief The allowed values for specific-trap (SNMPv1 trap). @@ -86,7 +86,7 @@ namespace agentxcpp * \exception inval_param If the generic_trap parameter has an * invalid value. */ - OidValue generate_v1_snmpTrapOID(generic_trap_t generic_trap, + OidVariable generate_v1_snmpTrapOID(generic_trap_t generic_trap, quint32 specific_trap=0); diff --git a/src/varbind.cpp b/src/varbind.cpp index 243e21d..6357b0b 100644 --- a/src/varbind.cpp +++ b/src/varbind.cpp @@ -18,14 +18,14 @@ */ #include "varbind.hpp" -#include "OctetStringValue.hpp" -#include "IntegerValue.hpp" -#include "Counter32Value.hpp" -#include "Counter64Value.hpp" -#include "Gauge32Value.hpp" -#include "TimeTicksValue.hpp" -#include "OpaqueValue.hpp" -#include "IpAddressValue.hpp" +#include "OctetStringVariable.hpp" +#include "IntegerVariable.hpp" +#include "Counter32Variable.hpp" +#include "Counter64Variable.hpp" +#include "Gauge32Variable.hpp" +#include "TimeTicksVariable.hpp" +#include "OpaqueVariable.hpp" +#include "IpAddressVariable.hpp" #include "util.hpp" using namespace agentxcpp; @@ -52,21 +52,21 @@ binary varbind::serialize() const } -varbind::varbind(const OidValue& o, QSharedPointer v) +varbind::varbind(const OidVariable& o, QSharedPointer v) { name = o; var = v; // Determine type of variable and fill type field. - if( qSharedPointerDynamicCast(var) ) type = 2; - else if( qSharedPointerDynamicCast(var) ) type = 4; - else if( qSharedPointerDynamicCast(var) ) type = 6; - else if( qSharedPointerDynamicCast(var) ) type = 64; - else if( qSharedPointerDynamicCast(var) ) type = 65; - else if( qSharedPointerDynamicCast(var) ) type = 66; - else if( qSharedPointerDynamicCast(var) ) type = 67; - else if( qSharedPointerDynamicCast(var) ) type = 68; - else if( qSharedPointerDynamicCast(var) ) type = 70; + if( qSharedPointerDynamicCast(var) ) type = 2; + else if( qSharedPointerDynamicCast(var) ) type = 4; + else if( qSharedPointerDynamicCast(var) ) type = 6; + else if( qSharedPointerDynamicCast(var) ) type = 64; + else if( qSharedPointerDynamicCast(var) ) type = 65; + else if( qSharedPointerDynamicCast(var) ) type = 66; + else if( qSharedPointerDynamicCast(var) ) type = 67; + else if( qSharedPointerDynamicCast(var) ) type = 68; + else if( qSharedPointerDynamicCast(var) ) type = 70; else { // Type could not be determined -> invalid parameter. @@ -75,7 +75,7 @@ varbind::varbind(const OidValue& o, QSharedPointer v) } -varbind::varbind(const OidValue& o, type_t t) +varbind::varbind(const OidVariable& o, type_t t) { name = o; @@ -114,37 +114,37 @@ varbind::varbind(binary::const_iterator& pos, pos += 2; // read OID: no exceptions are catched; they are forwarded to the caller - name = OidValue(pos, end, big_endian); + name = OidVariable(pos, end, big_endian); // Get data: no exceptions are catched; they are forwarded to the caller switch(type) { case 2: - var = QSharedPointer(new IntegerValue(pos, end, big_endian)); + var = QSharedPointer(new IntegerVariable(pos, end, big_endian)); break; case 4: - var = QSharedPointer(new OctetStringValue(pos, end, big_endian)); + var = QSharedPointer(new OctetStringVariable(pos, end, big_endian)); break; case 6: - var = QSharedPointer(new OidValue(pos, end, big_endian)); + var = QSharedPointer(new OidVariable(pos, end, big_endian)); break; case 64: - var = QSharedPointer(new IpAddressValue(pos, end, big_endian)); + var = QSharedPointer(new IpAddressVariable(pos, end, big_endian)); break; case 65: - var = QSharedPointer(new Counter32Value(pos, end, big_endian)); + var = QSharedPointer(new Counter32Variable(pos, end, big_endian)); break; case 66: - var = QSharedPointer(new Gauge32Value(pos, end, big_endian)); + var = QSharedPointer(new Gauge32Variable(pos, end, big_endian)); break; case 67: - var = QSharedPointer(new TimeTicksValue(pos, end, big_endian)); + var = QSharedPointer(new TimeTicksVariable(pos, end, big_endian)); break; case 68: - var = QSharedPointer(new OpaqueValue(pos, end, big_endian)); + var = QSharedPointer(new OpaqueVariable(pos, end, big_endian)); break; case 70: - var = QSharedPointer(new Counter64Value(pos, end, big_endian)); + var = QSharedPointer(new Counter64Variable(pos, end, big_endian)); break; case 5: // Null case 128: // noSuchObject diff --git a/src/varbind.hpp b/src/varbind.hpp index 45e9e62..7059b2e 100644 --- a/src/varbind.hpp +++ b/src/varbind.hpp @@ -24,8 +24,8 @@ #include #include -#include "OidValue.hpp" -#include "AbstractValue.hpp" +#include "OidVariable.hpp" +#include "AbstractVariable.hpp" namespace agentxcpp { @@ -40,7 +40,7 @@ namespace agentxcpp /** * \brief The name (OID) of the VarBind. */ - OidValue name; + OidVariable name; /** * \brief The variable inside the varbind. @@ -48,7 +48,7 @@ namespace agentxcpp * This pointer may be 0 if the varbind has a type without a * variable (e.g. "NoSuchObject"). */ - QSharedPointer var; + QSharedPointer var; /** * \brief The type of the varbind. @@ -66,7 +66,7 @@ namespace agentxcpp * The variable must be one of the following types: * - IntegerValue * - OctetStringValue - * - OidValue + * - OidVariable * - IpAddressValue * - Counter32Value * - Gauge32Value @@ -76,7 +76,7 @@ namespace agentxcpp * If the type of the variable cannot be determined, inval_param is * thrown. */ - varbind(const OidValue&, QSharedPointer v); + varbind(const OidVariable&, QSharedPointer v); /** * \brief These values can be used to create a VarBind. @@ -95,7 +95,7 @@ namespace agentxcpp * Only the constants defined by varbind::type_t are allowed. A * wrong type will cause an inval_param exception. */ - varbind(const OidValue&, type_t); + varbind(const OidVariable&, type_t); /** * \internal @@ -128,7 +128,7 @@ namespace agentxcpp /** * \brief Get the name (the OID) stored within the varbind. */ - OidValue get_name() const + OidVariable get_name() const { return name; } @@ -139,7 +139,7 @@ namespace agentxcpp * \note This returns a smart pointer to the variable, i.e. the * variable can be modified in-place. */ - QSharedPointer get_var() const + QSharedPointer get_var() const { return var; } From 3cdba7983f1c102327791fa0dba85a546620bb49 Mon Sep 17 00:00:00 2001 From: "Tanjeff-N. Moos" Date: Fri, 21 Feb 2014 08:18:11 +0100 Subject: [PATCH 28/89] AbstractVariable::handle_get() returns a copy. The method shall return a copy of the variable, because that copy might float around agentXcpp while the value of the original variable might change meanwhile. This becomes particular important if multithreading is used (not intended so far, but we never know...). --- src/AbstractVariable.hpp | 2 +- src/Counter32Variable.hpp | 3 ++- src/Counter64Variable.hpp | 3 ++- src/Gauge32Variable.hpp | 3 ++- src/IntegerVariable.hpp | 3 ++- src/IpAddressVariable.hpp | 3 ++- src/OctetStringVariable.hpp | 3 ++- src/OidVariable.hpp | 3 ++- src/OpaqueVariable.hpp | 3 ++- src/TimeTicksVariable.hpp | 3 ++- 10 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/AbstractVariable.hpp b/src/AbstractVariable.hpp index 03408c0..557325b 100644 --- a/src/AbstractVariable.hpp +++ b/src/AbstractVariable.hpp @@ -56,7 +56,7 @@ namespace agentxcpp * \exception generic_error If obtaining the current value fails. * No other exception shall be thrown. */ - virtual void handle_get() = 0; + virtual QSharedPointer handle_get() = 0; /** diff --git a/src/Counter32Variable.hpp b/src/Counter32Variable.hpp index dc1fe89..6e4d532 100644 --- a/src/Counter32Variable.hpp +++ b/src/Counter32Variable.hpp @@ -98,9 +98,10 @@ namespace agentxcpp * This function calls get() to obtain the new value, * converts it to QSharedPointer and returns it. */ - virtual void handle_get() + virtual QSharedPointer handle_get() { this->get(); + return QSharedPointer(new Counter32Variable(*this)); } /** diff --git a/src/Counter64Variable.hpp b/src/Counter64Variable.hpp index 9dcd6a5..51308d8 100644 --- a/src/Counter64Variable.hpp +++ b/src/Counter64Variable.hpp @@ -98,9 +98,10 @@ namespace agentxcpp * This function calls get() to obtain the new value, * converts it to QSharedPointer and returns it. */ - virtual void handle_get() + virtual QSharedPointer handle_get() { this->get(); + return QSharedPointer(new Counter64Variable(*this)); } /** diff --git a/src/Gauge32Variable.hpp b/src/Gauge32Variable.hpp index ec405d5..7d1ba23 100644 --- a/src/Gauge32Variable.hpp +++ b/src/Gauge32Variable.hpp @@ -128,9 +128,10 @@ namespace agentxcpp * This function calls get() to obtain the new value, * converts it to QSharedPointer and returns it. */ - virtual void handle_get() + virtual QSharedPointer handle_get() { this->get(); + return QSharedPointer(new Gauge32Variable(*this)); } /** diff --git a/src/IntegerVariable.hpp b/src/IntegerVariable.hpp index d8b00ff..8313772 100644 --- a/src/IntegerVariable.hpp +++ b/src/IntegerVariable.hpp @@ -142,9 +142,10 @@ namespace agentxcpp * This function calls get() to obtain the new value, * converts it to QSharedPointer and returns it. */ - virtual void handle_get() + virtual QSharedPointer handle_get() { this->get(); + return QSharedPointer(new IntegerVariable(*this)); } /** diff --git a/src/IpAddressVariable.hpp b/src/IpAddressVariable.hpp index 3410a0c..d1177ab 100644 --- a/src/IpAddressVariable.hpp +++ b/src/IpAddressVariable.hpp @@ -182,9 +182,10 @@ namespace agentxcpp * This function calls get() to obtain the new value, * converts it to QSharedPointer and returns it. */ - virtual void handle_get() + virtual QSharedPointer handle_get() { this->get(); + return QSharedPointer(new IpAddressVariable(*this)); } /** diff --git a/src/OctetStringVariable.hpp b/src/OctetStringVariable.hpp index 117336e..905557a 100644 --- a/src/OctetStringVariable.hpp +++ b/src/OctetStringVariable.hpp @@ -121,9 +121,10 @@ namespace agentxcpp * * \brief Handle a Get Request. */ - virtual void handle_get() + virtual QSharedPointer handle_get() { this->get(); + return QSharedPointer(new OctetStringVariable(*this)); } /** diff --git a/src/OidVariable.hpp b/src/OidVariable.hpp index c2071f9..95a499e 100644 --- a/src/OidVariable.hpp +++ b/src/OidVariable.hpp @@ -451,9 +451,10 @@ namespace agentxcpp * This function calls get() to obtain the new value, * converts it to QSharedPointer and returns it. */ - virtual void handle_get() + virtual QSharedPointer handle_get() { this->get(); + return QSharedPointer(new OidVariable(*this)); } /** diff --git a/src/OpaqueVariable.hpp b/src/OpaqueVariable.hpp index 0cc0f27..f11d75f 100644 --- a/src/OpaqueVariable.hpp +++ b/src/OpaqueVariable.hpp @@ -127,9 +127,10 @@ namespace agentxcpp * This function calls get() to obtain the new value, * converts it to QSharedPointer and returns it. */ - virtual void handle_get() + virtual QSharedPointer handle_get() { this->get(); + return QSharedPointer(new OpaqueVariable(*this)); } /** diff --git a/src/TimeTicksVariable.hpp b/src/TimeTicksVariable.hpp index f6905a9..7a2b72c 100644 --- a/src/TimeTicksVariable.hpp +++ b/src/TimeTicksVariable.hpp @@ -124,9 +124,10 @@ namespace agentxcpp * This function calls get() to obtain the new value, * converts it to QSharedPointer and returns it. */ - virtual void handle_get() + virtual QSharedPointer handle_get() { this->get(); + return QSharedPointer(new TimeTicksVariable(*this)); } /** From c7be4eb218d64fa116211cc64703cfe7e40f0ca8 Mon Sep 17 00:00:00 2001 From: "Tanjeff-N. Moos" Date: Sun, 30 Mar 2014 21:52:27 +0200 Subject: [PATCH 29/89] Make OidVariable::contains() a const method. --- src/OidVariable.cpp | 2 +- src/OidVariable.hpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/OidVariable.cpp b/src/OidVariable.cpp index d201e80..c2fe6e2 100644 --- a/src/OidVariable.cpp +++ b/src/OidVariable.cpp @@ -346,7 +346,7 @@ OidVariable& OidVariable::operator=(const OidVariable& other) } -bool OidVariable::contains(const OidVariable& id) +bool OidVariable::contains(const OidVariable& id) const { // If id has fewer subids than this: not contained if(this->size() > id.size()) diff --git a/src/OidVariable.hpp b/src/OidVariable.hpp index 95a499e..1dfea5f 100644 --- a/src/OidVariable.hpp +++ b/src/OidVariable.hpp @@ -395,7 +395,7 @@ namespace agentxcpp * \return True if id is contained in the subtree, false * otherwise. */ - bool contains(const OidVariable& id); + bool contains(const OidVariable& id) const; /** * \internal From bad7738f3840cb92c92647e833a3844a8e953238 Mon Sep 17 00:00:00 2001 From: "Tanjeff-N. Moos" Date: Tue, 1 Apr 2014 23:53:22 +0200 Subject: [PATCH 30/89] Fix serialization code for OidVariable. --- src/OidVariable.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/OidVariable.cpp b/src/OidVariable.cpp index c2fe6e2..97b5eb0 100644 --- a/src/OidVariable.cpp +++ b/src/OidVariable.cpp @@ -17,7 +17,6 @@ * for more details. */ -//#include #include #include "OidVariable.hpp" #include "exceptions.hpp" @@ -176,10 +175,10 @@ binary OidVariable::serialize() const // copy subids to serialized while( subid != this->end() ) { - serialized.push_back( (*subid) << 24 & 0xff ); - serialized.push_back( (*subid) << 16 & 0xff ); - serialized.push_back( (*subid) << 8 & 0xff ); - serialized.push_back( (*subid) << 0 & 0xff ); + serialized.push_back( (*subid) >> 24 & 0xff ); + serialized.push_back( (*subid) >> 16 & 0xff ); + serialized.push_back( (*subid) >> 8 & 0xff ); + serialized.push_back( (*subid) >> 0 & 0xff ); subid++; } From 9e3dd00e99d9090d328eca42b31997da6f853942 Mon Sep 17 00:00:00 2001 From: "Tanjeff-N. Moos" Date: Wed, 2 Apr 2014 08:36:36 +0200 Subject: [PATCH 31/89] Add some convenience functions to OidVariable. Namely, the following functions were added: - OidVariable operator+(quint32 subid) const - OidVariable operator+(const OidVariable& o) const - OidVariable& operator+=(const OidVariable& o) - OidVariable(const OidVariable& o, quint32 id) --- src/OidVariable.cpp | 10 +++++ src/OidVariable.hpp | 90 ++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 98 insertions(+), 2 deletions(-) diff --git a/src/OidVariable.cpp b/src/OidVariable.cpp index 97b5eb0..79ad835 100644 --- a/src/OidVariable.cpp +++ b/src/OidVariable.cpp @@ -83,6 +83,16 @@ OidVariable::OidVariable(const OidVariable& o, std::string id) } +OidVariable::OidVariable(const OidVariable& o, quint32 id) +{ + // start with o + *this = o; + + // add suboid + append(id); +} + + std::ostream& agentxcpp::operator<<(std::ostream& out, const OidVariable& o) { // Leading dot diff --git a/src/OidVariable.hpp b/src/OidVariable.hpp index 1dfea5f..8f69f13 100644 --- a/src/OidVariable.hpp +++ b/src/OidVariable.hpp @@ -157,8 +157,8 @@ namespace agentxcpp OidVariable(std::string id); /** - * \brief Initialize an OidValue object with another OidValue plus an OID in - * string format. + * \brief Initialize an OidValue object with another OidValue plus + * a subid. * * All subid's are copied from 'o'. Then, the OID contained within * the string 'id' is appended. The format of the string is @@ -176,6 +176,25 @@ namespace agentxcpp */ OidVariable(const OidVariable& o, std::string id); + /** + * \brief Initialize an OidValue object with another OidValue plus + * a subid. + * + * All subid's are copied from 'o'. Then, the subid 'id' is + * appended. + * + * \internal + * The 'include' field is copied from 'o'. + * \endinternal + * + * \param o The starting OID. + * + * \param id The subid to append. + * + * \exception None. + */ + OidVariable(const OidVariable& o, quint32 id); + /** * \brief Assignment operator * @@ -374,6 +393,73 @@ namespace agentxcpp return o <= *this; } + /** + * \brief Concatenation. + * + * This operator returns a temporary OidVariable object which is + * this OID plus 'subid' appended. Example: + * + * \code + * OidVariable a("1.2.3"); + * OidVariable b = a + 4; // b will be 1.2.3.4 + * \endcode + * + * \param subid The subid to append. + * + * \return The temporary object 'this.subid'. + */ + OidVariable operator+(quint32 subid) const + { + OidVariable result(*this); + result.append(subid); + return result; + } + + /** + * \brief Concatenation + * + * This operator returns a temporary OidVariable object which is + * this OID plus 'o' appended. Example: + * + * \code + * OidVariable a("1.2.3"); + * OidVariable b("4.5.6"); + * OidVariable c = a + b; // c will be 1.2.3.4.5.6 + * \endcode + * + * \param o The OID to append. + * + * \return The temporary object. + */ + OidVariable operator+(const OidVariable& o) const + { + OidVariable result(*this); + result += o; + return result; + } + + /** + * \brief Concatenation + * + * This operator appends 'o' to this OID. Example: + * + * \code + * OidVariable a("1.2.3"); + * OidVariable b("4.5.6"); + * a += b; + * // a is now 1.2.3.4.5.6 + * \endcode + * + * \param o The OID to append. + * + * \return A reference to this OID. + */ + OidVariable& operator+=(const OidVariable& o) + { + this->QVector::operator+=(o); + return *this; + } + /** * \brief Checks whether the given OidValue is in the subtree of this * OidValue. From 4fc662a8c1ccfb0f0130dea1ebba2ff34020ba18 Mon Sep 17 00:00:00 2001 From: "Tanjeff-N. Moos" Date: Wed, 2 Apr 2014 19:44:19 +0200 Subject: [PATCH 32/89] Implement Table, change MasterProxy accordingly. The Table and TableEntry classes are now implemented. The MasterProxy class now doesn't handle tables any more. Instead, a table registers its variables with a MasterProxy object. In other words: the Table knows its MasterProxy, but not vice versa. In addition, the MasterProxy now supports adding/removing several variables at once (handy for table entries) and provides an isRegistered() method. --- src/MasterProxy.cpp | 33 +++++--- src/MasterProxy.hpp | 86 ++++++++++--------- src/Table.cpp | 75 ++++++++++++++++ src/Table.hpp | 202 ++++++++++++++++++++++++++++++++++++++++++-- src/TableEntry.hpp | 76 +++++++++++++++++ 5 files changed, 413 insertions(+), 59 deletions(-) create mode 100644 src/TableEntry.hpp diff --git a/src/MasterProxy.cpp b/src/MasterProxy.cpp index 140992f..512cf24 100644 --- a/src/MasterProxy.cpp +++ b/src/MasterProxy.cpp @@ -854,6 +854,19 @@ void MasterProxy::handle_pdu(QSharedPointer pdu) catch(disconnected) { /* connection loss. Ignore.*/ } } +void MasterProxy::addVariables(QVector< QPair< + OidVariable, QSharedPointer > > v) +{ + QVectorIterator > > iter(v); + while(iter.hasNext()) + { + QPair > varPair; + varPair = iter.next(); + + add_variable(varPair.first, varPair.second); + } +} void MasterProxy::add_variable(const OidVariable& id, QSharedPointer v) { @@ -885,7 +898,7 @@ void MasterProxy::add_variable(const OidVariable& id, QSharedPointer t) +bool MasterProxy::isRegistered(OidVariable id) { // Check whether id is contained in a registration bool is_registered = false; @@ -905,13 +918,7 @@ void MasterProxy::addTable(const OidVariable& id, QSharedPointer
t) } // TODO: handle other registrations (e.g. instance registration) } - - if( ! is_registered ) - { - // Not in a registered area - throw(unknown_registration()); - } - tables[id] = t; + return is_registered; } @@ -922,13 +929,15 @@ void MasterProxy::remove_variable(const OidVariable& id) variables.erase(id); // If variable was not registered: ignore } -void MasterProxy::removeTable(const OidVariable& id) +void MasterProxy::removeVariables(const QVector& ids) { - // Remove variable - tables.remove(id); // If table was not registered: ignore + QVectorIterator iter(ids); + while(iter.hasNext()) + { + remove_variable(iter.next()); + } } - void MasterProxy::send_notification(const OidVariable& snmpTrapOID, const TimeTicksVariable* sysUpTime, const vector& varbinds) diff --git a/src/MasterProxy.hpp b/src/MasterProxy.hpp index 7ab2e5c..766b88b 100644 --- a/src/MasterProxy.hpp +++ b/src/MasterProxy.hpp @@ -29,6 +29,7 @@ #include #include #include +#include #include "OidVariable.hpp" #include "AbstractVariable.hpp" @@ -44,7 +45,6 @@ #include "CommitSetPDU.hpp" #include "UndoSetPDU.hpp" #include "UnixDomainConnector.hpp" -#include "Table.hpp" namespace agentxcpp { @@ -258,11 +258,6 @@ namespace agentxcpp */ std::map< OidVariable, QSharedPointer > variables; - /** - * \brief Storage for all SNMP tables known to the MasterProxy. - */ - QMap< OidVariable, QSharedPointer
> tables; - /** * \brief The variables affected by the Set operation currently * in progress. @@ -767,29 +762,27 @@ namespace agentxcpp */ void add_variable(const OidVariable& id, QSharedPointer v); - /** - * \brief Add an SNMP table for serving. - * - * This adds an SNMP table which can then be read and/or - * written. - * - * Tables can only be added to MIB regions which were registered - * in advance. - * - * If adding a table with an id for which another table is - * already registered, it replaces the old one. - * - * \param subtree The OID of the table. - * - * \param t The table. - * - * \exception unknown_registration If trying to add a table - * with an id which does not reside - * within a registered MIB - * region. - */ - void addTable(const OidVariable& subtree, - QSharedPointer
t); + /** + * \brief Add several SNMP variables for serving. + * + * This function takes multiple variables and calls + * agentxcpp::add_variable(const OidVariable&, + * QSharedPointer) for each of them. + * + * \param vars The variables to be added. Each QPair object contains + * an OID and the pointer to the variable; see + * agentxcpp::add_variable(const OidVariable&, + * QSharedPointer) for an explanation. + * + * \exception unknown_registration If trying to add a variable + * with an id which does not reside + * within a registered MIB + * region. + * + */ + void addVariables(QVector< QPair< + OidVariable, QSharedPointer > + > vars); /** * \brief Remove an SNMP variable so that is not longer accessible. @@ -806,20 +799,33 @@ namespace agentxcpp */ void remove_variable(const OidVariable& id); - /** - * \brief Remove an SNMP table so that is not longer accessible. - * - * This removes a table previously added using addTable(). - * The table will no longer receive SNMP requests. - * - * If no table is known for the given id, nothing happens. + /** + * \brief Remove several SNMP variables so that they are not longer + * accessible. + * + * This function takes multiple variables and calls + * agentxcpp::remove_variable(const OidVariable&) + * for each of them. * - * \param id The OID of the table to remove. This is the OID - * which was given to addTable(). + * \param ids The variables to be removed. * * \exception None. - */ - void removeTable(const OidVariable& id); + */ + void removeVariables(const QVector& ids); + + /** + * \brief Check whether an OID is within the registered ranges. + * + * This function checks whether the given OID is with an OID + * range which was registered before. + * + * \param id The OID to check. + * + * \return true if it is with an registered range, false otherwise. + * + * \exception None. + */ + bool isRegistered(OidVariable id); }; } diff --git a/src/Table.cpp b/src/Table.cpp index 08e0bf0..8efcc09 100644 --- a/src/Table.cpp +++ b/src/Table.cpp @@ -20,3 +20,78 @@ #include "Table.hpp" using namespace agentxcpp; + +bool Table::addEntry(QSharedPointer entry) +{ + if(! myMasterProxy) + { + return false; + } + + OidVariable entryIndex = entry->index(); + + // Ensure that index is not registered + if(entries.contains(entry)) + { + // The entry was already added + return false; + } + + // Register entry + entries[entry] = entryIndex; + + OidVariable index = myOid + entryIndex; + + // Register all variables of the entry + quint32 i = 1; + QSharedPointer var; + QVector< QPair< OidVariable,QSharedPointer > > toRegister; + while( (var = entry->getVariable(i)) ) + { + // Add variable to list + toRegister.append(qMakePair(index + i, var)); + + ++i; + } + myMasterProxy->addVariables(toRegister); + + // All went well, as far as we can tell. + return true; +} + + +bool Table::removeEntry(QSharedPointer entry) +{ + if(! myMasterProxy) + { + return false; + } + + // Ensure that entry is known + if(entries.contains(entry)) + { + // Entry not found + return false; + } + + // Unregister all variables of the entry + OidVariable entryIndex = entries[entry]; // Use index at time of registration + quint32 i = 1; + QSharedPointer var; + QVector toUnregister; + while( (var = entry->getVariable(i)) ) + { + // Add variable to list + toUnregister.append(myOid + entryIndex + i); + + ++i; + } + myMasterProxy->removeVariables(toUnregister); + + // Remove entry from local storage + entries.remove(entry); + + // All went well, as far as we can tell. + return true; + +} diff --git a/src/Table.hpp b/src/Table.hpp index 3718ec9..79bb448 100644 --- a/src/Table.hpp +++ b/src/Table.hpp @@ -17,17 +17,205 @@ * for more details. */ -#ifndef TABLE_HPP_ -#define TABLE_HPP_ +#ifndef _TABLE_HPP_ +#define _TABLE_HPP_ + +#include +#include + +#include "OidVariable.hpp" +#include "TableEntry.hpp" +#include "MasterProxy.hpp" -#include "AbstractVariable.hpp" namespace agentxcpp { - class Table : public AbstractVariable - { - }; +/** + * \brief Manage an SNMP table. + * + * This class manages a sequence of TableEntry objects. Unlike normal + * variables (which inherit from AbstractVariable), the table cannot be + * registered with a MasterProxy object. Instead, the table itself holds a + * pointer to a MasterProxy object and adds and removes its variables + * dynamically. + * + * To implement an SNMP table, a Table object is created and provided with + * - its own OID (which is the "root node" of all contained variables) and + * - a MasterProxy object. + * As long as the MasterProxy object is not provided, no entries can be added + * or removed from the table. + * + * Each TableEntry object has an index, which must be unique within a table. + * The Table class ensures this when adding a TableEntry. + * + * The OID's of the variables within a table are derived from the index of + * their TableEntry, which in turn is derived from the contents of the index + * variables of that very entry. The index variables are normal SNMP variables + * which can be changed (either programatically or by an SNMP set operation). + * In such a case, the TableEntry's index would change. However, the Table + * object is currently not able to detect such a change, i.e. variables will + * keep their OID instead of changing it according to the new index. + * + * \todo Table should detect index changes and re-add the variables + * accordingly. Suggestion: AbstractVariable should provide a + * valueChanged() signal, the Table object registers to this signal for + * all variables in an entry. If the signal is fired, the table checks + * whether the TableEntry index changed, and if so, re-adds the + * variables. I think QSignalMapper is needed. + */ +class Table +{ + public: + + /** + * \brief Constructor. + * + * Create a Table object, assign it an OID and associate it with a + * MasterProxy object. If master is 0, no TableEntry's may be added. + * + * \param oid The tables OID. + * + * \param master The MasterProxy which is used by the table to add + * variables. + * + * \exception None. + */ + Table(OidVariable oid = OidVariable(), MasterProxy* master = 0) + : myMasterProxy(master), + myOid(oid) + { + } + + /** + * \brief Set the OID of the table. + * + * This OID is used to build up the full OID of the variables + * contained in the table. + * + * \note The OID should not be changed while TableEntry objects are + * managed by the Table object. If this happens, the MasterProxy + * will provide access to the variables added before the OID + * change infinitely. The only way to remove those variables is + * to do so manually, using e.g. + * MasterProxy::remove_variable(). + * + * \param oid The new table OID. + * + * \exception None. + * + * \todo Provide a clear() method to cleanly remove all tableEntry's + * + * \todo Re-add managed variables in case of OID change. + */ + void setOid(OidVariable oid) + { + myOid = oid; + } + + /** + * \brief Get the table's OID. + * + * \return The OID used for the table. + * + * \exception None. + */ + OidVariable oid() + { + return myOid; + } + + /** + * \brief Set the MasterProxy object used by this table. + * + * \param master The new MasterProxy object. + * + * \note The MasterProxy should not be changed while TableEntry + * objects are managed by the Table object. If this happens, the + * old MasterProxy will provide access to the variables added + * before infinitely. The only way to remove those variables is + * to do so manually, using e.g. + * MasterProxy::remove_variable(). + * + * \exception None. + * + * \todo: Remove variables from master, re-add them at new master. + */ + void setMasterProxy(MasterProxy* master) + { + myMasterProxy = master; + } + + /** + * \brief Get the MasterProxy object associated with this table. + * + * \return The MasterProxy used for by table. May be the NULL pointer. + * + * \exception None. + */ + MasterProxy* masterProxy() + { + return myMasterProxy; + } + + /** + * \brief Add an entry to the table. + * + * This method adds all variables of the entry to the MasterProxy. + * + * This function fails in the following cases: + * - no MasterProxy is currently associated with the table + * - the entry was already added. + * + * \param entry The TableEntry object to add. + * + * \return true on success, false otherwise. + * + * \exception None. + */ + bool addEntry(QSharedPointer entry); + + /** + * \brief Remove an entry from the table. + * + * This method removes all variables of the entry from the + * MasterProxy. + * + * This function fails in the following cases: + * - no MasterProxy is currently associated with the table + * - the entry is not known to the table (it was not added, or it was + * already removed). + * + * \param entry The TableEntry object to remove. + * + * \return true on success, false otherwise. + * + * \exception None. + */ + bool removeEntry(QSharedPointer entry); + + private: + /** + * \brief The managed TableEntry objects. + * + * For each entry the following data is stored: + * - a pointer to the TableEntry object and + * - the TableEntry's index at the time it was added to the table. + */ + QMap< QSharedPointer, OidVariable > entries; + + /** + * \brief The used MasterProxy object. + * + * May be NULL. + */ + MasterProxy* myMasterProxy; + + /** + * \brief The tables OID. + */ + OidVariable myOid; +}; } /* namespace agentxcpp */ -#endif /* TABLE_HPP_ */ +#endif /* _TABLE_HPP_ */ diff --git a/src/TableEntry.hpp b/src/TableEntry.hpp new file mode 100644 index 0000000..f5a63f4 --- /dev/null +++ b/src/TableEntry.hpp @@ -0,0 +1,76 @@ +/* + * Copyright 2011-2013 Tanjeff-Nicolai Moos + * + * This file is part of the agentXcpp library. + * + * AgentXcpp is free software: you can redistribute it and/or modify + * it under the terms of the AgentXcpp library license, version 1, which + * consists of the GNU General Public License and some additional + * permissions. + * + * AgentXcpp is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * See the AgentXcpp library license in the LICENSE file of this package + * for more details. + */ + +#ifndef _TABLEENTRY_HPP_ +#define _TABLEENTRY_HPP_ + +#include "OidVariable.hpp" + +namespace agentxcpp +{ + + /** + * \brief Base class for table entries. + */ + class TableEntry + { + public: + + /** + * \brief Get the index for this entry. + * + * This method shall provide the index for the entry. The index is + * the concatenation of the index variables, converted to OID's. + * See ///TUTORIAL/// for an example. + * + * \return The index of the entry. + * + * \exception This method shall not throw. + */ + virtual OidVariable index() = 0; + + /** + * \brief Get the variable with of column 'id'. + * + * This method shall return the variable with the column 'id'. If + * no variable is available for the column, the NULL pointer shall + * be returned. + * + * The variables of the table entry shall be consequtive, to + * support iterating the entry (i.e. by incrementing 'id' until + * the NULL pointer is returned). + * + * \return The variable with column 'id'. + * + * \exception This method shall not throw. + */ + virtual QSharedPointer getVariable(quint32 id) = 0; + + /** + * \brief Virtual Destructor. + */ + virtual ~TableEntry() + { + } + + private: + }; + +} /* namespace agentxcpp */ +#endif /* _TABLEENTRY_HPP_ */ From 63990becebacbbe376cd6fc5f4ed360081cde701 Mon Sep 17 00:00:00 2001 From: "Tanjeff-N. Moos" Date: Wed, 2 Apr 2014 22:34:51 +0200 Subject: [PATCH 33/89] Add DisplayStringVariable class. --- src/DisplayStringVariable.hpp | 63 +++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 src/DisplayStringVariable.hpp diff --git a/src/DisplayStringVariable.hpp b/src/DisplayStringVariable.hpp new file mode 100644 index 0000000..c0503ee --- /dev/null +++ b/src/DisplayStringVariable.hpp @@ -0,0 +1,63 @@ +#ifndef _DISPLAYSTRING_H_ +#define _DISPLAYSTRING_H_ + +// Make the class agentxcpp::Variable available: +#include +// Make the class agentxcpp::IntegerValue available: +#include + +namespace agentxcpp +{ + +/** + * \brief A DisplayString variable. + * + * This class represent an SNMP variable with SYNTAX DisplatString. The data + * is stored and processed as an OctetStringVariable, but this class provides + * the methods value() and setValue() for easy string handling. + */ +class DisplayStringVariable : public OctetStringVariable +{ + + public: + + /** + * \brief Create a DisplayString variable + * + * \param _value The initial value of the variable. + * + * \exception None. + */ + DisplayStringVariable(QString _value = QString()) + { + OctetStringVariable::setValue(_value); + } + + /** + * \brief Set the value of the variable. + * + * \param _value The new value. + * + * \exception None. + */ + void setValue(QString _value) + { + OctetStringVariable::setValue(_value); + } + + /** + * \brief Get the value of the variable. + * + * \return The current value. + * + * \exception None. + */ + QString value() + { + return OctetStringVariable::toString(); + } + +}; + +} +#endif // _DISPLAYSTRING_H_ From e437711d48d7475265b3693897cc631e0d4d3f49 Mon Sep 17 00:00:00 2001 From: "Tanjeff-N. Moos" Date: Sat, 5 Apr 2014 17:06:29 +0200 Subject: [PATCH 34/89] Update tutorials, start table tutorial. The tutorial for SNMP table support only includes the extended MIB by now. --- doc/getting_started.dox | 1 + doc/how_to_add_rw_support.dox | 116 +++++++++++------------- doc/how_to_implement_tables.dox | 141 ++++++++++++++++++++++++++++++ doc/how_to_send_notifications.dox | 47 +++++----- doc/how_to_write_a_subagent.dox | 97 +++++++++----------- 5 files changed, 260 insertions(+), 142 deletions(-) create mode 100644 doc/how_to_implement_tables.dox diff --git a/doc/getting_started.dox b/doc/getting_started.dox index 4345045..b614075 100644 --- a/doc/getting_started.dox +++ b/doc/getting_started.dox @@ -29,6 +29,7 @@ sections: -# \subpage how_to_add_rw_support "Learn how to implement writeable SNMP variables." -# \subpage how_to_send_notifications "Learn how to send traps and notifications with agentXcpp." +-# \subpage how_to_implement_tables "Learn how to implement SNMP tables with agentXcpp." Finally, start writing your own subagents. Happy hacking! diff --git a/doc/how_to_add_rw_support.dox b/doc/how_to_add_rw_support.dox index 5c4a7eb..9764b96 100644 --- a/doc/how_to_add_rw_support.dox +++ b/doc/how_to_add_rw_support.dox @@ -7,7 +7,7 @@ * it under the terms of the AgentXcpp library license, version 1, which * consists of the GNU General Public License and some additional * permissions. - * +snmpget -v2c -c rw localhost SIMPLE-MIB::simpleCounter.0 * * AgentXcpp is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the @@ -55,16 +55,16 @@ This is the same as before, but with "ACCESS read-write". A single SNMP Set request may set multiple variables at once (possibly distributed over multiple subagents), and SNMP guarantees an atomic operation -in that case. This means that, should any variable fail to perform the Set -operation, no other variable is allowed to perform the set operation either. -Therefore, the Set operation is carried out in multiple distinct steps: +in that case. This means that, should any variable fail to perform the SET +operation, no other variable is allowed to perform the SET operation either. +Therefore, the SET operation is carried out in multiple distinct steps: -# \b TestSet checks whether the variable could be set at all. This step is performed for all variables (in all subagents) affected by the single SNMP - request. If any variable is not able to accept its new value, the Set + request. If any variable is not able to accept its new value, the SET operation is aborted (and no variable gets updated). During this step - subagents shall allocate the resources they need to carry out the Set - operation later. + subagents shall allocate the resources they need to carry out the SET + operation later, but they shall not update their value yet. -# \b CommitSet actually sets the new value. This step may fail for a variable, even if the TestSet step announced that the CommitSet would work. If that happens, all other variables which already performed the CommitSet must undo @@ -74,58 +74,57 @@ Therefore, the Set operation is carried out in multiple distinct steps: - \b CleanupSet is usually the last step, performed after CommitSet was successful for all variables. In the CleanupSet step, the subagent shall release any resources which where allocated in the TestSet step. - - \b UndoSet is performed if CommitSet failed for any variable. UndoSet is - then called for all variables which already performed CommitSet and + - \b UndoSet may be performed if CommitSet failed for any variable. UndoSet + is then called for all variables which already performed CommitSet and therefore must undo their action. For variables which didn't perform - CommitSet yet, CleanupSet is called instead. Like CleanupSet, UndoSet - shall also releases all resources which were allocated in the TestSet - step. + CommitSet yet, CleanupSet is called instead. UndoSet shall undo the + actions performed by CommitSet and release all resources which were + allocated in the TestSet step. -To implement these actions, the \ref agentxcpp::Variable -"Variable" class provides the methods \ref -agentxcpp::Variable::undoset "testset()", \ref -agentxcpp::Variable::undoset "commitset()", \ref -agentxcpp::Variable::undoset "cleanupset()" and \ref -agentxcpp::Variable::undoset "undoset()" which can be overridden by a -concrete implementation. +To implement these actions, the Variable classes provides the methods +testset(), commitset(), cleanupset() and undoset(), which can be overridden by +a concrete implementation. \section extend_simplecounter Extending the SimpleCounter class To implement write support for the SimpleCounter class, we implement all four -methods. The \ref agentxcpp::Variable::undoset "testset()" -implementation allocates an \ref agentxcpp::IntegerValue "IntegerValue" value, which is deallocated by \ref -agentxcpp::Variable::undoset "cleanupset()" respectively \ref -agentxcpp::Variable::undoset "undoset()". This is not very realistic, -but it demonstrates the usage of the individual steps. +methods. The testset() implementation allocates an quint32 value, which is +deallocated by cleanupset() respectively undoset(). This is not very +realistic, but it demonstrates the usage of the individual steps. The +commitset() method stores the old value (in case an undo needs to be carried +out by undoset()) and sets the new value. + + \subsection TestSet -The \ref agentxcpp::Variable::undoset "testset()" function must be -overridden by any variable which should be writeable. If it is not overridden, -agentXcpp assumes that the variable is read-only (which we exploited in the -first, read-only version). Hence, we implement it for our SimpleCounter class -by adding the following code to it: +The testset() method must be overridden by any variable which should be +writeable. If it is not overridden, agentXcpp assumes that the variable is +read-only (which we exploited in the first, read-only version). This also +means that an e.g. IntegerVariable object is read-only by default and needs to +be subclassed to add write support. Hence, we implement it for our +SimpleCounter class by adding the following code to it: \code private: - IntegerValue* old_value; + quint32* old_value; public: - virtual testset_result_t testset(QSharedPointer new_value) + virtual testset_result_t + testset(QSharedPointer new_value) { try { // Allocate space to store the old value - old_value = new IntegerValue; + old_value = new quint32; } catch(std::bad_alloc) { // Resource allocation failed. return resourceUnavailable; } - // setting the variable will succeed return noError; } @@ -133,27 +132,23 @@ by adding the following code to it: The \ref agentxcpp::Variable::testset "testset()" method receives the value and can check whether setting the variable to this value would work. -Here, we don't check the value, but we allocate an \ref agentxcpp::IntegerValue -"IntegerValue" to store the old value, which is needed for \ref agentxcpp::Variable::undoset -"undoset()". If allocation fails, we return the error +Here, we don't check the value, but we allocate an quint32 to store the old +value, which is needed for undoset(). If allocation fails, we return the error \ref agentxcpp::AbstractVariable::resourceUnavailable "resourceUnavailable". \subsection CommitSet -The \ref agentxcpp::Variable::commitset "commitset()" method must -also be implemented for writeable variables. In the SimpleCounter class, this -method sets the internal value and stores the old one, in case \ref -agentxcpp::Variable::undoset "undoset()" is called: +The commitset() method must also be implemented for writeable variables. In +the SimpleCounter class, this method stores the old value and sets the internal +value: \code - virtual bool commitset(QSharedPointer new_value) + virtual bool commitset(QSharedPointer new_value) { // Remember old value for rollback - *old_value = counter; - + (*old_value) = v; // Set new value - counter = *new_value; - + v = new_value->value(); // Operation succeeded return true; } @@ -161,41 +156,36 @@ agentxcpp::Variable::undoset "undoset()" is called: \subsection CleanupSet -The \ref agentxcpp::Variable::cleanupset "cleanupset()" method -releases old_value again: +The cleanupset() method releases old_value again: \code - virtual void cleanupset(QSharedPointer new_value) + virtual void cleanupset(QSharedPointer new_value) { // Release old value delete old_value; } \endcode -If old_value were an IntegerValue (instead of a pointer to IntegerValue) no allocation -and deallocation would have been necessary. The \ref -agentxcpp::Variable::cleanupset "cleanupset()" method would not be -implemented then. In fact, this method is the only one which is optional for -writeable variables, while the other methods are mandatory. +If old_value were an quint32 (instead of a pointer to quint32), no allocation +and deallocation would have been necessary. The cleanupset() method would not +be implemented then. In fact, this method is the only one which is optional +for writeable variables, while the other methods are mandatory. \subsection UndoSet -The \ref agentxcpp::Variable::undoset "undoset()" method must be -implemented by each variable and perform a rollback. It is technically possible -to omit this method; the compiler has no way to detect a missing -implementation. However, it is an error to omit it, and an error will be -reported to the master agent if it is missing. For simpleCounter implementation -is easy: +The undoset() method must be implemented by each writeable variable and shall +perform a rollback. It is technically possible to omit this method; the +compiler has no way to detect a missing implementation. However, it is an error +to omit it, and an error will be reported to the master agent if it is missing. +For simpleCounter implementation is easy: \code - virtual bool undoset(QSharedPointer new_value) + virtual bool undoset(QSharedPointer new_value) { // Restore old value - counter = *old_value; - + v = *old_value; // Release old value delete old_value; - // Rollback succeeded return true; } diff --git a/doc/how_to_implement_tables.dox b/doc/how_to_implement_tables.dox new file mode 100644 index 0000000..619dd8c --- /dev/null +++ b/doc/how_to_implement_tables.dox @@ -0,0 +1,141 @@ +/* + * Copyright 2011-2013 Tanjeff-Nicolai Moos + * + * This file is part of the agentXcpp library. + * + * AgentXcpp is free software: you can redistribute it and/or modify + * it under the terms of the AgentXcpp library license, version 1, which + * consists of the GNU General Public License and some additional + * permissions. + * + * AgentXcpp is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * See the AgentXcpp library license in the LICENSE file of this package + * for more details. + */ + +/*! + + +\page how_to_implement_tables How to implement a table + +\note This is a follow-up tutorial to \ref how_to_send_notifications. + +So far we learned how to implement single variables and how to send +notifications. This tutorial teaches us how an SNMP table can be implemented. +Again, we start with what we did in the previous tutorials, and add a simple +table to the SIMPLE-MIB: + +\verbatim +SIMPLE-MIB DEFINITIONS ::= BEGIN + +IMPORTS + OBJECT-TYPE FROM SNMPv2-SMI + enterprises FROM SNMPv2-SMI + NOTIFICATION-TYPE FROM SNMPv2-SMI; + +simpleCounter OBJECT-TYPE + SYNTAX INTEGER + ACCESS read-write + STATUS current + DESCRIPTION "A simple counter which is incremented each time + it is queried. Starts with 0." + ::={ enterprises 42 1 } + +simpleCounterStatus NOTIFICATION-TYPE + OBJECTS { simpleCounter } + STATUS current + DESCRIPTION "A notification sent each second." + ::={ enterprises 42 0 1 } + +counterChangeTable OBJECT-TYPE + SYNTAX SEQUENCE OF counterChangeEntry + ACCESS not-accessible + STATUS current + DESCRIPTION "This table lists all changes of the simpleCounter object." + ::= { enterprises 42 2 } + +counterChangeEntry OBJECT-TYPE + SYNTAX counterChangeEntry + ACCESS not-accessible + STATUS current + DESCRIPTION "An entry within the counterChangeEntry table." + INDEX { counterChangeEpoch, counterChangeMilliseconds } + ::= { counterChangeTable 1 } + counterChangeEntry ::= SEQUENCE { + counterChangeEpoch INTEGER, + counterChangeMilliseconds INTEGER, + counterChangeTimeString DisplayString, + counterChangeCounterValue INTEGER + } + +counterChangeEpoch OBJECT-TYPE + SYNTAX INTEGER + ACCESS read-only + STATUS current + DESCRIPTION "The time at which the change occured.This variable contains + the epoch, i.e. seconds since 1970-01-01, 00:00." + ::={ counterChangeEntry 1 } + +counterChangeMilliseconds OBJECT-TYPE + SYNTAX INTEGER + ACCESS read-only + STATUS current + DESCRIPTION "The time at which counter changed. This variable contains the + milliseconds since counterChangeEpoch, to increase + precision." + ::={ counterChangeEntry 2 } + +counterChangeTimeString OBJECT-TYPE + SYNTAX OCTETSTRING + ACCESS read-only + STATUS current + DESCRIPTION "The time (counterChangeEpoch + counterChangeMilliseconds) as a + human-readable string." + ::={ counterChangeEntry 3 } + +counterChangeValue OBJECT-TYPE + SYNTAX INTEGER + ACCESS read-only + STATUS current + DESCRIPTION "The counter value right after the change." + ::={ counterChangeEntry 4 } + +END +\endverbatim + +Our table has an entry for each counter change which occured in the past. The +table starts empty and each time the counter changes (i.e. by an SNMP GET or +SET request), an entry is added. + +Each entry within the table has a timestamp, which consists of the epoch time +and a milliseconds component. This is to show how multiple variables can be +used to form the tables index. In addition, the time is reported in an +human-readable format (e.g. "2011-09-11, 12:00:52.77"). Finally, each entry +reports the new counter value. + +*/ + +//\section implementing_the_variables Implementing the variables. +// +//First of all, we will create the variables notificationEventEpoch, +//notificationEventMilliseconds, notificationEventTimeString and +//notificationEventCounterValue. These are all read-only variable, therefore it +//suffice to instantiate the stanard classes agentXcpp provides: +// +//\code +// IntegerVariable notificationEventEpoch; +// IntegerVariable notificationEventMilliseconds; +// DisplayStringVariable notificationEventTimeString; +// IntegerVariable notificationEventCounterValue; +//\endcode +// +// +// +// +// +// +//*/ diff --git a/doc/how_to_send_notifications.dox b/doc/how_to_send_notifications.dox index 3596352..6409a1f 100644 --- a/doc/how_to_send_notifications.dox +++ b/doc/how_to_send_notifications.dox @@ -37,7 +37,7 @@ notification (or trap) is determined solely by the master agent. We start with the subagent developed in \ref how_to_add_rw_support, which provides the SNMP variable simpleCounter. This counter is incremented each time it is read. Next we will enhance our implementation so that it sends a -notification every second. +notification each second. First of all, let's augment the SIMPLE-MIB: @@ -60,7 +60,7 @@ simpleCounter OBJECT-TYPE simpleCounterStatus NOTIFICATION-TYPE OBJECTS { simpleCounter } STATUS current - DESCRIPTION "A notification sent each 5 seconds." + DESCRIPTION "A notification sent each second." ::={ enterprises 42 0 1 } END @@ -78,7 +78,7 @@ So, how do we implement a notification? Normally, a subagent is just sitting there, waiting for SNMP requests and handling them. Notifications typically arise outside of this mechanism. We simulate that by using a timer which fires every second and sends a notification. We will use a QTimer which can use the -event loop provided by QT. For this we need a class with a QT slot to which the +event loop provided by Qt. For this we need a class with a Qt slot to which the QTimer can be connected. We name that class NotificationSender and put it into its own file: NotificationSender.hpp (for simplicity we implement the whole class in the header, so we won't need an implementation @@ -90,7 +90,7 @@ file). Here ist the NotificationSender.hpp file: #include #include -#include +#include #include #include "SimpleCounter.hpp" @@ -102,12 +102,12 @@ class NotificationSender : public QObject private: MasterProxy* master; - OidValue simpleCounter_oid; + OidVariable simpleCounter_oid; QSharedPointer counter; public: NotificationSender(MasterProxy* _master, - OidValue _oid, + OidVariable _oid, QSharedPointer _counter) : master(_master), simpleCounter_oid(_oid), counter(_counter) { @@ -119,11 +119,11 @@ class NotificationSender : public QObject std::cout << "notification!" << std::endl; std::vector objects; - QSharedPointer counter_value(new IntegerValue(counter->value())); - objects.push_back(varbind(simpleCounter_oid, counter_value)); + QSharedPointer counterVariable(new IntegerVariable(counter->value())); + objects.push_back(varbind(simpleCounter_oid, counterVariable)); QMetaObject::invokeMethod(master, "send_notification", - Q_ARG(const OidValue&, simpleCounter_oid), + Q_ARG(const OidVariable&, simpleCounter_oid), Q_ARG(const std::vector&, objects) ); } @@ -135,18 +135,17 @@ class NotificationSender : public QObject \todo Which OID must be given to send_notification()? The NotificationSender inherits QObject and uses the Q_OBJECT macro, which is -both needed to make the class suitable for QT's signal/slot mechanism. The +both needed to make the class suitable for Qt's signal/slot mechanism. The constructor takes a pointer to the MasterProxy object (needed to send notifications), the simpleCounter's oid (will be included in the notifications) -and a pointer to the counter (will be queried to include the value in the +and a pointer to the counter (will be queried to include its value in the notifications). The sendNotification() slot will be connected to the QTimer object and sends a notification each time it is invoked. Also, it performs an -output to indicate that a notification is sent, which we will possibly miss as -long as the master agent is not yet configured properly. +output to indicate that a notification is sent. We use QMetaObject::invokeMethod() here to invoke the MasterProxy::send_notification() slot. This would even work if the -NotificationSender were running in a separate thread. In the example, were the +NotificationSender were running in a separate thread. In our example, were the NotificationSender and the MasterProxy run in the same thread, a simple call would also work: @@ -173,15 +172,15 @@ int main(int argc, char** argv) QCoreApplication app(argc, argv); MasterProxy master; - OidValue simpleagent_oid = OidValue(enterprises_oid, "42.1"); - master.register_subtree(simpleagent_oid); + OidVariable simpleagentOid = OidVariable(enterprises_oid, "42.1"); + master.register_subtree(simpleagentOid); QSharedPointer counter(new SimpleCounter); - OidValue simpleCounter_oid(simpleagent_oid, "0"); - master.add_variable(simpleCounter_oid, counter); + OidVariable simpleCounterOid = simpleagentOid + 0; + master.add_variable(simpleCounterOid, counter); - // New code: ---------------------------------------- - NotificationSender sender(&master, simpleCounter_oid, counter); + // New code for sending notifications --------------- + NotificationSender sender(&master, simpleCounterOid, counter); QTimer timer; QObject::connect(&timer, SIGNAL(timeout()), @@ -234,7 +233,7 @@ Now, the executable is ready to run. \section running_notification Running the Subagent -\subsection master_agent The master agent +\subsection configuring_the_master_agent Configuring the master agent The subagent is run as described in \ref how_to_write_a_subagent, but to make notifications work, we need additional configuration for the master agent. @@ -259,7 +258,7 @@ Note that the path depends on your system. For example in ArchLinux, it is /etc/rc.d/snmpd. -\subsection snmptrapd The snmptrapd program +\subsection starting_snmptrapd Starting the snmptrapd program To receive notifications, we use the snmptrapd program from the NET-SNMP package. First, we have to configure it. Make sure that the following line is @@ -285,7 +284,7 @@ to stderr (i.e. to the console window). \subsection starting_subagent Starting the Subagent -The subagent is started as last times: +Now, the subagent is started: \verbatim ./simpleagent @@ -306,4 +305,6 @@ snmpset -v1 -c rw localhost SIMPLE-MIB::simpleCounter.0 i 42 This increases or sets the counter value, and the new values are reported within the notifications. +In next lesson you can learn \ref how_to_implement_tables "how to implement SNMP tables"! + */ diff --git a/doc/how_to_write_a_subagent.dox b/doc/how_to_write_a_subagent.dox index 02ddf3f..bd42b81 100644 --- a/doc/how_to_write_a_subagent.dox +++ b/doc/how_to_write_a_subagent.dox @@ -25,9 +25,9 @@ \note It is assumed that agentXcpp is installed properly; see \ref installation for how to do that. -This HOWTO explains how to implement, compile and run a trivial subagent. Our -trivial subagent has only one variable called 'simpleCounter' which is -described within the following MIB: +This HOWTO explains how to implement, compile and run a trivial subagent. Our +subagent has only one variable called 'simpleCounter' which is described within +the following MIB: \verbatim SIMPLE-MIB DEFINITIONS ::= BEGIN @@ -55,8 +55,8 @@ and the main() function within simpleagent.cpp. \section implement_class Implementing the simpleCounter variable -The simpleCounter thing described above is an OBJECT-TYPE. OBJECT-TYPE is a -description of the object, not the object itself. The OID of simpleCounter is +The simpleCounter thing mentioned in the MIB is an OBJECT-TYPE. OBJECT-TYPE is +a description of the object, not the object itself. The OID of simpleCounter is "enterprises.42.1", while the real object will be accessible with OID "enterprises.42.1.0". @@ -75,11 +75,8 @@ completeness): #ifndef _SIMPLECOUNTER_H_ #define _SIMPLECOUNTER_H_ -// Make the class agentxcpp::Variable available: -#include - -// Make the class agentxcpp::IntegerValue available: -#include +// Make the class agentxcpp::IntegerVariable available: +#include \endcode All agentXcpp classes are in the namespace 'agentxcpp'. To make the code more @@ -92,43 +89,31 @@ using namespace agentxcpp; Next, we start our SimpleCounter class: \code -class SimpleCounter : public Variable +class SimpleCounter : public IntegerVariable { \endcode -The simpleCounter has a value type which is given in the SYNTAX clause in the MIB. -AgentXcpp provides various classes to match standard SYNTAX types, all of which -inherit from the \ref agentxcpp::AbstractValue "AbstractValue" class. Our -SimpleCounter class uses \ref agentxcpp::IntegerValue "IntegerValue" as its -value type. +The simpleCounter has a type which is given in the SYNTAX clause in the MIB. +AgentXcpp provides various classes to match standard SYNTAX types. These +classes can be inherited to implement variables of this type, which is what +SimpleCounter does. However, IntegerVariable and it companions can also be used +without subclassing them; they have default get() implementations which do +nothing. Their internal value can be obtained with value() and set with +setValue(), and an SNMP GET request will return this internal state. -Next, the \ref agentxcpp::Variable::get() "get()" method from \ref -agentxcpp::Variable "Variable" must be overridden. This method is invoked on -SNMP GET requests and returns the current value of the object. In our case, it -increments the member variable "counter" and returns the new value: +SimpleCounter inherits from IntegerVariable and overrides +IntegerVariable::get(). This method is invoked on SNMP GET requests and should +update the internal value of the IntegerVariable object. In our case, it simply +increments the member variable "v" (this is easier than using value() and +setValue()): \code - private: - IntegerValue counter; - public: - virtual IntegerValue get() - { - counter.value++; - return counter; - } -\endcode - -We also add a value() method to obtain the current value without -incrementing it. This might become useful in future: - -\code - IntegerValue value() + virtual void get() { - return counter; + ++v; } }; - #endif // _SIMPLECOUNTER_H_ \endcode @@ -195,29 +180,27 @@ the standard OID "1.3.6.1.4.1". The master will then send all SNMP requests within that subtree to our subagent (e.g. "enterprises.42.1.0" or "enterprises.42.1.1.2.0"), regardless of whether the subagent actually can serve them. If a request cannot be served, the \ref agentxcpp::MasterProxy -"MasterProxy" will take care of it and sends an appropriate error message to -the master agent. Thus, our SimpleCounter implementation does not have to deal -with that. +"MasterProxy" will take care of it and send an appropriate error message to the +master agent. Thus, our SimpleCounter implementation does not have to deal with +that. -And here is the code for subtree registration: +Here is the code for subtree registration: \code - OidValue simpleagent_oid = OidValue(enterprises_oid, "42.1"); - master.register_subtree(simpleagent_oid); + OidVariable simpleagentOid = OidVariable(enterprises_oid, "42.1"); + master.register_subtree(simpleagentOid); \endcode -As you can see, an \ref agentxcpp::OidValue "OidValue" object can be created by giving it -the "enterprises_oid" object (which is provided by agentXcpp for convenience) -and an additional string with further subids. +As you can see, an \ref agentxcpp::OidVariable "OidVariable" object can be +created by giving it the "enterprises_oid" object (which is provided by +agentXcpp for convenience) and an additional string with further subids. -Next, we create a SimpleCounter variable and register it with agentXcpp: +Next, we create a SimpleCounter variable and register it with the master: \code QSharedPointer counter(new SimpleCounter); - - OidValue simpleCounter_oid(simpleagent_oid, "0"); - - master.add_variable(simpleCounter_oid, counter); + OidVariable simpleCounterOid = simpleagentOid + 0; + master.add_variable(simpleCounterOid, counter); \endcode This is the place where we create the real SNMP variable 'counter'. This variable is @@ -254,6 +237,8 @@ is used here to add the compiler flags for QT. Note that we do not compile the SimpleCounter class separately, because it is implemented completely within its header file. +On other systems you may need to use another command. + \section running Running the Subagent @@ -287,8 +272,9 @@ The community name is needed later, when issuing a SNMP GET request. We set it to "rw" in the example, but you can use anything you wish. The agentXPerms are not strictly required, but making the socket world-readable -saves us some trouble regarding access restrictions. Next, we (re)start the -master agent using its init scripts: +saves us some trouble regarding access restrictions. In the real world you +should probably use a more restrictive setting. Next, we (re)start the master +agent using its init scripts: \verbatim /etc/init.d/snmpd stop @@ -308,8 +294,7 @@ Now the subagent can be started: ./simpleagent \endverbatim -The subagent should keep sitting in the console, and now we can try if it -works. +The subagent keeps sitting in the console, and now we can try if it works. @@ -317,7 +302,7 @@ works. Our little subagent exposes an INTEGER object with the OID "1.3.6.1.4.1.42.1.0". We can query this object with an SNMP GET request. We use -the NET-SNMP utility snmpget (but you can use any tool you wish, of course): +the NET-SNMP utility snmpget (you can use any tool that you wish, of course): \verbatim snmpget -v2c -c rw localhost 1.3.6.1.4.1.42.1.0 From 6c1fe93b49586a0d126760d44342485fba221a0c Mon Sep 17 00:00:00 2001 From: "Tanjeff-N. Moos" Date: Sat, 5 Apr 2014 17:08:06 +0200 Subject: [PATCH 35/89] Fix wrong path in #include's. --- src/DisplayStringVariable.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/DisplayStringVariable.hpp b/src/DisplayStringVariable.hpp index c0503ee..55126f2 100644 --- a/src/DisplayStringVariable.hpp +++ b/src/DisplayStringVariable.hpp @@ -2,9 +2,9 @@ #define _DISPLAYSTRING_H_ // Make the class agentxcpp::Variable available: -#include +#include "AbstractVariable.hpp" // Make the class agentxcpp::IntegerValue available: -#include +#include "OctetStringVariable.hpp" namespace agentxcpp { From 984a3ddda6779e199d3f747160bc9b53bd16ede7 Mon Sep 17 00:00:00 2001 From: "Tanjeff-N. Moos" Date: Thu, 10 Apr 2014 09:06:26 +0200 Subject: [PATCH 36/89] Add new class Oid. The new class represents an OID. The OidVariable class will be reworked to use Oid internally for storing the its value. This will separate the functionality of an simple OID value from the functionality of an SNMP variable providing an OID value. --- src/Oid.cpp | 249 +++++++++++++++++++++++ src/Oid.hpp | 557 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 806 insertions(+) create mode 100644 src/Oid.cpp create mode 100644 src/Oid.hpp diff --git a/src/Oid.cpp b/src/Oid.cpp new file mode 100644 index 0000000..6cbf35a --- /dev/null +++ b/src/Oid.cpp @@ -0,0 +1,249 @@ +/* + * Copyright 2011-2012 Tanjeff-Nicolai Moos + * + * This file is part of the agentXcpp library. + * + * AgentXcpp is free software: you can redistribute it and/or modify + * it under the terms of the AgentXcpp library license, version 1, which + * consists of the GNU General Public License and some additional + * permissions. + * + * AgentXcpp is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * See the AgentXcpp library license in the LICENSE file of this package + * for more details. + */ + +#include +#include "Oid.hpp" +#include "exceptions.hpp" + + +using namespace agentxcpp; +using namespace std; + + +void Oid::parseString(std::string s) +{ + // Do not parse empty string + if(s.empty()) return; + + // Parse the string + std::istringstream ss(s); + quint32 subid; + char ch; + while(ss) + { + // Read a subid + ss >> subid; + if(!ss) + { + // cannot get number: parse error + // This happens also if the number is too large + throw( inval_param() ); + } + push_back(subid); + + // Read a period + ss >> ch; + if(!ss) + { + // end of string: end of parsing + break; + } + if(ch != '.') + { + // Wrong char: parse error + throw( inval_param() ); + } + } +} + + + +Oid::Oid(std::string s) +{ + // parse the string. Forward all exceptions. + parseString(s); +} + + +Oid::Oid(const Oid& o, std::string id) +{ + // start with o + *this = o; + + // add OID from string. Forward all exceptions. + parseString(id); +} + + +Oid::Oid(const Oid& o, quint32 id) +{ + // start with o + *this = o; + + // add suboid + append(id); +} + + +std::ostream& agentxcpp::operator<<(std::ostream& out, const Oid& o) +{ + // Leading dot + out << "."; + + // If no subidentifiers are present, we are done + if(o.size() == 0) + { + return out; + } + + // Get iterator to first subidentifier + Oid::const_iterator it = o.begin(); + + // Print first subidentifier + out << *it; + it++; + + // Output remaining subidentifiers, each prepended with a dot + while(it != o.end()) + { + out << "." << *it; + it++; + } + + // Done, return + return out; +} + + +bool Oid::operator<(const Oid& o) const +{ + Oid::const_iterator mine, yours; + mine = this->begin(); + yours = o.begin(); + + // Test as many parts as the shorter OID has: + while( mine != this->end() + && yours != o.end() ) + { + if( *mine < *yours ) + { + // my OidValue part is less than yours + return true; + } + if( *mine > *yours ) + { + // my OidValue part is greater than yours + return false; + } + + // our parts are identical; test next part: + mine++; + yours++; + } + + // Ok, either you and I have different length (where the one with fewer + // parts is less than the other) or we have the same number of parts (in + // which case we are identical). + if( this->size() < o.size() ) + { + // I have less parts than you, so I am less than you: + return true; + } + else + { + // I have not less parts than you: + return false; + } +} + + + +bool Oid::operator==(const Oid& o) const +{ + // Quick test: if the OidValues have different number of parts, they are not + // equal: + if( this->size() != o.size() ) + { + return false; + } + + // Test all parts: + Oid::const_iterator mine, yours; + mine = this->begin(); + yours = o.begin(); + + while( mine != this->end() + && yours != o.end() ) + { + if( *mine != *yours ) + { + // The parts differ: OIDs not equal + return false; + } + + // Parts are equal, test next parts + mine++; + yours++; + } + + // All parts tested and all parts were equal. Further both OIDs have the + // same number of parts, thus they are equal. + return true; +} + + +Oid& Oid::operator=(const Oid& other) +{ + // copy inherited stuff + QVector::operator=(other); + + // Return reference to us + return *this; +} + + +bool Oid::contains(const Oid& id) const +{ + // If id has fewer subids than this: not contained + if(this->size() > id.size()) + { + // Is not contained + return false; + } + + // id has at least as many subids than this -> iteration is safe + for(int i = 0; i < this->size(); i++) + { + if( (*this)[i] != id[i] ) + { + // We differ in a subid! + return false; + } + } + + // If we get here, the id starts the same subids as this (it has possibly + // more subids). This means that it is contained in the subtree spanned by + // this. + return true; +} + + +//bool Oid::is_null() const +//{ +// if( this->size() == 0 && +// ! this->include) +// { +// // Is the null OID +// return true; +// } +// else +// { +// return false; +// } +//} diff --git a/src/Oid.hpp b/src/Oid.hpp new file mode 100644 index 0000000..f69b13a --- /dev/null +++ b/src/Oid.hpp @@ -0,0 +1,557 @@ +/* + * Copyright 2011-2014 Tanjeff-Nicolai Moos + * + * This file is part of the agentXcpp library. + * + * AgentXcpp is free software: you can redistribute it and/or modify + * it under the terms of the AgentXcpp library license, version 1, which + * consists of the GNU General Public License and some additional + * permissions. + * + * AgentXcpp is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * See the AgentXcpp library license in the LICENSE file of this package + * for more details. + */ + +#ifndef _OID_H_ +#define _OID_H_ + +#include +#include + +#include +#include + +#include "exceptions.hpp" + + +namespace agentxcpp +{ + /** + * \brief Represents an SNMP object identifier (OID). + * + * This class represents an OID. OID's are sequences of sub-identifiers, + * which are integers. + * + * This class provides constructors taking a string which contains an OID. + * For example, this works: + * + * \code + * Oid myCompany("1.3.6.1.4.1.355"); + * \endcode + * + * Also a constructor is provided which takes an Oid and a string and + * concatenates them, so this works also: + * + * \code + * Oid myObject(myCompany, "1.1.3.0"); + * \endcode + * + * In addition, some common Oid's are provided as constants, e.g. + * 'enterprises_oid', so the following will also work: + * + * \code + * Oid yourCompany(enterprises_oid, 42); // 42 is an integer + * Oid yourCompanyMib(enterprises_oid, "42.1.1"); // "42.1.1" is a string + * \endcode + * + * The string given to the constructors must have a valid syntax. If a + * malformed string is provided, inval_param is thrown and the object is + * not constructed. For example, the following strings are malformed: + * + * \code + * "1,3,6" // wrong separator (must be a period) + * "1.3.6." // trailing character at the end + * "1.3.6.1.4.1.123456789123" // last subid is too big (must fit in a 32 bit unsigned integer) + * \endcode + * + * However, the following strings are accepted: + * + * \code + * "1.3.6" + * "1" // a single subid is ok + * "1.3.6.1.4.1.42.1.0" // 0 as subid is ok + * "" // empty string is ok + * \endcode + * + * This class inherits from QVector, which means that an Oid + * object can be manipulated the same way as a QVector<> can be + * manipulated: + * + * \code + * Oid theirCompany = enterprises_oid; + * theirCompany.append(23); // Don't use a string here! + * \endcode + * + */ + class Oid: public QVector + { + private: + + /** + * \brief Parse an OID from a string and append it. + * + * The OID contained within the string 's' is parsed and appended to + * this object. The format of the string is described above. + * + * \param s The OID to be parsed. + * + * \exception inval_param If the string is malformed. + */ + void parseString(std::string s); + + public: + + /** + * \brief Initialize an Oid object with an OID in string format. + * + * This constructor takes a string and initializes the Oid object + * with the OID contained within this string. The format of the + * string is described above. + * + * \param id The initial object identifier. + * + * \exception inval_param If the string is malformed. + */ + Oid(std::string id); + + /** + * \brief Initialize an Oid object with another Oid plus + * a subid. + * + * All subid's are copied from 'o'. Then, the OID contained within + * the string 'id' is appended. The format of the string is + * described in the documentation of this class. + * + * \param o The starting OID. + * + * \param id The OID to append. + * + * \exception inval_param If the string is malformed. + */ + Oid(const Oid& o, std::string id); + + /** + * \brief Initialize an Oid object with another Oid plus + * a subid. + * + * All subid's are copied from 'o'. Then, the subid 'id' is + * appended. + * + * \param o The starting OID. + * + * \param id The subid to append. + * + * \exception None. + */ + Oid(const Oid& o, quint32 id); + + /** + * \brief Assignment operator + * + * Copies all data from 'o' into this OID. + * + * \param o The OID to copy from. + * + * \return A reference to this OID. + */ + Oid& operator=(const Oid& o); + + /** + * \brief The less-than operator + * + * An OID is less than another OID if either the first + * not-identical part is lesser or if all parts are identical and + * it has lesser parts. + * + * Example:\n + * 1.3.6.1.4.1.42.3.3.1 \n + * is less than \n + * 1.3.6.1.4.1.42.3.4.1 \n + * Note the next to last number. + * + * Also,\n + * 1.3.6.1.4.1.42.3.3.1 \n + * is less than \n + * 1.3.6.1.4.1.42.3.3.1.1 \n + * because it is shorter. + * + * However, \n + * 1.3.6.1.4.1.42.3.3.1 \n + * is greater than \n + * 1.3.6.1.4.1.42.3.2.1.1 \n + * because the 9th number is greater (although the first OID has + * less numbers than the second). + * + * \param o The OID to compare to. + * + * \return True if the OID is less than 'o', false otherwise. + */ + bool operator<(const Oid& o) const; + + /** + * \brief The less-than-or-equal operator + * + * See operator<() for a more detailed description about comparing + * OIDs. + * + * \param o The OID to compare to. + * + * \return True if the OID is less than or equal 'o', + * false otherwise. + */ + bool operator<=(const Oid& o) const + { + if(*this == o || *this < o) + { + return true; + } + else + { + return false; + } + } + + /** + * \brief The equal-operator + * + * See operator<() for a more detailed description about comparing + * OIDs. + * + * \param o The OID to compare to. + * + * \return True if the OIDs are equal, false otherwise. + */ + bool operator==(const Oid& o) const; + + /** + * \brief The not-equal-operator for OIDs. + * + * See operator<() for a more detailed description about comparing + * OIDs. + * + * \param o The OID to compare to. + * + * \return False if the OIDs are equal, true otherwise. + */ + bool operator!=(const Oid& o) const + { + return ! (*this == o); + } + + /** + * \brief The greater-than operator. + * + * See operator<() for a more detailed description about comparing + * OIDs. + * + * \param o The OID to compare to. + * + * \return True if the OID is greater than 'o', false otherwise. + */ + bool operator>(const Oid& o) const + { + // a > b is the same as b < a :-) + return o < *this; + } + + /** + * \brief The greater-than-or-equal operator. + * + * See operator<() for a more detailed description about comparing + * OIDs. + * + * \param o The OID to compare to. + * + * \return True if the OID is greater than or equal 'o', + * false otherwise. + */ + bool operator>=(const Oid& o) const + { + // a >= b is the same as b <= a :-) + return o <= *this; + } + + /** + * \brief Concatenation. + * + * This operator returns a temporary Oid object which is + * this OID plus 'subid' appended. Example: + * + * \code + * Oid a("1.2.3"); + * Oid b = a + 4; // b will be 1.2.3.4 + * \endcode + * + * \param subid The subid to append. + * + * \return The temporary object. + */ + Oid operator+(quint32 subid) const + { + Oid result(*this); + result.append(subid); + return result; + } + + /** + * \brief Concatenation + * + * This operator returns a temporary Oid object which is + * this OID plus 'o' appended. Example: + * + * \code + * Oid a("1.2.3"); + * Oid b("4.5.6"); + * Oid c = a + b; // c will be 1.2.3.4.5.6 + * \endcode + * + * \param o The OID to append. + * + * \return The temporary object. + */ + Oid operator+(const Oid& o) const + { + Oid result(*this); + result += o; + return result; + } + + /** + * \brief Concatenation. + * + * This operator appends 'o' to this OID. Example: + * + * \code + * Oid a("1.2.3"); + * Oid b("4.5.6"); + * a += b; + * // a is now 1.2.3.4.5.6 + * \endcode + * + * \param o The OID to append. + * + * \return A reference to this OID. + */ + Oid& operator+=(const Oid& o) + { + this->QVector::operator+=(o); + return *this; + } + + /** + * \brief Checks whether the given Oid is in the subtree of this + * Oid. + * + * This method checks whether the given OID is included in the + * subtree which has this Oid as root. + * + * Examples:\n + * \code + * Oid id("1.3.6.1.4.1.42.3"); + * id.contains( Oid("1.3.6.1.4.1.42.3") ); // true + * id.contains( Oid("1.3.6.1.4.1.42") ); // false + * id.contains( Oid("1.3.6.1.4.1.43.3") ); // false + * id.contains( Oid("1.3.6.1.4.1.42.3.3.1") ); // true + * \endcode + * + * \param id The OID to check. + * + * \return True if id is contained in the subtree, false + * otherwise. + */ + bool contains(const Oid& id) const; + + /* + * \internal + * + * \brief Whether it is the null Object Identifier + * + * According to RFC 2741, 5.1 "Object Identifier", a null object + * identifier has serial representation of 4 bytes which are + * all set to 0. An OID with no subid's and the index field set to + * 0 results in that representation and is thus considered to be + * the null OID. + * + * \return True if the object is the null OID, false otherwise. + */ +// bool is_null() const; + + friend std::ostream& operator<<(std::ostream& out, + const Oid& o); + }; + + /** + * \brief The output operator for the Oid class. + * + * Object identifiers (Oid objects) can be output as follows: + * + * \code + * Oid led_state(enterprises_oid, "1.3.3.1"); + * cout << "LED state OID: " << led_state << endl; + * \endcode + * + * The last line will output "LED state OID: .1.3.6.1.4.1.3.3.1". + * + * \param out The stream to which to write the output. + * + * \param o The OID to output. + * + * \return The 'out' parameter. + */ + std::ostream& operator<<(std::ostream& out, const agentxcpp::Oid& o); + + + // TODO: Possibly these should be put into the agentxcpp::Oid namespace? + // The use of \memberof is not elegant. + + /** + * \memberof Oid + * + * \brief The 'iso' OID according to RFC 1155. + */ + const Oid iso_oid("1"); + + /** + * \memberof Oid + * + * \brief The 'ccitt' OID according to RFC 1155. + */ + const Oid ccitt_oid("0"); + + /** + * \memberof Oid + * + * \brief The 'joint.iso.ccitt' OID according to RFC 1155. + */ + const Oid joint_iso_ccitt_oid("2"); + + /** + * \memberof Oid + * + * \brief The 'iso.org' OID according to RFC 1155. + */ + const Oid org_oid(iso_oid,"3"); + + /** + * \memberof Oid + * + * \brief The 'iso.org.dod' OID according to RFC 1155. + */ + const Oid dod_oid(org_oid,"6"); + + /** + * \memberof Oid + * + * \brief The 'iso.org.dod.internet' OID according to RFC 1155. + */ + const Oid internet_oid(dod_oid,"1"); + + /** + * \memberof Oid + * + * \brief The 'iso.org.dod.internet.directory' OID according to RFC 1155. + */ + const Oid directory_oid(internet_oid,"1"); + + /** + * \memberof Oid + * + * \brief The 'iso.org.dod.internet.mgmt' OID according to RFC 1155. + */ + const Oid mgmt_oid(internet_oid,"2"); + + /** + * \memberof Oid + * + * \brief The 'iso.org.dod.internet.experimental' OID according to + * RFC 1155. + */ + const Oid experimental_oid(internet_oid,"3"); + + /** + * \memberof Oid + * + * \brief The 'iso.org.dod.internet.private' OID according to RFC 1155. + */ + const Oid private_oid(internet_oid,"4"); + + /** + * \memberof Oid + * + * \brief The 'iso.org.dod.internet.private.enterprises' OID according to + * RFC 1155. + */ + const Oid enterprises_oid(private_oid, "1"); + + /** + * \memberof Oid + * + * \brief The 'snmpMIBObjects' OID according to RFC 1907. + * + * \internal + * + * This OID is used in the context of notifications. + * + * According to RFC 1907:
+ * snmpTrapOID ::= snmpTrap.1
+ * snmpTrap ::= snmpMIBObjects.4
+ * snmpMIBObjects ::= snmpMIB.1
+ * snmpMIB ::= snmpModules.1
+ * + * According to RFC 2578 (SNMPv2-SMI):
+ * snmpModules ::= snmpV2.3
+ * snmpV2 ::= internet.6 + * + * Conclusion:
+ * snmpMIBObjects ::= internet.6.3.1.1 + */ + const Oid snmpMIBObjects_oid(internet_oid, "6.3.1.1"); + + /** + * \memberof Oid + * + * \brief The 'snmpTrapOID' OID according to RFC 1907. + * + * \internal + * + * This OID is used in the context of notifications. + * + * According to RFC 1907:
+ * snmpTrapOID ::= snmpTrap.1
+ * snmpTrap ::= snmpMIBObjects.4
+ * + * Conclusion:
+ * snmpTrapOID ::= snmpMIBObjects.4.1 + */ + const Oid snmpTrapOID_oid(snmpMIBObjects_oid, "4.1"); + + /** + * + * \memberof Oid + * + * \brief The sysUpTime_oid OID according to RFC 1907. + * + * \internal + * + * This OID is used in the context of notifications. + * + * According to RFC 1907:
+ * sysUpTime = system.3
+ * system = mib-2.1 + * + * According to RFC 1902:
+ * mib-2 = mgmt.1OidValue + * + * Conclusion: + * sysUpTime = mgmt.1.1.3 + */ + const Oid sysUpTime_oid(mgmt_oid, "1.1.3"); +} + + +#endif // _OID_H_ From c8d78a58a280b78166f722d0144e3cf6b72ed7f5 Mon Sep 17 00:00:00 2001 From: "Tanjeff-N. Moos" Date: Thu, 10 Apr 2014 22:40:06 +0200 Subject: [PATCH 37/89] Reduce functionality provided by OidVariable. Some functionality was moved to the new Oid class. --- src/AddAgentCapsPDU.cpp | 8 +- src/AddAgentCapsPDU.hpp | 10 +- src/GetBulkPDU.cpp | 15 +- src/GetBulkPDU.hpp | 8 +- src/GetNextPDU.cpp | 15 +- src/GetNextPDU.hpp | 6 +- src/GetPDU.cpp | 12 +- src/GetPDU.hpp | 6 +- src/IntegerVariable.hpp | 6 +- src/IpAddressVariable.hpp | 6 +- src/MasterProxy.cpp | 57 ++-- src/MasterProxy.hpp | 38 +-- src/OctetStringVariable.cpp | 4 +- src/OctetStringVariable.hpp | 4 +- src/Oid.cpp | 26 +- src/Oid.hpp | 41 ++- src/OidVariable.cpp | 266 ++------------- src/OidVariable.hpp | 625 +++--------------------------------- src/OpenPDU.cpp | 6 +- src/OpenPDU.hpp | 8 +- src/RegisterPDU.cpp | 5 +- src/RegisterPDU.hpp | 8 +- src/RemoveAgentCapsPDU.cpp | 7 +- src/RemoveAgentCapsPDU.hpp | 10 +- src/ResponsePDU.hpp | 1 - src/Table.cpp | 10 +- src/Table.hpp | 12 +- src/TableEntry.hpp | 5 +- src/UnregisterPDU.cpp | 5 +- src/UnregisterPDU.hpp | 8 +- src/helpers.cpp | 18 +- src/helpers.hpp | 2 +- src/varbind.cpp | 9 +- src/varbind.hpp | 10 +- 34 files changed, 284 insertions(+), 993 deletions(-) diff --git a/src/AddAgentCapsPDU.cpp b/src/AddAgentCapsPDU.cpp index 86effcc..4b20ebd 100644 --- a/src/AddAgentCapsPDU.cpp +++ b/src/AddAgentCapsPDU.cpp @@ -18,6 +18,7 @@ */ #include "AddAgentCapsPDU.hpp" +#include "OidVariable.hpp" using namespace agentxcpp; @@ -28,7 +29,8 @@ AddAgentCapsPDU::AddAgentCapsPDU(binary::const_iterator& pos, : PDUwithContext(pos, end, big_endian) { // parse ID - id = OidVariable(pos, end, big_endian); + OidVariable o(pos, end, big_endian); + id = o.value(); // parse descr descr = OctetStringVariable(pos, end, big_endian); @@ -42,7 +44,7 @@ binary AddAgentCapsPDU::serialize() binary serialized; // Serialize data - serialized += id.serialize(); + serialized += OidVariable(id).serialize(); serialized += descr.serialize(); // Add header @@ -53,7 +55,7 @@ binary AddAgentCapsPDU::serialize() } -AddAgentCapsPDU::AddAgentCapsPDU(OidVariable id, OctetStringVariable descr) +AddAgentCapsPDU::AddAgentCapsPDU(Oid id, OctetStringVariable descr) { this->id = id; this->descr = descr; diff --git a/src/AddAgentCapsPDU.hpp b/src/AddAgentCapsPDU.hpp index e78f9cd..0c651a7 100644 --- a/src/AddAgentCapsPDU.hpp +++ b/src/AddAgentCapsPDU.hpp @@ -20,7 +20,7 @@ #define _ADDAGENTCAPSPDU_H_ #include "PDUwithContext.hpp" -#include "OidVariable.hpp" +#include "Oid.hpp" #include "OctetStringVariable.hpp" namespace agentxcpp @@ -40,7 +40,7 @@ namespace agentxcpp * See RFC 2741, 6.2.14. "The agentx-AddAgentCaps-PDU" for * details. */ - OidVariable id; + Oid id; /** * \brief An Octet String containing a DisplayString to be used as @@ -97,14 +97,14 @@ namespace agentxcpp * * \param descr The value of the descr field. */ - AddAgentCapsPDU(OidVariable id, OctetStringVariable descr); + AddAgentCapsPDU(Oid id, OctetStringVariable descr); /** * \brief Set the id field * * \param id The new id value. */ - void set_id(OidVariable id) + void set_id(Oid id) { this->id = id; } @@ -114,7 +114,7 @@ namespace agentxcpp * * \return The id value. */ - OidVariable get_id() + Oid get_id() { return this->id; } diff --git a/src/GetBulkPDU.cpp b/src/GetBulkPDU.cpp index 462a263..1345d0b 100644 --- a/src/GetBulkPDU.cpp +++ b/src/GetBulkPDU.cpp @@ -19,6 +19,7 @@ #include "GetBulkPDU.hpp" #include "util.hpp" +#include "OidVariable.hpp" using namespace agentxcpp; @@ -37,12 +38,12 @@ GetBulkPDU::GetBulkPDU(binary::const_iterator& pos, // Get SearchRanges until the PDU is completely parsed while( pos < end ) { - pair p; + pair p; - p.first = OidVariable(pos, end, big_endian); - p.second = OidVariable(pos, end, big_endian); + p.first = OidVariable(pos, end, big_endian).value(); + p.second = OidVariable(pos, end, big_endian).value(); - if(p.second.get_include() == true) + if(p.second.include() == true) { // Parse error according to RFC 2741, 5.2 "SearchRange": // include field of ending OID must be 0 @@ -67,11 +68,11 @@ binary GetBulkPDU::serialize() const write16(serialized, this->max_repititions); // Add OID's - vector< pair >::const_iterator i; + vector< pair >::const_iterator i; for(i = sr.begin(); i < sr.end(); i++) { - serialized += i->first.serialize(); - serialized += i->second.serialize(); + serialized += OidVariable(i->first).serialize(); + serialized += OidVariable(i->second).serialize(); } // Add header diff --git a/src/GetBulkPDU.hpp b/src/GetBulkPDU.hpp index 493dfda..624a916 100644 --- a/src/GetBulkPDU.hpp +++ b/src/GetBulkPDU.hpp @@ -25,7 +25,7 @@ #include #include "PDUwithContext.hpp" -#include "OidVariable.hpp" +#include "Oid.hpp" using std::vector; using std::pair; @@ -44,10 +44,10 @@ namespace agentxcpp * \brief The SearchRange list * * A GetBulk %PDU can have multiple SearchRanges. A SearchRange - * consists of two OidVariable's. We store them in a pair<>, and store the + * consists of two Oid's. We store them in a pair<>, and store the * pais<>'s in a vector< pair<> >. */ - vector< pair > sr; + vector< pair > sr; /** * \brief The number of variables in the SearchRangeList that are @@ -107,7 +107,7 @@ namespace agentxcpp * \note There is no set_sr() function, because the SearchRange * list can be modified in place. */ - vector< pair >& get_sr() + vector< pair >& get_sr() { return this->sr; } diff --git a/src/GetNextPDU.cpp b/src/GetNextPDU.cpp index 1dfae11..9f89c49 100644 --- a/src/GetNextPDU.cpp +++ b/src/GetNextPDU.cpp @@ -18,6 +18,7 @@ */ #include "GetNextPDU.hpp" +#include "OidVariable.hpp" using namespace agentxcpp; @@ -30,12 +31,12 @@ GetNextPDU::GetNextPDU(binary::const_iterator& pos, // Get SearchRanges until the PDU is completely parsed while( pos < end ) { - pair p; + pair p; - p.first = OidVariable(pos, end, big_endian); // starting oid - p.second = OidVariable(pos, end, big_endian); // ending oid + p.first = OidVariable(pos, end, big_endian).value(); // starting oid + p.second = OidVariable(pos, end, big_endian).value(); // ending oid - if(p.second.get_include() == true) + if(p.second.include() == true) { // Parse error according to RFC 2741, 5.2 "SearchRange": // include field of ending OID must be 0 @@ -54,11 +55,11 @@ binary GetNextPDU::serialize() const binary serialized; // Add OID's - vector< pair >::const_iterator i; + vector< pair >::const_iterator i; for(i = sr.begin(); i < sr.end(); i++) { - serialized += i->first.serialize(); - serialized += i->second.serialize(); + serialized += OidVariable(i->first).serialize(); + serialized += OidVariable(i->second).serialize(); } // Add header diff --git a/src/GetNextPDU.hpp b/src/GetNextPDU.hpp index 18aba45..22068df 100644 --- a/src/GetNextPDU.hpp +++ b/src/GetNextPDU.hpp @@ -23,7 +23,7 @@ #include #include "PDUwithContext.hpp" -#include "OidVariable.hpp" +#include "Oid.hpp" using std::vector; using std::pair; @@ -45,7 +45,7 @@ namespace agentxcpp * consists of two OidVariable's. We store them in a pair<>, and store the * pais<>'s in a vector< pair<> >. */ - vector< pair > sr; + vector< pair > sr; public: /** @@ -89,7 +89,7 @@ namespace agentxcpp * \note There is no set_sr() function, because the SearchRange * list can be modified in place. */ - vector< pair >& get_sr() + vector< pair >& get_sr() { return this->sr; } diff --git a/src/GetPDU.cpp b/src/GetPDU.cpp index 853d611..dd923ed 100644 --- a/src/GetPDU.cpp +++ b/src/GetPDU.cpp @@ -18,6 +18,7 @@ */ #include "GetPDU.hpp" +#include "OidVariable.hpp" using namespace agentxcpp; @@ -31,19 +32,16 @@ GetPDU::GetPDU(binary::const_iterator& pos, while( pos < end ) { // read starting OidVariable - sr.push_back(OidVariable(pos, end, big_endian)); + sr.push_back(OidVariable(pos, end, big_endian).value()); // read and forget ending OidVariable (but check its include field) - OidVariable ending(pos, end, big_endian); - if(ending.get_include() == true) + if(OidVariable(pos, end, big_endian).value().include() == true) { // Parse error according to RFC 2741, 5.2 "SearchRange": // include field of ending OID must be 0 throw( parse_error() ); } - - pos += 4; // ignore empty "end" OidVariable } } @@ -56,10 +54,10 @@ binary GetPDU::serialize() const binary serialized; // Add OID's - vector::const_iterator i; + vector::const_iterator i; for(i = sr.begin(); i < sr.end(); i++) { - serialized += i->serialize(); + serialized += OidVariable(*i).serialize(); } // Add header diff --git a/src/GetPDU.hpp b/src/GetPDU.hpp index ec124d5..ed395aa 100644 --- a/src/GetPDU.hpp +++ b/src/GetPDU.hpp @@ -22,7 +22,7 @@ #include #include "PDUwithContext.hpp" -#include "OidVariable.hpp" +#include "Oid.hpp" using std::vector; @@ -43,7 +43,7 @@ namespace agentxcpp * OID is always the null OID. We simply store the OID's for the * getPDU into a vector<>. */ - vector sr; + vector sr; public: /** @@ -87,7 +87,7 @@ namespace agentxcpp * \note There is no set_sr() function, because the SearchRange * list can be modified in place. */ - vector& get_sr() + vector& get_sr() { return this->sr; } diff --git a/src/IntegerVariable.hpp b/src/IntegerVariable.hpp index 8313772..ad2649b 100644 --- a/src/IntegerVariable.hpp +++ b/src/IntegerVariable.hpp @@ -24,7 +24,7 @@ #include "AbstractVariable.hpp" #include "exceptions.hpp" -#include "OidVariable.hpp" +#include "Oid.hpp" namespace agentxcpp { @@ -117,9 +117,9 @@ namespace agentxcpp * value 0 should be avoided according to * RFC 2578, 7.7. "Mapping of the INDEX clause". */ - OidVariable toOid() const + Oid toOid() const { - OidVariable oid; + Oid oid; oid.push_back(v); return oid; } diff --git a/src/IpAddressVariable.hpp b/src/IpAddressVariable.hpp index d1177ab..37b2e73 100644 --- a/src/IpAddressVariable.hpp +++ b/src/IpAddressVariable.hpp @@ -24,7 +24,7 @@ #include "AbstractVariable.hpp" #include "exceptions.hpp" -#include "OidVariable.hpp" +#include "Oid.hpp" namespace agentxcpp { @@ -164,9 +164,9 @@ namespace agentxcpp * has exactly 4 subids which corresponds to the 4 * integers of the IP address. */ - OidVariable toOid() const + Oid toOid() const { - OidVariable oid; + Oid oid; oid.push_back(address[0]); oid.push_back(address[1]); oid.push_back(address[2]); diff --git a/src/MasterProxy.cpp b/src/MasterProxy.cpp index 512cf24..6eaa823 100644 --- a/src/MasterProxy.cpp +++ b/src/MasterProxy.cpp @@ -27,6 +27,7 @@ #include "GetNextPDU.hpp" #include "NotifyPDU.hpp" #include "util.hpp" +#include "OidVariable.hpp" using namespace std; @@ -41,7 +42,7 @@ using namespace agentxcpp; MasterProxy::MasterProxy(std::string _description, quint8 _default_timeout, - OidVariable _id, + Oid _id, std::string _filename) : socket_file(_filename.c_str()), sessionID(0), @@ -273,7 +274,7 @@ void MasterProxy::do_registration(QSharedPointer pdu) -void MasterProxy::register_subtree(OidVariable subtree, +void MasterProxy::register_subtree(Oid subtree, quint8 priority, quint8 timeout) { @@ -308,7 +309,7 @@ void MasterProxy::register_subtree(OidVariable subtree, -void MasterProxy::unregister_subtree(OidVariable subtree, +void MasterProxy::unregister_subtree(Oid subtree, quint8 priority) { // The UnregisterPDU @@ -442,23 +443,23 @@ void MasterProxy::handle_getpdu(QSharedPointer response, QSharedPoi // RFC 2741, 7.2.3.1 "Subagent Processing of the agentx-Get-PDU" // Extract searchRange list - vector sr = get_pdu->get_sr(); + vector sr = get_pdu->get_sr(); - // Iterate over list and handle each OidVariable separately - vector::const_iterator i; + // Iterate over list and handle each Oid separately + vector::const_iterator i; quint16 index = 1; // Index is 1-based (RFC 2741, // 5.4. "Value Representation"): for(i = sr.begin(); i != sr.end(); i++) { // The name - const OidVariable& name = *i; + const Oid& name = *i; // Find variable for current OID - map< OidVariable, QSharedPointer >::const_iterator var; + map< Oid, QSharedPointer >::const_iterator var; var = variables.find(name); if(var != variables.end()) { - // Step (2): We have a variable for this OidVariable + // Step (2): We have a variable for this Oid // update variable try @@ -481,7 +482,7 @@ void MasterProxy::handle_getpdu(QSharedPointer response, QSharedPoi // Interpret 'name' as prefix: // append .0 and check whether we have a variable // with this name - OidVariable name_copy(name, 0); + Oid name_copy(name, 0); var = variables.find(name_copy); if(var != variables.end()) @@ -512,21 +513,21 @@ void MasterProxy::handle_getnextpdu(QSharedPointer response, QShare // RFC 2741, 7.2.3.2 "Subagent Processing of the agentx-GetNext-PDU" // Extract searchRange list - vector< pair >& sr = getnext_pdu->get_sr(); + vector< pair >& sr = getnext_pdu->get_sr(); // Iterate over list and handle each SearchRange separately - vector< pair >::const_iterator i; + vector< pair >::const_iterator i; quint16 index = 1; // Index is 1-based (RFC 2741, // 5.4. "Value Representation"): for(i = sr.begin(); i != sr.end(); i++) { // The names - const OidVariable& starting_oid = i->first; - const OidVariable& ending_oid = i->second; + const Oid& starting_oid = i->first; + const Oid& ending_oid = i->second; // Find "next" variable - map< OidVariable, QSharedPointer >::const_iterator next_var; - if( ! starting_oid.get_include()) + map< Oid, QSharedPointer >::const_iterator next_var; + if( ! starting_oid.include()) { // Find the closest lexicographical successor to the starting // OID (excluding the starting OID itself) @@ -600,7 +601,7 @@ void MasterProxy::handle_testsetpdu(QSharedPointer response, QShare for(i = vb.begin(), index = 1; i != vb.end(); i++, index++) { // Find the associated variable - map< OidVariable, QSharedPointer >::const_iterator var; + map< Oid, QSharedPointer >::const_iterator var; var = variables.find(i->get_name()); if(var == variables.end()) { @@ -855,20 +856,20 @@ void MasterProxy::handle_pdu(QSharedPointer pdu) } void MasterProxy::addVariables(QVector< QPair< - OidVariable, QSharedPointer > > v) + Oid, QSharedPointer > > v) { - QVectorIterator > > iter(v); while(iter.hasNext()) { - QPair > varPair; + QPair > varPair; varPair = iter.next(); add_variable(varPair.first, varPair.second); } } -void MasterProxy::add_variable(const OidVariable& id, QSharedPointer v) +void MasterProxy::add_variable(const Oid& id, QSharedPointer v) { // Check whether id is contained in a registration bool is_registered = false; @@ -898,7 +899,7 @@ void MasterProxy::add_variable(const OidVariable& id, QSharedPointer& ids) +void MasterProxy::removeVariables(const QVector& ids) { - QVectorIterator iter(ids); + QVectorIterator iter(ids); while(iter.hasNext()) { remove_variable(iter.next()); } } -void MasterProxy::send_notification(const OidVariable& snmpTrapOID, +void MasterProxy::send_notification(const Oid& snmpTrapOID, const TimeTicksVariable* sysUpTime, const vector& varbinds) { @@ -951,12 +952,12 @@ void MasterProxy::send_notification(const OidVariable& snmpTrapOID, if(sysUpTime) { QSharedPointer value(new TimeTicksVariable(*sysUpTime)); - vb.push_back(varbind(OidVariable(sysUpTime_oid, "0"), value)); + vb.push_back(varbind(Oid(sysUpTime_oid, "0"), value)); } // Second: add mandatory snmpTrapOID QSharedPointer trapoid(new OidVariable(snmpTrapOID)); - vb.push_back(varbind(OidVariable(snmpTrapOID_oid, "0"), trapoid)); + vb.push_back(varbind(Oid(snmpTrapOID_oid, "0"), trapoid)); // Append given varbinds vb.insert(vb.end(), varbinds.begin(), varbinds.end()); diff --git a/src/MasterProxy.hpp b/src/MasterProxy.hpp index 766b88b..b4233a7 100644 --- a/src/MasterProxy.hpp +++ b/src/MasterProxy.hpp @@ -31,7 +31,7 @@ #include #include -#include "OidVariable.hpp" +#include "Oid.hpp" #include "AbstractVariable.hpp" #include "TimeTicksVariable.hpp" #include "ClosePDU.hpp" @@ -161,7 +161,7 @@ namespace agentxcpp * \internal * * The variables are stored in the member variables, which is a - * std::map >. The key is the OID for which the + * std::map >. The key is the OID for which the * variable was added. This allows easy lookup for the request * dispatcher. * @@ -242,7 +242,7 @@ namespace agentxcpp * \brief An Object Identifier that identifies the subagent. May be * the null OID. */ - OidVariable id; + Oid id; /** * \brief The registrations. @@ -256,7 +256,7 @@ namespace agentxcpp /** * \brief Storage for all SNMP variables known to the MasterProxy. */ - std::map< OidVariable, QSharedPointer > variables; + std::map< Oid, QSharedPointer > variables; /** * \brief The variables affected by the Set operation currently @@ -503,7 +503,7 @@ namespace agentxcpp * * \todo Document exceptions. */ - void send_notification(const OidVariable& snmpTrapOID, + void send_notification(const Oid& snmpTrapOID, const TimeTicksVariable* sysUpTime, const std::vector& varbinds=vector()); @@ -511,15 +511,15 @@ namespace agentxcpp * \brief Writing aid: Send notification without sysUpTime.0. * * This calls \ref send_notification( - * const OidVariable&, const TimeTicksVariable*, + * const Oid&, const TimeTicksVariable*, * const vector&) with a NULL pointer * for the sysUpTime.0 parameter. * * For the documentation of the parameters and exceptions go to - * \ref send_notification(const OidVariable&, TimeTicksVariable>&, + * \ref send_notification(const Oid&, TimeTicksVariable>&, * const vector&) */ - void send_notification(const OidVariable& snmpTrapOID, + void send_notification(const Oid& snmpTrapOID, const std::vector& varbinds=vector()) { send_notification(snmpTrapOID, 0, varbinds); @@ -557,7 +557,7 @@ namespace agentxcpp */ MasterProxy(std::string description="", quint8 default_timeout=0, - OidVariable ID=OidVariable(), + Oid ID=Oid(), std::string unix_domain_socket="/var/agentx/master"); /** @@ -614,7 +614,7 @@ namespace agentxcpp * that a retry will result in a * duplicate_registration error. */ - void register_subtree(OidVariable subtree, + void register_subtree(Oid subtree, quint8 priority=127, quint8 timeout=0); @@ -659,7 +659,7 @@ namespace agentxcpp */ // TODO: the 'priority' parameter can possibly be omitted: the // value can be stored by master_agent upon subtree registration. - void unregister_subtree(OidVariable subtree, + void unregister_subtree(Oid subtree, quint8 priority=127); /** @@ -760,18 +760,18 @@ namespace agentxcpp * within a registered MIB * region. */ - void add_variable(const OidVariable& id, QSharedPointer v); + void add_variable(const Oid& id, QSharedPointer v); /** * \brief Add several SNMP variables for serving. * * This function takes multiple variables and calls - * agentxcpp::add_variable(const OidVariable&, + * agentxcpp::add_variable(const Oid&, * QSharedPointer) for each of them. * * \param vars The variables to be added. Each QPair object contains * an OID and the pointer to the variable; see - * agentxcpp::add_variable(const OidVariable&, + * agentxcpp::add_variable(const Oid&, * QSharedPointer) for an explanation. * * \exception unknown_registration If trying to add a variable @@ -781,7 +781,7 @@ namespace agentxcpp * */ void addVariables(QVector< QPair< - OidVariable, QSharedPointer > + Oid, QSharedPointer > > vars); /** @@ -797,21 +797,21 @@ namespace agentxcpp * * \exception None. */ - void remove_variable(const OidVariable& id); + void remove_variable(const Oid& id); /** * \brief Remove several SNMP variables so that they are not longer * accessible. * * This function takes multiple variables and calls - * agentxcpp::remove_variable(const OidVariable&) + * agentxcpp::remove_variable(const Oid&) * for each of them. * * \param ids The variables to be removed. * * \exception None. */ - void removeVariables(const QVector& ids); + void removeVariables(const QVector& ids); /** * \brief Check whether an OID is within the registered ranges. @@ -825,7 +825,7 @@ namespace agentxcpp * * \exception None. */ - bool isRegistered(OidVariable id); + bool isRegistered(Oid id); }; } diff --git a/src/OctetStringVariable.cpp b/src/OctetStringVariable.cpp index 59ded1e..405141a 100644 --- a/src/OctetStringVariable.cpp +++ b/src/OctetStringVariable.cpp @@ -140,9 +140,9 @@ OctetStringVariable::OctetStringVariable(binary::const_iterator& pos, } -OidVariable OctetStringVariable::toOid(bool fixedLength) const +Oid OctetStringVariable::toOid(bool fixedLength) const { - OidVariable oid; + Oid oid; // Store string length if needed if(!fixedLength) diff --git a/src/OctetStringVariable.hpp b/src/OctetStringVariable.hpp index 905557a..35be5c3 100644 --- a/src/OctetStringVariable.hpp +++ b/src/OctetStringVariable.hpp @@ -3,7 +3,7 @@ #include #include "AbstractVariable.hpp" -#include "OidVariable.hpp" +#include "Oid.hpp" namespace agentxcpp { @@ -114,7 +114,7 @@ namespace agentxcpp * * \param fixedLength Whether the string is fixed-length. */ - OidVariable toOid(bool fixedLength = false) const; + Oid toOid(bool fixedLength = false) const; /** * \internal diff --git a/src/Oid.cpp b/src/Oid.cpp index 6cbf35a..d313d86 100644 --- a/src/Oid.cpp +++ b/src/Oid.cpp @@ -234,16 +234,16 @@ bool Oid::contains(const Oid& id) const } -//bool Oid::is_null() const -//{ -// if( this->size() == 0 && -// ! this->include) -// { -// // Is the null OID -// return true; -// } -// else -// { -// return false; -// } -//} +bool Oid::is_null() const +{ + if( this->size() == 0 && + ! this->mInclude) + { + // Is the null OID + return true; + } + else + { + return false; + } +} diff --git a/src/Oid.hpp b/src/Oid.hpp index f69b13a..efee49d 100644 --- a/src/Oid.hpp +++ b/src/Oid.hpp @@ -92,6 +92,11 @@ namespace agentxcpp { private: + /** + * \brief the 'include' field. + */ + bool mInclude; + /** * \brief Parse an OID from a string and append it. * @@ -117,7 +122,7 @@ namespace agentxcpp * * \exception inval_param If the string is malformed. */ - Oid(std::string id); + Oid(std::string id = ""); /** * \brief Initialize an Oid object with another Oid plus @@ -379,7 +384,39 @@ namespace agentxcpp * * \return True if the object is the null OID, false otherwise. */ -// bool is_null() const; + bool is_null() const; + + /** + * \internal + * + * \brief Get the current include value. + * + * The include value is present in the serialized form of an OID. + * If an OID object is created by parsing a AgentX message, the + * 'include' member is set accordingly. + * + * See RFC 2741, sections 5.1 and 5.2 for details. + */ + bool include() const + { + return mInclude; + } + + /** + * \internal + * + * \brief set the include value + * + * The include value is present in the serialized form of an OID. + * If an OID object is serialized, the include field is encoded + * into the stream. + * + * See RFC 2741, sections 5.1 and 5.2 for details. + */ + void setInclude(bool i) + { + mInclude = i; + } friend std::ostream& operator<<(std::ostream& out, const Oid& o); diff --git a/src/OidVariable.cpp b/src/OidVariable.cpp index 79ad835..a4e5451 100644 --- a/src/OidVariable.cpp +++ b/src/OidVariable.cpp @@ -26,104 +26,12 @@ using namespace agentxcpp; using namespace std; -void OidVariable::parseString(std::string s) +OidVariable::OidVariable(const Oid& o) { - // Do not parse empty string - if(s.empty()) return; - - // Parse the string - std::istringstream ss(s); - quint32 subid; - char ch; - while(ss) - { - // Read a subid - ss >> subid; - if(!ss) - { - // cannot get number: parse error - // This happens also if the number is too large - throw( inval_param() ); - } - push_back(subid); - - // Read a period - ss >> ch; - if(!ss) - { - // end of string: end of parsing - break; - } - if(ch != '.') - { - // Wrong char: parse error - throw( inval_param() ); - } - } -} - - - -OidVariable::OidVariable(std::string s) -{ - include = false; - - // parse the string. Forward all exceptions. - parseString(s); -} - - -OidVariable::OidVariable(const OidVariable& o, std::string id) -{ - // start with o - *this = o; - - // add OID from string. Forward all exceptions. - parseString(id); -} - - -OidVariable::OidVariable(const OidVariable& o, quint32 id) -{ - // start with o - *this = o; - - // add suboid - append(id); + mValue = o; } -std::ostream& agentxcpp::operator<<(std::ostream& out, const OidVariable& o) -{ - // Leading dot - out << "."; - - // If no subidentifiers are present, we are done - if(o.size() == 0) - { - return out; - } - - // Get iterator to first subidentifier - OidVariable::const_iterator it = o.begin(); - - // Print first subidentifier - out << *it; - it++; - - // Output remaining subidentifiers, each prepended with a dot - while(it != o.end()) - { - out << "." << *it; - it++; - } - - // Done, return - return out; -} - - - binary OidVariable::serialize() const { // The serial representation of an OID is as follows (RFC 2741, section @@ -153,25 +61,25 @@ binary OidVariable::serialize() const serialized[reserved_idx] = 0; // Set include field - serialized[include_idx] = include ? 1 : 0; + serialized[include_idx] = mValue.include() ? 1 : 0; // Iterator for the subid's - OidVariable::const_iterator subid = this->begin(); + Oid::const_iterator subid = mValue.begin(); // Check whether we can use the prefix (RFC 2741, section 5.1) - if( this->size() >= 5 && - (*this)[0] == 1 && - (*this)[1] == 3 && - (*this)[2] == 6 && - (*this)[3] == 1 && - (*this)[4] <= 0xff) // we have only one byte for the prefix! + if( mValue.size() >= 5 && + mValue[0] == 1 && + mValue[1] == 3 && + mValue[2] == 6 && + mValue[3] == 1 && + mValue[4] <= 0xff) // we have only one byte for the prefix! { // store the first integer after 1.3.6.1 to prefix field - serialized[prefix_idx] = (*this)[4]; + serialized[prefix_idx] = mValue[4]; subid += 5; // point to the subid behind prefix // 5 elements are represented by prefix - serialized[n_subid_idx] = this->size() - 5; + serialized[n_subid_idx] = mValue.size() - 5; } else { @@ -179,11 +87,11 @@ binary OidVariable::serialize() const serialized[prefix_idx] = 0; // All subid's are stored in the stream explicitly - serialized[n_subid_idx] = this->size(); + serialized[n_subid_idx] = mValue.size(); } // copy subids to serialized - while( subid != this->end() ) + while( subid != mValue.end() ) { serialized.push_back( (*subid) >> 24 & 0xff ); serialized.push_back( (*subid) >> 16 & 0xff ); @@ -211,21 +119,21 @@ OidVariable::OidVariable(binary::const_iterator& pos, int prefix = *pos++; if( prefix != 0 ) { - this->push_back(1); - this->push_back(3); - this->push_back(6); - this->push_back(1); - this->push_back(prefix); + mValue.push_back(1); + mValue.push_back(3); + mValue.push_back(6); + mValue.push_back(1); + mValue.push_back(prefix); } // parse include field switch( *pos++ ) { case 0: - include = false; + mValue.setInclude(false); break; case 1: - include = true; + mValue.setInclude(true); break; default: // Invalid value; we are picky and indicate an error: @@ -259,138 +167,8 @@ OidVariable::OidVariable(binary::const_iterator& pos, subid |= *pos++ << 16; subid |= *pos++ << 24; } - this->push_back(subid); - } -} - - -bool OidVariable::operator<(const OidVariable& o) const -{ - OidVariable::const_iterator mine, yours; - mine = this->begin(); - yours = o.begin(); - - // Test as many parts as the shorter OID has: - while( mine != this->end() - && yours != o.end() ) - { - if( *mine < *yours ) - { - // my OidValue part is less than yours - return true; - } - if( *mine > *yours ) - { - // my OidValue part is greater than yours - return false; - } - - // our parts are identical; test next part: - mine++; - yours++; - } - - // Ok, either you and I have different length (where the one with fewer - // parts is less than the other) or we have the same number of parts (in - // which case we are identical). - if( this->size() < o.size() ) - { - // I have less parts than you, so I am less than you: - return true; - } - else - { - // I have not less parts than you: - return false; - } -} - - - -bool OidVariable::operator==(const OidVariable& o) const -{ - // Quick test: if the OidValues have different number of parts, they are not - // equal: - if( this->size() != o.size() ) - { - return false; - } - - // Test all parts: - OidVariable::const_iterator mine, yours; - mine = this->begin(); - yours = o.begin(); - - while( mine != this->end() - && yours != o.end() ) - { - if( *mine != *yours ) - { - // The parts differ: OIDs not equal - return false; - } - - // Parts are equal, test next parts - mine++; - yours++; - } - - // All parts tested and all parts were equal. Further both OIDs have the - // same number of parts, thus they are equal. - return true; -} - - -OidVariable& OidVariable::operator=(const OidVariable& other) -{ - // copy our own members - this->include = other.include; - - // copy inherited stuff - QVector::operator=(other); - AbstractVariable::operator=(other); - - // Return reference to us - return *this; -} - - -bool OidVariable::contains(const OidVariable& id) const -{ - // If id has fewer subids than this: not contained - if(this->size() > id.size()) - { - // Is not contained - return false; - } - - // id has at least as many subids than this -> iteration is safe - for(size_type i = 0; i < this->size(); i++) - { - if( (*this)[i] != id[i] ) - { - // We differ in a subid! - return false; - } + mValue.push_back(subid); } - - // If we get here, the id starts the same subids as this (it has possibly - // more subids). This means that it is contained in the subtree spanned by - // this. - return true; } -bool OidVariable::is_null() const -{ - if( this->size() == 0 && - ! this->include) - { - // Is the null OID - return true; - } - else - { - return false; - } -} diff --git a/src/OidVariable.hpp b/src/OidVariable.hpp index 8f69f13..4376559 100644 --- a/src/OidVariable.hpp +++ b/src/OidVariable.hpp @@ -1,5 +1,5 @@ /* - * Copyright 2011-2012 Tanjeff-Nicolai Moos + * Copyright 2011-2014 Tanjeff-Nicolai Moos * * This file is part of the agentXcpp library. * @@ -20,95 +20,26 @@ #ifndef _OIDVARIABLE_H_ #define _OIDVARIABLE_H_ -#include -#include - #include -#include #include "AbstractVariable.hpp" +#include "Oid.hpp" #include "exceptions.hpp" namespace agentxcpp { /** - * \brief Represents an SNMP object identifier (OID). - * - * This class represents an OID. OID's are sequences of sub-identifiers, - * which are integers. - * - * This class provides constructors taking a string which contains an OID. - * For example, this works: - * - * \code - * OidValue myCompany = OidValue("1.3.6.1.4.1.355"); - * \endcode - * - * Also a constructor is provided which takes an OidValue and a string and - * concatenates them, so this works also: - * - * \code - * OidValue myObject = OidValue(myCompany, "1.1.3.0"); - * \endcode - * - * In addition, some common OidValue's are provided as constants, e.g. - * 'enterprises_oid', so the following will also work (note that the second - * argument is a string, not an integer!): - * - * \code - * OidValue yourCompany = OidValue(enterprises_oid, "42"); // second param is a string! - * \endcode - * - * The string given to the constructors must have a valid syntax. If a - * malformed string is provided, inval_param is thrown and the object is - * not constructed. For example, the following strings are malformed: - * - * \code - * "1,3,6" // wrong separator (must be a period) - * "1.3.6." // trailing character at the end - * "1.3.6.1.4.1.123456789123" // last subid is too big (must fit in a 32 bit unsigned integer) - * \endcode - * - * However, the following strings are accepted: - * - * \code - * "1.3.6" - * "1" // a single subid is ok - * "1.3.6.1.4.1.42.1.0" // 0 as subid is ok - * "" // empty string is ok - * \endcode - * - * This class inherits from std:vector, which means that an OidValue - * object can be manipulated the same way as a std::vector<> can be - * manipulated: - * - * \code - * OidValue theirCompany = enterprises_oid; - * theirCompany.push_back(23); // Don't use a string here! - * \endcode - * + * \brief Represents an SNMP OBJECT-IDENTENTIFIER variable. */ - class OidVariable: public AbstractVariable, public QVector + class OidVariable: public AbstractVariable { private: - /** - * \brief the 'include' field. - */ - bool include; - - /** - * \brief Parse an OID from a string and append it. - * - * The OID contained within the string 's' is parsed and appended to - * this object. The format of the string is described above. - * - * \param s The OID to be parsed. - * - * \exception inval_param If the string is malformed. - */ - void parseString(std::string s); + /** + * \brief The value represented by this variable. + */ + Oid mValue; /** * \brief The new value for the variable in a Set operation. @@ -123,119 +54,38 @@ namespace agentxcpp public: /** - * \brief Default Constructor + * \brief Initialize an OidVariable object with an Oid. * - * This constructs an empty OidValue (the null OidValue). + * The internal value is set to the provided Oid. * - * \internal - * The 'include' field is initialized to 'false'. - * \endinternal + * \param o The initial Oid. * * \exception None. */ - OidVariable() - { - include = false; - } - + OidVariable(const Oid& o); /** - * \brief Initialize an OidValue object with an OID in string format. - * - * This constructor takes a string and initializes the OidValue object - * with the OID contained within this string. The format of the - * string is described above. - * - * \internal - * The 'include' field is initialized to 'false'. - * \endinternal - * - * \param id The initial object identifier. - * - * \exception inval_param If the string is malformed. - */ - OidVariable(std::string id); - - /** - * \brief Initialize an OidValue object with another OidValue plus - * a subid. - * - * All subid's are copied from 'o'. Then, the OID contained within - * the string 'id' is appended. The format of the string is - * described in the documentation of this class. - * - * \internal - * The 'include' field is copied from 'o'. - * \endinternal - * - * \param o The starting OID. - * - * \param id The OID to append. - * - * \exception inval_param If the string is malformed. - */ - OidVariable(const OidVariable& o, std::string id); - - /** - * \brief Initialize an OidValue object with another OidValue plus - * a subid. - * - * All subid's are copied from 'o'. Then, the subid 'id' is - * appended. - * - * \internal - * The 'include' field is copied from 'o'. - * \endinternal - * - * \param o The starting OID. - * - * \param id The subid to append. - * - * \exception None. - */ - OidVariable(const OidVariable& o, quint32 id); - - /** - * \brief Assignment operator - * - * Copies all data from 'o' into this OID. - * - * \param o The OID to copy from. - * - * \return A reference to this OID. - */ - OidVariable& operator=(const OidVariable& o); - - /** - * \internal - * - * \brief Get the current include value. + * \brief Get the value. * - * The include value is present in the serialized form of an OID. - * If an OID object is created by parsing a AgentX message, the - * 'include' member is set accordingly. + * \return The internal value. * - * See RFC 2741, sections 5.1 and 5.2 for details. + * \exception None. */ - bool get_include() const + Oid value() { - return include; + return mValue; } /** - * \internal + * \brief Set the value. * - * \brief set the include value + * \param o The new value. * - * The include value is present in the serialized form of an OID. - * If an OID object is serialized, the include field is encoded - * into the stream. - * - * See RFC 2741, sections 5.1 and 5.2 for details. + * \exception None. */ - void set_include(bool i) + void setValue(const Oid& o) { - include = i; + mValue = o; } /** @@ -243,6 +93,8 @@ namespace agentxcpp * * \brief Encode an OID object as described in RFC 2741, * section 5.1. + * + * \todo Maybe this function should move to the Oid class? */ binary serialize() const; @@ -273,234 +125,14 @@ namespace agentxcpp * \exception parse_error If parsing fails. In this case, the * iterator is left at an undefined * position. + * + * \todo Maybe this function should move to the Oid class? + * */ OidVariable(binary::const_iterator& pos, const binary::const_iterator& end, bool big_endian=true); - /** - * \brief The less-than operator - * - * An OID is less than another OID if either the first - * not-identical part is lesser or if all parts are identical and - * it has lesser parts. - * - * Example:\n - * 1.3.6.1.4.1.42.3.3.1 \n - * is less than \n - * 1.3.6.1.4.1.42.3.4.1 \n - * Note the next to last number. - * - * Also,\n - * 1.3.6.1.4.1.42.3.3.1 \n - * is less than \n - * 1.3.6.1.4.1.42.3.3.1.1 \n - * because it is shorter. - * - * However, \n - * 1.3.6.1.4.1.42.3.3.1 \n - * is greater than \n - * 1.3.6.1.4.1.42.3.2.1.1 \n - * because the 9th number is greater (although the first OID has - * less numbers than the second). - * - * \param o The OID to compare to. - * - * \return True if the OID is less than 'o', false otherwise. - */ - bool operator<(const OidVariable& o) const; - - /** - * \brief The less-than-or-equal operator - * - * See operator<() for a more detailed description about comparing - * OIDs. - * - * \param o The OID to compare to. - * - * \return True if the OID is less than or equal 'o', - * false otherwise. - */ - bool operator<=(const OidVariable& o) const - { - if(*this == o || *this < o) - { - return true; - } - else - { - return false; - } - } - - /** - * \brief The equal-operator - * - * See operator<() for a more detailed description about comparing - * OIDs. - * - * \param o The OID tocompare to. - * - * \return True if the OIDs are equal, false otherwise. - */ - bool operator==(const OidVariable& o) const; - - /** - * \brief The not-equal-operator for OidValues - * - * See operator<() for a more detailed description about comparing - * OIDs. - * - * \param o The OID tocompare to. - * - * \return False if the OIDs are equal, true otherwise. - */ - bool operator!=(const OidVariable& o) const - { - return ! (*this == o); - } - - /** - * \brief The greater-than operator - * - * See operator<() for a more detailed description about comparing - * OIDs. - * - * \param o The OID tocompare to. - * - * \return True if the OID is greater than 'o', false otherwise. - */ - bool operator>(const OidVariable& o) const - { - // a > b is the same as b < a :-) - return o < *this; - } - - /** - * \brief The greater-than-or-equal operator - * - * See operator<() for a more detailed description about comparing - * OIDs. - * - * \param o The OID to compare to. - * - * \return True if the OID is greater than or equal 'o', - * false otherwise. - */ - bool operator>=(const OidVariable& o) const - { - // a >= b is the same as b <= a :-) - return o <= *this; - } - - /** - * \brief Concatenation. - * - * This operator returns a temporary OidVariable object which is - * this OID plus 'subid' appended. Example: - * - * \code - * OidVariable a("1.2.3"); - * OidVariable b = a + 4; // b will be 1.2.3.4 - * \endcode - * - * \param subid The subid to append. - * - * \return The temporary object 'this.subid'. - */ - OidVariable operator+(quint32 subid) const - { - OidVariable result(*this); - result.append(subid); - return result; - } - - /** - * \brief Concatenation - * - * This operator returns a temporary OidVariable object which is - * this OID plus 'o' appended. Example: - * - * \code - * OidVariable a("1.2.3"); - * OidVariable b("4.5.6"); - * OidVariable c = a + b; // c will be 1.2.3.4.5.6 - * \endcode - * - * \param o The OID to append. - * - * \return The temporary object. - */ - OidVariable operator+(const OidVariable& o) const - { - OidVariable result(*this); - result += o; - return result; - } - - /** - * \brief Concatenation - * - * This operator appends 'o' to this OID. Example: - * - * \code - * OidVariable a("1.2.3"); - * OidVariable b("4.5.6"); - * a += b; - * // a is now 1.2.3.4.5.6 - * \endcode - * - * \param o The OID to append. - * - * \return A reference to this OID. - */ - OidVariable& operator+=(const OidVariable& o) - { - this->QVector::operator+=(o); - return *this; - } - - /** - * \brief Checks whether the given OidValue is in the subtree of this - * OidValue. - * - * This method checks whether the given OID is included in the - * subtree which has this OidValue as root. - * - * Examples:\n - * \code - * OidValue id("1.3.6.1.4.1.42.3"); - * id.contains( OidValue(1.3.6.1.4.1.42.3) ); // true - * id.contains( OidValue(1.3.6.1.4.1.42) ); // false - * id.contains( OidValue(1.3.6.1.4.1.43.3) ); // false - * id.contains( OidValue(1.3.6.1.4.1.42.3.3.1) ); // true - * \endcode - * - * \param id The OID to check. - * - * \return True if id is contained in the subtree, false - * otherwise. - */ - bool contains(const OidVariable& id) const; - - /** - * \internal - * - * \brief Whether it is the null Object Identifier - * - * According to RFC 2741, 5.1 "Object Identifier", a null object - * identifier has serial representation of 4 bytes which are - * all set to 0. An OID with no subid's and the index field set to - * 0 results in that representation and is thus considered to be - * the null OID. - * - * \return True if the object is the null OID, false otherwise. - */ - bool is_null() const; - - friend std::ostream& operator<<(std::ostream& out, - const OidVariable& o); - /** * \brief Convert the value to an OID. * @@ -512,19 +144,23 @@ namespace agentxcpp * Note that the length subid is omitted for fixed-length OIDs. * * \param fixedLength Whether the OID is fixed-length. + * + * \return The generated Oid. + * + * \exception None. */ - OidVariable toOid(bool fixedLength = false) const + Oid toOid(bool fixedLength = false) const { - OidVariable oid; + Oid oid; // Store length if needed if(!fixedLength) { - oid.push_back(this->size()); + oid.push_back(mValue.size()); } // Store value - oid += *this; + oid += mValue; return oid; } @@ -534,7 +170,7 @@ namespace agentxcpp * * \brief Handle a Get Request. * - * This function calls get() to obtain the new value, + * This function calls get() to update the internal value, * converts it to QSharedPointer and returns it. */ virtual QSharedPointer handle_get() @@ -547,14 +183,15 @@ namespace agentxcpp * \brief Handle a Get request. * * This method is called when an SNMP Get request is received. - * It shall - * return the current value of the variable. + * It shall update internal value of the variable. * * \note This method is pure virtual and thus \e must be * implemented. It is not possible to implement write-only * SNMP variables. * * \return The value of the variable. + * + * \exception None. */ virtual void get() { @@ -565,8 +202,8 @@ namespace agentxcpp * * \brief Handle a TestSet request. * - * This function converts the argument to QSharedPointer() and - * calls + * This function converts the argument to + * QSharedPointer() and calls * testset() with the converted value. If conversion fails, * testset() is not called. This function also stores the given * value to the new_value member. @@ -624,7 +261,7 @@ namespace agentxcpp * \brief Handle a CleanupSet request. * * This function calls cleanupset() with the value from the last - * handle_testset() invokation. + * handle_testset() invocation. */ virtual void handle_cleanupset() { @@ -636,13 +273,13 @@ namespace agentxcpp * * This method is called when an SNMP CleanupSet request is * received. It - * shall release any ressources allocated by testset(). + * shall release any resources allocated by testset(). * * The default implementation does nothing. If no action is - * required to perform the CleanupSet operaiton, this method need + * required to perform the CleanupSet operation, this method need * not be overridden. * - * \param v The new value for the object. + * \param _v The new value for the object. */ virtual void cleanupset(QSharedPointer _v) { @@ -673,7 +310,7 @@ namespace agentxcpp * operation failed. To implement a writable SNMP variable this * method must be overridden. * - * \param v The new value for the object. + * \param _v The new value for the object. * * \return True if the operation succeeded, false otherwise. */ @@ -715,7 +352,7 @@ namespace agentxcpp * * \endinternal * - * \param v The new value for the object. + * \param _v The new value for the object. * * \return True on success, false otherwise. */ @@ -725,174 +362,6 @@ namespace agentxcpp } }; - - /** - * \brief The output operator for the OidValue class. - * - * Object identifiers (OidValue objects) can be output as follows: - * - * \code - * OidValue led_state(enterprises_oid, "1.3.3.1"); - * cout << "LED state OID: " << led_state << endl; - * \endcode - * - * The last line will output "LED state OID: .1.3.6.1.4.1.3.3.1". - * - * \param out The stream to which to write the output. - * - * \param o The OID to output. - * - * \return The 'out' parameter. - */ - std::ostream& operator<<(std::ostream& out, const agentxcpp::OidVariable& o); - - - // TODO: Possibly these should be put into the agentxcpp::OidValue namespace? - // The use of \memberof is not elegant. - - /** - * \memberof OidValue - * - * \brief The 'iso' OID according to RFC 1155. - */ - const OidVariable iso_oid("1"); - - /** - * \memberof OidValue - * - * \brief The 'ccitt' OID according to RFC 1155. - */ - const OidVariable ccitt_oid("0"); - - /** - * \memberof OidValue - * - * \brief The 'joint.iso.ccitt' OID according to RFC 1155. - */ - const OidVariable joint_iso_ccitt_oid("2"); - - /** - * \memberof OidValue - * - * \brief The 'iso.org' OID according to RFC 1155. - */ - const OidVariable org_oid(iso_oid,"3"); - - /** - * \memberof OidValue - * - * \brief The 'iso.org.dod' OID according to RFC 1155. - */ - const OidVariable dod_oid(org_oid,"6"); - - /** - * \memberof OidValue - * - * \brief The 'iso.org.dod.internet' OID according to RFC 1155. - */ - const OidVariable internet_oid(dod_oid,"1"); - - /** - * \memberof OidValue - * - * \brief The 'iso.org.dod.internet.directory' OID according to RFC 1155. - */ - const OidVariable directory_oid(internet_oid,"1"); - - /** - * \memberof OidValue - * - * \brief The 'iso.org.dod.internet.mgmt' OID according to RFC 1155. - */ - const OidVariable mgmt_oid(internet_oid,"2"); - - /** - * \memberof OidValue - * - * \brief The 'iso.org.dod.internet.experimental' OID according to - * RFC 1155. - */ - const OidVariable experimental_oid(internet_oid,"3"); - - /** - * \memberof OidValue - * - * \brief The 'iso.org.dod.internet.private' OID according to RFC 1155. - */ - const OidVariable private_oid(internet_oid,"4"); - - /** - * \memberof OidValue - * - * \brief The 'iso.org.dod.internet.private.enterprises' OID according to - * RFC 1155. - */ - const OidVariable enterprises_oid(private_oid, "1"); - - /** - * \memberof OidValue - * - * \brief The 'snmpMIBObjects' OID according to RFC 1907. - * - * \internal - * - * This OID is used in the context of notifications. - * - * According to RFC 1907:
- * snmpTrapOID ::= snmpTrap.1
- * snmpTrap ::= snmpMIBObjects.4
- * snmpMIBObjects ::= snmpMIB.1
- * snmpMIB ::= snmpModules.1
- * - * According to RFC 2578 (SNMPv2-SMI):
- * snmpModules ::= snmpV2.3
- * snmpV2 ::= internet.6 - * - * Conclusion:
- * snmpMIBObjects ::= internet.6.3.1.1 - */ - const OidVariable snmpMIBObjects_oid(internet_oid, "6.3.1.1"); - - /** - * \memberof OidValue - * - * \brief The 'snmpTrapOID' OID according to RFC 1907. - * - * \internal - * - * This OID is used in the context of notifications. - * - * According to RFC 1907:
- * snmpTrapOID ::= snmpTrap.1
- * snmpTrap ::= snmpMIBObjects.4
- * - * Conclusion:
- * snmpTrapOID ::= snmpMIBObjects.4.1 - */ - const OidVariable snmpTrapOID_oid(snmpMIBObjects_oid, "4.1"); - - /** - * - * \memberof OidValue - * - * \brief The sysUpTime_oid OID according to RFC 1907. - * - * \internal - * - * This OID is used in the context of notifications. - * - * According to RFC 1907:
- * sysUpTime = system.3
- * system = mib-2.1 - * - * According to RFC 1902:
- * mib-2 = mgmt.1OidValue - * - * Conclusion: - * sysUpTime = mgmt.1.1.3 - */ - const OidVariable sysUpTime_oid(mgmt_oid, "1.1.3"); - } diff --git a/src/OpenPDU.cpp b/src/OpenPDU.cpp index 849158b..6db2102 100644 --- a/src/OpenPDU.cpp +++ b/src/OpenPDU.cpp @@ -18,7 +18,7 @@ */ #include "OpenPDU.hpp" - +#include "OidVariable.hpp" using namespace agentxcpp; @@ -37,7 +37,7 @@ OpenPDU::OpenPDU(binary::const_iterator& pos, timeout = *pos++; pos += 3; // skip reserved fields - id = OidVariable(pos, end, big_endian); + id = OidVariable(pos, end, big_endian).value(); descr = OctetStringVariable(pos, end, big_endian); } @@ -60,7 +60,7 @@ binary OpenPDU::serialize() const serialized.push_back(0); // id - serialized += id.serialize(); + serialized += OidVariable(id).serialize(); // descr serialized += descr.serialize(); diff --git a/src/OpenPDU.hpp b/src/OpenPDU.hpp index d130758..0c22eda 100644 --- a/src/OpenPDU.hpp +++ b/src/OpenPDU.hpp @@ -20,7 +20,7 @@ #define _OPENPDU_H_ #include "PDU.hpp" -#include "OidVariable.hpp" +#include "Oid.hpp" #include "OctetStringVariable.hpp" namespace agentxcpp @@ -34,7 +34,7 @@ namespace agentxcpp { private: quint8 timeout; - OidVariable id; + Oid id; OctetStringVariable descr; public: @@ -101,7 +101,7 @@ namespace agentxcpp /** * \brief Get ID */ - OidVariable get_id() + Oid get_id() { return this->id; } @@ -109,7 +109,7 @@ namespace agentxcpp /** * \brief Set ID */ - void set_id(OidVariable id) + void set_id(Oid id) { this->id = id; } diff --git a/src/RegisterPDU.cpp b/src/RegisterPDU.cpp index 093f1bc..30be391 100644 --- a/src/RegisterPDU.cpp +++ b/src/RegisterPDU.cpp @@ -18,6 +18,7 @@ */ #include "RegisterPDU.hpp" #include "util.hpp" +#include "OidVariable.hpp" using namespace agentxcpp; @@ -36,7 +37,7 @@ RegisterPDU::RegisterPDU(binary::const_iterator& pos, range_subid = *pos++; pos++; // skip reserved field - subtree = OidVariable(pos, end, big_endian); + subtree = OidVariable(pos, end, big_endian).value(); // read r.upper_bound only if r.range_subid is not 0 if(end - pos < 4) @@ -59,7 +60,7 @@ binary RegisterPDU::serialize() const serialized.push_back(range_subid); serialized.push_back(0); // reserved - serialized += subtree.serialize(); + serialized += OidVariable(subtree).serialize(); if( range_subid != 0 ) { diff --git a/src/RegisterPDU.hpp b/src/RegisterPDU.hpp index ea8924b..33f94ad 100644 --- a/src/RegisterPDU.hpp +++ b/src/RegisterPDU.hpp @@ -21,7 +21,7 @@ #include -#include "OidVariable.hpp" +#include "Oid.hpp" #include "PDUwithContext.hpp" namespace agentxcpp @@ -36,7 +36,7 @@ namespace agentxcpp private: quint8 timeout; quint8 priority; - OidVariable subtree; + Oid subtree; quint8 range_subid; quint32 upper_bound; @@ -59,14 +59,14 @@ namespace agentxcpp /** * \brief Set the subtree. */ - void set_subtree(OidVariable subtree) + void set_subtree(Oid subtree) { this->subtree = subtree; } /** * \brief Get the subtree. */ - OidVariable get_subtree() + Oid get_subtree() { return this->subtree; } diff --git a/src/RemoveAgentCapsPDU.cpp b/src/RemoveAgentCapsPDU.cpp index 4b8a419..4d478db 100644 --- a/src/RemoveAgentCapsPDU.cpp +++ b/src/RemoveAgentCapsPDU.cpp @@ -18,6 +18,7 @@ */ #include "RemoveAgentCapsPDU.hpp" +#include "OidVariable.hpp" using namespace agentxcpp; @@ -28,7 +29,7 @@ RemoveAgentCapsPDU::RemoveAgentCapsPDU(binary::const_iterator& pos, : PDUwithContext(pos, end, big_endian) { // parse ID - id = OidVariable(pos, end, big_endian); + id = OidVariable(pos, end, big_endian).value(); } @@ -39,7 +40,7 @@ binary RemoveAgentCapsPDU::serialize() binary serialized; // Serialize data - serialized += id.serialize(); + serialized += OidVariable(id).serialize(); // Add header add_header(PDU::agentxRemoveAgentCapsPDU, serialized); @@ -49,7 +50,7 @@ binary RemoveAgentCapsPDU::serialize() } -RemoveAgentCapsPDU::RemoveAgentCapsPDU(OidVariable id) +RemoveAgentCapsPDU::RemoveAgentCapsPDU(Oid id) { this->id = id; } diff --git a/src/RemoveAgentCapsPDU.hpp b/src/RemoveAgentCapsPDU.hpp index 698fa39..8733925 100644 --- a/src/RemoveAgentCapsPDU.hpp +++ b/src/RemoveAgentCapsPDU.hpp @@ -20,7 +20,7 @@ #define _REMOVEAGENTCAPSPDU_H_ #include "PDUwithContext.hpp" -#include "OidVariable.hpp" +#include "Oid.hpp" namespace agentxcpp { @@ -39,7 +39,7 @@ namespace agentxcpp * See RFC 2741, 6.2.15. "The agentx-RemoveAgentCaps-PDU" for * details. */ - OidVariable id; + Oid id; public: @@ -85,14 +85,14 @@ namespace agentxcpp * * \param id The value of the id field. */ - RemoveAgentCapsPDU(OidVariable id); + RemoveAgentCapsPDU(Oid id); /** * \brief Set the id field * * \param id The new id value. */ - void set_id(OidVariable id) + void set_id(Oid id) { this->id = id; } @@ -102,7 +102,7 @@ namespace agentxcpp * * \return The id value. */ - OidVariable get_id() + Oid get_id() { return this->id; } diff --git a/src/ResponsePDU.hpp b/src/ResponsePDU.hpp index a45b274..4fb8563 100644 --- a/src/ResponsePDU.hpp +++ b/src/ResponsePDU.hpp @@ -25,7 +25,6 @@ #include #include "PDU.hpp" -#include "OidVariable.hpp" #include "OctetStringVariable.hpp" #include "varbind.hpp" diff --git a/src/Table.cpp b/src/Table.cpp index 8efcc09..e1522ca 100644 --- a/src/Table.cpp +++ b/src/Table.cpp @@ -28,7 +28,7 @@ bool Table::addEntry(QSharedPointer entry) return false; } - OidVariable entryIndex = entry->index(); + Oid entryIndex = entry->index(); // Ensure that index is not registered if(entries.contains(entry)) @@ -40,12 +40,12 @@ bool Table::addEntry(QSharedPointer entry) // Register entry entries[entry] = entryIndex; - OidVariable index = myOid + entryIndex; + Oid index = myOid + entryIndex; // Register all variables of the entry quint32 i = 1; QSharedPointer var; - QVector< QPair< OidVariable,QSharedPointer > > toRegister; + QVector< QPair< Oid,QSharedPointer > > toRegister; while( (var = entry->getVariable(i)) ) { // Add variable to list @@ -75,10 +75,10 @@ bool Table::removeEntry(QSharedPointer entry) } // Unregister all variables of the entry - OidVariable entryIndex = entries[entry]; // Use index at time of registration + Oid entryIndex = entries[entry]; // Use index at time of registration quint32 i = 1; QSharedPointer var; - QVector toUnregister; + QVector toUnregister; while( (var = entry->getVariable(i)) ) { // Add variable to list diff --git a/src/Table.hpp b/src/Table.hpp index 79bb448..4c4f629 100644 --- a/src/Table.hpp +++ b/src/Table.hpp @@ -23,7 +23,7 @@ #include #include -#include "OidVariable.hpp" +#include "Oid.hpp" #include "TableEntry.hpp" #include "MasterProxy.hpp" @@ -81,7 +81,7 @@ class Table * * \exception None. */ - Table(OidVariable oid = OidVariable(), MasterProxy* master = 0) + Table(Oid oid = Oid(), MasterProxy* master = 0) : myMasterProxy(master), myOid(oid) { @@ -108,7 +108,7 @@ class Table * * \todo Re-add managed variables in case of OID change. */ - void setOid(OidVariable oid) + void setOid(Oid oid) { myOid = oid; } @@ -120,7 +120,7 @@ class Table * * \exception None. */ - OidVariable oid() + Oid oid() { return myOid; } @@ -202,7 +202,7 @@ class Table * - a pointer to the TableEntry object and * - the TableEntry's index at the time it was added to the table. */ - QMap< QSharedPointer, OidVariable > entries; + QMap< QSharedPointer, Oid > entries; /** * \brief The used MasterProxy object. @@ -214,7 +214,7 @@ class Table /** * \brief The tables OID. */ - OidVariable myOid; + Oid myOid; }; } /* namespace agentxcpp */ diff --git a/src/TableEntry.hpp b/src/TableEntry.hpp index f5a63f4..57d0068 100644 --- a/src/TableEntry.hpp +++ b/src/TableEntry.hpp @@ -20,7 +20,8 @@ #ifndef _TABLEENTRY_HPP_ #define _TABLEENTRY_HPP_ -#include "OidVariable.hpp" +#include "Oid.hpp" +#include "AbstractVariable.hpp" namespace agentxcpp { @@ -43,7 +44,7 @@ namespace agentxcpp * * \exception This method shall not throw. */ - virtual OidVariable index() = 0; + virtual Oid index() = 0; /** * \brief Get the variable with of column 'id'. diff --git a/src/UnregisterPDU.cpp b/src/UnregisterPDU.cpp index 05a029c..018c184 100644 --- a/src/UnregisterPDU.cpp +++ b/src/UnregisterPDU.cpp @@ -18,6 +18,7 @@ */ #include "UnregisterPDU.hpp" #include "util.hpp" +#include "OidVariable.hpp" using namespace agentxcpp; @@ -35,7 +36,7 @@ UnregisterPDU::UnregisterPDU(binary::const_iterator& pos, range_subid = *pos++; pos++; // skip reserved field - subtree = OidVariable(pos, end, big_endian); + subtree = OidVariable(pos, end, big_endian).value(); // read r.upper_bound only if r.range_subid is not 0 if( range_subid ) @@ -58,7 +59,7 @@ binary UnregisterPDU::serialize() const serialized.push_back(this->range_subid); serialized.push_back(0); // reserved - serialized += subtree.serialize(); + serialized += OidVariable(subtree).serialize(); if( range_subid ) { diff --git a/src/UnregisterPDU.hpp b/src/UnregisterPDU.hpp index 354f53a..f8b54b5 100644 --- a/src/UnregisterPDU.hpp +++ b/src/UnregisterPDU.hpp @@ -22,7 +22,7 @@ #include #include "PDUwithContext.hpp" -#include "OidVariable.hpp" +#include "Oid.hpp" namespace agentxcpp @@ -37,7 +37,7 @@ namespace agentxcpp private: quint8 priority; quint8 range_subid; - OidVariable subtree; + Oid subtree; quint32 upper_bound; public: @@ -59,14 +59,14 @@ namespace agentxcpp /** * \brief Set the subtree. */ - void set_subtree(OidVariable subtree) + void set_subtree(Oid subtree) { this->subtree = subtree; } /** * \brief Get the subtree. */ - OidVariable get_subtree() + Oid get_subtree() { return this->subtree; } diff --git a/src/helpers.cpp b/src/helpers.cpp index 8267924..449706c 100644 --- a/src/helpers.cpp +++ b/src/helpers.cpp @@ -48,32 +48,32 @@ namespace agentxcpp return sysuptime; } - OidVariable agentxcpp::generate_v1_snmpTrapOID(generic_trap_t generic_trap, + Oid agentxcpp::generate_v1_snmpTrapOID(generic_trap_t generic_trap, quint32 specific_trap) { // We need the OID of the SNMPv1 traps. These are defined here. // // First we define a "helper" OID: - static const OidVariable snmpTraps_oid(snmpMIBObjects_oid, "5"); + static const Oid snmpTraps_oid(snmpMIBObjects_oid, "5"); // // Some traps according to RFC 1907: - static const OidVariable snmpTraps_coldStart_oid(snmpTraps_oid, "1"); - static const OidVariable snmpTraps_warmStart_oid(snmpTraps_oid, "2"); - static const OidVariable snmpTraps_authenticationFailure_oid(snmpTraps_oid, "5"); + static const Oid snmpTraps_coldStart_oid(snmpTraps_oid, "1"); + static const Oid snmpTraps_warmStart_oid(snmpTraps_oid, "2"); + static const Oid snmpTraps_authenticationFailure_oid(snmpTraps_oid, "5"); // // Some traps according to RFC 1573: - static const OidVariable snmpTraps_linkDown_oid(snmpTraps_oid, "3"); - static const OidVariable snmpTraps_linkUp_oid(snmpTraps_oid, "4"); + static const Oid snmpTraps_linkDown_oid(snmpTraps_oid, "3"); + static const Oid snmpTraps_linkUp_oid(snmpTraps_oid, "4"); // Finally, egpNeighborLoss. According to RC 1907 it is defined in RFC // 1213, however, the latter doesn't define it. On the other hand, // RFC 2089 defines egpNeighborLoss as 1.3.6.1.6.3.1.1.5.6, which is // snmpTraps.6 and corresponds to the comment in RFC 1907, so we use this // one: - static const OidVariable snmpTraps_egpNeighborLoss_oid(snmpTraps_oid, "6"); + static const Oid snmpTraps_egpNeighborLoss_oid(snmpTraps_oid, "6"); // calculate the value of snmpTrapOID.0 according to RFC 1908: - OidVariable value; + Oid value; switch(generic_trap) { diff --git a/src/helpers.hpp b/src/helpers.hpp index f80327f..26eb932 100644 --- a/src/helpers.hpp +++ b/src/helpers.hpp @@ -86,7 +86,7 @@ namespace agentxcpp * \exception inval_param If the generic_trap parameter has an * invalid value. */ - OidVariable generate_v1_snmpTrapOID(generic_trap_t generic_trap, + Oid generate_v1_snmpTrapOID(generic_trap_t generic_trap, quint32 specific_trap=0); diff --git a/src/varbind.cpp b/src/varbind.cpp index 6357b0b..bb2eac6 100644 --- a/src/varbind.cpp +++ b/src/varbind.cpp @@ -27,6 +27,7 @@ #include "OpaqueVariable.hpp" #include "IpAddressVariable.hpp" #include "util.hpp" +#include "OidVariable.hpp" using namespace agentxcpp; @@ -43,7 +44,7 @@ binary varbind::serialize() const serialized.push_back( 0 ); // reserved // encode name - serialized += name.serialize(); + serialized += OidVariable(name).serialize(); // encode data if needed if (var) serialized += var->serialize(); @@ -52,7 +53,7 @@ binary varbind::serialize() const } -varbind::varbind(const OidVariable& o, QSharedPointer v) +varbind::varbind(const Oid& o, QSharedPointer v) { name = o; var = v; @@ -75,7 +76,7 @@ varbind::varbind(const OidVariable& o, QSharedPointer v) } -varbind::varbind(const OidVariable& o, type_t t) +varbind::varbind(const Oid& o, type_t t) { name = o; @@ -114,7 +115,7 @@ varbind::varbind(binary::const_iterator& pos, pos += 2; // read OID: no exceptions are catched; they are forwarded to the caller - name = OidVariable(pos, end, big_endian); + name = OidVariable(pos, end, big_endian).value(); // Get data: no exceptions are catched; they are forwarded to the caller switch(type) diff --git a/src/varbind.hpp b/src/varbind.hpp index 7059b2e..cddd72b 100644 --- a/src/varbind.hpp +++ b/src/varbind.hpp @@ -24,7 +24,7 @@ #include #include -#include "OidVariable.hpp" +#include "Oid.hpp" #include "AbstractVariable.hpp" namespace agentxcpp @@ -40,7 +40,7 @@ namespace agentxcpp /** * \brief The name (OID) of the VarBind. */ - OidVariable name; + Oid name; /** * \brief The variable inside the varbind. @@ -76,7 +76,7 @@ namespace agentxcpp * If the type of the variable cannot be determined, inval_param is * thrown. */ - varbind(const OidVariable&, QSharedPointer v); + varbind(const Oid&, QSharedPointer v); /** * \brief These values can be used to create a VarBind. @@ -95,7 +95,7 @@ namespace agentxcpp * Only the constants defined by varbind::type_t are allowed. A * wrong type will cause an inval_param exception. */ - varbind(const OidVariable&, type_t); + varbind(const Oid&, type_t); /** * \internal @@ -128,7 +128,7 @@ namespace agentxcpp /** * \brief Get the name (the OID) stored within the varbind. */ - OidVariable get_name() const + Oid get_name() const { return name; } From 6b1920159749f8a5ba87d87f989765a15718bd5e Mon Sep 17 00:00:00 2001 From: "Tanjeff-N. Moos" Date: Fri, 11 Apr 2014 23:42:20 +0200 Subject: [PATCH 38/89] Add Abstract::toOid(). This method was formerly implemented in some subclasses of AbstractVariable. I added the method to AbstractVariable and implemented it in all subclasses (where it was missing). --- src/AbstractVariable.hpp | 19 +++++++++++++++++++ src/Counter32Variable.hpp | 16 ++++++++++++---- src/Counter64Variable.hpp | 17 +++++++++++++---- src/Gauge32Variable.hpp | 18 +++++++++++++----- src/IntegerVariable.hpp | 2 +- src/IpAddressVariable.hpp | 2 +- src/OctetStringVariable.cpp | 5 ++++- src/OctetStringVariable.hpp | 8 +++----- src/OidVariable.hpp | 10 ++++++---- src/OpaqueVariable.cpp | 23 +++++++++++++++++++++++ src/OpaqueVariable.hpp | 12 ++++++++++++ src/TimeTicksVariable.hpp | 17 +++++++++++++---- 12 files changed, 120 insertions(+), 29 deletions(-) diff --git a/src/AbstractVariable.hpp b/src/AbstractVariable.hpp index 557325b..be497fd 100644 --- a/src/AbstractVariable.hpp +++ b/src/AbstractVariable.hpp @@ -22,6 +22,7 @@ #include #include "binary.hpp" +#include "Oid.hpp" namespace agentxcpp { @@ -228,6 +229,24 @@ namespace agentxcpp */ virtual binary serialize() const = 0; + /** + * \brief Convert an INDEX variable to an Oid part. + * + * If an SNMP variable is used as INDEX within a table, + * then its value is used as part of the Oid for that table + * entry (or row). Therefore, such variables must be + * convertible to Oid's. This method provides this conversion. + * + * Not all variable types are allowed to be used as INDEX and are + * therefore not convertible to Oid. For variables which are not + * convertible, this method shall return the null Oid. + * + * \return The variable, converted to Oid, or the null Oid if the + * variable don't support such conversion. + * + * \exception This method shall not throw. + */ + virtual Oid toOid() const = 0; }; } diff --git a/src/Counter32Variable.hpp b/src/Counter32Variable.hpp index 6e4d532..1cc58c7 100644 --- a/src/Counter32Variable.hpp +++ b/src/Counter32Variable.hpp @@ -7,10 +7,6 @@ namespace agentxcpp { /** * \brief Represents an Counter32 as described in RFC 2741. - * - * \note This class has no toOid() method, because Counter32 - * objects are not allowed in INDEX clauses according to - * RFC 2578, 7.7. "Mapping of the INDEX clause". */ class Counter32Variable : public AbstractVariable { @@ -284,6 +280,18 @@ namespace agentxcpp { return false; } + + /** + * \brief Return the null Oid. + * + * Objects of this class are not allowed in INDEX clauses according + * to RFC 2578, 7.7. "Mapping of the INDEX clause". Therefore, this + * method returns the null Oid. + */ + virtual Oid toOid() const + { + return Oid(); + } }; } #endif // _COUNTER32VARIABLE_H_ diff --git a/src/Counter64Variable.hpp b/src/Counter64Variable.hpp index 51308d8..d3cf9d4 100644 --- a/src/Counter64Variable.hpp +++ b/src/Counter64Variable.hpp @@ -7,10 +7,6 @@ namespace agentxcpp { /** * \brief Represents an Counter64 as described in RFC 2741. - * - * \note This class has no toOid() method, because Counter64 - * objects are not allowed in INDEX clauses according to - * RFC 2578, 7.7. "Mapping of the INDEX clause". */ class Counter64Variable : public AbstractVariable { @@ -284,6 +280,19 @@ namespace agentxcpp { return false; } + + /** + * \brief Return the null Oid. + * + * Objects of this class are not allowed in INDEX clauses according + * to RFC 2578, 7.7. "Mapping of the INDEX clause". Therefore, this + * method returns the null Oid. + */ + virtual Oid toOid() const + { + return Oid(); + } + }; } #endif // _COUNTER64VARIABLE_H_ diff --git a/src/Gauge32Variable.hpp b/src/Gauge32Variable.hpp index 7d1ba23..faec1d6 100644 --- a/src/Gauge32Variable.hpp +++ b/src/Gauge32Variable.hpp @@ -29,11 +29,6 @@ namespace agentxcpp { /** * \brief Represents a Gauge32 as described in RFC 2741 - * - * \note This class has no toOid() method, because RFC 2578, - * 7.7. "Mapping of the INDEX clause" does not describe - * how to convert Gauge32 to an OID. - * */ class Gauge32Variable : public AbstractVariable { @@ -315,6 +310,19 @@ namespace agentxcpp return false; } + /** + * \brief Return the null Oid. + * + * This method returns the null Oid because RFC 2578, 7.7. + * "Mapping of the INDEX clause" does not + * describe how to convert Gauge32 to an OID. + */ + virtual Oid toOid() const + { + return Oid(); + } + + }; } diff --git a/src/IntegerVariable.hpp b/src/IntegerVariable.hpp index ad2649b..12a9ba6 100644 --- a/src/IntegerVariable.hpp +++ b/src/IntegerVariable.hpp @@ -117,7 +117,7 @@ namespace agentxcpp * value 0 should be avoided according to * RFC 2578, 7.7. "Mapping of the INDEX clause". */ - Oid toOid() const + virtual Oid toOid() const { Oid oid; oid.push_back(v); diff --git a/src/IpAddressVariable.hpp b/src/IpAddressVariable.hpp index 37b2e73..a63f8c6 100644 --- a/src/IpAddressVariable.hpp +++ b/src/IpAddressVariable.hpp @@ -164,7 +164,7 @@ namespace agentxcpp * has exactly 4 subids which corresponds to the 4 * integers of the IP address. */ - Oid toOid() const + virtual Oid toOid() const { Oid oid; oid.push_back(address[0]); diff --git a/src/OctetStringVariable.cpp b/src/OctetStringVariable.cpp index 405141a..5c46e46 100644 --- a/src/OctetStringVariable.cpp +++ b/src/OctetStringVariable.cpp @@ -140,8 +140,11 @@ OctetStringVariable::OctetStringVariable(binary::const_iterator& pos, } -Oid OctetStringVariable::toOid(bool fixedLength) const +Oid OctetStringVariable::toOid() const { + // There are fixed length string, but don't support them currently. + bool fixedLength = false; + Oid oid; // Store string length if needed diff --git a/src/OctetStringVariable.hpp b/src/OctetStringVariable.hpp index 35be5c3..55eb3e0 100644 --- a/src/OctetStringVariable.hpp +++ b/src/OctetStringVariable.hpp @@ -110,11 +110,10 @@ namespace agentxcpp * string length is converted to a subid. Then, each * octet of the value is converted into a separate subid. * - * Note that the length subid is omitted for fixed-length strings. - * - * \param fixedLength Whether the string is fixed-length. + * \todo Support fixed-length strings according to RFC 2578, + * 7.7. "Mapping of the INDEX clause". */ - Oid toOid(bool fixedLength = false) const; + virtual Oid toOid() const; /** * \internal @@ -307,7 +306,6 @@ namespace agentxcpp { return false; } - }; } #endif // _OCTETSTRINGVARIABLE_H_ diff --git a/src/OidVariable.hpp b/src/OidVariable.hpp index 4376559..14802ed 100644 --- a/src/OidVariable.hpp +++ b/src/OidVariable.hpp @@ -141,16 +141,18 @@ namespace agentxcpp * length is converted to a subid. Then, each * subid of the value is appended. * - * Note that the length subid is omitted for fixed-length OIDs. - * - * \param fixedLength Whether the OID is fixed-length. + * \todo Support fixed-length OIDs according to RFC 2578, + * 7.7. "Mapping of the INDEX clause". * * \return The generated Oid. * * \exception None. */ - Oid toOid(bool fixedLength = false) const + virtual Oid toOid() const { + // fixed length currently unsupported: + bool fixedLength = false; + Oid oid; // Store length if needed diff --git a/src/OpaqueVariable.cpp b/src/OpaqueVariable.cpp index f1a080d..2617c99 100644 --- a/src/OpaqueVariable.cpp +++ b/src/OpaqueVariable.cpp @@ -103,3 +103,26 @@ OpaqueVariable::OpaqueVariable(binary::const_iterator& pos, pos++; } } + +Oid OpaqueVariable::toOid() const +{ + // There are fixed length string, but don't support them currently. + bool fixedLength = false; + + Oid oid; + + // Store string length if needed + if(!fixedLength) + { + oid.push_back(v.size()); + } + + // Store string + for(binary::const_iterator i = v.begin(); + i != v.end(); + ++i) + { + oid.push_back(*i); + } + return oid; +} diff --git a/src/OpaqueVariable.hpp b/src/OpaqueVariable.hpp index f11d75f..cadbc77 100644 --- a/src/OpaqueVariable.hpp +++ b/src/OpaqueVariable.hpp @@ -314,6 +314,18 @@ namespace agentxcpp return false; } + /** + * \brief Convert the value to an OID. + * + * The conversion is done according to RFC 2578, + * 7.7. "Mapping of the INDEX clause". First, the + * string length is converted to a subid. Then, each + * octet of the value is converted into a separate subid. + * + * \todo Support fixed-length strings according to RFC 2578, + * 7.7. "Mapping of the INDEX clause". + */ + virtual Oid toOid() const; }; } diff --git a/src/TimeTicksVariable.hpp b/src/TimeTicksVariable.hpp index 7a2b72c..bc32b80 100644 --- a/src/TimeTicksVariable.hpp +++ b/src/TimeTicksVariable.hpp @@ -29,10 +29,6 @@ namespace agentxcpp { /** * \brief Represents an TimeTicks as described in RFC 2741 - * - * \note This class has no toOid() method, because RFC 2578, - * 7.7. "Mapping of the INDEX clause" does not describe - * how to convert TimeTicks to an OID. */ class TimeTicksVariable : public AbstractVariable { @@ -310,6 +306,19 @@ namespace agentxcpp { return false; } + + /** + * \brief Return the null Oid. + * + * This method returns the null Oid because RFC 2578, 7.7. + * "Mapping of the INDEX clause" does not + * describe how to convert Timeicks to an OID. + */ + virtual Oid toOid() const + { + return Oid(); + } + }; } From 53a73f9a3a18795e0381d300fb5d1220df7baed7 Mon Sep 17 00:00:00 2001 From: "Tanjeff-N. Moos" Date: Fri, 11 Apr 2014 23:52:27 +0200 Subject: [PATCH 39/89] Rework Table and TableEntry to ease API. The TableEntry class now provides mwthods for returning all variables and for returning the index variables. The methods for calculating the index and for returning a specific variable based on its Oid were removed. --- src/Table.cpp | 49 ++++++++++++++++++++++++++++------------------ src/TableEntry.hpp | 28 ++++++++++++-------------- 2 files changed, 42 insertions(+), 35 deletions(-) diff --git a/src/Table.cpp b/src/Table.cpp index e1522ca..b4b7388 100644 --- a/src/Table.cpp +++ b/src/Table.cpp @@ -23,13 +23,12 @@ using namespace agentxcpp; bool Table::addEntry(QSharedPointer entry) { + // Check for MasterProxy object if(! myMasterProxy) { return false; } - Oid entryIndex = entry->index(); - // Ensure that index is not registered if(entries.contains(entry)) { @@ -37,21 +36,36 @@ bool Table::addEntry(QSharedPointer entry) return false; } + // Calculate entry's index + Oid entryIndex; + QVector< QSharedPointer > indexVariables = entry->indexVariables(); + QVectorIterator< QSharedPointer > iter(indexVariables); + while(iter.hasNext()) + { + Oid variableIndex = iter.next()->toOid(); + if(variableIndex.is_null()) + { + // Variable cannot be converted to Oid -> not + // allowed as index variable. + return false; + } + else + { + // Variable contributes to index + entryIndex += variableIndex; + } + } + // Register entry entries[entry] = entryIndex; - Oid index = myOid + entryIndex; - - // Register all variables of the entry - quint32 i = 1; - QSharedPointer var; + // Register all variables of the entry with the MasterProxy object + QVector< QSharedPointer > variables = entry->variables(); QVector< QPair< Oid,QSharedPointer > > toRegister; - while( (var = entry->getVariable(i)) ) + for(int i = 0; i < variables.size(); ++i) { // Add variable to list - toRegister.append(qMakePair(index + i, var)); - - ++i; + toRegister.append(qMakePair(myOid + entryIndex + i, variables[i])); } myMasterProxy->addVariables(toRegister); @@ -62,13 +76,14 @@ bool Table::addEntry(QSharedPointer entry) bool Table::removeEntry(QSharedPointer entry) { + // Check for MasterProxy object if(! myMasterProxy) { return false; } // Ensure that entry is known - if(entries.contains(entry)) + if(!entries.contains(entry)) { // Entry not found return false; @@ -76,15 +91,12 @@ bool Table::removeEntry(QSharedPointer entry) // Unregister all variables of the entry Oid entryIndex = entries[entry]; // Use index at time of registration - quint32 i = 1; - QSharedPointer var; QVector toUnregister; - while( (var = entry->getVariable(i)) ) + QVector< QSharedPointer > variables = entry->variables(); + for(int i = 0; i < variables.size(); ++i) { - // Add variable to list + // Add variable's Oid to list toUnregister.append(myOid + entryIndex + i); - - ++i; } myMasterProxy->removeVariables(toUnregister); @@ -93,5 +105,4 @@ bool Table::removeEntry(QSharedPointer entry) // All went well, as far as we can tell. return true; - } diff --git a/src/TableEntry.hpp b/src/TableEntry.hpp index 57d0068..f0901e1 100644 --- a/src/TableEntry.hpp +++ b/src/TableEntry.hpp @@ -34,34 +34,30 @@ namespace agentxcpp public: /** - * \brief Get the index for this entry. + * \brief Get the index variables of this entry. * - * This method shall provide the index for the entry. The index is - * the concatenation of the index variables, converted to OID's. - * See ///TUTORIAL/// for an example. + * This method shall provide the index variables for the entry. + * The order in the vector shall match the order specified + * in the MIB. * - * \return The index of the entry. + * \return The index variables of the entry. * * \exception This method shall not throw. */ - virtual Oid index() = 0; + virtual QVector< QSharedPointer > indexVariables() = 0; /** - * \brief Get the variable with of column 'id'. + * \brief Get the variables of this entry. * - * This method shall return the variable with the column 'id'. If - * no variable is available for the column, the NULL pointer shall - * be returned. + * This method shall return the variables for this entry. It is + * assumed that the index of a variable in the returned vector + * matches its index specified in the MIB. * - * The variables of the table entry shall be consequtive, to - * support iterating the entry (i.e. by incrementing 'id' until - * the NULL pointer is returned). - * - * \return The variable with column 'id'. + * \return The variables for this entry. * * \exception This method shall not throw. */ - virtual QSharedPointer getVariable(quint32 id) = 0; + virtual QVector< QSharedPointer > variables() = 0; /** * \brief Virtual Destructor. From 0f6002fc10366eeebc1d750707314a410afbc7a9 Mon Sep 17 00:00:00 2001 From: "Tanjeff-N. Moos" Date: Sat, 12 Apr 2014 00:18:15 +0200 Subject: [PATCH 40/89] Update tutorials (use Oid instead of OidVariable). --- doc/how_to_send_notifications.dox | 15 +++++++-------- doc/how_to_write_a_subagent.dox | 4 ++-- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/doc/how_to_send_notifications.dox b/doc/how_to_send_notifications.dox index 6409a1f..1f60a50 100644 --- a/doc/how_to_send_notifications.dox +++ b/doc/how_to_send_notifications.dox @@ -90,7 +90,7 @@ file). Here ist the NotificationSender.hpp file: #include #include -#include +#include #include #include "SimpleCounter.hpp" @@ -102,12 +102,12 @@ class NotificationSender : public QObject private: MasterProxy* master; - OidVariable simpleCounter_oid; + Oid simpleCounter_oid; QSharedPointer counter; public: NotificationSender(MasterProxy* _master, - OidVariable _oid, + Oid _oid, QSharedPointer _counter) : master(_master), simpleCounter_oid(_oid), counter(_counter) { @@ -123,7 +123,7 @@ class NotificationSender : public QObject objects.push_back(varbind(simpleCounter_oid, counterVariable)); QMetaObject::invokeMethod(master, "send_notification", - Q_ARG(const OidVariable&, simpleCounter_oid), + Q_ARG(const Oid&, simpleCounter_oid), Q_ARG(const std::vector&, objects) ); } @@ -172,16 +172,15 @@ int main(int argc, char** argv) QCoreApplication app(argc, argv); MasterProxy master; - OidVariable simpleagentOid = OidVariable(enterprises_oid, "42.1"); + Oid simpleagentOid = Oid(enterprises_oid, "42.1"); master.register_subtree(simpleagentOid); QSharedPointer counter(new SimpleCounter); - OidVariable simpleCounterOid = simpleagentOid + 0; + Oid simpleCounterOid = simpleagentOid + 0; master.add_variable(simpleCounterOid, counter); - + // New code for sending notifications --------------- NotificationSender sender(&master, simpleCounterOid, counter); - QTimer timer; QObject::connect(&timer, SIGNAL(timeout()), &sender, SLOT(sendNotification())); diff --git a/doc/how_to_write_a_subagent.dox b/doc/how_to_write_a_subagent.dox index bd42b81..4fd71b0 100644 --- a/doc/how_to_write_a_subagent.dox +++ b/doc/how_to_write_a_subagent.dox @@ -187,7 +187,7 @@ that. Here is the code for subtree registration: \code - OidVariable simpleagentOid = OidVariable(enterprises_oid, "42.1"); + Oid simpleagentOid = Oid(enterprises_oid, "42.1"); master.register_subtree(simpleagentOid); \endcode @@ -199,7 +199,7 @@ Next, we create a SimpleCounter variable and register it with the master: \code QSharedPointer counter(new SimpleCounter); - OidVariable simpleCounterOid = simpleagentOid + 0; + Oid simpleCounterOid = simpleagentOid + 0; master.add_variable(simpleCounterOid, counter); \endcode From 275491051c30dcc18e403073d4c48f53f0616845 Mon Sep 17 00:00:00 2001 From: "Tanjeff-N. Moos" Date: Sat, 12 Apr 2014 10:46:29 +0200 Subject: [PATCH 41/89] Add doxygen command \agentxcpp. The command can be used to reference items in the agentxcpp namespace, like so: \agentxcpp{MasterProxy} This will produce the Text "MasterProxy" which links to the MasterProxy class. --- doc/api.doxyfile | 2 +- doc/internals.doxyfile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/api.doxyfile b/doc/api.doxyfile index 39743e7..d61b1b3 100644 --- a/doc/api.doxyfile +++ b/doc/api.doxyfile @@ -223,7 +223,7 @@ TAB_SIZE = 8 # will result in a user-defined paragraph with heading "Side Effects:". # You can put \n's in the value part of an alias to insert newlines. -ALIASES = +ALIASES = agentxcpp{1}="\ref agentxcpp::\1 \"\1\"" # This tag can be used to specify a number of word-keyword mappings (TCL only). # A mapping has the form "name=value". For example adding diff --git a/doc/internals.doxyfile b/doc/internals.doxyfile index 16ac67b..f6b5ccb 100644 --- a/doc/internals.doxyfile +++ b/doc/internals.doxyfile @@ -223,7 +223,7 @@ TAB_SIZE = 8 # will result in a user-defined paragraph with heading "Side Effects:". # You can put \n's in the value part of an alias to insert newlines. -ALIASES = +ALIASES = agentxcpp{1}="\ref agentxcpp::\1 \"\1\"" # This tag can be used to specify a number of word-keyword mappings (TCL only). # A mapping has the form "name=value". For example adding From 094ceb6f29f213921e95648cdf0e3824ab141d21 Mon Sep 17 00:00:00 2001 From: "Tanjeff-N. Moos" Date: Fri, 18 Apr 2014 11:27:54 +0200 Subject: [PATCH 42/89] TableEntry::variables() returns QMap, not QVector. --- src/Table.cpp | 16 ++++++++++------ src/TableEntry.hpp | 11 +++++++---- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/Table.cpp b/src/Table.cpp index b4b7388..dd2f72f 100644 --- a/src/Table.cpp +++ b/src/Table.cpp @@ -60,12 +60,14 @@ bool Table::addEntry(QSharedPointer entry) entries[entry] = entryIndex; // Register all variables of the entry with the MasterProxy object - QVector< QSharedPointer > variables = entry->variables(); + QMap< quint32, QSharedPointer > variables = entry->variables(); + QMapIterator< quint32, QSharedPointer > iter2(variables); QVector< QPair< Oid,QSharedPointer > > toRegister; - for(int i = 0; i < variables.size(); ++i) + while(iter2.hasNext()) { + iter2.next(); // Add variable to list - toRegister.append(qMakePair(myOid + entryIndex + i, variables[i])); + toRegister.append(qMakePair(myOid + entryIndex + iter2.key(), iter2.value())); } myMasterProxy->addVariables(toRegister); @@ -91,12 +93,14 @@ bool Table::removeEntry(QSharedPointer entry) // Unregister all variables of the entry Oid entryIndex = entries[entry]; // Use index at time of registration + QMap< quint32, QSharedPointer > variables = entry->variables(); + QMapIterator< quint32, QSharedPointer > iter2(variables); QVector toUnregister; - QVector< QSharedPointer > variables = entry->variables(); - for(int i = 0; i < variables.size(); ++i) + while(iter2.hasNext()) { + iter2.next(); // Add variable's Oid to list - toUnregister.append(myOid + entryIndex + i); + toUnregister.append(myOid + entryIndex + iter2.key()); } myMasterProxy->removeVariables(toUnregister); diff --git a/src/TableEntry.hpp b/src/TableEntry.hpp index f0901e1..0cda36c 100644 --- a/src/TableEntry.hpp +++ b/src/TableEntry.hpp @@ -20,6 +20,9 @@ #ifndef _TABLEENTRY_HPP_ #define _TABLEENTRY_HPP_ +#include +#include + #include "Oid.hpp" #include "AbstractVariable.hpp" @@ -49,15 +52,15 @@ namespace agentxcpp /** * \brief Get the variables of this entry. * - * This method shall return the variables for this entry. It is - * assumed that the index of a variable in the returned vector - * matches its index specified in the MIB. + * This method shall return the variables for this entry. The + * variables are returned as a map, with the variables index + * as key and the variable itself as value. * * \return The variables for this entry. * * \exception This method shall not throw. */ - virtual QVector< QSharedPointer > variables() = 0; + virtual QMap< quint32, QSharedPointer > variables() = 0; /** * \brief Virtual Destructor. From d9146346025fa0267bc9a68f6cf70d0a6c065286 Mon Sep 17 00:00:00 2001 From: "Tanjeff-N. Moos" Date: Fri, 18 Apr 2014 23:41:05 +0200 Subject: [PATCH 43/89] Bugfix: Check iterator after map::upper_bound(). And after map::lower_bound(), too. --- src/MasterProxy.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/MasterProxy.cpp b/src/MasterProxy.cpp index 6eaa823..07e4aee 100644 --- a/src/MasterProxy.cpp +++ b/src/MasterProxy.cpp @@ -539,7 +539,7 @@ void MasterProxy::handle_getnextpdu(QSharedPointer response, QShare // lexicographical successor of it next_var = variables.lower_bound(starting_oid); } - if( ! ending_oid.is_null() ) + if(next_var != variables.end() && ! ending_oid.is_null() ) { // The "next" variable must precede the ending OID (it must not // be greater or equal than the ending OID) From 6fd03dfa29b53773c94d7356a84a3ed1094dd3d9 Mon Sep 17 00:00:00 2001 From: "Tanjeff-N. Moos" Date: Sat, 19 Apr 2014 00:02:40 +0200 Subject: [PATCH 44/89] Add NULL-pointer checks to Table::addEntry(). --- src/Table.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Table.cpp b/src/Table.cpp index dd2f72f..768917f 100644 --- a/src/Table.cpp +++ b/src/Table.cpp @@ -42,7 +42,13 @@ bool Table::addEntry(QSharedPointer entry) QVectorIterator< QSharedPointer > iter(indexVariables); while(iter.hasNext()) { - Oid variableIndex = iter.next()->toOid(); + QSharedPointer var = iter.next(); + if(!var) + { + // No variable -> fail + return false; + } + Oid variableIndex = var->toOid(); if(variableIndex.is_null()) { // Variable cannot be converted to Oid -> not @@ -66,6 +72,12 @@ bool Table::addEntry(QSharedPointer entry) while(iter2.hasNext()) { iter2.next(); + if(! iter2.value()) + { + // No variable given -> fail + entries.remove(entry); + return false; + } // Add variable to list toRegister.append(qMakePair(myOid + entryIndex + iter2.key(), iter2.value())); } From 29bf45144beeb5ebc368353a25a27b64850e4e05 Mon Sep 17 00:00:00 2001 From: "Tanjeff-N. Moos" Date: Sat, 19 Apr 2014 00:10:46 +0200 Subject: [PATCH 45/89] Fix OID;s of table objects. --- src/Table.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Table.cpp b/src/Table.cpp index 768917f..6d9a203 100644 --- a/src/Table.cpp +++ b/src/Table.cpp @@ -79,7 +79,7 @@ bool Table::addEntry(QSharedPointer entry) return false; } // Add variable to list - toRegister.append(qMakePair(myOid + entryIndex + iter2.key(), iter2.value())); + toRegister.append(qMakePair(myOid + iter2.key() + entryIndex, iter2.value())); } myMasterProxy->addVariables(toRegister); @@ -112,7 +112,7 @@ bool Table::removeEntry(QSharedPointer entry) { iter2.next(); // Add variable's Oid to list - toUnregister.append(myOid + entryIndex + iter2.key()); + toUnregister.append(myOid + iter2.key() + entryIndex); } myMasterProxy->removeVariables(toUnregister); From c73bc02495c8fc63268955b9327e1f9c173e892f Mon Sep 17 00:00:00 2001 From: "Tanjeff-N. Moos" Date: Sat, 19 Apr 2014 23:15:04 +0200 Subject: [PATCH 46/89] Add the TableEntry::subid member. The member represents the subid of the entry as given in the MIB. --- src/Table.cpp | 4 ++-- src/TableEntry.hpp | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Table.cpp b/src/Table.cpp index 6d9a203..47eef1a 100644 --- a/src/Table.cpp +++ b/src/Table.cpp @@ -79,7 +79,7 @@ bool Table::addEntry(QSharedPointer entry) return false; } // Add variable to list - toRegister.append(qMakePair(myOid + iter2.key() + entryIndex, iter2.value())); + toRegister.append(qMakePair(myOid + entry->subid + iter2.key() + entryIndex, iter2.value())); } myMasterProxy->addVariables(toRegister); @@ -112,7 +112,7 @@ bool Table::removeEntry(QSharedPointer entry) { iter2.next(); // Add variable's Oid to list - toUnregister.append(myOid + iter2.key() + entryIndex); + toUnregister.append(myOid + entry->subid + iter2.key() + entryIndex); } myMasterProxy->removeVariables(toUnregister); diff --git a/src/TableEntry.hpp b/src/TableEntry.hpp index 0cda36c..6ea06fb 100644 --- a/src/TableEntry.hpp +++ b/src/TableEntry.hpp @@ -35,6 +35,14 @@ namespace agentxcpp class TableEntry { public: + /** + * \brief The subid assigned to this entry. + * + * This variable shall be initialized by a subclass before + * the entry is added to a table. See \ref how_tables_work for + * an introduction to this value. + */ + quint32 subid; /** * \brief Get the index variables of this entry. From d2ee21794723f14f28cd75a1eb204dab2285d70e Mon Sep 17 00:00:00 2001 From: "Tanjeff-N. Moos" Date: Thu, 10 Apr 2014 08:30:05 +0200 Subject: [PATCH 47/89] Work on the table tutorial. --- doc/how_to_add_rw_support.dox | 3 +- doc/how_to_implement_tables.dox | 279 +++++++++++++++++++++++++++--- doc/how_to_send_notifications.dox | 12 +- doc/how_to_write_a_subagent.dox | 9 +- 4 files changed, 264 insertions(+), 39 deletions(-) diff --git a/doc/how_to_add_rw_support.dox b/doc/how_to_add_rw_support.dox index 9764b96..f35b901 100644 --- a/doc/how_to_add_rw_support.dox +++ b/doc/how_to_add_rw_support.dox @@ -199,8 +199,7 @@ Again, we compile and run the subagent. This is exactly the same as in the first tutorial (it is assumed that your system is already setup accordingly): \verbatim -g++ simpleagent.cpp -o simpleagent -lagentxcpp \ - `pkg-config --cflags --libs QtNetwork QtCore` +g++ simpleagent.cpp -o simpleagent -lagentxcpp `pkg-config --cflags --libs QtNetwork QtCore` \endverbatim Next, we start the subagent again: diff --git a/doc/how_to_implement_tables.dox b/doc/how_to_implement_tables.dox index 619dd8c..8f9e05b 100644 --- a/doc/how_to_implement_tables.dox +++ b/doc/how_to_implement_tables.dox @@ -1,4 +1,4 @@ -/* +* * Copyright 2011-2013 Tanjeff-Nicolai Moos * * This file is part of the agentXcpp library. @@ -93,8 +93,8 @@ counterChangeTimeString OBJECT-TYPE SYNTAX OCTETSTRING ACCESS read-only STATUS current - DESCRIPTION "The time (counterChangeEpoch + counterChangeMilliseconds) as a - human-readable string." + DESCRIPTION "The time (counterChangeEpoch + counterChangeMilliseconds) as + a human-readable string." ::={ counterChangeEntry 3 } counterChangeValue OBJECT-TYPE @@ -113,29 +113,260 @@ SET request), an entry is added. Each entry within the table has a timestamp, which consists of the epoch time and a milliseconds component. This is to show how multiple variables can be -used to form the tables index. In addition, the time is reported in an +used to form the table's index. In addition, the time is reported in an human-readable format (e.g. "2011-09-11, 12:00:52.77"). Finally, each entry reports the new counter value. + +\section how_tables_work How tables work in agentXcpp + +Technically, our SNMP table is a sequence of counterChangeEntry, which in turn +is a structure containing four "real" SNMP variables. The OID of these +variables are assembled like this: + + ... + +The is the OID given to the table. The counterChangeTable for +example has the OID enterprises.42.2, which is .1.3.6.1.4.1.42.2. + +The is a single number assigned to the table entry. The +CounterChangeEntry for example has the 1. + +The is a single number which can be thought to be the column +of a specific variable. The counterChangeEpoch has =1, while +counterChangeTimeString has =3. + +The is the concatenation of the index variables (counterChangeEpoch +and counterChangeMilliseconds), converted to OID. For example, if +counterChangeEpoch is 123456789 and counterChangeMilliseconds is 512, the index +would be "123456789.512". The index can be thought of as the identifier of the +row in which the entry resides. In terms of a relational database it would be +called the primary key of the record. + +Thus, the full OID of the counterChangeTimeString in the entry 123456789.512, +for example, would be ".1.3.6.1.4.1.42.2.1.3.123456789.512". + +A table is implemented by creating a \agentxcpp{Table} object and tell it its + (enterprises.42.2). An entry is implemented by subclassing +\agentxcpp{TableEntry}. For our table, we will implement the +CounterChangeEntry class which contains the four variables counterChangeEpoch, +counterChangeMilliseconds, counterChangeTimeString and +counterChangeCounterValue. The CounterChangeEntry class must implement the +\agentxcpp{TableEntry::indexVariables()} and +\agentxcpp{TableEntry::variables()} methods, and is must ensure that +is set correctly. + +Each time an entry is added, the table will query the new entry for all its +variables and add these to the MasterProxy object, so that they are +served like any other variable. If an entry is removed, the table will remove +its variables from the MasterProxy object again. Neither the table nor the +entry can actually be queried by SNMP requests; they are only used to organize +the variables which can be queried. Therefore, neither the table nor the +entries are added to the MasterProxy object. Only the variables are added. + + +\section implementing_entry Implementing the CounterChangeEntry class + +First of all, we implement the CounterChangeEntry class. Here is the full +code: + +\code +#ifndef _COUNTERCHANGEENTRY_H_ +#define _COUNTERCHANGEENTRY_H_ + +#include +#include +#include + +using namespace agentxcpp; + +class CounterChangeEntry : public TableEntry +{ + public: + QSharedPointer counterChangeEpoch; + QSharedPointer counterChangeMilliseconds; + QSharedPointer counterChangeTimeString; + QSharedPointer counterChangeValue; + + CounterChangeEntry() + : counterChangeEpoch(new IntegerVariable), + counterChangeMilliseconds(new IntegerVariable), + counterChangeTimeString(new DisplayStringVariable), + counterChangeValue(new IntegerVariable) + { + subid = 1; + } + + virtual QVector< QSharedPointer > indexVariables() + { + QVector< QSharedPointer > result; + result << counterChangeEpoch + << counterChangeMilliseconds; + return result; + } + + virtual QMap< quint32, QSharedPointer > variables() + { + QMap< quint32, QSharedPointer > result; + result[1] = counterChangeEpoch; + result[2] = counterChangeMilliseconds; + result[3] = counterChangeTimeString; + result[4] = counterChangeValue; + return result; + } +}; +#endif // _COUNTERCHANGEENTRY_H_ +\endcode + +The class inherits \agentxcpp{TableEntry}. It has four members which represent +the four SNMP variables. Since in agentXcpp those variables are handled as +QSharedPointer's, the constructor needs to create all of them using the new +operator. + +Each entry within a table needs a unique index, which becomes a part of the OID +of its variables. The index is built up by the index variables. Our MIB states +that counterChangeEpoch and counterChangeMilliseconds are used as index. The +CounterChangeEntry::indexVariables() method implements this by returning these +variables in a QVector, in the order in which they are used in the index. Note +that the entry's OID changes if the index variables change their value. Our +simpleagent will not change and entry after it was added to the table, though. + +The CounterChangeEntry::variables() method return all variables as a QMap. The +map key will be used by the table as part for the variable +stored as value. + + +\section extending_simplecounter Extending the SimpleCounter class. + +\code +#include +#include "CounterChangeEntry.hpp" +#include +\endcode + +Next, we extent the SimpleCounter class so that it adds an entry to the table +each time the counter is changed. One thing to do is to add a \agentxcpp{Table} +member, a member to store the entry just inserted into the table (needed for +undoset(), a suitable constructor and the helper function addEntry(): + +\code + private: + Table* table; // may be the null pointer + QSharedPointer lastInsertedEntry; // for undoset() + + public: + SimpleCounter(Table* t = 0) + { + table = t; + } + + void addEntry() + { + // Add entry with new value to table + if(table) + { + lastInsertedEntry = QSharedPointer(new CounterChangeEntry); + QDateTime timeStamp = QDateTime::currentDateTimeUtc(); + lastInsertedEntry->counterChangeEpoch->setValue(timeStamp.toTime_t()); + lastInsertedEntry->counterChangeMilliseconds->setValue(timeStamp.toMSecsSinceEpoch() - timeStamp.toTime_t()*1000); + lastInsertedEntry->counterChangeTimeString->setValue(timeStamp.toString("yyyy-MM-dd (dddd) hh:mm:ss.z")); + lastInsertedEntry->counterChangeValue->setValue(v); + table->addEntry(lastInsertedEntry); + } + } +\endcode + +And we have to extend the get(), commitset() and undoset() functions, which now +look like this: + +\code + virtual void get() + { + ++v; + addEntry(); + } + + virtual bool commitset(QSharedPointer new_value) + { + // Remember old value for rollback + (*old_value) = v; + // Set new value + v = new_value->value(); + // Add table entry + addEntry(); + // Operation succeeded + return true; + } + + virtual bool undoset(QSharedPointer new_value) + { + // Restore old value + v = *old_value; + // Release old value + delete old_value; + // Remove table entry + if(table) + { + table->removeEntry(lastInsertedEntry); + } + // Rollback succeeded + return true; + } +\endcode + +And finally we update the main() function as follows: + +\code +int main(int argc, char** argv) +{ + QCoreApplication app(argc, argv); + + MasterProxy master; + + Oid simpleagentOid = Oid(enterprises_oid, "42"); + master.register_subtree(simpleagentOid); + + Table table(simpleagentOid + 2, &master); + QSharedPointer counter(new SimpleCounter(&table)); + Oid simpleCounterOid = simpleagentOid + 1 + 0; + master.add_variable(simpleCounterOid, counter); + + // New code for sending notifications --------------- + NotificationSender sender(&master, simpleCounterOid, counter); + QTimer timer; + QObject::connect(&timer, SIGNAL(timeout()), + &sender, SLOT(sendNotification())); + timer.setInterval(1000); // 1000 milliseconds + timer.start(); + // -------------------------------------------------- + + app.exec(); +} +\endcode + + + +\section compiling_notification Compiling the Subagent + +OLD: + +\code +moc-qt4 `pkg-config --cflags QtCore QtNetwork` -o moc_NotificationSender.cc NotificationSender.hpp +\endcode + +\code +g++ -c moc_NotificationSender.cc `pkg-config --cflags QtCore QtNetwork` +\endcode + +NEEDED: + +\code +g++ simpleagent.cpp -o simpleagent moc_NotificationSender.o `pkg-config --cflags --libs QtNetwork QtCore` -lagentxcpp +\endcode + +Now, the executable is ready to run. + + + */ -//\section implementing_the_variables Implementing the variables. -// -//First of all, we will create the variables notificationEventEpoch, -//notificationEventMilliseconds, notificationEventTimeString and -//notificationEventCounterValue. These are all read-only variable, therefore it -//suffice to instantiate the stanard classes agentXcpp provides: -// -//\code -// IntegerVariable notificationEventEpoch; -// IntegerVariable notificationEventMilliseconds; -// DisplayStringVariable notificationEventTimeString; -// IntegerVariable notificationEventCounterValue; -//\endcode -// -// -// -// -// -// -//*/ diff --git a/doc/how_to_send_notifications.dox b/doc/how_to_send_notifications.dox index 1f60a50..239613f 100644 --- a/doc/how_to_send_notifications.dox +++ b/doc/how_to_send_notifications.dox @@ -172,11 +172,11 @@ int main(int argc, char** argv) QCoreApplication app(argc, argv); MasterProxy master; - Oid simpleagentOid = Oid(enterprises_oid, "42.1"); + Oid simpleagentOid = Oid(enterprises_oid, "42"); master.register_subtree(simpleagentOid); QSharedPointer counter(new SimpleCounter); - Oid simpleCounterOid = simpleagentOid + 0; + Oid simpleCounterOid = simpleagentOid + 1 + 0; master.add_variable(simpleCounterOid, counter); // New code for sending notifications --------------- @@ -205,9 +205,7 @@ invoke QT's meta-object compiler (moc) for the NotificationSender class, which we do first: \code -moc-qt4 `pkg-config --cflags QtCore QtNetwork` \ - -o moc_NotificationSender.cc \ - NotificationSender.hpp +moc-qt4 `pkg-config --cflags QtCore QtNetwork` -o moc_NotificationSender.cc NotificationSender.hpp \endcode This compiles the header NotificationSender.hpp into the file @@ -222,9 +220,7 @@ Finally we compile the simpleagent.cpp and link it against the generated object file: \code -g++ simpleagent.cpp -o simpleagent moc_NotificationSender.o \ - `pkg-config --cflags --libs QtNetwork QtCore` \ - -lagentxcpp +g++ simpleagent.cpp -o simpleagent moc_NotificationSender.o `pkg-config --cflags --libs QtNetwork QtCore` -lagentxcpp \endcode Now, the executable is ready to run. diff --git a/doc/how_to_write_a_subagent.dox b/doc/how_to_write_a_subagent.dox index 4fd71b0..75848d2 100644 --- a/doc/how_to_write_a_subagent.dox +++ b/doc/how_to_write_a_subagent.dox @@ -175,7 +175,7 @@ chosen, but it cannot be changed once the \ref agentxcpp::MasterProxy Now, as we have the \ref agentxcpp::MasterProxy "MasterProxy" object, we register a subtree. This means that we provide an OID to the master to indicate that our subagent wishes to serve all requests to OIDs starting with -that OID. For our subagent we use "enterprises.42.1", where 'enterprises' is +that OID. For our subagent we use "enterprises.42", where 'enterprises' is the standard OID "1.3.6.1.4.1". The master will then send all SNMP requests within that subtree to our subagent (e.g. "enterprises.42.1.0" or "enterprises.42.1.1.2.0"), regardless of whether the subagent actually can @@ -187,7 +187,7 @@ that. Here is the code for subtree registration: \code - Oid simpleagentOid = Oid(enterprises_oid, "42.1"); + Oid simpleagentOid = Oid(enterprises_oid, "42"); master.register_subtree(simpleagentOid); \endcode @@ -199,7 +199,7 @@ Next, we create a SimpleCounter variable and register it with the master: \code QSharedPointer counter(new SimpleCounter); - Oid simpleCounterOid = simpleagentOid + 0; + Oid simpleCounterOid = simpleagentOid + 1 + 0; master.add_variable(simpleCounterOid, counter); \endcode @@ -227,8 +227,7 @@ and, against the agentXcpp library. On a GNU/Linux system, you can type the following command: \code -g++ simpleagent.cpp -o simpleagent -lagentxcpp \ - `pkg-config --cflags --libs QtNetwork QtCore` +g++ simpleagent.cpp -o simpleagent -lagentxcpp `pkg-config --cflags --libs QtNetwork QtCore` \endcode This assumes that the agentxcpp library is installed properly, so that the From 43938e7cae1d990081b992ebeb98fa09ba89c2bf Mon Sep 17 00:00:00 2001 From: "Tanjeff-N. Moos" Date: Thu, 24 Apr 2014 00:53:27 +0200 Subject: [PATCH 48/89] Finish table tutorial. --- doc/how_to_implement_tables.dox | 129 ++++++++++++++++++++++---------- 1 file changed, 88 insertions(+), 41 deletions(-) diff --git a/doc/how_to_implement_tables.dox b/doc/how_to_implement_tables.dox index 8f9e05b..2a79427 100644 --- a/doc/how_to_implement_tables.dox +++ b/doc/how_to_implement_tables.dox @@ -26,8 +26,8 @@ So far we learned how to implement single variables and how to send notifications. This tutorial teaches us how an SNMP table can be implemented. -Again, we start with what we did in the previous tutorials, and add a simple -table to the SIMPLE-MIB: +We start with the code from the previous tutorials and add a table to the +SIMPLE-MIB: \verbatim SIMPLE-MIB DEFINITIONS ::= BEGIN @@ -112,10 +112,10 @@ table starts empty and each time the counter changes (i.e. by an SNMP GET or SET request), an entry is added. Each entry within the table has a timestamp, which consists of the epoch time -and a milliseconds component. This is to show how multiple variables can be -used to form the table's index. In addition, the time is reported in an -human-readable format (e.g. "2011-09-11, 12:00:52.77"). Finally, each entry -reports the new counter value. +and a milliseconds component, which is used as index of the entry. This is to +show how multiple variables can be used to form the table's index. In addition, +the time is reported in an human-readable format (e.g. "2011-09-11, +12:00:52.77"). Finally, each entry reports the new counter value. \section how_tables_work How tables work in agentXcpp @@ -126,35 +126,36 @@ variables are assembled like this: ... -The is the OID given to the table. The counterChangeTable for -example has the OID enterprises.42.2, which is .1.3.6.1.4.1.42.2. +The is the OID given to the table. The counterChangeTable has the +OID enterprises.42.2, which is .1.3.6.1.4.1.42.2. The is a single number assigned to the table entry. The -CounterChangeEntry for example has the 1. +CounterChangeEntry has the OID counterChangeTable.1, which means that + is 1. The is a single number which can be thought to be the column -of a specific variable. The counterChangeEpoch has =1, while -counterChangeTimeString has =3. +of a specific variable. The counterChangeEpoch has 1, while +counterChangeTimeString has 3. The is the concatenation of the index variables (counterChangeEpoch and counterChangeMilliseconds), converted to OID. For example, if -counterChangeEpoch is 123456789 and counterChangeMilliseconds is 512, the index -would be "123456789.512". The index can be thought of as the identifier of the -row in which the entry resides. In terms of a relational database it would be -called the primary key of the record. +counterChangeEpoch was 123456789 and counterChangeMilliseconds was 512, the +index would be "123456789.512". The index can be thought of as the identifier +of the row in which the entry resides. In terms of a relational database it +would be called the primary key of the record. Thus, the full OID of the counterChangeTimeString in the entry 123456789.512, for example, would be ".1.3.6.1.4.1.42.2.1.3.123456789.512". A table is implemented by creating a \agentxcpp{Table} object and tell it its (enterprises.42.2). An entry is implemented by subclassing -\agentxcpp{TableEntry}. For our table, we will implement the -CounterChangeEntry class which contains the four variables counterChangeEpoch, +\agentxcpp{TableEntry}, which initializes its subid to (i.e. 1 for +counterChangeEntry). For our table, we will implement the CounterChangeEntry +class which contains the four variables counterChangeEpoch, counterChangeMilliseconds, counterChangeTimeString and counterChangeCounterValue. The CounterChangeEntry class must implement the \agentxcpp{TableEntry::indexVariables()} and -\agentxcpp{TableEntry::variables()} methods, and is must ensure that -is set correctly. +\agentxcpp{TableEntry::variables()} methods. Each time an entry is added, the table will query the new entry for all its variables and add these to the MasterProxy object, so that they are @@ -220,34 +221,36 @@ class CounterChangeEntry : public TableEntry The class inherits \agentxcpp{TableEntry}. It has four members which represent the four SNMP variables. Since in agentXcpp those variables are handled as -QSharedPointer's, the constructor needs to create all of them using the new -operator. +QSharedPointer's, the constructor needs to create all of them using the +new operator. The constructor also sets \agentxcpp{TableEntry::subid} +to 1. -Each entry within a table needs a unique index, which becomes a part of the OID -of its variables. The index is built up by the index variables. Our MIB states -that counterChangeEpoch and counterChangeMilliseconds are used as index. The -CounterChangeEntry::indexVariables() method implements this by returning these -variables in a QVector, in the order in which they are used in the index. Note -that the entry's OID changes if the index variables change their value. Our -simpleagent will not change and entry after it was added to the table, though. +Our MIB states that counterChangeEpoch and counterChangeMilliseconds are used +as index. The CounterChangeEntry::indexVariables() method implements this by +returning these variables in a QVector, in the order in which they are used in +the index. Note that the entry's OID changes if the index variables change +their value. Our simpleagent will not change an entry after it was added to +the table, though. The CounterChangeEntry::variables() method return all variables as a QMap. The -map key will be used by the table as part for the variable -stored as value. +map key will be used by the table as part for the variable. \section extending_simplecounter Extending the SimpleCounter class. + +Next, we extent the SimpleCounter class so that it adds an entry to the table +each time the counter is changed. First of all, we need additional includes: + \code #include #include "CounterChangeEntry.hpp" #include \endcode -Next, we extent the SimpleCounter class so that it adds an entry to the table -each time the counter is changed. One thing to do is to add a \agentxcpp{Table} -member, a member to store the entry just inserted into the table (needed for -undoset(), a suitable constructor and the helper function addEntry(): +One thing to do is to add a \agentxcpp{Table} member, a member to store the +entry just inserted into the table (needed for undoset(), a suitable +constructor and the helper function addEntry(): \code private: @@ -276,8 +279,9 @@ undoset(), a suitable constructor and the helper function addEntry(): } \endcode -And we have to extend the get(), commitset() and undoset() functions, which now -look like this: +Next we have to replace the get(), commitset() and undoset() functions with +variants adding and removing an entries to/from the table. Here is how they +look like now: \code virtual void get() @@ -314,7 +318,9 @@ look like this: } \endcode -And finally we update the main() function as follows: +And finally we update the main() function, where a table is instantiated and +given to the SimpleCounter constructor. Here is the complete main() +function: \code int main(int argc, char** argv) @@ -326,12 +332,14 @@ int main(int argc, char** argv) Oid simpleagentOid = Oid(enterprises_oid, "42"); master.register_subtree(simpleagentOid); + // NEW: Instantiate a table: Table table(simpleagentOid + 2, &master); + // CHANGED: provide table when creating the counter: QSharedPointer counter(new SimpleCounter(&table)); Oid simpleCounterOid = simpleagentOid + 1 + 0; master.add_variable(simpleCounterOid, counter); - // New code for sending notifications --------------- + // Code for sending notifications --------------- NotificationSender sender(&master, simpleCounterOid, counter); QTimer timer; QObject::connect(&timer, SIGNAL(timeout()), @@ -344,11 +352,14 @@ int main(int argc, char** argv) } \endcode +And that's all we need for our table. Next, let's try it out. \section compiling_notification Compiling the Subagent -OLD: +We didn't add implementation files in this tutorial, so no additional steps are +needed for compiling. However, we have to recompile the the whole thing. We +know the following commands already from the previous tutorials: \code moc-qt4 `pkg-config --cflags QtCore QtNetwork` -o moc_NotificationSender.cc NotificationSender.hpp @@ -358,8 +369,6 @@ moc-qt4 `pkg-config --cflags QtCore QtNetwork` -o moc_NotificationSender.cc Noti g++ -c moc_NotificationSender.cc `pkg-config --cflags QtCore QtNetwork` \endcode -NEEDED: - \code g++ simpleagent.cpp -o simpleagent moc_NotificationSender.o `pkg-config --cflags --libs QtNetwork QtCore` -lagentxcpp \endcode @@ -367,6 +376,44 @@ g++ simpleagent.cpp -o simpleagent moc_NotificationSender.o `pkg-config --cflags Now, the executable is ready to run. +\section running Running the subagent + +The subagent is run like descibed in the previous tutorials, simply by executing it: + +\code +./simpleagent +\endcode + +Now, let's add some entries to the table by querying the simpleCounter variable: + +\code +snmpget -v1 -c rw localhost SIMPLE-MIB::simpleCounter.0 +\endcode + +\code +snmpset -v1 -c rw localhost SIMPLE-MIB::simpleCounter.0 i 23 +\endcode + +And finally we print the table using the snmptable command from the NET-SNMP +package, which requires that the MIB is installed properly: + +\code +snmptable -v2c -c rw localhost SIMPLE-MIB::counterChangeTable +\endcode + +If the MIB is not properly installed, or in case of programming errors, the +snmptable command might return nothing. The snmpwalk command can help out in +those cases, because it prints the complete subtree of a given OID, regardless +whether it is a table or not: + +\code +snmpwalk -v2c -c rw -On localhost 1.3.6.1.4.1.42.2 +\endcode + +Now you know all you need to implement your own SNMP subagents. Use the API +documentation to get more help on the individual classes. + +Happy Hacking! */ From e54d0b54d1bca5e92f50716a9f4af1ee681c7ed5 Mon Sep 17 00:00:00 2001 From: "Tanjeff-N. Moos" Date: Fri, 25 Apr 2014 00:39:25 +0200 Subject: [PATCH 49/89] Update documentation. --- doc/how_to_add_rw_support.dox | 2 +- doc/how_to_implement_tables.dox | 22 +++++++++++----------- src/AbstractVariable.hpp | 8 ++++---- src/Counter32Variable.hpp | 10 +++++----- src/Counter64Variable.hpp | 10 +++++----- src/Gauge32Variable.hpp | 10 +++++----- src/IntegerVariable.hpp | 14 +++++++------- src/IpAddressVariable.hpp | 10 +++++----- src/OctetStringVariable.hpp | 16 +++++++++------- src/OidVariable.hpp | 14 ++++++++++---- src/OpaqueVariable.hpp | 24 +++++++++++++++++++----- src/TimeTicksVariable.hpp | 26 ++++++++++++++++++++------ 12 files changed, 101 insertions(+), 65 deletions(-) diff --git a/doc/how_to_add_rw_support.dox b/doc/how_to_add_rw_support.dox index f35b901..8bb0e12 100644 --- a/doc/how_to_add_rw_support.dox +++ b/doc/how_to_add_rw_support.dox @@ -130,7 +130,7 @@ SimpleCounter class by adding the following code to it: } \endcode -The \ref agentxcpp::Variable::testset "testset()" method receives the +The \ref agentxcpp::IntegerVariable::testset "testset()" method receives the value and can check whether setting the variable to this value would work. Here, we don't check the value, but we allocate an quint32 to store the old value, which is needed for undoset(). If allocation fails, we return the error diff --git a/doc/how_to_implement_tables.dox b/doc/how_to_implement_tables.dox index 2a79427..1e01502 100644 --- a/doc/how_to_implement_tables.dox +++ b/doc/how_to_implement_tables.dox @@ -124,20 +124,20 @@ Technically, our SNMP table is a sequence of counterChangeEntry, which in turn is a structure containing four "real" SNMP variables. The OID of these variables are assembled like this: - ... + ... -The is the OID given to the table. The counterChangeTable has the +The is the OID given to the table. The counterChangeTable has the OID enterprises.42.2, which is .1.3.6.1.4.1.42.2. -The is a single number assigned to the table entry. The +The is a single number assigned to the table entry. The CounterChangeEntry has the OID counterChangeTable.1, which means that - is 1. + is 1. -The is a single number which can be thought to be the column -of a specific variable. The counterChangeEpoch has 1, while -counterChangeTimeString has 3. +The is a single number which can be thought to be the column +of a specific variable. The counterChangeEpoch has 1, while +counterChangeTimeString has 3. -The is the concatenation of the index variables (counterChangeEpoch +The is the concatenation of the index variables (counterChangeEpoch and counterChangeMilliseconds), converted to OID. For example, if counterChangeEpoch was 123456789 and counterChangeMilliseconds was 512, the index would be "123456789.512". The index can be thought of as the identifier @@ -148,8 +148,8 @@ Thus, the full OID of the counterChangeTimeString in the entry 123456789.512, for example, would be ".1.3.6.1.4.1.42.2.1.3.123456789.512". A table is implemented by creating a \agentxcpp{Table} object and tell it its - (enterprises.42.2). An entry is implemented by subclassing -\agentxcpp{TableEntry}, which initializes its subid to (i.e. 1 for + (enterprises.42.2). An entry is implemented by subclassing +\agentxcpp{TableEntry}, which initializes its subid to (i.e. 1 for counterChangeEntry). For our table, we will implement the CounterChangeEntry class which contains the four variables counterChangeEpoch, counterChangeMilliseconds, counterChangeTimeString and @@ -233,7 +233,7 @@ their value. Our simpleagent will not change an entry after it was added to the table, though. The CounterChangeEntry::variables() method return all variables as a QMap. The -map key will be used by the table as part for the variable. +map key will be used by the table as <variableSubOid> part for the variable. \section extending_simplecounter Extending the SimpleCounter class. diff --git a/src/AbstractVariable.hpp b/src/AbstractVariable.hpp index be497fd..47b7d8c 100644 --- a/src/AbstractVariable.hpp +++ b/src/AbstractVariable.hpp @@ -169,7 +169,7 @@ namespace agentxcpp * * \return The result of the validation. * - * \exception None: The function shall not throw. + * \exception The function shall not throw. */ virtual testset_result_t handle_testset(QSharedPointer) = 0; @@ -181,7 +181,7 @@ namespace agentxcpp * by handle_testset() (if any). If no resources were allocated, * this method is not required to do anything. * - * \exception None: The function shall not throw. + * \exception The function shall not throw. */ virtual void handle_cleanupset() = 0; @@ -198,7 +198,7 @@ namespace agentxcpp * * \return True on success, false otherwise. * - * \exception None: The function shall not throw. + * \exception The function shall not throw. */ virtual bool handle_commitset()= 0; @@ -211,7 +211,7 @@ namespace agentxcpp * * \return True on success, false otherwise. * - * \exception None: The function shall not throw. + * \exception The function shall not throw. */ virtual bool handle_undoset() = 0; diff --git a/src/Counter32Variable.hpp b/src/Counter32Variable.hpp index 1cc58c7..4fc3630 100644 --- a/src/Counter32Variable.hpp +++ b/src/Counter32Variable.hpp @@ -128,7 +128,7 @@ namespace agentxcpp * testset() is not called. This function also stores the given * value to the new_value member. * - * \param v The new value for the variable. + * \param _v The new value for the variable. * * \return agentxcpp::AbstractVariable::wrongType if the conversion * fails. Otherwise, @@ -166,7 +166,7 @@ namespace agentxcpp * this is a read-only variable. Thus, for read-only variables this * method need not be overridden. * - * \param v The new value for the object. + * \param _v The new value for the object. * * \return The result of the check. */ @@ -199,7 +199,7 @@ namespace agentxcpp * required to perform the CleanupSet operaiton, this method need * not be overridden. * - * \param v The new value for the object. + * \param _v The new value for the object. */ virtual void cleanupset(QSharedPointer _v) { @@ -230,7 +230,7 @@ namespace agentxcpp * operation failed. To implement a writable SNMP variable this * method must be overridden. * - * \param v The new value for the object. + * \param _v The new value for the object. * * \return True if the operation succeeded, false otherwise. */ @@ -272,7 +272,7 @@ namespace agentxcpp * * \endinternal * - * \param v The new value for the object. + * \param _v The new value for the object. * * \return True on success, false otherwise. */ diff --git a/src/Counter64Variable.hpp b/src/Counter64Variable.hpp index d3cf9d4..f9e62d3 100644 --- a/src/Counter64Variable.hpp +++ b/src/Counter64Variable.hpp @@ -128,7 +128,7 @@ namespace agentxcpp * testset() is not called. This function also stores the given * value to the new_value member. * - * \param v The new value for the variable. + * \param _v The new value for the variable. * * \return agentxcpp::AbstractVariable::wrongType if the conversion * fails. Otherwise, @@ -166,7 +166,7 @@ namespace agentxcpp * this is a read-only variable. Thus, for read-only variables this * method need not be overridden. * - * \param v The new value for the object. + * \param _v The new value for the object. * * \return The result of the check. */ @@ -199,7 +199,7 @@ namespace agentxcpp * required to perform the CleanupSet operaiton, this method need * not be overridden. * - * \param v The new value for the object. + * \param _v The new value for the object. */ virtual void cleanupset(QSharedPointer _v) { @@ -230,7 +230,7 @@ namespace agentxcpp * operation failed. To implement a writable SNMP variable this * method must be overridden. * - * \param v The new value for the object. + * \param _v The new value for the object. * * \return True if the operation succeeded, false otherwise. */ @@ -272,7 +272,7 @@ namespace agentxcpp * * \endinternal * - * \param v The new value for the object. + * \param _v The new value for the object. * * \return True on success, false otherwise. */ diff --git a/src/Gauge32Variable.hpp b/src/Gauge32Variable.hpp index faec1d6..a76ee89 100644 --- a/src/Gauge32Variable.hpp +++ b/src/Gauge32Variable.hpp @@ -157,7 +157,7 @@ namespace agentxcpp * testset() is not called. This function also stores the given * value to the new_value member. * - * \param v The new value for the variable. + * \param _v The new value for the variable. * * \return agentxcpp::AbstractVariable::wrongType if the conversion * fails. Otherwise, @@ -195,7 +195,7 @@ namespace agentxcpp * this is a read-only variable. Thus, for read-only variables this * method need not be overridden. * - * \param v The new value for the object. + * \param _v The new value for the object. * * \return The result of the check. */ @@ -228,7 +228,7 @@ namespace agentxcpp * required to perform the CleanupSet operaiton, this method need * not be overridden. * - * \param v The new value for the object. + * \param _v The new value for the object. */ virtual void cleanupset(QSharedPointer _v) { @@ -259,7 +259,7 @@ namespace agentxcpp * operation failed. To implement a writable SNMP variable this * method must be overridden. * - * \param v The new value for the object. + * \param _v The new value for the object. * * \return True if the operation succeeded, false otherwise. */ @@ -301,7 +301,7 @@ namespace agentxcpp * * \endinternal * - * \param v The new value for the object. + * \param _v The new value for the object. * * \return True on success, false otherwise. */ diff --git a/src/IntegerVariable.hpp b/src/IntegerVariable.hpp index 12a9ba6..6e4cd92 100644 --- a/src/IntegerVariable.hpp +++ b/src/IntegerVariable.hpp @@ -29,7 +29,7 @@ namespace agentxcpp { /** - * \brief Represents an Integer as described in RFC 2741 + * \brief Represents an Integer as described in RFC 2741. */ class IntegerVariable : public AbstractVariable { @@ -110,7 +110,7 @@ namespace agentxcpp * 7.7. "Mapping of the INDEX clause". The value is * converted to an Oid with a single subid. Note that * INTEGER values are signed, while subids are not. - * A negative value with be converted to big unsigned + * A negative value with be converted to a big unsigned * subid. * * \note If an INTEGER is used in an INDEX clause, the @@ -176,7 +176,7 @@ namespace agentxcpp * testset() is not called. This function also stores the given * value to the new_value member. * - * \param v The new value for the variable. + * \param _v The new value for the variable. * * \return agentxcpp::AbstractVariable::wrongType if the conversion * fails. Otherwise, @@ -214,7 +214,7 @@ namespace agentxcpp * this is a read-only variable. Thus, for read-only variables this * method need not be overridden. * - * \param v The new value for the object. + * \param _v The new value for the object. * * \return The result of the check. */ @@ -247,7 +247,7 @@ namespace agentxcpp * required to perform the CleanupSet operaiton, this method need * not be overridden. * - * \param v The new value for the object. + * \param _v The new value for the object. */ virtual void cleanupset(QSharedPointer _v) { @@ -278,7 +278,7 @@ namespace agentxcpp * operation failed. To implement a writable SNMP variable this * method must be overridden. * - * \param v The new value for the object. + * \param _v The new value for the object. * * \return True if the operation succeeded, false otherwise. */ @@ -320,7 +320,7 @@ namespace agentxcpp * * \endinternal * - * \param v The new value for the object. + * \param _v The new value for the object. * * \return True on success, false otherwise. */ diff --git a/src/IpAddressVariable.hpp b/src/IpAddressVariable.hpp index a63f8c6..4b6d1a4 100644 --- a/src/IpAddressVariable.hpp +++ b/src/IpAddressVariable.hpp @@ -216,7 +216,7 @@ namespace agentxcpp * testset() is not called. This function also stores the given * value to the new_value member. * - * \param v The new value for the variable. + * \param _v The new value for the variable. * * \return agentxcpp::AbstractVariable::wrongType if the conversion * fails. Otherwise, @@ -254,7 +254,7 @@ namespace agentxcpp * this is a read-only variable. Thus, for read-only variables this * method need not be overridden. * - * \param v The new value for the object. + * \param _v The new value for the object. * * \return The result of the check. */ @@ -287,7 +287,7 @@ namespace agentxcpp * required to perform the CleanupSet operaiton, this method need * not be overridden. * - * \param v The new value for the object. + * \param _v The new value for the object. */ virtual void cleanupset(QSharedPointer _v) { @@ -318,7 +318,7 @@ namespace agentxcpp * operation failed. To implement a writable SNMP variable this * method must be overridden. * - * \param v The new value for the object. + * \param _v The new value for the object. * * \return True if the operation succeeded, false otherwise. */ @@ -360,7 +360,7 @@ namespace agentxcpp * * \endinternal * - * \param v The new value for the object. + * \param _v The new value for the object. * * \return True on success, false otherwise. */ diff --git a/src/OctetStringVariable.hpp b/src/OctetStringVariable.hpp index 55eb3e0..b0c66b5 100644 --- a/src/OctetStringVariable.hpp +++ b/src/OctetStringVariable.hpp @@ -7,13 +7,15 @@ namespace agentxcpp { - + /** + * \brief Represents an OctetSting as described in RFC 2741. + */ class OctetStringVariable : public AbstractVariable { protected: /** - * \brief The string. + * \brief The value. * * According to RFC 2578, Octet_String represents arbitrary binary * or textual data. @@ -154,7 +156,7 @@ namespace agentxcpp * testset() is not called. This function also stores the given * value to the new_value member. * - * \param v The new value for the variable. + * \param _v The new value for the variable. * * \return agentxcpp::AbstractVariable::wrongType if the conversion * fails. Otherwise, @@ -192,7 +194,7 @@ namespace agentxcpp * this is a read-only variable. Thus, for read-only variables this * method need not be overridden. * - * \param v The new value for the object. + * \param _v The new value for the object. * * \return The result of the check. */ @@ -225,7 +227,7 @@ namespace agentxcpp * required to perform the CleanupSet operaiton, this method need * not be overridden. * - * \param v The new value for the object. + * \param _v The new value for the object. */ virtual void cleanupset(QSharedPointer _v) { @@ -256,7 +258,7 @@ namespace agentxcpp * operation failed. To implement a writable SNMP variable this * method must be overridden. * - * \param v The new value for the object. + * \param _v The new value for the object. * * \return True if the operation succeeded, false otherwise. */ @@ -298,7 +300,7 @@ namespace agentxcpp * * \endinternal * - * \param v The new value for the object. + * \param _v The new value for the object. * * \return True on success, false otherwise. */ diff --git a/src/OidVariable.hpp b/src/OidVariable.hpp index 14802ed..77ec238 100644 --- a/src/OidVariable.hpp +++ b/src/OidVariable.hpp @@ -31,6 +31,12 @@ namespace agentxcpp { /** * \brief Represents an SNMP OBJECT-IDENTENTIFIER variable. + * + * The agentXcpp library distinguishes between Oid and + * OidVariable types. An Oid is a sequence of numbers, + * while OidVariable is an SNMP variable representing an Oid. That + * means, that GET and SET requests are possible on OidVariable's, but + * not on Oid's. */ class OidVariable: public AbstractVariable { @@ -138,8 +144,8 @@ namespace agentxcpp * * The conversion is done according to RFC 2578, * 7.7. "Mapping of the INDEX clause". First, the - * length is converted to a subid. Then, each - * subid of the value is appended. + * length of the OID (i.e. the number of subid's it has) is + * converted to a subid. Then, each subid of the value is appended. * * \todo Support fixed-length OIDs according to RFC 2578, * 7.7. "Mapping of the INDEX clause". @@ -210,7 +216,7 @@ namespace agentxcpp * testset() is not called. This function also stores the given * value to the new_value member. * - * \param v The new value for the variable. + * \param _v The new value for the variable. * * \return agentxcpp::AbstractVariable::wrongType if the conversion * fails. Otherwise, @@ -248,7 +254,7 @@ namespace agentxcpp * this is a read-only variable. Thus, for read-only variables this * method need not be overridden. * - * \param v The new value for the object. + * \param _v The new value for the object. * * \return The result of the check. */ diff --git a/src/OpaqueVariable.hpp b/src/OpaqueVariable.hpp index cadbc77..bb2c1d8 100644 --- a/src/OpaqueVariable.hpp +++ b/src/OpaqueVariable.hpp @@ -109,11 +109,25 @@ namespace agentxcpp { } + /* + * \brief Set the value. + * + * \param _v The new value. + * + * \exception None. + */ void setValue(binary _v) { v = _v; } + /* + * \brief Get the value. + * + * \return The current value. + * + * \exception None. + */ binary value() { return v; @@ -161,7 +175,7 @@ namespace agentxcpp * testset() is not called. This function also stores the given * value to the new_value member. * - * \param v The new value for the variable. + * \param _v The new value for the variable. * * \return agentxcpp::AbstractVariable::wrongType if the conversion * fails. Otherwise, @@ -199,7 +213,7 @@ namespace agentxcpp * this is a read-only variable. Thus, for read-only variables this * method need not be overridden. * - * \param v The new value for the object. + * \param _v The new value for the object. * * \return The result of the check. */ @@ -232,7 +246,7 @@ namespace agentxcpp * required to perform the CleanupSet operaiton, this method need * not be overridden. * - * \param v The new value for the object. + * \param _v The new value for the object. */ virtual void cleanupset(QSharedPointer _v) { @@ -263,7 +277,7 @@ namespace agentxcpp * operation failed. To implement a writable SNMP variable this * method must be overridden. * - * \param v The new value for the object. + * \param _v The new value for the object. * * \return True if the operation succeeded, false otherwise. */ @@ -305,7 +319,7 @@ namespace agentxcpp * * \endinternal * - * \param v The new value for the object. + * \param _v The new value for the object. * * \return True on success, false otherwise. */ diff --git a/src/TimeTicksVariable.hpp b/src/TimeTicksVariable.hpp index bc32b80..b1a854c 100644 --- a/src/TimeTicksVariable.hpp +++ b/src/TimeTicksVariable.hpp @@ -102,11 +102,25 @@ namespace agentxcpp */ virtual binary serialize() const; + /* + * \brief Set the value. + * + * \param _v The new value. + * + * \exception None. + */ void setValue(quint32 _v) { v = _v; } + /* + * \brief get the value. + * + * \return The current value. + * + * \exception None. + */ quint32 value() { return v; @@ -154,7 +168,7 @@ namespace agentxcpp * testset() is not called. This function also stores the given * value to the new_value member. * - * \param v The new value for the variable. + * \param _v The new value for the variable. * * \return agentxcpp::AbstractVariable::wrongType if the conversion * fails. Otherwise, @@ -196,7 +210,7 @@ namespace agentxcpp * * \return The result of the check. */ - virtual testset_result_t testset(QSharedPointer _v) + virtual testset_result_t testset(QSharedPointer v) { return noAccess; } @@ -207,7 +221,7 @@ namespace agentxcpp * \brief Handle a CleanupSet request. * * This function calls cleanupset() with the value from the last - * handle_testset() invokation. + * handle_testset() invocation. */ virtual void handle_cleanupset() { @@ -225,7 +239,7 @@ namespace agentxcpp * required to perform the CleanupSet operaiton, this method need * not be overridden. * - * \param v The new value for the object. + * \param _v The new value for the object. */ virtual void cleanupset(QSharedPointer _v) { @@ -256,7 +270,7 @@ namespace agentxcpp * operation failed. To implement a writable SNMP variable this * method must be overridden. * - * \param v The new value for the object. + * \param _v The new value for the object. * * \return True if the operation succeeded, false otherwise. */ @@ -302,7 +316,7 @@ namespace agentxcpp * * \return True on success, false otherwise. */ - virtual bool undoset(QSharedPointer _v) + virtual bool undoset(QSharedPointer v) { return false; } From b07d692929bc1542913eda2d3477dbcd0e424b19 Mon Sep 17 00:00:00 2001 From: "Tanjeff-N. Moos" Date: Sun, 15 Nov 2015 22:47:04 +0100 Subject: [PATCH 50/89] Oid::operator=() now copies mInclude. --- src/Oid.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Oid.cpp b/src/Oid.cpp index d313d86..91bafe9 100644 --- a/src/Oid.cpp +++ b/src/Oid.cpp @@ -203,6 +203,8 @@ Oid& Oid::operator=(const Oid& other) // copy inherited stuff QVector::operator=(other); + mInclude = other.mInclude; + // Return reference to us return *this; } From c3b13c610f44951ac99f0d7938f408eea36c03ec Mon Sep 17 00:00:00 2001 From: "Tanjeff-N. Moos" Date: Tue, 17 Nov 2015 08:23:15 +0100 Subject: [PATCH 51/89] Add Table::contains(). --- src/IntegerVariable.hpp | 2 +- src/Table.cpp | 5 +++++ src/Table.hpp | 11 +++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/IntegerVariable.hpp b/src/IntegerVariable.hpp index 6e4cd92..13d7baa 100644 --- a/src/IntegerVariable.hpp +++ b/src/IntegerVariable.hpp @@ -244,7 +244,7 @@ namespace agentxcpp * shall release any ressources allocated by testset(). * * The default implementation does nothing. If no action is - * required to perform the CleanupSet operaiton, this method need + * required to perform the CleanupSet operation, this method need * not be overridden. * * \param _v The new value for the object. diff --git a/src/Table.cpp b/src/Table.cpp index 47eef1a..6d6fd96 100644 --- a/src/Table.cpp +++ b/src/Table.cpp @@ -21,6 +21,11 @@ using namespace agentxcpp; +bool Table::contains(QSharedPointer entry) const +{ + return entries.contains(entry); +} + bool Table::addEntry(QSharedPointer entry) { // Check for MasterProxy object diff --git a/src/Table.hpp b/src/Table.hpp index 4c4f629..9f972d3 100644 --- a/src/Table.hpp +++ b/src/Table.hpp @@ -175,6 +175,17 @@ class Table */ bool addEntry(QSharedPointer entry); + /** + * \brief Check whether the table contains a given entry. + * + * \param entry The entry to search for. + * + * \return True if the table contains the entry, false otherwise. + * + * \exception None. + */ + bool contains(QSharedPointer entry) const; + /** * \brief Remove an entry from the table. * From 49adc5f59bf97dd82dfa907b985de28573d929ed Mon Sep 17 00:00:00 2001 From: "Tanjeff-N. Moos" Date: Thu, 19 Nov 2015 23:39:49 +0100 Subject: [PATCH 52/89] The SET functions take bare values. Instead of taking pointers to Variable types (e.g. QSharedPointer), the bare value is taken (e.g. qint32). --- src/Counter32Variable.hpp | 16 ++++++++-------- src/Counter64Variable.hpp | 16 ++++++++-------- src/Gauge32Variable.hpp | 16 ++++++++-------- src/IntegerVariable.hpp | 16 ++++++++-------- src/IpAddressVariable.hpp | 16 ++++++++-------- src/OctetStringVariable.cpp | 2 +- src/OctetStringVariable.hpp | 16 ++++++++-------- src/OidVariable.hpp | 16 ++++++++-------- src/OpaqueVariable.hpp | 16 ++++++++-------- src/TimeTicksVariable.hpp | 16 ++++++++-------- 10 files changed, 73 insertions(+), 73 deletions(-) diff --git a/src/Counter32Variable.hpp b/src/Counter32Variable.hpp index 4fc3630..9cc6e20 100644 --- a/src/Counter32Variable.hpp +++ b/src/Counter32Variable.hpp @@ -142,7 +142,7 @@ namespace agentxcpp if (new_value) { // Type matches variable - return testset(new_value); + return testset(new_value->value()); } else { @@ -170,7 +170,7 @@ namespace agentxcpp * * \return The result of the check. */ - virtual testset_result_t testset(QSharedPointer _v) + virtual testset_result_t testset(quint32 _v) { return noAccess; } @@ -185,7 +185,7 @@ namespace agentxcpp */ virtual void handle_cleanupset() { - cleanupset(new_value); + cleanupset(new_value->value()); } /** @@ -201,7 +201,7 @@ namespace agentxcpp * * \param _v The new value for the object. */ - virtual void cleanupset(QSharedPointer _v) + virtual void cleanupset(quint32 _v) { return; } @@ -216,7 +216,7 @@ namespace agentxcpp */ virtual bool handle_commitset() { - return commitset(new_value); + return commitset(new_value->value()); } /** @@ -234,7 +234,7 @@ namespace agentxcpp * * \return True if the operation succeeded, false otherwise. */ - virtual bool commitset(QSharedPointer _v) + virtual bool commitset(quint32 _v) { return false; } @@ -250,7 +250,7 @@ namespace agentxcpp */ virtual bool handle_undoset() { - return undoset(new_value); + return undoset(new_value->value()); } /** @@ -276,7 +276,7 @@ namespace agentxcpp * * \return True on success, false otherwise. */ - virtual bool undoset(QSharedPointer _v) + virtual bool undoset(quint32 _v) { return false; } diff --git a/src/Counter64Variable.hpp b/src/Counter64Variable.hpp index f9e62d3..f27eb36 100644 --- a/src/Counter64Variable.hpp +++ b/src/Counter64Variable.hpp @@ -142,7 +142,7 @@ namespace agentxcpp if (new_value) { // Type matches variable - return testset(new_value); + return testset(new_value->value()); } else { @@ -170,7 +170,7 @@ namespace agentxcpp * * \return The result of the check. */ - virtual testset_result_t testset(QSharedPointer _v) + virtual testset_result_t testset(quint64 _v) { return noAccess; } @@ -185,7 +185,7 @@ namespace agentxcpp */ virtual void handle_cleanupset() { - cleanupset(new_value); + cleanupset(new_value->value()); } /** @@ -201,7 +201,7 @@ namespace agentxcpp * * \param _v The new value for the object. */ - virtual void cleanupset(QSharedPointer _v) + virtual void cleanupset(quint64 _v) { return; } @@ -216,7 +216,7 @@ namespace agentxcpp */ virtual bool handle_commitset() { - return commitset(new_value); + return commitset(new_value->value()); } /** @@ -234,7 +234,7 @@ namespace agentxcpp * * \return True if the operation succeeded, false otherwise. */ - virtual bool commitset(QSharedPointer _v) + virtual bool commitset(quint64 _v) { return false; } @@ -250,7 +250,7 @@ namespace agentxcpp */ virtual bool handle_undoset() { - return undoset(new_value); + return undoset(new_value->value()); } /** @@ -276,7 +276,7 @@ namespace agentxcpp * * \return True on success, false otherwise. */ - virtual bool undoset(QSharedPointer _v) + virtual bool undoset(quint64 _v) { return false; } diff --git a/src/Gauge32Variable.hpp b/src/Gauge32Variable.hpp index a76ee89..b5e6b35 100644 --- a/src/Gauge32Variable.hpp +++ b/src/Gauge32Variable.hpp @@ -171,7 +171,7 @@ namespace agentxcpp if (new_value) { // Type matches variable - return testset(new_value); + return testset(new_value->value()); } else { @@ -199,7 +199,7 @@ namespace agentxcpp * * \return The result of the check. */ - virtual testset_result_t testset(QSharedPointer _v) + virtual testset_result_t testset(quint32 _v) { return noAccess; } @@ -214,7 +214,7 @@ namespace agentxcpp */ virtual void handle_cleanupset() { - cleanupset(new_value); + cleanupset(new_value->value()); } /** @@ -230,7 +230,7 @@ namespace agentxcpp * * \param _v The new value for the object. */ - virtual void cleanupset(QSharedPointer _v) + virtual void cleanupset(quint32 _v) { return; } @@ -245,7 +245,7 @@ namespace agentxcpp */ virtual bool handle_commitset() { - return commitset(new_value); + return commitset(new_value->value()); } /** @@ -263,7 +263,7 @@ namespace agentxcpp * * \return True if the operation succeeded, false otherwise. */ - virtual bool commitset(QSharedPointer _v) + virtual bool commitset(quint32 _v) { return false; } @@ -279,7 +279,7 @@ namespace agentxcpp */ virtual bool handle_undoset() { - return undoset(new_value); + return undoset(new_value->value()); } /** @@ -305,7 +305,7 @@ namespace agentxcpp * * \return True on success, false otherwise. */ - virtual bool undoset(QSharedPointer _v) + virtual bool undoset(quint32 _v) { return false; } diff --git a/src/IntegerVariable.hpp b/src/IntegerVariable.hpp index 13d7baa..4997bad 100644 --- a/src/IntegerVariable.hpp +++ b/src/IntegerVariable.hpp @@ -190,7 +190,7 @@ namespace agentxcpp if (new_value) { // Type matches variable - return testset(new_value); + return testset(new_value->value()); } else { @@ -218,7 +218,7 @@ namespace agentxcpp * * \return The result of the check. */ - virtual testset_result_t testset(QSharedPointer _v) + virtual testset_result_t testset(qint32 _v) { return noAccess; } @@ -233,7 +233,7 @@ namespace agentxcpp */ virtual void handle_cleanupset() { - cleanupset(new_value); + cleanupset(new_value->value()); } /** @@ -249,7 +249,7 @@ namespace agentxcpp * * \param _v The new value for the object. */ - virtual void cleanupset(QSharedPointer _v) + virtual void cleanupset(qint32 _v) { return; } @@ -264,7 +264,7 @@ namespace agentxcpp */ virtual bool handle_commitset() { - return commitset(new_value); + return commitset(new_value->value()); } /** @@ -282,7 +282,7 @@ namespace agentxcpp * * \return True if the operation succeeded, false otherwise. */ - virtual bool commitset(QSharedPointer _v) + virtual bool commitset(qint32 _v) { return false; } @@ -298,7 +298,7 @@ namespace agentxcpp */ virtual bool handle_undoset() { - return undoset(new_value); + return undoset(new_value->value()); } /** @@ -324,7 +324,7 @@ namespace agentxcpp * * \return True on success, false otherwise. */ - virtual bool undoset(QSharedPointer _v) + virtual bool undoset(qint32 _v) { return false; } diff --git a/src/IpAddressVariable.hpp b/src/IpAddressVariable.hpp index 4b6d1a4..ecbfd0b 100644 --- a/src/IpAddressVariable.hpp +++ b/src/IpAddressVariable.hpp @@ -230,7 +230,7 @@ namespace agentxcpp if (new_value) { // Type matches variable - return testset(new_value); + return testset(new_value->address); } else { @@ -258,7 +258,7 @@ namespace agentxcpp * * \return The result of the check. */ - virtual testset_result_t testset(QSharedPointer _v) + virtual testset_result_t testset(const quint8 _v[4]) { return noAccess; } @@ -273,7 +273,7 @@ namespace agentxcpp */ virtual void handle_cleanupset() { - cleanupset(new_value); + cleanupset(new_value->address); } /** @@ -289,7 +289,7 @@ namespace agentxcpp * * \param _v The new value for the object. */ - virtual void cleanupset(QSharedPointer _v) + virtual void cleanupset(const quint8 _v[4]) { return; } @@ -304,7 +304,7 @@ namespace agentxcpp */ virtual bool handle_commitset() { - return commitset(new_value); + return commitset(new_value->address); } /** @@ -322,7 +322,7 @@ namespace agentxcpp * * \return True if the operation succeeded, false otherwise. */ - virtual bool commitset(QSharedPointer _v) + virtual bool commitset(const quint8 _v[4]) { return false; } @@ -338,7 +338,7 @@ namespace agentxcpp */ virtual bool handle_undoset() { - return undoset(new_value); + return undoset(new_value->address); } /** @@ -364,7 +364,7 @@ namespace agentxcpp * * \return True on success, false otherwise. */ - virtual bool undoset(QSharedPointer _v) + virtual bool undoset(const quint8 _v[4]) { return false; } diff --git a/src/OctetStringVariable.cpp b/src/OctetStringVariable.cpp index 5c46e46..248bec3 100644 --- a/src/OctetStringVariable.cpp +++ b/src/OctetStringVariable.cpp @@ -32,7 +32,7 @@ OctetStringVariable::OctetStringVariable(QString v) void OctetStringVariable::setValue(QString _value) { - // Here we convert initial value to a binary string. We do this in three + // Here we convert initial value to a binary string. We do this in four // steps: // 1. get the bare data: v.toStdString().data() // 2. cast the data to the value type of binary diff --git a/src/OctetStringVariable.hpp b/src/OctetStringVariable.hpp index b0c66b5..fd9fc8e 100644 --- a/src/OctetStringVariable.hpp +++ b/src/OctetStringVariable.hpp @@ -170,7 +170,7 @@ namespace agentxcpp if (new_value) { // Type matches variable - return testset(new_value); + return testset(new_value->value()); } else { @@ -198,7 +198,7 @@ namespace agentxcpp * * \return The result of the check. */ - virtual testset_result_t testset(QSharedPointer _v) + virtual testset_result_t testset(const binary& _v) { return noAccess; } @@ -213,7 +213,7 @@ namespace agentxcpp */ virtual void handle_cleanupset() { - cleanupset(new_value); + cleanupset(new_value->value()); } /** @@ -229,7 +229,7 @@ namespace agentxcpp * * \param _v The new value for the object. */ - virtual void cleanupset(QSharedPointer _v) + virtual void cleanupset(const binary& _v) { return; } @@ -244,7 +244,7 @@ namespace agentxcpp */ virtual bool handle_commitset() { - return commitset(new_value); + return commitset(new_value->value()); } /** @@ -262,7 +262,7 @@ namespace agentxcpp * * \return True if the operation succeeded, false otherwise. */ - virtual bool commitset(QSharedPointer _v) + virtual bool commitset(const binary& _v) { return false; } @@ -278,7 +278,7 @@ namespace agentxcpp */ virtual bool handle_undoset() { - return undoset(new_value); + return undoset(new_value->value()); } /** @@ -304,7 +304,7 @@ namespace agentxcpp * * \return True on success, false otherwise. */ - virtual bool undoset(QSharedPointer _v) + virtual bool undoset(const binary& _v) { return false; } diff --git a/src/OidVariable.hpp b/src/OidVariable.hpp index 77ec238..fcc0fe9 100644 --- a/src/OidVariable.hpp +++ b/src/OidVariable.hpp @@ -230,7 +230,7 @@ namespace agentxcpp if (new_value) { // Type matches variable - return testset(new_value); + return testset(new_value->value()); } else { @@ -258,7 +258,7 @@ namespace agentxcpp * * \return The result of the check. */ - virtual testset_result_t testset(QSharedPointer _v) + virtual testset_result_t testset(const Oid& _v) { return noAccess; } @@ -273,7 +273,7 @@ namespace agentxcpp */ virtual void handle_cleanupset() { - cleanupset(new_value); + cleanupset(new_value->value()); } /** @@ -289,7 +289,7 @@ namespace agentxcpp * * \param _v The new value for the object. */ - virtual void cleanupset(QSharedPointer _v) + virtual void cleanupset(const Oid& _v) { return; } @@ -304,7 +304,7 @@ namespace agentxcpp */ virtual bool handle_commitset() { - return commitset(new_value); + return commitset(new_value->value()); } /** @@ -322,7 +322,7 @@ namespace agentxcpp * * \return True if the operation succeeded, false otherwise. */ - virtual bool commitset(QSharedPointer _v) + virtual bool commitset(const Oid& _v) { return false; } @@ -338,7 +338,7 @@ namespace agentxcpp */ virtual bool handle_undoset() { - return undoset(new_value); + return undoset(new_value->value()); } /** @@ -364,7 +364,7 @@ namespace agentxcpp * * \return True on success, false otherwise. */ - virtual bool undoset(QSharedPointer _v) + virtual bool undoset(const Oid& _v) { return false; } diff --git a/src/OpaqueVariable.hpp b/src/OpaqueVariable.hpp index bb2c1d8..08a5b92 100644 --- a/src/OpaqueVariable.hpp +++ b/src/OpaqueVariable.hpp @@ -189,7 +189,7 @@ namespace agentxcpp if (new_value) { // Type matches variable - return testset(new_value); + return testset(new_value->value()); } else { @@ -217,7 +217,7 @@ namespace agentxcpp * * \return The result of the check. */ - virtual testset_result_t testset(QSharedPointer _v) + virtual testset_result_t testset(const binary& _v) { return noAccess; } @@ -232,7 +232,7 @@ namespace agentxcpp */ virtual void handle_cleanupset() { - cleanupset(new_value); + cleanupset(new_value->value()); } /** @@ -248,7 +248,7 @@ namespace agentxcpp * * \param _v The new value for the object. */ - virtual void cleanupset(QSharedPointer _v) + virtual void cleanupset(const binary& _v) { return; } @@ -263,7 +263,7 @@ namespace agentxcpp */ virtual bool handle_commitset() { - return commitset(new_value); + return commitset(new_value->value()); } /** @@ -281,7 +281,7 @@ namespace agentxcpp * * \return True if the operation succeeded, false otherwise. */ - virtual bool commitset(QSharedPointer _v) + virtual bool commitset(const binary& _v) { return false; } @@ -297,7 +297,7 @@ namespace agentxcpp */ virtual bool handle_undoset() { - return undoset(new_value); + return undoset(new_value->value()); } /** @@ -323,7 +323,7 @@ namespace agentxcpp * * \return True on success, false otherwise. */ - virtual bool undoset(QSharedPointer _v) + virtual bool undoset(const binary& _v) { return false; } diff --git a/src/TimeTicksVariable.hpp b/src/TimeTicksVariable.hpp index b1a854c..3f364fa 100644 --- a/src/TimeTicksVariable.hpp +++ b/src/TimeTicksVariable.hpp @@ -182,7 +182,7 @@ namespace agentxcpp if (new_value) { // Type matches variable - return testset(new_value); + return testset(new_value->value()); } else { @@ -210,7 +210,7 @@ namespace agentxcpp * * \return The result of the check. */ - virtual testset_result_t testset(QSharedPointer v) + virtual testset_result_t testset(quint32 _v) { return noAccess; } @@ -225,7 +225,7 @@ namespace agentxcpp */ virtual void handle_cleanupset() { - cleanupset(new_value); + cleanupset(new_value->value()); } /** @@ -241,7 +241,7 @@ namespace agentxcpp * * \param _v The new value for the object. */ - virtual void cleanupset(QSharedPointer _v) + virtual void cleanupset(quint32 _v) { return; } @@ -256,7 +256,7 @@ namespace agentxcpp */ virtual bool handle_commitset() { - return commitset(new_value); + return commitset(new_value->value()); } /** @@ -274,7 +274,7 @@ namespace agentxcpp * * \return True if the operation succeeded, false otherwise. */ - virtual bool commitset(QSharedPointer _v) + virtual bool commitset(quint32 _v) { return false; } @@ -290,7 +290,7 @@ namespace agentxcpp */ virtual bool handle_undoset() { - return undoset(new_value); + return undoset(new_value->value()); } /** @@ -316,7 +316,7 @@ namespace agentxcpp * * \return True on success, false otherwise. */ - virtual bool undoset(QSharedPointer v) + virtual bool undoset(quint32 _v) { return false; } From abc35a20cd7c1c4013d51d62d03ea17dc04545a2 Mon Sep 17 00:00:00 2001 From: "Tanjeff-N. Moos" Date: Sat, 21 Nov 2015 09:48:21 +0100 Subject: [PATCH 53/89] Rename class: varbind -> Varbind. --- src/IndexAllocatePDU.cpp | 4 ++-- src/IndexAllocatePDU.hpp | 6 +++--- src/IndexDeallocatePDU.cpp | 4 ++-- src/IndexDeallocatePDU.hpp | 6 +++--- src/MasterProxy.cpp | 22 +++++++++++----------- src/MasterProxy.hpp | 4 ++-- src/NotifyPDU.cpp | 4 ++-- src/NotifyPDU.hpp | 6 +++--- src/ResponsePDU.cpp | 4 ++-- src/ResponsePDU.hpp | 4 ++-- src/TestSetPDU.cpp | 4 ++-- src/TestSetPDU.hpp | 6 +++--- src/{varbind.cpp => Varbind.cpp} | 11 ++++++----- src/{varbind.hpp => Varbind.hpp} | 8 ++++---- 14 files changed, 47 insertions(+), 46 deletions(-) rename src/{varbind.cpp => Varbind.cpp} (95%) rename src/{varbind.hpp => Varbind.hpp} (96%) diff --git a/src/IndexAllocatePDU.cpp b/src/IndexAllocatePDU.cpp index 1223e5e..aa6a94d 100644 --- a/src/IndexAllocatePDU.cpp +++ b/src/IndexAllocatePDU.cpp @@ -30,7 +30,7 @@ IndexAllocatePDU::IndexAllocatePDU(binary::const_iterator& pos, // Get VarBind's until the PDU is completely parsed while( pos < end ) { - vb.push_back(varbind(pos, end, big_endian)); + vb.push_back(Varbind(pos, end, big_endian)); } } @@ -42,7 +42,7 @@ binary IndexAllocatePDU::serialize() binary serialized; // Add VarBind's - vector::const_iterator i; + vector::const_iterator i; for(i = vb.begin(); i < vb.end(); i++) { serialized += i->serialize(); diff --git a/src/IndexAllocatePDU.hpp b/src/IndexAllocatePDU.hpp index caf8ab8..401b7f3 100644 --- a/src/IndexAllocatePDU.hpp +++ b/src/IndexAllocatePDU.hpp @@ -22,7 +22,7 @@ #include #include "PDUwithContext.hpp" -#include "varbind.hpp" +#include "Varbind.hpp" using std::vector; @@ -40,7 +40,7 @@ namespace agentxcpp * \brief The VarBindList containing the index names and values * requested for allocation. */ - vector vb; + vector vb; public: /** @@ -85,7 +85,7 @@ namespace agentxcpp * \note There is no set_vb() function, because the VarBind * list can be modified in place. */ - vector& get_vb() + vector& get_vb() { return this->vb; } diff --git a/src/IndexDeallocatePDU.cpp b/src/IndexDeallocatePDU.cpp index 50b27cb..b079290 100644 --- a/src/IndexDeallocatePDU.cpp +++ b/src/IndexDeallocatePDU.cpp @@ -30,7 +30,7 @@ IndexDeallocatePDU::IndexDeallocatePDU(binary::const_iterator& pos, // Get VarBind's until the PDU is completely parsed while( pos < end ) { - vb.push_back(varbind(pos, end, big_endian)); + vb.push_back(Varbind(pos, end, big_endian)); } } @@ -42,7 +42,7 @@ binary IndexDeallocatePDU::serialize() binary serialized; // Add VarBind's - vector::const_iterator i; + vector::const_iterator i; for(i = vb.begin(); i < vb.end(); i++) { serialized += i->serialize(); diff --git a/src/IndexDeallocatePDU.hpp b/src/IndexDeallocatePDU.hpp index 7ba3b47..24be197 100644 --- a/src/IndexDeallocatePDU.hpp +++ b/src/IndexDeallocatePDU.hpp @@ -22,7 +22,7 @@ #include #include "PDUwithContext.hpp" -#include "varbind.hpp" +#include "Varbind.hpp" using std::vector; @@ -40,7 +40,7 @@ namespace agentxcpp * \brief The VarBind list containing the index names and values to * be released. */ - vector vb; + vector vb; public: /** @@ -85,7 +85,7 @@ namespace agentxcpp * \note There is no set_vb() function, because the VarBind * list can be modified in place. */ - vector& get_vb() + vector& get_vb() { return this->vb; } diff --git a/src/MasterProxy.cpp b/src/MasterProxy.cpp index 07e4aee..c578295 100644 --- a/src/MasterProxy.cpp +++ b/src/MasterProxy.cpp @@ -466,7 +466,7 @@ void MasterProxy::handle_getpdu(QSharedPointer response, QSharedPoi { // Add variable to response (Step (1): include name) var->second->handle_get(); - response->varbindlist.push_back( varbind(name, var->second) ); + response->varbindlist.push_back( Varbind(name, var->second) ); } catch(...) { @@ -490,14 +490,14 @@ void MasterProxy::handle_getpdu(QSharedPointer response, QSharedPoi // Step (4): We have a variable with the object // identifier prefix 'name': Send noSuchInstance // error (Step (1): include name) - response->varbindlist.push_back( varbind(name, varbind::noSuchInstance) ); + response->varbindlist.push_back( Varbind(name, Varbind::noSuchInstance) ); } else { // Step (3): we have no variable with the object // identifier prefix 'name': Send noSuchObject // error (Step (1): include name) - response->varbindlist.push_back( varbind(name, varbind::noSuchObject) ); + response->varbindlist.push_back( Varbind(name, Varbind::noSuchObject) ); } } @@ -560,7 +560,7 @@ void MasterProxy::handle_getnextpdu(QSharedPointer response, QShare try { next_var->second->handle_get(); - response->varbindlist.push_back( varbind(next_var->first, next_var->second) ); + response->varbindlist.push_back( Varbind(next_var->first, next_var->second) ); } catch(...) { @@ -574,7 +574,7 @@ void MasterProxy::handle_getnextpdu(QSharedPointer response, QShare else { // "Next" variable was NOT found - response->varbindlist.push_back( varbind(starting_oid, varbind::endOfMibView) ); + response->varbindlist.push_back( Varbind(starting_oid, Varbind::endOfMibView) ); } index++; @@ -589,14 +589,14 @@ void MasterProxy::handle_testsetpdu(QSharedPointer response, QShare // RFC 2741, 7.2.4.1 "Subagent Processing of the agentx-TestSet-PDU" // Extract Varbind list - vector& vb = testset_pdu->get_vb(); + vector& vb = testset_pdu->get_vb(); // Initially, no Varbind failed: response->set_error(ResponsePDU::noAgentXError); // Iterate over list and handle each Varbind separately. Return on the // first varbind which doesn't validate correctly. - vector::const_iterator i; + vector::const_iterator i; quint16 index; for(i = vb.begin(), index = 1; i != vb.end(); i++, index++) { @@ -941,23 +941,23 @@ void MasterProxy::removeVariables(const QVector& ids) void MasterProxy::send_notification(const Oid& snmpTrapOID, const TimeTicksVariable* sysUpTime, - const vector& varbinds) + const vector& varbinds) { QSharedPointer pdu(new NotifyPDU); pdu->set_sessionID(this->sessionID); - vector& vb = pdu->get_vb(); + vector& vb = pdu->get_vb(); // First of all: add mandatory sysUpTime (if given) if(sysUpTime) { QSharedPointer value(new TimeTicksVariable(*sysUpTime)); - vb.push_back(varbind(Oid(sysUpTime_oid, "0"), value)); + vb.push_back(Varbind(Oid(sysUpTime_oid, "0"), value)); } // Second: add mandatory snmpTrapOID QSharedPointer trapoid(new OidVariable(snmpTrapOID)); - vb.push_back(varbind(Oid(snmpTrapOID_oid, "0"), trapoid)); + vb.push_back(Varbind(Oid(snmpTrapOID_oid, "0"), trapoid)); // Append given varbinds vb.insert(vb.end(), varbinds.begin(), varbinds.end()); diff --git a/src/MasterProxy.hpp b/src/MasterProxy.hpp index b4233a7..7bef138 100644 --- a/src/MasterProxy.hpp +++ b/src/MasterProxy.hpp @@ -505,7 +505,7 @@ namespace agentxcpp */ void send_notification(const Oid& snmpTrapOID, const TimeTicksVariable* sysUpTime, - const std::vector& varbinds=vector()); + const std::vector& varbinds=vector()); /** * \brief Writing aid: Send notification without sysUpTime.0. @@ -520,7 +520,7 @@ namespace agentxcpp * const vector&) */ void send_notification(const Oid& snmpTrapOID, - const std::vector& varbinds=vector()) + const std::vector& varbinds=vector()) { send_notification(snmpTrapOID, 0, varbinds); } diff --git a/src/NotifyPDU.cpp b/src/NotifyPDU.cpp index 1cd70b6..5381e7d 100644 --- a/src/NotifyPDU.cpp +++ b/src/NotifyPDU.cpp @@ -30,7 +30,7 @@ NotifyPDU::NotifyPDU(binary::const_iterator& pos, // Get VarBind's until the PDU is completely parsed while( pos < end ) { - vb.push_back(varbind(pos, end, big_endian)); + vb.push_back(Varbind(pos, end, big_endian)); } } @@ -42,7 +42,7 @@ binary NotifyPDU::serialize() const binary serialized; // Add VarBind's - vector::const_iterator i; + vector::const_iterator i; for(i = vb.begin(); i < vb.end(); i++) { serialized += i->serialize(); diff --git a/src/NotifyPDU.hpp b/src/NotifyPDU.hpp index d68c5c1..085f4c9 100644 --- a/src/NotifyPDU.hpp +++ b/src/NotifyPDU.hpp @@ -24,7 +24,7 @@ #include #include "PDUwithContext.hpp" -#include "varbind.hpp" +#include "Varbind.hpp" using std::vector; @@ -41,7 +41,7 @@ namespace agentxcpp /** * \brief The VarBind list */ - vector vb; + vector vb; public: /** @@ -95,7 +95,7 @@ namespace agentxcpp * if sysUpTime.0 was supplied, as the first if it was * not. */ - vector& get_vb() + vector& get_vb() { return this->vb; } diff --git a/src/ResponsePDU.cpp b/src/ResponsePDU.cpp index 56d7c87..0a616d8 100644 --- a/src/ResponsePDU.cpp +++ b/src/ResponsePDU.cpp @@ -32,7 +32,7 @@ ResponsePDU::ResponsePDU(binary::const_iterator& pos, // read varbindlist if present while(pos != end) { - varbindlist.push_back(varbind(pos, end, big_endian)); + varbindlist.push_back(Varbind(pos, end, big_endian)); } /* We accept only allowed values: */ @@ -92,7 +92,7 @@ binary ResponsePDU::serialize() const write16(serialized, this->index); // Encode VarBindList - vector::const_iterator i; + vector::const_iterator i; for(i = this->varbindlist.begin(); i != this->varbindlist.end(); i++) { serialized += i->serialize(); diff --git a/src/ResponsePDU.hpp b/src/ResponsePDU.hpp index 4fb8563..3cb0ca3 100644 --- a/src/ResponsePDU.hpp +++ b/src/ResponsePDU.hpp @@ -26,7 +26,7 @@ #include "PDU.hpp" #include "OctetStringVariable.hpp" -#include "varbind.hpp" +#include "Varbind.hpp" using std::vector; @@ -119,7 +119,7 @@ namespace agentxcpp * * This vector may be empty if the %PDU has no VarBinds. */ - vector varbindlist; + vector varbindlist; /** * \brief Parse constructor diff --git a/src/TestSetPDU.cpp b/src/TestSetPDU.cpp index 5d02c72..e366d26 100644 --- a/src/TestSetPDU.cpp +++ b/src/TestSetPDU.cpp @@ -30,7 +30,7 @@ TestSetPDU::TestSetPDU(binary::const_iterator& pos, // Get VarBind's until the PDU is completely parsed while( pos < end ) { - vb.push_back(varbind(pos, end, big_endian)); + vb.push_back(Varbind(pos, end, big_endian)); } } @@ -42,7 +42,7 @@ binary TestSetPDU::serialize() const binary serialized; // Add VarBind's - vector::const_iterator i; + vector::const_iterator i; for(i = vb.begin(); i < vb.end(); i++) { serialized += i->serialize(); diff --git a/src/TestSetPDU.hpp b/src/TestSetPDU.hpp index aeb0f4f..a5c0520 100644 --- a/src/TestSetPDU.hpp +++ b/src/TestSetPDU.hpp @@ -22,7 +22,7 @@ #include #include "PDUwithContext.hpp" -#include "varbind.hpp" +#include "Varbind.hpp" using std::vector; @@ -42,7 +42,7 @@ namespace agentxcpp // TODO: should be use std::list instead? After all, ist is called // a VarBind _list_. This is also true for some other PDU's, grep // for 'vector' in *PDU.hpp - vector vb; + vector vb; public: /** @@ -86,7 +86,7 @@ namespace agentxcpp * \note There is no set_vb() function, because the VarBind * list can be modified in place. */ - vector& get_vb() + vector& get_vb() { return this->vb; } diff --git a/src/varbind.cpp b/src/Varbind.cpp similarity index 95% rename from src/varbind.cpp rename to src/Varbind.cpp index bb2eac6..4376bd2 100644 --- a/src/varbind.cpp +++ b/src/Varbind.cpp @@ -17,7 +17,8 @@ * for more details. */ -#include "varbind.hpp" +#include "Varbind.hpp" + #include "OctetStringVariable.hpp" #include "IntegerVariable.hpp" #include "Counter32Variable.hpp" @@ -31,7 +32,7 @@ using namespace agentxcpp; -binary varbind::serialize() const +binary Varbind::serialize() const { binary serialized; @@ -53,7 +54,7 @@ binary varbind::serialize() const } -varbind::varbind(const Oid& o, QSharedPointer v) +Varbind::Varbind(const Oid& o, QSharedPointer v) { name = o; var = v; @@ -76,7 +77,7 @@ varbind::varbind(const Oid& o, QSharedPointer v) } -varbind::varbind(const Oid& o, type_t t) +Varbind::Varbind(const Oid& o, type_t t) { name = o; @@ -96,7 +97,7 @@ varbind::varbind(const Oid& o, type_t t) } } -varbind::varbind(binary::const_iterator& pos, +Varbind::Varbind(binary::const_iterator& pos, const binary::const_iterator& end, bool big_endian) { diff --git a/src/varbind.hpp b/src/Varbind.hpp similarity index 96% rename from src/varbind.hpp rename to src/Varbind.hpp index cddd72b..c6f4b67 100644 --- a/src/varbind.hpp +++ b/src/Varbind.hpp @@ -34,7 +34,7 @@ namespace agentxcpp * * \brief Represents a VarBind according to RFC 2741, section 5.4. */ - class varbind + class Varbind { private: /** @@ -76,7 +76,7 @@ namespace agentxcpp * If the type of the variable cannot be determined, inval_param is * thrown. */ - varbind(const Oid&, QSharedPointer v); + Varbind(const Oid&, QSharedPointer v); /** * \brief These values can be used to create a VarBind. @@ -95,7 +95,7 @@ namespace agentxcpp * Only the constants defined by varbind::type_t are allowed. A * wrong type will cause an inval_param exception. */ - varbind(const Oid&, type_t); + Varbind(const Oid&, type_t); /** * \internal @@ -121,7 +121,7 @@ namespace agentxcpp * \param big_endian Whether the input stream is in big endian * format */ - varbind(binary::const_iterator& pos, + Varbind(binary::const_iterator& pos, const binary::const_iterator& end, bool big_endian=true); From 3140e39d759602d06b2575b52b15c10860e19f92 Mon Sep 17 00:00:00 2001 From: "Tanjeff-N. Moos" Date: Sat, 21 Nov 2015 10:01:02 +0100 Subject: [PATCH 54/89] AbstractVariable::handle_get() returns now 'void'. --- src/AbstractVariable.hpp | 2 +- src/Counter32Variable.hpp | 3 +-- src/Counter64Variable.hpp | 3 +-- src/Gauge32Variable.hpp | 3 +-- src/IntegerVariable.hpp | 3 +-- src/IpAddressVariable.hpp | 3 +-- src/OctetStringVariable.hpp | 3 +-- src/OidVariable.hpp | 3 +-- src/OpaqueVariable.hpp | 3 +-- src/TimeTicksVariable.hpp | 3 +-- 10 files changed, 10 insertions(+), 19 deletions(-) diff --git a/src/AbstractVariable.hpp b/src/AbstractVariable.hpp index 47b7d8c..98aebd8 100644 --- a/src/AbstractVariable.hpp +++ b/src/AbstractVariable.hpp @@ -57,7 +57,7 @@ namespace agentxcpp * \exception generic_error If obtaining the current value fails. * No other exception shall be thrown. */ - virtual QSharedPointer handle_get() = 0; + virtual void handle_get() = 0; /** diff --git a/src/Counter32Variable.hpp b/src/Counter32Variable.hpp index 9cc6e20..0455fce 100644 --- a/src/Counter32Variable.hpp +++ b/src/Counter32Variable.hpp @@ -94,10 +94,9 @@ namespace agentxcpp * This function calls get() to obtain the new value, * converts it to QSharedPointer and returns it. */ - virtual QSharedPointer handle_get() + virtual void handle_get() { this->get(); - return QSharedPointer(new Counter32Variable(*this)); } /** diff --git a/src/Counter64Variable.hpp b/src/Counter64Variable.hpp index f27eb36..99edcf6 100644 --- a/src/Counter64Variable.hpp +++ b/src/Counter64Variable.hpp @@ -94,10 +94,9 @@ namespace agentxcpp * This function calls get() to obtain the new value, * converts it to QSharedPointer and returns it. */ - virtual QSharedPointer handle_get() + virtual void handle_get() { this->get(); - return QSharedPointer(new Counter64Variable(*this)); } /** diff --git a/src/Gauge32Variable.hpp b/src/Gauge32Variable.hpp index b5e6b35..078c8f0 100644 --- a/src/Gauge32Variable.hpp +++ b/src/Gauge32Variable.hpp @@ -123,10 +123,9 @@ namespace agentxcpp * This function calls get() to obtain the new value, * converts it to QSharedPointer and returns it. */ - virtual QSharedPointer handle_get() + virtual void handle_get() { this->get(); - return QSharedPointer(new Gauge32Variable(*this)); } /** diff --git a/src/IntegerVariable.hpp b/src/IntegerVariable.hpp index 4997bad..519b555 100644 --- a/src/IntegerVariable.hpp +++ b/src/IntegerVariable.hpp @@ -142,10 +142,9 @@ namespace agentxcpp * This function calls get() to obtain the new value, * converts it to QSharedPointer and returns it. */ - virtual QSharedPointer handle_get() + virtual void handle_get() { this->get(); - return QSharedPointer(new IntegerVariable(*this)); } /** diff --git a/src/IpAddressVariable.hpp b/src/IpAddressVariable.hpp index ecbfd0b..494853c 100644 --- a/src/IpAddressVariable.hpp +++ b/src/IpAddressVariable.hpp @@ -182,10 +182,9 @@ namespace agentxcpp * This function calls get() to obtain the new value, * converts it to QSharedPointer and returns it. */ - virtual QSharedPointer handle_get() + virtual void handle_get() { this->get(); - return QSharedPointer(new IpAddressVariable(*this)); } /** diff --git a/src/OctetStringVariable.hpp b/src/OctetStringVariable.hpp index fd9fc8e..a10be77 100644 --- a/src/OctetStringVariable.hpp +++ b/src/OctetStringVariable.hpp @@ -122,10 +122,9 @@ namespace agentxcpp * * \brief Handle a Get Request. */ - virtual QSharedPointer handle_get() + virtual void handle_get() { this->get(); - return QSharedPointer(new OctetStringVariable(*this)); } /** diff --git a/src/OidVariable.hpp b/src/OidVariable.hpp index fcc0fe9..52b0fcd 100644 --- a/src/OidVariable.hpp +++ b/src/OidVariable.hpp @@ -181,10 +181,9 @@ namespace agentxcpp * This function calls get() to update the internal value, * converts it to QSharedPointer and returns it. */ - virtual QSharedPointer handle_get() + virtual void handle_get() { this->get(); - return QSharedPointer(new OidVariable(*this)); } /** diff --git a/src/OpaqueVariable.hpp b/src/OpaqueVariable.hpp index 08a5b92..5e37cef 100644 --- a/src/OpaqueVariable.hpp +++ b/src/OpaqueVariable.hpp @@ -141,10 +141,9 @@ namespace agentxcpp * This function calls get() to obtain the new value, * converts it to QSharedPointer and returns it. */ - virtual QSharedPointer handle_get() + virtual void handle_get() { this->get(); - return QSharedPointer(new OpaqueVariable(*this)); } /** diff --git a/src/TimeTicksVariable.hpp b/src/TimeTicksVariable.hpp index 3f364fa..506ffea 100644 --- a/src/TimeTicksVariable.hpp +++ b/src/TimeTicksVariable.hpp @@ -134,10 +134,9 @@ namespace agentxcpp * This function calls get() to obtain the new value, * converts it to QSharedPointer and returns it. */ - virtual QSharedPointer handle_get() + virtual void handle_get() { this->get(); - return QSharedPointer(new TimeTicksVariable(*this)); } /** From ab0b760fcd9ffc6bf112580d092394db9ab12849 Mon Sep 17 00:00:00 2001 From: "Tanjeff-N. Moos" Date: Sat, 21 Nov 2015 21:41:43 +0100 Subject: [PATCH 55/89] Update documetation. --- doc/documentation.dox | 30 +++---- doc/how_to_implement_tables.dox | 8 +- doc/how_to_send_notifications.dox | 10 +-- doc/internals.doxyfile | 2 +- doc/parsing.dox | 12 +-- doc/variables.dox | 125 +++++++++++++++++++++--------- 6 files changed, 120 insertions(+), 67 deletions(-) diff --git a/doc/documentation.dox b/doc/documentation.dox index 526207d..828221a 100644 --- a/doc/documentation.dox +++ b/doc/documentation.dox @@ -19,7 +19,7 @@ /*! -\internal +\cond INTERNAL \page documentation About the Documentation @@ -30,31 +30,33 @@ documentation while the latter is used for the internals documentation. The source of documentation is (nearly) identical for both documentations. Classes, members, functions, etc. are documented directly in the C++ source -files, using the \\internal keyword mark internal-only content. The -doc/ directory contains the mainpages (api.mainpage and -%internals.mainpage), which are different for the API and the +files, using the \\internal keyword or a pair of \\cond +INTERNAL and \\endcond to mark internal-only content. +Documentation blocks marked in this way are included only in the internals +documentation, because the INTERNAL_DOCS configuration item is set to +YES for the internals documentation, but to NO for the API +documentation, and the ENABLED_SECTIONS configuration item includes +the section name "INTERNAL" for the internals documentation (hence +\\cond can test for "INTERNAL"). + +The doc/ directory also contains the mainpages (api.mainpage +and %internals.mainpage), which are different for the API and the internals documentation. The *.dox files provide subpages explaining the concepts used in the library (e.g. the source of this page is -doc/documentation.dox). - -Documentation blocks marked with the \\internal keyword are included -only in the internals documentation (the INTERNAL_DOCS configuration -item is set to YES for the internals documentation, but to NO -for the API documentation). The API documentation contains only documentation -blocks which are not marked with \\internal. This is also true for the -codeblocks in *.dox files (e.g. this page is not included in the API -documentation). +%doc/documentation.dox). If you are developing for AgentXcpp, consider the following conventions: - Use \\internal to mark documentation blocks which should not appear in the API documentation. If only a part of the documentation block should be excluded, surround the part to be excluded with - \\internal and \\endinternal. + \\internal and \\endinternal. You may also use \\cond + INTERNAL and \\endcond. - Document each and every item, such as classes, class members, functions, global variables, etc. - Include a \\brief command for every documented item. - Include a subpage (i.e. a *.dox file) for each abstract concept. Add links to that pages to the appropriate mainpage(s). +\endcond */ diff --git a/doc/how_to_implement_tables.dox b/doc/how_to_implement_tables.dox index 1e01502..ca1ddfb 100644 --- a/doc/how_to_implement_tables.dox +++ b/doc/how_to_implement_tables.dox @@ -166,7 +166,7 @@ the variables which can be queried. Therefore, neither the table nor the entries are added to the MasterProxy object. Only the variables are added. -\section implementing_entry Implementing the CounterChangeEntry class +\section tables_implementing_entry Implementing the CounterChangeEntry class First of all, we implement the CounterChangeEntry class. Here is the full code: @@ -236,7 +236,7 @@ The CounterChangeEntry::variables() method return all variables as a QMap. The map key will be used by the table as <variableSubOid> part for the variable. -\section extending_simplecounter Extending the SimpleCounter class. +\section tables_extending_simplecounter Extending the SimpleCounter class. Next, we extent the SimpleCounter class so that it adds an entry to the table @@ -355,7 +355,7 @@ int main(int argc, char** argv) And that's all we need for our table. Next, let's try it out. -\section compiling_notification Compiling the Subagent +\section tables_compiling_notification Compiling the Subagent We didn't add implementation files in this tutorial, so no additional steps are needed for compiling. However, we have to recompile the the whole thing. We @@ -376,7 +376,7 @@ g++ simpleagent.cpp -o simpleagent moc_NotificationSender.o `pkg-config --cflags Now, the executable is ready to run. -\section running Running the subagent +\section tables_running Running the subagent The subagent is run like descibed in the previous tutorials, simply by executing it: diff --git a/doc/how_to_send_notifications.dox b/doc/how_to_send_notifications.dox index 239613f..b9fdeac 100644 --- a/doc/how_to_send_notifications.dox +++ b/doc/how_to_send_notifications.dox @@ -118,13 +118,13 @@ class NotificationSender : public QObject { std::cout << "notification!" << std::endl; - std::vector objects; - QSharedPointer counterVariable(new IntegerVariable(counter->value())); - objects.push_back(varbind(simpleCounter_oid, counterVariable)); + std::vector objects; + IntegerVariable(counter->value())); + objects.push_back(Varbind(simpleCounter_oid, counterVariable)); QMetaObject::invokeMethod(master, "send_notification", Q_ARG(const Oid&, simpleCounter_oid), - Q_ARG(const std::vector&, objects) + Q_ARG(const std::vector&, objects) ); } }; @@ -277,7 +277,7 @@ can see its output. The -Le parameter redirects the logging messages to stderr (i.e. to the console window). -\subsection starting_subagent Starting the Subagent +\subsection notifications_starting_subagent Starting the Subagent Now, the subagent is started: diff --git a/doc/internals.doxyfile b/doc/internals.doxyfile index f6b5ccb..5468dd2 100644 --- a/doc/internals.doxyfile +++ b/doc/internals.doxyfile @@ -565,7 +565,7 @@ GENERATE_DEPRECATEDLIST= YES # The ENABLED_SECTIONS tag can be used to enable conditional # documentation sections, marked by \if sectionname ... \endif. -ENABLED_SECTIONS = +ENABLED_SECTIONS = INTERNAL # The MAX_INITIALIZER_LINES tag determines the maximum number of lines # the initial value of a variable or macro consists of for it to appear in diff --git a/doc/parsing.dox b/doc/parsing.dox index db02480..b27473f 100644 --- a/doc/parsing.dox +++ b/doc/parsing.dox @@ -27,22 +27,22 @@ This section explains how PDU parsing is done in agentXcpp. AgentX PDUs are read from a stream, constructing C++ objects which represent the PDUs and all their parts (such as varbinds, for example). In general, the -C++ objects, such as OpenPDU, varbind, OidValue or IntegerValue, are created by +C++ objects, such as OpenPDU, Varbind, OidValue or IntegerValue, are created by providing an iterator (pointing into a buffer) to their constructors. The constructor uses the iterator to read the serialized form of the object and construct the C++ object accordingly. Along the way, the iterator is modified to point behind the object which was just deserialized. -An example of such a constructor is varbind::varbind(binary::const_iterator&, +An example of such a constructor is Varbind::Varbind(binary::const_iterator&, const binary::const_iterator&, bool). It takes an iterator ('pos') and begins -parsing at where 'pos' points to. While reading, the varbind object is -constructed. A varbind always contains (at least) an OidValue. The varbind +parsing at where 'pos' points to. While reading, the Varbind object is +constructed. A Varbind always contains (at least) an OidValue. The Varbind constructor therefore creates an OidValue object by passing the 'pos' iterator to the constructor of the OidValue class, which reads the serialized OidValue and constructs the OidValue object. If needed, another variable is created the -same way (e.g. an IntegerValue or an OctetStringValue). When the varbind +same way (e.g. an IntegerValue or an OctetStringValue). When the Varbind object is fully constructed, the 'pos' iterator points to the position behind -the varbind and the constructor returns. Note that the iterator is modified by +the Varbind and the constructor returns. Note that the iterator is modified by the constructor. The caller may then use 'pos' to create the next object, until the buffer is completely parsed. diff --git a/doc/variables.dox b/doc/variables.dox index 028bc69..372d99a 100644 --- a/doc/variables.dox +++ b/doc/variables.dox @@ -19,61 +19,112 @@ /*! -\internal \page variables The Variable Objects -\section introduction Introduction +\section variables_introduction Introduction SNMP and AgentX are all about variables, and how to obtain or alter their -values. In agentXcpp, variables are represented by classes which implement the -agentxcpp::AbstractVariable interface. Values are represented by classes -implementing agentxcpp::AbstractValue. +values. In agentXcpp, variables are represented by objects which implement the +\agentxcpp{AbstractVariable} interface. The library provides some classes such +as \agentxcpp{IntegerVariable} and \agentxcpp{OctetStringVariable}, all +implementing \agentxcpp{AbstractVariable}. These classes can directly be +instantiated to serve as read-only variables (they do not support SNMP SET +requests), and their value can be obtained with value() and altered with +setValue(). + +However, it is normally more useful to derive from these classes and reimplement +get(), so that the value can be obtained in the moment a GET request occurs. +Also, the testset(), commitset(), undoset() and +cleanupset() methods can be reimplemented to add write support. + +\section variables_get How SNMP GET requests are served + +Each variable has an internal member to store its value, e.g. +\agentxcpp{IntegerVariable::v}. The get() method is called by the +library when an SNMP GET is requested for the variable. This method should then +update the internal member to reflect the current state. The default +get() implementation does nothing and thus allows to read the value as +set by the last call to setValue(). This makes it possible to use the Variable +class without inheriting. + + +\internal + +\subsection variables_get_internal How GET requests are handled internally + +When the \agentxcpp{MasterProxy} object receives a GET (or GETNEXT) request, it +looks up the variable registered with the requested OID. This works even for +variables which are part of a table, because the \agentxcpp{Table} class +registers its variables like any other variable. Then the MasterProxy invokes +the variable's \agentxcpp{AbstractVariable::handle_get()} method to update the +value of the variable. After that, it adds the variable to a \agentxcpp{Varbind} +object which is then embedded into the response and sent back to the master +agent (possibly with further varbinds). + +The variable's \agentxcpp{AbstractVariable::handle_get()} method is implemented +in the subclasses. It first calls get() to update the internally stored value. +The default implementation of get() does nothing, but can be overridden by +subclasses. + + + -SNMP variables +\section variables_set How SNMP SET requests are served -The library provides some classes such as agentxcpp::IntegerValue and -agentxcpp::OctetStringValue, which have an internal value and can be -serialized and deserialized to be included in PDU messages. To actually -provide an SNMP variable, one of these classes must be derived. +Each variable provides the functions testset(), commitset(), +cleanupset() and undoset(), which are called while processing +an SNMP SET request for the variable. Each of these functions takes the new +value as parameter (e.g. an qint32 value for \agentxcpp{IntegerVariable}). The +functions should then act as described in \ref the_set_steps, returning success +or failure. It is not required that the functions update the internal member, +because on SET request, a subagent does not send the new state back to the +master agent. +The default implementation of the SET-supporting methods is to fail with +\agentxcpp{AbstractVariable::noAccess}, indicating that the variable is +read-only. It is required to reimplement the methods in a derived class to +enable write support. -\section serializing_parsing Serializing and Parsing Variables +\cond INTERNAL -The agentxcpp::variable interface provides the serialize function to serialize -a variable object. Parsing is done using parse constructors. This is the same -mechanism as used by the %PDU classes. See \ref pdus for an explanation. +\subsection variables_set_internal How SET requests are handled internally +When the \agentxcpp{MasterProxy} object receives a TESTSET, COMMITSET, +CLEANUPSET or UNDOSET request, it looks up the variable corresponding to the +given OID and calls its \agentxcpp{AbstractVariable::handle_testset()}, +\agentxcpp{AbstractVariable::handle_commitset()}, +\agentxcpp{AbstractVariable::handle_cleanupset()} or +\agentxcpp{AbstractVariable::handle_undoset()} method, respectively. These +methods are implemented in the subclasses of AbstractVariable. The first one, +handle_testset(), is the only one which receives new new value, in form +of a pointer to \agentxcpp{AbstractVariable}, and stores it internally for later +use. The other three methods then use the stored pointer to obtain access to the +new value. +In particular, the handle_testset() method converts the pointer to +\agentxcpp{AbstractVariable} into a pointer to the more concrete classe (e.g. +\agentxcpp{Gauge32Variable} and stores it. Then, it calls the testset() method. +The handle_commitset() handle_cleanupset() and +handle_undoset() methods only call commitset(), +cleanupset() and undoset(), respectively. -\section get GET Requests +The default implementation of testset() returns +\agentxcpp{AbstractVariable::noAccess} to indicate that the variable is +read-only. The method can be overridden by subclasses to enable write support. +The default implementations of commitset(), cleanupset() and +undoset() all return false to indicate an error. -When the agentxcpp::MasterProxy object receives a GET request, it looks up the -variable registered with the requested OID. Then it invokes the variable's -update() function (found in the agentxcpp::variable interface) to update the -internal state of the variable. Finally the variable is serialized and embedded -within a agentxcpp::ResponsePDU and sent to the master agent. -The agentxcpp::variable::update() method is implemented in the variable classes -such as agentxcpp::IntegerValue, agentxcpp::OctetStringValue, -agentxcpp::Counter32Value, and -so on. The implementation just calls the get() method of the respective -object, which returns the new value of the object. Then, update() stores the -new value within the variable. +\section variables_serializing_parsing Serializing and Parsing Variables -When implementing an SNMP variable, the user of the agentXcpp library derives -one of the variable classes (e.g. agentxcpp::OctetStringValue) and overrides the -get() method. The get() method may throw agentxcpp::generic_error, in which -case a generic error is reported to the master agent. Note that any other -exception also results in a generic error reported to the master agent. +The \agentxcpp{AbstractVariable} interface provides the +\agentxcpp{AbstractVariable::serialize()} function to serialize a variable +object. Parsing is done using parse constructors. This is the same mechanism as +used by the %PDU classes. See \ref pdus for a general explanation. -The variable classes provide default implementations of get() which throws -agentxcpp::generic_error. As a side effect, a generic error is reported if a -derived class does not override get(). The main reason for providing a default -implementations is that get() cannot be pure virtual, because the variable -classes are created while parsing PDU contents. Abstract classes would not -allow that mechanism. +\endcond */ From 5f412f717e335d6f6f05eb0fa38357a13738704b Mon Sep 17 00:00:00 2001 From: "Tanjeff-N. Moos" Date: Sat, 21 Nov 2015 23:48:06 +0100 Subject: [PATCH 56/89] Update docs for AbstractVariable. --- doc/api.doxyfile | 2 +- src/AbstractVariable.hpp | 70 ++++++++++++++++++++++++---------------- 2 files changed, 44 insertions(+), 28 deletions(-) diff --git a/doc/api.doxyfile b/doc/api.doxyfile index d61b1b3..672be91 100644 --- a/doc/api.doxyfile +++ b/doc/api.doxyfile @@ -899,7 +899,7 @@ VERBATIM_HEADERS = NO # of all compounds will be generated. Enable this if the project # contains a lot of classes, structs, unions or interfaces. -ALPHABETICAL_INDEX = NO +ALPHABETICAL_INDEX = YES # If the alphabetical index is enabled (see ALPHABETICAL_INDEX) then # the COLS_IN_ALPHA_INDEX tag can be used to specify the number of columns diff --git a/src/AbstractVariable.hpp b/src/AbstractVariable.hpp index 98aebd8..7379bce 100644 --- a/src/AbstractVariable.hpp +++ b/src/AbstractVariable.hpp @@ -30,10 +30,12 @@ namespace agentxcpp * \brief Base class for SNMP variables. * * This class is the base class for SNMP variable implementations. It - * provides the interface which is used by agentXcpp to perform - * operations on variables. + * provides the interface which is used by agentXcpp (namely by the + * MasterProxy class) to perform operations on variables. An overiew on + * variable handling in agentxcpp is given in \ref variables. + * + * \note This class should never be inherited by non-agentXcpp code. * - * \todo Explain how Variables work in general. */ class AbstractVariable { @@ -41,18 +43,23 @@ namespace agentxcpp public: /** - * \brief Destructor. + * \brief Virtual destructor. */ virtual ~AbstractVariable() { } /** + * \internal + * * \brief Handle AgentX Get request. * - * This method is called when the SNMP request "Get" is received - * for the - * variable. It shall update the internal state. + * This method is called by the MasterProxy object when the SNMP + * request "Get" is received for the variable. It should update the + * internal state. + * + * \note Any exception thrown by this method results in sending a + * generic error to the master agent. * * \exception generic_error If obtaining the current value fails. * No other exception shall be thrown. @@ -71,13 +78,14 @@ namespace agentxcpp * agentXcpp implementation and is therefore not part of this * enumeration. * - * \internal - * * The numeric values are given in RFC 2741, 7.2.4.1. "Subagent * Processing of the agentx-TestSet-PDU". * + * \internal + * * \note These values must be in sync with the corresponding * errors defined in agentxcpp::ResponsePDU::error_t. + * */ enum testset_result_t { @@ -155,13 +163,14 @@ namespace agentxcpp }; /** + * \internal + * * \brief Validate whether a Set operation would be successful. * * This method is called when the SNMP request "TestSet" is - * received. It - * shall check whether a Set operation is possible for the - * variable. It shall acquire the resources needed to perform the - * Set operation (but the Set shall not yet be performed). + * received. It shall check whether a Set operation is possible for + * the variable. It shall acquire the resources needed to perform + * the Set operation (but the Set shall not yet be performed). * * \note This is the only method which receives the new value to be * set. An implementation must save the new value for @@ -174,6 +183,8 @@ namespace agentxcpp virtual testset_result_t handle_testset(QSharedPointer) = 0; /** + * \internal + * * \brief Release resources after a Set operation. * * This method is called when the SNMP request "CleanupSet" @@ -186,12 +197,13 @@ namespace agentxcpp virtual void handle_cleanupset() = 0; /** + * \internal + * * \brief Actually perform the Set operation. * * This method is called when the SNMP request "CommitSet" - * is received for - * the variable. It shall perform the Set operation. It shall - * report whether the operation succeeded. + * is received for the variable. It shall perform the Set + * operation. It shall report whether the operation succeeded. * * \note The new value is given to handle_testset() prior to * calling handle_commitset(). @@ -203,11 +215,13 @@ namespace agentxcpp virtual bool handle_commitset()= 0; /** + * \internal + * * \brief Undo a Set operation which was already performed. * * This method is called when the SNMP request "UndoSet" is - * received. It - * shall undo the operation performed by handle_commitset(). + * received. It shall undo the operation performed by + * handle_commitset(). * * \return True on success, false otherwise. * @@ -218,31 +232,33 @@ namespace agentxcpp /** * \internal * - * \brief Serialize the value. + * \brief Serialize the variable. * - * This function must be implemented by all derived classes. The - * function shall generate a serialized form of the internal value. + * This function shall generate a serialized form of the internal + * variable (i.e. the network representation of the variable). * - * \return The serialized form of the value. + * \return The serialized form of the variable. * - * \exception None: The function shall not throw. + * \exception The function shall not throw. */ virtual binary serialize() const = 0; /** + * \internal + * * \brief Convert an INDEX variable to an Oid part. * * If an SNMP variable is used as INDEX within a table, * then its value is used as part of the Oid for that table - * entry (or row). Therefore, such variables must be - * convertible to Oid's. This method provides this conversion. + * entry. Therefore, such variables must be convertible to Oid's. + * This method provides this conversion. * * Not all variable types are allowed to be used as INDEX and are * therefore not convertible to Oid. For variables which are not * convertible, this method shall return the null Oid. * - * \return The variable, converted to Oid, or the null Oid if the - * variable don't support such conversion. + * \return The Oid representing the variables value, or the null + * Oid if the variable don't support such conversion. * * \exception This method shall not throw. */ From 09387b961c36890812c6d60fd8b1f75ef6641375 Mon Sep 17 00:00:00 2001 From: "Tanjeff-N. Moos" Date: Wed, 25 Nov 2015 22:15:53 +0100 Subject: [PATCH 57/89] Rename get() -> perform_get() etc., update docs. --- doc/how_to_add_rw_support.dox | 68 +++---- doc/variables.dox | 86 +++++---- src/AbstractVariable.hpp | 2 - src/Counter32Variable.hpp | 175 ++++-------------- src/Counter64Variable.hpp | 167 +++-------------- src/Gauge32Variable.hpp | 173 ++++-------------- src/IntegerVariable.hpp | 208 ++++++++++++--------- src/IpAddressVariable.hpp | 174 ++++-------------- src/MasterProxy.hpp | 2 +- src/OctetStringVariable.hpp | 168 ++++------------- src/OidVariable.hpp | 332 +++++++++++----------------------- src/OpaqueVariable.hpp | 263 +++++++-------------------- src/SConscript | 2 +- src/TimeTicksVariable.hpp | 202 ++++----------------- 14 files changed, 578 insertions(+), 1444 deletions(-) diff --git a/doc/how_to_add_rw_support.dox b/doc/how_to_add_rw_support.dox index 8bb0e12..db2bac6 100644 --- a/doc/how_to_add_rw_support.dox +++ b/doc/how_to_add_rw_support.dox @@ -83,28 +83,29 @@ Therefore, the SET operation is carried out in multiple distinct steps: To implement these actions, the Variable classes provides the methods -testset(), commitset(), cleanupset() and undoset(), which can be overridden by -a concrete implementation. +perform_testset(), perform_commitset(), +perform_cleanupset() and perform_undoset(), which can be +overridden by a concrete implementation. \section extend_simplecounter Extending the SimpleCounter class To implement write support for the SimpleCounter class, we implement all four -methods. The testset() implementation allocates an quint32 value, which is -deallocated by cleanupset() respectively undoset(). This is not very -realistic, but it demonstrates the usage of the individual steps. The -commitset() method stores the old value (in case an undo needs to be carried -out by undoset()) and sets the new value. +methods. The perform_testset() implementation allocates an quint32 value, which is +deallocated by perform_cleanupset() respectively perform_undoset(). This is not +very realistic, but it demonstrates the usage of the individual steps. The +perform_commitset() method stores the old value (in case an undo needs to be carried out by +perform_undoset()) and sets the new value. \subsection TestSet -The testset() method must be overridden by any variable which should be -writeable. If it is not overridden, agentXcpp assumes that the variable is -read-only (which we exploited in the first, read-only version). This also -means that an e.g. IntegerVariable object is read-only by default and needs to -be subclassed to add write support. Hence, we implement it for our +The perform_testset() method must be overridden by any variable which +should be writeable. If it is not overridden, agentXcpp assumes that the +variable is read-only (which we exploited in the first, read-only version). +This also means that an e.g. IntegerVariable object is read-only by default and +needs to be subclassed to add write support. Hence, we implement it for our SimpleCounter class by adding the following code to it: \code @@ -113,7 +114,7 @@ SimpleCounter class by adding the following code to it: public: virtual testset_result_t - testset(QSharedPointer new_value) + perform_testset(QSharedPointer new_value) { try { @@ -130,20 +131,20 @@ SimpleCounter class by adding the following code to it: } \endcode -The \ref agentxcpp::IntegerVariable::testset "testset()" method receives the -value and can check whether setting the variable to this value would work. -Here, we don't check the value, but we allocate an quint32 to store the old -value, which is needed for undoset(). If allocation fails, we return the error -\ref agentxcpp::AbstractVariable::resourceUnavailable "resourceUnavailable". +The \ref agentxcpp::IntegerVariable::perform_testset "perform_testset()" method +receives the value and can check whether setting the variable to this value +would work. Here, we don't check the value, but we allocate an quint32 to store the old value, +which is needed for perform_undoset(). If allocation fails, we return the error \ref +agentxcpp::AbstractVariable::resourceUnavailable "resourceUnavailable". \subsection CommitSet -The commitset() method must also be implemented for writeable variables. In -the SimpleCounter class, this method stores the old value and sets the internal -value: +The perform_commitset() method must also be implemented for writeable +variables. In the SimpleCounter class, this method stores the old value and +sets the internal value: \code - virtual bool commitset(QSharedPointer new_value) + virtual bool perform_commitset(QSharedPointer new_value) { // Remember old value for rollback (*old_value) = v; @@ -156,31 +157,30 @@ value: \subsection CleanupSet -The cleanupset() method releases old_value again: +The perform_cleanupset() method releases old_value again: \code - virtual void cleanupset(QSharedPointer new_value) + virtual void perform_cleanupset(QSharedPointer new_value) { // Release old value delete old_value; } \endcode -If old_value were an quint32 (instead of a pointer to quint32), no allocation -and deallocation would have been necessary. The cleanupset() method would not -be implemented then. In fact, this method is the only one which is optional -for writeable variables, while the other methods are mandatory. +If old_value were an quint32 (instead of a pointer to quint32), no allocation and deallocation would +have been necessary. The perform_cleanupset() method would not be implemented then. In +fact, this method is the only one which is optional for writeable variables, while the other methods +are mandatory. \subsection UndoSet -The undoset() method must be implemented by each writeable variable and shall -perform a rollback. It is technically possible to omit this method; the -compiler has no way to detect a missing implementation. However, it is an error -to omit it, and an error will be reported to the master agent if it is missing. -For simpleCounter implementation is easy: +The perform_undoset() method must be implemented by each writeable variable and shall +perform a rollback. It is technically possible to omit this method; the compiler has no way to +detect a missing implementation. However, it is an error to omit it, and an error will be reported +to the master agent if it is missing. For simpleCounter implementation is easy: \code - virtual bool undoset(QSharedPointer new_value) + virtual bool perform_undoset(QSharedPointer new_value) { // Restore old value v = *old_value; diff --git a/doc/variables.dox b/doc/variables.dox index 372d99a..5b049c7 100644 --- a/doc/variables.dox +++ b/doc/variables.dox @@ -31,31 +31,36 @@ values. In agentXcpp, variables are represented by objects which implement the \agentxcpp{AbstractVariable} interface. The library provides some classes such as \agentxcpp{IntegerVariable} and \agentxcpp{OctetStringVariable}, all implementing \agentxcpp{AbstractVariable}. These classes can directly be -instantiated to serve as read-only variables (they do not support SNMP SET +instantiated to serve as read-only variables (they do not support SNMP Set requests), and their value can be obtained with value() and altered with setValue(). However, it is normally more useful to derive from these classes and reimplement -get(), so that the value can be obtained in the moment a GET request occurs. -Also, the testset(), commitset(), undoset() and -cleanupset() methods can be reimplemented to add write support. +perform_get(), so that the value can be obtained in the moment a Get request +occurs. Also, the perform_testset(), perform_commitset(), +perform_undoset() and perform_cleanupset() methods can be +reimplemented to add write support. -\section variables_get How SNMP GET requests are served +\section variables_get How SNMP Get requests are served Each variable has an internal member to store its value, e.g. -\agentxcpp{IntegerVariable::v}. The get() method is called by the -library when an SNMP GET is requested for the variable. This method should then -update the internal member to reflect the current state. The default -get() implementation does nothing and thus allows to read the value as -set by the last call to setValue(). This makes it possible to use the Variable -class without inheriting. +\agentxcpp{IntegerVariable::v}. This value can be read with value() and +set with setValue(). The perform_get() method is called by the +library when an SNMP Get is requested for the variable. This method should then +update the value to reflect the current state. The default +perform_get() implementation does nothing and thus allows to read the +value as set by the last call to setValue(). This makes it possible to use the +Variable class without inheriting. + +\note It is currently not possible to inhibit Get requests, i.e. it is not + possible to implement write-only variables. \internal -\subsection variables_get_internal How GET requests are handled internally +\subsection variables_get_internal How Get requests are handled internally -When the \agentxcpp{MasterProxy} object receives a GET (or GETNEXT) request, it +When the \agentxcpp{MasterProxy} object receives a Get (or GetNext) request, it looks up the variable registered with the requested OID. This works even for variables which are part of a table, because the \agentxcpp{Table} class registers its variables like any other variable. Then the MasterProxy invokes @@ -65,35 +70,36 @@ object which is then embedded into the response and sent back to the master agent (possibly with further varbinds). The variable's \agentxcpp{AbstractVariable::handle_get()} method is implemented -in the subclasses. It first calls get() to update the internally stored value. -The default implementation of get() does nothing, but can be overridden by -subclasses. +in the subclasses. It first calls perform_get() to update the +internally stored value. The default implementation of perform_get() +does nothing, but can be overridden by subclasses. -\section variables_set How SNMP SET requests are served +\section variables_set How SNMP Set requests are served -Each variable provides the functions testset(), commitset(), -cleanupset() and undoset(), which are called while processing -an SNMP SET request for the variable. Each of these functions takes the new -value as parameter (e.g. an qint32 value for \agentxcpp{IntegerVariable}). The -functions should then act as described in \ref the_set_steps, returning success -or failure. It is not required that the functions update the internal member, -because on SET request, a subagent does not send the new state back to the -master agent. +Each variable provides the functions perform_testset(), +perform_commitset(), perform_cleanupset() and +perform_undoset(), which are called while processing an SNMP Set +request for the variable (see also \ref the_set_steps). Each of these functions +takes the new value as parameter (e.g. an qint32 value for +\agentxcpp{IntegerVariable}). The functions should then act as described in \ref +the_set_steps, returning success or failure. It is not required that the +functions update the internal member, because on Set request a subagent does not +send the new state back to the master agent. -The default implementation of the SET-supporting methods is to fail with +The default implementation of the Set-supporting methods is to fail with \agentxcpp{AbstractVariable::noAccess}, indicating that the variable is read-only. It is required to reimplement the methods in a derived class to enable write support. \cond INTERNAL -\subsection variables_set_internal How SET requests are handled internally +\subsection variables_set_internal How Set requests are handled internally -When the \agentxcpp{MasterProxy} object receives a TESTSET, COMMITSET, -CLEANUPSET or UNDOSET request, it looks up the variable corresponding to the +When the \agentxcpp{MasterProxy} object receives a TestSet, CommitSet, +CleanupSet or UndoSet request, it looks up the variable corresponding to the given OID and calls its \agentxcpp{AbstractVariable::handle_testset()}, \agentxcpp{AbstractVariable::handle_commitset()}, \agentxcpp{AbstractVariable::handle_cleanupset()} or @@ -105,17 +111,19 @@ use. The other three methods then use the stored pointer to obtain access to the new value. In particular, the handle_testset() method converts the pointer to -\agentxcpp{AbstractVariable} into a pointer to the more concrete classe (e.g. -\agentxcpp{Gauge32Variable} and stores it. Then, it calls the testset() method. -The handle_commitset() handle_cleanupset() and -handle_undoset() methods only call commitset(), -cleanupset() and undoset(), respectively. - -The default implementation of testset() returns +\agentxcpp{AbstractVariable} into a pointer to the more concrete class (e.g. +\agentxcpp{Gauge32Variable} and stores it. Then, it calls the +perform_testset() method. The handle_commitset() +handle_cleanupset() and handle_undoset() methods only call +perform_commitset(), perform_cleanupset() and +perform_undoset(), respectively. + +The default implementation of perform_testset() returns \agentxcpp{AbstractVariable::noAccess} to indicate that the variable is -read-only. The method can be overridden by subclasses to enable write support. -The default implementations of commitset(), cleanupset() and -undoset() all return false to indicate an error. +read-only. The method can be overridden by subclasses to enable write support. +The default implementations of perform_commitset(), +perform_cleanupset() and perform_undoset() all return false to +indicate an error. \section variables_serializing_parsing Serializing and Parsing Variables diff --git a/src/AbstractVariable.hpp b/src/AbstractVariable.hpp index 7379bce..fb1ebcf 100644 --- a/src/AbstractVariable.hpp +++ b/src/AbstractVariable.hpp @@ -244,8 +244,6 @@ namespace agentxcpp virtual binary serialize() const = 0; /** - * \internal - * * \brief Convert an INDEX variable to an Oid part. * * If an SNMP variable is used as INDEX within a table, diff --git a/src/Counter32Variable.hpp b/src/Counter32Variable.hpp index 0455fce..914e08a 100644 --- a/src/Counter32Variable.hpp +++ b/src/Counter32Variable.hpp @@ -23,12 +23,7 @@ namespace agentxcpp private: /** - * \brief The new value for the variable in a Set operation. - * - * The Set operation is performed in up to four steps (testset, - * commitset, cleanupset, undoset). Only the testset step actually - * receives the new value. This value is stored here so that it can - * be delivered to commitset(), undoset() and cleanupset(). + * \copydoc agentxcpp::IntegerVariable::new_value */ QSharedPointer new_value; @@ -39,30 +34,14 @@ namespace agentxcpp { } - /** - * \internal - * - * \brief Parse Constructor. - * - * This constructor parses the serialized form of the object. - * It takes an iterator, starts parsing at the position of the - * iterator and advances the iterator to the position right behind - * the object. - * - * The constructor expects valid data from the stream; if parsing - * fails, parse_error is thrown. In this case, the iterator - * position is undefined. + /** + * \internal * - * \param pos Iterator pointing to the current stream position. - * The iterator is advanced while reading the header. - * - * \param end Iterator pointing one element past the end of the - * current stream. This is needed to mark the end of the - * buffer. - * - * \param big_endian Whether the input stream is in big endian - * format - */ + * \copydoc + * agentxcpp::IntegerVariable::IntegerVariable(binary::const_iterator&, + * const binary::const_iterator&, bool) + * + */ Counter32Variable(binary::const_iterator& pos, const binary::const_iterator& end, bool big_endian=true); @@ -76,11 +55,17 @@ namespace agentxcpp */ virtual binary serialize() const; + /** + * \copydoc agentxcpp::IntegerVariable::setValue() + */ void setValue(quint32 _value) { v = _value; } + /* + * \copydoc agentxcpp::IntegerVariable::value() + */ virtual quint32 value() { return v; @@ -89,51 +74,24 @@ namespace agentxcpp /** * \internal * - * \brief Handle a Get Request. - * - * This function calls get() to obtain the new value, - * converts it to QSharedPointer and returns it. + * \copydoc agentxcpp::IntegerVariable::handle_get() */ virtual void handle_get() { - this->get(); + perform_get(); } /** - * \brief Handle a Get request. - * - * This method is called when an SNMP Get request is received. - * It shall - * return the current value of the variable. - * - * \note This method is pure virtual and thus \e must be - * implemented. It is not possible to implement write-only - * SNMP variables. - * - * \return The value of the variable. + * \copydoc agentxcpp::IntegerVariable::perform_get() */ - virtual void get() + virtual void perform_get() { } /** * \internal * - * \brief Handle a TestSet request. - * - * This function converts the argument to QSharedPointer() and - * calls - * testset() with the converted value. If conversion fails, - * testset() is not called. This function also stores the given - * value to the new_value member. - * - * \param _v The new value for the variable. - * - * \return agentxcpp::AbstractVariable::wrongType if the conversion - * fails. Otherwise, - * the result of - * testset() is - * returned. + * \copydoc agentxcpp::IntegerVariable::handle_testet() */ virtual testset_result_t handle_testset(QSharedPointer _v) { @@ -141,7 +99,7 @@ namespace agentxcpp if (new_value) { // Type matches variable - return testset(new_value->value()); + return perform_testset(new_value->value()); } else { @@ -154,22 +112,9 @@ namespace agentxcpp /** * \brief Handle a TestSet request. * - * This method is called when an SNMP TestSet request is received. - * It - * shall check whether a Set operation is possible for the - * variable. It shall acquire the resources needed to perform the - * Set operation (but the Set shall not yet be performed). - * - * The default implementation returns - * agentxcpp::AbstractVariable::noAccess to indicate that - * this is a read-only variable. Thus, for read-only variables this - * method need not be overridden. - * - * \param _v The new value for the object. - * - * \return The result of the check. + * \copydoc agentxcpp::IntegerVariable::perform_testet() */ - virtual testset_result_t testset(quint32 _v) + virtual testset_result_t perform_testset(quint32 _v) { return noAccess; } @@ -177,30 +122,17 @@ namespace agentxcpp /** * \internal * - * \brief Handle a CleanupSet request. - * - * This function calls cleanupset() with the value from the last - * handle_testset() invokation. + * \copydoc agentxcpp::IntegerVariable::handle_cleanupset() */ virtual void handle_cleanupset() { - cleanupset(new_value->value()); + perform_cleanupset(new_value->value()); } /** - * \brief Handle a CleanupSet request. - * - * This method is called when an SNMP CleanupSet request is - * received. It - * shall release any ressources allocated by testset(). - * - * The default implementation does nothing. If no action is - * required to perform the CleanupSet operaiton, this method need - * not be overridden. - * - * \param _v The new value for the object. + * \copydoc agentxcpp::IntegerVariable::perform_cleanupset() */ - virtual void cleanupset(quint32 _v) + virtual void perform_cleanupset(quint32 _v) { return; } @@ -208,32 +140,17 @@ namespace agentxcpp /** * \internal * - * \brief Handle a CommitSet request. - * - * This function calls commitset() with the value from the last - * handle_testset() Invocation and returns its return value. + * \copydoc agentxcpp::IntegerVariable::handle_commitset() */ virtual bool handle_commitset() { - return commitset(new_value->value()); + return perform_commitset(new_value->value()); } /** - * \brief Handle a CommitSet request. - * - * This method is called when an SNMP CommitSet request is - * received. It - * shall perform the actual write operation. - * - * The default implementation returns false to indicate that the - * operation failed. To implement a writable SNMP variable this - * method must be overridden. - * - * \param _v The new value for the object. - * - * \return True if the operation succeeded, false otherwise. + * \copydoc agentxcpp::IntegerVariable::perform_commitset() */ - virtual bool commitset(quint32 _v) + virtual bool perform_commitset(quint32 _v) { return false; } @@ -241,41 +158,17 @@ namespace agentxcpp /** * \internal * - * \brief Handle a UndoSet request. - * - * This function calls undoset() with the value from the last - * handle_testset() invocation and returns its return value. - * + * \copydoc agentxcpp::IntegerVariable::handle_undoset() */ virtual bool handle_undoset() { - return undoset(new_value->value()); + return perform_undoset(new_value->value()); } /** - * \brief Handle an UndoSet request. - * - * This method is called when an SNMP UndoSet request is received. - * It - * shall undo whatever commitset() performed. It shall also release - * all resources allocated by testset(). - * - * The default implementation returns false to indicate that - * the operation failed. It is strongly recommended that writable - * variables override this method. - * - * \internal - * - * A default implementation is provided to allow implementing - * read-only variables. - * - * \endinternal - * - * \param _v The new value for the object. - * - * \return True on success, false otherwise. + * \copydoc agentxcpp::IntegerVariable::perform_undoset() */ - virtual bool undoset(quint32 _v) + virtual bool perform_undoset(quint32 _v) { return false; } diff --git a/src/Counter64Variable.hpp b/src/Counter64Variable.hpp index 99edcf6..62cf67c 100644 --- a/src/Counter64Variable.hpp +++ b/src/Counter64Variable.hpp @@ -23,12 +23,7 @@ namespace agentxcpp private: /** - * \brief The new value for the variable in a Set operation. - * - * The Set operation is performed in up to four steps (testset, - * commitset, cleanupset, undoset). Only the testset step actually - * receives the new value. This value is stored here so that it can - * be delivered to commitset(), undoset() and cleanupset(). + * \copydoc agentxcpp::IntegerVariable::new_value */ QSharedPointer new_value; @@ -42,26 +37,10 @@ namespace agentxcpp /** * \internal * - * \brief Parse Constructor. - * - * This constructor parses the serialized form of the object. - * It takes an iterator, starts parsing at the position of the - * iterator and advances the iterator to the position right behind - * the object. - * - * The constructor expects valid data from the stream; if parsing - * fails, parse_error is thrown. In this case, the iterator - * position is undefined. - * - * \param pos Iterator pointing to the current stream position. - * The iterator is advanced while reading the header. - * - * \param end Iterator pointing one element past the end of the - * current stream. This is needed to mark the end of the - * buffer. + * \copydoc + * agentxcpp::IntegerVariable::IntegerVariable(binary::const_iterator&, + * const binary::const_iterator&, bool) * - * \param big_endian Whether the input stream is in big endian - * format */ Counter64Variable(binary::const_iterator& pos, const binary::const_iterator& end, @@ -76,11 +55,17 @@ namespace agentxcpp */ virtual binary serialize() const; + /** + * \copydoc agentxcpp::IntegerVariable::setValue() + */ void setValue(quint64 _value) { v = _value; } + /* + * \copydoc agentxcpp::IntegerVariable::value() + */ virtual quint64 value() { return v; @@ -89,51 +74,24 @@ namespace agentxcpp /** * \internal * - * \brief Handle a Get Request. - * - * This function calls get() to obtain the new value, - * converts it to QSharedPointer and returns it. + * \copydoc agentxcpp::IntegerVariable::handle_get() */ virtual void handle_get() { - this->get(); + perform_get(); } /** - * \brief Handle a Get request. - * - * This method is called when an SNMP Get request is received. - * It shall - * return the current value of the variable. - * - * \note This method is pure virtual and thus \e must be - * implemented. It is not possible to implement write-only - * SNMP variables. - * - * \return The value of the variable. + * \copydoc agentxcpp::IntegerVariable::perform_get() */ - virtual void get() + virtual void perform_get() { } /** * \internal * - * \brief Handle a TestSet request. - * - * This function converts the argument to QSharedPointer() and - * calls - * testset() with the converted value. If conversion fails, - * testset() is not called. This function also stores the given - * value to the new_value member. - * - * \param _v The new value for the variable. - * - * \return agentxcpp::AbstractVariable::wrongType if the conversion - * fails. Otherwise, - * the result of - * testset() is - * returned. + * \copydoc agentxcpp::IntegerVariable::handle_testet() */ virtual testset_result_t handle_testset(QSharedPointer _v) { @@ -141,7 +99,7 @@ namespace agentxcpp if (new_value) { // Type matches variable - return testset(new_value->value()); + return perform_testset(new_value->value()); } else { @@ -154,22 +112,9 @@ namespace agentxcpp /** * \brief Handle a TestSet request. * - * This method is called when an SNMP TestSet request is received. - * It - * shall check whether a Set operation is possible for the - * variable. It shall acquire the resources needed to perform the - * Set operation (but the Set shall not yet be performed). - * - * The default implementation returns - * agentxcpp::AbstractVariable::noAccess to indicate that - * this is a read-only variable. Thus, for read-only variables this - * method need not be overridden. - * - * \param _v The new value for the object. - * - * \return The result of the check. + * \copydoc agentxcpp::IntegerVariable::perform_testet() */ - virtual testset_result_t testset(quint64 _v) + virtual testset_result_t perform_testset(quint64 _v) { return noAccess; } @@ -177,30 +122,17 @@ namespace agentxcpp /** * \internal * - * \brief Handle a CleanupSet request. - * - * This function calls cleanupset() with the value from the last - * handle_testset() invokation. + * \copydoc agentxcpp::IntegerVariable::handle_cleanupset() */ virtual void handle_cleanupset() { - cleanupset(new_value->value()); + perform_cleanupset(new_value->value()); } /** - * \brief Handle a CleanupSet request. - * - * This method is called when an SNMP CleanupSet request is - * received. It - * shall release any ressources allocated by testset(). - * - * The default implementation does nothing. If no action is - * required to perform the CleanupSet operaiton, this method need - * not be overridden. - * - * \param _v The new value for the object. + * \copydoc agentxcpp::IntegerVariable::perform_cleanupset() */ - virtual void cleanupset(quint64 _v) + virtual void perform_cleanupset(quint64 _v) { return; } @@ -208,32 +140,17 @@ namespace agentxcpp /** * \internal * - * \brief Handle a CommitSet request. - * - * This function calls commitset() with the value from the last - * handle_testset() Invocation and returns its return value. + * \copydoc agentxcpp::IntegerVariable::handle_commitset() */ virtual bool handle_commitset() { - return commitset(new_value->value()); + return perform_commitset(new_value->value()); } /** - * \brief Handle a CommitSet request. - * - * This method is called when an SNMP CommitSet request is - * received. It - * shall perform the actual write operation. - * - * The default implementation returns false to indicate that the - * operation failed. To implement a writable SNMP variable this - * method must be overridden. - * - * \param _v The new value for the object. - * - * \return True if the operation succeeded, false otherwise. + * \copydoc agentxcpp::IntegerVariable::perform_commitset() */ - virtual bool commitset(quint64 _v) + virtual bool perform_commitset(quint64 _v) { return false; } @@ -241,41 +158,17 @@ namespace agentxcpp /** * \internal * - * \brief Handle a UndoSet request. - * - * This function calls undoset() with the value from the last - * handle_testset() invocation and returns its return value. - * + * \copydoc agentxcpp::IntegerVariable::handle_undoset() */ virtual bool handle_undoset() { - return undoset(new_value->value()); + return perform_undoset(new_value->value()); } /** - * \brief Handle an UndoSet request. - * - * This method is called when an SNMP UndoSet request is received. - * It - * shall undo whatever commitset() performed. It shall also release - * all resources allocated by testset(). - * - * The default implementation returns false to indicate that - * the operation failed. It is strongly recommended that writable - * variables override this method. - * - * \internal - * - * A default implementation is provided to allow implementing - * read-only variables. - * - * \endinternal - * - * \param _v The new value for the object. - * - * \return True on success, false otherwise. + * \copydoc agentxcpp::IntegerVariable::perform_undoset() */ - virtual bool undoset(quint64 _v) + virtual bool perform_undoset(quint64 _v) { return false; } diff --git a/src/Gauge32Variable.hpp b/src/Gauge32Variable.hpp index 078c8f0..555f464 100644 --- a/src/Gauge32Variable.hpp +++ b/src/Gauge32Variable.hpp @@ -44,12 +44,7 @@ namespace agentxcpp private: /** - * \brief The new value for the variable in a Set operation. - * - * The Set operation is performed in up to four steps (testset, - * commitset, cleanupset, undoset). Only the testset step actually - * receives the new value. This value is stored here so that it can - * be delivered to commitset(), undoset() and cleanupset(). + * \copydoc agentxcpp::IntegerVariable::new_value */ QSharedPointer new_value; @@ -70,27 +65,11 @@ namespace agentxcpp /** * \internal + * + * \copydoc + * agentxcpp::IntegerVariable::IntegerVariable(binary::const_iterator&, + * const binary::const_iterator&, bool) * - * \brief Parse Constructor. - * - * This constructor parses the serialized form of the object. - * It takes an iterator, starts parsing at the position of the - * iterator and advances the iterator to the position right behind - * the object. - * - * The constructor expects valid data from the stream; if parsing - * fails, parse_error is thrown. In this case, the iterator - * position is undefined. - * - * \param pos Iterator pointing to the current stream position. - * The iterator is advanced while reading the header. - * - * \param end Iterator pointing one element past the end of the - * current stream. This is needed to mark the end of the - * buffer. - * - * \param big_endian Whether the input stream is in big endian - * format */ Gauge32Variable(binary::const_iterator& pos, const binary::const_iterator& end, @@ -105,11 +84,17 @@ namespace agentxcpp */ virtual binary serialize() const; - void setValue(quint32 _v) + /** + * \copydoc agentxcpp::IntegerVariable::setValue() + */ + void setValue(quint32 _value) { - v = _v; + v = _value; } + /* + * \copydoc agentxcpp::IntegerVariable::value() + */ quint32 value() { return v; @@ -118,51 +103,24 @@ namespace agentxcpp /** * \internal * - * \brief Handle a Get Request. - * - * This function calls get() to obtain the new value, - * converts it to QSharedPointer and returns it. + * \copydoc agentxcpp::IntegerVariable::handle_get() */ virtual void handle_get() { - this->get(); + perform_get(); } /** - * \brief Handle a Get request. - * - * This method is called when an SNMP Get request is received. - * It shall - * return the current value of the variable. - * - * \note This method is pure virtual and thus \e must be - * implemented. It is not possible to implement write-only - * SNMP variables. - * - * \return The value of the variable. + * \copydoc agentxcpp::IntegerVariable::perform_get() */ - virtual void get() + virtual void perform_get() { } /** * \internal * - * \brief Handle a TestSet request. - * - * This function converts the argument to QSharedPointer() and - * calls - * testset() with the converted value. If conversion fails, - * testset() is not called. This function also stores the given - * value to the new_value member. - * - * \param _v The new value for the variable. - * - * \return agentxcpp::AbstractVariable::wrongType if the conversion - * fails. Otherwise, - * the result of - * testset() is - * returned. + * \copydoc agentxcpp::IntegerVariable::handle_testet() */ virtual testset_result_t handle_testset(QSharedPointer _v) { @@ -170,7 +128,7 @@ namespace agentxcpp if (new_value) { // Type matches variable - return testset(new_value->value()); + return perform_testset(new_value->value()); } else { @@ -183,22 +141,9 @@ namespace agentxcpp /** * \brief Handle a TestSet request. * - * This method is called when an SNMP TestSet request is received. - * It - * shall check whether a Set operation is possible for the - * variable. It shall acquire the resources needed to perform the - * Set operation (but the Set shall not yet be performed). - * - * The default implementation returns - * agentxcpp::AbstractVariable::noAccess to indicate that - * this is a read-only variable. Thus, for read-only variables this - * method need not be overridden. - * - * \param _v The new value for the object. - * - * \return The result of the check. + * \copydoc agentxcpp::IntegerVariable::perform_testet() */ - virtual testset_result_t testset(quint32 _v) + virtual testset_result_t perform_testset(quint32 _v) { return noAccess; } @@ -206,30 +151,17 @@ namespace agentxcpp /** * \internal * - * \brief Handle a CleanupSet request. - * - * This function calls cleanupset() with the value from the last - * handle_testset() invokation. + * \copydoc agentxcpp::IntegerVariable::handle_cleanupset() */ virtual void handle_cleanupset() { - cleanupset(new_value->value()); + perform_cleanupset(new_value->value()); } /** - * \brief Handle a CleanupSet request. - * - * This method is called when an SNMP CleanupSet request is - * received. It - * shall release any ressources allocated by testset(). - * - * The default implementation does nothing. If no action is - * required to perform the CleanupSet operaiton, this method need - * not be overridden. - * - * \param _v The new value for the object. + * \copydoc agentxcpp::IntegerVariable::perform_cleanupset() */ - virtual void cleanupset(quint32 _v) + virtual void perform_cleanupset(quint32 _v) { return; } @@ -237,32 +169,17 @@ namespace agentxcpp /** * \internal * - * \brief Handle a CommitSet request. - * - * This function calls commitset() with the value from the last - * handle_testset() Invocation and returns its return value. + * \copydoc agentxcpp::IntegerVariable::handle_commitset() */ virtual bool handle_commitset() { - return commitset(new_value->value()); + return perform_commitset(new_value->value()); } /** - * \brief Handle a CommitSet request. - * - * This method is called when an SNMP CommitSet request is - * received. It - * shall perform the actual write operation. - * - * The default implementation returns false to indicate that the - * operation failed. To implement a writable SNMP variable this - * method must be overridden. - * - * \param _v The new value for the object. - * - * \return True if the operation succeeded, false otherwise. + * \copydoc agentxcpp::IntegerVariable::perform_commitset() */ - virtual bool commitset(quint32 _v) + virtual bool perform_commitset(quint32 _v) { return false; } @@ -270,41 +187,17 @@ namespace agentxcpp /** * \internal * - * \brief Handle a UndoSet request. - * - * This function calls undoset() with the value from the last - * handle_testset() invocation and returns its return value. - * + * \copydoc agentxcpp::IntegerVariable::handle_undoset() */ virtual bool handle_undoset() { - return undoset(new_value->value()); + return perform_undoset(new_value->value()); } /** - * \brief Handle an UndoSet request. - * - * This method is called when an SNMP UndoSet request is received. - * It - * shall undo whatever commitset() performed. It shall also release - * all resources allocated by testset(). - * - * The default implementation returns false to indicate that - * the operation failed. It is strongly recommended that writable - * variables override this method. - * - * \internal - * - * A default implementation is provided to allow implementing - * read-only variables. - * - * \endinternal - * - * \param _v The new value for the object. - * - * \return True on success, false otherwise. + * \copydoc agentxcpp::IntegerVariable::perform_undoset() */ - virtual bool undoset(quint32 _v) + virtual bool perform_undoset(quint32 _v) { return false; } diff --git a/src/IntegerVariable.hpp b/src/IntegerVariable.hpp index 519b555..4b3e905 100644 --- a/src/IntegerVariable.hpp +++ b/src/IntegerVariable.hpp @@ -29,27 +29,44 @@ namespace agentxcpp { /** - * \brief Represents an Integer as described in RFC 2741. + * \brief This class represents an Integer variable as described in RFC + * 2741. + * + * The page \ref variables explains how to use variables. + * + * \note When an IntegerVariable is used as INDEX within a table, it should + * never hold the value 0. This is because the value is then used as + * part of an OID, where 0 is forbidden (or at least discouraged). */ class IntegerVariable : public AbstractVariable { protected: /** - * \brief The Integer value. + * \brief The current value. * - * According to RFC 2578, INTEGER is a signed 32-bit number. - */ + * This is the value which is sent to the master agent on SNMP Get + * requests. According to RFC 2578, INTEGER is a signed 32-bit + * number. The value can be obtained with value() and set with + * setValue(). + * + * The perform_get() method should update this member. + * + * The methods perform_testset(), perform_commitset(), + * perform_cleanupset() and/or perform_undoset() may update this + * member, but it is not needed for proper function. + */ qint32 v; private: /** - * \brief The new value for the variable in a Set operation. + * \brief The new value for the variable. Used during a Set + * operation. * - * The Set operation is performed in up to four steps (testset, - * commitset, cleanupset, undoset). Only the testset step actually + * The Set operation is performed in up to four steps (perform_testset, + * perform_commitset, perform_cleanupset, perform_undoset). Only the perform_testset step actually * receives the new value. This value is stored here so that it can - * be delivered to commitset(), undoset() and cleanupset(). + * be delivered to perform_commitset(), perform_undoset() and perform_cleanupset(). */ QSharedPointer new_value; @@ -58,9 +75,9 @@ namespace agentxcpp /** * \internal * - * \brief Create an IntegerValue object. - * - * The default value of the new object is 0. + * \brief Constructor. + * + * Creates an IntegerValue object. * * \exception None. */ @@ -69,12 +86,13 @@ namespace agentxcpp /** * \internal * - * \brief Encode the object as described in RFC 2741, section 5.4 + * \brief Encode the object as described in RFC 2741, section + * 5.4. * * This function uses big endian. */ virtual binary serialize() const; - + /** * \internal * @@ -90,21 +108,21 @@ namespace agentxcpp * position is undefined. * * \param pos Iterator pointing to the current stream position. - * The iterator is advanced while reading the header. + * The iterator is advanced while parsing. * * \param end Iterator pointing one element past the end of the - * current stream. This is needed to mark the end of the - * buffer. + * current stream. This is needed to avoid buffer + * overrun. * * \param big_endian Whether the input stream is in big endian - * format + * format. */ IntegerVariable(binary::const_iterator& pos, const binary::const_iterator& end, bool big_endian=true); /** - * \brief Convert the value to an OID. + * \brief Convert the value to an OID. * * The conversion is done according to RFC 2578, * 7.7. "Mapping of the INDEX clause". The value is @@ -112,6 +130,8 @@ namespace agentxcpp * INTEGER values are signed, while subids are not. * A negative value with be converted to a big unsigned * subid. + * + * This method should not be overridden. * * \note If an INTEGER is used in an INDEX clause, the * value 0 should be avoided according to @@ -124,11 +144,21 @@ namespace agentxcpp return oid; } + /** + * \brief Set the value. + * + * \param _value The new value. + */ void setValue(qint32 _value) { v = _value; } + /** + * \brief Get the current value. + * + * \return The new value. + */ qint32 value() { return v; @@ -139,28 +169,22 @@ namespace agentxcpp * * \brief Handle a Get Request. * - * This function calls get() to obtain the new value, - * converts it to QSharedPointer and returns it. + * This function calls perform_get() to update the internal + * value. */ virtual void handle_get() { - this->get(); + perform_get(); } /** - * \brief Handle a Get request. - * - * This method is called when an SNMP Get request is received. - * It shall - * return the current value of the variable. + * \brief Perform a Get request. * - * \note This method is pure virtual and thus \e must be - * implemented. It is not possible to implement write-only - * SNMP variables. - * - * \return The value of the variable. + * This method is invoked when an SNMP Get request is received. + * It should update the internal value + * \agentxcpp{IntegerVariable::v}. */ - virtual void get() + virtual void perform_get() { } @@ -169,19 +193,19 @@ namespace agentxcpp * * \brief Handle a TestSet request. * - * This function converts the argument to QSharedPointer() and - * calls - * testset() with the converted value. If conversion fails, - * testset() is not called. This function also stores the given - * value to the new_value member. + * This function converts the argument to + * QSharedPointer, stores it in + * \agentxcpp{IntegerVariable::new_value} and then calls perform_testset() + * with the internal value of + * \agentxcpp{IntegerVariable::new_value}. If conversion fails, + * \agentxcpp{AbstractVariable::wrongType} is returned and + * perform_testset() is not called. * * \param _v The new value for the variable. * - * \return agentxcpp::AbstractVariable::wrongType if the conversion - * fails. Otherwise, - * the result of - * testset() is - * returned. + * \return \agentxcpp{AbstractVariable::wrongType} + * if the conversion fails. Otherwise, the result of + * perform_testset() is returned. */ virtual testset_result_t handle_testset(QSharedPointer _v) { @@ -189,7 +213,7 @@ namespace agentxcpp if (new_value) { // Type matches variable - return testset(new_value->value()); + return perform_testset(new_value->value()); } else { @@ -200,24 +224,26 @@ namespace agentxcpp } /** - * \brief Handle a TestSet request. + * \brief Perform an SNMP TestSet request. * - * This method is called when an SNMP TestSet request is received. - * It - * shall check whether a Set operation is possible for the + * This method is invoked when an SNMP TestSet request is + * received. + * It shall check whether a Set operation is possible for the * variable. It shall acquire the resources needed to perform the - * Set operation (but the Set shall not yet be performed). + * Set operation (but the Set operation shall not yet be + * performed). * - * The default implementation returns - * agentxcpp::AbstractVariable::noAccess to indicate that + * The default implementation returns + * \agentxcpp{AbstractVariable::noAccess} to indicate that * this is a read-only variable. Thus, for read-only variables this * method need not be overridden. * - * \param _v The new value for the object. + * \param _v The new value provided by the master agent. * - * \return The result of the check. + * \return The result of the check (this is reported to the master + * agent). */ - virtual testset_result_t testset(qint32 _v) + virtual testset_result_t perform_testset(qint32 _v) { return noAccess; } @@ -227,28 +253,31 @@ namespace agentxcpp * * \brief Handle a CleanupSet request. * - * This function calls cleanupset() with the value from the last - * handle_testset() invokation. + * This function calls perform_cleanupset() with the internal value of \ref + * agentxcpp::IntegerVariable::new_value "new_value" (which was + * updated by the last \ref + * agentxcpp::IntegerVariable::handle_testset() "handle_testset()" + * invocation). */ virtual void handle_cleanupset() { - cleanupset(new_value->value()); + perform_cleanupset(new_value->value()); } /** - * \brief Handle a CleanupSet request. + * \brief Perform an SNMP CleanupSet request. * - * This method is called when an SNMP CleanupSet request is - * received. It - * shall release any ressources allocated by testset(). + * This method is invoked when an SNMP CleanupSet request is + * received. It shall release any resources allocated by + * perform_testset(). * * The default implementation does nothing. If no action is * required to perform the CleanupSet operation, this method need * not be overridden. * - * \param _v The new value for the object. + * \param _v The value to which the variable was (possibly) set. */ - virtual void cleanupset(qint32 _v) + virtual void perform_cleanupset(qint32 _v) { return; } @@ -258,30 +287,35 @@ namespace agentxcpp * * \brief Handle a CommitSet request. * - * This function calls commitset() with the value from the last - * handle_testset() Invocation and returns its return value. + * This function calls \ref agentxcpp::IntegerVariable::perform_commitset() + * "perform_commitset()" with the internal value of \ref + * agentxcpp::IntegerVariable::new_value "new_value" (which was + * updated by the last \ref + * agentxcpp::IntegerVariable::handle_testset() "handle_testset()" + * invocation). + * + * \return The return value of perform_commitset(). */ virtual bool handle_commitset() { - return commitset(new_value->value()); + return perform_commitset(new_value->value()); } /** - * \brief Handle a CommitSet request. + * \brief Perform an SNMP CommitSet request. * - * This method is called when an SNMP CommitSet request is - * received. It - * shall perform the actual write operation. + * This method is invoked when an SNMP CommitSet request is + * received. It shall perform the actual write operation. * * The default implementation returns false to indicate that the - * operation failed. To implement a writable SNMP variable this + * operation failed. To implement a writeable SNMP variable this * method must be overridden. * - * \param _v The new value for the object. + * \param _v The value which shall be written. * * \return True if the operation succeeded, false otherwise. */ - virtual bool commitset(qint32 _v) + virtual bool perform_commitset(qint32 _v) { return false; } @@ -291,25 +325,31 @@ namespace agentxcpp * * \brief Handle a UndoSet request. * - * This function calls undoset() with the value from the last - * handle_testset() invocation and returns its return value. + * This function calls perform_undoset() with the internal value of \ref + * agentxcpp::IntegerVariable::new_value "new_value" (which was + * updated by the last \ref + * agentxcpp::IntegerVariable::handle_testset() "handle_testset()" + * invocation). + * + * \return The return value of perform_undoset(). * */ virtual bool handle_undoset() { - return undoset(new_value->value()); + return perform_undoset(new_value->value()); } /** - * \brief Handle an UndoSet request. + * \brief Perform an SNMP UndoSet request. * - * This method is called when an SNMP UndoSet request is received. - * It - * shall undo whatever commitset() performed. It shall also release - * all resources allocated by testset(). + * This method is invoked when an SNMP UndoSet request is + * received. + * It shall undo whatever perform_commitset() performed. It shall also + * release all resources allocated by perform_testset(), because + * perform_cleanupset() \e will \e not be called afterwards. * * The default implementation returns false to indicate that - * the operation failed. It is strongly recommended that writable + * the operation failed. It is strongly recommended that writeable * variables override this method. * * \internal @@ -319,16 +359,14 @@ namespace agentxcpp * * \endinternal * - * \param _v The new value for the object. + * \param _v The value just set by perform_commitset(). * * \return True on success, false otherwise. */ - virtual bool undoset(qint32 _v) + virtual bool perform_undoset(qint32 _v) { return false; } - - }; } diff --git a/src/IpAddressVariable.hpp b/src/IpAddressVariable.hpp index 494853c..45f3dcf 100644 --- a/src/IpAddressVariable.hpp +++ b/src/IpAddressVariable.hpp @@ -47,40 +47,19 @@ namespace agentxcpp quint8 address[4]; // only IPv4 /** - * \brief The new value for the variable in a Set operation. - * - * The Set operation is performed in up to four steps (testset, - * commitset, cleanupset, undoset). Only the testset step actually - * receives the new value. This value is stored here so that it can - * be delivered to commitset(), undoset() and cleanupset(). + * \copydoc agentxcpp::IntegerVariable::new_value */ QSharedPointer new_value; public: - /** - * \internal - * - * \brief Parse Constructor. - * - * This constructor parses the serialized form of the object. - * It takes an iterator, starts parsing at the position of the - * iterator and advances the iterator to the position right behind - * the object. - * - * The constructor expects valid data from the stream; if parsing - * fails, parse_error is thrown. In this case, the iterator - * position is undefined. - * - * \param pos Iterator pointing to the current stream position. - * The iterator is advanced while reading the header. - * - * \param end Iterator pointing one element past the end of the - * current stream. This is needed to mark the end of the - * buffer. - * - * \param big_endian Whether the input stream is in big endian - * format - */ + /** + * \internal + * + * \copydoc + * agentxcpp::IntegerVariable::IntegerVariable(binary::const_iterator&, + * const binary::const_iterator&, bool) + * + */ IpAddressVariable(binary::const_iterator& pos, const binary::const_iterator& end, bool big_endian=true); @@ -114,8 +93,9 @@ namespace agentxcpp address[3] = d; } + /** - * \brief Set the IpAddress. + * \brief Set the value. * * The stored IpAddress is updated to "a.b.c.d". * @@ -177,51 +157,24 @@ namespace agentxcpp /** * \internal * - * \brief Handle a Get Request. - * - * This function calls get() to obtain the new value, - * converts it to QSharedPointer and returns it. + * \copydoc agentxcpp::IntegerVariable::handle_get() */ virtual void handle_get() { - this->get(); + perform_get(); } /** - * \brief Handle a Get request. - * - * This method is called when an SNMP Get request is received. - * It shall - * return the current value of the variable. - * - * \note This method is pure virtual and thus \e must be - * implemented. It is not possible to implement write-only - * SNMP variables. - * - * \return The value of the variable. + * \copydoc agentxcpp::IntegerVariable::perform_get() */ - virtual void get() + virtual void perform_get() { } /** * \internal * - * \brief Handle a TestSet request. - * - * This function converts the argument to QSharedPointer() and - * calls - * testset() with the converted value. If conversion fails, - * testset() is not called. This function also stores the given - * value to the new_value member. - * - * \param _v The new value for the variable. - * - * \return agentxcpp::AbstractVariable::wrongType if the conversion - * fails. Otherwise, - * the result of - * testset() is - * returned. + * \copydoc agentxcpp::IntegerVariable::handle_testet() */ virtual testset_result_t handle_testset(QSharedPointer _v) { @@ -229,7 +182,7 @@ namespace agentxcpp if (new_value) { // Type matches variable - return testset(new_value->address); + return perform_testset(new_value->address); } else { @@ -242,22 +195,9 @@ namespace agentxcpp /** * \brief Handle a TestSet request. * - * This method is called when an SNMP TestSet request is received. - * It - * shall check whether a Set operation is possible for the - * variable. It shall acquire the resources needed to perform the - * Set operation (but the Set shall not yet be performed). - * - * The default implementation returns - * agentxcpp::AbstractVariable::noAccess to indicate that - * this is a read-only variable. Thus, for read-only variables this - * method need not be overridden. - * - * \param _v The new value for the object. - * - * \return The result of the check. + * \copydoc agentxcpp::IntegerVariable::perform_testet() */ - virtual testset_result_t testset(const quint8 _v[4]) + virtual testset_result_t perform_testset(const quint8 _v[4]) { return noAccess; } @@ -265,30 +205,17 @@ namespace agentxcpp /** * \internal * - * \brief Handle a CleanupSet request. - * - * This function calls cleanupset() with the value from the last - * handle_testset() invokation. + * \copydoc agentxcpp::IntegerVariable::handle_cleanupset() */ virtual void handle_cleanupset() { - cleanupset(new_value->address); + perform_cleanupset(new_value->address); } /** - * \brief Handle a CleanupSet request. - * - * This method is called when an SNMP CleanupSet request is - * received. It - * shall release any ressources allocated by testset(). - * - * The default implementation does nothing. If no action is - * required to perform the CleanupSet operaiton, this method need - * not be overridden. - * - * \param _v The new value for the object. + * \copydoc agentxcpp::IntegerVariable::perform_cleanupset() */ - virtual void cleanupset(const quint8 _v[4]) + virtual void perform_cleanupset(const quint8 _v[4]) { return; } @@ -296,32 +223,17 @@ namespace agentxcpp /** * \internal * - * \brief Handle a CommitSet request. - * - * This function calls commitset() with the value from the last - * handle_testset() Invocation and returns its return value. + * \copydoc agentxcpp::IntegerVariable::handle_commitset() */ virtual bool handle_commitset() { - return commitset(new_value->address); + return perform_commitset(new_value->address); } /** - * \brief Handle a CommitSet request. - * - * This method is called when an SNMP CommitSet request is - * received. It - * shall perform the actual write operation. - * - * The default implementation returns false to indicate that the - * operation failed. To implement a writable SNMP variable this - * method must be overridden. - * - * \param _v The new value for the object. - * - * \return True if the operation succeeded, false otherwise. + * \copydoc agentxcpp::IntegerVariable::perform_commitset() */ - virtual bool commitset(const quint8 _v[4]) + virtual bool perform_commitset(const quint8 _v[4]) { return false; } @@ -329,41 +241,17 @@ namespace agentxcpp /** * \internal * - * \brief Handle a UndoSet request. - * - * This function calls undoset() with the value from the last - * handle_testset() invocation and returns its return value. - * + * \copydoc agentxcpp::IntegerVariable::handle_undoset() */ virtual bool handle_undoset() { - return undoset(new_value->address); + return perform_undoset(new_value->address); } /** - * \brief Handle an UndoSet request. - * - * This method is called when an SNMP UndoSet request is received. - * It - * shall undo whatever commitset() performed. It shall also release - * all resources allocated by testset(). - * - * The default implementation returns false to indicate that - * the operation failed. It is strongly recommended that writable - * variables override this method. - * - * \internal - * - * A default implementation is provided to allow implementing - * read-only variables. - * - * \endinternal - * - * \param _v The new value for the object. - * - * \return True on success, false otherwise. + * \copydoc agentxcpp::IntegerVariable::perform_undoset() */ - virtual bool undoset(const quint8 _v[4]) + virtual bool perform_undoset(const quint8 _v[4]) { return false; } diff --git a/src/MasterProxy.hpp b/src/MasterProxy.hpp index 7bef138..9f58882 100644 --- a/src/MasterProxy.hpp +++ b/src/MasterProxy.hpp @@ -482,7 +482,7 @@ namespace agentxcpp * to RFC 1907, which says: "The time (in * hundreths of a second) since the network * management portion of the system was last - * re-initialized.". You can use You can use + * re-initialized.". You can use * agentxcpp::processUpTime() to get the uptime of * the current process. If the NULL pointer * is given, the sysUpTime.0 will not be included diff --git a/src/OctetStringVariable.hpp b/src/OctetStringVariable.hpp index a10be77..950432b 100644 --- a/src/OctetStringVariable.hpp +++ b/src/OctetStringVariable.hpp @@ -24,6 +24,9 @@ namespace agentxcpp private: + /** + * \copydoc agentxcpp::IntegerVariable::new_value + */ QSharedPointer new_value; public: @@ -41,7 +44,7 @@ namespace agentxcpp * \brief Construct object from binary data. */ OctetStringVariable(binary _value = binary()) - : v(_value) + : v(_value) { } @@ -53,46 +56,30 @@ namespace agentxcpp /** * \internal * - * \brief Parse Constructor. - * - * This constructor parses the serialized form of the object. - * It takes an iterator, starts parsing at the position of the - * iterator and advances the iterator to the position right behind - * the object. - * - * The constructor expects valid data from the stream; if parsing - * fails, parse_error is thrown. In this case, the iterator - * position is undefined. - * - * \param pos Iterator pointing to the current stream position. - * The iterator is advanced while reading the header. + * \copydoc + * agentxcpp::IntegerVariable::IntegerVariable(binary::const_iterator&, + * const binary::const_iterator&, bool) * - * \param end Iterator pointing one element past the end of the - * current stream. This is needed to mark the end of the - * buffer. - * - * \param big_endian Whether the input stream is in big endian - * format */ OctetStringVariable(binary::const_iterator& pos, const binary::const_iterator& end, bool big_endian=true); /** - * \brief Set the current value. + * \copydoc agentxcpp::IntegerVariable::setValue() */ - void setValue(binary new_value) + void setValue(binary _value) { - v = new_value; + v = _value; } /** * \brief Set the current value. */ - void setValue(QString new_value); + void setValue(QString _value); - /** - * \brief Get the current value + /* + * \copydoc agentxcpp::IntegerVariable::value() */ binary value() const { @@ -120,48 +107,24 @@ namespace agentxcpp /** * \internal * - * \brief Handle a Get Request. + * \copydoc agentxcpp::IntegerVariable::handle_get() */ virtual void handle_get() { - this->get(); + perform_get(); } /** - * \brief Handle a Get request. - * - * This method is called when an SNMP Get request is received. - * It shall - * return the current value of the variable. - * - * \note This method is pure virtual and thus \e must be - * implemented. It is not possible to implement write-only - * SNMP variables. - * - * \return The value of the variable. + * \copydoc agentxcpp::IntegerVariable::perform_get() */ - virtual void get() + virtual void perform_get() { } /** * \internal * - * \brief Handle a TestSet request. - * - * This function converts the argument to QSharedPointer() and - * calls - * testset() with the converted value. If conversion fails, - * testset() is not called. This function also stores the given - * value to the new_value member. - * - * \param _v The new value for the variable. - * - * \return agentxcpp::AbstractVariable::wrongType if the conversion - * fails. Otherwise, - * the result of - * testset() is - * returned. + * \copydoc agentxcpp::IntegerVariable::handle_testet() */ virtual testset_result_t handle_testset(QSharedPointer _v) { @@ -169,7 +132,7 @@ namespace agentxcpp if (new_value) { // Type matches variable - return testset(new_value->value()); + return perform_testset(new_value->value()); } else { @@ -182,22 +145,9 @@ namespace agentxcpp /** * \brief Handle a TestSet request. * - * This method is called when an SNMP TestSet request is received. - * It - * shall check whether a Set operation is possible for the - * variable. It shall acquire the resources needed to perform the - * Set operation (but the Set shall not yet be performed). - * - * The default implementation returns - * agentxcpp::AbstractVariable::noAccess to indicate that - * this is a read-only variable. Thus, for read-only variables this - * method need not be overridden. - * - * \param _v The new value for the object. - * - * \return The result of the check. + * \copydoc agentxcpp::IntegerVariable::perform_testet() */ - virtual testset_result_t testset(const binary& _v) + virtual testset_result_t perform_testset(const binary& _v) { return noAccess; } @@ -205,30 +155,17 @@ namespace agentxcpp /** * \internal * - * \brief Handle a CleanupSet request. - * - * This function calls cleanupset() with the value from the last - * handle_testset() invokation. + * \copydoc agentxcpp::IntegerVariable::handle_cleanupset() */ virtual void handle_cleanupset() { - cleanupset(new_value->value()); + perform_cleanupset(new_value->value()); } /** - * \brief Handle a CleanupSet request. - * - * This method is called when an SNMP CleanupSet request is - * received. It - * shall release any ressources allocated by testset(). - * - * The default implementation does nothing. If no action is - * required to perform the CleanupSet operaiton, this method need - * not be overridden. - * - * \param _v The new value for the object. + * \copydoc agentxcpp::IntegerVariable::perform_cleanupset() */ - virtual void cleanupset(const binary& _v) + virtual void perform_cleanupset(const binary& _v) { return; } @@ -236,32 +173,17 @@ namespace agentxcpp /** * \internal * - * \brief Handle a CommitSet request. - * - * This function calls commitset() with the value from the last - * handle_testset() Invocation and returns its return value. + * \copydoc agentxcpp::IntegerVariable::handle_commitset() */ virtual bool handle_commitset() { - return commitset(new_value->value()); + return perform_commitset(new_value->value()); } /** - * \brief Handle a CommitSet request. - * - * This method is called when an SNMP CommitSet request is - * received. It - * shall perform the actual write operation. - * - * The default implementation returns false to indicate that the - * operation failed. To implement a writable SNMP variable this - * method must be overridden. - * - * \param _v The new value for the object. - * - * \return True if the operation succeeded, false otherwise. + * \copydoc agentxcpp::IntegerVariable::perform_commitset() */ - virtual bool commitset(const binary& _v) + virtual bool perform_commitset(const binary& _v) { return false; } @@ -269,41 +191,17 @@ namespace agentxcpp /** * \internal * - * \brief Handle a UndoSet request. - * - * This function calls undoset() with the value from the last - * handle_testset() invocation and returns its return value. - * + * \copydoc agentxcpp::IntegerVariable::handle_undoset() */ virtual bool handle_undoset() { - return undoset(new_value->value()); + return perform_undoset(new_value->value()); } /** - * \brief Handle an UndoSet request. - * - * This method is called when an SNMP UndoSet request is received. - * It - * shall undo whatever commitset() performed. It shall also release - * all resources allocated by testset(). - * - * The default implementation returns false to indicate that - * the operation failed. It is strongly recommended that writable - * variables override this method. - * - * \internal - * - * A default implementation is provided to allow implementing - * read-only variables. - * - * \endinternal - * - * \param _v The new value for the object. - * - * \return True on success, false otherwise. + * \copydoc agentxcpp::IntegerVariable::perform_undoset() */ - virtual bool undoset(const binary& _v) + virtual bool perform_undoset(const binary& _v) { return false; } diff --git a/src/OidVariable.hpp b/src/OidVariable.hpp index 52b0fcd..a59cc20 100644 --- a/src/OidVariable.hpp +++ b/src/OidVariable.hpp @@ -40,188 +40,123 @@ namespace agentxcpp */ class OidVariable: public AbstractVariable { - private: + private: /** * \brief The value represented by this variable. */ - Oid mValue; + Oid mValue; /** - * \brief The new value for the variable in a Set operation. - * - * The Set operation is performed in up to four steps (testset, - * commitset, cleanupset, undoset). Only the testset step actually - * receives the new value. This value is stored here so that it can - * be delivered to commitset(), undoset() and cleanupset(). + * \copydoc agentxcpp::IntegerVariable::new_value */ QSharedPointer new_value; - public: + public: - /** - * \brief Initialize an OidVariable object with an Oid. - * - * The internal value is set to the provided Oid. + /** + * \brief Initialize an OidVariable object with an Oid. * - * \param o The initial Oid. - * - * \exception None. - */ - OidVariable(const Oid& o); - - /** - * \brief Get the value. - * - * \return The internal value. - * - * \exception None. - */ - Oid value() - { - return mValue; - } - - /** - * \brief Set the value. - * - * \param o The new value. - * - * \exception None. - */ - void setValue(const Oid& o) - { - mValue = o; - } - - /** - * \internal - * - * \brief Encode an OID object as described in RFC 2741, - * section 5.1. - * - * \todo Maybe this function should move to the Oid class? - */ - binary serialize() const; - - /** - * \internal - * - * \brief Parse Constructor. - * - * This constructor parses the serialized form of the object. - * It takes an iterator, starts parsing at the position of the - * iterator and advances the iterator to the position right behind - * the object. - * - * The constructor expects valid data from the stream; if parsing - * fails, parse_error is thrown. In this case, the iterator is left - * at an undefined position. - * - * \param pos Iterator pointing to the current stream position. - * The iterator is advanced while reading the header. - * - * \param end Iterator pointing one element past the end of the - * current stream. This is needed to mark the end of the - * buffer. - * - * \param big_endian Whether the input stream is in big endian - * format - * - * \exception parse_error If parsing fails. In this case, the - * iterator is left at an undefined - * position. - * - * \todo Maybe this function should move to the Oid class? - * - */ - OidVariable(binary::const_iterator& pos, - const binary::const_iterator& end, - bool big_endian=true); - - /** - * \brief Convert the value to an OID. - * - * The conversion is done according to RFC 2578, - * 7.7. "Mapping of the INDEX clause". First, the - * length of the OID (i.e. the number of subid's it has) is - * converted to a subid. Then, each subid of the value is appended. - * - * \todo Support fixed-length OIDs according to RFC 2578, - * 7.7. "Mapping of the INDEX clause". - * - * \return The generated Oid. - * - * \exception None. - */ - virtual Oid toOid() const - { - // fixed length currently unsupported: - bool fixedLength = false; - - Oid oid; - - // Store length if needed - if(!fixedLength) - { - oid.push_back(mValue.size()); - } - - // Store value - oid += mValue; - - return oid; - } + * The internal value is set to the provided Oid. + * + * \param o The initial Oid. + * + * \exception None. + */ + OidVariable(const Oid& o); + + /* + * \copydoc agentxcpp::IntegerVariable::value() + */ + Oid value() + { + return mValue; + } + + /** + * \copydoc agentxcpp::IntegerVariable::setValue() + */ + void setValue(const Oid& _value) + { + mValue = _value; + } /** * \internal * - * \brief Handle a Get Request. + * \brief Encode the object as described in RFC 2741, section 5.4 * - * This function calls get() to update the internal value, - * converts it to QSharedPointer and returns it. + * This function uses big endian. */ - virtual void handle_get() - { - this->get(); - } + binary serialize() const; /** - * \brief Handle a Get request. + * \internal * - * This method is called when an SNMP Get request is received. - * It shall update internal value of the variable. + * \copydoc + * agentxcpp::IntegerVariable::IntegerVariable(binary::const_iterator&, + * const binary::const_iterator&, bool) * - * \note This method is pure virtual and thus \e must be - * implemented. It is not possible to implement write-only - * SNMP variables. + */ + OidVariable(binary::const_iterator& pos, + const binary::const_iterator& end, + bool big_endian=true); + + /** + * \brief Convert the value to an OID. * - * \return The value of the variable. + * The conversion is done according to RFC 2578, + * 7.7. "Mapping of the INDEX clause". First, the + * length of the OID (i.e. the number of subid's it has) is + * converted to a subid. Then, each subid of the value is appended. + * + * \todo Support fixed-length OIDs according to RFC 2578, + * 7.7. "Mapping of the INDEX clause". + * + * \return The generated Oid. * * \exception None. */ - virtual void get() + virtual Oid toOid() const { + // fixed length currently unsupported: + bool fixedLength = false; + + Oid oid; + + // Store length if needed + if(!fixedLength) + { + oid.push_back(mValue.size()); + } + + // Store value + oid += mValue; + + return oid; } /** * \internal * - * \brief Handle a TestSet request. - * - * This function converts the argument to - * QSharedPointer() and calls - * testset() with the converted value. If conversion fails, - * testset() is not called. This function also stores the given - * value to the new_value member. - * - * \param _v The new value for the variable. + * \copydoc agentxcpp::IntegerVariable::handle_get() + */ + virtual void handle_get() + { + perform_get(); + } + + /** + * \copydoc agentxcpp::IntegerVariable::perform_get() + */ + virtual void perform_get() + { + } + + /** + * \internal * - * \return agentxcpp::AbstractVariable::wrongType if the conversion - * fails. Otherwise, - * the result of - * testset() is - * returned. + * \copydoc agentxcpp::IntegerVariable::handle_testet() */ virtual testset_result_t handle_testset(QSharedPointer _v) { @@ -229,7 +164,7 @@ namespace agentxcpp if (new_value) { // Type matches variable - return testset(new_value->value()); + return perform_testset(new_value->value()); } else { @@ -242,22 +177,9 @@ namespace agentxcpp /** * \brief Handle a TestSet request. * - * This method is called when an SNMP TestSet request is received. - * It - * shall check whether a Set operation is possible for the - * variable. It shall acquire the resources needed to perform the - * Set operation (but the Set shall not yet be performed). - * - * The default implementation returns - * agentxcpp::AbstractVariable::noAccess to indicate that - * this is a read-only variable. Thus, for read-only variables this - * method need not be overridden. - * - * \param _v The new value for the object. - * - * \return The result of the check. + * \copydoc agentxcpp::IntegerVariable::perform_testet() */ - virtual testset_result_t testset(const Oid& _v) + virtual testset_result_t perform_testset(const Oid& _v) { return noAccess; } @@ -265,30 +187,17 @@ namespace agentxcpp /** * \internal * - * \brief Handle a CleanupSet request. - * - * This function calls cleanupset() with the value from the last - * handle_testset() invocation. + * \copydoc agentxcpp::IntegerVariable::handle_cleanupset() */ virtual void handle_cleanupset() { - cleanupset(new_value->value()); + perform_cleanupset(new_value->value()); } /** - * \brief Handle a CleanupSet request. - * - * This method is called when an SNMP CleanupSet request is - * received. It - * shall release any resources allocated by testset(). - * - * The default implementation does nothing. If no action is - * required to perform the CleanupSet operation, this method need - * not be overridden. - * - * \param _v The new value for the object. + * \copydoc agentxcpp::IntegerVariable::perform_cleanupset() */ - virtual void cleanupset(const Oid& _v) + virtual void perform_cleanupset(const Oid& _v) { return; } @@ -296,32 +205,17 @@ namespace agentxcpp /** * \internal * - * \brief Handle a CommitSet request. - * - * This function calls commitset() with the value from the last - * handle_testset() Invocation and returns its return value. + * \copydoc agentxcpp::IntegerVariable::handle_commitset() */ virtual bool handle_commitset() { - return commitset(new_value->value()); + return perform_commitset(new_value->value()); } /** - * \brief Handle a CommitSet request. - * - * This method is called when an SNMP CommitSet request is - * received. It - * shall perform the actual write operation. - * - * The default implementation returns false to indicate that the - * operation failed. To implement a writable SNMP variable this - * method must be overridden. - * - * \param _v The new value for the object. - * - * \return True if the operation succeeded, false otherwise. + * \copydoc agentxcpp::IntegerVariable::perform_commitset() */ - virtual bool commitset(const Oid& _v) + virtual bool perform_commitset(const Oid& _v) { return false; } @@ -329,45 +223,21 @@ namespace agentxcpp /** * \internal * - * \brief Handle a UndoSet request. - * - * This function calls undoset() with the value from the last - * handle_testset() invocation and returns its return value. - * + * \copydoc agentxcpp::IntegerVariable::handle_undoset() */ virtual bool handle_undoset() { - return undoset(new_value->value()); + return perform_undoset(new_value->value()); } + /** - * \brief Handle an UndoSet request. - * - * This method is called when an SNMP UndoSet request is received. - * It - * shall undo whatever commitset() performed. It shall also release - * all resources allocated by testset(). - * - * The default implementation returns false to indicate that - * the operation failed. It is strongly recommended that writable - * variables override this method. - * - * \internal - * - * A default implementation is provided to allow implementing - * read-only variables. - * - * \endinternal - * - * \param _v The new value for the object. - * - * \return True on success, false otherwise. + * \copydoc agentxcpp::IntegerVariable::perform_undoset() */ - virtual bool undoset(const Oid& _v) + virtual bool perform_undoset(const Oid& _v) { return false; } - }; } diff --git a/src/OpaqueVariable.hpp b/src/OpaqueVariable.hpp index 5e37cef..421670d 100644 --- a/src/OpaqueVariable.hpp +++ b/src/OpaqueVariable.hpp @@ -36,151 +36,93 @@ namespace agentxcpp */ class OpaqueVariable : public AbstractVariable { - protected: - /** - * \brief The string. - * - * According to RFC 2578, Opaque is used to wrap any ASN.1-type. - */ - binary v; + protected: + /** + * \brief The string. + * + * According to RFC 2578, Opaque is used to wrap any ASN.1-type. + */ + binary v; private: /** - * \brief The new value for the variable in a Set operation. - * - * The Set operation is performed in up to four steps (testset, - * commitset, cleanupset, undoset). Only the testset step actually - * receives the new value. This value is stored here so that it can - * be delivered to commitset(), undoset() and cleanupset(). + * \copydoc agentxcpp::IntegerVariable::new_value */ QSharedPointer new_value; - public: + public: + + /** + * \internal + * + * \brief Encode the object as described in RFC 2741, section 5.4 + * + * This function uses big endian. + */ + binary serialize() const; - /** - * \internal - * - * \brief Encode the object as described in RFC 2741, section 5.4 / - * 5.3 - * - * Note: - * We always use big endian. - */ - binary serialize() const; - - /** - * \internal - * - * \brief Parse Constructor. - * - * This constructor parses the serialized form of the object. - * It takes an iterator, starts parsing at the position of the - * iterator and advances the iterator to the position right behind - * the object. - * - * The constructor expects valid data from the stream; if parsing - * fails, parse_error is thrown. In this case, the iterator - * position is undefined. - * - * \param pos Iterator pointing to the current stream position. - * The iterator is advanced while reading the header. - * - * \param end Iterator pointing one element past the end of the - * current stream. This is needed to mark the end of the - * buffer. - * - * \param big_endian Whether the input stream is in big endian - * format - */ - OpaqueVariable(binary::const_iterator& pos, - const binary::const_iterator& end, - bool big_endian=true); + /** + * \internal + * + * \copydoc + * agentxcpp::IntegerVariable::IntegerVariable(binary::const_iterator&, + * const binary::const_iterator&, bool) + * + */ + OpaqueVariable(binary::const_iterator& pos, + const binary::const_iterator& end, + bool big_endian=true); /** * \brief Constructor for initializing with data. */ - OpaqueVariable(binary initial_value) : v(initial_value) {} + OpaqueVariable(binary initial_value) : v(initial_value) {} - /** - * \brief Standard constructor. - */ - OpaqueVariable() - { - } + /** + * \brief Standard constructor. + */ + OpaqueVariable() + { + } - /* - * \brief Set the value. - * - * \param _v The new value. - * - * \exception None. - */ - void setValue(binary _v) - { - v = _v; - } + /** + * \copydoc agentxcpp::IntegerVariable::setValue() + */ + void setValue(binary _value) + { + v = _value; + } - /* - * \brief Get the value. - * - * \return The current value. - * - * \exception None. - */ - binary value() - { - return v; - } + /* + * \copydoc agentxcpp::IntegerVariable::value() + */ + binary value() + { + return v; + } /** * \internal * - * \brief Handle a Get Request. - * - * This function calls get() to obtain the new value, - * converts it to QSharedPointer and returns it. + * \copydoc agentxcpp::IntegerVariable::handle_get() */ virtual void handle_get() { - this->get(); + perform_get(); } /** - * \brief Handle a Get request. - * - * This method is called when an SNMP Get request is received. - * It shall - * return the current value of the variable. - * - * \note This method is pure virtual and thus \e must be - * implemented. It is not possible to implement write-only - * SNMP variables. - * - * \return The value of the variable. + * \copydoc agentxcpp::IntegerVariable::perform_get() */ - virtual void get() + virtual void perform_get() { } /** * \internal * - * \brief Handle a TestSet request. - * - * This function converts the argument to QSharedPointer() and - * calls - * testset() with the converted value. If conversion fails, - * testset() is not called. This function also stores the given - * value to the new_value member. - * - * \param _v The new value for the variable. - * - * \return agentxcpp::AbstractVariable::wrongType if the conversion - * fails. Otherwise, - * the result of - * testset() is - * returned. + * \copydoc agentxcpp::IntegerVariable::handle_testet() */ virtual testset_result_t handle_testset(QSharedPointer _v) { @@ -188,7 +130,7 @@ namespace agentxcpp if (new_value) { // Type matches variable - return testset(new_value->value()); + return perform_testset(new_value->value()); } else { @@ -201,22 +143,9 @@ namespace agentxcpp /** * \brief Handle a TestSet request. * - * This method is called when an SNMP TestSet request is received. - * It - * shall check whether a Set operation is possible for the - * variable. It shall acquire the resources needed to perform the - * Set operation (but the Set shall not yet be performed). - * - * The default implementation returns - * agentxcpp::AbstractVariable::noAccess to indicate that - * this is a read-only variable. Thus, for read-only variables this - * method need not be overridden. - * - * \param _v The new value for the object. - * - * \return The result of the check. + * \copydoc agentxcpp::IntegerVariable::perform_testet() */ - virtual testset_result_t testset(const binary& _v) + virtual testset_result_t perform_testset(const binary& _v) { return noAccess; } @@ -224,30 +153,17 @@ namespace agentxcpp /** * \internal * - * \brief Handle a CleanupSet request. - * - * This function calls cleanupset() with the value from the last - * handle_testset() invokation. + * \copydoc agentxcpp::IntegerVariable::handle_cleanupset() */ virtual void handle_cleanupset() { - cleanupset(new_value->value()); + perform_cleanupset(new_value->value()); } /** - * \brief Handle a CleanupSet request. - * - * This method is called when an SNMP CleanupSet request is - * received. It - * shall release any ressources allocated by testset(). - * - * The default implementation does nothing. If no action is - * required to perform the CleanupSet operaiton, this method need - * not be overridden. - * - * \param _v The new value for the object. + * \copydoc agentxcpp::IntegerVariable::perform_cleanupset() */ - virtual void cleanupset(const binary& _v) + virtual void perform_cleanupset(const binary& _v) { return; } @@ -255,32 +171,17 @@ namespace agentxcpp /** * \internal * - * \brief Handle a CommitSet request. - * - * This function calls commitset() with the value from the last - * handle_testset() Invocation and returns its return value. + * \copydoc agentxcpp::IntegerVariable::handle_commitset() */ virtual bool handle_commitset() { - return commitset(new_value->value()); + return perform_commitset(new_value->value()); } /** - * \brief Handle a CommitSet request. - * - * This method is called when an SNMP CommitSet request is - * received. It - * shall perform the actual write operation. - * - * The default implementation returns false to indicate that the - * operation failed. To implement a writable SNMP variable this - * method must be overridden. - * - * \param _v The new value for the object. - * - * \return True if the operation succeeded, false otherwise. + * \copydoc agentxcpp::IntegerVariable::perform_commitset() */ - virtual bool commitset(const binary& _v) + virtual bool perform_commitset(const binary& _v) { return false; } @@ -288,41 +189,17 @@ namespace agentxcpp /** * \internal * - * \brief Handle a UndoSet request. - * - * This function calls undoset() with the value from the last - * handle_testset() invocation and returns its return value. - * + * \copydoc agentxcpp::IntegerVariable::handle_undoset() */ virtual bool handle_undoset() { - return undoset(new_value->value()); + return perform_undoset(new_value->value()); } /** - * \brief Handle an UndoSet request. - * - * This method is called when an SNMP UndoSet request is received. - * It - * shall undo whatever commitset() performed. It shall also release - * all resources allocated by testset(). - * - * The default implementation returns false to indicate that - * the operation failed. It is strongly recommended that writable - * variables override this method. - * - * \internal - * - * A default implementation is provided to allow implementing - * read-only variables. - * - * \endinternal - * - * \param _v The new value for the object. - * - * \return True on success, false otherwise. + * \copydoc agentxcpp::IntegerVariable::perform_undoset() */ - virtual bool undoset(const binary& _v) + virtual bool perform_undoset(const binary& _v) { return false; } diff --git a/src/SConscript b/src/SConscript index 3ec1d2f..faa2ca6 100644 --- a/src/SConscript +++ b/src/SConscript @@ -23,7 +23,7 @@ Import('env') # If we are using g++: enable warnings (there is no portable way to enable # warnings, so we enable them only for g++. For development it's enough.) if(env["CXX"] == "g++"): - env.Append(CPPFLAGS = ['-Wall']) + env.Append(CPPFLAGS = ['-Wall', '-Werror']) # Build the library: agentxcpp = env.SharedLibrary('agentxcpp', Glob('*.cpp')) diff --git a/src/TimeTicksVariable.hpp b/src/TimeTicksVariable.hpp index 506ffea..41d61a7 100644 --- a/src/TimeTicksVariable.hpp +++ b/src/TimeTicksVariable.hpp @@ -44,12 +44,7 @@ namespace agentxcpp private: /** - * \brief The new value for the variable in a Set operation. - * - * The Set operation is performed in up to four steps (testset, - * commitset, cleanupset, undoset). Only the testset step actually - * receives the new value. This value is stored here so that it can - * be delivered to commitset(), undoset() and cleanupset(). + * \copydoc agentxcpp::IntegerVariable::new_value */ QSharedPointer new_value; @@ -65,31 +60,15 @@ namespace agentxcpp { } - /** - * \internal - * - * \brief Parse Constructor. - * - * This constructor parses the serialized form of the object. - * It takes an iterator, starts parsing at the position of the - * iterator and advances the iterator to the position right behind - * the object. - * - * The constructor expects valid data from the stream; if parsing - * fails, parse_error is thrown. In this case, the iterator - * position is undefined. - * - * \param pos Iterator pointing to the current stream position. - * The iterator is advanced while reading the header. - * - * \param end Iterator pointing one element past the end of the - * current stream. This is needed to mark the end of the - * buffer. - * - * \param big_endian Whether the input stream is in big endian - * format - */ - TimeTicksVariable(binary::const_iterator& pos, + /** + * \internal + * + * \copydoc + * agentxcpp::IntegerVariable::IntegerVariable(binary::const_iterator&, + * const binary::const_iterator&, bool) + * + */ + TimeTicksVariable(binary::const_iterator& pos, const binary::const_iterator& end, bool big_endian=true); @@ -102,78 +81,43 @@ namespace agentxcpp */ virtual binary serialize() const; - /* - * \brief Set the value. - * - * \param _v The new value. - * - * \exception None. - */ - void setValue(quint32 _v) - { - v = _v; + /** + * \copydoc agentxcpp::IntegerVariable::setValue() + */ + void setValue(quint32 _value) + { + v = _value; } /* - * \brief get the value. - * - * \return The current value. - * - * \exception None. + * \copydoc agentxcpp::IntegerVariable::value() */ - quint32 value() - { - return v; + quint32 value() + { + return v; } /** * \internal * - * \brief Handle a Get Request. - * - * This function calls get() to obtain the new value, - * converts it to QSharedPointer and returns it. + * \copydoc agentxcpp::IntegerVariable::handle_get() */ virtual void handle_get() { - this->get(); + perform_get(); } /** - * \brief Handle a Get request. - * - * This method is called when an SNMP Get request is received. - * It shall - * return the current value of the variable. - * - * \note This method is pure virtual and thus \e must be - * implemented. It is not possible to implement write-only - * SNMP variables. - * - * \return The value of the variable. + * \copydoc agentxcpp::IntegerVariable::perform_get() */ - virtual void get() + virtual void perform_get() { } /** * \internal * - * \brief Handle a TestSet request. - * - * This function converts the argument to QSharedPointer() and - * calls - * testset() with the converted value. If conversion fails, - * testset() is not called. This function also stores the given - * value to the new_value member. - * - * \param _v The new value for the variable. - * - * \return agentxcpp::AbstractVariable::wrongType if the conversion - * fails. Otherwise, - * the result of - * testset() is - * returned. + * \copydoc agentxcpp::IntegerVariable::handle_testet() */ virtual testset_result_t handle_testset(QSharedPointer _v) { @@ -181,7 +125,7 @@ namespace agentxcpp if (new_value) { // Type matches variable - return testset(new_value->value()); + return perform_testset(new_value->value()); } else { @@ -194,22 +138,9 @@ namespace agentxcpp /** * \brief Handle a TestSet request. * - * This method is called when an SNMP TestSet request is received. - * It - * shall check whether a Set operation is possible for the - * variable. It shall acquire the resources needed to perform the - * Set operation (but the Set shall not yet be performed). - * - * The default implementation returns - * agentxcpp::AbstractVariable::noAccess to indicate that - * this is a read-only variable. Thus, for read-only variables this - * method need not be overridden. - * - * \param v The new value for the object. - * - * \return The result of the check. + * \copydoc agentxcpp::IntegerVariable::perform_testet() */ - virtual testset_result_t testset(quint32 _v) + virtual testset_result_t perform_testset(quint32 _v) { return noAccess; } @@ -217,30 +148,17 @@ namespace agentxcpp /** * \internal * - * \brief Handle a CleanupSet request. - * - * This function calls cleanupset() with the value from the last - * handle_testset() invocation. + * \copydoc agentxcpp::IntegerVariable::handle_cleanupset() */ virtual void handle_cleanupset() { - cleanupset(new_value->value()); + perform_cleanupset(new_value->value()); } /** - * \brief Handle a CleanupSet request. - * - * This method is called when an SNMP CleanupSet request is - * received. It - * shall release any ressources allocated by testset(). - * - * The default implementation does nothing. If no action is - * required to perform the CleanupSet operaiton, this method need - * not be overridden. - * - * \param _v The new value for the object. + * \copydoc agentxcpp::IntegerVariable::perform_cleanupset() */ - virtual void cleanupset(quint32 _v) + virtual void perform_cleanupset(quint32 _v) { return; } @@ -248,32 +166,16 @@ namespace agentxcpp /** * \internal * - * \brief Handle a CommitSet request. - * - * This function calls commitset() with the value from the last - * handle_testset() Invocation and returns its return value. + * \copydoc agentxcpp::IntegerVariable::handle_commitset() */ virtual bool handle_commitset() { - return commitset(new_value->value()); + return perform_commitset(new_value->value()); } /** - * \brief Handle a CommitSet request. - * - * This method is called when an SNMP CommitSet request is - * received. It - * shall perform the actual write operation. - * - * The default implementation returns false to indicate that the - * operation failed. To implement a writable SNMP variable this - * method must be overridden. - * - * \param _v The new value for the object. - * - * \return True if the operation succeeded, false otherwise. - */ - virtual bool commitset(quint32 _v) + * \copydoc agentxcpp::IntegerVariable::perform_commitset() + */ virtual bool perform_commitset(quint32 _v) { return false; } @@ -281,41 +183,17 @@ namespace agentxcpp /** * \internal * - * \brief Handle a UndoSet request. - * - * This function calls undoset() with the value from the last - * handle_testset() invocation and returns its return value. - * + * \copydoc agentxcpp::IntegerVariable::handle_undoset() */ virtual bool handle_undoset() { - return undoset(new_value->value()); + return perform_undoset(new_value->value()); } /** - * \brief Handle an UndoSet request. - * - * This method is called when an SNMP UndoSet request is received. - * It - * shall undo whatever commitset() performed. It shall also release - * all resources allocated by testset(). - * - * The default implementation returns false to indicate that - * the operation failed. It is strongly recommended that writable - * variables override this method. - * - * \internal - * - * A default implementation is provided to allow implementing - * read-only variables. - * - * \endinternal - * - * \param v The new value for the object. - * - * \return True on success, false otherwise. + * \copydoc agentxcpp::IntegerVariable::perform_undoset() */ - virtual bool undoset(quint32 _v) + virtual bool perform_undoset(quint32 _v) { return false; } From 95279dbb26a818fb0895d6e6a82bc8b2d70ef6a1 Mon Sep 17 00:00:00 2001 From: "Tanjeff-N. Moos" Date: Thu, 26 Nov 2015 21:28:07 +0100 Subject: [PATCH 58/89] Update tutorials. --- doc/how_to_add_rw_support.dox | 33 ++++++------- doc/how_to_implement_tables.dox | 78 +++++++++++++++---------------- doc/how_to_send_notifications.dox | 58 +++++++++-------------- doc/how_to_write_a_subagent.dox | 6 +-- 4 files changed, 80 insertions(+), 95 deletions(-) diff --git a/doc/how_to_add_rw_support.dox b/doc/how_to_add_rw_support.dox index db2bac6..d4d2936 100644 --- a/doc/how_to_add_rw_support.dox +++ b/doc/how_to_add_rw_support.dox @@ -55,21 +55,23 @@ This is the same as before, but with "ACCESS read-write". A single SNMP Set request may set multiple variables at once (possibly distributed over multiple subagents), and SNMP guarantees an atomic operation -in that case. This means that, should any variable fail to perform the SET -operation, no other variable is allowed to perform the SET operation either. +in that case. This means that, should any variable fail to perform the Set +operation, no other variable is allowed to perform the Set operation either. Therefore, the SET operation is carried out in multiple distinct steps: -# \b TestSet checks whether the variable could be set at all. This step is - performed for all variables (in all subagents) affected by the single SNMP - request. If any variable is not able to accept its new value, the SET - operation is aborted (and no variable gets updated). During this step - subagents shall allocate the resources they need to carry out the SET - operation later, but they shall not update their value yet. + performed for all variables (in all subagents) affected by the single SNMP Set + request. If any variable is not able to accept its new value, the Set + operation is aborted, and the next step "CommitSet" is skipped (and no + variable gets updated). During this step subagents shall allocate the + resources they need to carry out the Set operation later, but they shall not + update their value yet. -# \b CommitSet actually sets the new value. This step may fail for a variable, - even if the TestSet step announced that the CommitSet would work. If that + even if the TestSet step announced that the CommitSet would work. If that happens, all other variables which already performed the CommitSet must undo - their action. It is strongly recommended to implement variables in such a - way that CommitSet does not fail, when possible. + their action (which is done in the UndoSet step). It is strongly recommended + to implement variables in such a way that CommitSet does not fail, when + possible. -# The third step is one of the following: - \b CleanupSet is usually the last step, performed after CommitSet was successful for all variables. In the CleanupSet step, the subagent shall @@ -113,8 +115,7 @@ SimpleCounter class by adding the following code to it: quint32* old_value; public: - virtual testset_result_t - perform_testset(QSharedPointer new_value) + virtual testset_result_t perform_testset(qint32 new_value) { try { @@ -144,12 +145,12 @@ The perform_commitset() method must also be implemented for writeable variables. In the SimpleCounter class, this method stores the old value and sets the internal value: \code - virtual bool perform_commitset(QSharedPointer new_value) + virtual bool perform_commitset(qint32 new_value) { // Remember old value for rollback (*old_value) = v; // Set new value - v = new_value->value(); + v = new_value; // Operation succeeded return true; } @@ -160,7 +161,7 @@ sets the internal value: The perform_cleanupset() method releases old_value again: \code - virtual void perform_cleanupset(QSharedPointer new_value) + virtual void perform_cleanupset(qint32 new_value) { // Release old value delete old_value; @@ -180,7 +181,7 @@ detect a missing implementation. However, it is an error to omit it, and an erro to the master agent if it is missing. For simpleCounter implementation is easy: \code - virtual bool perform_undoset(QSharedPointer new_value) + virtual bool perform_undoset(qint32 new_value) { // Restore old value v = *old_value; diff --git a/doc/how_to_implement_tables.dox b/doc/how_to_implement_tables.dox index ca1ddfb..93630d9 100644 --- a/doc/how_to_implement_tables.dox +++ b/doc/how_to_implement_tables.dox @@ -107,9 +107,8 @@ counterChangeValue OBJECT-TYPE END \endverbatim -Our table has an entry for each counter change which occured in the past. The -table starts empty and each time the counter changes (i.e. by an SNMP GET or -SET request), an entry is added. +Our table has an entry for each counter change which occurred in the past. The table starts empty +and each time the counter changes (i.e. by an SNMP GET or SET request), an entry is added. Each entry within the table has a timestamp, which consists of the epoch time and a milliseconds component, which is used as index of the entry. This is to @@ -124,20 +123,20 @@ Technically, our SNMP table is a sequence of counterChangeEntry, which in turn is a structure containing four "real" SNMP variables. The OID of these variables are assembled like this: - ... + \.\.\.\ -The is the OID given to the table. The counterChangeTable has the +The \ is the OID given to the table. The counterChangeTable has the OID enterprises.42.2, which is .1.3.6.1.4.1.42.2. -The is a single number assigned to the table entry. The +The \ is a single number assigned to the table entry. The CounterChangeEntry has the OID counterChangeTable.1, which means that - is 1. +\ is 1. -The is a single number which can be thought to be the column -of a specific variable. The counterChangeEpoch has 1, while -counterChangeTimeString has 3. +The \ is a single number which can be thought to be the column +of a specific variable. The counterChangeEpoch has \ 1, while +counterChangeTimeString has \ 3. -The is the concatenation of the index variables (counterChangeEpoch +The \ is the concatenation of the index variables (counterChangeEpoch and counterChangeMilliseconds), converted to OID. For example, if counterChangeEpoch was 123456789 and counterChangeMilliseconds was 512, the index would be "123456789.512". The index can be thought of as the identifier @@ -148,18 +147,16 @@ Thus, the full OID of the counterChangeTimeString in the entry 123456789.512, for example, would be ".1.3.6.1.4.1.42.2.1.3.123456789.512". A table is implemented by creating a \agentxcpp{Table} object and tell it its - (enterprises.42.2). An entry is implemented by subclassing -\agentxcpp{TableEntry}, which initializes its subid to (i.e. 1 for -counterChangeEntry). For our table, we will implement the CounterChangeEntry -class which contains the four variables counterChangeEpoch, -counterChangeMilliseconds, counterChangeTimeString and +\ (enterprises.42.2). An entry is implemented by subclassing \agentxcpp{TableEntry}, +such that the subclass initializes its \agentxcpp{TableEntry::subid} to \ (i.e. 1 for +counterChangeEntry). For our table, we will implement the CounterChangeEntry class which contains +the four variables counterChangeEpoch, counterChangeMilliseconds, counterChangeTimeString and counterChangeCounterValue. The CounterChangeEntry class must implement the -\agentxcpp{TableEntry::indexVariables()} and -\agentxcpp{TableEntry::variables()} methods. +\agentxcpp{TableEntry::indexVariables()} and \agentxcpp{TableEntry::variables()} methods. -Each time an entry is added, the table will query the new entry for all its +Each time an entry is added to the table, the table will query the new entry for all its variables and add these to the MasterProxy object, so that they are -served like any other variable. If an entry is removed, the table will remove +served like any other variable. If an entry is removed from the table, the table will remove its variables from the MasterProxy object again. Neither the table nor the entry can actually be queried by SNMP requests; they are only used to organize the variables which can be queried. Therefore, neither the table nor the @@ -169,7 +166,7 @@ entries are added to the MasterProxy object. Only the variables are added. \section tables_implementing_entry Implementing the CounterChangeEntry class First of all, we implement the CounterChangeEntry class. Here is the full -code: +code of CounterChangeEntry.hpp: \code #ifndef _COUNTERCHANGEENTRY_H_ @@ -219,11 +216,10 @@ class CounterChangeEntry : public TableEntry #endif // _COUNTERCHANGEENTRY_H_ \endcode -The class inherits \agentxcpp{TableEntry}. It has four members which represent -the four SNMP variables. Since in agentXcpp those variables are handled as -QSharedPointer's, the constructor needs to create all of them using the -new operator. The constructor also sets \agentxcpp{TableEntry::subid} -to 1. +The class inherits \agentxcpp{TableEntry} and has four members which represent the four SNMP +variables. Since in agentXcpp those variables are handled as QSharedPointer's, the constructor needs +to create all of them using the new operator. The constructor also sets +\agentxcpp{TableEntry::subid} to 1. Our MIB states that counterChangeEpoch and counterChangeMilliseconds are used as index. The CounterChangeEntry::indexVariables() method implements this by @@ -279,30 +275,33 @@ constructor and the helper function addEntry(): } \endcode -Next we have to replace the get(), commitset() and undoset() functions with -variants adding and removing an entries to/from the table. Here is how they -look like now: +Next we have to replace the perform_get(), perform_commitset() and +perform_undoset() functions with variants adding and removing an entries to/from the table. +Here is how they look like now: \code - virtual void get() + // Replaces the first version: + virtual void perform_get() { ++v; addEntry(); } - virtual bool commitset(QSharedPointer new_value) + // Replaces the first version: + virtual bool perform_commitset(qint32 new_value) { // Remember old value for rollback (*old_value) = v; // Set new value - v = new_value->value(); + v = new_value; // Add table entry addEntry(); // Operation succeeded return true; } - virtual bool undoset(QSharedPointer new_value) + // Replaces the first version: + virtual bool perform_undoset(qint32 new_value) { // Restore old value v = *old_value; @@ -318,9 +317,8 @@ look like now: } \endcode -And finally we update the main() function, where a table is instantiated and -given to the SimpleCounter constructor. Here is the complete main() -function: +And finally we update the main() function, where a table is instantiated and given to the +SimpleCounter constructor. Here is the complete revised main() function: \code int main(int argc, char** argv) @@ -357,9 +355,9 @@ And that's all we need for our table. Next, let's try it out. \section tables_compiling_notification Compiling the Subagent -We didn't add implementation files in this tutorial, so no additional steps are -needed for compiling. However, we have to recompile the the whole thing. We -know the following commands already from the previous tutorials: +We didn't add implementation files in this tutorial, so no additional steps are needed for +compiling. However, we have to recompile the whole thing. We know the following commands already +from the previous tutorials: \code moc-qt4 `pkg-config --cflags QtCore QtNetwork` -o moc_NotificationSender.cc NotificationSender.hpp @@ -378,7 +376,7 @@ Now, the executable is ready to run. \section tables_running Running the subagent -The subagent is run like descibed in the previous tutorials, simply by executing it: +The subagent is run like described in the previous tutorials, simply by executing it: \code ./simpleagent diff --git a/doc/how_to_send_notifications.dox b/doc/how_to_send_notifications.dox index b9fdeac..2991270 100644 --- a/doc/how_to_send_notifications.dox +++ b/doc/how_to_send_notifications.dox @@ -66,7 +66,7 @@ simpleCounterStatus NOTIFICATION-TYPE END \endverbatim -As can be seen, we added the simpleCounterChange notification, which will +As can be seen, we added the simpleCounterStatus notification, which will include the simpleCounter value when sent. Note that the next-to-last subidentifier for notifications must be 0 according to RFC 1902, 8.5. "Mapping of the NOTIFICATION-TYPE value". @@ -81,8 +81,8 @@ every second and sends a notification. We will use a QTimer which can use the event loop provided by Qt. For this we need a class with a Qt slot to which the QTimer can be connected. We name that class NotificationSender and put it into its own file: NotificationSender.hpp (for simplicity we -implement the whole class in the header, so we won't need an implementation -file). Here ist the NotificationSender.hpp file: +implement the whole class in the header, so we won't need an implementation file). Here is the +NotificationSender.hpp file: \code #ifndef _NOTIFICATIONSENDER_H_ @@ -119,42 +119,28 @@ class NotificationSender : public QObject std::cout << "notification!" << std::endl; std::vector objects; - IntegerVariable(counter->value())); - objects.push_back(Varbind(simpleCounter_oid, counterVariable)); + IntegerVariable(counter->value()); + objects.push_back(Varbind(simpleCounter_oid, counter)); - QMetaObject::invokeMethod(master, "send_notification", - Q_ARG(const Oid&, simpleCounter_oid), - Q_ARG(const std::vector&, objects) - ); + master->send_notification(enterprises_oid + 42 + 0 + 1, objects); } }; #endif // _NOTIFICATIONSENDER_H_ \endcode -\todo Which OID must be given to send_notification()? +The NotificationSender inherits QObject and uses the Q_OBJECT macro, which is both needed to make +the class suitable for Qt's signal/slot mechanism. The constructor takes a pointer to the +MasterProxy object (needed to send notifications), a pointer to the SimpleCounter object (will be +included in the notifications) and the simpleCounter's OID (will also be included in the +notifications). The sendNotification() slot will be connected to the QTimer object and sends a +notification each time it is invoked. -The NotificationSender inherits QObject and uses the Q_OBJECT macro, which is -both needed to make the class suitable for Qt's signal/slot mechanism. The -constructor takes a pointer to the MasterProxy object (needed to send -notifications), the simpleCounter's oid (will be included in the notifications) -and a pointer to the counter (will be queried to include its value in the -notifications). The sendNotification() slot will be connected to the QTimer -object and sends a notification each time it is invoked. Also, it performs an -output to indicate that a notification is sent. - -We use QMetaObject::invokeMethod() here to invoke the -MasterProxy::send_notification() slot. This would even work if the -NotificationSender were running in a separate thread. In our example, were the -NotificationSender and the MasterProxy run in the same thread, a simple call -would also work: - -\code -// Could be used instead of QMetaObject::invokeMethod(), -// because NotificationSender and MasterProxy run in -// the same thread: -master->send_notification(simpleCounter_oid, objects); -\endcode +The direct call to the +\ref agentxcpp::MasterProxy::send_notification(const Oid&, const std::vector< Varbind >&) +"MasterProxy::send_notification()" slot works, because the NotificationSender and the MasterProxy +will run in the same thread. If they were running in separate threads, +QMetaObject::invokeMethod() would be used to invoke the slot. Next, we augment the code within the main() function. But first, we need additional includes in simpleagent.cpp: @@ -164,7 +150,7 @@ need additional includes in simpleagent.cpp: #include "NotificationSender.hpp" \endcode -And this is the complete main() function: +And this is the complete revised main() function: \code int main(int argc, char** argv) @@ -192,10 +178,10 @@ int main(int argc, char** argv) } \endcode -First, we create a NotificationSender object. Then, we create a QTimer object, -connect its timeout() signal to the NotificationSender's -sendNotification() slot, configure its interval to 1 second (the timer -is repetitive by default), and start it. +The additional code creates a NotificationSender object. Then, it creates a +QTimer object, connects its timeout() signal to the +NotificationSender's sendNotification() slot, configures its interval +to 1 second (the timer is repetitive by default), and starts it. \section compiling_notification Compiling the Subagent diff --git a/doc/how_to_write_a_subagent.dox b/doc/how_to_write_a_subagent.dox index 75848d2..f8ebd2e 100644 --- a/doc/how_to_write_a_subagent.dox +++ b/doc/how_to_write_a_subagent.dox @@ -97,19 +97,19 @@ The simpleCounter has a type which is given in the SYNTAX clause in the MIB. AgentXcpp provides various classes to match standard SYNTAX types. These classes can be inherited to implement variables of this type, which is what SimpleCounter does. However, IntegerVariable and it companions can also be used -without subclassing them; they have default get() implementations which do +without subclassing them; they have default perform_get() implementations which do nothing. Their internal value can be obtained with value() and set with setValue(), and an SNMP GET request will return this internal state. SimpleCounter inherits from IntegerVariable and overrides -IntegerVariable::get(). This method is invoked on SNMP GET requests and should +IntegerVariable::perform_get(). This method is invoked on SNMP GET requests and should update the internal value of the IntegerVariable object. In our case, it simply increments the member variable "v" (this is easier than using value() and setValue()): \code public: - virtual void get() + virtual void perform_get() { ++v; } From 0cbf7de3cd7667ca2fc33796486391aa164c1d1d Mon Sep 17 00:00:00 2001 From: "Tanjeff-N. Moos" Date: Fri, 27 Nov 2015 08:17:19 +0100 Subject: [PATCH 59/89] Review docs for Integer and Counter32 variables. --- src/Counter32Variable.hpp | 19 ++++++++------- src/IntegerVariable.hpp | 49 +++++++++++++++------------------------ 2 files changed, 29 insertions(+), 39 deletions(-) diff --git a/src/Counter32Variable.hpp b/src/Counter32Variable.hpp index 914e08a..726fca9 100644 --- a/src/Counter32Variable.hpp +++ b/src/Counter32Variable.hpp @@ -29,6 +29,9 @@ namespace agentxcpp public: + /** + * \brief Constructor. + */ Counter32Variable(quint32 _value = 0) : v(_value) { @@ -37,9 +40,7 @@ namespace agentxcpp /** * \internal * - * \copydoc - * agentxcpp::IntegerVariable::IntegerVariable(binary::const_iterator&, - * const binary::const_iterator&, bool) + * \copydoc agentxcpp::IntegerVariable::IntegerVariable(binary::const_iterator&, const binary::const_iterator&, bool) * */ Counter32Variable(binary::const_iterator& pos, @@ -63,8 +64,10 @@ namespace agentxcpp v = _value; } - /* - * \copydoc agentxcpp::IntegerVariable::value() + /** + * \brief Get the current value. + * + * \return The value. */ virtual quint32 value() { @@ -91,7 +94,7 @@ namespace agentxcpp /** * \internal * - * \copydoc agentxcpp::IntegerVariable::handle_testet() + * \copydoc agentxcpp::IntegerVariable::handle_testset() */ virtual testset_result_t handle_testset(QSharedPointer _v) { @@ -110,9 +113,7 @@ namespace agentxcpp } /** - * \brief Handle a TestSet request. - * - * \copydoc agentxcpp::IntegerVariable::perform_testet() + * \copydoc agentxcpp::IntegerVariable::perform_testset() */ virtual testset_result_t perform_testset(quint32 _v) { diff --git a/src/IntegerVariable.hpp b/src/IntegerVariable.hpp index 4b3e905..d9b0731 100644 --- a/src/IntegerVariable.hpp +++ b/src/IntegerVariable.hpp @@ -63,8 +63,9 @@ namespace agentxcpp * \brief The new value for the variable. Used during a Set * operation. * - * The Set operation is performed in up to four steps (perform_testset, - * perform_commitset, perform_cleanupset, perform_undoset). Only the perform_testset step actually + * The Set operation is performed in up to four steps (TestSet, + * CommitSet, CleanupSet, UndoSet). Only the TestSet step + * actually * receives the new value. This value is stored here so that it can * be delivered to perform_commitset(), perform_undoset() and perform_cleanupset(). */ @@ -73,9 +74,7 @@ namespace agentxcpp public: /** - * \internal - * - * \brief Constructor. + * \brief Constructor. * * Creates an IntegerValue object. * @@ -157,9 +156,9 @@ namespace agentxcpp /** * \brief Get the current value. * - * \return The new value. + * \return The value. */ - qint32 value() + virtual qint32 value() { return v; } @@ -181,8 +180,7 @@ namespace agentxcpp * \brief Perform a Get request. * * This method is invoked when an SNMP Get request is received. - * It should update the internal value - * \agentxcpp{IntegerVariable::v}. + * It should update the internal value \ref v. */ virtual void perform_get() { @@ -193,11 +191,9 @@ namespace agentxcpp * * \brief Handle a TestSet request. * - * This function converts the argument to - * QSharedPointer, stores it in - * \agentxcpp{IntegerVariable::new_value} and then calls perform_testset() - * with the internal value of - * \agentxcpp{IntegerVariable::new_value}. If conversion fails, + * This function converts the argument, stores it in \ref new_value + * and then calls perform_testset() with the internal value of \ref + * new_value. If conversion fails, * \agentxcpp{AbstractVariable::wrongType} is returned and * perform_testset() is not called. * @@ -253,11 +249,9 @@ namespace agentxcpp * * \brief Handle a CleanupSet request. * - * This function calls perform_cleanupset() with the internal value of \ref - * agentxcpp::IntegerVariable::new_value "new_value" (which was - * updated by the last \ref - * agentxcpp::IntegerVariable::handle_testset() "handle_testset()" - * invocation). + * This function calls perform_cleanupset() with the internal value + * of \ref new_value (which was updated by the last + * \ref handle_testset() invocation). */ virtual void handle_cleanupset() { @@ -287,12 +281,9 @@ namespace agentxcpp * * \brief Handle a CommitSet request. * - * This function calls \ref agentxcpp::IntegerVariable::perform_commitset() - * "perform_commitset()" with the internal value of \ref - * agentxcpp::IntegerVariable::new_value "new_value" (which was - * updated by the last \ref - * agentxcpp::IntegerVariable::handle_testset() "handle_testset()" - * invocation). + * This function calls \ref perform_commitset() with the internal + * value of \ref new_value (which was updated by the last + * \ref handle_testset() invocation). * * \return The return value of perform_commitset(). */ @@ -325,11 +316,9 @@ namespace agentxcpp * * \brief Handle a UndoSet request. * - * This function calls perform_undoset() with the internal value of \ref - * agentxcpp::IntegerVariable::new_value "new_value" (which was - * updated by the last \ref - * agentxcpp::IntegerVariable::handle_testset() "handle_testset()" - * invocation). + * This function calls perform_undoset() with the internal value of + * \ref new_value (which was updated by the last + * \ref handle_testset() invocation). * * \return The return value of perform_undoset(). * From bf5e89806b5df2369b3049da1be94c7f489db801 Mon Sep 17 00:00:00 2001 From: "Tanjeff-N. Moos" Date: Fri, 27 Nov 2015 10:40:34 +0100 Subject: [PATCH 60/89] Review docs for Counter64Variable. --- src/Counter64Variable.hpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/Counter64Variable.hpp b/src/Counter64Variable.hpp index 62cf67c..cfb2f78 100644 --- a/src/Counter64Variable.hpp +++ b/src/Counter64Variable.hpp @@ -29,6 +29,9 @@ namespace agentxcpp public: + /** + * \brief Constructor. + */ Counter64Variable(quint64 _value = 0) : v(_value) { @@ -37,9 +40,7 @@ namespace agentxcpp /** * \internal * - * \copydoc - * agentxcpp::IntegerVariable::IntegerVariable(binary::const_iterator&, - * const binary::const_iterator&, bool) + * \copydoc agentxcpp::IntegerVariable::IntegerVariable(binary::const_iterator&, const binary::const_iterator&, bool) * */ Counter64Variable(binary::const_iterator& pos, @@ -63,8 +64,10 @@ namespace agentxcpp v = _value; } - /* - * \copydoc agentxcpp::IntegerVariable::value() + /** + * \brief Get the current value. + * + * \return The value. */ virtual quint64 value() { @@ -91,7 +94,7 @@ namespace agentxcpp /** * \internal * - * \copydoc agentxcpp::IntegerVariable::handle_testet() + * \copydoc agentxcpp::IntegerVariable::handle_testset() */ virtual testset_result_t handle_testset(QSharedPointer _v) { @@ -112,7 +115,7 @@ namespace agentxcpp /** * \brief Handle a TestSet request. * - * \copydoc agentxcpp::IntegerVariable::perform_testet() + * \copydoc agentxcpp::IntegerVariable::perform_testset() */ virtual testset_result_t perform_testset(quint64 _v) { From a6d9640e19c3dceca5a3d9cd8b6c4a09a59f313c Mon Sep 17 00:00:00 2001 From: "Tanjeff-N. Moos" Date: Fri, 27 Nov 2015 12:01:04 +0100 Subject: [PATCH 61/89] Gauge32Variable: Implement toOid(), review docs. --- src/Gauge32Variable.hpp | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/src/Gauge32Variable.hpp b/src/Gauge32Variable.hpp index 555f464..39b2606 100644 --- a/src/Gauge32Variable.hpp +++ b/src/Gauge32Variable.hpp @@ -52,9 +52,7 @@ namespace agentxcpp public: /** - * \internal - * - * \brief Create a Gauge32Value without initialization. + * \brief Default Constructor. * * The value after creation is 0. */ @@ -66,9 +64,7 @@ namespace agentxcpp /** * \internal * - * \copydoc - * agentxcpp::IntegerVariable::IntegerVariable(binary::const_iterator&, - * const binary::const_iterator&, bool) + * \copydoc agentxcpp::IntegerVariable::IntegerVariable(binary::const_iterator&, const binary::const_iterator&, bool) * */ Gauge32Variable(binary::const_iterator& pos, @@ -92,8 +88,10 @@ namespace agentxcpp v = _value; } - /* - * \copydoc agentxcpp::IntegerVariable::value() + /** + * \brief Get the current value. + * + * \return The value. */ quint32 value() { @@ -120,7 +118,7 @@ namespace agentxcpp /** * \internal * - * \copydoc agentxcpp::IntegerVariable::handle_testet() + * \copydoc agentxcpp::IntegerVariable::handle_testset() */ virtual testset_result_t handle_testset(QSharedPointer _v) { @@ -141,7 +139,7 @@ namespace agentxcpp /** * \brief Handle a TestSet request. * - * \copydoc agentxcpp::IntegerVariable::perform_testet() + * \copydoc agentxcpp::IntegerVariable::perform_testset() */ virtual testset_result_t perform_testset(quint32 _v) { @@ -203,15 +201,23 @@ namespace agentxcpp } /** - * \brief Return the null Oid. + * \brief Convert the value to an OID. + * + * The conversion is done according to RFC 2578, + * 7.7. "Mapping of the INDEX clause". The value is + * converted to an Oid with a single subid. * - * This method returns the null Oid because RFC 2578, 7.7. - * "Mapping of the INDEX clause" does not - * describe how to convert Gauge32 to an OID. - */ + * This method should not be overridden. + * + * \note If an GAUGE32 is used in an INDEX clause, the + * value 0 should be avoided according to + * RFC 2578, 7.7. "Mapping of the INDEX clause". + */ virtual Oid toOid() const { - return Oid(); + Oid oid; + oid.push_back(v); + return oid; } From 576bdcd4af672a789cdbfea2019628a667b42e0c Mon Sep 17 00:00:00 2001 From: "Tanjeff-N. Moos" Date: Fri, 27 Nov 2015 12:20:41 +0100 Subject: [PATCH 62/89] IpAddressVariable: Implement toOid(), review docs. --- src/IpAddressVariable.cpp | 16 +++++------ src/IpAddressVariable.hpp | 60 ++++++++++++++++++++------------------- 2 files changed, 39 insertions(+), 37 deletions(-) diff --git a/src/IpAddressVariable.cpp b/src/IpAddressVariable.cpp index 4c946df..5cd4638 100644 --- a/src/IpAddressVariable.cpp +++ b/src/IpAddressVariable.cpp @@ -33,10 +33,10 @@ binary IpAddressVariable::serialize() const serialized.push_back(4); // encode address - serialized.push_back(address[0]); - serialized.push_back(address[1]); - serialized.push_back(address[2]); - serialized.push_back(address[3]); + serialized.push_back(v[0]); + serialized.push_back(v[1]); + serialized.push_back(v[2]); + serialized.push_back(v[3]); return serialized; } @@ -65,8 +65,8 @@ IpAddressVariable::IpAddressVariable(binary::const_iterator& pos, // Get address // always most significant first according to // RFC2741, 5.4 "Value Representation" - address[0] = *pos++; - address[1] = *pos++; - address[2] = *pos++; - address[3] = *pos++; + v[0] = *pos++; + v[1] = *pos++; + v[2] = *pos++; + v[3] = *pos++; } diff --git a/src/IpAddressVariable.hpp b/src/IpAddressVariable.hpp index 45f3dcf..81abfba 100644 --- a/src/IpAddressVariable.hpp +++ b/src/IpAddressVariable.hpp @@ -33,18 +33,22 @@ namespace agentxcpp */ class IpAddressVariable : public AbstractVariable { - private: - /** - * \brief Hide default constructor - */ - IpAddressVariable(); - + protected: /** * \brief The IP address. * * According to RFC 2578, IpAddress is a 32-bit number. */ - quint8 address[4]; // only IPv4 + quint8 v[4]; // only IPv4 + + private: + /** + * \brief Hidden default constructor. + * + * This constructor is private so it cannot be used to construct + * objects. + */ + IpAddressVariable(); /** * \copydoc agentxcpp::IntegerVariable::new_value @@ -55,9 +59,7 @@ namespace agentxcpp /** * \internal * - * \copydoc - * agentxcpp::IntegerVariable::IntegerVariable(binary::const_iterator&, - * const binary::const_iterator&, bool) + * \copydoc agentxcpp::IntegerVariable::IntegerVariable(binary::const_iterator&, const binary::const_iterator&, bool) * */ IpAddressVariable(binary::const_iterator& pos, @@ -87,10 +89,10 @@ namespace agentxcpp quint8 c, quint8 d) { - address[0] = a; - address[1] = b; - address[2] = c; - address[3] = d; + v[0] = a; + v[1] = b; + v[2] = c; + v[3] = d; } @@ -106,10 +108,10 @@ namespace agentxcpp quint8 c, quint8 d) { - address[0] = a; - address[1] = b; - address[2] = c; - address[3] = d; + v[0] = a; + v[1] = b; + v[2] = c; + v[3] = d; } /** @@ -133,7 +135,7 @@ namespace agentxcpp { throw(inval_param()); } - return address[index]; + return v[index]; } /** @@ -147,10 +149,10 @@ namespace agentxcpp virtual Oid toOid() const { Oid oid; - oid.push_back(address[0]); - oid.push_back(address[1]); - oid.push_back(address[2]); - oid.push_back(address[3]); + oid.push_back(v[0]); + oid.push_back(v[1]); + oid.push_back(v[2]); + oid.push_back(v[3]); return oid; } @@ -174,7 +176,7 @@ namespace agentxcpp /** * \internal * - * \copydoc agentxcpp::IntegerVariable::handle_testet() + * \copydoc agentxcpp::IntegerVariable::handle_testset() */ virtual testset_result_t handle_testset(QSharedPointer _v) { @@ -182,7 +184,7 @@ namespace agentxcpp if (new_value) { // Type matches variable - return perform_testset(new_value->address); + return perform_testset(new_value->v); } else { @@ -195,7 +197,7 @@ namespace agentxcpp /** * \brief Handle a TestSet request. * - * \copydoc agentxcpp::IntegerVariable::perform_testet() + * \copydoc agentxcpp::IntegerVariable::perform_testset() */ virtual testset_result_t perform_testset(const quint8 _v[4]) { @@ -209,7 +211,7 @@ namespace agentxcpp */ virtual void handle_cleanupset() { - perform_cleanupset(new_value->address); + perform_cleanupset(new_value->v); } /** @@ -227,7 +229,7 @@ namespace agentxcpp */ virtual bool handle_commitset() { - return perform_commitset(new_value->address); + return perform_commitset(new_value->v); } /** @@ -245,7 +247,7 @@ namespace agentxcpp */ virtual bool handle_undoset() { - return perform_undoset(new_value->address); + return perform_undoset(new_value->v); } /** From de47eaf84291594bca9108d7f06f7a348b104684 Mon Sep 17 00:00:00 2001 From: "Tanjeff-N. Moos" Date: Sun, 29 Nov 2015 09:47:22 +0100 Subject: [PATCH 63/89] Review DisplayStringVariable/OctetStringVariable. --- src/DisplayStringVariable.hpp | 6 ++++-- src/OctetStringVariable.hpp | 20 +++++++++++--------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/DisplayStringVariable.hpp b/src/DisplayStringVariable.hpp index 55126f2..bc9d725 100644 --- a/src/DisplayStringVariable.hpp +++ b/src/DisplayStringVariable.hpp @@ -14,7 +14,7 @@ namespace agentxcpp * * This class represent an SNMP variable with SYNTAX DisplatString. The data * is stored and processed as an OctetStringVariable, but this class provides - * the methods value() and setValue() for easy string handling. + * additional methods for easy string handling. */ class DisplayStringVariable : public OctetStringVariable { @@ -22,7 +22,9 @@ class DisplayStringVariable : public OctetStringVariable public: /** - * \brief Create a DisplayString variable + * \brief (Default) constructor. + * + * Create a DisplayString variable. * * \param _value The initial value of the variable. * diff --git a/src/OctetStringVariable.hpp b/src/OctetStringVariable.hpp index 950432b..946b385 100644 --- a/src/OctetStringVariable.hpp +++ b/src/OctetStringVariable.hpp @@ -41,7 +41,9 @@ namespace agentxcpp binary serialize() const; /** - * \brief Construct object from binary data. + * \brief (Default) constructor. + * + * Construct object from binary data, or construct the empty string. */ OctetStringVariable(binary _value = binary()) : v(_value) @@ -56,9 +58,7 @@ namespace agentxcpp /** * \internal * - * \copydoc - * agentxcpp::IntegerVariable::IntegerVariable(binary::const_iterator&, - * const binary::const_iterator&, bool) + * \copydoc agentxcpp::IntegerVariable::IntegerVariable(binary::const_iterator&, const binary::const_iterator&, bool) * */ OctetStringVariable(binary::const_iterator& pos, @@ -74,12 +74,14 @@ namespace agentxcpp } /** - * \brief Set the current value. + * \copydoc agentxcpp::IntegerVariable::setValue() */ void setValue(QString _value); - /* - * \copydoc agentxcpp::IntegerVariable::value() + /** + * \brief Get the current value. + * + * \return The value. */ binary value() const { @@ -124,7 +126,7 @@ namespace agentxcpp /** * \internal * - * \copydoc agentxcpp::IntegerVariable::handle_testet() + * \copydoc agentxcpp::IntegerVariable::handle_testset() */ virtual testset_result_t handle_testset(QSharedPointer _v) { @@ -145,7 +147,7 @@ namespace agentxcpp /** * \brief Handle a TestSet request. * - * \copydoc agentxcpp::IntegerVariable::perform_testet() + * \copydoc agentxcpp::IntegerVariable::perform_testset() */ virtual testset_result_t perform_testset(const binary& _v) { From 4dd38eebda3edd488cd0ff329ce27f8dc761c5e4 Mon Sep 17 00:00:00 2001 From: "Tanjeff-N. Moos" Date: Sun, 29 Nov 2015 19:08:09 +0100 Subject: [PATCH 64/89] OidVariable: Implement toOid(), review docs. --- src/OidVariable.cpp | 42 +++++++++++++++++++++--------------------- src/OidVariable.hpp | 42 +++++++++++++++++++++++++----------------- 2 files changed, 46 insertions(+), 38 deletions(-) diff --git a/src/OidVariable.cpp b/src/OidVariable.cpp index a4e5451..5f60fa3 100644 --- a/src/OidVariable.cpp +++ b/src/OidVariable.cpp @@ -28,7 +28,7 @@ using namespace std; OidVariable::OidVariable(const Oid& o) { - mValue = o; + v = o; } @@ -61,25 +61,25 @@ binary OidVariable::serialize() const serialized[reserved_idx] = 0; // Set include field - serialized[include_idx] = mValue.include() ? 1 : 0; + serialized[include_idx] = v.include() ? 1 : 0; // Iterator for the subid's - Oid::const_iterator subid = mValue.begin(); + Oid::const_iterator subid = v.begin(); // Check whether we can use the prefix (RFC 2741, section 5.1) - if( mValue.size() >= 5 && - mValue[0] == 1 && - mValue[1] == 3 && - mValue[2] == 6 && - mValue[3] == 1 && - mValue[4] <= 0xff) // we have only one byte for the prefix! + if( v.size() >= 5 && + v[0] == 1 && + v[1] == 3 && + v[2] == 6 && + v[3] == 1 && + v[4] <= 0xff) // we have only one byte for the prefix! { // store the first integer after 1.3.6.1 to prefix field - serialized[prefix_idx] = mValue[4]; + serialized[prefix_idx] = v[4]; subid += 5; // point to the subid behind prefix // 5 elements are represented by prefix - serialized[n_subid_idx] = mValue.size() - 5; + serialized[n_subid_idx] = v.size() - 5; } else { @@ -87,11 +87,11 @@ binary OidVariable::serialize() const serialized[prefix_idx] = 0; // All subid's are stored in the stream explicitly - serialized[n_subid_idx] = mValue.size(); + serialized[n_subid_idx] = v.size(); } // copy subids to serialized - while( subid != mValue.end() ) + while( subid != v.end() ) { serialized.push_back( (*subid) >> 24 & 0xff ); serialized.push_back( (*subid) >> 16 & 0xff ); @@ -119,21 +119,21 @@ OidVariable::OidVariable(binary::const_iterator& pos, int prefix = *pos++; if( prefix != 0 ) { - mValue.push_back(1); - mValue.push_back(3); - mValue.push_back(6); - mValue.push_back(1); - mValue.push_back(prefix); + v.push_back(1); + v.push_back(3); + v.push_back(6); + v.push_back(1); + v.push_back(prefix); } // parse include field switch( *pos++ ) { case 0: - mValue.setInclude(false); + v.setInclude(false); break; case 1: - mValue.setInclude(true); + v.setInclude(true); break; default: // Invalid value; we are picky and indicate an error: @@ -167,7 +167,7 @@ OidVariable::OidVariable(binary::const_iterator& pos, subid |= *pos++ << 16; subid |= *pos++ << 24; } - mValue.push_back(subid); + v.push_back(subid); } } diff --git a/src/OidVariable.hpp b/src/OidVariable.hpp index a59cc20..2b308de 100644 --- a/src/OidVariable.hpp +++ b/src/OidVariable.hpp @@ -35,17 +35,18 @@ namespace agentxcpp * The agentXcpp library distinguishes between Oid and * OidVariable types. An Oid is a sequence of numbers, * while OidVariable is an SNMP variable representing an Oid. That - * means, that GET and SET requests are possible on OidVariable's, but + * means, that Get and Set requests are possible on OidVariable's, but * not on Oid's. */ class OidVariable: public AbstractVariable { - private: - + protected: /** * \brief The value represented by this variable. */ - Oid mValue; + Oid v; + + private: /** * \copydoc agentxcpp::IntegerVariable::new_value @@ -65,12 +66,23 @@ namespace agentxcpp */ OidVariable(const Oid& o); - /* - * \copydoc agentxcpp::IntegerVariable::value() + /** + * \brief Default constructor. + * + * Initialize the value to the null Oid. + */ + OidVariable() + { + } + + /** + * \brief Get the current value. + * + * \return The value. */ Oid value() { - return mValue; + return v; } /** @@ -78,7 +90,7 @@ namespace agentxcpp */ void setValue(const Oid& _value) { - mValue = _value; + v = _value; } /** @@ -93,9 +105,7 @@ namespace agentxcpp /** * \internal * - * \copydoc - * agentxcpp::IntegerVariable::IntegerVariable(binary::const_iterator&, - * const binary::const_iterator&, bool) + * \copydoc agentxcpp::IntegerVariable::IntegerVariable(binary::const_iterator&, const binary::const_iterator&, bool) * */ OidVariable(binary::const_iterator& pos, @@ -127,11 +137,11 @@ namespace agentxcpp // Store length if needed if(!fixedLength) { - oid.push_back(mValue.size()); + oid.push_back(v.size()); } // Store value - oid += mValue; + oid += v; return oid; } @@ -156,7 +166,7 @@ namespace agentxcpp /** * \internal * - * \copydoc agentxcpp::IntegerVariable::handle_testet() + * \copydoc agentxcpp::IntegerVariable::handle_testset() */ virtual testset_result_t handle_testset(QSharedPointer _v) { @@ -175,9 +185,7 @@ namespace agentxcpp } /** - * \brief Handle a TestSet request. - * - * \copydoc agentxcpp::IntegerVariable::perform_testet() + * \copydoc agentxcpp::IntegerVariable::perform_testset() */ virtual testset_result_t perform_testset(const Oid& _v) { From b02ced46512f98ec0c4d7cb365b22a1822cfaac3 Mon Sep 17 00:00:00 2001 From: "Tanjeff-N. Moos" Date: Sun, 29 Nov 2015 19:24:00 +0100 Subject: [PATCH 65/89] OpaqueVariable: Implement toOid(), review docs. --- src/OpaqueVariable.hpp | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/src/OpaqueVariable.hpp b/src/OpaqueVariable.hpp index 421670d..9797c19 100644 --- a/src/OpaqueVariable.hpp +++ b/src/OpaqueVariable.hpp @@ -28,19 +28,14 @@ namespace agentxcpp * \brief Represents an Opaque object as described in RFC 2741, section * 5.4. * - * This class represent binary data. - * - * \note There are no functions to convert the binary data to/from - * std::string. If that is needed, OctetStringValue might be a better - * choice. + * This class represents binary data. According to RFC 2578, + * OPAQUE is used to wrap any ASN.1-type. */ class OpaqueVariable : public AbstractVariable { protected: /** - * \brief The string. - * - * According to RFC 2578, Opaque is used to wrap any ASN.1-type. + * \brief The value. */ binary v; @@ -65,9 +60,7 @@ namespace agentxcpp /** * \internal * - * \copydoc - * agentxcpp::IntegerVariable::IntegerVariable(binary::const_iterator&, - * const binary::const_iterator&, bool) + * \copydoc agentxcpp::IntegerVariable::IntegerVariable(binary::const_iterator&, const binary::const_iterator&, bool) * */ OpaqueVariable(binary::const_iterator& pos, @@ -80,7 +73,9 @@ namespace agentxcpp OpaqueVariable(binary initial_value) : v(initial_value) {} /** - * \brief Standard constructor. + * \brief Default constructor. + * + * Initialize the object so it holds no data. */ OpaqueVariable() { @@ -94,8 +89,10 @@ namespace agentxcpp v = _value; } - /* - * \copydoc agentxcpp::IntegerVariable::value() + /** + * \brief Get the current value. + * + * \return The value. */ binary value() { @@ -122,7 +119,7 @@ namespace agentxcpp /** * \internal * - * \copydoc agentxcpp::IntegerVariable::handle_testet() + * \copydoc agentxcpp::IntegerVariable::handle_testset() */ virtual testset_result_t handle_testset(QSharedPointer _v) { @@ -141,9 +138,7 @@ namespace agentxcpp } /** - * \brief Handle a TestSet request. - * - * \copydoc agentxcpp::IntegerVariable::perform_testet() + * \copydoc agentxcpp::IntegerVariable::perform_testset() */ virtual testset_result_t perform_testset(const binary& _v) { @@ -209,7 +204,7 @@ namespace agentxcpp * * The conversion is done according to RFC 2578, * 7.7. "Mapping of the INDEX clause". First, the - * string length is converted to a subid. Then, each + * length of the data (in bytes) is converted to a subid. Then, each * octet of the value is converted into a separate subid. * * \todo Support fixed-length strings according to RFC 2578, From ffa23de5d6dedaee2ab8d2f1723fb5f29fc66dcd Mon Sep 17 00:00:00 2001 From: "Tanjeff-N. Moos" Date: Mon, 30 Nov 2015 09:19:47 +0100 Subject: [PATCH 66/89] TimeTicksVariable: Implement toOid(), review docs. --- src/IntegerVariable.hpp | 2 +- src/TimeTicksVariable.hpp | 44 ++++++++++++++++++++++----------------- 2 files changed, 26 insertions(+), 20 deletions(-) diff --git a/src/IntegerVariable.hpp b/src/IntegerVariable.hpp index d9b0731..edec142 100644 --- a/src/IntegerVariable.hpp +++ b/src/IntegerVariable.hpp @@ -314,7 +314,7 @@ namespace agentxcpp /** * \internal * - * \brief Handle a UndoSet request. + * \brief Handle an UndoSet request. * * This function calls perform_undoset() with the internal value of * \ref new_value (which was updated by the last diff --git a/src/TimeTicksVariable.hpp b/src/TimeTicksVariable.hpp index 41d61a7..9cc0b79 100644 --- a/src/TimeTicksVariable.hpp +++ b/src/TimeTicksVariable.hpp @@ -28,7 +28,7 @@ namespace agentxcpp { /** - * \brief Represents an TimeTicks as described in RFC 2741 + * \brief Represents a TimeTicks as described in RFC 2741 */ class TimeTicksVariable : public AbstractVariable { @@ -51,8 +51,8 @@ namespace agentxcpp public: /** - * \brief Create an TimeTicksValue without initialization. - * + * \brief (Default) constructor. + * * \param initial_value The initial value of the object. */ TimeTicksVariable(quint32 initial_value = 0) @@ -63,9 +63,7 @@ namespace agentxcpp /** * \internal * - * \copydoc - * agentxcpp::IntegerVariable::IntegerVariable(binary::const_iterator&, - * const binary::const_iterator&, bool) + * \copydoc agentxcpp::IntegerVariable::IntegerVariable(binary::const_iterator&, const binary::const_iterator&, bool) * */ TimeTicksVariable(binary::const_iterator& pos, @@ -89,8 +87,10 @@ namespace agentxcpp v = _value; } - /* - * \copydoc agentxcpp::IntegerVariable::value() + /** + * \brief Get the current value. + * + * \return The value. */ quint32 value() { @@ -117,7 +117,7 @@ namespace agentxcpp /** * \internal * - * \copydoc agentxcpp::IntegerVariable::handle_testet() + * \copydoc agentxcpp::IntegerVariable::handle_testset() */ virtual testset_result_t handle_testset(QSharedPointer _v) { @@ -136,9 +136,7 @@ namespace agentxcpp } /** - * \brief Handle a TestSet request. - * - * \copydoc agentxcpp::IntegerVariable::perform_testet() + * \copydoc agentxcpp::IntegerVariable::perform_testset() */ virtual testset_result_t perform_testset(quint32 _v) { @@ -198,16 +196,24 @@ namespace agentxcpp return false; } - /** - * \brief Return the null Oid. + /** + * \brief Convert the value to an OID. + * + * The conversion is done according to RFC 2578, + * 7.7. "Mapping of the INDEX clause". The value is + * converted to an Oid with a single subid. * - * This method returns the null Oid because RFC 2578, 7.7. - * "Mapping of the INDEX clause" does not - * describe how to convert Timeicks to an OID. - */ + * This method should not be overridden. + * + * \note If a TIMETICK is used in an INDEX clause, the + * value 0 should be avoided according to + * RFC 2578, 7.7. "Mapping of the INDEX clause". + */ virtual Oid toOid() const { - return Oid(); + Oid oid; + oid.push_back(v); + return oid; } }; From 68d19bb6106ef588eac7c18aa6e35bdf5217c877 Mon Sep 17 00:00:00 2001 From: "Tanjeff-N. Moos" Date: Mon, 30 Nov 2015 09:20:35 +0100 Subject: [PATCH 67/89] Small improvement of table tutorial. --- doc/how_to_implement_tables.dox | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/doc/how_to_implement_tables.dox b/doc/how_to_implement_tables.dox index 93630d9..44f80d7 100644 --- a/doc/how_to_implement_tables.dox +++ b/doc/how_to_implement_tables.dox @@ -202,7 +202,7 @@ class CounterChangeEntry : public TableEntry << counterChangeMilliseconds; return result; } - + virtual QMap< quint32, QSharedPointer > variables() { QMap< quint32, QSharedPointer > result; @@ -228,6 +228,9 @@ the index. Note that the entry's OID changes if the index variables change their value. Our simpleagent will not change an entry after it was added to the table, though. +\note The variable types Counter32 and Counter64 are not allowed as index + variables according to RFC 2578, 7.7. + The CounterChangeEntry::variables() method return all variables as a QMap. The map key will be used by the table as <variableSubOid> part for the variable. From 81a78979ef4bf2f937633153ce2e13e7f3ff0fa8 Mon Sep 17 00:00:00 2001 From: "Tanjeff-N. Moos" Date: Sun, 6 Dec 2015 00:30:01 +0100 Subject: [PATCH 68/89] Rename tutorial files. --- doc/{how_to_write_a_subagent.dox => tutor_1_ro_variables.dox} | 0 doc/{how_to_add_rw_support.dox => tutor_2_rw_variables.dox} | 0 doc/{how_to_send_notifications.dox => tutor_3_notifications.dox} | 0 doc/{how_to_implement_tables.dox => tutor_4_tables.dox} | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename doc/{how_to_write_a_subagent.dox => tutor_1_ro_variables.dox} (100%) rename doc/{how_to_add_rw_support.dox => tutor_2_rw_variables.dox} (100%) rename doc/{how_to_send_notifications.dox => tutor_3_notifications.dox} (100%) rename doc/{how_to_implement_tables.dox => tutor_4_tables.dox} (100%) diff --git a/doc/how_to_write_a_subagent.dox b/doc/tutor_1_ro_variables.dox similarity index 100% rename from doc/how_to_write_a_subagent.dox rename to doc/tutor_1_ro_variables.dox diff --git a/doc/how_to_add_rw_support.dox b/doc/tutor_2_rw_variables.dox similarity index 100% rename from doc/how_to_add_rw_support.dox rename to doc/tutor_2_rw_variables.dox diff --git a/doc/how_to_send_notifications.dox b/doc/tutor_3_notifications.dox similarity index 100% rename from doc/how_to_send_notifications.dox rename to doc/tutor_3_notifications.dox diff --git a/doc/how_to_implement_tables.dox b/doc/tutor_4_tables.dox similarity index 100% rename from doc/how_to_implement_tables.dox rename to doc/tutor_4_tables.dox From ed5899bb4a20d5b02b740c786b8d87dc8cc933cb Mon Sep 17 00:00:00 2001 From: "Tanjeff-N. Moos" Date: Sat, 6 Feb 2016 23:50:54 +0100 Subject: [PATCH 69/89] Get correct version even outside of git repos. --- SConstruct | 20 +++----------- doc/buildsystem.dox | 7 ++--- getversion.py | 65 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 72 insertions(+), 20 deletions(-) create mode 100755 getversion.py diff --git a/SConstruct b/SConstruct index c07ae1d..d23bb62 100644 --- a/SConstruct +++ b/SConstruct @@ -20,6 +20,7 @@ import subprocess import sys import os +import getversion ################################################# @@ -146,23 +147,8 @@ if with_libs != None: ################################################# ## Obtain description of current version -# Get current revision -# We ask git for a description of the current revision and add it to the -# environment. If an error occurs (e.g. git is not installed ot we are outside -# of a git repo) no revision can be determined. -# -# Note: subprocess.check_output() would be more appropriate, but doesn't -# exist in Python 2.4 :-( -try: - proc = subprocess.Popen(["git", "describe", "--always", "--dirty"], - stdout=subprocess.PIPE) - (out,err) = proc.communicate() - if proc.returncode == 0: - # only if call succeeded: - env['revision'] = out.strip() -except: - # git describe failed - probably git is not installed. - pass +# Add current revision to the environment +env['revision'] = getversion.getVersion() ################################################# diff --git a/doc/buildsystem.dox b/doc/buildsystem.dox index 4558ba8..488b4c4 100644 --- a/doc/buildsystem.dox +++ b/doc/buildsystem.dox @@ -101,7 +101,7 @@ To clean the project directory, type: scons -c This doesn't clean any files installed with scons install. - + \section howitworks How Scons works in agentXcpp @@ -134,8 +134,9 @@ provided: - --includedir=INCLUDEDIR - --docdir=DOCDIR -Next, the git command describe is used to determine the revision from -which agentXcpp is built. The revision is added to the build environment. +Next, getVersion() from the getversion.py script is invoked +to determine the revision from which agentXcpp is built. The revision is added +to the build environment. Finally, the subsidiary SConscript's are invoked, exporting the environment. diff --git a/getversion.py b/getversion.py new file mode 100755 index 0000000..cad3a0b --- /dev/null +++ b/getversion.py @@ -0,0 +1,65 @@ +#!/usr/bin/env python + +# +# Copyright 2011-2016 Tanjeff-Nicolai Moos +# +# This file is part of the agentXcpp library. +# +# AgentXcpp is free software: you can redistribute it and/or modify +# it under the terms of the AgentXcpp library license, version 1, which +# consists of the GNU General Public License and some additional +# permissions. +# +# AgentXcpp is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# See the AgentXcpp library license in the LICENSE file of this package +# for more details. +# + +import subprocess +import os + +# This function returns a string describing the current +# source tree version. +# +# First, it tries 'git describe'. If that fails, it tries to +# read the 'version' file located in the same directory +# as this script. If that also fails, it returns the string +# "unknown". +def getVersion(): + # 1) Try to get a version string from git + try: + # Note: subprocess.check_output() would maybe be more appropriate, but doesn't + # exist in Python 2.4 + proc = subprocess.Popen(["git", "describe", "--always", "--dirty", "--tags"], + stdout=subprocess.PIPE, stderr=subprocess.PIPE) + (out,err) = proc.communicate() + if proc.returncode == 0: + # only if call succeeded: + return out.strip() + except: + # git describe failed - maybe we are outside a git repo. + # -> continue execution + pass + + # 2) If 1. failed: Try 'version' file + scriptDir = os.path.dirname(os.path.realpath(__file__)) + versionFilePath = os.path.join(scriptDir, "version") + try: + with open(versionFilePath) as versionFile: + version = versionFile.readline() + return version.strip() + except: + # Failed. + pass + + # 3) If 1. and 2. failed, we don't know the version + return "unknown" + +# If this script is called directy (i.e. it was not imported +# by another script): print version string. +if __name__ == "__main__": + print(getVersion()) From ad72f7cd485dbfc059db318b009ddbc5ad4e0233 Mon Sep 17 00:00:00 2001 From: "Tanjeff-N. Moos" Date: Sun, 7 Feb 2016 22:20:43 +0100 Subject: [PATCH 70/89] Improve create-release script. 1) reimplement in python 2) don't require a commandline argument 3) add version file to archives --- create-release.py | 131 +++++++++++++++++++++++++++++++++ create-release.sh | 42 ----------- doc/how_to_create_releases.dox | 16 +--- 3 files changed, 135 insertions(+), 54 deletions(-) create mode 100755 create-release.py delete mode 100755 create-release.sh diff --git a/create-release.py b/create-release.py new file mode 100755 index 0000000..58d854a --- /dev/null +++ b/create-release.py @@ -0,0 +1,131 @@ +#!/usr/bin/env python + +# +# Copyright 2011-2016 Tanjeff-Nicolai Moos +# +# This file is part of the agentXcpp library. +# +# AgentXcpp is free software: you can redistribute it and/or modify +# it under the terms of the AgentXcpp library license, version 1, which +# consists of the GNU General Public License and some additional +# permissions. +# +# AgentXcpp is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# See the AgentXcpp library license in the LICENSE file of this package +# for more details. +# + +import subprocess +import gzip +import sys +import shutil +import tarfile +import zipfile +import os +import getversion + +# Note: This script uses subprocess.Popen() in favor of subprocess.check_output(), +# because the latter is not available in Python 2.4. + + +################### +# Some information +version = getversion.getVersion() +scriptDir = os.path.dirname(os.path.realpath(__file__)) +delivDir = os.path.join(scriptDir, "deliv") +versionFileName = os.path.join(scriptDir, 'version') +prefix = 'agentxcpp-' + version + '/' + + +################### +# Check if the repo is clean. +# We consider the repo clean if no tracked files were changed +# and no files are in the git staging area. Ignored and untracked +# files are allowed. +clean = True +try: + proc = subprocess.Popen(["git", "status", "--porcelain"], + stdout=subprocess.PIPE, stderr=subprocess.STDOUT) + (out,err) = proc.communicate() + for line in out.split('\n'): + if line.startswith('??') or line == "": + continue # ignore untracked files + clean = False + if clean == False: + print("Your repository is dirty. Use 'git status'.") +except: + print("Can't determine repository state. Are you in a git repo?") + clean = False +if clean == False: + # No delivery if repo is dirty + sys.exit(-1) + + +################### +# Remove and re-create delivery directory +if os.path.exists(delivDir): + print("Deleting " + os.path.relpath(delivDir) + "/") + shutil.rmtree(delivDir) +os.mkdir(delivDir) + + +################### +# Create version file +with open(versionFileName, 'w') as versionFile: + versionFile.write(version) + versionFile.write('\n') + +################### +# Create tar file +print("Creating tar file...") +tarName = os.path.join(delivDir, 'agentxcpp-' + version + '.tar') +tgzName = os.path.join(delivDir, 'agentxcpp-' + version + '.tgz') +proc = subprocess.Popen(["git", "archive", + "--format=tar", + '--prefix=' + prefix, + version, + '-o', tarName], + stdout=subprocess.PIPE) +(out,err) = proc.communicate() + +# Add version file to tarfile +with tarfile.open(tarName, "a") as tar: + tar.add(versionFileName, prefix + os.path.basename(versionFileName)) + +# Compress tar file, removing the uncompressed file +with open(tarName, 'rb') as f_in, gzip.open(tgzName, 'wb') as f_out: + shutil.copyfileobj(f_in, f_out) +os.remove(tarName) + + +################### +# Create ZIP file +print("Creating zip file...") +zipName = os.path.join(delivDir,'agentxcpp-' + version + '.zip') +proc = subprocess.Popen(["git", "archive", + "--format=zip", + '--prefix=' + prefix, + version, + '-o', zipName], + stdout=subprocess.PIPE) +(out,err) = proc.communicate() + +# Add version file to zipfile +with zipfile.ZipFile(zipName, "a") as f: + f.write(versionFileName, prefix + os.path.basename(versionFileName)) + + +################### +# Coda + +# Remove version file +os.remove(versionFileName) + +print("") +print("Created delivery for version " + version) +print("The files to deliver are now located in " + os.path.relpath(delivDir) + '/\n') + diff --git a/create-release.sh b/create-release.sh deleted file mode 100755 index a401327..0000000 --- a/create-release.sh +++ /dev/null @@ -1,42 +0,0 @@ -#!/bin/sh - -if [ -z "$1" ] -then - echo "Usage:" - echo "$0 " - exit 0 -fi - -git describe "$1" > /dev/null -if [ $? -ne 0 ] -then - echo "Error: $1 is not a value specifier." - exit -fi - -git archive --format=tar \ - "--prefix=agentXcpp-$1/" \ - "$1" \ - -o "agentXcpp-$1.tar" -if [ $? -ne 0 ] -then - echo "Error: git was not able to create an archive." - exit -fi - -gzip "agentXcpp-$1.tar" -if [ $? -ne 0 ] -then - echo "Error: gzip was not able to compress the archive." - exit -fi - -git archive --format=zip \ - "--prefix=agentXcpp-$1/" \ - "$1" \ - -o "agentXcpp-$1.zip" -if [ $? -ne 0 ] -then - echo "Error." - exit -fi diff --git a/doc/how_to_create_releases.dox b/doc/how_to_create_releases.dox index 6cfc81a..103ac8e 100644 --- a/doc/how_to_create_releases.dox +++ b/doc/how_to_create_releases.dox @@ -35,25 +35,17 @@ whenever an official release is created: -# Update the ChangeLog. Check it in. -# Update the README. Check it in. --# Create an annotated git tag for the release.
+-# Create an git tag for the release.
Each release shall have a tag to uniqely identify it. Do not push the tag yet. --# Create the packages using the create-release.sh script.
- The packages shall have the names agentXcpp-<version>.tar.gz and - agentXcpp-<version>.zip respectively, where <version> is the - tag name. The contents shall be a single directory named - agentXcpp-<version>. This directory shall contain the source code. - This is all ensured by the create_release.sh script. +-# Create the packages using the create-release.py script.
-# Test one of the packages:
-# Unpack it. -# Build and install the contained software.
There should be no warnings during build. -# Perform the howtos to ensure that they work. - -# This is the time to browse the documentation (API and internals) and - check whether it is in good shape. This step cannot be formalized, but - eye-catching errors might be found by simply looking around a bit. -# If the test fails: no release possible; remove the tag, fix the problem - and re-start from step 1. --# If the test succeeds, the packages and the tag can be published. + and re-start from step 1. +-# If the test succeeds, the packages can be published and the tag can be pushed. */ From 1000938592c71f2497c621ee990ff56384b6e446 Mon Sep 17 00:00:00 2001 From: "Tanjeff-N. Moos" Date: Sun, 7 Feb 2016 23:11:13 +0100 Subject: [PATCH 71/89] Update doxyfiles to doxygen 1.8.8. --- doc/api.doxyfile | 2416 ++++++++++++++++++++++++---------------- doc/internals.doxyfile | 2416 ++++++++++++++++++++++++---------------- 2 files changed, 2956 insertions(+), 1876 deletions(-) diff --git a/doc/api.doxyfile b/doc/api.doxyfile index f42490f..cf49ee3 100644 --- a/doc/api.doxyfile +++ b/doc/api.doxyfile @@ -1,124 +1,122 @@ -# -# Copyright 2011-2012 Tanjeff-Nicolai Moos -# -# This file is part of the agentXcpp library. -# -# AgentXcpp is free software: you can redistribute it and/or modify -# it under the terms of the AgentXcpp library license, version 1, which -# consists of the GNU General Public License and some additional -# permissions. -# -# AgentXcpp is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# See the AgentXcpp library license in the LICENSE file of this package -# for more details. -# - - -# Doxyfile 1.8.1.2 +# Doxyfile 1.8.8 # This file describes the settings to be used by the documentation system # doxygen (www.doxygen.org) for a project. # -# All text after a hash (#) is considered a comment and will be ignored. +# All text after a double hash (##) is considered a comment and is placed in +# front of the TAG it is preceding. +# +# All text after a single hash (#) is considered a comment and will be ignored. # The format is: -# TAG = value [value, ...] -# For lists items can also be appended using: -# TAG += value [value, ...] -# Values that contain spaces should be placed between quotes (" "). +# TAG = value [value, ...] +# For lists, items can also be appended using: +# TAG += value [value, ...] +# Values that contain spaces should be placed between quotes (\" \"). #--------------------------------------------------------------------------- # Project related configuration options #--------------------------------------------------------------------------- # This tag specifies the encoding used for all characters in the config file -# that follow. The default is UTF-8 which is also the encoding used for all -# text before the first occurrence of this tag. Doxygen uses libiconv (or the -# iconv built into libc) for the transcoding. See -# http://www.gnu.org/software/libiconv for the list of possible encodings. +# that follow. The default is UTF-8 which is also the encoding used for all text +# before the first occurrence of this tag. Doxygen uses libiconv (or the iconv +# built into libc) for the transcoding. See http://www.gnu.org/software/libiconv +# for the list of possible encodings. +# The default value is: UTF-8. DOXYFILE_ENCODING = UTF-8 -# The PROJECT_NAME tag is a single word (or sequence of words) that should -# identify the project. Note that if you do not use Doxywizard you need -# to put quotes around the project name if it contains spaces. +# The PROJECT_NAME tag is a single word (or a sequence of words surrounded by +# double-quotes, unless you are using Doxywizard) that should identify the +# project for which the documentation is generated. This name is used in the +# title of most generated pages and in a few other places. +# The default value is: My Project. PROJECT_NAME = AgentXcpp -# The PROJECT_NUMBER tag can be used to enter a project or revision number. -# This could be handy for archiving the generated documentation or -# if some version control system is used. +# The PROJECT_NUMBER tag can be used to enter a project or revision number. This +# could be handy for archiving the generated documentation or if some version +# control system is used. PROJECT_NUMBER = # Using the PROJECT_BRIEF tag one can provide an optional one line description -# for a project that appears at the top of each page and should give viewer -# a quick idea about the purpose of the project. Keep the description short. +# for a project that appears at the top of each page and should give viewer a +# quick idea about the purpose of the project. Keep the description short. PROJECT_BRIEF = "API Documentation" -# With the PROJECT_LOGO tag one can specify an logo or icon that is -# included in the documentation. The maximum height of the logo should not -# exceed 55 pixels and the maximum width should not exceed 200 pixels. -# Doxygen will copy the logo to the output directory. +# With the PROJECT_LOGO tag one can specify an logo or icon that is included in +# the documentation. The maximum height of the logo should not exceed 55 pixels +# and the maximum width should not exceed 200 pixels. Doxygen will copy the logo +# to the output directory. PROJECT_LOGO = html_logo.png -# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) -# base path where the generated documentation will be put. -# If a relative path is entered, it will be relative to the location -# where doxygen was started. If left blank the current directory will be used. +# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) path +# into which the generated documentation will be written. If a relative path is +# entered, it will be relative to the location where doxygen was started. If +# left blank the current directory will be used. OUTPUT_DIRECTORY = api -# If the CREATE_SUBDIRS tag is set to YES, then doxygen will create -# 4096 sub-directories (in 2 levels) under the output directory of each output -# format and will distribute the generated files over these directories. -# Enabling this option can be useful when feeding doxygen a huge amount of -# source files, where putting all generated files in the same directory would -# otherwise cause performance problems for the file system. +# If the CREATE_SUBDIRS tag is set to YES, then doxygen will create 4096 sub- +# directories (in 2 levels) under the output directory of each output format and +# will distribute the generated files over these directories. Enabling this +# option can be useful when feeding doxygen a huge amount of source files, where +# putting all generated files in the same directory would otherwise causes +# performance problems for the file system. +# The default value is: NO. CREATE_SUBDIRS = NO +# If the ALLOW_UNICODE_NAMES tag is set to YES, doxygen will allow non-ASCII +# characters to appear in the names of generated files. If set to NO, non-ASCII +# characters will be escaped, for example _xE3_x81_x84 will be used for Unicode +# U+3044. +# The default value is: NO. + +ALLOW_UNICODE_NAMES = NO + # The OUTPUT_LANGUAGE tag is used to specify the language in which all # documentation generated by doxygen is written. Doxygen will use this # information to generate all constant output in the proper language. -# The default language is English, other supported languages are: -# Afrikaans, Arabic, Brazilian, Catalan, Chinese, Chinese-Traditional, -# Croatian, Czech, Danish, Dutch, Esperanto, Farsi, Finnish, French, German, -# Greek, Hungarian, Italian, Japanese, Japanese-en (Japanese with English -# messages), Korean, Korean-en, Lithuanian, Norwegian, Macedonian, Persian, -# Polish, Portuguese, Romanian, Russian, Serbian, Serbian-Cyrillic, Slovak, -# Slovene, Spanish, Swedish, Ukrainian, and Vietnamese. +# Possible values are: Afrikaans, Arabic, Armenian, Brazilian, Catalan, Chinese, +# Chinese-Traditional, Croatian, Czech, Danish, Dutch, English (United States), +# Esperanto, Farsi (Persian), Finnish, French, German, Greek, Hungarian, +# Indonesian, Italian, Japanese, Japanese-en (Japanese with English messages), +# Korean, Korean-en (Korean with English messages), Latvian, Lithuanian, +# Macedonian, Norwegian, Persian (Farsi), Polish, Portuguese, Romanian, Russian, +# Serbian, Serbian-Cyrillic, Slovak, Slovene, Spanish, Swedish, Turkish, +# Ukrainian and Vietnamese. +# The default value is: English. OUTPUT_LANGUAGE = English -# If the BRIEF_MEMBER_DESC tag is set to YES (the default) Doxygen will -# include brief member descriptions after the members that are listed in -# the file and class documentation (similar to JavaDoc). -# Set to NO to disable this. +# If the BRIEF_MEMBER_DESC tag is set to YES doxygen will include brief member +# descriptions after the members that are listed in the file and class +# documentation (similar to Javadoc). Set to NO to disable this. +# The default value is: YES. BRIEF_MEMBER_DESC = YES -# If the REPEAT_BRIEF tag is set to YES (the default) Doxygen will prepend -# the brief description of a member or function before the detailed description. -# Note: if both HIDE_UNDOC_MEMBERS and BRIEF_MEMBER_DESC are set to NO, the +# If the REPEAT_BRIEF tag is set to YES doxygen will prepend the brief +# description of a member or function before the detailed description +# +# Note: If both HIDE_UNDOC_MEMBERS and BRIEF_MEMBER_DESC are set to NO, the # brief descriptions will be completely suppressed. +# The default value is: YES. REPEAT_BRIEF = YES -# This tag implements a quasi-intelligent brief description abbreviator -# that is used to form the text in various listings. Each string -# in this list, if found as the leading text of the brief description, will be -# stripped from the text and the result after processing the whole list, is -# used as the annotated text. Otherwise, the brief description is used as-is. -# If left blank, the following values are used ("$name" is automatically -# replaced with the name of the entity): "The $name class" "The $name widget" -# "The $name file" "is" "provides" "specifies" "contains" -# "represents" "a" "an" "the" +# This tag implements a quasi-intelligent brief description abbreviator that is +# used to form the text in various listings. Each string in this list, if found +# as the leading text of the brief description, will be stripped from the text +# and the result, after processing the whole list, is used as the annotated +# text. Otherwise, the brief description is used as-is. If left blank, the +# following values are used ($name is automatically replaced with the name of +# the entity):The $name class, The $name widget, The $name file, is, provides, +# specifies, contains, represents, a, an and the. ABBREVIATE_BRIEF = "The $name class" \ "The $name widget" \ @@ -133,8 +131,9 @@ ABBREVIATE_BRIEF = "The $name class" \ the # If the ALWAYS_DETAILED_SEC and REPEAT_BRIEF tags are both set to YES then -# Doxygen will generate a detailed section even if there is only a brief +# doxygen will generate a detailed section even if there is only a brief # description. +# The default value is: NO. ALWAYS_DETAILED_SEC = YES @@ -142,169 +141,207 @@ ALWAYS_DETAILED_SEC = YES # inherited members of a class in the documentation of that class as if those # members were ordinary class members. Constructors, destructors and assignment # operators of the base classes will not be shown. +# The default value is: NO. INLINE_INHERITED_MEMB = NO -# If the FULL_PATH_NAMES tag is set to YES then Doxygen will prepend the full -# path before files name in the file list and in the header files. If set -# to NO the shortest path that makes the file name unique will be used. +# If the FULL_PATH_NAMES tag is set to YES doxygen will prepend the full path +# before files name in the file list and in the header files. If set to NO the +# shortest path that makes the file name unique will be used +# The default value is: YES. FULL_PATH_NAMES = YES -# If the FULL_PATH_NAMES tag is set to YES then the STRIP_FROM_PATH tag -# can be used to strip a user-defined part of the path. Stripping is -# only done if one of the specified strings matches the left-hand part of -# the path. The tag can be used to show relative paths in the file list. -# If left blank the directory from which doxygen is run is used as the -# path to strip. +# The STRIP_FROM_PATH tag can be used to strip a user-defined part of the path. +# Stripping is only done if one of the specified strings matches the left-hand +# part of the path. The tag can be used to show relative paths in the file list. +# If left blank the directory from which doxygen is run is used as the path to +# strip. +# +# Note that you can specify absolute paths here, but also relative paths, which +# will be relative from the directory where doxygen is started. +# This tag requires that the tag FULL_PATH_NAMES is set to YES. STRIP_FROM_PATH = -# The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of -# the path mentioned in the documentation of a class, which tells -# the reader which header file to include in order to use a class. -# If left blank only the name of the header file containing the class -# definition is used. Otherwise one should specify the include paths that -# are normally passed to the compiler using the -I flag. +# The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of the +# path mentioned in the documentation of a class, which tells the reader which +# header file to include in order to use a class. If left blank only the name of +# the header file containing the class definition is used. Otherwise one should +# specify the list of include paths that are normally passed to the compiler +# using the -I flag. STRIP_FROM_INC_PATH = -# If the SHORT_NAMES tag is set to YES, doxygen will generate much shorter -# (but less readable) file names. This can be useful if your file system -# doesn't support long names like on DOS, Mac, or CD-ROM. +# If the SHORT_NAMES tag is set to YES, doxygen will generate much shorter (but +# less readable) file names. This can be useful is your file systems doesn't +# support long names like on DOS, Mac, or CD-ROM. +# The default value is: NO. SHORT_NAMES = NO -# If the JAVADOC_AUTOBRIEF tag is set to YES then Doxygen -# will interpret the first line (until the first dot) of a JavaDoc-style -# comment as the brief description. If set to NO, the JavaDoc -# comments will behave just like regular Qt-style comments -# (thus requiring an explicit @brief command for a brief description.) +# If the JAVADOC_AUTOBRIEF tag is set to YES then doxygen will interpret the +# first line (until the first dot) of a Javadoc-style comment as the brief +# description. If set to NO, the Javadoc-style will behave just like regular Qt- +# style comments (thus requiring an explicit @brief command for a brief +# description.) +# The default value is: NO. JAVADOC_AUTOBRIEF = NO -# If the QT_AUTOBRIEF tag is set to YES then Doxygen will -# interpret the first line (until the first dot) of a Qt-style -# comment as the brief description. If set to NO, the comments -# will behave just like regular Qt-style comments (thus requiring -# an explicit \brief command for a brief description.) +# If the QT_AUTOBRIEF tag is set to YES then doxygen will interpret the first +# line (until the first dot) of a Qt-style comment as the brief description. If +# set to NO, the Qt-style will behave just like regular Qt-style comments (thus +# requiring an explicit \brief command for a brief description.) +# The default value is: NO. QT_AUTOBRIEF = NO -# The MULTILINE_CPP_IS_BRIEF tag can be set to YES to make Doxygen -# treat a multi-line C++ special comment block (i.e. a block of //! or /// -# comments) as a brief description. This used to be the default behaviour. -# The new default is to treat a multi-line C++ comment block as a detailed -# description. Set this tag to YES if you prefer the old behaviour instead. +# The MULTILINE_CPP_IS_BRIEF tag can be set to YES to make doxygen treat a +# multi-line C++ special comment block (i.e. a block of //! or /// comments) as +# a brief description. This used to be the default behavior. The new default is +# to treat a multi-line C++ comment block as a detailed description. Set this +# tag to YES if you prefer the old behavior instead. +# +# Note that setting this tag to YES also means that rational rose comments are +# not recognized any more. +# The default value is: NO. MULTILINE_CPP_IS_BRIEF = NO -# If the INHERIT_DOCS tag is set to YES (the default) then an undocumented -# member inherits the documentation from any documented member that it -# re-implements. +# If the INHERIT_DOCS tag is set to YES then an undocumented member inherits the +# documentation from any documented member that it re-implements. +# The default value is: YES. INHERIT_DOCS = NO -# If the SEPARATE_MEMBER_PAGES tag is set to YES, then doxygen will produce -# a new page for each member. If set to NO, the documentation of a member will -# be part of the file/class/namespace that contains it. +# If the SEPARATE_MEMBER_PAGES tag is set to YES, then doxygen will produce a +# new page for each member. If set to NO, the documentation of a member will be +# part of the file/class/namespace that contains it. +# The default value is: NO. SEPARATE_MEMBER_PAGES = NO -# The TAB_SIZE tag can be used to set the number of spaces in a tab. -# Doxygen uses this value to replace tabs by spaces in code fragments. +# The TAB_SIZE tag can be used to set the number of spaces in a tab. Doxygen +# uses this value to replace tabs by spaces in code fragments. +# Minimum value: 1, maximum value: 16, default value: 4. TAB_SIZE = 8 -# This tag can be used to specify a number of aliases that acts -# as commands in the documentation. An alias has the form "name=value". -# For example adding "sideeffect=\par Side Effects:\n" will allow you to -# put the command \sideeffect (or @sideeffect) in the documentation, which -# will result in a user-defined paragraph with heading "Side Effects:". -# You can put \n's in the value part of an alias to insert newlines. +# This tag can be used to specify a number of aliases that act as commands in +# the documentation. An alias has the form: +# name=value +# For example adding +# "sideeffect=@par Side Effects:\n" +# will allow you to put the command \sideeffect (or @sideeffect) in the +# documentation, which will result in a user-defined paragraph with heading +# "Side Effects:". You can put \n's in the value part of an alias to insert +# newlines. -ALIASES = agentxcpp{1}="\ref agentxcpp::\1 \"\1\"" +ALIASES = "agentxcpp{1}=\ref agentxcpp::\1 \"\1\"" # This tag can be used to specify a number of word-keyword mappings (TCL only). -# A mapping has the form "name=value". For example adding -# "class=itcl::class" will allow you to use the command class in the -# itcl::class meaning. +# A mapping has the form "name=value". For example adding "class=itcl::class" +# will allow you to use the command class in the itcl::class meaning. TCL_SUBST = -# Set the OPTIMIZE_OUTPUT_FOR_C tag to YES if your project consists of C -# sources only. Doxygen will then generate output that is more tailored for C. -# For instance, some of the names that are used will be different. The list -# of all members will be omitted, etc. +# Set the OPTIMIZE_OUTPUT_FOR_C tag to YES if your project consists of C sources +# only. Doxygen will then generate output that is more tailored for C. For +# instance, some of the names that are used will be different. The list of all +# members will be omitted, etc. +# The default value is: NO. OPTIMIZE_OUTPUT_FOR_C = NO -# Set the OPTIMIZE_OUTPUT_JAVA tag to YES if your project consists of Java -# sources only. Doxygen will then generate output that is more tailored for -# Java. For instance, namespaces will be presented as packages, qualified -# scopes will look different, etc. +# Set the OPTIMIZE_OUTPUT_JAVA tag to YES if your project consists of Java or +# Python sources only. Doxygen will then generate output that is more tailored +# for that language. For instance, namespaces will be presented as packages, +# qualified scopes will look different, etc. +# The default value is: NO. OPTIMIZE_OUTPUT_JAVA = NO # Set the OPTIMIZE_FOR_FORTRAN tag to YES if your project consists of Fortran -# sources only. Doxygen will then generate output that is more tailored for -# Fortran. +# sources. Doxygen will then generate output that is tailored for Fortran. +# The default value is: NO. OPTIMIZE_FOR_FORTRAN = NO # Set the OPTIMIZE_OUTPUT_VHDL tag to YES if your project consists of VHDL -# sources. Doxygen will then generate output that is tailored for -# VHDL. +# sources. Doxygen will then generate output that is tailored for VHDL. +# The default value is: NO. OPTIMIZE_OUTPUT_VHDL = NO # Doxygen selects the parser to use depending on the extension of the files it -# parses. With this tag you can assign which parser to use for a given extension. -# Doxygen has a built-in mapping, but you can override or extend it using this -# tag. The format is ext=language, where ext is a file extension, and language -# is one of the parsers supported by doxygen: IDL, Java, Javascript, CSharp, C, -# C++, D, PHP, Objective-C, Python, Fortran, VHDL, C, C++. For instance to make -# doxygen treat .inc files as Fortran files (default is PHP), and .f files as C -# (default is Fortran), use: inc=Fortran f=C. Note that for custom extensions -# you also need to set FILE_PATTERNS otherwise the files are not read by doxygen. +# parses. With this tag you can assign which parser to use for a given +# extension. Doxygen has a built-in mapping, but you can override or extend it +# using this tag. The format is ext=language, where ext is a file extension, and +# language is one of the parsers supported by doxygen: IDL, Java, Javascript, +# C#, C, C++, D, PHP, Objective-C, Python, Fortran (fixed format Fortran: +# FortranFixed, free formatted Fortran: FortranFree, unknown formatted Fortran: +# Fortran. In the later case the parser tries to guess whether the code is fixed +# or free formatted code, this is the default for Fortran type files), VHDL. For +# instance to make doxygen treat .inc files as Fortran files (default is PHP), +# and .f files as C (default is Fortran), use: inc=Fortran f=C. +# +# Note For files without extension you can use no_extension as a placeholder. +# +# Note that for custom extensions you also need to set FILE_PATTERNS otherwise +# the files are not read by doxygen. EXTENSION_MAPPING = -# If MARKDOWN_SUPPORT is enabled (the default) then doxygen pre-processes all -# comments according to the Markdown format, which allows for more readable +# If the MARKDOWN_SUPPORT tag is enabled then doxygen pre-processes all comments +# according to the Markdown format, which allows for more readable # documentation. See http://daringfireball.net/projects/markdown/ for details. -# The output of markdown processing is further processed by doxygen, so you -# can mix doxygen, HTML, and XML commands with Markdown formatting. -# Disable only in case of backward compatibilities issues. +# The output of markdown processing is further processed by doxygen, so you can +# mix doxygen, HTML, and XML commands with Markdown formatting. Disable only in +# case of backward compatibilities issues. +# The default value is: YES. MARKDOWN_SUPPORT = YES +# When enabled doxygen tries to link words that correspond to documented +# classes, or namespaces to their corresponding documentation. Such a link can +# be prevented in individual cases by by putting a % sign in front of the word +# or globally by setting AUTOLINK_SUPPORT to NO. +# The default value is: YES. + +AUTOLINK_SUPPORT = YES + # If you use STL classes (i.e. std::string, std::vector, etc.) but do not want -# to include (a tag file for) the STL sources as input, then you should -# set this tag to YES in order to let doxygen match functions declarations and -# definitions whose arguments contain STL classes (e.g. func(std::string); v.s. -# func(std::string) {}). This also makes the inheritance and collaboration +# to include (a tag file for) the STL sources as input, then you should set this +# tag to YES in order to let doxygen match functions declarations and +# definitions whose arguments contain STL classes (e.g. func(std::string); +# versus func(std::string) {}). This also make the inheritance and collaboration # diagrams that involve STL classes more complete and accurate. +# The default value is: NO. BUILTIN_STL_SUPPORT = YES # If you use Microsoft's C++/CLI language, you should set this option to YES to # enable parsing support. +# The default value is: NO. CPP_CLI_SUPPORT = NO -# Set the SIP_SUPPORT tag to YES if your project consists of sip sources only. -# Doxygen will parse them like normal C++ but will assume all classes use public -# instead of private inheritance when no explicit protection keyword is present. +# Set the SIP_SUPPORT tag to YES if your project consists of sip (see: +# http://www.riverbankcomputing.co.uk/software/sip/intro) sources only. Doxygen +# will parse them like normal C++ but will assume all classes use public instead +# of private inheritance when no explicit protection keyword is present. +# The default value is: NO. SIP_SUPPORT = NO -# For Microsoft's IDL there are propget and propput attributes to indicate getter -# and setter methods for a property. Setting this option to YES (the default) -# will make doxygen replace the get and set methods by a property in the -# documentation. This will only work if the methods are indeed getting or -# setting a simple type. If this is not the case, or you want to show the -# methods anyway, you should set this option to NO. +# For Microsoft's IDL there are propget and propput attributes to indicate +# getter and setter methods for a property. Setting this option to YES will make +# doxygen to replace the get and set methods by a property in the documentation. +# This will only work if the methods are indeed getting or setting a simple +# type. If this is not the case, or you want to show the methods anyway, you +# should set this option to NO. +# The default value is: YES. IDL_PROPERTY_SUPPORT = YES @@ -312,67 +349,61 @@ IDL_PROPERTY_SUPPORT = YES # tag is set to YES, then doxygen will reuse the documentation of the first # member in the group (if any) for the other members of the group. By default # all members of a group must be documented explicitly. +# The default value is: NO. DISTRIBUTE_GROUP_DOC = NO -# Set the SUBGROUPING tag to YES (the default) to allow class member groups of -# the same type (for instance a group of public functions) to be put as a -# subgroup of that type (e.g. under the Public Functions section). Set it to -# NO to prevent subgrouping. Alternatively, this can be done per class using -# the \nosubgrouping command. +# Set the SUBGROUPING tag to YES to allow class member groups of the same type +# (for instance a group of public functions) to be put as a subgroup of that +# type (e.g. under the Public Functions section). Set it to NO to prevent +# subgrouping. Alternatively, this can be done per class using the +# \nosubgrouping command. +# The default value is: YES. SUBGROUPING = YES -# When the INLINE_GROUPED_CLASSES tag is set to YES, classes, structs and -# unions are shown inside the group in which they are included (e.g. using -# @ingroup) instead of on a separate page (for HTML and Man pages) or -# section (for LaTeX and RTF). +# When the INLINE_GROUPED_CLASSES tag is set to YES, classes, structs and unions +# are shown inside the group in which they are included (e.g. using \ingroup) +# instead of on a separate page (for HTML and Man pages) or section (for LaTeX +# and RTF). +# +# Note that this feature does not work in combination with +# SEPARATE_MEMBER_PAGES. +# The default value is: NO. INLINE_GROUPED_CLASSES = NO -# When the INLINE_SIMPLE_STRUCTS tag is set to YES, structs, classes, and -# unions with only public data fields will be shown inline in the documentation -# of the scope in which they are defined (i.e. file, namespace, or group -# documentation), provided this scope is documented. If set to NO (the default), -# structs, classes, and unions are shown on a separate page (for HTML and Man -# pages) or section (for LaTeX and RTF). +# When the INLINE_SIMPLE_STRUCTS tag is set to YES, structs, classes, and unions +# with only public data fields or simple typedef fields will be shown inline in +# the documentation of the scope in which they are defined (i.e. file, +# namespace, or group documentation), provided this scope is documented. If set +# to NO, structs, classes, and unions are shown on a separate page (for HTML and +# Man pages) or section (for LaTeX and RTF). +# The default value is: NO. INLINE_SIMPLE_STRUCTS = NO -# When TYPEDEF_HIDES_STRUCT is enabled, a typedef of a struct, union, or enum -# is documented as struct, union, or enum with the name of the typedef. So +# When TYPEDEF_HIDES_STRUCT tag is enabled, a typedef of a struct, union, or +# enum is documented as struct, union, or enum with the name of the typedef. So # typedef struct TypeS {} TypeT, will appear in the documentation as a struct # with name TypeT. When disabled the typedef will appear as a member of a file, -# namespace, or class. And the struct will be named TypeS. This can typically -# be useful for C code in case the coding convention dictates that all compound +# namespace, or class. And the struct will be named TypeS. This can typically be +# useful for C code in case the coding convention dictates that all compound # types are typedef'ed and only the typedef is referenced, never the tag name. +# The default value is: NO. TYPEDEF_HIDES_STRUCT = NO -# The SYMBOL_CACHE_SIZE determines the size of the internal cache use to -# determine which symbols to keep in memory and which to flush to disk. -# When the cache is full, less often used symbols will be written to disk. -# For small to medium size projects (<1000 input files) the default value is -# probably good enough. For larger projects a too small cache size can cause -# doxygen to be busy swapping symbols to and from disk most of the time -# causing a significant performance penalty. -# If the system has enough physical memory increasing the cache will improve the -# performance by keeping more symbols in memory. Note that the value works on -# a logarithmic scale so increasing the size by one will roughly double the -# memory usage. The cache size is given by this formula: -# 2^(16+SYMBOL_CACHE_SIZE). The valid range is 0..9, the default is 0, -# corresponding to a cache size of 2^16 = 65536 symbols. - -SYMBOL_CACHE_SIZE = 0 - -# Similar to the SYMBOL_CACHE_SIZE the size of the symbol lookup cache can be -# set using LOOKUP_CACHE_SIZE. This cache is used to resolve symbols given -# their name and scope. Since this can be an expensive process and often the -# same symbol appear multiple times in the code, doxygen keeps a cache of -# pre-resolved symbols. If the cache is too small doxygen will become slower. -# If the cache is too large, memory is wasted. The cache size is given by this -# formula: 2^(16+LOOKUP_CACHE_SIZE). The valid range is 0..9, the default is 0, -# corresponding to a cache size of 2^16 = 65536 symbols. +# The size of the symbol lookup cache can be set using LOOKUP_CACHE_SIZE. This +# cache is used to resolve symbols given their name and scope. Since this can be +# an expensive process and often the same symbol appears multiple times in the +# code, doxygen keeps a cache of pre-resolved symbols. If the cache is too small +# doxygen will become slower. If the cache is too large, memory is wasted. The +# cache size is given by this formula: 2^(16+LOOKUP_CACHE_SIZE). The valid range +# is 0..9, the default is 0, corresponding to a cache size of 2^16=65536 +# symbols. At the end of a run doxygen will report the cache usage and suggest +# the optimal cache size from a speed point of view. +# Minimum value: 0, maximum value: 9, default value: 0. LOOKUP_CACHE_SIZE = 0 @@ -381,329 +412,378 @@ LOOKUP_CACHE_SIZE = 0 #--------------------------------------------------------------------------- # If the EXTRACT_ALL tag is set to YES doxygen will assume all entities in -# documentation are documented, even if no documentation was available. -# Private class members and static file members will be hidden unless -# the EXTRACT_PRIVATE and EXTRACT_STATIC tags are set to YES +# documentation are documented, even if no documentation was available. Private +# class members and static file members will be hidden unless the +# EXTRACT_PRIVATE respectively EXTRACT_STATIC tags are set to YES. +# Note: This will also disable the warnings about undocumented members that are +# normally produced when WARNINGS is set to YES. +# The default value is: NO. EXTRACT_ALL = NO -# If the EXTRACT_PRIVATE tag is set to YES all private members of a class -# will be included in the documentation. +# If the EXTRACT_PRIVATE tag is set to YES all private members of a class will +# be included in the documentation. +# The default value is: NO. EXTRACT_PRIVATE = NO -# If the EXTRACT_PACKAGE tag is set to YES all members with package or internal scope will be included in the documentation. +# If the EXTRACT_PACKAGE tag is set to YES all members with package or internal +# scope will be included in the documentation. +# The default value is: NO. EXTRACT_PACKAGE = NO -# If the EXTRACT_STATIC tag is set to YES all static members of a file -# will be included in the documentation. +# If the EXTRACT_STATIC tag is set to YES all static members of a file will be +# included in the documentation. +# The default value is: NO. EXTRACT_STATIC = NO -# If the EXTRACT_LOCAL_CLASSES tag is set to YES classes (and structs) -# defined locally in source files will be included in the documentation. -# If set to NO only classes defined in header files are included. +# If the EXTRACT_LOCAL_CLASSES tag is set to YES classes (and structs) defined +# locally in source files will be included in the documentation. If set to NO +# only classes defined in header files are included. Does not have any effect +# for Java sources. +# The default value is: YES. EXTRACT_LOCAL_CLASSES = YES -# This flag is only useful for Objective-C code. When set to YES local -# methods, which are defined in the implementation section but not in -# the interface are included in the documentation. -# If set to NO (the default) only methods in the interface are included. +# This flag is only useful for Objective-C code. When set to YES local methods, +# which are defined in the implementation section but not in the interface are +# included in the documentation. If set to NO only methods in the interface are +# included. +# The default value is: NO. EXTRACT_LOCAL_METHODS = NO # If this flag is set to YES, the members of anonymous namespaces will be # extracted and appear in the documentation as a namespace called -# 'anonymous_namespace{file}', where file will be replaced with the base -# name of the file that contains the anonymous namespace. By default -# anonymous namespaces are hidden. +# 'anonymous_namespace{file}', where file will be replaced with the base name of +# the file that contains the anonymous namespace. By default anonymous namespace +# are hidden. +# The default value is: NO. EXTRACT_ANON_NSPACES = NO -# If the HIDE_UNDOC_MEMBERS tag is set to YES, Doxygen will hide all -# undocumented members of documented classes, files or namespaces. -# If set to NO (the default) these members will be included in the -# various overviews, but no documentation section is generated. -# This option has no effect if EXTRACT_ALL is enabled. +# If the HIDE_UNDOC_MEMBERS tag is set to YES, doxygen will hide all +# undocumented members inside documented classes or files. If set to NO these +# members will be included in the various overviews, but no documentation +# section is generated. This option has no effect if EXTRACT_ALL is enabled. +# The default value is: NO. HIDE_UNDOC_MEMBERS = YES -# If the HIDE_UNDOC_CLASSES tag is set to YES, Doxygen will hide all -# undocumented classes that are normally visible in the class hierarchy. -# If set to NO (the default) these classes will be included in the various -# overviews. This option has no effect if EXTRACT_ALL is enabled. +# If the HIDE_UNDOC_CLASSES tag is set to YES, doxygen will hide all +# undocumented classes that are normally visible in the class hierarchy. If set +# to NO these classes will be included in the various overviews. This option has +# no effect if EXTRACT_ALL is enabled. +# The default value is: NO. HIDE_UNDOC_CLASSES = YES -# If the HIDE_FRIEND_COMPOUNDS tag is set to YES, Doxygen will hide all -# friend (class|struct|union) declarations. -# If set to NO (the default) these declarations will be included in the -# documentation. +# If the HIDE_FRIEND_COMPOUNDS tag is set to YES, doxygen will hide all friend +# (class|struct|union) declarations. If set to NO these declarations will be +# included in the documentation. +# The default value is: NO. HIDE_FRIEND_COMPOUNDS = NO -# If the HIDE_IN_BODY_DOCS tag is set to YES, Doxygen will hide any -# documentation blocks found inside the body of a function. -# If set to NO (the default) these blocks will be appended to the -# function's detailed documentation block. +# If the HIDE_IN_BODY_DOCS tag is set to YES, doxygen will hide any +# documentation blocks found inside the body of a function. If set to NO these +# blocks will be appended to the function's detailed documentation block. +# The default value is: NO. HIDE_IN_BODY_DOCS = NO -# The INTERNAL_DOCS tag determines if documentation -# that is typed after a \internal command is included. If the tag is set -# to NO (the default) then the documentation will be excluded. -# Set it to YES to include the internal documentation. +# The INTERNAL_DOCS tag determines if documentation that is typed after a +# \internal command is included. If the tag is set to NO then the documentation +# will be excluded. Set it to YES to include the internal documentation. +# The default value is: NO. INTERNAL_DOCS = NO -# If the CASE_SENSE_NAMES tag is set to NO then Doxygen will only generate -# file names in lower-case letters. If set to YES upper-case letters are also +# If the CASE_SENSE_NAMES tag is set to NO then doxygen will only generate file +# names in lower-case letters. If set to YES upper-case letters are also # allowed. This is useful if you have classes or files whose names only differ # in case and if your file system supports case sensitive file names. Windows # and Mac users are advised to set this option to NO. +# The default value is: system dependent. CASE_SENSE_NAMES = NO -# If the HIDE_SCOPE_NAMES tag is set to NO (the default) then Doxygen -# will show members with their full class and namespace scopes in the -# documentation. If set to YES the scope will be hidden. +# If the HIDE_SCOPE_NAMES tag is set to NO then doxygen will show members with +# their full class and namespace scopes in the documentation. If set to YES the +# scope will be hidden. +# The default value is: NO. HIDE_SCOPE_NAMES = NO -# If the SHOW_INCLUDE_FILES tag is set to YES (the default) then Doxygen -# will put a list of the files that are included by a file in the documentation -# of that file. +# If the SHOW_INCLUDE_FILES tag is set to YES then doxygen will put a list of +# the files that are included by a file in the documentation of that file. +# The default value is: YES. SHOW_INCLUDE_FILES = YES -# If the FORCE_LOCAL_INCLUDES tag is set to YES then Doxygen -# will list include files with double quotes in the documentation -# rather than with sharp brackets. +# If the SHOW_GROUPED_MEMB_INC tag is set to YES then Doxygen will add for each +# grouped member an include statement to the documentation, telling the reader +# which file to include in order to use the member. +# The default value is: NO. + +SHOW_GROUPED_MEMB_INC = NO + +# If the FORCE_LOCAL_INCLUDES tag is set to YES then doxygen will list include +# files with double quotes in the documentation rather than with sharp brackets. +# The default value is: NO. FORCE_LOCAL_INCLUDES = NO -# If the INLINE_INFO tag is set to YES (the default) then a tag [inline] -# is inserted in the documentation for inline members. +# If the INLINE_INFO tag is set to YES then a tag [inline] is inserted in the +# documentation for inline members. +# The default value is: YES. INLINE_INFO = YES -# If the SORT_MEMBER_DOCS tag is set to YES (the default) then doxygen -# will sort the (detailed) documentation of file and class members -# alphabetically by member name. If set to NO the members will appear in -# declaration order. +# If the SORT_MEMBER_DOCS tag is set to YES then doxygen will sort the +# (detailed) documentation of file and class members alphabetically by member +# name. If set to NO the members will appear in declaration order. +# The default value is: YES. SORT_MEMBER_DOCS = YES -# If the SORT_BRIEF_DOCS tag is set to YES then doxygen will sort the -# brief documentation of file, namespace and class members alphabetically -# by member name. If set to NO (the default) the members will appear in -# declaration order. +# If the SORT_BRIEF_DOCS tag is set to YES then doxygen will sort the brief +# descriptions of file, namespace and class members alphabetically by member +# name. If set to NO the members will appear in declaration order. Note that +# this will also influence the order of the classes in the class list. +# The default value is: NO. SORT_BRIEF_DOCS = NO -# If the SORT_MEMBERS_CTORS_1ST tag is set to YES then doxygen -# will sort the (brief and detailed) documentation of class members so that -# constructors and destructors are listed first. If set to NO (the default) -# the constructors will appear in the respective orders defined by -# SORT_MEMBER_DOCS and SORT_BRIEF_DOCS. -# This tag will be ignored for brief docs if SORT_BRIEF_DOCS is set to NO -# and ignored for detailed docs if SORT_MEMBER_DOCS is set to NO. +# If the SORT_MEMBERS_CTORS_1ST tag is set to YES then doxygen will sort the +# (brief and detailed) documentation of class members so that constructors and +# destructors are listed first. If set to NO the constructors will appear in the +# respective orders defined by SORT_BRIEF_DOCS and SORT_MEMBER_DOCS. +# Note: If SORT_BRIEF_DOCS is set to NO this option is ignored for sorting brief +# member documentation. +# Note: If SORT_MEMBER_DOCS is set to NO this option is ignored for sorting +# detailed member documentation. +# The default value is: NO. SORT_MEMBERS_CTORS_1ST = NO -# If the SORT_GROUP_NAMES tag is set to YES then doxygen will sort the -# hierarchy of group names into alphabetical order. If set to NO (the default) -# the group names will appear in their defined order. +# If the SORT_GROUP_NAMES tag is set to YES then doxygen will sort the hierarchy +# of group names into alphabetical order. If set to NO the group names will +# appear in their defined order. +# The default value is: NO. SORT_GROUP_NAMES = NO -# If the SORT_BY_SCOPE_NAME tag is set to YES, the class list will be -# sorted by fully-qualified names, including namespaces. If set to -# NO (the default), the class list will be sorted only by class name, -# not including the namespace part. +# If the SORT_BY_SCOPE_NAME tag is set to YES, the class list will be sorted by +# fully-qualified names, including namespaces. If set to NO, the class list will +# be sorted only by class name, not including the namespace part. # Note: This option is not very useful if HIDE_SCOPE_NAMES is set to YES. -# Note: This option applies only to the class list, not to the -# alphabetical list. +# Note: This option applies only to the class list, not to the alphabetical +# list. +# The default value is: NO. SORT_BY_SCOPE_NAME = NO -# If the STRICT_PROTO_MATCHING option is enabled and doxygen fails to -# do proper type resolution of all parameters of a function it will reject a -# match between the prototype and the implementation of a member function even -# if there is only one candidate or it is obvious which candidate to choose -# by doing a simple string match. By disabling STRICT_PROTO_MATCHING doxygen -# will still accept a match between prototype and implementation in such cases. +# If the STRICT_PROTO_MATCHING option is enabled and doxygen fails to do proper +# type resolution of all parameters of a function it will reject a match between +# the prototype and the implementation of a member function even if there is +# only one candidate or it is obvious which candidate to choose by doing a +# simple string match. By disabling STRICT_PROTO_MATCHING doxygen will still +# accept a match between prototype and implementation in such cases. +# The default value is: NO. STRICT_PROTO_MATCHING = NO -# The GENERATE_TODOLIST tag can be used to enable (YES) or -# disable (NO) the todo list. This list is created by putting \todo -# commands in the documentation. +# The GENERATE_TODOLIST tag can be used to enable ( YES) or disable ( NO) the +# todo list. This list is created by putting \todo commands in the +# documentation. +# The default value is: YES. GENERATE_TODOLIST = NO -# The GENERATE_TESTLIST tag can be used to enable (YES) or -# disable (NO) the test list. This list is created by putting \test -# commands in the documentation. +# The GENERATE_TESTLIST tag can be used to enable ( YES) or disable ( NO) the +# test list. This list is created by putting \test commands in the +# documentation. +# The default value is: YES. GENERATE_TESTLIST = YES -# The GENERATE_BUGLIST tag can be used to enable (YES) or -# disable (NO) the bug list. This list is created by putting \bug -# commands in the documentation. +# The GENERATE_BUGLIST tag can be used to enable ( YES) or disable ( NO) the bug +# list. This list is created by putting \bug commands in the documentation. +# The default value is: YES. GENERATE_BUGLIST = YES -# The GENERATE_DEPRECATEDLIST tag can be used to enable (YES) or -# disable (NO) the deprecated list. This list is created by putting -# \deprecated commands in the documentation. +# The GENERATE_DEPRECATEDLIST tag can be used to enable ( YES) or disable ( NO) +# the deprecated list. This list is created by putting \deprecated commands in +# the documentation. +# The default value is: YES. GENERATE_DEPRECATEDLIST= YES -# The ENABLED_SECTIONS tag can be used to enable conditional -# documentation sections, marked by \if sectionname ... \endif. +# The ENABLED_SECTIONS tag can be used to enable conditional documentation +# sections, marked by \if ... \endif and \cond +# ... \endcond blocks. ENABLED_SECTIONS = -# The MAX_INITIALIZER_LINES tag determines the maximum number of lines -# the initial value of a variable or macro consists of for it to appear in -# the documentation. If the initializer consists of more lines than specified -# here it will be hidden. Use a value of 0 to hide initializers completely. -# The appearance of the initializer of individual variables and macros in the -# documentation can be controlled using \showinitializer or \hideinitializer -# command in the documentation regardless of this setting. +# The MAX_INITIALIZER_LINES tag determines the maximum number of lines that the +# initial value of a variable or macro / define can have for it to appear in the +# documentation. If the initializer consists of more lines than specified here +# it will be hidden. Use a value of 0 to hide initializers completely. The +# appearance of the value of individual variables and macros / defines can be +# controlled using \showinitializer or \hideinitializer command in the +# documentation regardless of this setting. +# Minimum value: 0, maximum value: 10000, default value: 30. MAX_INITIALIZER_LINES = 30 -# Set the SHOW_USED_FILES tag to NO to disable the list of files generated -# at the bottom of the documentation of classes and structs. If set to YES the -# list will mention the files that were used to generate the documentation. +# Set the SHOW_USED_FILES tag to NO to disable the list of files generated at +# the bottom of the documentation of classes and structs. If set to YES the list +# will mention the files that were used to generate the documentation. +# The default value is: YES. SHOW_USED_FILES = NO -# Set the SHOW_FILES tag to NO to disable the generation of the Files page. -# This will remove the Files entry from the Quick Index and from the -# Folder Tree View (if specified). The default is YES. +# Set the SHOW_FILES tag to NO to disable the generation of the Files page. This +# will remove the Files entry from the Quick Index and from the Folder Tree View +# (if specified). +# The default value is: YES. SHOW_FILES = YES -# Set the SHOW_NAMESPACES tag to NO to disable the generation of the -# Namespaces page. -# This will remove the Namespaces entry from the Quick Index -# and from the Folder Tree View (if specified). The default is YES. +# Set the SHOW_NAMESPACES tag to NO to disable the generation of the Namespaces +# page. This will remove the Namespaces entry from the Quick Index and from the +# Folder Tree View (if specified). +# The default value is: YES. SHOW_NAMESPACES = NO # The FILE_VERSION_FILTER tag can be used to specify a program or script that # doxygen should invoke to get the current version for each file (typically from # the version control system). Doxygen will invoke the program by executing (via -# popen()) the command , where is the value of -# the FILE_VERSION_FILTER tag, and is the name of an input file -# provided by doxygen. Whatever the program writes to standard output -# is used as the file version. See the manual for examples. +# popen()) the command command input-file, where command is the value of the +# FILE_VERSION_FILTER tag, and input-file is the name of an input file provided +# by doxygen. Whatever the program writes to standard output is used as the file +# version. For an example see the documentation. FILE_VERSION_FILTER = # The LAYOUT_FILE tag can be used to specify a layout file which will be parsed # by doxygen. The layout file controls the global structure of the generated # output files in an output format independent way. To create the layout file -# that represents doxygen's defaults, run doxygen with the -l option. -# You can optionally specify a file name after the option, if omitted -# DoxygenLayout.xml will be used as the name of the layout file. +# that represents doxygen's defaults, run doxygen with the -l option. You can +# optionally specify a file name after the option, if omitted DoxygenLayout.xml +# will be used as the name of the layout file. +# +# Note that if you run doxygen from a directory containing a file called +# DoxygenLayout.xml, doxygen will parse it automatically even if the LAYOUT_FILE +# tag is left empty. LAYOUT_FILE = -# The CITE_BIB_FILES tag can be used to specify one or more bib files -# containing the references data. This must be a list of .bib files. The -# .bib extension is automatically appended if omitted. Using this command -# requires the bibtex tool to be installed. See also -# http://en.wikipedia.org/wiki/BibTeX for more info. For LaTeX the style -# of the bibliography can be controlled using LATEX_BIB_STYLE. To use this -# feature you need bibtex and perl available in the search path. +# The CITE_BIB_FILES tag can be used to specify one or more bib files containing +# the reference definitions. This must be a list of .bib files. The .bib +# extension is automatically appended if omitted. This requires the bibtex tool +# to be installed. See also http://en.wikipedia.org/wiki/BibTeX for more info. +# For LaTeX the style of the bibliography can be controlled using +# LATEX_BIB_STYLE. To use this feature you need bibtex and perl available in the +# search path. See also \cite for info how to create references. CITE_BIB_FILES = #--------------------------------------------------------------------------- -# configuration options related to warning and progress messages +# Configuration options related to warning and progress messages #--------------------------------------------------------------------------- -# The QUIET tag can be used to turn on/off the messages that are generated -# by doxygen. Possible values are YES and NO. If left blank NO is used. +# The QUIET tag can be used to turn on/off the messages that are generated to +# standard output by doxygen. If QUIET is set to YES this implies that the +# messages are off. +# The default value is: NO. QUIET = NO # The WARNINGS tag can be used to turn on/off the warning messages that are -# generated by doxygen. Possible values are YES and NO. If left blank -# NO is used. +# generated to standard error ( stderr) by doxygen. If WARNINGS is set to YES +# this implies that the warnings are on. +# +# Tip: Turn warnings on while writing the documentation. +# The default value is: YES. WARNINGS = YES -# If WARN_IF_UNDOCUMENTED is set to YES, then doxygen will generate warnings -# for undocumented members. If EXTRACT_ALL is set to YES then this flag will -# automatically be disabled. +# If the WARN_IF_UNDOCUMENTED tag is set to YES, then doxygen will generate +# warnings for undocumented members. If EXTRACT_ALL is set to YES then this flag +# will automatically be disabled. +# The default value is: YES. WARN_IF_UNDOCUMENTED = YES -# If WARN_IF_DOC_ERROR is set to YES, doxygen will generate warnings for -# potential errors in the documentation, such as not documenting some -# parameters in a documented function, or documenting parameters that -# don't exist or using markup commands wrongly. +# If the WARN_IF_DOC_ERROR tag is set to YES, doxygen will generate warnings for +# potential errors in the documentation, such as not documenting some parameters +# in a documented function, or documenting parameters that don't exist or using +# markup commands wrongly. +# The default value is: YES. WARN_IF_DOC_ERROR = YES -# The WARN_NO_PARAMDOC option can be enabled to get warnings for -# functions that are documented, but have no documentation for their parameters -# or return value. If set to NO (the default) doxygen will only warn about -# wrong or incomplete parameter documentation, but not about the absence of -# documentation. +# This WARN_NO_PARAMDOC option can be enabled to get warnings for functions that +# are documented, but have no documentation for their parameters or return +# value. If set to NO doxygen will only warn about wrong or incomplete parameter +# documentation, but not about the absence of documentation. +# The default value is: NO. WARN_NO_PARAMDOC = NO -# The WARN_FORMAT tag determines the format of the warning messages that -# doxygen can produce. The string should contain the $file, $line, and $text -# tags, which will be replaced by the file and line number from which the -# warning originated and the warning text. Optionally the format may contain -# $version, which will be replaced by the version of the file (if it could -# be obtained via FILE_VERSION_FILTER) +# The WARN_FORMAT tag determines the format of the warning messages that doxygen +# can produce. The string should contain the $file, $line, and $text tags, which +# will be replaced by the file and line number from which the warning originated +# and the warning text. Optionally the format may contain $version, which will +# be replaced by the version of the file (if it could be obtained via +# FILE_VERSION_FILTER) +# The default value is: $file:$line: $text. WARN_FORMAT = "$file:$line: $text" -# The WARN_LOGFILE tag can be used to specify a file to which warning -# and error messages should be written. If left blank the output is written -# to stderr. +# The WARN_LOGFILE tag can be used to specify a file to which warning and error +# messages should be written. If left blank the output is written to standard +# error (stderr). WARN_LOGFILE = #--------------------------------------------------------------------------- -# configuration options related to the input files +# Configuration options related to the input files #--------------------------------------------------------------------------- -# The INPUT tag can be used to specify the files and/or directories that contain -# documented source files. You may enter file names like "myfile.cpp" or -# directories like "/usr/src/myproject". Separate the files or directories -# with spaces. +# The INPUT tag is used to specify the files and/or directories that contain +# documented source files. You may enter file names like myfile.cpp or +# directories like /usr/src/myproject. Separate the files or directories with +# spaces. +# Note: If this tag is empty the current directory is searched. INPUT = ../src \ ./ \ api.mainpage # This tag can be used to specify the character encoding of the source files -# that doxygen parses. Internally doxygen uses the UTF-8 encoding, which is -# also the default input encoding. Doxygen uses libiconv (or the iconv built -# into libc) for the transcoding. See http://www.gnu.org/software/libiconv for -# the list of possible encodings. +# that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses +# libiconv (or the iconv built into libc) for the transcoding. See the libiconv +# documentation (see: http://www.gnu.org/software/libiconv) for the list of +# possible encodings. +# The default value is: UTF-8. INPUT_ENCODING = UTF-8 # If the value of the INPUT tag contains directories, you can use the -# FILE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp -# and *.h) to filter out the source-files in the directories. If left -# blank the following patterns are tested: -# *.c *.cc *.cxx *.cpp *.c++ *.d *.java *.ii *.ixx *.ipp *.i++ *.inl *.h *.hh -# *.hxx *.hpp *.h++ *.idl *.odl *.cs *.php *.php3 *.inc *.m *.mm *.dox *.py -# *.f90 *.f *.for *.vhd *.vhdl +# FILE_PATTERNS tag to specify one or more wildcard patterns (like *.cpp and +# *.h) to filter out the source-files in the directories. If left blank the +# following patterns are tested:*.c, *.cc, *.cxx, *.cpp, *.c++, *.java, *.ii, +# *.ixx, *.ipp, *.i++, *.inl, *.idl, *.ddl, *.odl, *.h, *.hh, *.hxx, *.hpp, +# *.h++, *.cs, *.d, *.php, *.php4, *.php5, *.phtml, *.inc, *.m, *.markdown, +# *.md, *.mm, *.dox, *.py, *.f90, *.f, *.for, *.tcl, *.vhd, *.vhdl, *.ucf, +# *.qsf, *.as and *.js. FILE_PATTERNS = *.c \ *.cc \ @@ -737,15 +817,16 @@ FILE_PATTERNS = *.c \ *.vhd \ *.vhdl -# The RECURSIVE tag can be used to turn specify whether or not subdirectories -# should be searched for input files as well. Possible values are YES and NO. -# If left blank NO is used. +# The RECURSIVE tag can be used to specify whether or not subdirectories should +# be searched for input files as well. +# The default value is: NO. RECURSIVE = YES # The EXCLUDE tag can be used to specify files and/or directories that should be # excluded from the INPUT source files. This way you can easily exclude a # subdirectory from a directory tree whose root is specified with the INPUT tag. +# # Note that relative paths are relative to the directory from which doxygen is # run. @@ -754,14 +835,16 @@ EXCLUDE = # The EXCLUDE_SYMLINKS tag can be used to select whether or not files or # directories that are symbolic links (a Unix file system feature) are excluded # from the input. +# The default value is: NO. EXCLUDE_SYMLINKS = NO # If the value of the INPUT tag contains directories, you can use the # EXCLUDE_PATTERNS tag to specify one or more wildcard patterns to exclude -# certain files from those directories. Note that the wildcards are matched -# against the file with absolute path, so to exclude all test directories -# for example use the pattern */test/* +# certain files from those directories. +# +# Note that the wildcards are matched against the file with absolute path, so to +# exclude all test directories for example use the pattern */test/* EXCLUDE_PATTERNS = */moc_*.cc @@ -770,755 +853,1108 @@ EXCLUDE_PATTERNS = */moc_*.cc # output. The symbol name can be a fully qualified name, a word, or if the # wildcard * is used, a substring. Examples: ANamespace, AClass, # AClass::ANamespace, ANamespace::*Test +# +# Note that the wildcards are matched against the file with absolute path, so to +# exclude all test directories use the pattern */test/* EXCLUDE_SYMBOLS = -# The EXAMPLE_PATH tag can be used to specify one or more files or -# directories that contain example code fragments that are included (see -# the \include command). +# The EXAMPLE_PATH tag can be used to specify one or more files or directories +# that contain example code fragments that are included (see the \include +# command). EXAMPLE_PATH = ../ # If the value of the EXAMPLE_PATH tag contains directories, you can use the -# EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp -# and *.h) to filter out the source-files in the directories. If left -# blank all files are included. +# EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp and +# *.h) to filter out the source-files in the directories. If left blank all +# files are included. EXAMPLE_PATTERNS = * # If the EXAMPLE_RECURSIVE tag is set to YES then subdirectories will be -# searched for input files to be used with the \include or \dontinclude -# commands irrespective of the value of the RECURSIVE tag. -# Possible values are YES and NO. If left blank NO is used. +# searched for input files to be used with the \include or \dontinclude commands +# irrespective of the value of the RECURSIVE tag. +# The default value is: NO. EXAMPLE_RECURSIVE = NO -# The IMAGE_PATH tag can be used to specify one or more files or -# directories that contain image that are included in the documentation (see -# the \image command). +# The IMAGE_PATH tag can be used to specify one or more files or directories +# that contain images that are to be included in the documentation (see the +# \image command). IMAGE_PATH = . # The INPUT_FILTER tag can be used to specify a program that doxygen should # invoke to filter for each input file. Doxygen will invoke the filter program -# by executing (via popen()) the command , where -# is the value of the INPUT_FILTER tag, and is the name of an -# input file. Doxygen will then use the output that the filter program writes -# to standard output. -# If FILTER_PATTERNS is specified, this tag will be -# ignored. +# by executing (via popen()) the command: +# +# +# +# where is the value of the INPUT_FILTER tag, and is the +# name of an input file. Doxygen will then use the output that the filter +# program writes to standard output. If FILTER_PATTERNS is specified, this tag +# will be ignored. +# +# Note that the filter must not add or remove lines; it is applied before the +# code is scanned, but not when the output code is generated. If lines are added +# or removed, the anchors will not be placed correctly. INPUT_FILTER = # The FILTER_PATTERNS tag can be used to specify filters on a per file pattern -# basis. -# Doxygen will compare the file name with each pattern and apply the -# filter if there is a match. -# The filters are a list of the form: -# pattern=filter (like *.cpp=my_cpp_filter). See INPUT_FILTER for further -# info on how filters are used. If FILTER_PATTERNS is empty or if -# non of the patterns match the file name, INPUT_FILTER is applied. +# basis. Doxygen will compare the file name with each pattern and apply the +# filter if there is a match. The filters are a list of the form: pattern=filter +# (like *.cpp=my_cpp_filter). See INPUT_FILTER for further information on how +# filters are used. If the FILTER_PATTERNS tag is empty or if none of the +# patterns match the file name, INPUT_FILTER is applied. FILTER_PATTERNS = # If the FILTER_SOURCE_FILES tag is set to YES, the input filter (if set using -# INPUT_FILTER) will be used to filter the input files when producing source -# files to browse (i.e. when SOURCE_BROWSER is set to YES). +# INPUT_FILTER ) will also be used to filter the input files that are used for +# producing the source files to browse (i.e. when SOURCE_BROWSER is set to YES). +# The default value is: NO. FILTER_SOURCE_FILES = NO # The FILTER_SOURCE_PATTERNS tag can be used to specify source filters per file -# pattern. A pattern will override the setting for FILTER_PATTERN (if any) -# and it is also possible to disable source filtering for a specific pattern -# using *.ext= (so without naming a filter). This option only has effect when -# FILTER_SOURCE_FILES is enabled. +# pattern. A pattern will override the setting for FILTER_PATTERN (if any) and +# it is also possible to disable source filtering for a specific pattern using +# *.ext= (so without naming a filter). +# This tag requires that the tag FILTER_SOURCE_FILES is set to YES. FILTER_SOURCE_PATTERNS = +# If the USE_MDFILE_AS_MAINPAGE tag refers to the name of a markdown file that +# is part of the input, its contents will be placed on the main page +# (index.html). This can be useful if you have a project on for instance GitHub +# and want to reuse the introduction page also for the doxygen output. + +USE_MDFILE_AS_MAINPAGE = + #--------------------------------------------------------------------------- -# configuration options related to source browsing +# Configuration options related to source browsing #--------------------------------------------------------------------------- -# If the SOURCE_BROWSER tag is set to YES then a list of source files will -# be generated. Documented entities will be cross-referenced with these sources. -# Note: To get rid of all source code in the generated output, make sure also -# VERBATIM_HEADERS is set to NO. +# If the SOURCE_BROWSER tag is set to YES then a list of source files will be +# generated. Documented entities will be cross-referenced with these sources. +# +# Note: To get rid of all source code in the generated output, make sure that +# also VERBATIM_HEADERS is set to NO. +# The default value is: NO. SOURCE_BROWSER = NO -# Setting the INLINE_SOURCES tag to YES will include the body -# of functions and classes directly in the documentation. +# Setting the INLINE_SOURCES tag to YES will include the body of functions, +# classes and enums directly into the documentation. +# The default value is: NO. INLINE_SOURCES = NO -# Setting the STRIP_CODE_COMMENTS tag to YES (the default) will instruct -# doxygen to hide any special comment blocks from generated source code -# fragments. Normal C, C++ and Fortran comments will always remain visible. +# Setting the STRIP_CODE_COMMENTS tag to YES will instruct doxygen to hide any +# special comment blocks from generated source code fragments. Normal C, C++ and +# Fortran comments will always remain visible. +# The default value is: YES. STRIP_CODE_COMMENTS = NO -# If the REFERENCED_BY_RELATION tag is set to YES -# then for each documented function all documented -# functions referencing it will be listed. +# If the REFERENCED_BY_RELATION tag is set to YES then for each documented +# function all documented functions referencing it will be listed. +# The default value is: NO. REFERENCED_BY_RELATION = NO -# If the REFERENCES_RELATION tag is set to YES -# then for each documented function all documented entities -# called/used by that function will be listed. +# If the REFERENCES_RELATION tag is set to YES then for each documented function +# all documented entities called/used by that function will be listed. +# The default value is: NO. REFERENCES_RELATION = NO -# If the REFERENCES_LINK_SOURCE tag is set to YES (the default) -# and SOURCE_BROWSER tag is set to YES, then the hyperlinks from -# functions in REFERENCES_RELATION and REFERENCED_BY_RELATION lists will -# link to the source code. -# Otherwise they will link to the documentation. +# If the REFERENCES_LINK_SOURCE tag is set to YES and SOURCE_BROWSER tag is set +# to YES, then the hyperlinks from functions in REFERENCES_RELATION and +# REFERENCED_BY_RELATION lists will link to the source code. Otherwise they will +# link to the documentation. +# The default value is: YES. REFERENCES_LINK_SOURCE = NO -# If the USE_HTAGS tag is set to YES then the references to source code -# will point to the HTML generated by the htags(1) tool instead of doxygen -# built-in source browser. The htags tool is part of GNU's global source -# tagging system (see http://www.gnu.org/software/global/global.html). You -# will need version 4.8.6 or higher. +# If SOURCE_TOOLTIPS is enabled (the default) then hovering a hyperlink in the +# source code will show a tooltip with additional information such as prototype, +# brief description and links to the definition and documentation. Since this +# will make the HTML file larger and loading of large files a bit slower, you +# can opt to disable this feature. +# The default value is: YES. +# This tag requires that the tag SOURCE_BROWSER is set to YES. + +SOURCE_TOOLTIPS = YES + +# If the USE_HTAGS tag is set to YES then the references to source code will +# point to the HTML generated by the htags(1) tool instead of doxygen built-in +# source browser. The htags tool is part of GNU's global source tagging system +# (see http://www.gnu.org/software/global/global.html). You will need version +# 4.8.6 or higher. +# +# To use it do the following: +# - Install the latest version of global +# - Enable SOURCE_BROWSER and USE_HTAGS in the config file +# - Make sure the INPUT points to the root of the source tree +# - Run doxygen as normal +# +# Doxygen will invoke htags (and that will in turn invoke gtags), so these +# tools must be available from the command line (i.e. in the search path). +# +# The result: instead of the source browser generated by doxygen, the links to +# source code will now point to the output of htags. +# The default value is: NO. +# This tag requires that the tag SOURCE_BROWSER is set to YES. USE_HTAGS = NO -# If the VERBATIM_HEADERS tag is set to YES (the default) then Doxygen -# will generate a verbatim copy of the header file for each class for -# which an include is specified. Set to NO to disable this. +# If the VERBATIM_HEADERS tag is set the YES then doxygen will generate a +# verbatim copy of the header file for each class for which an include is +# specified. Set to NO to disable this. +# See also: Section \class. +# The default value is: YES. VERBATIM_HEADERS = NO +# If the CLANG_ASSISTED_PARSING tag is set to YES, then doxygen will use the +# clang parser (see: http://clang.llvm.org/) for more accurate parsing at the +# cost of reduced performance. This can be particularly helpful with template +# rich C++ code for which doxygen's built-in parser lacks the necessary type +# information. +# Note: The availability of this option depends on whether or not doxygen was +# compiled with the --with-libclang option. +# The default value is: NO. + +CLANG_ASSISTED_PARSING = NO + +# If clang assisted parsing is enabled you can provide the compiler with command +# line options that you would normally use when invoking the compiler. Note that +# the include paths will already be set by doxygen for the files and directories +# specified with INPUT and INCLUDE_PATH. +# This tag requires that the tag CLANG_ASSISTED_PARSING is set to YES. + +CLANG_OPTIONS = + #--------------------------------------------------------------------------- -# configuration options related to the alphabetical class index +# Configuration options related to the alphabetical class index #--------------------------------------------------------------------------- -# If the ALPHABETICAL_INDEX tag is set to YES, an alphabetical index -# of all compounds will be generated. Enable this if the project -# contains a lot of classes, structs, unions or interfaces. +# If the ALPHABETICAL_INDEX tag is set to YES, an alphabetical index of all +# compounds will be generated. Enable this if the project contains a lot of +# classes, structs, unions or interfaces. +# The default value is: YES. ALPHABETICAL_INDEX = YES -# If the alphabetical index is enabled (see ALPHABETICAL_INDEX) then -# the COLS_IN_ALPHA_INDEX tag can be used to specify the number of columns -# in which this list will be split (can be a number in the range [1..20]) +# The COLS_IN_ALPHA_INDEX tag can be used to specify the number of columns in +# which the alphabetical index list will be split. +# Minimum value: 1, maximum value: 20, default value: 5. +# This tag requires that the tag ALPHABETICAL_INDEX is set to YES. COLS_IN_ALPHA_INDEX = 2 -# In case all classes in a project start with a common prefix, all -# classes will be put under the same header in the alphabetical index. -# The IGNORE_PREFIX tag can be used to specify one or more prefixes that -# should be ignored while generating the index headers. +# In case all classes in a project start with a common prefix, all classes will +# be put under the same header in the alphabetical index. The IGNORE_PREFIX tag +# can be used to specify a prefix (or a list of prefixes) that should be ignored +# while generating the index headers. +# This tag requires that the tag ALPHABETICAL_INDEX is set to YES. IGNORE_PREFIX = #--------------------------------------------------------------------------- -# configuration options related to the HTML output +# Configuration options related to the HTML output #--------------------------------------------------------------------------- -# If the GENERATE_HTML tag is set to YES (the default) Doxygen will -# generate HTML output. +# If the GENERATE_HTML tag is set to YES doxygen will generate HTML output +# The default value is: YES. GENERATE_HTML = YES -# The HTML_OUTPUT tag is used to specify where the HTML docs will be put. -# If a relative path is entered the value of OUTPUT_DIRECTORY will be -# put in front of it. If left blank `html' will be used as the default path. +# The HTML_OUTPUT tag is used to specify where the HTML docs will be put. If a +# relative path is entered the value of OUTPUT_DIRECTORY will be put in front of +# it. +# The default directory is: html. +# This tag requires that the tag GENERATE_HTML is set to YES. HTML_OUTPUT = html -# The HTML_FILE_EXTENSION tag can be used to specify the file extension for -# each generated HTML page (for example: .htm,.php,.asp). If it is left blank -# doxygen will generate files with .html extension. +# The HTML_FILE_EXTENSION tag can be used to specify the file extension for each +# generated HTML page (for example: .htm, .php, .asp). +# The default value is: .html. +# This tag requires that the tag GENERATE_HTML is set to YES. HTML_FILE_EXTENSION = .html -# The HTML_HEADER tag can be used to specify a personal HTML header for -# each generated HTML page. If it is left blank doxygen will generate a -# standard header. Note that when using a custom header you are responsible -# for the proper inclusion of any scripts and style sheets that doxygen -# needs, which is dependent on the configuration options used. -# It is advised to generate a default header using "doxygen -w html -# header.html footer.html stylesheet.css YourConfigFile" and then modify -# that header. Note that the header is subject to change so you typically -# have to redo this when upgrading to a newer version of doxygen or when -# changing the value of configuration settings such as GENERATE_TREEVIEW! +# The HTML_HEADER tag can be used to specify a user-defined HTML header file for +# each generated HTML page. If the tag is left blank doxygen will generate a +# standard header. +# +# To get valid HTML the header file that includes any scripts and style sheets +# that doxygen needs, which is dependent on the configuration options used (e.g. +# the setting GENERATE_TREEVIEW). It is highly recommended to start with a +# default header using +# doxygen -w html new_header.html new_footer.html new_stylesheet.css +# YourConfigFile +# and then modify the file new_header.html. See also section "Doxygen usage" +# for information on how to generate the default header that doxygen normally +# uses. +# Note: The header is subject to change so you typically have to regenerate the +# default header when upgrading to a newer version of doxygen. For a description +# of the possible markers and block names see the documentation. +# This tag requires that the tag GENERATE_HTML is set to YES. HTML_HEADER = -# The HTML_FOOTER tag can be used to specify a personal HTML footer for -# each generated HTML page. If it is left blank doxygen will generate a -# standard footer. +# The HTML_FOOTER tag can be used to specify a user-defined HTML footer for each +# generated HTML page. If the tag is left blank doxygen will generate a standard +# footer. See HTML_HEADER for more information on how to generate a default +# footer and what special commands can be used inside the footer. See also +# section "Doxygen usage" for information on how to generate the default footer +# that doxygen normally uses. +# This tag requires that the tag GENERATE_HTML is set to YES. HTML_FOOTER = -# The HTML_STYLESHEET tag can be used to specify a user-defined cascading -# style sheet that is used by each HTML page. It can be used to -# fine-tune the look of the HTML output. If the tag is left blank doxygen -# will generate a default style sheet. Note that doxygen will try to copy -# the style sheet file to the HTML output directory, so don't put your own -# style sheet in the HTML output directory as well, or it will be erased! +# The HTML_STYLESHEET tag can be used to specify a user-defined cascading style +# sheet that is used by each HTML page. It can be used to fine-tune the look of +# the HTML output. If left blank doxygen will generate a default style sheet. +# See also section "Doxygen usage" for information on how to generate the style +# sheet that doxygen normally uses. +# Note: It is recommended to use HTML_EXTRA_STYLESHEET instead of this tag, as +# it is more robust and this tag (HTML_STYLESHEET) will in the future become +# obsolete. +# This tag requires that the tag GENERATE_HTML is set to YES. HTML_STYLESHEET = +# The HTML_EXTRA_STYLESHEET tag can be used to specify additional user-defined +# cascading style sheets that are included after the standard style sheets +# created by doxygen. Using this option one can overrule certain style aspects. +# This is preferred over using HTML_STYLESHEET since it does not replace the +# standard style sheet and is therefor more robust against future updates. +# Doxygen will copy the style sheet files to the output directory. +# Note: The order of the extra stylesheet files is of importance (e.g. the last +# stylesheet in the list overrules the setting of the previous ones in the +# list). For an example see the documentation. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_EXTRA_STYLESHEET = + # The HTML_EXTRA_FILES tag can be used to specify one or more extra images or # other source files which should be copied to the HTML output directory. Note # that these files will be copied to the base HTML output directory. Use the -# $relpath$ marker in the HTML_HEADER and/or HTML_FOOTER files to load these -# files. In the HTML_STYLESHEET file, use the file name only. Also note that -# the files will be copied as-is; there are no commands or markers available. +# $relpath^ marker in the HTML_HEADER and/or HTML_FOOTER files to load these +# files. In the HTML_STYLESHEET file, use the file name only. Also note that the +# files will be copied as-is; there are no commands or markers available. +# This tag requires that the tag GENERATE_HTML is set to YES. HTML_EXTRA_FILES = -# The HTML_COLORSTYLE_HUE tag controls the color of the HTML output. -# Doxygen will adjust the colors in the style sheet and background images -# according to this color. Hue is specified as an angle on a colorwheel, -# see http://en.wikipedia.org/wiki/Hue for more information. -# For instance the value 0 represents red, 60 is yellow, 120 is green, -# 180 is cyan, 240 is blue, 300 purple, and 360 is red again. -# The allowed range is 0 to 359. +# The HTML_COLORSTYLE_HUE tag controls the color of the HTML output. Doxygen +# will adjust the colors in the stylesheet and background images according to +# this color. Hue is specified as an angle on a colorwheel, see +# http://en.wikipedia.org/wiki/Hue for more information. For instance the value +# 0 represents red, 60 is yellow, 120 is green, 180 is cyan, 240 is blue, 300 +# purple, and 360 is red again. +# Minimum value: 0, maximum value: 359, default value: 220. +# This tag requires that the tag GENERATE_HTML is set to YES. HTML_COLORSTYLE_HUE = 17 -# The HTML_COLORSTYLE_SAT tag controls the purity (or saturation) of -# the colors in the HTML output. For a value of 0 the output will use -# grayscales only. A value of 255 will produce the most vivid colors. +# The HTML_COLORSTYLE_SAT tag controls the purity (or saturation) of the colors +# in the HTML output. For a value of 0 the output will use grayscales only. A +# value of 255 will produce the most vivid colors. +# Minimum value: 0, maximum value: 255, default value: 100. +# This tag requires that the tag GENERATE_HTML is set to YES. HTML_COLORSTYLE_SAT = 0 -# The HTML_COLORSTYLE_GAMMA tag controls the gamma correction applied to -# the luminance component of the colors in the HTML output. Values below -# 100 gradually make the output lighter, whereas values above 100 make -# the output darker. The value divided by 100 is the actual gamma applied, -# so 80 represents a gamma of 0.8, The value 220 represents a gamma of 2.2, -# and 100 does not change the gamma. +# The HTML_COLORSTYLE_GAMMA tag controls the gamma correction applied to the +# luminance component of the colors in the HTML output. Values below 100 +# gradually make the output lighter, whereas values above 100 make the output +# darker. The value divided by 100 is the actual gamma applied, so 80 represents +# a gamma of 0.8, The value 220 represents a gamma of 2.2, and 100 does not +# change the gamma. +# Minimum value: 40, maximum value: 240, default value: 80. +# This tag requires that the tag GENERATE_HTML is set to YES. HTML_COLORSTYLE_GAMMA = 120 # If the HTML_TIMESTAMP tag is set to YES then the footer of each generated HTML -# page will contain the date and time when the page was generated. Setting -# this to NO can help when comparing the output of multiple runs. +# page will contain the date and time when the page was generated. Setting this +# to NO can help when comparing the output of multiple runs. +# The default value is: YES. +# This tag requires that the tag GENERATE_HTML is set to YES. HTML_TIMESTAMP = NO # If the HTML_DYNAMIC_SECTIONS tag is set to YES then the generated HTML # documentation will contain sections that can be hidden and shown after the # page has loaded. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. HTML_DYNAMIC_SECTIONS = NO -# With HTML_INDEX_NUM_ENTRIES one can control the preferred number of -# entries shown in the various tree structured indices initially; the user -# can expand and collapse entries dynamically later on. Doxygen will expand -# the tree to such a level that at most the specified number of entries are -# visible (unless a fully collapsed tree already exceeds this amount). -# So setting the number of entries 1 will produce a full collapsed tree by -# default. 0 is a special value representing an infinite number of entries -# and will result in a full expanded tree by default. +# With HTML_INDEX_NUM_ENTRIES one can control the preferred number of entries +# shown in the various tree structured indices initially; the user can expand +# and collapse entries dynamically later on. Doxygen will expand the tree to +# such a level that at most the specified number of entries are visible (unless +# a fully collapsed tree already exceeds this amount). So setting the number of +# entries 1 will produce a full collapsed tree by default. 0 is a special value +# representing an infinite number of entries and will result in a full expanded +# tree by default. +# Minimum value: 0, maximum value: 9999, default value: 100. +# This tag requires that the tag GENERATE_HTML is set to YES. HTML_INDEX_NUM_ENTRIES = 100 -# If the GENERATE_DOCSET tag is set to YES, additional index files -# will be generated that can be used as input for Apple's Xcode 3 -# integrated development environment, introduced with OSX 10.5 (Leopard). -# To create a documentation set, doxygen will generate a Makefile in the -# HTML output directory. Running make will produce the docset in that -# directory and running "make install" will install the docset in -# ~/Library/Developer/Shared/Documentation/DocSets so that Xcode will find -# it at startup. -# See http://developer.apple.com/tools/creatingdocsetswithdoxygen.html +# If the GENERATE_DOCSET tag is set to YES, additional index files will be +# generated that can be used as input for Apple's Xcode 3 integrated development +# environment (see: http://developer.apple.com/tools/xcode/), introduced with +# OSX 10.5 (Leopard). To create a documentation set, doxygen will generate a +# Makefile in the HTML output directory. Running make will produce the docset in +# that directory and running make install will install the docset in +# ~/Library/Developer/Shared/Documentation/DocSets so that Xcode will find it at +# startup. See http://developer.apple.com/tools/creatingdocsetswithdoxygen.html # for more information. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. GENERATE_DOCSET = NO -# When GENERATE_DOCSET tag is set to YES, this tag determines the name of the -# feed. A documentation feed provides an umbrella under which multiple -# documentation sets from a single provider (such as a company or product suite) -# can be grouped. +# This tag determines the name of the docset feed. A documentation feed provides +# an umbrella under which multiple documentation sets from a single provider +# (such as a company or product suite) can be grouped. +# The default value is: Doxygen generated docs. +# This tag requires that the tag GENERATE_DOCSET is set to YES. DOCSET_FEEDNAME = "Doxygen generated docs" -# When GENERATE_DOCSET tag is set to YES, this tag specifies a string that -# should uniquely identify the documentation set bundle. This should be a -# reverse domain-name style string, e.g. com.mycompany.MyDocSet. Doxygen -# will append .docset to the name. +# This tag specifies a string that should uniquely identify the documentation +# set bundle. This should be a reverse domain-name style string, e.g. +# com.mycompany.MyDocSet. Doxygen will append .docset to the name. +# The default value is: org.doxygen.Project. +# This tag requires that the tag GENERATE_DOCSET is set to YES. DOCSET_BUNDLE_ID = org.doxygen.Project -# When GENERATE_PUBLISHER_ID tag specifies a string that should uniquely identify +# The DOCSET_PUBLISHER_ID tag specifies a string that should uniquely identify # the documentation publisher. This should be a reverse domain-name style # string, e.g. com.mycompany.MyDocSet.documentation. +# The default value is: org.doxygen.Publisher. +# This tag requires that the tag GENERATE_DOCSET is set to YES. DOCSET_PUBLISHER_ID = org.doxygen.Publisher -# The GENERATE_PUBLISHER_NAME tag identifies the documentation publisher. +# The DOCSET_PUBLISHER_NAME tag identifies the documentation publisher. +# The default value is: Publisher. +# This tag requires that the tag GENERATE_DOCSET is set to YES. DOCSET_PUBLISHER_NAME = Publisher -# If the GENERATE_HTMLHELP tag is set to YES, additional index files -# will be generated that can be used as input for tools like the -# Microsoft HTML help workshop to generate a compiled HTML help file (.chm) -# of the generated HTML documentation. +# If the GENERATE_HTMLHELP tag is set to YES then doxygen generates three +# additional HTML index files: index.hhp, index.hhc, and index.hhk. The +# index.hhp is a project file that can be read by Microsoft's HTML Help Workshop +# (see: http://www.microsoft.com/en-us/download/details.aspx?id=21138) on +# Windows. +# +# The HTML Help Workshop contains a compiler that can convert all HTML output +# generated by doxygen into a single compiled HTML file (.chm). Compiled HTML +# files are now used as the Windows 98 help format, and will replace the old +# Windows help format (.hlp) on all Windows platforms in the future. Compressed +# HTML files also contain an index, a table of contents, and you can search for +# words in the documentation. The HTML workshop also contains a viewer for +# compressed HTML files. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. GENERATE_HTMLHELP = NO -# If the GENERATE_HTMLHELP tag is set to YES, the CHM_FILE tag can -# be used to specify the file name of the resulting .chm file. You -# can add a path in front of the file if the result should not be +# The CHM_FILE tag can be used to specify the file name of the resulting .chm +# file. You can add a path in front of the file if the result should not be # written to the html output directory. +# This tag requires that the tag GENERATE_HTMLHELP is set to YES. CHM_FILE = -# If the GENERATE_HTMLHELP tag is set to YES, the HHC_LOCATION tag can -# be used to specify the location (absolute path including file name) of -# the HTML help compiler (hhc.exe). If non-empty doxygen will try to run -# the HTML help compiler on the generated index.hhp. +# The HHC_LOCATION tag can be used to specify the location (absolute path +# including file name) of the HTML help compiler ( hhc.exe). If non-empty +# doxygen will try to run the HTML help compiler on the generated index.hhp. +# The file has to be specified with full path. +# This tag requires that the tag GENERATE_HTMLHELP is set to YES. HHC_LOCATION = -# If the GENERATE_HTMLHELP tag is set to YES, the GENERATE_CHI flag -# controls if a separate .chi index file is generated (YES) or that -# it should be included in the master .chm file (NO). +# The GENERATE_CHI flag controls if a separate .chi index file is generated ( +# YES) or that it should be included in the master .chm file ( NO). +# The default value is: NO. +# This tag requires that the tag GENERATE_HTMLHELP is set to YES. GENERATE_CHI = NO -# If the GENERATE_HTMLHELP tag is set to YES, the CHM_INDEX_ENCODING -# is used to encode HtmlHelp index (hhk), content (hhc) and project file -# content. +# The CHM_INDEX_ENCODING is used to encode HtmlHelp index ( hhk), content ( hhc) +# and project file content. +# This tag requires that the tag GENERATE_HTMLHELP is set to YES. CHM_INDEX_ENCODING = -# If the GENERATE_HTMLHELP tag is set to YES, the BINARY_TOC flag -# controls whether a binary table of contents is generated (YES) or a -# normal table of contents (NO) in the .chm file. +# The BINARY_TOC flag controls whether a binary table of contents is generated ( +# YES) or a normal table of contents ( NO) in the .chm file. Furthermore it +# enables the Previous and Next buttons. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTMLHELP is set to YES. BINARY_TOC = NO -# The TOC_EXPAND flag can be set to YES to add extra items for group members -# to the contents of the HTML help documentation and to the tree view. +# The TOC_EXPAND flag can be set to YES to add extra items for group members to +# the table of contents of the HTML help documentation and to the tree view. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTMLHELP is set to YES. TOC_EXPAND = NO # If the GENERATE_QHP tag is set to YES and both QHP_NAMESPACE and -# QHP_VIRTUAL_FOLDER are set, an additional index file will be generated -# that can be used as input for Qt's qhelpgenerator to generate a -# Qt Compressed Help (.qch) of the generated HTML documentation. +# QHP_VIRTUAL_FOLDER are set, an additional index file will be generated that +# can be used as input for Qt's qhelpgenerator to generate a Qt Compressed Help +# (.qch) of the generated HTML documentation. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. GENERATE_QHP = NO -# If the QHG_LOCATION tag is specified, the QCH_FILE tag can -# be used to specify the file name of the resulting .qch file. -# The path specified is relative to the HTML output folder. +# If the QHG_LOCATION tag is specified, the QCH_FILE tag can be used to specify +# the file name of the resulting .qch file. The path specified is relative to +# the HTML output folder. +# This tag requires that the tag GENERATE_QHP is set to YES. QCH_FILE = -# The QHP_NAMESPACE tag specifies the namespace to use when generating -# Qt Help Project output. For more information please see -# http://doc.trolltech.com/qthelpproject.html#namespace +# The QHP_NAMESPACE tag specifies the namespace to use when generating Qt Help +# Project output. For more information please see Qt Help Project / Namespace +# (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#namespace). +# The default value is: org.doxygen.Project. +# This tag requires that the tag GENERATE_QHP is set to YES. QHP_NAMESPACE = org.doxygen.Project -# The QHP_VIRTUAL_FOLDER tag specifies the namespace to use when generating -# Qt Help Project output. For more information please see -# http://doc.trolltech.com/qthelpproject.html#virtual-folders +# The QHP_VIRTUAL_FOLDER tag specifies the namespace to use when generating Qt +# Help Project output. For more information please see Qt Help Project / Virtual +# Folders (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#virtual- +# folders). +# The default value is: doc. +# This tag requires that the tag GENERATE_QHP is set to YES. QHP_VIRTUAL_FOLDER = doc -# If QHP_CUST_FILTER_NAME is set, it specifies the name of a custom filter to -# add. For more information please see -# http://doc.trolltech.com/qthelpproject.html#custom-filters +# If the QHP_CUST_FILTER_NAME tag is set, it specifies the name of a custom +# filter to add. For more information please see Qt Help Project / Custom +# Filters (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#custom- +# filters). +# This tag requires that the tag GENERATE_QHP is set to YES. QHP_CUST_FILTER_NAME = -# The QHP_CUST_FILT_ATTRS tag specifies the list of the attributes of the -# custom filter to add. For more information please see -# -# Qt Help Project / Custom Filters. +# The QHP_CUST_FILTER_ATTRS tag specifies the list of the attributes of the +# custom filter to add. For more information please see Qt Help Project / Custom +# Filters (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#custom- +# filters). +# This tag requires that the tag GENERATE_QHP is set to YES. QHP_CUST_FILTER_ATTRS = # The QHP_SECT_FILTER_ATTRS tag specifies the list of the attributes this -# project's -# filter section matches. -# -# Qt Help Project / Filter Attributes. +# project's filter section matches. Qt Help Project / Filter Attributes (see: +# http://qt-project.org/doc/qt-4.8/qthelpproject.html#filter-attributes). +# This tag requires that the tag GENERATE_QHP is set to YES. QHP_SECT_FILTER_ATTRS = -# If the GENERATE_QHP tag is set to YES, the QHG_LOCATION tag can -# be used to specify the location of Qt's qhelpgenerator. -# If non-empty doxygen will try to run qhelpgenerator on the generated -# .qhp file. +# The QHG_LOCATION tag can be used to specify the location of Qt's +# qhelpgenerator. If non-empty doxygen will try to run qhelpgenerator on the +# generated .qhp file. +# This tag requires that the tag GENERATE_QHP is set to YES. QHG_LOCATION = -# If the GENERATE_ECLIPSEHELP tag is set to YES, additional index files -# will be generated, which together with the HTML files, form an Eclipse help -# plugin. To install this plugin and make it available under the help contents -# menu in Eclipse, the contents of the directory containing the HTML and XML -# files needs to be copied into the plugins directory of eclipse. The name of -# the directory within the plugins directory should be the same as -# the ECLIPSE_DOC_ID value. After copying Eclipse needs to be restarted before -# the help appears. +# If the GENERATE_ECLIPSEHELP tag is set to YES, additional index files will be +# generated, together with the HTML files, they form an Eclipse help plugin. To +# install this plugin and make it available under the help contents menu in +# Eclipse, the contents of the directory containing the HTML and XML files needs +# to be copied into the plugins directory of eclipse. The name of the directory +# within the plugins directory should be the same as the ECLIPSE_DOC_ID value. +# After copying Eclipse needs to be restarted before the help appears. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. GENERATE_ECLIPSEHELP = NO -# A unique identifier for the eclipse help plugin. When installing the plugin -# the directory name containing the HTML and XML files should also have -# this name. +# A unique identifier for the Eclipse help plugin. When installing the plugin +# the directory name containing the HTML and XML files should also have this +# name. Each documentation set should have its own identifier. +# The default value is: org.doxygen.Project. +# This tag requires that the tag GENERATE_ECLIPSEHELP is set to YES. ECLIPSE_DOC_ID = org.doxygen.Project -# The DISABLE_INDEX tag can be used to turn on/off the condensed index (tabs) -# at top of each HTML page. The value NO (the default) enables the index and -# the value YES disables it. Since the tabs have the same information as the -# navigation tree you can set this option to NO if you already set -# GENERATE_TREEVIEW to YES. +# If you want full control over the layout of the generated HTML pages it might +# be necessary to disable the index and replace it with your own. The +# DISABLE_INDEX tag can be used to turn on/off the condensed index (tabs) at top +# of each HTML page. A value of NO enables the index and the value YES disables +# it. Since the tabs in the index contain the same information as the navigation +# tree, you can set this option to YES if you also set GENERATE_TREEVIEW to YES. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. DISABLE_INDEX = YES # The GENERATE_TREEVIEW tag is used to specify whether a tree-like index -# structure should be generated to display hierarchical information. -# If the tag value is set to YES, a side panel will be generated -# containing a tree-like index structure (just like the one that -# is generated for HTML Help). For this to work a browser that supports -# JavaScript, DHTML, CSS and frames is required (i.e. any modern browser). -# Windows users are probably better off using the HTML help feature. -# Since the tree basically has the same information as the tab index you -# could consider to set DISABLE_INDEX to NO when enabling this option. +# structure should be generated to display hierarchical information. If the tag +# value is set to YES, a side panel will be generated containing a tree-like +# index structure (just like the one that is generated for HTML Help). For this +# to work a browser that supports JavaScript, DHTML, CSS and frames is required +# (i.e. any modern browser). Windows users are probably better off using the +# HTML help feature. Via custom stylesheets (see HTML_EXTRA_STYLESHEET) one can +# further fine-tune the look of the index. As an example, the default style +# sheet generated by doxygen has an example that shows how to put an image at +# the root of the tree instead of the PROJECT_NAME. Since the tree basically has +# the same information as the tab index, you could consider setting +# DISABLE_INDEX to YES when enabling this option. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. GENERATE_TREEVIEW = YES -# The ENUM_VALUES_PER_LINE tag can be used to set the number of enum values -# (range [0,1..20]) that doxygen will group on one line in the generated HTML -# documentation. Note that a value of 0 will completely suppress the enum -# values from appearing in the overview section. +# The ENUM_VALUES_PER_LINE tag can be used to set the number of enum values that +# doxygen will group on one line in the generated HTML documentation. +# +# Note that a value of 0 will completely suppress the enum values from appearing +# in the overview section. +# Minimum value: 0, maximum value: 20, default value: 4. +# This tag requires that the tag GENERATE_HTML is set to YES. ENUM_VALUES_PER_LINE = 4 -# If the treeview is enabled (see GENERATE_TREEVIEW) then this tag can be -# used to set the initial width (in pixels) of the frame in which the tree -# is shown. +# If the treeview is enabled (see GENERATE_TREEVIEW) then this tag can be used +# to set the initial width (in pixels) of the frame in which the tree is shown. +# Minimum value: 0, maximum value: 1500, default value: 250. +# This tag requires that the tag GENERATE_HTML is set to YES. TREEVIEW_WIDTH = 250 -# When the EXT_LINKS_IN_WINDOW option is set to YES doxygen will open -# links to external symbols imported via tag files in a separate window. +# When the EXT_LINKS_IN_WINDOW option is set to YES doxygen will open links to +# external symbols imported via tag files in a separate window. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. EXT_LINKS_IN_WINDOW = NO -# Use this tag to change the font size of Latex formulas included -# as images in the HTML documentation. The default is 10. Note that -# when you change the font size after a successful doxygen run you need -# to manually remove any form_*.png images from the HTML output directory -# to force them to be regenerated. +# Use this tag to change the font size of LaTeX formulas included as images in +# the HTML documentation. When you change the font size after a successful +# doxygen run you need to manually remove any form_*.png images from the HTML +# output directory to force them to be regenerated. +# Minimum value: 8, maximum value: 50, default value: 10. +# This tag requires that the tag GENERATE_HTML is set to YES. FORMULA_FONTSIZE = 10 # Use the FORMULA_TRANPARENT tag to determine whether or not the images -# generated for formulas are transparent PNGs. Transparent PNGs are -# not supported properly for IE 6.0, but are supported on all modern browsers. -# Note that when changing this option you need to delete any form_*.png files -# in the HTML output before the changes have effect. +# generated for formulas are transparent PNGs. Transparent PNGs are not +# supported properly for IE 6.0, but are supported on all modern browsers. +# +# Note that when changing this option you need to delete any form_*.png files in +# the HTML output directory before the changes have effect. +# The default value is: YES. +# This tag requires that the tag GENERATE_HTML is set to YES. FORMULA_TRANSPARENT = YES -# Enable the USE_MATHJAX option to render LaTeX formulas using MathJax -# (see http://www.mathjax.org) which uses client side Javascript for the -# rendering instead of using prerendered bitmaps. Use this if you do not -# have LaTeX installed or if you want to formulas look prettier in the HTML -# output. When enabled you may also need to install MathJax separately and -# configure the path to it using the MATHJAX_RELPATH option. +# Enable the USE_MATHJAX option to render LaTeX formulas using MathJax (see +# http://www.mathjax.org) which uses client side Javascript for the rendering +# instead of using prerendered bitmaps. Use this if you do not have LaTeX +# installed or if you want to formulas look prettier in the HTML output. When +# enabled you may also need to install MathJax separately and configure the path +# to it using the MATHJAX_RELPATH option. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. USE_MATHJAX = NO -# When MathJax is enabled you need to specify the location relative to the -# HTML output directory using the MATHJAX_RELPATH option. The destination -# directory should contain the MathJax.js script. For instance, if the mathjax -# directory is located at the same level as the HTML output directory, then -# MATHJAX_RELPATH should be ../mathjax. The default value points to -# the MathJax Content Delivery Network so you can quickly see the result without -# installing MathJax. -# However, it is strongly recommended to install a local -# copy of MathJax from http://www.mathjax.org before deployment. +# When MathJax is enabled you can set the default output format to be used for +# the MathJax output. See the MathJax site (see: +# http://docs.mathjax.org/en/latest/output.html) for more details. +# Possible values are: HTML-CSS (which is slower, but has the best +# compatibility), NativeMML (i.e. MathML) and SVG. +# The default value is: HTML-CSS. +# This tag requires that the tag USE_MATHJAX is set to YES. + +MATHJAX_FORMAT = HTML-CSS + +# When MathJax is enabled you need to specify the location relative to the HTML +# output directory using the MATHJAX_RELPATH option. The destination directory +# should contain the MathJax.js script. For instance, if the mathjax directory +# is located at the same level as the HTML output directory, then +# MATHJAX_RELPATH should be ../mathjax. The default value points to the MathJax +# Content Delivery Network so you can quickly see the result without installing +# MathJax. However, it is strongly recommended to install a local copy of +# MathJax from http://www.mathjax.org before deployment. +# The default value is: http://cdn.mathjax.org/mathjax/latest. +# This tag requires that the tag USE_MATHJAX is set to YES. MATHJAX_RELPATH = http://www.mathjax.org/mathjax -# The MATHJAX_EXTENSIONS tag can be used to specify one or MathJax extension -# names that should be enabled during MathJax rendering. +# The MATHJAX_EXTENSIONS tag can be used to specify one or more MathJax +# extension names that should be enabled during MathJax rendering. For example +# MATHJAX_EXTENSIONS = TeX/AMSmath TeX/AMSsymbols +# This tag requires that the tag USE_MATHJAX is set to YES. MATHJAX_EXTENSIONS = -# When the SEARCHENGINE tag is enabled doxygen will generate a search box -# for the HTML output. The underlying search engine uses javascript -# and DHTML and should work on any modern browser. Note that when using -# HTML help (GENERATE_HTMLHELP), Qt help (GENERATE_QHP), or docsets -# (GENERATE_DOCSET) there is already a search function so this one should -# typically be disabled. For large projects the javascript based search engine -# can be slow, then enabling SERVER_BASED_SEARCH may provide a better solution. +# The MATHJAX_CODEFILE tag can be used to specify a file with javascript pieces +# of code that will be used on startup of the MathJax code. See the MathJax site +# (see: http://docs.mathjax.org/en/latest/output.html) for more details. For an +# example see the documentation. +# This tag requires that the tag USE_MATHJAX is set to YES. + +MATHJAX_CODEFILE = + +# When the SEARCHENGINE tag is enabled doxygen will generate a search box for +# the HTML output. The underlying search engine uses javascript and DHTML and +# should work on any modern browser. Note that when using HTML help +# (GENERATE_HTMLHELP), Qt help (GENERATE_QHP), or docsets (GENERATE_DOCSET) +# there is already a search function so this one should typically be disabled. +# For large projects the javascript based search engine can be slow, then +# enabling SERVER_BASED_SEARCH may provide a better solution. It is possible to +# search using the keyboard; to jump to the search box use + S +# (what the is depends on the OS and browser, but it is typically +# , /