]> git.stg.codes - stg.git/blob - projects/stargazer/plugins/other/smux/smux.h
SMUX plugin code separated to SNMP helper functions and core logic
[stg.git] / projects / stargazer / plugins / other / smux / smux.h
1 #ifndef __SMUX_H__
2 #define __SMUX_H__
3
4 #include <pthread.h>
5
6 #include <string>
7 #include <map>
8
9 #include "asn1/SMUX-PDUs.h"
10 #include "asn1/ObjectSyntax.h"
11
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"
17
18 #include "sensors.h"
19
20 extern "C" PLUGIN * GetPlugin();
21
22 class USER;
23 class SETTINGS;
24 class SMUX;
25
26 typedef bool (SMUX::*SMUXPacketHandler)(const SMUX_PDUs_t * pdus);
27 typedef bool (SMUX::*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 SMUX_SETTINGS {
32 public:
33     SMUX_SETTINGS();
34     virtual ~SMUX_SETTINGS() {}
35     const std::string & GetStrError() const { return errorStr; }
36     int ParseSettings(const MODULE_SETTINGS & s);
37
38     uint32_t GetIP() const { return ip; }
39     uint16_t GetPort() const { return port; }
40     const std::string GetPassword() const { return password; }
41
42 private:
43     mutable std::string errorStr;
44
45     uint32_t ip;
46     uint16_t port;
47     std::string password;
48 };
49 //-----------------------------------------------------------------------------
50 class SMUX : public PLUGIN {
51 public:
52     SMUX();
53     virtual ~SMUX();
54
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; }
62     int ParseSettings();
63
64     int Start();
65     int Stop();
66     int Reload() { return 0; }
67     bool IsRunning() { return running && !stopped; }
68
69     const std::string & GetStrError() const { return errorStr; }
70     const std::string GetVersion() const { return "Stg SMUX Plugin 1.1"; }
71     uint16_t GetStartPosition() const { return 100; }
72     uint16_t GetStopPosition() const { return 100; }
73
74 private:
75     static void * Runner(void * d);
76     void Run();
77     bool PrepareNet();
78
79     bool DispatchPDUs(const SMUX_PDUs_t * pdus);
80
81     bool CloseHandler(const SMUX_PDUs_t * pdus);
82     bool RegisterResponseHandler(const SMUX_PDUs_t * pdus);
83     bool PDUsRequestHandler(const SMUX_PDUs_t * pdus);
84     bool CommitOrRollbackHandler(const SMUX_PDUs_t * pdus);
85
86     bool GetRequestHandler(const PDUs_t * pdus);
87     bool GetNextRequestHandler(const PDUs_t * pdus);
88     bool SetRequestHandler(const PDUs_t * pdus);
89
90     USERS * users;
91     TARIFFS * tariffs;
92
93     mutable std::string errorStr;
94     SMUX_SETTINGS smuxSettings;
95     MODULE_SETTINGS settings;
96
97     pthread_t thread;
98     pthread_mutex_t mutex;
99     bool running;
100     bool stopped;
101
102     int sock;
103
104     SMUXHandlers smuxHandlers;
105     PDUsHandlers pdusHandlers;
106     Sensors sensors;
107
108 };
109 //-----------------------------------------------------------------------------
110
111 extern "C" PLUGIN * GetPlugin();
112
113 #endif