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::ParseIntInRange(const string & str, int min, int max, int * val)
49 if (strtoi2(str.c_str(), *val))
51 errorStr = "Incorrect value \'" + str + "\'.";
54 if (*val < min || *val > max)
56 errorStr = "Value \'" + str + "\' out of range.";
61 //-----------------------------------------------------------------------------
62 int XR_CONFIG_SETTINGS::ParseSettings(const MODULE_SETTINGS & s)
66 vector<PARAM_VALUE>::const_iterator pvi;
69 pvi = find(s.moduleParams.begin(), s.moduleParams.end(), pv);
70 if (pvi == s.moduleParams.end())
72 errorStr = "Parameter \'Port\' not found.";
76 if (ParseIntInRange(pvi->value[0], 2, 65535, &p))
78 errorStr = "Cannot parse parameter \'Port\': " + errorStr;
85 //-----------------------------------------------------------------------------
86 uint16_t XR_CONFIG_SETTINGS::GetPort()
90 //-----------------------------------------------------------------------------
91 //-----------------------------------------------------------------------------
92 //-----------------------------------------------------------------------------
93 BASE_PLUGIN * GetPlugin()
95 return xrc.GetPlugin();
97 //-----------------------------------------------------------------------------
98 //-----------------------------------------------------------------------------
99 //-----------------------------------------------------------------------------
100 const string XR_CONFIG::GetVersion() const
102 return "XR_configurator v.0.01";
104 //-----------------------------------------------------------------------------
105 XR_CONFIG::XR_CONFIG()
110 //-----------------------------------------------------------------------------
111 void XR_CONFIG::SetUsers(USERS * u)
115 //-----------------------------------------------------------------------------
116 void XR_CONFIG::SetTariffs(TARIFFS * t)
120 //-----------------------------------------------------------------------------
121 void XR_CONFIG::SetAdmins(ADMINS * a)
125 //-----------------------------------------------------------------------------
126 void XR_CONFIG::SetStore(BASE_STORE * s)
130 //-----------------------------------------------------------------------------
131 void XR_CONFIG::SetStgSettings(const SETTINGS * s)
135 //-----------------------------------------------------------------------------
136 void XR_CONFIG::SetSettings(const MODULE_SETTINGS & s)
140 //-----------------------------------------------------------------------------
141 int XR_CONFIG::ParseSettings()
143 int ret = xrConfigSettings.ParseSettings(settings);
145 errorStr = xrConfigSettings.GetStrError();
148 //-----------------------------------------------------------------------------
149 const string & XR_CONFIG::GetStrError() const
153 //-----------------------------------------------------------------------------
154 int XR_CONFIG::Start()
161 config.SetPort(xrConfigSettings.GetPort());
162 config.SetAdmins(admins);
163 config.SetUsers(users);
164 config.SetTariffs(tariffs);
165 config.SetStgSettings(stgSettings);
166 config.SetStore(store);
168 if (config.Prepare())
170 errorStr = config.GetStrError();
174 if (pthread_create(&thread, NULL, Run, this))
176 errorStr = "Cannot create thread.";
177 printfd(__FILE__, "Cannot create thread\n");
183 //-----------------------------------------------------------------------------
184 int XR_CONFIG::Stop()
191 //5 seconds to thread stops itself
193 for (i = 0; i < 25; i++)
201 //after 5 seconds waiting thread still running. now killing it
204 //TODO pthread_cancel()
205 if (pthread_kill(thread, SIGINT))
207 errorStr = "Cannot kill thread.";
208 printfd(__FILE__, "Cannot kill thread\n");
211 printfd(__FILE__, "XR_CONFIG killed\n");
216 //-----------------------------------------------------------------------------
217 bool XR_CONFIG::IsRunning()
221 //-----------------------------------------------------------------------------
222 void * XR_CONFIG::Run(void * d)
224 XR_CONFIG * stgConf = (XR_CONFIG *)d;
225 stgConf->isRunning = true;
227 stgConf->config.Run(&stgConf->config);
229 stgConf->isRunning = false;
232 //-----------------------------------------------------------------------------
233 uint16_t XR_CONFIG::GetStartPosition() const
237 //-----------------------------------------------------------------------------
238 uint16_t XR_CONFIG::GetStopPosition() const
242 //-----------------------------------------------------------------------------
243 int XR_CONFIG::SetUserCash(const string & admLogin, const string & usrLogin, double cash) const
247 //-----------------------------------------------------------------------------