]> git.stg.codes - stg.git/blob - projects/stargazer/plugins/other/smux/smux.h
More clear plugin API
[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 SetSettings(const MODULE_SETTINGS & s) { settings = s; }
65     int ParseSettings();
66
67     int Start();
68     int Stop();
69     int Reload() { return 0; }
70     bool IsRunning() { return running && !stopped; }
71
72     const std::string & GetStrError() const { return errorStr; }
73     const std::string GetVersion() const { return "Stg SMUX Plugin 1.1"; }
74     uint16_t GetStartPosition() const { return 100; }
75     uint16_t GetStopPosition() const { return 100; }
76
77 private:
78     static void * Runner(void * d);
79     void Run();
80     bool PrepareNet();
81
82     bool DispatchPDUs(const SMUX_PDUs_t * pdus);
83
84     bool CloseHandler(const SMUX_PDUs_t * pdus);
85     bool RegisterResponseHandler(const SMUX_PDUs_t * pdus);
86     bool PDUsRequestHandler(const SMUX_PDUs_t * pdus);
87     bool CommitOrRollbackHandler(const SMUX_PDUs_t * pdus);
88
89     bool GetRequestHandler(const PDUs_t * pdus);
90     bool GetNextRequestHandler(const PDUs_t * pdus);
91     bool SetRequestHandler(const PDUs_t * pdus);
92
93     bool UpdateTables();
94
95     USERS * users;
96     TARIFFS * tariffs;
97     ADMINS * admins;
98     SERVICES * services;
99     CORPORATIONS * corporations;
100
101     mutable std::string errorStr;
102     SMUX_SETTINGS smuxSettings;
103     MODULE_SETTINGS settings;
104
105     pthread_t thread;
106     pthread_mutex_t mutex;
107     bool running;
108     bool stopped;
109
110     int sock;
111
112     SMUXHandlers smuxHandlers;
113     PDUsHandlers pdusHandlers;
114     Sensors sensors;
115     Tables tables;
116
117 };
118 //-----------------------------------------------------------------------------
119
120 extern "C" PLUGIN * GetPlugin();
121
122 #endif