Compile fixes
[ACE_TAO.git] / ACE / ASNMP / agent / snmp_agent.cpp
blobe71a5d52cde35ab5a159c4fcc018dc21d58f2485
1 // This server daemon processes SNMPv1 requests over MIB II System group
3 #include "snmp_agent.h"
4 #include "agent_impl.h" // actual implementation
5 #include "ace/Argv_Type_Converter.h"
6 #include "ace/Get_Opt.h"
7 #include "ace/Reactor.h"
9 // module globals
10 #define SNMP_AGENT_PORT (161)
11 #define WR_COM ACE_TEXT ("private")
12 #define RD_COM ACE_TEXT ("public")
14 snmp_agent::snmp_agent() : agent_(0)
16 ACE_TRACE("snmp_agent::snmp_agent");
19 snmp_agent::~snmp_agent()
21 ACE_TRACE("snmp_agent::~snmp_agent");
22 delete agent_;
26 int snmp_agent::valid() const
28 ACE_TRACE("snmp_agent::valid");
29 return (agent_ != 0);
32 int snmp_agent::set_args(int argc, char *argv[])
34 ACE_TRACE("snmp_agent::set_args");
35 unsigned short port = SNMP_AGENT_PORT;
36 const ACE_TCHAR *rd = RD_COM;
37 const ACE_TCHAR *wr = WR_COM;
38 ACE_Argv_Type_Converter to_tchar (argc, argv);
40 ACE_Get_Opt get_opt
41 (argc, to_tchar.get_TCHAR_argv (), ACE_TEXT ("p:w:r:hv"));
43 for (int c; (c = get_opt ()) != -1; )
45 switch (c)
47 case 'p':
48 port = (ACE_OS::atoi (get_opt.optarg));
49 break;
50 case 'w': // write community string
51 wr = get_opt.optarg;
52 break;
53 case 'r': // read community string
54 rd = get_opt.optarg;
55 break;
56 case 'h': // help & version info
57 case 'v':
58 ACE_DEBUG
59 ((LM_DEBUG,
60 ACE_TEXT ("(%P|%t) Example SNMP Version 1 Agent - ASNMP/ACE\n")));
61 return -1;
62 default:
63 return -1; // invalid arg
67 agent_ = new agent_impl(port,
68 ACE_TEXT_ALWAYS_CHAR (rd),
69 ACE_TEXT_ALWAYS_CHAR (wr)); // opens OS IO port
70 return 0;
73 int snmp_agent::run()
75 ACE_TRACE("snmp_agent::run");
76 ACE_ASSERT(agent_);
78 // open service port
79 #if 0
80 if (agent_->open_port()) {
81 ACE_DEBUG((LM_DEBUG, "(%P|%t) open port %d failed\n", agent_->get_port()));
82 return -1;
84 #endif
86 // Run forever, processing SNMP requests.
88 ACE_DEBUG ((LM_DEBUG,
89 ACE_TEXT ("(%P|%t) starting up snmp agent (server) daemon\n")));
91 agent_->process_requests();
93 ACE_DEBUG
94 ((LM_DEBUG,
95 ACE_TEXT ("(%P|%t) shutting down snmp agent (server) daemon\n")));
96 return 0;