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