6 #include "stg/tariffs.h"
7 #include "stg/admins.h"
9 #include "stg/plugin_creator.h"
10 #include "stgconfig.h"
12 //-----------------------------------------------------------------------------
13 //-----------------------------------------------------------------------------
14 //-----------------------------------------------------------------------------
15 PLUGIN_CREATOR<STG_CONFIG> stgc;
16 //-----------------------------------------------------------------------------
17 //-----------------------------------------------------------------------------
18 //-----------------------------------------------------------------------------
19 int STG_CONFIG_SETTINGS::ParseSettings(const MODULE_SETTINGS & s)
23 vector<PARAM_VALUE>::const_iterator pvi;
24 ///////////////////////////
26 pvi = std::find(s.moduleParams.begin(), s.moduleParams.end(), pv);
27 if (pvi == s.moduleParams.end())
29 errorStr = "Parameter \'Port\' not found.";
30 printfd(__FILE__, "Parameter 'Port' not found\n");
33 if (ParseIntInRange(pvi->value[0], 2, 65535, &p))
35 errorStr = "Cannot parse parameter \'Port\': " + errorStr;
36 printfd(__FILE__, "%s\n", errorStr.c_str());
43 //-----------------------------------------------------------------------------
44 //-----------------------------------------------------------------------------
45 //-----------------------------------------------------------------------------
48 return stgc.GetPlugin();
50 //-----------------------------------------------------------------------------
51 //-----------------------------------------------------------------------------
52 //-----------------------------------------------------------------------------
53 const std::string STG_CONFIG::GetVersion() const
55 return "Stg configurator v.0.08";
57 //-----------------------------------------------------------------------------
58 STG_CONFIG::STG_CONFIG()
68 //-----------------------------------------------------------------------------
69 int STG_CONFIG::ParseSettings()
71 int ret = stgConfigSettings.ParseSettings(settings);
73 errorStr = stgConfigSettings.GetStrError();
76 //-----------------------------------------------------------------------------
77 int STG_CONFIG::Start()
84 config.SetPort(stgConfigSettings.GetPort());
85 config.SetAdmins(admins);
86 config.SetUsers(users);
87 config.SetTariffs(tariffs);
88 config.SetStgSettings(stgSettings);
89 config.SetStore(store);
93 errorStr = config.GetStrError();
97 if (pthread_create(&thread, NULL, Run, this))
99 errorStr = "Cannot create thread.";
100 printfd(__FILE__, "Cannot create thread\n");
106 //-----------------------------------------------------------------------------
107 int STG_CONFIG::Stop()
114 //5 seconds to thread stops itself
116 for (i = 0; i < 25; i++)
124 //after 5 seconds waiting thread still running. now killing it
127 //TODO pthread_cancel()
128 if (pthread_kill(thread, SIGINT))
130 errorStr = "Cannot kill thread.";
131 printfd(__FILE__, "Cannot kill thread\n");
134 printfd(__FILE__, "STG_CONFIG killed\n");
139 //-----------------------------------------------------------------------------
140 void * STG_CONFIG::Run(void * d)
142 STG_CONFIG * stgConf = (STG_CONFIG *)d;
143 stgConf->isRunning = true;
145 stgConf->config.Run();
147 stgConf->isRunning = false;
150 //-----------------------------------------------------------------------------