Commit 1f5d6110 authored by Pavel Vainerman's avatar Pavel Vainerman

make style

parent bb263d34
...@@ -485,12 +485,6 @@ mv -f %buildroot%python_sitelibdir_noarch/* %buildroot%python_sitelibdir/%oname ...@@ -485,12 +485,6 @@ mv -f %buildroot%python_sitelibdir_noarch/* %buildroot%python_sitelibdir/%oname
* Wed Feb 17 2016 Pavel Vainerman <pv@altlinux.ru> 2.2-alt23 * Wed Feb 17 2016 Pavel Vainerman <pv@altlinux.ru> 2.2-alt23
- IONotifyController: fixed buf for init thresholdslist - IONotifyController: fixed buf for init thresholdslist
* Mon Jan 18 2016 Pavel Vainerman <pv@altlinux.ru> 2.2-alt19
- rebuild new version
* Fri Jan 15 2016 Pavel Vainerman <pv@altlinux.ru> 2.2-alt17
- rebuild new version
* Tue Feb 09 2016 Pavel Vainerman <pv@altlinux.ru> 2.2-alt22 * Tue Feb 09 2016 Pavel Vainerman <pv@altlinux.ru> 2.2-alt22
- ModbusSlave(TCP): add show ip:port to vmonit setbug #9012 - ModbusSlave(TCP): add show ip:port to vmonit setbug #9012
......
...@@ -48,6 +48,7 @@ MySQLInterface::~MySQLInterface() ...@@ -48,6 +48,7 @@ MySQLInterface::~MySQLInterface()
{ {
cerr << "MySQLInterface::~MySQLInterface(): an error occured while closing connection!" << endl; cerr << "MySQLInterface::~MySQLInterface(): an error occured while closing connection!" << endl;
} }
delete mysql; delete mysql;
} }
...@@ -188,6 +189,7 @@ void MySQLInterface::makeResult(DBResult& dbres, MYSQL_RES* myres, bool finalize ...@@ -188,6 +189,7 @@ void MySQLInterface::makeResult(DBResult& dbres, MYSQL_RES* myres, bool finalize
{ {
if( finalize ) if( finalize )
mysql_free_result(myres); mysql_free_result(myres);
return; return;
} }
......
...@@ -233,6 +233,7 @@ void SQLiteInterface::makeResult(DBResult& dbres, sqlite3_stmt* s, bool finalize ...@@ -233,6 +233,7 @@ void SQLiteInterface::makeResult(DBResult& dbres, sqlite3_stmt* s, bool finalize
{ {
if( finalize ) if( finalize )
sqlite3_finalize(s); sqlite3_finalize(s);
return; return;
} }
......
...@@ -30,6 +30,7 @@ MQTTPublisher::MQTTPublisher(UniSetTypes::ObjectId objId, xmlNode* cnode, UniSet ...@@ -30,6 +30,7 @@ MQTTPublisher::MQTTPublisher(UniSetTypes::ObjectId objId, xmlNode* cnode, UniSet
myinfo << myname << "(init): filter-field=" << ff << " filter-value=" << fv << endl; myinfo << myname << "(init): filter-field=" << ff << " filter-value=" << fv << endl;
xmlNode* senssec = conf->getXMLSensorsSection(); xmlNode* senssec = conf->getXMLSensorsSection();
if( !senssec ) if( !senssec )
{ {
ostringstream err; ostringstream err;
...@@ -39,6 +40,7 @@ MQTTPublisher::MQTTPublisher(UniSetTypes::ObjectId objId, xmlNode* cnode, UniSet ...@@ -39,6 +40,7 @@ MQTTPublisher::MQTTPublisher(UniSetTypes::ObjectId objId, xmlNode* cnode, UniSet
} }
UniXML::iterator sit(senssec); UniXML::iterator sit(senssec);
if( !sit.goChildren() ) if( !sit.goChildren() )
{ {
ostringstream err; ostringstream err;
...@@ -48,6 +50,7 @@ MQTTPublisher::MQTTPublisher(UniSetTypes::ObjectId objId, xmlNode* cnode, UniSet ...@@ -48,6 +50,7 @@ MQTTPublisher::MQTTPublisher(UniSetTypes::ObjectId objId, xmlNode* cnode, UniSet
} }
ostringstream pubname; ostringstream pubname;
for( ; sit.getCurrent(); sit++ ) for( ; sit.getCurrent(); sit++ )
{ {
if( !UniSetTypes::check_filter(sit, ff, fv) ) if( !UniSetTypes::check_filter(sit, ff, fv) )
...@@ -55,6 +58,7 @@ MQTTPublisher::MQTTPublisher(UniSetTypes::ObjectId objId, xmlNode* cnode, UniSet ...@@ -55,6 +58,7 @@ MQTTPublisher::MQTTPublisher(UniSetTypes::ObjectId objId, xmlNode* cnode, UniSet
std::string sname = sit.getProp("name"); std::string sname = sit.getProp("name");
ObjectId sid = conf->getSensorID(sname); ObjectId sid = conf->getSensorID(sname);
if( sid == DefaultObjectId ) if( sid == DefaultObjectId )
{ {
ostringstream err; ostringstream err;
...@@ -66,7 +70,7 @@ MQTTPublisher::MQTTPublisher(UniSetTypes::ObjectId objId, xmlNode* cnode, UniSet ...@@ -66,7 +70,7 @@ MQTTPublisher::MQTTPublisher(UniSetTypes::ObjectId objId, xmlNode* cnode, UniSet
pubname.str(""); pubname.str("");
pubname << topicsensors << "/" << sname; pubname << topicsensors << "/" << sname;
MQTTInfo m(sid,pubname.str()); MQTTInfo m(sid, pubname.str());
publist.emplace(sid, std::move(m) ); publist.emplace(sid, std::move(m) );
if( smTestID == DefaultObjectId ) if( smTestID == DefaultObjectId )
...@@ -87,9 +91,9 @@ MQTTPublisher::MQTTPublisher(UniSetTypes::ObjectId objId, xmlNode* cnode, UniSet ...@@ -87,9 +91,9 @@ MQTTPublisher::MQTTPublisher(UniSetTypes::ObjectId objId, xmlNode* cnode, UniSet
port = conf->getArgPInt("--" + argprefix + "mqtt-port", it.getProp("mqttPort"), 1883); port = conf->getArgPInt("--" + argprefix + "mqtt-port", it.getProp("mqttPort"), 1883);
keepalive = conf->getArgPInt("--" + argprefix + "mqtt-keepalive", it.getProp("mqttKeepAlive"), 60); keepalive = conf->getArgPInt("--" + argprefix + "mqtt-keepalive", it.getProp("mqttKeepAlive"), 60);
// см. sysCommad() // см. sysCommad()
// connect_async(host.c_str(),port,keepalive); // connect_async(host.c_str(),port,keepalive);
// loop_start(); // loop_start();
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
MQTTPublisher::~MQTTPublisher() MQTTPublisher::~MQTTPublisher()
...@@ -117,11 +121,12 @@ bool MQTTPublisher::deactivateObject() ...@@ -117,11 +121,12 @@ bool MQTTPublisher::deactivateObject()
void MQTTPublisher::sysCommand(const SystemMessage* sm) void MQTTPublisher::sysCommand(const SystemMessage* sm)
{ {
UObject_SK::sysCommand(sm); UObject_SK::sysCommand(sm);
if( sm->command == SystemMessage::StartUp || sm->command == SystemMessage::WatchDog ) if( sm->command == SystemMessage::StartUp || sm->command == SystemMessage::WatchDog )
{ {
if( !connectOK ) if( !connectOK )
{ {
connect_async(host.c_str(),port,keepalive); connect_async(host.c_str(), port, keepalive);
loop_start(); loop_start();
} }
} }
...@@ -165,10 +170,11 @@ void MQTTPublisher::on_connect(int rc) ...@@ -165,10 +170,11 @@ void MQTTPublisher::on_connect(int rc)
if( connectOK ) if( connectOK )
askSensors(UniversalIO::UIONotify); askSensors(UniversalIO::UIONotify);
// else
// { // else
// askTimer(reconnectTimer,reconnectTime); // {
// } // askTimer(reconnectTimer,reconnectTime);
// }
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
void MQTTPublisher::on_message( const mosquitto_message* message ) void MQTTPublisher::on_message( const mosquitto_message* message )
...@@ -220,7 +226,8 @@ std::shared_ptr<MQTTPublisher> MQTTPublisher::init_mqttpublisher(int argc, const ...@@ -220,7 +226,8 @@ std::shared_ptr<MQTTPublisher> MQTTPublisher::init_mqttpublisher(int argc, const
void MQTTPublisher::askSensors( UniversalIO::UIOCommand cmd ) void MQTTPublisher::askSensors( UniversalIO::UIOCommand cmd )
{ {
UObject_SK::askSensors(cmd); UObject_SK::askSensors(cmd);
for( const auto& i: publist )
for( const auto& i : publist )
{ {
try try
{ {
...@@ -236,6 +243,7 @@ void MQTTPublisher::askSensors( UniversalIO::UIOCommand cmd ) ...@@ -236,6 +243,7 @@ void MQTTPublisher::askSensors( UniversalIO::UIOCommand cmd )
void MQTTPublisher::sensorInfo( const UniSetTypes::SensorMessage* sm ) void MQTTPublisher::sensorInfo( const UniSetTypes::SensorMessage* sm )
{ {
auto i = publist.find(sm->id); auto i = publist.find(sm->id);
if( i == publist.end() ) if( i == publist.end() )
return; return;
...@@ -247,7 +255,8 @@ void MQTTPublisher::sensorInfo( const UniSetTypes::SensorMessage* sm ) ...@@ -247,7 +255,8 @@ void MQTTPublisher::sensorInfo( const UniSetTypes::SensorMessage* sm )
//subscribe(NULL, i.second.pubname.c_str()); //subscribe(NULL, i.second.pubname.c_str());
myinfo << "(sensorInfo): publish: topic='" << i->second.pubname << "' msg='" << tmsg.c_str() << "'" << endl; myinfo << "(sensorInfo): publish: topic='" << i->second.pubname << "' msg='" << tmsg.c_str() << "'" << endl;
int ret = publish(NULL,i->second.pubname.c_str(),tmsg.size(),tmsg.c_str(),1,false); int ret = publish(NULL, i->second.pubname.c_str(), tmsg.size(), tmsg.c_str(), 1, false);
if( ret != MOSQ_ERR_SUCCESS ) if( ret != MOSQ_ERR_SUCCESS )
{ {
mycrit << myname << "(sensorInfo): PUBLISH FAILED: err(" << ret << "): " << mosqpp::strerror(ret) << endl; mycrit << myname << "(sensorInfo): PUBLISH FAILED: err(" << ret << "): " << mosqpp::strerror(ret) << endl;
......
...@@ -81,8 +81,8 @@ class MQTTPublisher: ...@@ -81,8 +81,8 @@ class MQTTPublisher:
virtual void on_connect(int rc) override; virtual void on_connect(int rc) override;
virtual void on_message(const struct mosquitto_message *message) override; virtual void on_message(const struct mosquitto_message* message) override;
virtual void on_subscribe(int mid, int qos_count, const int *granted_qos) override; virtual void on_subscribe(int mid, int qos_count, const int* granted_qos) override;
protected: protected:
MQTTPublisher(); MQTTPublisher();
......
...@@ -531,7 +531,7 @@ const std::string MBTCPMultiMaster::MBSlaveInfo::getShortInfo() const ...@@ -531,7 +531,7 @@ const std::string MBTCPMultiMaster::MBSlaveInfo::getShortInfo() const
<< " recv_timeout=" << recv_timeout << " recv_timeout=" << recv_timeout
<< " resp_force=" << respond_force << " resp_force=" << respond_force
<< " use=" << use << " use=" << use
<< " ignore=" << ( ptIgnoreTimeout.checkTime() ? "0":"1") << " ignore=" << ( ptIgnoreTimeout.checkTime() ? "0" : "1")
<< " priority=" << priority << " priority=" << priority
<< " persistent-connection=" << !force_disconnect << " persistent-connection=" << !force_disconnect
<< ")"; << ")";
......
...@@ -2409,6 +2409,7 @@ UniSetTypes::SimpleInfo* MBSlave::getInfo( CORBA::Long userparam ) ...@@ -2409,6 +2409,7 @@ UniSetTypes::SimpleInfo* MBSlave::getInfo( CORBA::Long userparam )
inf << "LogServer: " << logserv_host << ":" << logserv_port << endl; inf << "LogServer: " << logserv_host << ":" << logserv_port << endl;
inf << "iomap=" << iomap.size() << " myaddr: " << ModbusServer::vaddr2str(vaddr) << endl; inf << "iomap=" << iomap.size() << " myaddr: " << ModbusServer::vaddr2str(vaddr) << endl;
inf << "Statistic: askCount=" << askCount << " pingOK=" << pingOK << endl; inf << "Statistic: askCount=" << askCount << " pingOK=" << pingOK << endl;
if( sslot ) // т.е. если у нас tcp if( sslot ) // т.е. если у нас tcp
{ {
ost::InetAddress iaddr = sslot->getInetAddress(); ost::InetAddress iaddr = sslot->getInetAddress();
......
...@@ -386,7 +386,7 @@ RRDServer::RRDInfo::RRDInfo(const string& fname, long tmID, long sec, const RRDS ...@@ -386,7 +386,7 @@ RRDServer::RRDInfo::RRDInfo(const string& fname, long tmID, long sec, const RRDS
filename(fname), tid(tmID), sec(sec), dslist(lst) filename(fname), tid(tmID), sec(sec), dslist(lst)
{ {
// фомируем dsmap // фомируем dsmap
for( auto&& i: dslist ) for( auto && i : dslist )
dsmap.emplace(i->sid,i); dsmap.emplace(i->sid, i);
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
...@@ -29,7 +29,7 @@ class UObject_SK: ...@@ -29,7 +29,7 @@ class UObject_SK:
public UniSetObject public UniSetObject
{ {
public: public:
UObject_SK( UniSetTypes::ObjectId id, xmlNode* node=UniSetTypes::uniset_conf()->getNode("UObject"), const std::string& argprefix="" ); UObject_SK( UniSetTypes::ObjectId id, xmlNode* node = UniSetTypes::uniset_conf()->getNode("UObject"), const std::string& argprefix = "" );
UObject_SK(); UObject_SK();
virtual ~UObject_SK(); virtual ~UObject_SK();
...@@ -43,54 +43,60 @@ class UObject_SK: ...@@ -43,54 +43,60 @@ class UObject_SK:
virtual bool setMsg( UniSetTypes::ObjectId code, bool state = true ); virtual bool setMsg( UniSetTypes::ObjectId code, bool state = true );
inline std::shared_ptr<DebugStream> log(){ return mylog; } inline std::shared_ptr<DebugStream> log()
inline std::shared_ptr<LogAgregator> logAgregator(){ return loga; } {
return mylog;
}
inline std::shared_ptr<LogAgregator> logAgregator()
{
return loga;
}
void init_dlog( std::shared_ptr<DebugStream> d ); void init_dlog( std::shared_ptr<DebugStream> d );
// "синтаксический сахар"..для логов // "синтаксический сахар"..для логов
#ifndef myinfo #ifndef myinfo
#define myinfo if( log()->debugging(Debug::INFO) ) log()->info() #define myinfo if( log()->debugging(Debug::INFO) ) log()->info()
#endif #endif
#ifndef mywarn #ifndef mywarn
#define mywarn if( log()->debugging(Debug::WARN) ) log()->warn() #define mywarn if( log()->debugging(Debug::WARN) ) log()->warn()
#endif #endif
#ifndef mycrit #ifndef mycrit
#define mycrit if( log()->debugging(Debug::CRIT) ) log()->crit() #define mycrit if( log()->debugging(Debug::CRIT) ) log()->crit()
#endif #endif
#ifndef mylog1 #ifndef mylog1
#define mylog1 if( log()->debugging(Debug::LEVEL1) ) log()->level1() #define mylog1 if( log()->debugging(Debug::LEVEL1) ) log()->level1()
#endif #endif
#ifndef mylog2 #ifndef mylog2
#define mylog2 if( log()->debugging(Debug::LEVEL2) ) log()->level2() #define mylog2 if( log()->debugging(Debug::LEVEL2) ) log()->level2()
#endif #endif
#ifndef mylog3 #ifndef mylog3
#define mylog3 if( log()->debugging(Debug::LEVEL3) ) log()->level3() #define mylog3 if( log()->debugging(Debug::LEVEL3) ) log()->level3()
#endif #endif
#ifndef mylog4 #ifndef mylog4
#define mylog4 if( log()->debugging(Debug::LEVEL4) ) log()->level4() #define mylog4 if( log()->debugging(Debug::LEVEL4) ) log()->level4()
#endif #endif
#ifndef mylog5 #ifndef mylog5
#define mylog5 if( log()->debugging(Debug::LEVEL5) ) log()->level5() #define mylog5 if( log()->debugging(Debug::LEVEL5) ) log()->level5()
#endif #endif
#ifndef mylog6 #ifndef mylog6
#define mylog6 if( log()->debugging(Debug::LEVEL6) ) log()->level6() #define mylog6 if( log()->debugging(Debug::LEVEL6) ) log()->level6()
#endif #endif
#ifndef mylog7 #ifndef mylog7
#define mylog7 if( log()->debugging(Debug::LEVEL7) ) log()->level7() #define mylog7 if( log()->debugging(Debug::LEVEL7) ) log()->level7()
#endif #endif
#ifndef mylog8 #ifndef mylog8
#define mylog8 if( log()->debugging(Debug::LEVEL8) ) log()->level8() #define mylog8 if( log()->debugging(Debug::LEVEL8) ) log()->level8()
#endif #endif
#ifndef mylog9 #ifndef mylog9
#define mylog9 if( log()->debugging(Debug::LEVEL9) ) log()->level9() #define mylog9 if( log()->debugging(Debug::LEVEL9) ) log()->level9()
#endif #endif
#ifndef mylogany #ifndef mylogany
#define mylogany log()->any() #define mylogany log()->any()
#endif #endif
#ifndef vmonit #ifndef vmonit
#define vmonit( var ) vmon.add( #var, var ) #define vmonit( var ) vmon.add( #var, var )
#endif #endif
// Вспомогательные функции для удобства логирования // Вспомогательные функции для удобства логирования
// ------------------------------------------------------------ // ------------------------------------------------------------
...@@ -107,16 +113,19 @@ class UObject_SK: ...@@ -107,16 +113,19 @@ class UObject_SK:
\param id - идентификатор датчика \param id - идентификатор датчика
\param showLinkName - TRUE - выводить SensorName, FALSE - не выводить \param showLinkName - TRUE - выводить SensorName, FALSE - не выводить
*/ */
std::string str( UniSetTypes::ObjectId id, bool showLinkName=true ); std::string str( UniSetTypes::ObjectId id, bool showLinkName = true );
/*! Вывод значения входа/выхода в формате: in_xxx(SensorName)=val /*! Вывод значения входа/выхода в формате: in_xxx(SensorName)=val
\param id - идентификатор датчика \param id - идентификатор датчика
\param showLinkName - TRUE - выводить SensorName, FALSE - не выводить \param showLinkName - TRUE - выводить SensorName, FALSE - не выводить
*/ */
std::string strval( UniSetTypes::ObjectId id, bool showLinkName=true ); std::string strval( UniSetTypes::ObjectId id, bool showLinkName = true );
/*! Вывод состояния внутренних переменных */ /*! Вывод состояния внутренних переменных */
inline std::string dumpVars(){ return std::move(vmon.pretty_str()); } inline std::string dumpVars()
{
return std::move(vmon.pretty_str());
}
// ------------------------------------------------------------ // ------------------------------------------------------------
std::string help(); std::string help();
...@@ -145,13 +154,16 @@ class UObject_SK: ...@@ -145,13 +154,16 @@ class UObject_SK:
virtual void callback() override; virtual void callback() override;
virtual void processingMessage( UniSetTypes::VoidMessage* msg ) override; virtual void processingMessage( UniSetTypes::VoidMessage* msg ) override;
virtual void sysCommand( const UniSetTypes::SystemMessage* sm ){}; virtual void sysCommand( const UniSetTypes::SystemMessage* sm ) {};
virtual void askSensors( UniversalIO::UIOCommand cmd ){} virtual void askSensors( UniversalIO::UIOCommand cmd ) {}
virtual void sensorInfo( const UniSetTypes::SensorMessage* sm ) override{} virtual void sensorInfo( const UniSetTypes::SensorMessage* sm ) override {}
virtual void timerInfo( const UniSetTypes::TimerMessage* tm ) override{} virtual void timerInfo( const UniSetTypes::TimerMessage* tm ) override {}
virtual void sigterm( int signo ) override; virtual void sigterm( int signo ) override;
virtual bool activateObject() override; virtual bool activateObject() override;
virtual std::string getMonitInfo(){ return ""; } /*!< пользовательская информация выводимая в getInfo() */ virtual std::string getMonitInfo()
{
return ""; /*!< пользовательская информация выводимая в getInfo() */
}
virtual void testMode( bool state ); virtual void testMode( bool state );
void updatePreviousValues(); void updatePreviousValues();
...@@ -171,7 +183,7 @@ class UObject_SK: ...@@ -171,7 +183,7 @@ class UObject_SK:
int resetMsgTime; int resetMsgTime;
// Выполнение очередного шага программы // Выполнение очередного шага программы
virtual void step(){} virtual void step() {}
int sleep_msec; /*!< пауза между итерациями */ int sleep_msec; /*!< пауза между итерациями */
bool active; bool active;
...@@ -186,9 +198,15 @@ class UObject_SK: ...@@ -186,9 +198,15 @@ class UObject_SK:
xmlNode* confnode; xmlNode* confnode;
/*! получить числовое свойство из конф. файла по привязанной confnode */ /*! получить числовое свойство из конф. файла по привязанной confnode */
int getIntProp(const std::string& name) { return UniSetTypes::uniset_conf()->getIntProp(confnode, name); } int getIntProp(const std::string& name)
{
return UniSetTypes::uniset_conf()->getIntProp(confnode, name);
}
/*! получить текстовое свойство из конф. файла по привязанной confnode */ /*! получить текстовое свойство из конф. файла по привязанной confnode */
inline const std::string getProp(const std::string& name) { return UniSetTypes::uniset_conf()->getProp(confnode, name); } inline const std::string getProp(const std::string& name)
{
return UniSetTypes::uniset_conf()->getProp(confnode, name);
}
timeout_t smReadyTimeout; /*!< время ожидания готовности SM */ timeout_t smReadyTimeout; /*!< время ожидания готовности SM */
std::atomic_bool activated; std::atomic_bool activated;
......
...@@ -32,26 +32,26 @@ using namespace UniSetTypes; ...@@ -32,26 +32,26 @@ using namespace UniSetTypes;
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
UObject_SK::UObject_SK(): UObject_SK::UObject_SK():
// Инициализация идентификаторов (имена берутся из конф. файла) // Инициализация идентификаторов (имена берутся из конф. файла)
// Используемые идентификаторы сообщений (имена берутся из конф. файла) // Используемые идентификаторы сообщений (имена берутся из конф. файла)
// variables // variables
active(false), active(false),
idHeartBeat(DefaultObjectId), idHeartBeat(DefaultObjectId),
maxHeartBeat(10), maxHeartBeat(10),
confnode(0), confnode(0),
smReadyTimeout(0), smReadyTimeout(0),
activated(false), activated(false),
askPause(2000), askPause(2000),
forceOut(false), forceOut(false),
end_private(false) end_private(false)
{ {
ucrit << "UObject: init failed!!!!!!!!!!!!!!!" << endl; ucrit << "UObject: init failed!!!!!!!!!!!!!!!" << endl;
throw Exception( string(myname+": init failed!!!") ); throw Exception( string(myname + ": init failed!!!") );
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// ( val, confval, default val ) // ( val, confval, default val )
...@@ -59,6 +59,7 @@ static const std::string init3_str( const std::string& s1, const std::string& s2 ...@@ -59,6 +59,7 @@ static const std::string init3_str( const std::string& s1, const std::string& s2
{ {
if( !s1.empty() ) if( !s1.empty() )
return s1; return s1;
if( !s2.empty() ) if( !s2.empty() )
return s2; return s2;
...@@ -66,34 +67,34 @@ static const std::string init3_str( const std::string& s1, const std::string& s2 ...@@ -66,34 +67,34 @@ static const std::string init3_str( const std::string& s1, const std::string& s2
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
UObject_SK::UObject_SK( ObjectId id, xmlNode* cnode, const std::string& _argprefix ): UObject_SK::UObject_SK( ObjectId id, xmlNode* cnode, const std::string& _argprefix ):
UniSetObject(id), UniSetObject(id),
// Инициализация идентификаторов (имена берутся из конф. файла) // Инициализация идентификаторов (имена берутся из конф. файла)
// Используемые идентификаторы сообщений (имена берутся из конф. файла) // Используемые идентификаторы сообщений (имена берутся из конф. файла)
// variables // variables
sleep_msec(150), sleep_msec(150),
active(true), active(true),
argprefix( (_argprefix.empty() ? myname+"-" : _argprefix) ), argprefix( (_argprefix.empty() ? myname + "-" : _argprefix) ),
idHeartBeat(DefaultObjectId), idHeartBeat(DefaultObjectId),
maxHeartBeat(10), maxHeartBeat(10),
confnode(cnode), confnode(cnode),
smReadyTimeout(0), smReadyTimeout(0),
activated(false), activated(false),
askPause(uniset_conf()->getPIntProp(cnode,"askPause",2000)), askPause(uniset_conf()->getPIntProp(cnode, "askPause", 2000)),
forceOut(false), forceOut(false),
end_private(false) end_private(false)
{ {
auto conf = uniset_conf(); auto conf = uniset_conf();
if( UniSetTypes::findArgParam("--print-id-list",uniset_conf()->getArgc(),uniset_conf()->getArgv()) != -1 ) if( UniSetTypes::findArgParam("--print-id-list", uniset_conf()->getArgc(), uniset_conf()->getArgv()) != -1 )
{ {
// abort(); // abort();
} }
...@@ -109,10 +110,10 @@ end_private(false) ...@@ -109,10 +110,10 @@ end_private(false)
{ {
ostringstream s; ostringstream s;
s << argprefix << "log"; s << argprefix << "log";
conf->initLogStream(mylog,s.str()); conf->initLogStream(mylog, s.str());
} }
loga = make_shared<LogAgregator>(myname+"-loga"); loga = make_shared<LogAgregator>(myname + "-loga");
loga->add(mylog); loga->add(mylog);
loga->add(ulog()); loga->add(ulog());
...@@ -130,12 +131,14 @@ end_private(false) ...@@ -130,12 +131,14 @@ end_private(false)
logserv_port = conf->getArgPInt("--" + argprefix + "logserver-port", it.getProp("logserverPort"), getId()); logserv_port = conf->getArgPInt("--" + argprefix + "logserver-port", it.getProp("logserverPort"), getId());
} }
forceOut = conf->getArgPInt("--" + argprefix + "force-out",it.getProp("forceOut"),false); forceOut = conf->getArgPInt("--" + argprefix + "force-out", it.getProp("forceOut"), false);
string heart = conf->getArgParam("--" + argprefix + "heartbeat-id", it.getProp("heartbeat_id"));
string heart = conf->getArgParam("--" + argprefix + "heartbeat-id",it.getProp("heartbeat_id"));
if( !heart.empty() ) if( !heart.empty() )
{ {
idHeartBeat = conf->getSensorID(heart); idHeartBeat = conf->getSensorID(heart);
if( idHeartBeat == DefaultObjectId ) if( idHeartBeat == DefaultObjectId )
{ {
ostringstream err; ostringstream err;
...@@ -143,13 +146,14 @@ end_private(false) ...@@ -143,13 +146,14 @@ end_private(false)
throw SystemError(err.str()); throw SystemError(err.str());
} }
int heartbeatTime = conf->getArgPInt("--" + argprefix + "heartbeat-time",it.getProp("heartbeatTime"),conf->getHeartBeatTime()); int heartbeatTime = conf->getArgPInt("--" + argprefix + "heartbeat-time", it.getProp("heartbeatTime"), conf->getHeartBeatTime());
if( heartbeatTime>0 )
if( heartbeatTime > 0 )
ptHeartBeat.setTiming(heartbeatTime); ptHeartBeat.setTiming(heartbeatTime);
else else
ptHeartBeat.setTiming(UniSetTimer::WaitUpTime); ptHeartBeat.setTiming(UniSetTimer::WaitUpTime);
maxHeartBeat = conf->getArgPInt("--" + argprefix + "heartbeat-max",it.getProp("heartbeat_max"), 10); maxHeartBeat = conf->getArgPInt("--" + argprefix + "heartbeat-max", it.getProp("heartbeat_max"), 10);
} }
// Инициализация значений // Инициализация значений
...@@ -158,16 +162,18 @@ end_private(false) ...@@ -158,16 +162,18 @@ end_private(false)
si.id = UniSetTypes::DefaultObjectId; si.id = UniSetTypes::DefaultObjectId;
si.node = conf->getLocalNode(); si.node = conf->getLocalNode();
sleep_msec = conf->getArgPInt("--" + argprefix + "sleep-msec","150", 150); sleep_msec = conf->getArgPInt("--" + argprefix + "sleep-msec", "150", 150);
string s_resetTime(""); string s_resetTime("");
if( s_resetTime.empty() ) if( s_resetTime.empty() )
s_resetTime = "500"; s_resetTime = "500";
resetMsgTime = uni_atoi(init3_str(conf->getArgParam("--" + argprefix + "resetMsgTime"),conf->getProp(cnode,"resetMsgTime"),s_resetTime)); resetMsgTime = uni_atoi(init3_str(conf->getArgParam("--" + argprefix + "resetMsgTime"), conf->getProp(cnode, "resetMsgTime"), s_resetTime));
ptResetMsg.setTiming(resetMsgTime); ptResetMsg.setTiming(resetMsgTime);
int sm_tout = conf->getArgInt("--" + argprefix + "sm-ready-timeout",""); int sm_tout = conf->getArgInt("--" + argprefix + "sm-ready-timeout", "");
if( sm_tout == 0 ) if( sm_tout == 0 )
smReadyTimeout = 60000; smReadyTimeout = 60000;
else if( sm_tout < 0 ) else if( sm_tout < 0 )
...@@ -175,7 +181,7 @@ end_private(false) ...@@ -175,7 +181,7 @@ end_private(false)
else else
smReadyTimeout = sm_tout; smReadyTimeout = sm_tout;
smTestID = conf->getSensorID(init3_str(conf->getArgParam("--" + argprefix + "sm-test-id"),conf->getProp(cnode,"smTestID"),"")); smTestID = conf->getSensorID(init3_str(conf->getArgParam("--" + argprefix + "sm-test-id"), conf->getProp(cnode, "smTestID"), ""));
activateTimeout = conf->getArgPInt("--" + argprefix + "activate-timeout", 20000); activateTimeout = conf->getArgPInt("--" + argprefix + "activate-timeout", 20000);
...@@ -245,7 +251,7 @@ bool UObject_SK::setMsg( UniSetTypes::ObjectId _code, bool _state ) ...@@ -245,7 +251,7 @@ bool UObject_SK::setMsg( UniSetTypes::ObjectId _code, bool _state )
void UObject_SK::resetMsg() void UObject_SK::resetMsg()
{ {
mylog8 << myname << "(resetMsg): reset messages.." << endl; mylog8 << myname << "(resetMsg): reset messages.." << endl;
// reset messages // reset messages
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
...@@ -273,19 +279,23 @@ std::string UObject_SK::dumpIO() ...@@ -273,19 +279,23 @@ std::string UObject_SK::dumpIO()
s << endl; s << endl;
int n = 0; int n = 0;
for( const auto& e: v_in )
for( const auto& e : v_in )
{ {
s << e; s << e;
if( (n++)%2 )
if( (n++) % 2 )
s << std::endl; s << std::endl;
} }
s << endl; s << endl;
n = 0; n = 0;
for( const auto& e: v_out )
for( const auto& e : v_out )
{ {
s << e; s << e;
if( (n++)%2 )
if( (n++) % 2 )
s << std::endl; s << std::endl;
} }
...@@ -349,11 +359,13 @@ void UObject_SK::preSysCommand( const SystemMessage* _sm ) ...@@ -349,11 +359,13 @@ void UObject_SK::preSysCommand( const SystemMessage* _sm )
{ {
case SystemMessage::WatchDog: case SystemMessage::WatchDog:
uinfo << myname << "(preSysCommand): WatchDog" << endl; uinfo << myname << "(preSysCommand): WatchDog" << endl;
if( !active || !ptStartUpTimeout.checkTime() ) if( !active || !ptStartUpTimeout.checkTime() )
{ {
uwarn << myname << "(preSysCommand): игнорируем WatchDog, потому-что только-что стартанули" << endl; uwarn << myname << "(preSysCommand): игнорируем WatchDog, потому-что только-что стартанули" << endl;
break; break;
} }
case SystemMessage::StartUp: case SystemMessage::StartUp:
{ {
if( !logserv_host.empty() && logserv_port != 0 && !logserv->isRunning() ) if( !logserv_host.empty() && logserv_port != 0 && !logserv->isRunning() )
...@@ -386,9 +398,10 @@ void UObject_SK::preSysCommand( const SystemMessage* _sm ) ...@@ -386,9 +398,10 @@ void UObject_SK::preSysCommand( const SystemMessage* _sm )
// переоткрываем логи // переоткрываем логи
mylogany << myname << "(preSysCommand): logRotate" << endl; mylogany << myname << "(preSysCommand): logRotate" << endl;
string fname( log()->getLogFile() ); string fname( log()->getLogFile() );
if( !fname.empty() ) if( !fname.empty() )
{ {
mylog->logFile(fname.c_str(),true); mylog->logFile(fname.c_str(), true);
mylogany << myname << "(preSysCommand): ***************** mylog LOG ROTATE *****************" << endl; mylogany << myname << "(preSysCommand): ***************** mylog LOG ROTATE *****************" << endl;
} }
} }
...@@ -414,14 +427,16 @@ UniSetTypes::SimpleInfo* UObject_SK::getInfo( CORBA::Long userparam ) ...@@ -414,14 +427,16 @@ UniSetTypes::SimpleInfo* UObject_SK::getInfo( CORBA::Long userparam )
inf << endl; inf << endl;
auto timers = getTimersList(); auto timers = getTimersList();
inf << "Timers[" << timers.size() << "]:" << endl; inf << "Timers[" << timers.size() << "]:" << endl;
for( const auto& t: timers )
for( const auto& t : timers )
{ {
inf << " " << setw(15) << getTimerName(t.id) << "[" << t.id << "]: msec=" inf << " " << setw(15) << getTimerName(t.id) << "[" << t.id << "]: msec="
<< setw(6) << t.tmr.getInterval() << setw(6) << t.tmr.getInterval()
<< " timeleft=" << setw(6) << t.curTimeMS << " timeleft=" << setw(6) << t.curTimeMS
<< " tick=" << setw(3) << ( t.curTick>=0 ? t.curTick : -1 ) << " tick=" << setw(3) << ( t.curTick >= 0 ? t.curTick : -1 )
<< endl; << endl;
} }
inf << endl; inf << endl;
inf << vmon.pretty_str() << endl; inf << vmon.pretty_str() << endl;
inf << endl; inf << endl;
...@@ -474,7 +489,7 @@ void UObject_SK::waitSM( int wait_msec, ObjectId _testID ) ...@@ -474,7 +489,7 @@ void UObject_SK::waitSM( int wait_msec, ObjectId _testID )
<< wait_msec << " msec" << wait_msec << " msec"
<< " testID=" << _testID << endl; << " testID=" << _testID << endl;
if( !ui->waitReady(_testID,wait_msec) ) if( !ui->waitReady(_testID, wait_msec) )
{ {
ostringstream err; ostringstream err;
err << myname err << myname
...@@ -482,11 +497,11 @@ void UObject_SK::waitSM( int wait_msec, ObjectId _testID ) ...@@ -482,11 +497,11 @@ void UObject_SK::waitSM( int wait_msec, ObjectId _testID )
<< wait_msec << " мсек"; << wait_msec << " мсек";
ucrit << err.str() << endl; ucrit << err.str() << endl;
// terminate(); // terminate();
// abort(); // abort();
raise(SIGTERM); raise(SIGTERM);
terminate(); terminate();
// throw SystemError(err.str()); // throw SystemError(err.str());
} }
...@@ -506,37 +521,39 @@ void UObject_SK::callback() ...@@ -506,37 +521,39 @@ void UObject_SK::callback()
{ {
if( !active ) if( !active )
return; return;
try try
{ {
// проверка таймеров // проверка таймеров
checkTimers(this); checkTimers(this);
if( resetMsgTime>0 && trResetMsg.hi(ptResetMsg.checkTime()) ) if( resetMsgTime > 0 && trResetMsg.hi(ptResetMsg.checkTime()) )
{ {
// cout << myname << ": ********* reset messages *********" << endl; // cout << myname << ": ********* reset messages *********" << endl;
resetMsg(); resetMsg();
} }
// обработка сообщений (таймеров и т.п.) // обработка сообщений (таймеров и т.п.)
for( unsigned int i=0; i<20; i++ ) for( unsigned int i = 0; i < 20; i++ )
{ {
if( !receiveMessage(msg) ) if( !receiveMessage(msg) )
break; break;
processingMessage(&msg); processingMessage(&msg);
updateOutputs(forceOut); updateOutputs(forceOut);
// updatePreviousValues(); // updatePreviousValues();
} }
// Выполнение шага программы // Выполнение шага программы
step(); step();
// "сердцебиение" // "сердцебиение"
if( idHeartBeat!=DefaultObjectId && ptHeartBeat.checkTime() ) if( idHeartBeat != DefaultObjectId && ptHeartBeat.checkTime() )
{ {
try try
{ {
ui->setValue(idHeartBeat,maxHeartBeat); ui->setValue(idHeartBeat, maxHeartBeat);
ptHeartBeat.reset(); ptHeartBeat.reset();
} }
catch( const Exception& ex ) catch( const Exception& ex )
...@@ -558,7 +575,7 @@ void UObject_SK::callback() ...@@ -558,7 +575,7 @@ void UObject_SK::callback()
ucrit << myname << "(execute): СORBA::SystemException: " ucrit << myname << "(execute): СORBA::SystemException: "
<< ex.NP_minorString() << endl; << ex.NP_minorString() << endl;
} }
catch( const std::exception&ex ) catch( const std::exception& ex )
{ {
ucrit << myname << "(execute): catch " << ex.what() << endl; ucrit << myname << "(execute): catch " << ex.what() << endl;
} }
...@@ -576,7 +593,7 @@ void UObject_SK::setValue( UniSetTypes::ObjectId _sid, long _val ) ...@@ -576,7 +593,7 @@ void UObject_SK::setValue( UniSetTypes::ObjectId _sid, long _val )
ui->setValue(_sid,_val); ui->setValue(_sid, _val);
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
void UObject_SK::updateOutputs( bool _force ) void UObject_SK::updateOutputs( bool _force )
...@@ -598,7 +615,7 @@ void UObject_SK::initFromSM() ...@@ -598,7 +615,7 @@ void UObject_SK::initFromSM()
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
void UObject_SK::askSensor( UniSetTypes::ObjectId _sid, UniversalIO::UIOCommand _cmd, UniSetTypes::ObjectId _node ) void UObject_SK::askSensor( UniSetTypes::ObjectId _sid, UniversalIO::UIOCommand _cmd, UniSetTypes::ObjectId _node )
{ {
ui->askRemoteSensor(_sid,_cmd,_node,getId()); ui->askRemoteSensor(_sid, _cmd, _node, getId());
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
long UObject_SK::getValue( UniSetTypes::ObjectId _sid ) long UObject_SK::getValue( UniSetTypes::ObjectId _sid )
...@@ -620,10 +637,12 @@ long UObject_SK::getValue( UniSetTypes::ObjectId _sid ) ...@@ -620,10 +637,12 @@ long UObject_SK::getValue( UniSetTypes::ObjectId _sid )
void UObject_SK::preAskSensors( UniversalIO::UIOCommand _cmd ) void UObject_SK::preAskSensors( UniversalIO::UIOCommand _cmd )
{ {
PassiveTimer ptAct(activateTimeout); PassiveTimer ptAct(activateTimeout);
while( !activated && !ptAct.checkTime() ) while( !activated && !ptAct.checkTime() )
{ {
cout << myname << "(preAskSensors): wait activate..." << endl; cout << myname << "(preAskSensors): wait activate..." << endl;
msleep(300); msleep(300);
if( activated ) if( activated )
break; break;
} }
...@@ -643,7 +662,7 @@ void UObject_SK::preAskSensors( UniversalIO::UIOCommand _cmd ) ...@@ -643,7 +662,7 @@ void UObject_SK::preAskSensors( UniversalIO::UIOCommand _cmd )
{ {
ucrit << myname << "(preAskSensors): " << ex << endl; ucrit << myname << "(preAskSensors): " << ex << endl;
} }
catch( const std::exception&ex ) catch( const std::exception& ex )
{ {
ucrit << myname << "(execute): catch " << ex.what() << endl; ucrit << myname << "(execute): catch " << ex.what() << endl;
} }
......
...@@ -82,7 +82,11 @@ struct DBInterfaceDeleter ...@@ -82,7 +82,11 @@ struct DBInterfaceDeleter
{ {
void operator()(DBInterface* p) const void operator()(DBInterface* p) const
{ {
try{ delete p; } catch(...) {} try
{
delete p;
}
catch(...) {}
} }
}; };
// ---------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------
......
...@@ -196,7 +196,10 @@ class LT_Object ...@@ -196,7 +196,10 @@ class LT_Object
TimersList getTimersList(); TimersList getTimersList();
/*! пользовательская функция для вывода названия таймера */ /*! пользовательская функция для вывода названия таймера */
virtual std::string getTimerName( int id ){ return ""; } virtual std::string getTimerName( int id )
{
return "";
}
private: private:
TimersList tlst; TimersList tlst;
......
...@@ -78,8 +78,14 @@ class ModbusTCPServer: ...@@ -78,8 +78,14 @@ class ModbusTCPServer:
void getSessions( Sessions& lst ); void getSessions( Sessions& lst );
inline ost::InetAddress getInetAddress(){ return iaddr; } inline ost::InetAddress getInetAddress()
inline ost::tpport_t getInetPort(){ return port; } {
return iaddr;
}
inline ost::tpport_t getInetPort()
{
return port;
}
protected: protected:
......
...@@ -868,14 +868,15 @@ IONotifyController_i::ThresholdList* IONotifyController::getThresholds( UniSetTy ...@@ -868,14 +868,15 @@ IONotifyController_i::ThresholdList* IONotifyController::getThresholds( UniSetTy
<< uniset_conf()->oind->getNameById(it->second.si.id) << uniset_conf()->oind->getNameById(it->second.si.id)
<< " " << ex << endl; << " " << ex << endl;
} }
/*
/*
catch( const IOController_i::NameNotFound& ex ) catch( const IOController_i::NameNotFound& ex )
{ {
uwarn << myname << "(getThresholds): IOController_i::NameNotFound.. for sid" uwarn << myname << "(getThresholds): IOController_i::NameNotFound.. for sid"
<< uniset_conf()->oind->getNameById(it->second.si.id) << uniset_conf()->oind->getNameById(it->second.si.id)
<< endl; << endl;
} }
*/ */
res->tlist.length( it->second.list.size() ); res->tlist.length( it->second.list.size() );
unsigned int k = 0; unsigned int k = 0;
...@@ -911,7 +912,7 @@ IONotifyController_i::ThresholdsListSeq* IONotifyController::getThresholdsList() ...@@ -911,7 +912,7 @@ IONotifyController_i::ThresholdsListSeq* IONotifyController::getThresholdsList()
try try
{ {
(*res)[i].si = it->second.si; (*res)[i].si = it->second.si;
(*res)[i].value = IOController::localGetValue(it->second.ait,it->second.si.id); (*res)[i].value = IOController::localGetValue(it->second.ait, it->second.si.id);
(*res)[i].type = it->second.type; (*res)[i].type = it->second.type;
} }
catch( const std::exception& ex ) catch( const std::exception& ex )
......
...@@ -125,7 +125,7 @@ void NCRestorer::addthresholdlist( IONotifyController* ic, std::shared_ptr<IOCon ...@@ -125,7 +125,7 @@ void NCRestorer::addthresholdlist( IONotifyController* ic, std::shared_ptr<IOCon
auto i = ic->find(inf->si.id); auto i = ic->find(inf->si.id);
ic->askTMap[inf->si.id].ait = i->second; ic->askTMap[inf->si.id].ait = i->second;
} }
catch(...){} catch(...) {}
ic->askTMap[inf->si.id].si = inf->si; ic->askTMap[inf->si.id].si = inf->si;
ic->askTMap[inf->si.id].type = inf->type; ic->askTMap[inf->si.id].type = inf->type;
......
...@@ -6,22 +6,26 @@ bool DBNetInterface::connect( const std::string& param ) ...@@ -6,22 +6,26 @@ bool DBNetInterface::connect( const std::string& param )
std::string user = ""; std::string user = "";
std::string pswd = ""; std::string pswd = "";
std::string dbname = ""; std::string dbname = "";
for(;;) for(;;)
{ {
std::string::size_type pos = param.find_first_of("@"); std::string::size_type pos = param.find_first_of("@");
user = param.substr(0, pos); user = param.substr(0, pos);
if( pos == std::string::npos ) if( pos == std::string::npos )
break; break;
std::string::size_type prev = pos + 1; std::string::size_type prev = pos + 1;
pos = param.find_first_of(":", prev); pos = param.find_first_of(":", prev);
host = param.substr(prev, pos - prev); host = param.substr(prev, pos - prev);
if( pos == std::string::npos ) if( pos == std::string::npos )
break; break;
prev = pos + 1; prev = pos + 1;
pos = param.find_first_of(":", prev); pos = param.find_first_of(":", prev);
pswd = param.substr(prev, pos - prev); pswd = param.substr(prev, pos - prev);
if( pos == std::string::npos ) if( pos == std::string::npos )
break; break;
......
...@@ -199,7 +199,7 @@ timeout_t LT_Object::askTimer( UniSetTypes::TimerId timerid, timeout_t timeMS, c ...@@ -199,7 +199,7 @@ timeout_t LT_Object::askTimer( UniSetTypes::TimerId timerid, timeout_t timeMS, c
} // unlock } // unlock
uinfo << "(LT_askTimer): поступил заказ на таймер([" << timerid << "]" uinfo << "(LT_askTimer): поступил заказ на таймер([" << timerid << "]"
<< getTimerName(timerid) <<") " << timeMS << " [мс]\n"; << getTimerName(timerid) << ") " << timeMS << " [мс]\n";
} }
else // отказ (при timeMS == 0) else // отказ (при timeMS == 0)
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment