6 #include "../../../tariffs.h"
7 #include "../../../admins.h"
8 #include "../../../users.h"
10 class STGCONFIG_CREATOR
13 STG_CONFIG * stgconfig;
17 : stgconfig(new STG_CONFIG())
25 STG_CONFIG * GetPlugin()
30 //-----------------------------------------------------------------------------
31 //-----------------------------------------------------------------------------
32 //-----------------------------------------------------------------------------
33 STGCONFIG_CREATOR stgc;
34 //-----------------------------------------------------------------------------
35 //-----------------------------------------------------------------------------
36 //-----------------------------------------------------------------------------
37 STG_CONFIG_SETTINGS::STG_CONFIG_SETTINGS()
41 //-----------------------------------------------------------------------------
42 const string& STG_CONFIG_SETTINGS::GetStrError() const
46 //-----------------------------------------------------------------------------
47 int STG_CONFIG_SETTINGS::ParseIntInRange(const string & str, int min, int max, int * val)
49 if (str2x(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 STG_CONFIG_SETTINGS::ParseSettings(const MODULE_SETTINGS & s)
66 vector<PARAM_VALUE>::const_iterator pvi;
67 ///////////////////////////
69 pvi = find(s.moduleParams.begin(), s.moduleParams.end(), pv);
70 if (pvi == s.moduleParams.end())
72 errorStr = "Parameter \'Port\' not found.";
73 printfd(__FILE__, "Parameter 'Port' not found\n");
76 if (ParseIntInRange(pvi->value[0], 2, 65535, &p))
78 errorStr = "Cannot parse parameter \'Port\': " + errorStr;
79 printfd(__FILE__, "%s\n", errorStr.c_str());
86 //-----------------------------------------------------------------------------
87 uint16_t STG_CONFIG_SETTINGS::GetPort() const
91 //-----------------------------------------------------------------------------
92 //-----------------------------------------------------------------------------
93 //-----------------------------------------------------------------------------
94 BASE_PLUGIN * GetPlugin()
96 return stgc.GetPlugin();
98 //-----------------------------------------------------------------------------
99 //-----------------------------------------------------------------------------
100 //-----------------------------------------------------------------------------
101 const string STG_CONFIG::GetVersion() const
103 return "Stg configurator v.0.08";
105 //-----------------------------------------------------------------------------
106 STG_CONFIG::STG_CONFIG()
116 //-----------------------------------------------------------------------------
117 void STG_CONFIG::SetUsers(USERS * u)
121 //-----------------------------------------------------------------------------
122 void STG_CONFIG::SetTariffs(TARIFFS * t)
126 //-----------------------------------------------------------------------------
127 void STG_CONFIG::SetAdmins(ADMINS * a)
131 //-----------------------------------------------------------------------------
132 void STG_CONFIG::SetStore(BASE_STORE * s)
136 //-----------------------------------------------------------------------------
137 void STG_CONFIG::SetStgSettings(const SETTINGS * s)
141 //-----------------------------------------------------------------------------
142 void STG_CONFIG::SetSettings(const MODULE_SETTINGS & s)
146 //-----------------------------------------------------------------------------
147 int STG_CONFIG::ParseSettings()
149 int ret = stgConfigSettings.ParseSettings(settings);
151 errorStr = stgConfigSettings.GetStrError();
154 //-----------------------------------------------------------------------------
155 const string & STG_CONFIG::GetStrError() const
159 //-----------------------------------------------------------------------------
160 int STG_CONFIG::Start()
167 config.SetPort(stgConfigSettings.GetPort());
168 config.SetAdmins(admins);
169 config.SetUsers(users);
170 config.SetTariffs(tariffs);
171 config.SetStgSettings(stgSettings);
172 config.SetStore(store);
174 if (config.Prepare())
176 errorStr = config.GetStrError();
180 if (pthread_create(&thread, NULL, Run, this))
182 errorStr = "Cannot create thread.";
183 printfd(__FILE__, "Cannot create thread\n");
189 //-----------------------------------------------------------------------------
190 int STG_CONFIG::Stop()
197 //5 seconds to thread stops itself
199 for (i = 0; i < 25; i++)
207 //after 5 seconds waiting thread still running. now killing it
210 //TODO pthread_cancel()
211 if (pthread_kill(thread, SIGINT))
213 errorStr = "Cannot kill thread.";
214 printfd(__FILE__, "Cannot kill thread\n");
217 printfd(__FILE__, "STG_CONFIG killed\n");
222 //-----------------------------------------------------------------------------
223 bool STG_CONFIG::IsRunning()
227 //-----------------------------------------------------------------------------
228 void * STG_CONFIG::Run(void * d)
230 STG_CONFIG * stgConf = (STG_CONFIG *)d;
231 stgConf->isRunning = true;
233 stgConf->config.Run(&stgConf->config);
235 stgConf->isRunning = false;
238 //-----------------------------------------------------------------------------
239 uint16_t STG_CONFIG::GetStartPosition() const
243 //-----------------------------------------------------------------------------
244 uint16_t STG_CONFIG::GetStopPosition() const
248 //-----------------------------------------------------------------------------