1 #ifndef __SNMP_AGENT_H__
2 #define __SNMP_AGENT_H__
9 #include "asn1/SMUX-PDUs.h"
11 #include "stg/os_int.h"
12 #include "stg/plugin.h"
13 #include "stg/module_settings.h"
14 #include "stg/users.h"
16 extern "C" PLUGIN * GetPlugin();
22 typedef bool (SNMP_AGENT::*SMUXPacketHandler)(const SMUX_PDUs_t * pdus);
23 typedef bool (SNMP_AGENT::*PDUsHandler)(const PDUs_t * pdus);
24 typedef std::map<SMUX_PDUs_PR, SMUXPacketHandler> SMUXHandlers;
25 typedef std::map<PDUs_PR, PDUsHandler> PDUsHandlers;
26 //-----------------------------------------------------------------------------
27 class SNMP_AGENT_SETTINGS {
29 SNMP_AGENT_SETTINGS();
30 virtual ~SNMP_AGENT_SETTINGS() {}
31 const std::string & GetStrError() const { return errorStr; }
32 int ParseSettings(const MODULE_SETTINGS & s);
34 uint32_t GetIP() const { return ip; }
35 uint16_t GetPort() const { return port; }
36 const std::string GetPassword() const { return password; }
39 mutable std::string errorStr;
45 //-----------------------------------------------------------------------------
46 class SNMP_AGENT : public PLUGIN {
49 virtual ~SNMP_AGENT();
51 void SetUsers(USERS *) {}
52 void SetTariffs(TARIFFS *) {}
53 void SetAdmins(ADMINS *) {}
54 void SetTraffcounter(TRAFFCOUNTER *) {}
55 void SetStore(STORE *) {}
56 void SetStgSettings(const SETTINGS *) {}
57 void SetSettings(const MODULE_SETTINGS & s) { settings = s; }
62 int Reload() { return 0; }
63 bool IsRunning() { return running && !stopped; }
65 const std::string & GetStrError() const { return errorStr; }
66 const std::string GetVersion() const { return "Stg SNMP Agent 1.0"; }
67 uint16_t GetStartPosition() const { return 100; }
68 uint16_t GetStopPosition() const { return 100; }
71 static void * Runner(void * d);
75 bool DispatchPDUs(const SMUX_PDUs_t * pdus);
77 bool CloseHandler(const SMUX_PDUs_t * pdus);
78 bool RegisterResponseHandler(const SMUX_PDUs_t * pdus);
79 bool PDUsHandler(const SMUX_PDUs_t * pdus);
80 bool CommitOrRollbackHandler(const SMUX_PDUs_t * pdus);
82 bool GetRequestHandler(const PDUs_t * pdus);
83 bool GetNextRequestHandler(const PDUs_t * pdus);
84 bool SetRequestHandler(const PDUs_t * pdus);
86 mutable std::string errorStr;
87 SNMP_AGENT_SETTINGS snmpAgentSettings;
88 MODULE_SETTINGS settings;
91 pthread_mutex_t mutex;
97 SMUXHandlers smuxHandlers;
98 PDUsHandlers pdusHandlers;
100 //-----------------------------------------------------------------------------
102 extern "C" PLUGIN * GetPlugin();