]> git.stg.codes - stg.git/blob - projects/stargazer/plugins/other/snmp/snmp.h
Core functionality implemented
[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::*SNMPPacketHandler)(const SMUX_PDUs_t * pdus);
23 //-----------------------------------------------------------------------------
24 class SNMP_AGENT_SETTINGS {
25 public:
26     SNMP_AGENT_SETTINGS();
27     virtual ~SNMP_AGENT_SETTINGS() {}
28     const std::string & GetStrError() const { return errorStr; }
29     int ParseSettings(const MODULE_SETTINGS & s);
30
31     uint32_t GetIP() const { return ip; }
32     uint16_t GetPort() const { return port; }
33     const std::string GetPassword() const { return password; }
34
35 private:
36     mutable std::string errorStr;
37
38     uint32_t ip;
39     uint16_t port;
40     std::string password;
41 };
42 //-----------------------------------------------------------------------------
43 class SNMP_AGENT : public PLUGIN {
44 public:
45     SNMP_AGENT();
46     virtual ~SNMP_AGENT();
47
48     void SetUsers(USERS *) {}
49     void SetTariffs(TARIFFS *) {}
50     void SetAdmins(ADMINS *) {}
51     void SetTraffcounter(TRAFFCOUNTER *) {}
52     void SetStore(STORE *) {}
53     void SetStgSettings(const SETTINGS *) {}
54     void SetSettings(const MODULE_SETTINGS & s) { settings = s; }
55     int ParseSettings();
56
57     int Start();
58     int Stop();
59     int Reload() { return 0; }
60     bool IsRunning() { return running && !stopped; }
61
62     const std::string & GetStrError() const { return errorStr; }
63     const std::string GetVersion() const { return "Stg SNMP Agent 1.0"; }
64     uint16_t GetStartPosition() const { return 100; }
65     uint16_t GetStopPosition() const { return 100; }
66
67 private:
68     static void * Runner(void * d);
69     void Run();
70     bool PrepareNet();
71
72     bool DispatchPDUs(const SMUX_PDUs_t * pdus);
73
74     bool CloseHandler(const SMUX_PDUs_t * pdus);
75     bool RegisterResponseHandler(const SMUX_PDUs_t * pdus);
76     bool PDUsHandler(const SMUX_PDUs_t * pdus);
77     bool CommitOrRollbackHandler(const SMUX_PDUs_t * pdus);
78
79     mutable std::string errorStr;
80     SNMP_AGENT_SETTINGS snmpAgentSettings;
81     MODULE_SETTINGS settings;
82
83     pthread_t thread;
84     pthread_mutex_t mutex;
85     bool running;
86     bool stopped;
87
88     int sock;
89
90     std::map<SMUX_PDUs_PR, SNMPPacketHandler> handlers;
91 };
92 //-----------------------------------------------------------------------------
93
94 extern "C" PLUGIN * GetPlugin();
95
96 #endif