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()
73 //-----------------------------------------------------------------------------
74 int STG_CONFIG::ParseSettings()
76 int ret = stgConfigSettings.ParseSettings(settings);
78 errorStr = stgConfigSettings.GetStrError();
81 //-----------------------------------------------------------------------------
82 int STG_CONFIG::Start()
89 config.SetPort(stgConfigSettings.GetPort());
90 config.SetAdmins(admins);
91 config.SetUsers(users);
92 config.SetTariffs(tariffs);
93 config.SetStgSettings(stgSettings);
94 config.SetStore(store);
98 errorStr = config.GetStrError();
102 if (pthread_create(&thread, NULL, Run, this))
104 errorStr = "Cannot create thread.";
105 printfd(__FILE__, "Cannot create thread\n");
111 //-----------------------------------------------------------------------------
112 int STG_CONFIG::Stop()
119 //5 seconds to thread stops itself
121 for (i = 0; i < 25; i++)
126 struct timespec ts = {0, 200000000};
127 nanosleep(&ts, NULL);
130 //after 5 seconds waiting thread still running. now killing it
133 //TODO pthread_cancel()
134 if (pthread_kill(thread, SIGINT))
136 errorStr = "Cannot kill thread.";
137 printfd(__FILE__, "Cannot kill thread\n");
140 printfd(__FILE__, "STG_CONFIG killed\n");
145 //-----------------------------------------------------------------------------
146 void * STG_CONFIG::Run(void * d)
149 sigfillset(&signalSet);
150 pthread_sigmask(SIG_BLOCK, &signalSet, NULL);
152 STG_CONFIG * stgConf = (STG_CONFIG *)d;
153 stgConf->isRunning = true;
155 stgConf->config.Run();
157 stgConf->isRunning = false;
160 //-----------------------------------------------------------------------------