git.stg.codes
/
stg.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Use `time` for message creation time.
[stg.git]
/
projects
/
stargazer
/
plugins
/
other
/
smux
/
smux.cpp
diff --git
a/projects/stargazer/plugins/other/smux/smux.cpp
b/projects/stargazer/plugins/other/smux/smux.cpp
index 31b91bb390ee431b7caf1e732832012586d5bb89..c74aeae982727bed08dba8f79d15bcb0067d5194 100644
(file)
--- a/
projects/stargazer/plugins/other/smux/smux.cpp
+++ b/
projects/stargazer/plugins/other/smux/smux.cpp
@@
-15,17
+15,12
@@
#include <utility>
#include "stg/common.h"
#include <utility>
#include "stg/common.h"
-#include "stg/plugin_creator.h"
#include "smux.h"
#include "utils.h"
namespace
{
#include "smux.h"
#include "utils.h"
namespace
{
-PLUGIN_CREATOR<SMUX> smc;
-
-bool SPrefixLess(const Sensors::value_type & a,
- const Sensors::value_type & b);
bool SPrefixLess(const Sensors::value_type & a,
const Sensors::value_type & b)
bool SPrefixLess(const Sensors::value_type & a,
const Sensors::value_type & b)
@@
-35,11
+30,10
@@
return a.first.PrefixLess(b.first);
}
}
-extern "C" PLUGIN * GetPlugin();
-
-PLUGIN * GetPlugin()
+extern "C" STG::Plugin* GetPlugin()
{
{
-return smc.GetPlugin();
+ static SMUX plugin;
+ return &plugin;
}
SMUX_SETTINGS::SMUX_SETTINGS()
}
SMUX_SETTINGS::SMUX_SETTINGS()
@@
-49,15
+43,15
@@
SMUX_SETTINGS::SMUX_SETTINGS()
password()
{}
password()
{}
-int SMUX_SETTINGS::ParseSettings(const
MODULE_SETTINGS
& s)
+int SMUX_SETTINGS::ParseSettings(const
STG::ModuleSettings
& s)
{
{
-
PARAM_VALUE
pv;
-std::vector<
PARAM_VALUE
>::const_iterator pvi;
+
STG::ParamValue
pv;
+std::vector<
STG::ParamValue
>::const_iterator pvi;
int p;
pv.param = "Port";
pvi = std::find(s.moduleParams.begin(), s.moduleParams.end(), pv);
int p;
pv.param = "Port";
pvi = std::find(s.moduleParams.begin(), s.moduleParams.end(), pv);
-if (pvi == s.moduleParams.end())
+if (pvi == s.moduleParams.end()
|| pvi->value.empty()
)
{
errorStr = "Parameter \'Port\' not found.";
printfd(__FILE__, "Parameter 'Port' not found\n");
{
errorStr = "Parameter \'Port\' not found.";
printfd(__FILE__, "Parameter 'Port' not found\n");
@@
-73,7
+67,7
@@
port = static_cast<uint16_t>(p);
pv.param = "Password";
pvi = std::find(s.moduleParams.begin(), s.moduleParams.end(), pv);
pv.param = "Password";
pvi = std::find(s.moduleParams.begin(), s.moduleParams.end(), pv);
-if (pvi == s.moduleParams.end())
+if (pvi == s.moduleParams.end()
|| pvi->value.empty()
)
{
errorStr = "Parameter \'Password\' not found.";
printfd(__FILE__, "Parameter 'Password' not found\n");
{
errorStr = "Parameter \'Password\' not found.";
printfd(__FILE__, "Parameter 'Password' not found\n");
@@
-86,7
+80,7
@@
else
pv.param = "Server";
pvi = std::find(s.moduleParams.begin(), s.moduleParams.end(), pv);
pv.param = "Server";
pvi = std::find(s.moduleParams.begin(), s.moduleParams.end(), pv);
-if (pvi == s.moduleParams.end())
+if (pvi == s.moduleParams.end()
|| pvi->value.empty()
)
{
errorStr = "Parameter \'Server\' not found.";
printfd(__FILE__, "Parameter 'Server' not found\n");
{
errorStr = "Parameter \'Server\' not found.";
printfd(__FILE__, "Parameter 'Server' not found\n");
@@
-98,33
+92,22
@@
return 0;
}
SMUX::SMUX()
}
SMUX::SMUX()
- : PLUGIN(),
- users(NULL),
+ : users(NULL),
tariffs(NULL),
admins(NULL),
services(NULL),
corporations(NULL),
traffcounter(NULL),
tariffs(NULL),
admins(NULL),
services(NULL),
corporations(NULL),
traffcounter(NULL),
- errorStr(),
- smuxSettings(),
- settings(),
- thread(),
- mutex(),
running(false),
stopped(true),
needReconnect(false),
lastReconnectTry(0),
reconnectTimeout(1),
sock(-1),
running(false),
stopped(true),
needReconnect(false),
lastReconnectTry(0),
reconnectTimeout(1),
sock(-1),
- smuxHandlers(),
- pdusHandlers(),
- sensors(),
- tables(),
- notifiers(),
addUserNotifier(*this),
delUserNotifier(*this),
addDelTariffNotifier(*this),
addUserNotifier(*this),
delUserNotifier(*this),
addDelTariffNotifier(*this),
- logger(
GetPluginLogger(GetStgLogger(),
"smux"))
+ logger(
STG::PluginLogger::get(
"smux"))
{
pthread_mutex_init(&mutex, NULL);
{
pthread_mutex_init(&mutex, NULL);
@@
-272,12
+255,17
@@
printfd(__FILE__, "SMUX::Stop() - After\n");
return 0;
}
return 0;
}
-int SMUX::Reload()
+int SMUX::Reload(
const STG::ModuleSettings & /*ms*/
)
{
if (Stop())
return -1;
if (Start())
return -1;
{
if (Stop())
return -1;
if (Start())
return -1;
+if (!needReconnect)
+ {
+ printfd(__FILE__, "SMUX reconnected succesfully.\n");
+ logger("Reconnected successfully.");
+ }
return 0;
}
return 0;
}
@@
-467,20
+455,20
@@
sensors.insert(newSensors.begin(), newSensors.end());
return true;
}
return true;
}
-void SMUX::SetNotifier(U
SER_PTR
userPtr)
+void SMUX::SetNotifier(U
serPtr
userPtr)
{
notifiers.push_back(CHG_AFTER_NOTIFIER(*this, userPtr));
{
notifiers.push_back(CHG_AFTER_NOTIFIER(*this, userPtr));
-userPtr->GetPropert
y
().tariffName.AddAfterNotifier(¬ifiers.back());
+userPtr->GetPropert
ies
().tariffName.AddAfterNotifier(¬ifiers.back());
}
}
-void SMUX::UnsetNotifier(U
SER_PTR
userPtr)
+void SMUX::UnsetNotifier(U
serPtr
userPtr)
{
std::list<CHG_AFTER_NOTIFIER>::iterator it = notifiers.begin();
while (it != notifiers.end())
{
if (it->GetUserPtr() == userPtr)
{
{
std::list<CHG_AFTER_NOTIFIER>::iterator it = notifiers.begin();
while (it != notifiers.end())
{
if (it->GetUserPtr() == userPtr)
{
- userPtr->GetPropert
y
().tariffName.DelAfterNotifier(&(*it));
+ userPtr->GetPropert
ies
().tariffName.DelAfterNotifier(&(*it));
notifiers.erase(it);
break;
}
notifiers.erase(it);
break;
}
@@
-493,7
+481,7
@@
void SMUX::SetNotifiers()
int h = users->OpenSearch();
assert(h && "USERS::OpenSearch is always correct");
int h = users->OpenSearch();
assert(h && "USERS::OpenSearch is always correct");
-U
SER_PTR
u;
+U
serPtr
u;
while (!users->SearchNext(h, &u))
SetNotifier(u);
while (!users->SearchNext(h, &u))
SetNotifier(u);
@@
-517,7
+505,7
@@
users->DelNotifierUserAdd(&addUserNotifier);
std::list<CHG_AFTER_NOTIFIER>::iterator it(notifiers.begin());
while (it != notifiers.end())
{
std::list<CHG_AFTER_NOTIFIER>::iterator it(notifiers.begin());
while (it != notifiers.end())
{
- it->GetUserPtr()->GetPropert
y
().tariffName.DelAfterNotifier(&(*it));
+ it->GetUserPtr()->GetPropert
ies
().tariffName.DelAfterNotifier(&(*it));
++it;
}
notifiers.clear();
++it;
}
notifiers.clear();