10 #include "stg/SMUX-PDUs.h"
11 #include "stg/ObjectSyntax.h"
13 #include "stg/os_int.h"
14 #include "stg/plugin.h"
15 #include "stg/module_settings.h"
16 #include "stg/notifer.h"
17 #include "stg/noncopyable.h"
18 #include "stg/logger.h"
33 typedef bool (SMUX::*SMUXPacketHandler)(const SMUX_PDUs_t * pdus);
34 typedef bool (SMUX::*PDUsHandler)(const PDUs_t * pdus);
35 typedef std::map<SMUX_PDUs_PR, SMUXPacketHandler> SMUXHandlers;
36 typedef std::map<PDUs_PR, PDUsHandler> PDUsHandlers;
37 //-----------------------------------------------------------------------------
41 virtual ~SMUX_SETTINGS() {}
42 const std::string & GetStrError() const { return errorStr; }
43 int ParseSettings(const MODULE_SETTINGS & s);
45 uint32_t GetIP() const { return ip; }
46 uint16_t GetPort() const { return port; }
47 const std::string GetPassword() const { return password; }
50 mutable std::string errorStr;
56 //-----------------------------------------------------------------------------
57 class CHG_AFTER_NOTIFIER : public PROPERTY_NOTIFIER_BASE<std::string> {
59 CHG_AFTER_NOTIFIER(SMUX & s, const USER_PTR & u)
60 : PROPERTY_NOTIFIER_BASE<std::string>(),
61 smux(s), userPtr(u) {}
62 CHG_AFTER_NOTIFIER(const CHG_AFTER_NOTIFIER & rvalue)
63 : PROPERTY_NOTIFIER_BASE<std::string>(),
64 smux(rvalue.smux), userPtr(rvalue.userPtr) {}
65 void Notify(const std::string &, const std::string &);
67 USER_PTR GetUserPtr() const { return userPtr; }
70 CHG_AFTER_NOTIFIER & operator=(const CHG_AFTER_NOTIFIER & rvalue);
74 //-----------------------------------------------------------------------------
75 class ADD_DEL_TARIFF_NOTIFIER : public NOTIFIER_BASE<TARIFF_DATA>, private NONCOPYABLE {
77 ADD_DEL_TARIFF_NOTIFIER(SMUX & s)
78 : NOTIFIER_BASE<TARIFF_DATA>(), smux(s) {}
79 void Notify(const TARIFF_DATA &);
84 //-----------------------------------------------------------------------------
85 class ADD_USER_NOTIFIER : public NOTIFIER_BASE<USER_PTR>, private NONCOPYABLE {
87 ADD_USER_NOTIFIER(SMUX & s) : NOTIFIER_BASE<USER_PTR>(), smux(s) {}
88 void Notify(const USER_PTR &);
93 //-----------------------------------------------------------------------------
94 class DEL_USER_NOTIFIER : public NOTIFIER_BASE<USER_PTR>, private NONCOPYABLE {
96 DEL_USER_NOTIFIER(SMUX & s) : NOTIFIER_BASE<USER_PTR>(), smux(s) {}
97 void Notify(const USER_PTR &);
102 //-----------------------------------------------------------------------------
103 class SMUX : public PLUGIN {
108 void SetUsers(USERS * u) { users = u; }
109 void SetTariffs(TARIFFS * t) { tariffs = t; }
110 void SetAdmins(ADMINS * a) { admins = a; }
111 void SetServices(SERVICES * s) { services = s; }
112 void SetTraffcounter(TRAFFCOUNTER * tc) { traffcounter = tc; }
113 void SetCorporations(CORPORATIONS * c) { corporations = c; }
114 void SetSettings(const MODULE_SETTINGS & s) { settings = s; }
120 bool IsRunning() { return running && !stopped; }
122 const std::string & GetStrError() const { return errorStr; }
123 const std::string GetVersion() const { return "Stg SMUX Plugin 1.1"; }
124 uint16_t GetStartPosition() const { return 10; }
125 uint16_t GetStopPosition() const { return 10; }
129 void SetNotifier(USER_PTR userPtr);
130 void UnsetNotifier(USER_PTR userPtr);
133 SMUX(const SMUX & rvalue);
134 SMUX & operator=(const SMUX & rvalue);
136 static void * Runner(void * d);
141 bool DispatchPDUs(const SMUX_PDUs_t * pdus);
143 bool CloseHandler(const SMUX_PDUs_t * pdus);
144 bool RegisterResponseHandler(const SMUX_PDUs_t * pdus);
145 bool PDUsRequestHandler(const SMUX_PDUs_t * pdus);
146 bool CommitOrRollbackHandler(const SMUX_PDUs_t * pdus);
148 bool GetRequestHandler(const PDUs_t * pdus);
149 bool GetNextRequestHandler(const PDUs_t * pdus);
150 bool SetRequestHandler(const PDUs_t * pdus);
153 void ResetNotifiers();
159 CORPORATIONS * corporations;
160 TRAFFCOUNTER * traffcounter;
162 mutable std::string errorStr;
163 SMUX_SETTINGS smuxSettings;
164 MODULE_SETTINGS settings;
167 pthread_mutex_t mutex;
172 time_t lastReconnectTry;
173 unsigned reconnectTimeout;
177 SMUXHandlers smuxHandlers;
178 PDUsHandlers pdusHandlers;
182 std::list<CHG_AFTER_NOTIFIER> notifiers;
183 ADD_USER_NOTIFIER addUserNotifier;
184 DEL_USER_NOTIFIER delUserNotifier;
185 ADD_DEL_TARIFF_NOTIFIER addDelTariffNotifier;
187 PLUGIN_LOGGER logger;
189 //-----------------------------------------------------------------------------
192 void CHG_AFTER_NOTIFIER::Notify(const std::string &, const std::string &)
198 void ADD_DEL_TARIFF_NOTIFIER::Notify(const TARIFF_DATA &)
204 void ADD_USER_NOTIFIER::Notify(const USER_PTR & userPtr)
206 smux.SetNotifier(userPtr);
211 void DEL_USER_NOTIFIER::Notify(const USER_PTR & userPtr)
213 smux.UnsetNotifier(userPtr);