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 int STG_CONFIG_SETTINGS::ParseSettings(const MODULE_SETTINGS & s)
24 vector<PARAM_VALUE>::const_iterator pvi;
25 ///////////////////////////
27 pvi = std::find(s.moduleParams.begin(), s.moduleParams.end(), pv);
28 if (pvi == s.moduleParams.end())
30 errorStr = "Parameter \'Port\' not found.";
31 printfd(__FILE__, "Parameter 'Port' not found\n");
34 if (ParseIntInRange(pvi->value[0], 2, 65535, &p))
36 errorStr = "Cannot parse parameter \'Port\': " + errorStr;
37 printfd(__FILE__, "%s\n", errorStr.c_str());
44 //-----------------------------------------------------------------------------
45 //-----------------------------------------------------------------------------
46 //-----------------------------------------------------------------------------
49 return stgc.GetPlugin();
51 //-----------------------------------------------------------------------------
52 //-----------------------------------------------------------------------------
53 //-----------------------------------------------------------------------------
54 const std::string STG_CONFIG::GetVersion() const
56 return "Stg configurator v.0.08";
58 //-----------------------------------------------------------------------------
59 STG_CONFIG::STG_CONFIG()
69 //-----------------------------------------------------------------------------
70 int STG_CONFIG::ParseSettings()
72 int ret = stgConfigSettings.ParseSettings(settings);
74 errorStr = stgConfigSettings.GetStrError();
77 //-----------------------------------------------------------------------------
78 int STG_CONFIG::Start()
85 config.SetPort(stgConfigSettings.GetPort());
86 config.SetAdmins(admins);
87 config.SetUsers(users);
88 config.SetTariffs(tariffs);
89 config.SetStgSettings(stgSettings);
90 config.SetStore(store);
94 errorStr = config.GetStrError();
98 if (pthread_create(&thread, NULL, Run, this))
100 errorStr = "Cannot create thread.";
101 printfd(__FILE__, "Cannot create thread\n");
107 //-----------------------------------------------------------------------------
108 int STG_CONFIG::Stop()
115 //5 seconds to thread stops itself
117 for (i = 0; i < 25; i++)
125 //after 5 seconds waiting thread still running. now killing it
128 //TODO pthread_cancel()
129 if (pthread_kill(thread, SIGINT))
131 errorStr = "Cannot kill thread.";
132 printfd(__FILE__, "Cannot kill thread\n");
135 printfd(__FILE__, "STG_CONFIG killed\n");
140 //-----------------------------------------------------------------------------
141 void * STG_CONFIG::Run(void * d)
143 STG_CONFIG * stgConf = (STG_CONFIG *)d;
144 stgConf->isRunning = true;
146 stgConf->config.Run(&stgConf->config);
148 stgConf->isRunning = false;
151 //-----------------------------------------------------------------------------