5 #include "stg/plugin_creator.h"
7 #include "../../../tariff2.h"
8 #include "../../../admins.h"
9 #include "../../../users.h"
11 //-----------------------------------------------------------------------------
12 //-----------------------------------------------------------------------------
13 //-----------------------------------------------------------------------------
14 PLUGIN_CREATOR<XR_CONFIG> xrc;
15 //-----------------------------------------------------------------------------
16 //-----------------------------------------------------------------------------
17 //-----------------------------------------------------------------------------
18 BASE_PLUGIN * GetPlugin()
20 return xrc.GetPlugin();
22 //-----------------------------------------------------------------------------
23 //-----------------------------------------------------------------------------
24 //-----------------------------------------------------------------------------
25 XR_CONFIG_SETTINGS::XR_CONFIG_SETTINGS()
29 //-----------------------------------------------------------------------------
30 const string & XR_CONFIG_SETTINGS::GetStrError() const
34 //-----------------------------------------------------------------------------
35 int XR_CONFIG_SETTINGS::ParseSettings(const MODULE_SETTINGS & s)
40 //-----------------------------------------------------------------------------
41 uint16_t XR_CONFIG_SETTINGS::GetPort()
45 //-----------------------------------------------------------------------------
46 //-----------------------------------------------------------------------------
47 //-----------------------------------------------------------------------------
48 const string XR_CONFIG::GetVersion() const
50 return "XR_configurator v.0.01";
52 //-----------------------------------------------------------------------------
53 XR_CONFIG::XR_CONFIG()
58 //-----------------------------------------------------------------------------
59 void XR_CONFIG::SetUsers(USERS * u)
63 //-----------------------------------------------------------------------------
64 void XR_CONFIG::SetTariffs(TARIFFS * t)
68 //-----------------------------------------------------------------------------
69 void XR_CONFIG::SetAdmins(ADMINS * a)
73 //-----------------------------------------------------------------------------
74 void XR_CONFIG::SetStore(BASE_STORE * s)
78 //-----------------------------------------------------------------------------
79 void XR_CONFIG::SetStgSettings(const SETTINGS * s)
83 //-----------------------------------------------------------------------------
84 void XR_CONFIG::SetSettings(const MODULE_SETTINGS & s)
88 //-----------------------------------------------------------------------------
89 int XR_CONFIG::ParseSettings()
91 int ret = xrConfigSettings.ParseSettings(settings);
93 errorStr = xrConfigSettings.GetStrError();
96 //-----------------------------------------------------------------------------
97 const string & XR_CONFIG::GetStrError() const
101 //-----------------------------------------------------------------------------
102 int XR_CONFIG::Start()
109 config.SetPort(xrConfigSettings.GetPort());
110 config.SetAdmins(admins);
111 config.SetUsers(users);
112 config.SetTariffs(tariffs);
113 config.SetStgSettings(stgSettings);
114 config.SetStore(store);
116 if (config.Prepare())
118 errorStr = config.GetStrError();
122 if (pthread_create(&thread, NULL, Run, this))
124 errorStr = "Cannot create thread.";
125 printfd(__FILE__, "Cannot create thread\n");
131 //-----------------------------------------------------------------------------
132 int XR_CONFIG::Stop()
139 //5 seconds to thread stops itself
141 for (i = 0; i < 25; i++)
149 //after 5 seconds waiting thread still running. now killing it
152 //TODO pthread_cancel()
153 if (pthread_kill(thread, SIGINT))
155 errorStr = "Cannot kill thread.";
156 printfd(__FILE__, "Cannot kill thread\n");
159 printfd(__FILE__, "XR_CONFIG killed\n");
164 //-----------------------------------------------------------------------------
165 bool XR_CONFIG::IsRunning()
169 //-----------------------------------------------------------------------------
170 void * XR_CONFIG::Run(void * d)
172 XR_CONFIG * stgConf = (XR_CONFIG *)d;
173 stgConf->isRunning = true;
175 stgConf->config.Run(&stgConf->config);
177 stgConf->isRunning = false;
180 //-----------------------------------------------------------------------------
181 uint16_t XR_CONFIG::GetStartPosition() const
185 //-----------------------------------------------------------------------------
186 uint16_t XR_CONFIG::GetStopPosition() const
190 //-----------------------------------------------------------------------------
191 int XR_CONFIG::SetUserCash(const string & admLogin, const string & usrLogin, double cash) const
195 //-----------------------------------------------------------------------------