2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 * Author : Boris Mikhailenko <stg34@stargazer.dp.ua>
21 #include "stgconfig.h"
23 #include "stg/plugin_creator.h"
24 #include "stg/common.h"
31 //-----------------------------------------------------------------------------
32 //-----------------------------------------------------------------------------
33 //-----------------------------------------------------------------------------
34 static PLUGIN_CREATOR<STG_CONFIG> stgc;
35 //-----------------------------------------------------------------------------
36 //-----------------------------------------------------------------------------
37 //-----------------------------------------------------------------------------
38 int STG_CONFIG_SETTINGS::ParseSettings(const MODULE_SETTINGS & s)
42 std::vector<PARAM_VALUE>::const_iterator pvi;
43 ///////////////////////////
45 pvi = std::find(s.moduleParams.begin(), s.moduleParams.end(), pv);
46 if (pvi == s.moduleParams.end())
48 errorStr = "Parameter \'Port\' not found.";
49 printfd(__FILE__, "Parameter 'Port' not found\n");
52 if (ParseIntInRange(pvi->value[0], 2, 65535, &p))
54 errorStr = "Cannot parse parameter \'Port\': " + errorStr;
55 printfd(__FILE__, "%s\n", errorStr.c_str());
58 port = static_cast<uint16_t>(p);
62 //-----------------------------------------------------------------------------
63 //-----------------------------------------------------------------------------
64 //-----------------------------------------------------------------------------
65 extern "C" PLUGIN * GetPlugin()
67 return stgc.GetPlugin();
69 //-----------------------------------------------------------------------------
70 //-----------------------------------------------------------------------------
71 //-----------------------------------------------------------------------------
72 STG_CONFIG::STG_CONFIG()
78 logger(GetPluginLogger(GetStgLogger(), "conf_sg")),
83 //-----------------------------------------------------------------------------
84 int STG_CONFIG::ParseSettings()
86 int ret = stgConfigSettings.ParseSettings(settings);
88 errorStr = stgConfigSettings.GetStrError();
91 //-----------------------------------------------------------------------------
92 int STG_CONFIG::Start()
99 config.SetPort(stgConfigSettings.GetPort());
101 if (config.Prepare())
103 errorStr = config.GetStrError();
107 if (pthread_create(&thread, NULL, Run, this))
109 errorStr = "Cannot create thread.";
110 printfd(__FILE__, "Cannot create thread\n");
111 logger("Cannot create thread.");
117 //-----------------------------------------------------------------------------
118 int STG_CONFIG::Stop()
125 //5 seconds to thread stops itself
126 for (int i = 0; i < 25; i++)
131 struct timespec ts = {0, 200000000};
132 nanosleep(&ts, NULL);
140 //-----------------------------------------------------------------------------
141 void * STG_CONFIG::Run(void * d)
144 sigfillset(&signalSet);
145 pthread_sigmask(SIG_BLOCK, &signalSet, NULL);
147 STG_CONFIG * stgConf = static_cast<STG_CONFIG *>(d);
148 stgConf->isRunning = true;
150 stgConf->config.Run();
152 stgConf->isRunning = false;
155 //-----------------------------------------------------------------------------