]> git.stg.codes - stg.git/blob - projects/stargazer/plugins/other/snmp/snmp.h
Request handlers added
[stg.git] / projects / stargazer / plugins / other / snmp / snmp.h
1 #ifndef __SNMP_AGENT_H__
2 #define __SNMP_AGENT_H__
3
4 #include <pthread.h>
5
6 #include <string>
7 #include <map>
8
9 #include "asn1/SMUX-PDUs.h"
10
11 #include "stg/os_int.h"
12 #include "stg/plugin.h"
13 #include "stg/module_settings.h"
14 #include "stg/users.h"
15
16 extern "C" PLUGIN * GetPlugin();
17
18 class USER;
19 class SETTINGS;
20 class SNMP_AGENT;
21
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 {
28 public:
29     SNMP_AGENT_SETTINGS();
30     virtual ~SNMP_AGENT_SETTINGS() {}
31     const std::string & GetStrError() const { return errorStr; }
32     int ParseSettings(const MODULE_SETTINGS & s);
33
34     uint32_t GetIP() const { return ip; }
35     uint16_t GetPort() const { return port; }
36     const std::string GetPassword() const { return password; }
37
38 private:
39     mutable std::string errorStr;
40
41     uint32_t ip;
42     uint16_t port;
43     std::string password;
44 };
45 //-----------------------------------------------------------------------------
46 class SNMP_AGENT : public PLUGIN {
47 public:
48     SNMP_AGENT();
49     virtual ~SNMP_AGENT();
50
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; }
58     int ParseSettings();
59
60     int Start();
61     int Stop();
62     int Reload() { return 0; }
63     bool IsRunning() { return running && !stopped; }
64
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; }
69
70 private:
71     static void * Runner(void * d);
72     void Run();
73     bool PrepareNet();
74
75     bool DispatchPDUs(const SMUX_PDUs_t * pdus);
76
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);
81
82     bool GetRequestHandler(const PDUs_t * pdus);
83     bool GetNextRequestHandler(const PDUs_t * pdus);
84     bool SetRequestHandler(const PDUs_t * pdus);
85
86     mutable std::string errorStr;
87     SNMP_AGENT_SETTINGS snmpAgentSettings;
88     MODULE_SETTINGS settings;
89
90     pthread_t thread;
91     pthread_mutex_t mutex;
92     bool running;
93     bool stopped;
94
95     int sock;
96
97     SMUXHandlers smuxHandlers;
98     PDUsHandlers pdusHandlers;
99 };
100 //-----------------------------------------------------------------------------
101
102 extern "C" PLUGIN * GetPlugin();
103
104 #endif