7 #include "stg/tariffs.h"
8 #include "stg/admins.h"
10 #include "stgconfig.h"
12 class STGCONFIG_CREATOR
15 STG_CONFIG * stgconfig;
19 : stgconfig(new STG_CONFIG())
27 STG_CONFIG * GetPlugin()
32 //-----------------------------------------------------------------------------
33 //-----------------------------------------------------------------------------
34 //-----------------------------------------------------------------------------
35 STGCONFIG_CREATOR stgc;
36 //-----------------------------------------------------------------------------
37 //-----------------------------------------------------------------------------
38 //-----------------------------------------------------------------------------
39 STG_CONFIG_SETTINGS::STG_CONFIG_SETTINGS()
43 //-----------------------------------------------------------------------------
44 const std::string & STG_CONFIG_SETTINGS::GetStrError() const
48 //-----------------------------------------------------------------------------
49 int STG_CONFIG_SETTINGS::ParseSettings(const MODULE_SETTINGS & s)
53 vector<PARAM_VALUE>::const_iterator pvi;
54 ///////////////////////////
56 pvi = std::find(s.moduleParams.begin(), s.moduleParams.end(), pv);
57 if (pvi == s.moduleParams.end())
59 errorStr = "Parameter \'Port\' not found.";
60 printfd(__FILE__, "Parameter 'Port' not found\n");
63 if (ParseIntInRange(pvi->value[0], 2, 65535, &p))
65 errorStr = "Cannot parse parameter \'Port\': " + errorStr;
66 printfd(__FILE__, "%s\n", errorStr.c_str());
73 //-----------------------------------------------------------------------------
74 uint16_t STG_CONFIG_SETTINGS::GetPort() const
78 //-----------------------------------------------------------------------------
79 //-----------------------------------------------------------------------------
80 //-----------------------------------------------------------------------------
83 return stgc.GetPlugin();
85 //-----------------------------------------------------------------------------
86 //-----------------------------------------------------------------------------
87 //-----------------------------------------------------------------------------
88 const std::string STG_CONFIG::GetVersion() const
90 return "Stg configurator v.0.08";
92 //-----------------------------------------------------------------------------
93 STG_CONFIG::STG_CONFIG()
103 //-----------------------------------------------------------------------------
104 void STG_CONFIG::SetUsers(USERS * u)
108 //-----------------------------------------------------------------------------
109 void STG_CONFIG::SetTariffs(TARIFFS * t)
113 //-----------------------------------------------------------------------------
114 void STG_CONFIG::SetAdmins(ADMINS * a)
118 //-----------------------------------------------------------------------------
119 void STG_CONFIG::SetStore(STORE * s)
123 //-----------------------------------------------------------------------------
124 void STG_CONFIG::SetStgSettings(const SETTINGS * s)
128 //-----------------------------------------------------------------------------
129 void STG_CONFIG::SetSettings(const MODULE_SETTINGS & s)
133 //-----------------------------------------------------------------------------
134 int STG_CONFIG::ParseSettings()
136 int ret = stgConfigSettings.ParseSettings(settings);
138 errorStr = stgConfigSettings.GetStrError();
141 //-----------------------------------------------------------------------------
142 const std::string & STG_CONFIG::GetStrError() const
146 //-----------------------------------------------------------------------------
147 int STG_CONFIG::Start()
154 config.SetPort(stgConfigSettings.GetPort());
155 config.SetAdmins(admins);
156 config.SetUsers(users);
157 config.SetTariffs(tariffs);
158 config.SetStgSettings(stgSettings);
159 config.SetStore(store);
161 if (config.Prepare())
163 errorStr = config.GetStrError();
167 if (pthread_create(&thread, NULL, Run, this))
169 errorStr = "Cannot create thread.";
170 printfd(__FILE__, "Cannot create thread\n");
176 //-----------------------------------------------------------------------------
177 int STG_CONFIG::Stop()
184 //5 seconds to thread stops itself
186 for (i = 0; i < 25; i++)
194 //after 5 seconds waiting thread still running. now killing it
197 //TODO pthread_cancel()
198 if (pthread_kill(thread, SIGINT))
200 errorStr = "Cannot kill thread.";
201 printfd(__FILE__, "Cannot kill thread\n");
204 printfd(__FILE__, "STG_CONFIG killed\n");
209 //-----------------------------------------------------------------------------
210 bool STG_CONFIG::IsRunning()
214 //-----------------------------------------------------------------------------
215 void * STG_CONFIG::Run(void * d)
217 STG_CONFIG * stgConf = (STG_CONFIG *)d;
218 stgConf->isRunning = true;
220 stgConf->config.Run(&stgConf->config);
222 stgConf->isRunning = false;
225 //-----------------------------------------------------------------------------
226 uint16_t STG_CONFIG::GetStartPosition() const
230 //-----------------------------------------------------------------------------
231 uint16_t STG_CONFIG::GetStopPosition() const
235 //-----------------------------------------------------------------------------