6 #include "../../../tariff2.h"
7 #include "../../../admins.h"
8 #include "../../../users.h"
10 class XR_CONFIG_CREATOR
17 : xrconfig(new XR_CONFIG())
25 XR_CONFIG * GetPlugin()
30 //-----------------------------------------------------------------------------
31 //-----------------------------------------------------------------------------
32 //-----------------------------------------------------------------------------
34 //-----------------------------------------------------------------------------
35 //-----------------------------------------------------------------------------
36 //-----------------------------------------------------------------------------
37 XR_CONFIG_SETTINGS::XR_CONFIG_SETTINGS()
41 //-----------------------------------------------------------------------------
42 const string & XR_CONFIG_SETTINGS::GetStrError() const
46 //-----------------------------------------------------------------------------
47 int XR_CONFIG_SETTINGS::ParseSettings(const MODULE_SETTINGS & s)
52 //-----------------------------------------------------------------------------
53 uint16_t XR_CONFIG_SETTINGS::GetPort()
57 //-----------------------------------------------------------------------------
58 //-----------------------------------------------------------------------------
59 //-----------------------------------------------------------------------------
60 BASE_PLUGIN * GetPlugin()
62 return xrc.GetPlugin();
64 //-----------------------------------------------------------------------------
65 //-----------------------------------------------------------------------------
66 //-----------------------------------------------------------------------------
67 const string XR_CONFIG::GetVersion() const
69 return "XR_configurator v.0.01";
71 //-----------------------------------------------------------------------------
72 XR_CONFIG::XR_CONFIG()
77 //-----------------------------------------------------------------------------
78 void XR_CONFIG::SetUsers(USERS * u)
82 //-----------------------------------------------------------------------------
83 void XR_CONFIG::SetTariffs(TARIFFS * t)
87 //-----------------------------------------------------------------------------
88 void XR_CONFIG::SetAdmins(ADMINS * a)
92 //-----------------------------------------------------------------------------
93 void XR_CONFIG::SetStore(BASE_STORE * s)
97 //-----------------------------------------------------------------------------
98 void XR_CONFIG::SetStgSettings(const SETTINGS * s)
102 //-----------------------------------------------------------------------------
103 void XR_CONFIG::SetSettings(const MODULE_SETTINGS & s)
107 //-----------------------------------------------------------------------------
108 int XR_CONFIG::ParseSettings()
110 int ret = xrConfigSettings.ParseSettings(settings);
112 errorStr = xrConfigSettings.GetStrError();
115 //-----------------------------------------------------------------------------
116 const string & XR_CONFIG::GetStrError() const
120 //-----------------------------------------------------------------------------
121 int XR_CONFIG::Start()
128 config.SetPort(xrConfigSettings.GetPort());
129 config.SetAdmins(admins);
130 config.SetUsers(users);
131 config.SetTariffs(tariffs);
132 config.SetStgSettings(stgSettings);
133 config.SetStore(store);
135 if (config.Prepare())
137 errorStr = config.GetStrError();
141 if (pthread_create(&thread, NULL, Run, this))
143 errorStr = "Cannot create thread.";
144 printfd(__FILE__, "Cannot create thread\n");
150 //-----------------------------------------------------------------------------
151 int XR_CONFIG::Stop()
158 //5 seconds to thread stops itself
160 for (i = 0; i < 25; i++)
168 //after 5 seconds waiting thread still running. now killing it
171 //TODO pthread_cancel()
172 if (pthread_kill(thread, SIGINT))
174 errorStr = "Cannot kill thread.";
175 printfd(__FILE__, "Cannot kill thread\n");
178 printfd(__FILE__, "XR_CONFIG killed\n");
183 //-----------------------------------------------------------------------------
184 bool XR_CONFIG::IsRunning()
188 //-----------------------------------------------------------------------------
189 void * XR_CONFIG::Run(void * d)
191 XR_CONFIG * stgConf = (XR_CONFIG *)d;
192 stgConf->isRunning = true;
194 stgConf->config.Run(&stgConf->config);
196 stgConf->isRunning = false;
199 //-----------------------------------------------------------------------------
200 uint16_t XR_CONFIG::GetStartPosition() const
204 //-----------------------------------------------------------------------------
205 uint16_t XR_CONFIG::GetStopPosition() const
209 //-----------------------------------------------------------------------------
210 int XR_CONFIG::SetUserCash(const string & admLogin, const string & usrLogin, double cash) const
214 //-----------------------------------------------------------------------------