Merge branch 'master' into jwi-bcc64xsingletonwarning
[ACE_TAO.git] / ACE / ASNMP / asnmp / snmp.h
blob8f46161e0c61b8f21ec4951456719f1bb1a89a5a
1 /* -*-C++-*- */
2 #ifndef SNMP_CLS_
3 #define SNMP_CLS_
4 //=============================================================================
5 /**
6 * @file snmp.h
8 * SNMP class definition. The Snmp class provides an object oriented
9 * approach to SNMP. The SNMP class is an encapsulation of SNMP
10 * sessions, gets, sets, etc. The class manages all SNMP
11 * resources and provides complete retry and timeout capability.
13 * @author Peter E Mellquist design
14 * @author first implementation Michael R. MacFaden port to ACE / use Reactor pattern
16 //=============================================================================
18 /*===================================================================
19 Copyright (c) 1996
20 Hewlett-Packard Company
22 ATTENTION: USE OF THIS SOFTWARE IS SUBJECT TO THE FOLLOWING TERMS.
23 Permission to use, copy, modify, distribute and/or sell this software
24 and/or its documentation is hereby granted without fee. User agrees
25 to display the above copyright notice and this license notice in all
26 copies of the software and any documentation of the software. User
27 agrees to assume all liability for the use of the software; Hewlett-Packard
28 makes no representations about the suitability of this software for any
29 purpose. It is provided "AS-IS without warranty of any kind,either express
30 or implied. User hereby grants a royalty-free license to any and all
31 derivatives based upon this software code base.
32 =====================================================================*/
34 #include "ace/Reactor.h"
36 #if !defined (ACE_LACKS_PRAGMA_ONCE)
37 # pragma once
38 #endif /* ACE_LACKS_PRAGMA_ONCE */
40 #include "ace/SOCK_Dgram.h"
42 #include "asnmp/oid.h" // snmp++ oid class
43 #include "asnmp/vb.h" // snbmp++ vb class
44 #include "asnmp/target.h" // snmp++ target class
45 #include "asnmp/pdu.h" // snmp++ pdu class
46 #include "asnmp/snmperrs.h" // error macros and strings
47 #include "asnmp/address.h" // snmp++ address class defs
48 #include "asnmp/transaction_result.h"
49 #include "asnmp/ASNMP_Export.h"
51 class Snmp;
52 class ASNMP_Export Snmp_Result
54 public:
55 Snmp_Result ();
56 virtual ~Snmp_Result();
57 virtual void result(Snmp *snmp, int result) = 0;
60 // Snmp session class - supports Version 1 operations in blocking mode
61 /**
62 * @class Snmp
64 * @brief Concrete class Snmp defined the session and interface to
65 * communicate with another SNMP Version 1 agent
67 class ASNMP_Export Snmp : public transaction_result
69 Snmp_Result * result_;
70 Pdu * pdu_;
71 unsigned hold_req_id_;
72 public:
73 Snmp(unsigned short port = INADDR_ANY);
74 virtual ~Snmp();
76 /// retrieve data from a peer agent for a given list of oid values
77 /// default port 161
78 int get( Pdu &pdu, UdpTarget &target, Snmp_Result * cb = 0);
80 /**
81 * retrieve data lexically adjacent to the oids specified in the pdu
82 * from the peer agent
83 * default port 161
85 int get_next( Pdu &pdu, UdpTarget &target, Snmp_Result * cb = 0);
87 /// set data in the agent from the list of oids in the pdu
88 /// default port 161
89 int set( Pdu &pdu, UdpTarget &target, Snmp_Result * cb = 0);
91 /// send an SNMPv1 trap (unreliable) to a remote system (def port 162)
92 int trap( Pdu &pdu, UdpTarget &target);
94 /// status of object after construction
95 int valid() const;
97 /// given error code, return string reason
98 static const char * error_string(int code);
100 /// retrieve a reason string if any of the above commands fail
101 const char * error_string();
103 /// for async transaction results
104 void result(transaction * t, int rc);
106 /// allow the host name to be overriden
107 static void override_host_name(const char* name);
109 /// returns the overriden host name
110 static void get_host_name(char* name, int len);
112 protected:
113 void check_default_port(UdpTarget& target,unsigned short port=DEF_AGENT_PORT);
114 int run_transaction(Pdu& pdu, UdpTarget& target);
115 int run_transaction(Pdu& pdu, UdpTarget& target, Snmp_Result * cb);
116 int validate_args(const Pdu& pdu, const UdpTarget& target) const;
118 Snmp(const Snmp&);
120 /// io object
121 ACE_SOCK_Dgram iv_snmp_session_;
123 /// status of construction
124 int construct_status_;
126 /// result code from last transaction
127 int last_transaction_status_;
129 /// transaction request id
130 unsigned req_id_;
132 static char host_name_[MAXHOSTNAMELEN];
135 #endif //SNMP_CLS_