]> git.stg.codes - stg.git/blob - projects/stargazer/plugins/other/smux/smux.h
Rules counter added to the SMUX plugin
[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 "stg/SMUX-PDUs.h"
10 #include "stg/ObjectSyntax.h"
11
12 #include "stg/os_int.h"
13 #include "stg/plugin.h"
14 #include "stg/module_settings.h"
15
16 #include "sensors.h"
17 #include "tables.h"
18 #include "types.h"
19
20 extern "C" PLUGIN * GetPlugin();
21
22 class USER;
23 class SETTINGS;
24 class SMUX;
25 class USERS;
26 class TARIFFS;
27 class SERVICES;
28 class CORPORATIONS;
29 class TRAFFCOUNTER;
30
31 typedef bool (SMUX::*SMUXPacketHandler)(const SMUX_PDUs_t * pdus);
32 typedef bool (SMUX::*PDUsHandler)(const PDUs_t * pdus);
33 typedef std::map<SMUX_PDUs_PR, SMUXPacketHandler> SMUXHandlers;
34 typedef std::map<PDUs_PR, PDUsHandler> PDUsHandlers;
35 //-----------------------------------------------------------------------------
36 class SMUX_SETTINGS {
37 public:
38     SMUX_SETTINGS();
39     virtual ~SMUX_SETTINGS() {}
40     const std::string & GetStrError() const { return errorStr; }
41     int ParseSettings(const MODULE_SETTINGS & s);
42
43     uint32_t GetIP() const { return ip; }
44     uint16_t GetPort() const { return port; }
45     const std::string GetPassword() const { return password; }
46
47 private:
48     mutable std::string errorStr;
49
50     uint32_t ip;
51     uint16_t port;
52     std::string password;
53 };
54 //-----------------------------------------------------------------------------
55 class SMUX : public PLUGIN {
56 public:
57     SMUX();
58     virtual ~SMUX();
59
60     void SetUsers(USERS * u) { users = u; }
61     void SetTariffs(TARIFFS * t) { tariffs = t; }
62     void SetAdmins(ADMINS * a) { admins = a; }
63     void SetServices(SERVICES * s) { services = s; }
64     void SetTraffcounter(TRAFFCOUNTER * tc) { traffcounter = tc; }
65     void SetCorporations(CORPORATIONS * c) { corporations = c; }
66     void SetSettings(const MODULE_SETTINGS & s) { settings = s; }
67     int ParseSettings();
68
69     int Start();
70     int Stop();
71     int Reload() { return 0; }
72     bool IsRunning() { return running && !stopped; }
73
74     const std::string & GetStrError() const { return errorStr; }
75     const std::string GetVersion() const { return "Stg SMUX Plugin 1.1"; }
76     uint16_t GetStartPosition() const { return 100; }
77     uint16_t GetStopPosition() const { return 100; }
78
79 private:
80     static void * Runner(void * d);
81     void Run();
82     bool PrepareNet();
83
84     bool DispatchPDUs(const SMUX_PDUs_t * pdus);
85
86     bool CloseHandler(const SMUX_PDUs_t * pdus);
87     bool RegisterResponseHandler(const SMUX_PDUs_t * pdus);
88     bool PDUsRequestHandler(const SMUX_PDUs_t * pdus);
89     bool CommitOrRollbackHandler(const SMUX_PDUs_t * pdus);
90
91     bool GetRequestHandler(const PDUs_t * pdus);
92     bool GetNextRequestHandler(const PDUs_t * pdus);
93     bool SetRequestHandler(const PDUs_t * pdus);
94
95     bool UpdateTables();
96
97     USERS * users;
98     TARIFFS * tariffs;
99     ADMINS * admins;
100     SERVICES * services;
101     CORPORATIONS * corporations;
102     TRAFFCOUNTER * traffcounter;
103
104     mutable std::string errorStr;
105     SMUX_SETTINGS smuxSettings;
106     MODULE_SETTINGS settings;
107
108     pthread_t thread;
109     pthread_mutex_t mutex;
110     bool running;
111     bool stopped;
112
113     int sock;
114
115     SMUXHandlers smuxHandlers;
116     PDUsHandlers pdusHandlers;
117     Sensors sensors;
118     Tables tables;
119
120 };
121 //-----------------------------------------------------------------------------
122
123 extern "C" PLUGIN * GetPlugin();
124
125 #endif