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()
64 logger(GetPluginLogger(GetStgLogger(), "conf_sg")),
74 //-----------------------------------------------------------------------------
75 int STG_CONFIG::ParseSettings()
77 int ret = stgConfigSettings.ParseSettings(settings);
79 errorStr = stgConfigSettings.GetStrError();
82 //-----------------------------------------------------------------------------
83 int STG_CONFIG::Start()
90 config.SetPort(stgConfigSettings.GetPort());
91 config.SetAdmins(admins);
92 config.SetUsers(users);
93 config.SetTariffs(tariffs);
94 config.SetStgSettings(stgSettings);
95 config.SetStore(store);
99 errorStr = config.GetStrError();
103 if (pthread_create(&thread, NULL, Run, this))
105 errorStr = "Cannot create thread.";
106 printfd(__FILE__, "Cannot create thread\n");
107 logger("Cannot create thread.");
113 //-----------------------------------------------------------------------------
114 int STG_CONFIG::Stop()
121 //5 seconds to thread stops itself
123 for (i = 0; i < 25; i++)
128 struct timespec ts = {0, 200000000};
129 nanosleep(&ts, NULL);
137 //-----------------------------------------------------------------------------
138 void * STG_CONFIG::Run(void * d)
141 sigfillset(&signalSet);
142 pthread_sigmask(SIG_BLOCK, &signalSet, NULL);
144 STG_CONFIG * stgConf = (STG_CONFIG *)d;
145 stgConf->isRunning = true;
147 stgConf->config.Run();
149 stgConf->isRunning = false;
152 //-----------------------------------------------------------------------------