3 #include "stg/plugin_creator.h"
4 #include "stg/common.h"
11 //-----------------------------------------------------------------------------
12 //-----------------------------------------------------------------------------
13 //-----------------------------------------------------------------------------
14 static PLUGIN_CREATOR<STG_CONFIG> stgc;
15 //-----------------------------------------------------------------------------
16 //-----------------------------------------------------------------------------
17 //-----------------------------------------------------------------------------
18 int STG_CONFIG_SETTINGS::ParseSettings(const MODULE_SETTINGS & s)
22 std::vector<PARAM_VALUE>::const_iterator pvi;
23 ///////////////////////////
25 pvi = std::find(s.moduleParams.begin(), s.moduleParams.end(), pv);
26 if (pvi == s.moduleParams.end())
28 errorStr = "Parameter \'Port\' not found.";
29 printfd(__FILE__, "Parameter 'Port' not found\n");
32 if (ParseIntInRange(pvi->value[0], 2, 65535, &p))
34 errorStr = "Cannot parse parameter \'Port\': " + errorStr;
35 printfd(__FILE__, "%s\n", errorStr.c_str());
38 port = static_cast<uint16_t>(p);
42 //-----------------------------------------------------------------------------
43 //-----------------------------------------------------------------------------
44 //-----------------------------------------------------------------------------
47 return stgc.GetPlugin();
49 //-----------------------------------------------------------------------------
50 //-----------------------------------------------------------------------------
51 //-----------------------------------------------------------------------------
52 std::string STG_CONFIG::GetVersion() const
54 return "Stg configurator v.0.08";
56 //-----------------------------------------------------------------------------
57 STG_CONFIG::STG_CONFIG()
63 logger(GetPluginLogger(GetStgLogger(), "conf_sg")),
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());
88 errorStr = config.GetStrError();
92 if (pthread_create(&thread, NULL, Run, this))
94 errorStr = "Cannot create thread.";
95 printfd(__FILE__, "Cannot create thread\n");
96 logger("Cannot create thread.");
102 //-----------------------------------------------------------------------------
103 int STG_CONFIG::Stop()
110 //5 seconds to thread stops itself
111 for (int i = 0; i < 25; i++)
116 struct timespec ts = {0, 200000000};
117 nanosleep(&ts, NULL);
125 //-----------------------------------------------------------------------------
126 void * STG_CONFIG::Run(void * d)
129 sigfillset(&signalSet);
130 pthread_sigmask(SIG_BLOCK, &signalSet, NULL);
132 STG_CONFIG * stgConf = static_cast<STG_CONFIG *>(d);
133 stgConf->isRunning = true;
135 stgConf->config.Run();
137 stgConf->isRunning = false;
140 //-----------------------------------------------------------------------------