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"
21 extern "C" PLUGIN * GetPlugin();
32 typedef bool (SMUX::*SMUXPacketHandler)(const SMUX_PDUs_t * pdus);
33 typedef bool (SMUX::*PDUsHandler)(const PDUs_t * pdus);
34 typedef std::map<SMUX_PDUs_PR, SMUXPacketHandler> SMUXHandlers;
35 typedef std::map<PDUs_PR, PDUsHandler> PDUsHandlers;
36 //-----------------------------------------------------------------------------
40 virtual ~SMUX_SETTINGS() {}
41 const std::string & GetStrError() const { return errorStr; }
42 int ParseSettings(const MODULE_SETTINGS & s);
44 uint32_t GetIP() const { return ip; }
45 uint16_t GetPort() const { return port; }
46 const std::string GetPassword() const { return password; }
49 mutable std::string errorStr;
55 //-----------------------------------------------------------------------------
56 class CHG_AFTER_NOTIFIER : public PROPERTY_NOTIFIER_BASE<std::string> {
58 CHG_AFTER_NOTIFIER(SMUX & s, const USER_PTR & u) : smux(s), userPtr(u) {}
59 void Notify(const std::string &, const std::string &);
61 USER_PTR GetUserPtr() { return userPtr; }
67 //-----------------------------------------------------------------------------
68 class ADD_DEL_USER_NOTIFIER : public NOTIFIER_BASE<USER_PTR> {
70 ADD_DEL_USER_NOTIFIER(SMUX & s) : smux(s) {}
71 void Notify(const USER_PTR &);
76 //-----------------------------------------------------------------------------
77 class SMUX : public PLUGIN {
82 void SetUsers(USERS * u) { users = u; }
83 void SetTariffs(TARIFFS * t) { tariffs = t; }
84 void SetAdmins(ADMINS * a) { admins = a; }
85 void SetServices(SERVICES * s) { services = s; }
86 void SetTraffcounter(TRAFFCOUNTER * tc) { traffcounter = tc; }
87 void SetCorporations(CORPORATIONS * c) { corporations = c; }
88 void SetSettings(const MODULE_SETTINGS & s) { settings = s; }
93 int Reload() { return 0; }
94 bool IsRunning() { return running && !stopped; }
96 const std::string & GetStrError() const { return errorStr; }
97 const std::string GetVersion() const { return "Stg SMUX Plugin 1.1"; }
98 uint16_t GetStartPosition() const { return 100; }
99 uint16_t GetStopPosition() const { return 100; }
104 static void * Runner(void * d);
108 bool DispatchPDUs(const SMUX_PDUs_t * pdus);
110 bool CloseHandler(const SMUX_PDUs_t * pdus);
111 bool RegisterResponseHandler(const SMUX_PDUs_t * pdus);
112 bool PDUsRequestHandler(const SMUX_PDUs_t * pdus);
113 bool CommitOrRollbackHandler(const SMUX_PDUs_t * pdus);
115 bool GetRequestHandler(const PDUs_t * pdus);
116 bool GetNextRequestHandler(const PDUs_t * pdus);
117 bool SetRequestHandler(const PDUs_t * pdus);
120 void ResetNotifiers();
126 CORPORATIONS * corporations;
127 TRAFFCOUNTER * traffcounter;
129 mutable std::string errorStr;
130 SMUX_SETTINGS smuxSettings;
131 MODULE_SETTINGS settings;
134 pthread_mutex_t mutex;
140 SMUXHandlers smuxHandlers;
141 PDUsHandlers pdusHandlers;
145 std::list<CHG_AFTER_NOTIFIER> notifiers;
146 ADD_DEL_USER_NOTIFIER addDelNotifier;
148 //-----------------------------------------------------------------------------
150 extern "C" PLUGIN * GetPlugin();