1 #ifndef __SNMP_AGENT_H__
2 #define __SNMP_AGENT_H__
9 #include "asn1/SMUX-PDUs.h"
10 #include "asn1/ObjectSyntax.h"
12 #include "stg/os_int.h"
13 #include "stg/plugin.h"
14 #include "stg/module_settings.h"
15 #include "stg/users.h"
16 #include "stg/tariffs.h"
20 extern "C" PLUGIN * GetPlugin();
26 typedef bool (SNMP_AGENT::*SMUXPacketHandler)(const SMUX_PDUs_t * pdus);
27 typedef bool (SNMP_AGENT::*PDUsHandler)(const PDUs_t * pdus);
28 typedef std::map<SMUX_PDUs_PR, SMUXPacketHandler> SMUXHandlers;
29 typedef std::map<PDUs_PR, PDUsHandler> PDUsHandlers;
30 //-----------------------------------------------------------------------------
31 class SNMP_AGENT_SETTINGS {
33 SNMP_AGENT_SETTINGS();
34 virtual ~SNMP_AGENT_SETTINGS() {}
35 const std::string & GetStrError() const { return errorStr; }
36 int ParseSettings(const MODULE_SETTINGS & s);
38 uint32_t GetIP() const { return ip; }
39 uint16_t GetPort() const { return port; }
40 const std::string GetPassword() const { return password; }
43 mutable std::string errorStr;
49 //-----------------------------------------------------------------------------
50 class SNMP_AGENT : public PLUGIN {
53 virtual ~SNMP_AGENT();
55 void SetUsers(USERS * u) { users = u; }
56 void SetTariffs(TARIFFS * t) { tariffs = t; }
57 void SetAdmins(ADMINS *) {}
58 void SetTraffcounter(TRAFFCOUNTER *) {}
59 void SetStore(STORE *) {}
60 void SetStgSettings(const SETTINGS *) {}
61 void SetSettings(const MODULE_SETTINGS & s) { settings = s; }
66 int Reload() { return 0; }
67 bool IsRunning() { return running && !stopped; }
69 const std::string & GetStrError() const { return errorStr; }
70 const std::string GetVersion() const { return "Stg SNMP Agent 1.0"; }
71 uint16_t GetStartPosition() const { return 100; }
72 uint16_t GetStopPosition() const { return 100; }
75 static void * Runner(void * d);
79 bool DispatchPDUs(const SMUX_PDUs_t * pdus);
81 bool CloseHandler(const SMUX_PDUs_t * pdus);
82 bool RegisterResponseHandler(const SMUX_PDUs_t * pdus);
83 bool PDUsHandler(const SMUX_PDUs_t * pdus);
84 bool CommitOrRollbackHandler(const SMUX_PDUs_t * pdus);
86 bool GetRequestHandler(const PDUs_t * pdus);
87 bool GetNextRequestHandler(const PDUs_t * pdus);
88 bool SetRequestHandler(const PDUs_t * pdus);
93 mutable std::string errorStr;
94 SNMP_AGENT_SETTINGS snmpAgentSettings;
95 MODULE_SETTINGS settings;
98 pthread_mutex_t mutex;
104 SMUXHandlers smuxHandlers;
105 PDUsHandlers pdusHandlers;
108 //-----------------------------------------------------------------------------
110 extern "C" PLUGIN * GetPlugin();