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()
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()
111 //-----------------------------------------------------------------------------
112 void STG_CONFIG::SetUsers(USERS * u)
116 //-----------------------------------------------------------------------------
117 void STG_CONFIG::SetTariffs(TARIFFS * t)
121 //-----------------------------------------------------------------------------
122 void STG_CONFIG::SetAdmins(ADMINS * a)
126 //-----------------------------------------------------------------------------
127 void STG_CONFIG::SetStore(BASE_STORE * s)
131 //-----------------------------------------------------------------------------
132 void STG_CONFIG::SetStgSettings(const SETTINGS * s)
136 //-----------------------------------------------------------------------------
137 void STG_CONFIG::SetSettings(const MODULE_SETTINGS & s)
141 //-----------------------------------------------------------------------------
142 int STG_CONFIG::ParseSettings()
144 int ret = stgConfigSettings.ParseSettings(settings);
146 errorStr = stgConfigSettings.GetStrError();
149 //-----------------------------------------------------------------------------
150 const string & STG_CONFIG::GetStrError() const
154 //-----------------------------------------------------------------------------
155 int STG_CONFIG::Start()
162 config.SetPort(stgConfigSettings.GetPort());
163 config.SetAdmins(admins);
164 config.SetUsers(users);
165 config.SetTariffs(tariffs);
166 config.SetStgSettings(stgSettings);
167 config.SetStore(store);
169 if (config.Prepare())
171 errorStr = config.GetStrError();
175 if (pthread_create(&thread, NULL, Run, this))
177 errorStr = "Cannot create thread.";
178 printfd(__FILE__, "Cannot create thread\n");
184 //-----------------------------------------------------------------------------
185 int STG_CONFIG::Stop()
192 //5 seconds to thread stops itself
194 for (i = 0; i < 25; i++)
202 //after 5 seconds waiting thread still running. now killing it
205 //TODO pthread_cancel()
206 if (pthread_kill(thread, SIGINT))
208 errorStr = "Cannot kill thread.";
209 printfd(__FILE__, "Cannot kill thread\n");
212 printfd(__FILE__, "STG_CONFIG killed\n");
217 //-----------------------------------------------------------------------------
218 bool STG_CONFIG::IsRunning()
222 //-----------------------------------------------------------------------------
223 void * STG_CONFIG::Run(void * d)
225 STG_CONFIG * stgConf = (STG_CONFIG *)d;
226 stgConf->isRunning = true;
228 stgConf->config.Run(&stgConf->config);
230 stgConf->isRunning = false;
233 //-----------------------------------------------------------------------------
234 uint16_t STG_CONFIG::GetStartPosition() const
238 //-----------------------------------------------------------------------------
239 uint16_t STG_CONFIG::GetStopPosition() const
243 //-----------------------------------------------------------------------------