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) : smux(s), userPtr(u) {}
61 CHG_AFTER_NOTIFIER(const CHG_AFTER_NOTIFIER & rvalue) : smux(rvalue.smux), userPtr(rvalue.userPtr) {}
62 void Notify(const std::string &, const std::string &);
64 USER_PTR GetUserPtr() { return userPtr; }
67 CHG_AFTER_NOTIFIER & operator=(const CHG_AFTER_NOTIFIER & rvalue);
71 //-----------------------------------------------------------------------------
72 class ADD_DEL_TARIFF_NOTIFIER : public NOTIFIER_BASE<TARIFF_DATA>, private NONCOPYABLE {
74 ADD_DEL_TARIFF_NOTIFIER(SMUX & s) : smux(s) {}
75 void Notify(const TARIFF_DATA &);
80 //-----------------------------------------------------------------------------
81 class ADD_USER_NOTIFIER : public NOTIFIER_BASE<USER_PTR>, private NONCOPYABLE {
83 ADD_USER_NOTIFIER(SMUX & s) : smux(s) {}
84 void Notify(const USER_PTR &);
89 //-----------------------------------------------------------------------------
90 class DEL_USER_NOTIFIER : public NOTIFIER_BASE<USER_PTR>, private NONCOPYABLE {
92 DEL_USER_NOTIFIER(SMUX & s) : smux(s) {}
93 void Notify(const USER_PTR &);
98 //-----------------------------------------------------------------------------
99 class SMUX : public PLUGIN {
104 void SetUsers(USERS * u) { users = u; }
105 void SetTariffs(TARIFFS * t) { tariffs = t; }
106 void SetAdmins(ADMINS * a) { admins = a; }
107 void SetServices(SERVICES * s) { services = s; }
108 void SetTraffcounter(TRAFFCOUNTER * tc) { traffcounter = tc; }
109 void SetCorporations(CORPORATIONS * c) { corporations = c; }
110 void SetSettings(const MODULE_SETTINGS & s) { settings = s; }
116 bool IsRunning() { return running && !stopped; }
118 const std::string & GetStrError() const { return errorStr; }
119 const std::string GetVersion() const { return "Stg SMUX Plugin 1.1"; }
120 uint16_t GetStartPosition() const { return 100; }
121 uint16_t GetStopPosition() const { return 100; }
125 void SetNotifier(USER_PTR userPtr);
126 void UnsetNotifier(USER_PTR userPtr);
129 SMUX(const SMUX & rvalue);
130 SMUX & operator=(const SMUX & rvalue);
132 static void * Runner(void * d);
136 bool DispatchPDUs(const SMUX_PDUs_t * pdus);
138 bool CloseHandler(const SMUX_PDUs_t * pdus);
139 bool RegisterResponseHandler(const SMUX_PDUs_t * pdus);
140 bool PDUsRequestHandler(const SMUX_PDUs_t * pdus);
141 bool CommitOrRollbackHandler(const SMUX_PDUs_t * pdus);
143 bool GetRequestHandler(const PDUs_t * pdus);
144 bool GetNextRequestHandler(const PDUs_t * pdus);
145 bool SetRequestHandler(const PDUs_t * pdus);
148 void ResetNotifiers();
154 CORPORATIONS * corporations;
155 TRAFFCOUNTER * traffcounter;
157 mutable std::string errorStr;
158 SMUX_SETTINGS smuxSettings;
159 MODULE_SETTINGS settings;
162 pthread_mutex_t mutex;
168 SMUXHandlers smuxHandlers;
169 PDUsHandlers pdusHandlers;
173 std::list<CHG_AFTER_NOTIFIER> notifiers;
174 ADD_USER_NOTIFIER addUserNotifier;
175 DEL_USER_NOTIFIER delUserNotifier;
176 ADD_DEL_TARIFF_NOTIFIER addDelTariffNotifier;
178 //-----------------------------------------------------------------------------
181 void ADD_DEL_TARIFF_NOTIFIER::Notify(const TARIFF_DATA &)
187 void ADD_USER_NOTIFIER::Notify(const USER_PTR & userPtr)
189 smux.SetNotifier(userPtr);
194 void DEL_USER_NOTIFIER::Notify(const USER_PTR & userPtr)
196 smux.UnsetNotifier(userPtr);
200 extern "C" PLUGIN * GetPlugin();