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"
22 extern "C" PLUGIN * GetPlugin();
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) : smux(s), userPtr(u) {}
60 void Notify(const std::string &, const std::string &);
62 USER_PTR GetUserPtr() { return userPtr; }
68 //-----------------------------------------------------------------------------
69 class ADD_DEL_TARIFF_NOTIFIER : public NOTIFIER_BASE<TARIFF_DATA> {
71 ADD_DEL_TARIFF_NOTIFIER(SMUX & s) : smux(s) {}
72 void Notify(const TARIFF_DATA &);
77 //-----------------------------------------------------------------------------
78 class ADD_USER_NOTIFIER : public NOTIFIER_BASE<USER_PTR> {
80 ADD_USER_NOTIFIER(SMUX & s) : smux(s) {}
81 void Notify(const USER_PTR &);
86 //-----------------------------------------------------------------------------
87 class DEL_USER_NOTIFIER : public NOTIFIER_BASE<USER_PTR> {
89 DEL_USER_NOTIFIER(SMUX & s) : smux(s) {}
90 void Notify(const USER_PTR &);
95 //-----------------------------------------------------------------------------
96 class SMUX : public PLUGIN {
101 void SetUsers(USERS * u) { users = u; }
102 void SetTariffs(TARIFFS * t) { tariffs = t; }
103 void SetAdmins(ADMINS * a) { admins = a; }
104 void SetServices(SERVICES * s) { services = s; }
105 void SetTraffcounter(TRAFFCOUNTER * tc) { traffcounter = tc; }
106 void SetCorporations(CORPORATIONS * c) { corporations = c; }
107 void SetSettings(const MODULE_SETTINGS & s) { settings = s; }
113 bool IsRunning() { return running && !stopped; }
115 const std::string & GetStrError() const { return errorStr; }
116 const std::string GetVersion() const { return "Stg SMUX Plugin 1.1"; }
117 uint16_t GetStartPosition() const { return 100; }
118 uint16_t GetStopPosition() const { return 100; }
122 void SetNotifier(USER_PTR userPtr);
123 void UnsetNotifier(USER_PTR userPtr);
126 static void * Runner(void * d);
130 bool DispatchPDUs(const SMUX_PDUs_t * pdus);
132 bool CloseHandler(const SMUX_PDUs_t * pdus);
133 bool RegisterResponseHandler(const SMUX_PDUs_t * pdus);
134 bool PDUsRequestHandler(const SMUX_PDUs_t * pdus);
135 bool CommitOrRollbackHandler(const SMUX_PDUs_t * pdus);
137 bool GetRequestHandler(const PDUs_t * pdus);
138 bool GetNextRequestHandler(const PDUs_t * pdus);
139 bool SetRequestHandler(const PDUs_t * pdus);
142 void ResetNotifiers();
148 CORPORATIONS * corporations;
149 TRAFFCOUNTER * traffcounter;
151 mutable std::string errorStr;
152 SMUX_SETTINGS smuxSettings;
153 MODULE_SETTINGS settings;
156 pthread_mutex_t mutex;
162 SMUXHandlers smuxHandlers;
163 PDUsHandlers pdusHandlers;
167 std::list<CHG_AFTER_NOTIFIER> notifiers;
168 ADD_USER_NOTIFIER addUserNotifier;
169 DEL_USER_NOTIFIER delUserNotifier;
170 ADD_DEL_TARIFF_NOTIFIER addDelTariffNotifier;
172 //-----------------------------------------------------------------------------
175 void ADD_DEL_TARIFF_NOTIFIER::Notify(const TARIFF_DATA &)
181 void ADD_USER_NOTIFIER::Notify(const USER_PTR & userPtr)
183 smux.SetNotifier(userPtr);
188 void DEL_USER_NOTIFIER::Notify(const USER_PTR & userPtr)
190 smux.UnsetNotifier(userPtr);
194 extern "C" PLUGIN * GetPlugin();