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"
24 extern "C" PLUGIN * GetPlugin();
35 typedef bool (SMUX::*SMUXPacketHandler)(const SMUX_PDUs_t * pdus);
36 typedef bool (SMUX::*PDUsHandler)(const PDUs_t * pdus);
37 typedef std::map<SMUX_PDUs_PR, SMUXPacketHandler> SMUXHandlers;
38 typedef std::map<PDUs_PR, PDUsHandler> PDUsHandlers;
39 //-----------------------------------------------------------------------------
43 virtual ~SMUX_SETTINGS() {}
44 const std::string & GetStrError() const { return errorStr; }
45 int ParseSettings(const MODULE_SETTINGS & s);
47 uint32_t GetIP() const { return ip; }
48 uint16_t GetPort() const { return port; }
49 const std::string GetPassword() const { return password; }
52 mutable std::string errorStr;
58 //-----------------------------------------------------------------------------
59 class CHG_AFTER_NOTIFIER : public PROPERTY_NOTIFIER_BASE<std::string> {
61 CHG_AFTER_NOTIFIER(SMUX & s, const USER_PTR & u)
62 : PROPERTY_NOTIFIER_BASE<std::string>(),
63 smux(s), userPtr(u) {}
64 CHG_AFTER_NOTIFIER(const CHG_AFTER_NOTIFIER & rvalue)
65 : PROPERTY_NOTIFIER_BASE<std::string>(),
66 smux(rvalue.smux), userPtr(rvalue.userPtr) {}
67 void Notify(const std::string &, const std::string &);
69 USER_PTR GetUserPtr() const { return userPtr; }
72 CHG_AFTER_NOTIFIER & operator=(const CHG_AFTER_NOTIFIER & rvalue);
76 //-----------------------------------------------------------------------------
77 class ADD_DEL_TARIFF_NOTIFIER : public NOTIFIER_BASE<TARIFF_DATA>, private NONCOPYABLE {
79 ADD_DEL_TARIFF_NOTIFIER(SMUX & s)
80 : NOTIFIER_BASE<TARIFF_DATA>(), smux(s) {}
81 void Notify(const TARIFF_DATA &);
86 //-----------------------------------------------------------------------------
87 class ADD_USER_NOTIFIER : public NOTIFIER_BASE<USER_PTR>, private NONCOPYABLE {
89 ADD_USER_NOTIFIER(SMUX & s) : NOTIFIER_BASE<USER_PTR>(), smux(s) {}
90 void Notify(const USER_PTR &);
95 //-----------------------------------------------------------------------------
96 class DEL_USER_NOTIFIER : public NOTIFIER_BASE<USER_PTR>, private NONCOPYABLE {
98 DEL_USER_NOTIFIER(SMUX & s) : NOTIFIER_BASE<USER_PTR>(), smux(s) {}
99 void Notify(const USER_PTR &);
104 //-----------------------------------------------------------------------------
105 class SMUX : public PLUGIN {
110 void SetUsers(USERS * u) { users = u; }
111 void SetTariffs(TARIFFS * t) { tariffs = t; }
112 void SetAdmins(ADMINS * a) { admins = a; }
113 void SetServices(SERVICES * s) { services = s; }
114 void SetTraffcounter(TRAFFCOUNTER * tc) { traffcounter = tc; }
115 void SetCorporations(CORPORATIONS * c) { corporations = c; }
116 void SetSettings(const MODULE_SETTINGS & s) { settings = s; }
122 bool IsRunning() { return running && !stopped; }
124 const std::string & GetStrError() const { return errorStr; }
125 const std::string GetVersion() const { return "Stg SMUX Plugin 1.1"; }
126 uint16_t GetStartPosition() const { return 10; }
127 uint16_t GetStopPosition() const { return 10; }
131 void SetNotifier(USER_PTR userPtr);
132 void UnsetNotifier(USER_PTR userPtr);
135 SMUX(const SMUX & rvalue);
136 SMUX & operator=(const SMUX & rvalue);
138 static void * Runner(void * d);
142 bool DispatchPDUs(const SMUX_PDUs_t * pdus);
144 bool CloseHandler(const SMUX_PDUs_t * pdus);
145 bool RegisterResponseHandler(const SMUX_PDUs_t * pdus);
146 bool PDUsRequestHandler(const SMUX_PDUs_t * pdus);
147 bool CommitOrRollbackHandler(const SMUX_PDUs_t * pdus);
149 bool GetRequestHandler(const PDUs_t * pdus);
150 bool GetNextRequestHandler(const PDUs_t * pdus);
151 bool SetRequestHandler(const PDUs_t * pdus);
154 void ResetNotifiers();
160 CORPORATIONS * corporations;
161 TRAFFCOUNTER * traffcounter;
163 mutable std::string errorStr;
164 SMUX_SETTINGS smuxSettings;
165 MODULE_SETTINGS settings;
168 pthread_mutex_t mutex;
174 SMUXHandlers smuxHandlers;
175 PDUsHandlers pdusHandlers;
179 std::list<CHG_AFTER_NOTIFIER> notifiers;
180 ADD_USER_NOTIFIER addUserNotifier;
181 DEL_USER_NOTIFIER delUserNotifier;
182 ADD_DEL_TARIFF_NOTIFIER addDelTariffNotifier;
184 PLUGIN_LOGGER logger;
186 //-----------------------------------------------------------------------------
189 void CHG_AFTER_NOTIFIER::Notify(const std::string &, const std::string &)
195 void ADD_DEL_TARIFF_NOTIFIER::Notify(const TARIFF_DATA &)
201 void ADD_USER_NOTIFIER::Notify(const USER_PTR & userPtr)
203 smux.SetNotifier(userPtr);
208 void DEL_USER_NOTIFIER::Notify(const USER_PTR & userPtr)
210 smux.UnsetNotifier(userPtr);
214 extern "C" PLUGIN * GetPlugin();