📄 target.h
字号:
/*_############################################################################ _## _## target.h _## _## SNMP++v3.2.21a _## ----------------------------------------------- _## Copyright (c) 2001-2006 Jochen Katz, Frank Fock _## _## This software is based on SNMP++2.6 from Hewlett Packard: _## _## Copyright (c) 1996 _## Hewlett-Packard Company _## _## ATTENTION: USE OF THIS SOFTWARE IS SUBJECT TO THE FOLLOWING TERMS. _## Permission to use, copy, modify, distribute and/or sell this software _## and/or its documentation is hereby granted without fee. User agrees _## to display the above copyright notice and this license notice in all _## copies of the software and any documentation of the software. User _## agrees to assume all liability for the use of the software; _## Hewlett-Packard and Jochen Katz make no representations about the _## suitability of this software for any purpose. It is provided _## "AS-IS" without warranty of any kind, either express or implied. User _## hereby grants a royalty-free license to any and all derivatives based _## upon this software code base. _## _## Stuttgart, Germany, Tue Nov 21 22:12:16 CET 2006 _## _##########################################################################*//*=================================================================== Copyright (c) 1999 Hewlett-Packard Company ATTENTION: USE OF THIS SOFTWARE IS SUBJECT TO THE FOLLOWING TERMS. Permission to use, copy, modify, distribute and/or sell this software and/or its documentation is hereby granted without fee. User agrees to display the above copyright notice and this license notice in all copies of the software and any documentation of the software. User agrees to assume all liability for the use of the software; Hewlett-Packard makes no representations about the suitability of this software for any purpose. It is provided "AS-IS" without warranty of any kind,either express or implied. User hereby grants a royalty-free license to any and all derivatives based upon this software code base. SNMP++ T A R G E T . H TARGET CLASS DEFINITION DESIGN + AUTHOR: Peter E Mellquist LANGUAGE: ANSI C++ OPERATING SYSTEMS: DOS/WINDOWS 3.1 BSD UNIX DESCRIPTION: Target class defines target SNMP agents.=====================================================================*/// $Id: target.h,v 1.7 2004/06/20 18:49:21 katz Exp $#ifndef _TARGET#define _TARGET//----[ includes ]-----------------------------------------------------#include "snmp_pp/config_snmp_pp.h"#include "snmp_pp/address.h"#include "snmp_pp/octet.h"#include "snmp_pp/collect.h"#ifdef SNMP_PP_NAMESPACEnamespace Snmp_pp {#endif//----[ enumerated types for SNMP versions ]---------------------------/** * The SNMP version to use is passed with this enum. */enum snmp_version{ version1, ///< (0) SNMPv1 version2c ///< (1) SNMPv2c#ifdef _SNMPv3 ,version2stern, ///< (2) Dont use this! version3 ///< (3) SNMPv3#endif};//----[ Target class ]-------------------------------------------------/** * Abstract class used to provide a virtual interface into Targets. * * @note Although it is possible to create an object of this class, * you won't be happy with that... */class DLLOPT SnmpTarget{ public: /** * Enum to identify a target object through SnmpTarget::get_type() method. */ enum target_type { type_base, ///< It is a SnmpTarget object type_ctarget, ///< It is a CTarget object type_utarget ///< It is a Utarget object }; /** * Create a SnmpTarget object with default values. * The validity of the target will be false. */ SnmpTarget() : validity(false), timeout(default_timeout), retries(default_retries), version(version1), ttype(type_base) {}; /** * Create a SnmpTarget object with the given Address. */ SnmpTarget( const Address &address) : validity(false), timeout(default_timeout), retries(default_retries), version(version1), ttype(type_base), my_address(address) { if (my_address.valid()) validity = true; }; /** * Destructor that has nothing to do. */ virtual ~SnmpTarget() {}; /** * Return the type of the target object. * * If a SNMP message is received through a callback (that only * passes a SnmpTarget pointer to the callback function), this * method can be used to check the type of the object before doing a * cast to CTarget or UTarget. */ target_type get_type() const { return ttype; }; /** * Returns the validity of the target object. * * @return true, if the target is valid. */ bool valid() const { return validity;}; /** * Set the retry value. * * @param r - The number of retries if no response is received. */ void set_retry( const int r) { retries = r; }; /** * Get the retry value. * * @return The number of retries on timeout. */ int get_retry() const { return retries; }; /** * Set the timeout for requests. * * The default timeout for requests is 1 second (100). * * @param t - Timeout in 10ms, so 100 will set the timeout to 1 second. */ void set_timeout( const unsigned long t) { timeout = t; }; /** * Get the timeout. * * @return The timeout for requests sent using this target object. */ unsigned long get_timeout() const { return timeout; }; /** * Change the default timeout. * * Changing the default timeout value will only have an effect for * target objects that are created after setting this value. * * @param t - The new default timeout value */ static void set_default_timeout( const unsigned long t) { default_timeout = t; }; /** * Change the default retries vlaue. * * Changing the default retries value will only have an effect for * target objects that are created after setting this value. * * @param r - The new retries value */ static void set_default_retries( const int r) { default_retries = r; }; /** * Clone operator. * * Virtual clone operation for creating a new SnmpTarget from an existing * SnmpTarget. * * @note The caller MUST use the delete operation on the return * value when done. * * @return A pointer to the new object on success, 0 on failure. */ virtual SnmpTarget *clone() const; /** * Get the address object. * * @param address - GenAddress object to store the target address. * @return TRUE on success. */ int get_address( GenAddress &address) const; /** * Get the address object. * * @return The target address. */ const GenAddress &get_address() const { return my_address; }; /** * Set the address object. * * @param address - The address that this target should use. * @return TRUE on success. */ virtual int set_address( const Address &address); /** * Get the SNMP version for this target. * * @return The SNMP version of this target object. * @see enum snmp_version */ snmp_version get_version() const { return version;}; /** * Set the SNMP version of this target. * * @param v - The SNMP version that should be used for sending messages. */ void set_version( const snmp_version v) { version = v; }; /** * Overloeaded compare operator. * * Two SnmpTarget objects are considered equal, if all member * variables are equal. * * @return 1 if targets are equal, 0 if not. */ int operator==(const SnmpTarget &rhs) const; /** * Reset the object. */ void clear(); protected: bool validity; ///< Validity of the object unsigned long timeout; ///< xmit timeout in 10 milli secs int retries; ///< number of retries snmp_version version; ///< SNMP version to use target_type ttype; ///< Type of the target GenAddress my_address; ///< Address object static unsigned long default_timeout; ///< default timeout for new objects static int default_retries; ///< default retries for new objects};//----[ CTarget class ]----------------------------------------------/** * Community based target object. * This target can be used for SNMPv1 and SNMPv2c messages. */class DLLOPT CTarget: public SnmpTarget{ public: /** * Constructor with no args. * The validity of the target will be false. */ CTarget(); /** * Constructor with all args. * * @param address - Address of the target host (cann be any address object) * @param read_community_name - Community for get requests * @param write_community_name - Community for set requests */ CTarget( const Address &address, const char *read_community_name, const char *write_community_name); /** * Constructor with all args. * * @param address - Address of the target host (cann be any address object) * @param read_community_name - Community for get requests * @param write_community_name - Community for set requests */ CTarget( const Address &address, const OctetStr &read_community_name, const OctetStr &write_community_name); /** * Constructor with only address. * * The read and write community names will be set to "public". * * @param address - Address of the target host (cann be any address object) */ CTarget( const Address &address); /** * Constructor from existing CTarget. */ CTarget( const CTarget &target); /** * Destructor, that has nothing to do. */ ~CTarget() {}; /**
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -