]> git.stg.codes - stg.git/blob - projects/stargazer/plugins/other/snmp/snmp.h
Partially working snmp agent
[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
8 #include "stg/os_int.h"
9 #include "stg/plugin.h"
10 #include "stg/module_settings.h"
11 #include "stg/users.h"
12
13 extern "C" PLUGIN * GetPlugin();
14
15 class USER;
16 class SETTINGS;
17 //-----------------------------------------------------------------------------
18 class SNMP_AGENT_SETTINGS {
19 public:
20     SNMP_AGENT_SETTINGS();
21     virtual ~SNMP_AGENT_SETTINGS() {}
22     const std::string & GetStrError() const { return errorStr; }
23     int ParseSettings(const MODULE_SETTINGS & s);
24
25     uint32_t GetIP() const { return ip; }
26     uint16_t GetPort() const { return port; }
27     const std::string GetPassword() const { return password; }
28
29 private:
30     mutable std::string errorStr;
31
32     uint32_t ip;
33     uint16_t port;
34     std::string password;
35 };
36 //-----------------------------------------------------------------------------
37 class SNMP_AGENT : public PLUGIN {
38 public:
39     SNMP_AGENT();
40     virtual ~SNMP_AGENT();
41
42     void SetUsers(USERS *) {}
43     void SetTariffs(TARIFFS *) {}
44     void SetAdmins(ADMINS *) {}
45     void SetTraffcounter(TRAFFCOUNTER *) {}
46     void SetStore(STORE *) {}
47     void SetStgSettings(const SETTINGS *) {}
48     void SetSettings(const MODULE_SETTINGS & s) { settings = s; }
49     int ParseSettings();
50
51     int Start();
52     int Stop();
53     int Reload() { return 0; }
54     bool IsRunning() { return running && !stopped; }
55
56     const std::string & GetStrError() const { return errorStr; }
57     const std::string GetVersion() const { return "Stg SNMP Agent 1.0"; }
58     uint16_t GetStartPosition() const { return 100; }
59     uint16_t GetStopPosition() const { return 100; }
60
61 private:
62     static void * Runner(void * d);
63     void Run();
64     bool PrepareNet();
65
66     mutable std::string errorStr;
67     SNMP_AGENT_SETTINGS snmpAgentSettings;
68     MODULE_SETTINGS settings;
69
70     pthread_t thread;
71     pthread_mutex_t mutex;
72     bool running;
73     bool stopped;
74
75     int sock;
76 };
77 //-----------------------------------------------------------------------------
78
79 extern "C" PLUGIN * GetPlugin();
80
81 #endif