]> git.stg.codes - stg.git/blob - projects/stargazer/plugins/other/smux/smux.h
Admin, service and corporation sesnsors added for SUMX
[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
30 typedef bool (SMUX::*SMUXPacketHandler)(const SMUX_PDUs_t * pdus);
31 typedef bool (SMUX::*PDUsHandler)(const PDUs_t * pdus);
32 typedef std::map<SMUX_PDUs_PR, SMUXPacketHandler> SMUXHandlers;
33 typedef std::map<PDUs_PR, PDUsHandler> PDUsHandlers;
34 //-----------------------------------------------------------------------------
35 class SMUX_SETTINGS {
36 public:
37     SMUX_SETTINGS();
38     virtual ~SMUX_SETTINGS() {}
39     const std::string & GetStrError() const { return errorStr; }
40     int ParseSettings(const MODULE_SETTINGS & s);
41
42     uint32_t GetIP() const { return ip; }
43     uint16_t GetPort() const { return port; }
44     const std::string GetPassword() const { return password; }
45
46 private:
47     mutable std::string errorStr;
48
49     uint32_t ip;
50     uint16_t port;
51     std::string password;
52 };
53 //-----------------------------------------------------------------------------
54 class SMUX : public PLUGIN {
55 public:
56     SMUX();
57     virtual ~SMUX();
58
59     void SetUsers(USERS * u) { users = u; }
60     void SetTariffs(TARIFFS * t) { tariffs = t; }
61     void SetAdmins(ADMINS * a) { admins = a; }
62     void SetServices(SERVICES * s) { services = s; }
63     void SetCorporations(CORPORATIONS * c) { corporations = c; }
64     void SetTraffcounter(TRAFFCOUNTER *) {}
65     void SetStore(STORE *) {}
66     void SetStgSettings(const SETTINGS *) {}
67     void SetSettings(const MODULE_SETTINGS & s) { settings = s; }
68     int ParseSettings();
69
70     int Start();
71     int Stop();
72     int Reload() { return 0; }
73     bool IsRunning() { return running && !stopped; }
74
75     const std::string & GetStrError() const { return errorStr; }
76     const std::string GetVersion() const { return "Stg SMUX Plugin 1.1"; }
77     uint16_t GetStartPosition() const { return 100; }
78     uint16_t GetStopPosition() const { return 100; }
79
80 private:
81     static void * Runner(void * d);
82     void Run();
83     bool PrepareNet();
84
85     bool DispatchPDUs(const SMUX_PDUs_t * pdus);
86
87     bool CloseHandler(const SMUX_PDUs_t * pdus);
88     bool RegisterResponseHandler(const SMUX_PDUs_t * pdus);
89     bool PDUsRequestHandler(const SMUX_PDUs_t * pdus);
90     bool CommitOrRollbackHandler(const SMUX_PDUs_t * pdus);
91
92     bool GetRequestHandler(const PDUs_t * pdus);
93     bool GetNextRequestHandler(const PDUs_t * pdus);
94     bool SetRequestHandler(const PDUs_t * pdus);
95
96     bool UpdateTables();
97
98     USERS * users;
99     TARIFFS * tariffs;
100     ADMINS * admins;
101     SERVICES * services;
102     CORPORATIONS * corporations;
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