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"
23 extern "C" PLUGIN * GetPlugin();
34 typedef bool (SMUX::*SMUXPacketHandler)(const SMUX_PDUs_t * pdus);
35 typedef bool (SMUX::*PDUsHandler)(const PDUs_t * pdus);
36 typedef std::map<SMUX_PDUs_PR, SMUXPacketHandler> SMUXHandlers;
37 typedef std::map<PDUs_PR, PDUsHandler> PDUsHandlers;
38 //-----------------------------------------------------------------------------
42 virtual ~SMUX_SETTINGS() {}
43 const std::string & GetStrError() const { return errorStr; }
44 int ParseSettings(const MODULE_SETTINGS & s);
46 uint32_t GetIP() const { return ip; }
47 uint16_t GetPort() const { return port; }
48 const std::string GetPassword() const { return password; }
51 mutable std::string errorStr;
57 //-----------------------------------------------------------------------------
58 class CHG_AFTER_NOTIFIER : public PROPERTY_NOTIFIER_BASE<std::string> {
60 CHG_AFTER_NOTIFIER(SMUX & s, const USER_PTR & u)
61 : PROPERTY_NOTIFIER_BASE<std::string>(),
62 smux(s), userPtr(u) {}
63 CHG_AFTER_NOTIFIER(const CHG_AFTER_NOTIFIER & rvalue)
64 : PROPERTY_NOTIFIER_BASE<std::string>(),
65 smux(rvalue.smux), userPtr(rvalue.userPtr) {}
66 void Notify(const std::string &, const std::string &);
68 USER_PTR GetUserPtr() const { return userPtr; }
71 CHG_AFTER_NOTIFIER & operator=(const CHG_AFTER_NOTIFIER & rvalue);
75 //-----------------------------------------------------------------------------
76 class ADD_DEL_TARIFF_NOTIFIER : public NOTIFIER_BASE<TARIFF_DATA>, private NONCOPYABLE {
78 ADD_DEL_TARIFF_NOTIFIER(SMUX & s)
79 : NOTIFIER_BASE<TARIFF_DATA>(), smux(s) {}
80 void Notify(const TARIFF_DATA &);
85 //-----------------------------------------------------------------------------
86 class ADD_USER_NOTIFIER : public NOTIFIER_BASE<USER_PTR>, private NONCOPYABLE {
88 ADD_USER_NOTIFIER(SMUX & s) : NOTIFIER_BASE<USER_PTR>(), smux(s) {}
89 void Notify(const USER_PTR &);
94 //-----------------------------------------------------------------------------
95 class DEL_USER_NOTIFIER : public NOTIFIER_BASE<USER_PTR>, private NONCOPYABLE {
97 DEL_USER_NOTIFIER(SMUX & s) : NOTIFIER_BASE<USER_PTR>(), smux(s) {}
98 void Notify(const USER_PTR &);
103 //-----------------------------------------------------------------------------
104 class SMUX : public PLUGIN {
109 void SetUsers(USERS * u) { users = u; }
110 void SetTariffs(TARIFFS * t) { tariffs = t; }
111 void SetAdmins(ADMINS * a) { admins = a; }
112 void SetServices(SERVICES * s) { services = s; }
113 void SetTraffcounter(TRAFFCOUNTER * tc) { traffcounter = tc; }
114 void SetCorporations(CORPORATIONS * c) { corporations = c; }
115 void SetSettings(const MODULE_SETTINGS & s) { settings = s; }
121 bool IsRunning() { return running && !stopped; }
123 const std::string & GetStrError() const { return errorStr; }
124 const std::string GetVersion() const { return "Stg SMUX Plugin 1.1"; }
125 uint16_t GetStartPosition() const { return 10; }
126 uint16_t GetStopPosition() const { return 10; }
130 void SetNotifier(USER_PTR userPtr);
131 void UnsetNotifier(USER_PTR userPtr);
134 SMUX(const SMUX & rvalue);
135 SMUX & operator=(const SMUX & rvalue);
137 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;
173 SMUXHandlers smuxHandlers;
174 PDUsHandlers pdusHandlers;
178 std::list<CHG_AFTER_NOTIFIER> notifiers;
179 ADD_USER_NOTIFIER addUserNotifier;
180 DEL_USER_NOTIFIER delUserNotifier;
181 ADD_DEL_TARIFF_NOTIFIER addDelTariffNotifier;
183 //-----------------------------------------------------------------------------
186 void CHG_AFTER_NOTIFIER::Notify(const std::string &, const std::string &)
192 void ADD_DEL_TARIFF_NOTIFIER::Notify(const TARIFF_DATA &)
198 void ADD_USER_NOTIFIER::Notify(const USER_PTR & userPtr)
200 smux.SetNotifier(userPtr);
205 void DEL_USER_NOTIFIER::Notify(const USER_PTR & userPtr)
207 smux.UnsetNotifier(userPtr);
211 extern "C" PLUGIN * GetPlugin();