7 #include "stg/tariffs.h"
8 #include "stg/admins.h"
10 #include "stg/plugin_creator.h"
11 #include "stgconfig.h"
13 //-----------------------------------------------------------------------------
14 //-----------------------------------------------------------------------------
15 //-----------------------------------------------------------------------------
16 PLUGIN_CREATOR<STG_CONFIG> stgc;
17 //-----------------------------------------------------------------------------
18 //-----------------------------------------------------------------------------
19 //-----------------------------------------------------------------------------
20 STG_CONFIG_SETTINGS::STG_CONFIG_SETTINGS()
24 //-----------------------------------------------------------------------------
25 const std::string & STG_CONFIG_SETTINGS::GetStrError() const
29 //-----------------------------------------------------------------------------
30 int STG_CONFIG_SETTINGS::ParseSettings(const MODULE_SETTINGS & s)
34 vector<PARAM_VALUE>::const_iterator pvi;
35 ///////////////////////////
37 pvi = std::find(s.moduleParams.begin(), s.moduleParams.end(), pv);
38 if (pvi == s.moduleParams.end())
40 errorStr = "Parameter \'Port\' not found.";
41 printfd(__FILE__, "Parameter 'Port' not found\n");
44 if (ParseIntInRange(pvi->value[0], 2, 65535, &p))
46 errorStr = "Cannot parse parameter \'Port\': " + errorStr;
47 printfd(__FILE__, "%s\n", errorStr.c_str());
54 //-----------------------------------------------------------------------------
55 uint16_t STG_CONFIG_SETTINGS::GetPort() const
59 //-----------------------------------------------------------------------------
60 //-----------------------------------------------------------------------------
61 //-----------------------------------------------------------------------------
64 return stgc.GetPlugin();
66 //-----------------------------------------------------------------------------
67 //-----------------------------------------------------------------------------
68 //-----------------------------------------------------------------------------
69 const std::string STG_CONFIG::GetVersion() const
71 return "Stg configurator v.0.08";
73 //-----------------------------------------------------------------------------
74 STG_CONFIG::STG_CONFIG()
84 //-----------------------------------------------------------------------------
85 void STG_CONFIG::SetUsers(USERS * u)
89 //-----------------------------------------------------------------------------
90 void STG_CONFIG::SetTariffs(TARIFFS * t)
94 //-----------------------------------------------------------------------------
95 void STG_CONFIG::SetAdmins(ADMINS * a)
99 //-----------------------------------------------------------------------------
100 void STG_CONFIG::SetStore(STORE * s)
104 //-----------------------------------------------------------------------------
105 void STG_CONFIG::SetStgSettings(const SETTINGS * s)
109 //-----------------------------------------------------------------------------
110 void STG_CONFIG::SetSettings(const MODULE_SETTINGS & s)
114 //-----------------------------------------------------------------------------
115 int STG_CONFIG::ParseSettings()
117 int ret = stgConfigSettings.ParseSettings(settings);
119 errorStr = stgConfigSettings.GetStrError();
122 //-----------------------------------------------------------------------------
123 const std::string & STG_CONFIG::GetStrError() const
127 //-----------------------------------------------------------------------------
128 int STG_CONFIG::Start()
135 config.SetPort(stgConfigSettings.GetPort());
136 config.SetAdmins(admins);
137 config.SetUsers(users);
138 config.SetTariffs(tariffs);
139 config.SetStgSettings(stgSettings);
140 config.SetStore(store);
142 if (config.Prepare())
144 errorStr = config.GetStrError();
148 if (pthread_create(&thread, NULL, Run, this))
150 errorStr = "Cannot create thread.";
151 printfd(__FILE__, "Cannot create thread\n");
157 //-----------------------------------------------------------------------------
158 int STG_CONFIG::Stop()
165 //5 seconds to thread stops itself
167 for (i = 0; i < 25; i++)
175 //after 5 seconds waiting thread still running. now killing it
178 //TODO pthread_cancel()
179 if (pthread_kill(thread, SIGINT))
181 errorStr = "Cannot kill thread.";
182 printfd(__FILE__, "Cannot kill thread\n");
185 printfd(__FILE__, "STG_CONFIG killed\n");
190 //-----------------------------------------------------------------------------
191 bool STG_CONFIG::IsRunning()
195 //-----------------------------------------------------------------------------
196 void * STG_CONFIG::Run(void * d)
198 STG_CONFIG * stgConf = (STG_CONFIG *)d;
199 stgConf->isRunning = true;
201 stgConf->config.Run(&stgConf->config);
203 stgConf->isRunning = false;
206 //-----------------------------------------------------------------------------
207 uint16_t STG_CONFIG::GetStartPosition() const
211 //-----------------------------------------------------------------------------
212 uint16_t STG_CONFIG::GetStopPosition() const
216 //-----------------------------------------------------------------------------