You need to sign in or sign up before continuing.
Commit ea2e7544 authored by Pavel Vainerman's avatar Pavel Vainerman

(Global): глобальный рефакторинг работы с логами.

Встроил LogServer (для возможности удалённого чтения логов) во все главные компоненты: SharedMemory,MBMaster,MBSlave,IOControl,UNetExchange,RRDServer
parent bef704d0
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
Name: libuniset2 Name: libuniset2
Version: 2.0 Version: 2.0
Release: alt34.4 Release: alt35
Summary: UniSet - library for building distributed industrial control systems Summary: UniSet - library for building distributed industrial control systems
...@@ -445,6 +445,9 @@ mv -f %buildroot%python_sitelibdir_noarch/* %buildroot%python_sitelibdir/%oname ...@@ -445,6 +445,9 @@ mv -f %buildroot%python_sitelibdir_noarch/* %buildroot%python_sitelibdir/%oname
# .. # ..
%changelog %changelog
* Sun May 24 2015 Pavel Vainerman <pv@altlinux.ru> 2.0-alt35
- add supported LogServer for: SharedMemory,RRDServer,MBTCPMaster,MBSlave,UNetExchange,IOControl
* Wed May 20 2015 Pavel Vainerman <pv@altlinux.ru> 2.0-alt34.4 * Wed May 20 2015 Pavel Vainerman <pv@altlinux.ru> 2.0-alt34.4
- (ModbusSlave): fixed bug in much_real_write (again) (thank`s hd@nio14) - (ModbusSlave): fixed bug in much_real_write (again) (thank`s hd@nio14)
- (DelayTimer): fixed critical bug in logic (thank`s ilyap@etersoft.ru) - (DelayTimer): fixed critical bug in logic (thank`s ilyap@etersoft.ru)
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
#include "UniSetTypes.h" #include "UniSetTypes.h"
#include "Extensions.h" #include "Extensions.h"
#include "IOControl.h" #include "IOControl.h"
#include "IOLogSugar.h"
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
using namespace std; using namespace std;
using namespace UniSetTypes; using namespace UniSetTypes;
...@@ -57,14 +58,31 @@ IOControl::IOControl( UniSetTypes::ObjectId id, UniSetTypes::ObjectId icID, ...@@ -57,14 +58,31 @@ IOControl::IOControl( UniSetTypes::ObjectId id, UniSetTypes::ObjectId icID,
if( cnode == NULL ) if( cnode == NULL )
throw SystemError("Not found conf-node " + cname + " for " + myname); throw SystemError("Not found conf-node " + cname + " for " + myname);
iolog = make_shared<DebugStream>();
iolog->setLogName(myname);
conf->initLogStream(iolog,prefix+"-log");
loga = make_shared<LogAgregator>();
loga->add(iolog);
loga->add(ulog());
loga->add(dlog());
defCardNum = conf->getArgInt("--" + prefix + "-default-cardnum", "-1"); defCardNum = conf->getArgInt("--" + prefix + "-default-cardnum", "-1");
maxCardNum = conf->getArgInt("--" + prefix + "-max-cardnum", "10"); maxCardNum = conf->getArgInt("--" + prefix + "-max-cardnum", "10");
cards.resize(maxCardNum + 1); cards.resize(maxCardNum + 1);
dinfo << myname << "(init): numcards=" << numcards << endl; ioinfo << myname << "(init): numcards=" << numcards << endl;
UniXML::iterator it(cnode); UniXML::iterator it(cnode);
logserv = make_shared<LogServer>(loga);
logserv->init( prefix+"-logserver", cnode );
if( findArgParam("--" + prefix + "-run-logserver", conf->getArgc(), conf->getArgv()) != -1 )
{
logserv_host = conf->getArg2Param("--" + prefix + "-logserver-host", it.getProp("logserverHost"), "localhost");
logserv_port = conf->getArgPInt("--" + prefix + "-logserver-port", it.getProp("logserverPort"), getId());
}
noCards = true; noCards = true;
for( unsigned int i = 1; i < cards.size(); i++ ) for( unsigned int i = 1; i < cards.size(); i++ )
...@@ -88,7 +106,7 @@ IOControl::IOControl( UniSetTypes::ObjectId id, UniSetTypes::ObjectId icID, ...@@ -88,7 +106,7 @@ IOControl::IOControl( UniSetTypes::ObjectId id, UniSetTypes::ObjectId icID,
{ {
if( cards[i] == NULL ) if( cards[i] == NULL )
{ {
dlog3 << myname << "(init): Card N" << i iolog3 << myname << "(init): Card N" << i
<< " DISABLED! dev='" << " DISABLED! dev='"
<< iodev << "'" << endl; << iodev << "'" << endl;
} }
...@@ -97,7 +115,7 @@ IOControl::IOControl( UniSetTypes::ObjectId id, UniSetTypes::ObjectId icID, ...@@ -97,7 +115,7 @@ IOControl::IOControl( UniSetTypes::ObjectId id, UniSetTypes::ObjectId icID,
{ {
noCards = false; noCards = false;
cards[i] = new ComediInterface(iodev); cards[i] = new ComediInterface(iodev);
dlog3 << myname << "(init): ADD card" << i << " dev=" << iodev << endl; iolog3 << myname << "(init): ADD card" << i << " dev=" << iodev << endl;
} }
if( cards[i] != NULL ) if( cards[i] != NULL )
...@@ -122,7 +140,7 @@ IOControl::IOControl( UniSetTypes::ObjectId id, UniSetTypes::ObjectId icID, ...@@ -122,7 +140,7 @@ IOControl::IOControl( UniSetTypes::ObjectId id, UniSetTypes::ObjectId icID,
if( !stype.empty() ) if( !stype.empty() )
{ {
dinfo << myname ioinfo << myname
<< "(init): card" << i << "(init): card" << i
<< " subdev" << s << " set type " << stype << endl; << " subdev" << s << " set type " << stype << endl;
...@@ -133,7 +151,7 @@ IOControl::IOControl( UniSetTypes::ObjectId id, UniSetTypes::ObjectId icID, ...@@ -133,7 +151,7 @@ IOControl::IOControl( UniSetTypes::ObjectId id, UniSetTypes::ObjectId icID,
} }
} }
dinfo << myname << "(init): result numcards=" << cards.size() << endl; ioinfo << myname << "(init): result numcards=" << cards.size() << endl;
polltime = conf->getArgInt("--" + prefix + "-polltime", it.getProp("polltime")); polltime = conf->getArgInt("--" + prefix + "-polltime", it.getProp("polltime"));
...@@ -157,11 +175,11 @@ IOControl::IOControl( UniSetTypes::ObjectId id, UniSetTypes::ObjectId icID, ...@@ -157,11 +175,11 @@ IOControl::IOControl( UniSetTypes::ObjectId id, UniSetTypes::ObjectId icID,
{ {
ostringstream err; ostringstream err;
err << myname << ": Unkown ID for " << testlamp; err << myname << ": Unkown ID for " << testlamp;
dcrit << myname << "(init): " << err.str() << endl; iocrit << myname << "(init): " << err.str() << endl;
throw SystemError(err.str()); throw SystemError(err.str());
} }
dinfo << myname << "(init): testLamp_S='" << testlamp << "'" << endl; ioinfo << myname << "(init): testLamp_S='" << testlamp << "'" << endl;
} }
string tmode = conf->getArgParam("--" + prefix + "-test-mode", it.getProp("testmode_as")); string tmode = conf->getArgParam("--" + prefix + "-test-mode", it.getProp("testmode_as"));
...@@ -174,11 +192,11 @@ IOControl::IOControl( UniSetTypes::ObjectId id, UniSetTypes::ObjectId icID, ...@@ -174,11 +192,11 @@ IOControl::IOControl( UniSetTypes::ObjectId id, UniSetTypes::ObjectId icID,
{ {
ostringstream err; ostringstream err;
err << myname << ": Unknown ID for " << tmode; err << myname << ": Unknown ID for " << tmode;
dcrit << myname << "(init): " << err.str() << endl; iocrit << myname << "(init): " << err.str() << endl;
throw SystemError(err.str()); throw SystemError(err.str());
} }
dinfo << myname << "(init): testMode_as='" << testmode << "'" << endl; ioinfo << myname << "(init): testMode_as='" << testmode << "'" << endl;
} }
shm = make_shared<SMInterface>(icID, ui, myid, ic); shm = make_shared<SMInterface>(icID, ui, myid, ic);
...@@ -187,7 +205,7 @@ IOControl::IOControl( UniSetTypes::ObjectId id, UniSetTypes::ObjectId icID, ...@@ -187,7 +205,7 @@ IOControl::IOControl( UniSetTypes::ObjectId id, UniSetTypes::ObjectId icID,
s_field = conf->getArgParam("--" + prefix + "-s-filter-field"); s_field = conf->getArgParam("--" + prefix + "-s-filter-field");
s_fvalue = conf->getArgParam("--" + prefix + "-s-filter-value"); s_fvalue = conf->getArgParam("--" + prefix + "-s-filter-value");
dinfo << myname << "(init): read s_field='" << s_field ioinfo << myname << "(init): read s_field='" << s_field
<< "' s_fvalue='" << s_fvalue << "'" << endl; << "' s_fvalue='" << s_fvalue << "'" << endl;
int blink_msec = conf->getArgPInt("--" + prefix + "-blink-time", it.getProp("blink-time"), 300); int blink_msec = conf->getArgPInt("--" + prefix + "-blink-time", it.getProp("blink-time"), 300);
...@@ -213,12 +231,12 @@ IOControl::IOControl( UniSetTypes::ObjectId id, UniSetTypes::ObjectId icID, ...@@ -213,12 +231,12 @@ IOControl::IOControl( UniSetTypes::ObjectId id, UniSetTypes::ObjectId icID,
if( sidTestSMReady == DefaultObjectId ) if( sidTestSMReady == DefaultObjectId )
{ {
sidTestSMReady = conf->getSensorID("TestMode_S"); sidTestSMReady = conf->getSensorID("TestMode_S");
dwarn << myname iowarn << myname
<< "(init): Unknown ID for sm-ready-test-sid (--" << prefix << "-sm-ready-test-sid)." << "(init): Unknown ID for sm-ready-test-sid (--" << prefix << "-sm-ready-test-sid)."
<< " Use 'TestMode_S'" << endl; << " Use 'TestMode_S'" << endl;
} }
else else
dinfo << myname << "(init): test-sid: " << sm_ready_sid << endl; ioinfo << myname << "(init): test-sid: " << sm_ready_sid << endl;
// ----------------------- // -----------------------
...@@ -232,7 +250,7 @@ IOControl::IOControl( UniSetTypes::ObjectId id, UniSetTypes::ObjectId icID, ...@@ -232,7 +250,7 @@ IOControl::IOControl( UniSetTypes::ObjectId id, UniSetTypes::ObjectId icID,
{ {
ostringstream err; ostringstream err;
err << myname << ": Not found ID for 'HeartBeat' " << heart; err << myname << ": Not found ID for 'HeartBeat' " << heart;
dcrit << myname << "(init): " << err.str() << endl; iocrit << myname << "(init): " << err.str() << endl;
throw SystemError(err.str()); throw SystemError(err.str());
} }
...@@ -295,7 +313,7 @@ void IOControl::execute() ...@@ -295,7 +313,7 @@ void IOControl::execute()
} }
maxHalf = maxItem / 2; maxHalf = maxItem / 2;
dinfo << myname << "(init): iomap size = " << iomap.size() << endl; ioinfo << myname << "(init): iomap size = " << iomap.size() << endl;
//cerr << myname << "(iomap size): " << iomap.size() << endl; //cerr << myname << "(iomap size): " << iomap.size() << endl;
...@@ -326,7 +344,7 @@ void IOControl::execute() ...@@ -326,7 +344,7 @@ void IOControl::execute()
} }
if( !activated ) if( !activated )
dcrit << myname << "(execute): ************* don`t activate?! ************" << endl; iocrit << myname << "(execute): ************* don`t activate?! ************" << endl;
try try
{ {
...@@ -398,16 +416,16 @@ void IOControl::execute() ...@@ -398,16 +416,16 @@ void IOControl::execute()
} }
catch( const Exception& ex ) catch( const Exception& ex )
{ {
dlog3 << myname << "(execute): " << ex << endl; iolog3 << myname << "(execute): " << ex << endl;
} }
catch( const CORBA::SystemException& ex ) catch( const CORBA::SystemException& ex )
{ {
dlog3 << myname << "(execute): CORBA::SystemException: " iolog3 << myname << "(execute): CORBA::SystemException: "
<< ex.NP_minorString() << endl; << ex.NP_minorString() << endl;
} }
catch(...) catch(...)
{ {
dlog3 << myname << "(execute): catch ..." << endl; iolog3 << myname << "(execute): catch ..." << endl;
} }
if( term ) if( term )
...@@ -507,7 +525,7 @@ void IOControl::ioread( IOInfo* it ) ...@@ -507,7 +525,7 @@ void IOControl::ioread( IOInfo* it )
if( it->si.id == DefaultObjectId ) if( it->si.id == DefaultObjectId )
{ {
dlog3 << myname << "(iopoll): sid=DefaultObjectId?!" << endl; iolog3 << myname << "(iopoll): sid=DefaultObjectId?!" << endl;
return; return;
} }
...@@ -519,7 +537,7 @@ void IOControl::ioread( IOInfo* it ) ...@@ -519,7 +537,7 @@ void IOControl::ioread( IOInfo* it )
{ {
int val = card->getAnalogChannel(it->subdev, it->channel, it->range, it->aref); int val = card->getAnalogChannel(it->subdev, it->channel, it->range, it->aref);
dlog3 << myname << "(iopoll): read AI " iolog3 << myname << "(iopoll): read AI "
<< " sid=" << it->si.id << " sid=" << it->si.id
<< " subdev=" << it->subdev << " subdev=" << it->subdev
<< " chan=" << it->channel << " chan=" << it->channel
...@@ -641,23 +659,23 @@ void IOControl::ioread( IOInfo* it ) ...@@ -641,23 +659,23 @@ void IOControl::ioread( IOInfo* it )
} }
catch( const IOController_i::NameNotFound& ex ) catch( const IOController_i::NameNotFound& ex )
{ {
dlog3 << myname << "(iopoll):(NameNotFound) " << ex.err << endl; iolog3 << myname << "(iopoll):(NameNotFound) " << ex.err << endl;
} }
catch( const IOController_i::IOBadParam& ex ) catch( const IOController_i::IOBadParam& ex )
{ {
dlog3 << myname << "(iopoll):(IOBadParam) " << ex.err << endl; iolog3 << myname << "(iopoll):(IOBadParam) " << ex.err << endl;
} }
catch( const IONotifyController_i::BadRange& ex ) catch( const IONotifyController_i::BadRange& ex )
{ {
dlog3 << myname << "(iopoll): (BadRange)..." << endl; iolog3 << myname << "(iopoll): (BadRange)..." << endl;
} }
catch( const Exception& ex ) catch( const Exception& ex )
{ {
dlog3 << myname << "(iopoll): " << ex << endl; iolog3 << myname << "(iopoll): " << ex << endl;
} }
catch( const CORBA::SystemException& ex ) catch( const CORBA::SystemException& ex )
{ {
dlog3 << myname << "(iopoll): СORBA::SystemException: " iolog3 << myname << "(iopoll): СORBA::SystemException: "
<< ex.NP_minorString() << endl; << ex.NP_minorString() << endl;
} }
} }
...@@ -679,7 +697,7 @@ void IOControl::readConfiguration() ...@@ -679,7 +697,7 @@ void IOControl::readConfiguration()
if( !it.goChildren() ) if( !it.goChildren() )
{ {
dwarn << myname << "(readConfiguration): section <sensors> empty?!!\n"; iowarn << myname << "(readConfiguration): section <sensors> empty?!!\n";
return; return;
} }
...@@ -710,7 +728,7 @@ bool IOControl::initIOItem( UniXML::iterator& it ) ...@@ -710,7 +728,7 @@ bool IOControl::initIOItem( UniXML::iterator& it )
if( c.empty() || inf.ncard < 0 || inf.ncard >= (int)cards.size() ) if( c.empty() || inf.ncard < 0 || inf.ncard >= (int)cards.size() )
{ {
dlog3 << myname iolog3 << myname
<< "(initIOItem): Unknown or bad card number (" << "(initIOItem): Unknown or bad card number ("
<< inf.ncard << ") for " << it.getProp("name") << inf.ncard << ") for " << it.getProp("name")
<< " set default=" << defCardNum << endl; << " set default=" << defCardNum << endl;
...@@ -742,7 +760,7 @@ bool IOControl::initIOItem( UniXML::iterator& it ) ...@@ -742,7 +760,7 @@ bool IOControl::initIOItem( UniXML::iterator& it )
std::string prop_prefix( prefix + "_" ); std::string prop_prefix( prefix + "_" );
if( !IOBase::initItem(&inf, it, shm, prop_prefix, false, dlog(), myname, filtersize, filterT) ) if( !IOBase::initItem(&inf, it, shm, prop_prefix, false, iolog, myname, filtersize, filterT) )
return false; return false;
// если вектор уже заполнен // если вектор уже заполнен
...@@ -758,7 +776,7 @@ bool IOControl::initIOItem( UniXML::iterator& it ) ...@@ -758,7 +776,7 @@ bool IOControl::initIOItem( UniXML::iterator& it )
{ {
IOPriority p(prior, maxItem); IOPriority p(prior, maxItem);
pmap.push_back(p); pmap.push_back(p);
dlog3 << myname << "(readItem): add to priority list: " << iolog3 << myname << "(readItem): add to priority list: " <<
it.getProp("name") it.getProp("name")
<< " priority=" << prior << endl; << " priority=" << prior << endl;
} }
...@@ -767,7 +785,7 @@ bool IOControl::initIOItem( UniXML::iterator& it ) ...@@ -767,7 +785,7 @@ bool IOControl::initIOItem( UniXML::iterator& it )
if( inf.t_ai != DefaultObjectId ) if( inf.t_ai != DefaultObjectId )
{ {
iomap[maxItem++] = std::move(inf); iomap[maxItem++] = std::move(inf);
dlog3 << myname << "(readItem): add threshold '" << it.getProp("name") iolog3 << myname << "(readItem): add threshold '" << it.getProp("name")
<< " for '" << uniset_conf()->oind->getNameById(inf.t_ai) << endl; << " for '" << uniset_conf()->oind->getNameById(inf.t_ai) << endl;
return true; return true;
} }
...@@ -776,7 +794,7 @@ bool IOControl::initIOItem( UniXML::iterator& it ) ...@@ -776,7 +794,7 @@ bool IOControl::initIOItem( UniXML::iterator& it )
if( inf.channel < 0 || inf.channel > 32 ) if( inf.channel < 0 || inf.channel > 32 )
{ {
dwarn << myname << "(readItem): Unknown channel: " << inf.channel iowarn << myname << "(readItem): Unknown channel: " << inf.channel
<< " for " << it.getProp("name") << endl; << " for " << it.getProp("name") << endl;
return false; return false;
} }
...@@ -795,7 +813,7 @@ bool IOControl::initIOItem( UniXML::iterator& it ) ...@@ -795,7 +813,7 @@ bool IOControl::initIOItem( UniXML::iterator& it )
if( inf.range < 0 || inf.range > 3 ) if( inf.range < 0 || inf.range > 3 )
{ {
dcrit << myname << "(readItem): Unknown 'range': " << inf.range iocrit << myname << "(readItem): Unknown 'range': " << inf.range
<< " for " << it.getProp("name") << " for " << it.getProp("name")
<< " Must be range=[0..3]" << endl; << " Must be range=[0..3]" << endl;
return false; return false;
...@@ -805,14 +823,14 @@ bool IOControl::initIOItem( UniXML::iterator& it ) ...@@ -805,14 +823,14 @@ bool IOControl::initIOItem( UniXML::iterator& it )
if( inf.aref < 0 || inf.aref > 3 ) if( inf.aref < 0 || inf.aref > 3 )
{ {
dcrit << myname << "(readItem): Unknown 'aref': " << inf.aref iocrit << myname << "(readItem): Unknown 'aref': " << inf.aref
<< " for " << it.getProp("name") << " for " << it.getProp("name")
<< ". Must be aref=[0..3]" << endl; << ". Must be aref=[0..3]" << endl;
return false; return false;
} }
} }
dlog3 << myname << "(readItem): add: " << inf.stype << " " << inf << endl; iolog3 << myname << "(readItem): add: " << inf.stype << " " << inf << endl;
iomap[maxItem++] = std::move(inf); iomap[maxItem++] = std::move(inf);
return true; return true;
...@@ -868,7 +886,7 @@ void IOControl::sigterm( int signo ) ...@@ -868,7 +886,7 @@ void IOControl::sigterm( int signo )
} }
catch( const std::exception& ex ) catch( const std::exception& ex )
{ {
dlog3 << myname << "(sigterm): " << ex.what() << endl; iolog3 << myname << "(sigterm): " << ex.what() << endl;
} }
} }
...@@ -902,7 +920,7 @@ void IOControl::initOutputs() ...@@ -902,7 +920,7 @@ void IOControl::initOutputs()
} }
catch( const Exception& ex ) catch( const Exception& ex )
{ {
dlog3 << myname << "(initOutput): " << ex << endl; iolog3 << myname << "(initOutput): " << ex << endl;
} }
} }
} }
...@@ -943,7 +961,7 @@ void IOControl::initIOCard() ...@@ -943,7 +961,7 @@ void IOControl::initIOCard()
} }
catch( const Exception& ex) catch( const Exception& ex)
{ {
dcrit << myname << "(initIOCard): sid=" << it.si.id << " " << ex << endl; iocrit << myname << "(initIOCard): sid=" << it.si.id << " " << ex << endl;
} }
} }
} }
...@@ -969,7 +987,7 @@ void IOControl::blink( BlinkList& lst, bool& bstate ) ...@@ -969,7 +987,7 @@ void IOControl::blink( BlinkList& lst, bool& bstate )
} }
catch( const Exception& ex ) catch( const Exception& ex )
{ {
dcrit << myname << "(blink): " << ex << endl; iocrit << myname << "(blink): " << ex << endl;
} }
} }
...@@ -1053,7 +1071,7 @@ void IOControl::check_testmode() ...@@ -1053,7 +1071,7 @@ void IOControl::check_testmode()
} }
catch( const Exception& ex ) catch( const Exception& ex )
{ {
dlog3 << myname << "(sigterm): " << ex << endl; iolog3 << myname << "(sigterm): " << ex << endl;
} }
catch(...) {} catch(...) {}
} }
...@@ -1062,11 +1080,11 @@ void IOControl::check_testmode() ...@@ -1062,11 +1080,11 @@ void IOControl::check_testmode()
} }
catch( const Exception& ex) catch( const Exception& ex)
{ {
dcrit << myname << "(check_testmode): " << ex << endl; iocrit << myname << "(check_testmode): " << ex << endl;
} }
catch(...) catch(...)
{ {
dcrit << myname << "(check_testmode): catch ..." << endl; iocrit << myname << "(check_testmode): catch ..." << endl;
} }
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
...@@ -1127,11 +1145,11 @@ void IOControl::check_testlamp() ...@@ -1127,11 +1145,11 @@ void IOControl::check_testlamp()
} }
catch( const Exception& ex) catch( const Exception& ex)
{ {
dcrit << myname << "(check_testlamp): " << ex << endl; iocrit << myname << "(check_testlamp): " << ex << endl;
} }
catch( const std::exception& ex ) catch( const std::exception& ex )
{ {
dcrit << myname << "(check_testlamp): catch ..." << endl; iocrit << myname << "(check_testlamp): catch ..." << endl;
} }
} }
...@@ -1195,6 +1213,19 @@ void IOControl::help_print( int argc, const char* const* argv ) ...@@ -1195,6 +1213,19 @@ void IOControl::help_print( int argc, const char* const* argv )
cout << "--prefix-force-out - Обновлять выходы принудительно (не по заказу)" << endl; cout << "--prefix-force-out - Обновлять выходы принудительно (не по заказу)" << endl;
cout << "--prefix-skip-init-output - Не инициализировать 'выходы' при старте" << endl; cout << "--prefix-skip-init-output - Не инициализировать 'выходы' при старте" << endl;
cout << "--prefix-sm-ready-test-sid - Использовать указанный датчик, для проверки готовности SharedMemory" << endl; cout << "--prefix-sm-ready-test-sid - Использовать указанный датчик, для проверки готовности SharedMemory" << endl;
cout << endl;
cout << " Logs: " << endl;
cout << "--prefix-log-... - log control" << endl;
cout << " add-levels ..." << endl;
cout << " del-levels ..." << endl;
cout << " set-levels ..." << endl;
cout << " logfile filaname" << endl;
cout << " no-debug " << endl;
cout << " LogServer: " << endl;
cout << "--prefix-run-logserver - run logserver. Default: localhost:id" << endl;
cout << "--prefix-logserver-host ip - listen ip. Default: localhost" << endl;
cout << "--prefix-logserver-port num - listen port. Default: ID" << endl;
cout << LogServer::help_print("prefix-logserver") << endl;
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
void IOControl::sysCommand( const SystemMessage* sm ) void IOControl::sysCommand( const SystemMessage* sm )
...@@ -1203,11 +1234,17 @@ void IOControl::sysCommand( const SystemMessage* sm ) ...@@ -1203,11 +1234,17 @@ void IOControl::sysCommand( const SystemMessage* sm )
{ {
case SystemMessage::StartUp: case SystemMessage::StartUp:
{ {
if( !logserv_host.empty() && logserv_port != 0 && !logserv->isRunning() )
{
ioinfo << myname << "(init): run log server " << logserv_host << ":" << logserv_port << endl;
logserv->run(logserv_host, logserv_port, true);
}
PassiveTimer ptAct(activateTimeout); PassiveTimer ptAct(activateTimeout);
while( !activated && !ptAct.checkTime() ) while( !activated && !ptAct.checkTime() )
{ {
dinfo << myname << "(sysCommand): wait activate..." << endl; ioinfo << myname << "(sysCommand): wait activate..." << endl;
msleep(300); msleep(300);
if( activated ) if( activated )
...@@ -1215,7 +1252,7 @@ void IOControl::sysCommand( const SystemMessage* sm ) ...@@ -1215,7 +1252,7 @@ void IOControl::sysCommand( const SystemMessage* sm )
} }
if( !activated ) if( !activated )
dcrit << myname << "(sysCommand): ************* don`t activate?! ************" << endl; iocrit << myname << "(sysCommand): ************* don`t activate?! ************" << endl;
askSensors(UniversalIO::UIONotify); askSensors(UniversalIO::UIONotify);
break; break;
...@@ -1255,23 +1292,13 @@ void IOControl::sysCommand( const SystemMessage* sm ) ...@@ -1255,23 +1292,13 @@ void IOControl::sysCommand( const SystemMessage* sm )
case SystemMessage::LogRotate: case SystemMessage::LogRotate:
{ {
// переоткрываем логи iologany << myname << "(sysCommand): logRotate" << endl;
ulogany << myname << "(sysCommand): logRotate" << endl; string fname = iolog->getLogFile();
string fname( ulog()->getLogFile() );
if( !fname.empty() )
{
ulog()->logFile(fname, true);
ulogany << myname << "(sysCommand): ***************** ulog LOG ROTATE *****************" << endl;
}
dlogany << myname << "(sysCommand): logRotate" << endl;
fname = dlog()->getLogFile();
if( !fname.empty() ) if( !fname.empty() )
{ {
dlog()->logFile(fname, true); iolog->logFile(fname, true);
dlogany << myname << "(sysCommand): ***************** GGDEB LOG ROTATE *****************" << endl; iologany << myname << "(sysCommand): ***************** GGDEB LOG ROTATE *****************" << endl;
} }
} }
break; break;
...@@ -1296,7 +1323,7 @@ void IOControl::askSensors( UniversalIO::UIOCommand cmd ) ...@@ -1296,7 +1323,7 @@ void IOControl::askSensors( UniversalIO::UIOCommand cmd )
<< "(askSensors): Не дождались готовности(work) SharedMemory к работе в течение " << "(askSensors): Не дождались готовности(work) SharedMemory к работе в течение "
<< activateTimeout << " мсек"; << activateTimeout << " мсек";
dcrit << err.str() << endl; iocrit << err.str() << endl;
kill(SIGTERM, getpid()); // прерываем (перезапускаем) процесс... kill(SIGTERM, getpid()); // прерываем (перезапускаем) процесс...
throw SystemError(err.str()); throw SystemError(err.str());
} }
...@@ -1305,7 +1332,7 @@ void IOControl::askSensors( UniversalIO::UIOCommand cmd ) ...@@ -1305,7 +1332,7 @@ void IOControl::askSensors( UniversalIO::UIOCommand cmd )
while( !readconf_ok && !ptAct.checkTime() ) while( !readconf_ok && !ptAct.checkTime() )
{ {
dinfo << myname << "(askSensors): wait read configuration..." << endl; ioinfo << myname << "(askSensors): wait read configuration..." << endl;
msleep(50); msleep(50);
if( readconf_ok ) if( readconf_ok )
...@@ -1313,7 +1340,7 @@ void IOControl::askSensors( UniversalIO::UIOCommand cmd ) ...@@ -1313,7 +1340,7 @@ void IOControl::askSensors( UniversalIO::UIOCommand cmd )
} }
if( !readconf_ok ) if( !readconf_ok )
dcrit << myname << "(askSensors): ************* don`t read configuration?! ************" << endl; iocrit << myname << "(askSensors): ************* don`t read configuration?! ************" << endl;
try try
{ {
...@@ -1322,7 +1349,7 @@ void IOControl::askSensors( UniversalIO::UIOCommand cmd ) ...@@ -1322,7 +1349,7 @@ void IOControl::askSensors( UniversalIO::UIOCommand cmd )
} }
catch( const Exception& ex) catch( const Exception& ex)
{ {
dcrit << myname << "(askSensors): " << ex << endl; iocrit << myname << "(askSensors): " << ex << endl;
} }
try try
...@@ -1332,7 +1359,7 @@ void IOControl::askSensors( UniversalIO::UIOCommand cmd ) ...@@ -1332,7 +1359,7 @@ void IOControl::askSensors( UniversalIO::UIOCommand cmd )
} }
catch( const Exception& ex ) catch( const Exception& ex )
{ {
dcrit << myname << "(askSensors): " << ex << endl; iocrit << myname << "(askSensors): " << ex << endl;
} }
for( auto& it : iomap ) for( auto& it : iomap )
...@@ -1353,7 +1380,7 @@ void IOControl::askSensors( UniversalIO::UIOCommand cmd ) ...@@ -1353,7 +1380,7 @@ void IOControl::askSensors( UniversalIO::UIOCommand cmd )
} }
catch( const Exception& ex ) catch( const Exception& ex )
{ {
dcrit << myname << "(askSensors): " << ex << endl; iocrit << myname << "(askSensors): " << ex << endl;
} }
} }
} }
...@@ -1361,7 +1388,7 @@ void IOControl::askSensors( UniversalIO::UIOCommand cmd ) ...@@ -1361,7 +1388,7 @@ void IOControl::askSensors( UniversalIO::UIOCommand cmd )
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
void IOControl::sensorInfo( const UniSetTypes::SensorMessage* sm ) void IOControl::sensorInfo( const UniSetTypes::SensorMessage* sm )
{ {
dlog1 << myname << "(sensorInfo): sm->id=" << sm->id iolog1 << myname << "(sensorInfo): sm->id=" << sm->id
<< " val=" << sm->value << endl; << " val=" << sm->value << endl;
if( force_out ) if( force_out )
...@@ -1369,7 +1396,7 @@ void IOControl::sensorInfo( const UniSetTypes::SensorMessage* sm ) ...@@ -1369,7 +1396,7 @@ void IOControl::sensorInfo( const UniSetTypes::SensorMessage* sm )
if( sm->id == testLamp_S ) if( sm->id == testLamp_S )
{ {
dinfo << myname << "(sensorInfo): test_lamp=" << sm->value << endl; ioinfo << myname << "(sensorInfo): test_lamp=" << sm->value << endl;
isTestLamp = (bool)sm->value; isTestLamp = (bool)sm->value;
} }
else if( sm->id == testMode_as ) else if( sm->id == testMode_as )
...@@ -1382,7 +1409,7 @@ void IOControl::sensorInfo( const UniSetTypes::SensorMessage* sm ) ...@@ -1382,7 +1409,7 @@ void IOControl::sensorInfo( const UniSetTypes::SensorMessage* sm )
{ {
if( it.si.id == sm->id ) if( it.si.id == sm->id )
{ {
dinfo << myname << "(sensorInfo): sid=" << sm->id ioinfo << myname << "(sensorInfo): sid=" << sm->id
<< " value=" << sm->value << " value=" << sm->value
<< endl; << endl;
...@@ -1484,7 +1511,7 @@ void IOControl::sensorInfo( const UniSetTypes::SensorMessage* sm ) ...@@ -1484,7 +1511,7 @@ void IOControl::sensorInfo( const UniSetTypes::SensorMessage* sm )
} }
else if( it.stype == UniversalIO::DO ) else if( it.stype == UniversalIO::DO )
{ {
dlog1 << myname << "(sensorInfo): DO: sm->id=" << sm->id iolog1 << myname << "(sensorInfo): DO: sm->id=" << sm->id
<< " val=" << sm->value << endl; << " val=" << sm->value << endl;
uniset_rwmutex_wrlock lock(it.val_lock); uniset_rwmutex_wrlock lock(it.val_lock);
...@@ -1509,7 +1536,7 @@ void IOControl::waitSM() ...@@ -1509,7 +1536,7 @@ void IOControl::waitSM()
err << myname << "(execute): did not wait for the ready 'SharedMemory'. Timeout " err << myname << "(execute): did not wait for the ready 'SharedMemory'. Timeout "
<< smReadyTimeout << " msec"; << smReadyTimeout << " msec";
dcrit << err.str() << endl; iocrit << err.str() << endl;
throw SystemError(err.str()); throw SystemError(err.str());
} }
} }
...@@ -1522,7 +1549,7 @@ void IOControl::buildCardsList() ...@@ -1522,7 +1549,7 @@ void IOControl::buildCardsList()
if( !nnode ) if( !nnode )
{ {
dwarn << myname << "(buildCardsList): <nodes> not found?!" << endl; iowarn << myname << "(buildCardsList): <nodes> not found?!" << endl;
return; return;
} }
...@@ -1530,7 +1557,7 @@ void IOControl::buildCardsList() ...@@ -1530,7 +1557,7 @@ void IOControl::buildCardsList()
if( !xml ) if( !xml )
{ {
dwarn << myname << "(buildCardsList): xml=NULL?!" << endl; iowarn << myname << "(buildCardsList): xml=NULL?!" << endl;
return; return;
} }
...@@ -1549,7 +1576,7 @@ void IOControl::buildCardsList() ...@@ -1549,7 +1576,7 @@ void IOControl::buildCardsList()
if( !mynode ) if( !mynode )
{ {
dwarn << myname << "(buildCardsList): node='" << conf->getLocalNodeName() << "' not found.." << endl; iowarn << myname << "(buildCardsList): node='" << conf->getLocalNodeName() << "' not found.." << endl;
return; return;
} }
...@@ -1559,7 +1586,7 @@ void IOControl::buildCardsList() ...@@ -1559,7 +1586,7 @@ void IOControl::buildCardsList()
if( !cnode ) if( !cnode )
{ {
dwarn << myname << "(buildCardsList): Not found <iocards> for node=" << conf->getLocalNodeName() << "(" << conf->getLocalNode() << ")" << endl; iowarn << myname << "(buildCardsList): Not found <iocards> for node=" << conf->getLocalNodeName() << "(" << conf->getLocalNode() << ")" << endl;
return; return;
} }
...@@ -1567,7 +1594,7 @@ void IOControl::buildCardsList() ...@@ -1567,7 +1594,7 @@ void IOControl::buildCardsList()
if( !it.goChildren() ) if( !it.goChildren() )
{ {
dwarn << myname << "(buildCardsList): <iocards> empty.." << endl; iowarn << myname << "(buildCardsList): <iocards> empty.." << endl;
return; return;
} }
...@@ -1585,21 +1612,21 @@ void IOControl::buildCardsList() ...@@ -1585,21 +1612,21 @@ void IOControl::buildCardsList()
if( cardnum <= 0 ) if( cardnum <= 0 )
{ {
dlog3 << myname << "(init): Unknown card number?! card=" << it.getIntProp("card") << "(" << cname << ")" << endl; iolog3 << myname << "(init): Unknown card number?! card=" << it.getIntProp("card") << "(" << cname << ")" << endl;
continue; continue;
} }
if( cardnum > maxCardNum ) if( cardnum > maxCardNum )
{ {
dlog3 << myname << "(init): BAD card number card='" << it.getIntProp("card") << "'(" << cname << "). Must be < " << maxCardNum << endl; iolog3 << myname << "(init): BAD card number card='" << it.getIntProp("card") << "'(" << cname << "). Must be < " << maxCardNum << endl;
continue; continue;
} }
if( it.getIntProp("ignore") ) if( it.getIntProp("ignore") )
{ {
cards[cardnum] = NULL; cards[cardnum] = NULL;
dlog3 << myname << "(init): card=" << it.getProp("card") << "(" << cname << ")" iolog3 << myname << "(init): card=" << it.getProp("card") << "(" << cname << ")"
<< " DISABLED! ignore=1" << endl; << " DISABLED! ignore=1" << endl;
continue; continue;
} }
...@@ -1610,7 +1637,7 @@ void IOControl::buildCardsList() ...@@ -1610,7 +1637,7 @@ void IOControl::buildCardsList()
if( findArgParam( s.str(), conf->getArgc(), conf->getArgv()) != -1 ) if( findArgParam( s.str(), conf->getArgc(), conf->getArgv()) != -1 )
{ {
cards[cardnum] = NULL; cards[cardnum] = NULL;
dlog3 << myname << "(init): card=" << it.getProp("card") << "(" << cname << ")" iolog3 << myname << "(init): card=" << it.getProp("card") << "(" << cname << ")"
<< " DISABLED! (" << s.str() << ")" << endl; << " DISABLED! (" << s.str() << ")" << endl;
continue; continue;
} }
...@@ -1620,13 +1647,13 @@ void IOControl::buildCardsList() ...@@ -1620,13 +1647,13 @@ void IOControl::buildCardsList()
if( iodev.empty() || iodev == "/dev/null" ) if( iodev.empty() || iodev == "/dev/null" )
{ {
cards[cardnum] = NULL; cards[cardnum] = NULL;
dlog3 << myname << "(init): card=" << it.getProp("card") << "(" << cname << ")" iolog3 << myname << "(init): card=" << it.getProp("card") << "(" << cname << ")"
<< " DISABLED! iodev='" << " DISABLED! iodev='"
<< iodev << "'" << endl; << iodev << "'" << endl;
continue; continue;
} }
dlog3 << myname << "(init): ADD card=" << it.getProp("card") << "(" << cname << ")" << " dev=" << iodev << endl; iolog3 << myname << "(init): ADD card=" << it.getProp("card") << "(" << cname << ")" << " dev=" << iodev << endl;
try try
{ {
...@@ -1635,7 +1662,7 @@ void IOControl::buildCardsList() ...@@ -1635,7 +1662,7 @@ void IOControl::buildCardsList()
} }
catch( const Exception& ex ) catch( const Exception& ex )
{ {
dcrit << myname << "(buildCardsList): " << ex << endl; iocrit << myname << "(buildCardsList): " << ex << endl;
throw; throw;
} }
...@@ -1665,7 +1692,7 @@ void IOControl::buildCardsList() ...@@ -1665,7 +1692,7 @@ void IOControl::buildCardsList()
if( subdev_name.empty() ) if( subdev_name.empty() )
{ {
dinfo << myname << "(buidCardList): empty subdev. ignore... (" << s.str() << ")" << endl; ioinfo << myname << "(buidCardList): empty subdev. ignore... (" << s.str() << ")" << endl;
continue; continue;
} }
...@@ -1682,13 +1709,13 @@ void IOControl::buildCardsList() ...@@ -1682,13 +1709,13 @@ void IOControl::buildCardsList()
if( st == ComediInterface::GRAYHILL ) if( st == ComediInterface::GRAYHILL )
{ {
// для Grayhill конфигурирование не требуется // для Grayhill конфигурирование не требуется
dinfo << myname << "(buildCardsList): card=" << it.getProp("card") ioinfo << myname << "(buildCardsList): card=" << it.getProp("card")
<< "(" << cname << ")" << "(" << cname << ")"
<< " init subdev" << i << " 'GRAYHILL'" << endl; << " init subdev" << i << " 'GRAYHILL'" << endl;
continue; continue;
} }
dinfo << myname << "(buildCardsList): card=" << it.getProp("card") ioinfo << myname << "(buildCardsList): card=" << it.getProp("card")
<< "(" << cname << ")" << "(" << cname << ")"
<< " init subdev" << i << " " << it.getProp(s.str()) << endl; << " init subdev" << i << " " << it.getProp(s.str()) << endl;
cards[cardnum]->configureSubdev(i - 1, st); cards[cardnum]->configureSubdev(i - 1, st);
......
...@@ -21,6 +21,9 @@ ...@@ -21,6 +21,9 @@
#include "IOController.h" #include "IOController.h"
#include "IOBase.h" #include "IOBase.h"
#include "SharedMemory.h" #include "SharedMemory.h"
#include "LogServer.h"
#include "DebugStream.h"
#include "LogAgregator.h"
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
/*! /*!
\page page_IOControl (IOControl) Реализация процесса ввода/вывода \page page_IOControl (IOControl) Реализация процесса ввода/вывода
...@@ -393,6 +396,12 @@ class IOControl: ...@@ -393,6 +396,12 @@ class IOControl:
long testmode; long testmode;
long prev_testmode; long prev_testmode;
std::shared_ptr<LogAgregator> loga;
std::shared_ptr<DebugStream> iolog;
std::shared_ptr<LogServer> logserv;
std::string logserv_host = {""};
int logserv_port = {0};
private: private:
}; };
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
......
#ifndef IOLogSugar_H_
#define IOLogSugar_H_
// "синтаксический сахар"..для логов
#ifndef ioinfo
#define ioinfo if( iolog->debugging(Debug::INFO) ) iolog->info()
#endif
#ifndef iowarn
#define iowarn if( iolog->debugging(Debug::WARN) ) iolog->warn()
#endif
#ifndef iocrit
#define iocrit if( iolog->debugging(Debug::CRIT) ) iolog->crit()
#endif
#ifndef iolog1
#define iolog1 if( iolog->debugging(Debug::LEVEL1) ) iolog->level1()
#endif
#ifndef iolog2
#define iolog2 if( iolog->debugging(Debug::LEVEL2) ) iolog->level2()
#endif
#ifndef iolog3
#define iolog3 if( iolog->debugging(Debug::LEVEL3) ) iolog->level3()
#endif
#ifndef iolog4
#define iolog4 if( iolog->debugging(Debug::LEVEL4) ) iolog->level4()
#endif
#ifndef iolog5
#define iolog5 if( iolog->debugging(Debug::LEVEL5) ) iolog->level5()
#endif
#ifndef iolog6
#define iolog6 if( iolog->debugging(Debug::LEVEL6) ) iolog->level6()
#endif
#ifndef iolog7
#define iolog7 if( iolog->debugging(Debug::LEVEL7) ) iolog->level7()
#endif
#ifndef iolog8
#define iolog8 if( iolog->debugging(Debug::LEVEL8) ) iolog->level8()
#endif
#ifndef iolog9
#define iolog9 if( iolog->debugging(Debug::LEVEL9) ) iolog->level9()
#endif
#ifndef iologany
#define iologany iolog->any()
#endif
#endif
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <extensions/Extensions.h> #include <extensions/Extensions.h>
#include <ORepHelpers.h> #include <ORepHelpers.h>
#include "MBExchange.h" #include "MBExchange.h"
#include "modbus/MBLogSugar.h"
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
using namespace std; using namespace std;
using namespace UniSetTypes; using namespace UniSetTypes;
...@@ -46,11 +47,18 @@ MBExchange::MBExchange( UniSetTypes::ObjectId objId, UniSetTypes::ObjectId shmId ...@@ -46,11 +47,18 @@ MBExchange::MBExchange( UniSetTypes::ObjectId objId, UniSetTypes::ObjectId shmId
shm = make_shared<SMInterface>(shmId, ui, objId, ic); shm = make_shared<SMInterface>(shmId, ui, objId, ic);
mblog = make_shared<DebugStream>(); mblog = make_shared<DebugStream>();
mblog->setLogName(myname);
conf->initLogStream(mblog, prefix + "-log"); conf->initLogStream(mblog, prefix + "-log");
logserv = make_shared<LogServer>(mblog);
loga = make_shared<LogAgregator>();
loga->add(mblog);
loga->add(ulog());
loga->add(dlog());
UniXML::iterator it(cnode); UniXML::iterator it(cnode);
logserv = make_shared<LogServer>(loga);
logserv->init( prefix+"-logserver", cnode );
if( findArgParam("--" + prefix + "-run-logserver", conf->getArgc(), conf->getArgv()) != -1 ) if( findArgParam("--" + prefix + "-run-logserver", conf->getArgc(), conf->getArgv()) != -1 )
{ {
logserv_host = conf->getArg2Param("--" + prefix + "-logserver-host", it.getProp("logserverHost"), "localhost"); logserv_host = conf->getArg2Param("--" + prefix + "-logserver-host", it.getProp("logserverHost"), "localhost");
...@@ -221,6 +229,7 @@ void MBExchange::help_print( int argc, const char* const* argv ) ...@@ -221,6 +229,7 @@ void MBExchange::help_print( int argc, const char* const* argv )
cout << "--prefix-run-logserver - run logserver. Default: localhost:id" << endl; cout << "--prefix-run-logserver - run logserver. Default: localhost:id" << endl;
cout << "--prefix-logserver-host ip - listen ip. Default: localhost" << endl; cout << "--prefix-logserver-host ip - listen ip. Default: localhost" << endl;
cout << "--prefix-logserver-port num - listen port. Default: ID" << endl; cout << "--prefix-logserver-port num - listen port. Default: ID" << endl;
cout << LogServer::help_print("prefix-logserver") << endl;
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
MBExchange::~MBExchange() MBExchange::~MBExchange()
......
...@@ -21,9 +21,9 @@ ...@@ -21,9 +21,9 @@
#include "MTR.h" #include "MTR.h"
#include "RTUStorage.h" #include "RTUStorage.h"
#include "modbus/ModbusClient.h" #include "modbus/ModbusClient.h"
#include "modbus/MBLogSugar.h"
#include "LogAgregator.h" #include "LogAgregator.h"
#include "LogServer.h" #include "LogServer.h"
#include "LogAgregator.h"
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
/*! /*!
\par Базовый класс для реализация обмена по протоколу Modbus [RTU|TCP]. \par Базовый класс для реализация обмена по протоколу Modbus [RTU|TCP].
...@@ -352,6 +352,7 @@ class MBExchange: ...@@ -352,6 +352,7 @@ class MBExchange:
std::string defaultMBaddr; std::string defaultMBaddr;
bool defaultMBinitOK; // флаг определяющий нужно ли ждать "первого обмена" или при запуске сохранять в SM значение default. bool defaultMBinitOK; // флаг определяющий нужно ли ждать "первого обмена" или при запуске сохранять в SM значение default.
std::shared_ptr<LogAgregator> loga;
std::shared_ptr<DebugStream> mblog; std::shared_ptr<DebugStream> mblog;
std::shared_ptr<LogServer> logserv; std::shared_ptr<LogServer> logserv;
std::string logserv_host = {""}; std::string logserv_host = {""};
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include <Exceptions.h> #include <Exceptions.h>
#include <extensions/Extensions.h> #include <extensions/Extensions.h>
#include "MBTCPMaster.h" #include "MBTCPMaster.h"
#include "modbus/MBLogSugar.h"
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
using namespace std; using namespace std;
using namespace UniSetTypes; using namespace UniSetTypes;
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include <Exceptions.h> #include <Exceptions.h>
#include <extensions/Extensions.h> #include <extensions/Extensions.h>
#include "MBTCPMultiMaster.h" #include "MBTCPMultiMaster.h"
#include "modbus/MBLogSugar.h"
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
using namespace std; using namespace std;
using namespace UniSetTypes; using namespace UniSetTypes;
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
#include <sstream> #include <sstream>
#include "Extensions.h" #include "Extensions.h"
#include "RTUExchange.h" #include "RTUExchange.h"
#include "modbus/MBLogSugar.h"
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
using namespace std; using namespace std;
using namespace UniSetTypes; using namespace UniSetTypes;
...@@ -43,7 +44,7 @@ RTUExchange::RTUExchange( UniSetTypes::ObjectId objId, UniSetTypes::ObjectId shm ...@@ -43,7 +44,7 @@ RTUExchange::RTUExchange( UniSetTypes::ObjectId objId, UniSetTypes::ObjectId shm
prop_prefix = ""; prop_prefix = "";
} }
dinfo << myname << "(init): prop_prefix=" << prop_prefix << endl; mbinfo << myname << "(init): prop_prefix=" << prop_prefix << endl;
UniXML::iterator it(cnode); UniXML::iterator it(cnode);
...@@ -139,7 +140,7 @@ std::shared_ptr<ModbusClient> RTUExchange::initMB( bool reopen ) ...@@ -139,7 +140,7 @@ std::shared_ptr<ModbusClient> RTUExchange::initMB( bool reopen )
mbrtu->setSleepPause(sleepPause_usec); mbrtu->setSleepPause(sleepPause_usec);
mbrtu->setAfterSendPause(aftersend_pause); mbrtu->setAfterSendPause(aftersend_pause);
dinfo << myname << "(init): dev=" << devname << " speed=" << ComPort::getSpeed( mbrtu->getSpeed() ) << endl; mbinfo << myname << "(init): dev=" << devname << " speed=" << ComPort::getSpeed( mbrtu->getSpeed() ) << endl;
} }
catch( const Exception& ex ) catch( const Exception& ex )
{ {
...@@ -147,7 +148,7 @@ std::shared_ptr<ModbusClient> RTUExchange::initMB( bool reopen ) ...@@ -147,7 +148,7 @@ std::shared_ptr<ModbusClient> RTUExchange::initMB( bool reopen )
// delete mbrtu; // delete mbrtu;
mbrtu = 0; mbrtu = 0;
dwarn << myname << "(init): " << ex << endl; mbwarn << myname << "(init): " << ex << endl;
} }
catch(...) catch(...)
{ {
...@@ -155,7 +156,7 @@ std::shared_ptr<ModbusClient> RTUExchange::initMB( bool reopen ) ...@@ -155,7 +156,7 @@ std::shared_ptr<ModbusClient> RTUExchange::initMB( bool reopen )
// delete mbrtu; // delete mbrtu;
mbrtu = 0; mbrtu = 0;
dinfo << myname << "(init): catch...." << endl; mbinfo << myname << "(init): catch...." << endl;
} }
mb = mbrtu; mb = mbrtu;
...@@ -284,7 +285,7 @@ bool RTUExchange::poll() ...@@ -284,7 +285,7 @@ bool RTUExchange::poll()
updateSM(); updateSM();
// check thresholds // check thresholds
for( auto& t : thrlist ) for( auto&& t : thrlist )
{ {
if( !checkProcActive() ) if( !checkProcActive() )
return false; return false;
...@@ -297,7 +298,7 @@ bool RTUExchange::poll() ...@@ -297,7 +298,7 @@ bool RTUExchange::poll()
if( allNotRespond && ptReopen.checkTime() ) if( allNotRespond && ptReopen.checkTime() )
{ {
dwarn << myname << ": REOPEN timeout..(" << ptReopen.getInterval() << ")" << endl; mbwarn << myname << ": REOPEN timeout..(" << ptReopen.getInterval() << ")" << endl;
mb = initMB(true); mb = initMB(true);
ptReopen.reset(); ptReopen.reset();
...@@ -343,7 +344,7 @@ bool RTUExchange::initDeviceInfo( RTUDeviceMap& m, ModbusRTU::ModbusAddr a, UniX ...@@ -343,7 +344,7 @@ bool RTUExchange::initDeviceInfo( RTUDeviceMap& m, ModbusRTU::ModbusAddr a, UniX
if( d == m.end() ) if( d == m.end() )
{ {
dwarn << myname << "(initDeviceInfo): not found device for addr=" << ModbusRTU::addr2str(a) << endl; mbwarn << myname << "(initDeviceInfo): not found device for addr=" << ModbusRTU::addr2str(a) << endl;
return false; return false;
} }
...@@ -356,7 +357,7 @@ bool RTUExchange::initDeviceInfo( RTUDeviceMap& m, ModbusRTU::ModbusAddr a, UniX ...@@ -356,7 +357,7 @@ bool RTUExchange::initDeviceInfo( RTUDeviceMap& m, ModbusRTU::ModbusAddr a, UniX
if( d->second->speed == ComPort::ComSpeed0 ) if( d->second->speed == ComPort::ComSpeed0 )
{ {
d->second->speed = defSpeed; d->second->speed = defSpeed;
dcrit << myname << "(initDeviceInfo): Unknown speed=" << s << mbcrit << myname << "(initDeviceInfo): Unknown speed=" << s <<
" for addr=" << ModbusRTU::addr2str(a) << endl; " for addr=" << ModbusRTU::addr2str(a) << endl;
return false; return false;
} }
......
...@@ -17,7 +17,6 @@ int main( int argc, const char** argv ) ...@@ -17,7 +17,6 @@ int main( int argc, const char** argv )
{ {
cout << "--smemory-id objectName - SharedMemory objectID. Default: autodetect" << endl; cout << "--smemory-id objectName - SharedMemory objectID. Default: autodetect" << endl;
cout << "--confile filename - configuration file. Default: configure.xml" << endl; cout << "--confile filename - configuration file. Default: configure.xml" << endl;
cout << "--mbtcp-logfile filename - logfilename" << endl;
cout << endl; cout << endl;
MBTCPMaster::help_print(argc, argv); MBTCPMaster::help_print(argc, argv);
return 0; return 0;
...@@ -27,17 +26,6 @@ int main( int argc, const char** argv ) ...@@ -27,17 +26,6 @@ int main( int argc, const char** argv )
{ {
auto conf = uniset_init( argc, argv ); auto conf = uniset_init( argc, argv );
string logfilename(conf->getArgParam("--mbtcp-logfile"));
if( !logfilename.empty() )
{
std::ostringstream logname;
string dir(conf->getLogDir());
logname << dir << logfilename;
ulog()->logFile( logname.str() );
dlog()->logFile( logname.str() );
}
ObjectId shmID = DefaultObjectId; ObjectId shmID = DefaultObjectId;
string sID = conf->getArgParam("--smemory-id"); string sID = conf->getArgParam("--smemory-id");
......
...@@ -15,7 +15,6 @@ int main( int argc, const char** argv ) ...@@ -15,7 +15,6 @@ int main( int argc, const char** argv )
{ {
cout << "--smemory-id objectName - SharedMemory objectID. Default: get from configure..." << endl; cout << "--smemory-id objectName - SharedMemory objectID. Default: get from configure..." << endl;
cout << "--confile filename - configuration file. Default: configure.xml" << endl; cout << "--confile filename - configuration file. Default: configure.xml" << endl;
cout << "--mbtcp-logfile filename - logfilename" << endl;
cout << endl; cout << endl;
MBTCPMultiMaster::help_print(argc, argv); MBTCPMultiMaster::help_print(argc, argv);
return 0; return 0;
...@@ -25,17 +24,6 @@ int main( int argc, const char** argv ) ...@@ -25,17 +24,6 @@ int main( int argc, const char** argv )
{ {
auto conf = uniset_init( argc, argv ); auto conf = uniset_init( argc, argv );
string logfilename(conf->getArgParam("--mbtcp-logfile"));
if( !logfilename.empty() )
{
std::ostringstream logname;
string dir(conf->getLogDir());
logname << dir << logfilename;
ulog()->logFile( logname.str() );
dlog()->logFile( logname.str() );
}
ObjectId shmID = DefaultObjectId; ObjectId shmID = DefaultObjectId;
string sID = conf->getArgParam("--smemory-id"); string sID = conf->getArgParam("--smemory-id");
......
...@@ -17,7 +17,6 @@ int main( int argc, char** argv ) ...@@ -17,7 +17,6 @@ int main( int argc, char** argv )
{ {
cout << "--smemory-id objectName - SharedMemory objectID. Default: read from <SharedMemory>" << endl; cout << "--smemory-id objectName - SharedMemory objectID. Default: read from <SharedMemory>" << endl;
cout << "--confile filename - configuration file. Default: configure.xml" << endl; cout << "--confile filename - configuration file. Default: configure.xml" << endl;
cout << "--rs-logfile filename - logfilename. Default: rtuexchange.log" << endl;
cout << endl; cout << endl;
RTUExchange::help_print(argc, argv); RTUExchange::help_print(argc, argv);
return 0; return 0;
...@@ -25,17 +24,6 @@ int main( int argc, char** argv ) ...@@ -25,17 +24,6 @@ int main( int argc, char** argv )
auto conf = uniset_init( argc, argv ); auto conf = uniset_init( argc, argv );
string logfilename(conf->getArgParam("--rs-logfile"));
if( logfilename.empty() )
logfilename = "rtuexchange.log";
std::ostringstream logname;
string dir(conf->getLogDir());
logname << dir << logfilename;
ulog()->logFile( logname.str() );
dlog()->logFile( logname.str() );
ObjectId shmID = DefaultObjectId; ObjectId shmID = DefaultObjectId;
string sID = conf->getArgParam("--smemory-id"); string sID = conf->getArgParam("--smemory-id");
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "MBSlave.h" #include "MBSlave.h"
#include "modbus/ModbusRTUSlaveSlot.h" #include "modbus/ModbusRTUSlaveSlot.h"
#include "modbus/ModbusTCPServerSlot.h" #include "modbus/ModbusTCPServerSlot.h"
#include "modbus/MBLogSugar.h"
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
using namespace std; using namespace std;
using namespace UniSetTypes; using namespace UniSetTypes;
...@@ -35,8 +36,13 @@ MBSlave::MBSlave( UniSetTypes::ObjectId objId, UniSetTypes::ObjectId shmId, cons ...@@ -35,8 +36,13 @@ MBSlave::MBSlave( UniSetTypes::ObjectId objId, UniSetTypes::ObjectId shmId, cons
mutex_start.setName(myname + "_mutex_start"); mutex_start.setName(myname + "_mutex_start");
mblog = make_shared<DebugStream>(); mblog = make_shared<DebugStream>();
mblog->setLogName(myname);
conf->initLogStream(mblog, prefix + "-log"); conf->initLogStream(mblog, prefix + "-log");
logserv = make_shared<LogServer>(mblog);
loga = make_shared<LogAgregator>();
loga->add(mblog);
loga->add(ulog());
loga->add(dlog());
// xmlNode* cnode = conf->getNode(myname); // xmlNode* cnode = conf->getNode(myname);
...@@ -50,6 +56,8 @@ MBSlave::MBSlave( UniSetTypes::ObjectId objId, UniSetTypes::ObjectId shmId, cons ...@@ -50,6 +56,8 @@ MBSlave::MBSlave( UniSetTypes::ObjectId objId, UniSetTypes::ObjectId shmId, cons
UniXML::iterator it(cnode); UniXML::iterator it(cnode);
logserv = make_shared<LogServer>(loga);
logserv->init( prefix+"-logserver", cnode );
if( findArgParam("--" + prefix + "-run-logserver", conf->getArgc(), conf->getArgv()) != -1 ) if( findArgParam("--" + prefix + "-run-logserver", conf->getArgc(), conf->getArgv()) != -1 )
{ {
logserv_host = conf->getArg2Param("--" + prefix + "-logserver-host", it.getProp("logserverHost"), "localhost"); logserv_host = conf->getArg2Param("--" + prefix + "-logserver-host", it.getProp("logserverHost"), "localhost");
...@@ -1187,6 +1195,7 @@ void MBSlave::help_print( int argc, const char* const* argv ) ...@@ -1187,6 +1195,7 @@ void MBSlave::help_print( int argc, const char* const* argv )
cout << "--prefix-run-logserver - run logserver. Default: localhost:id" << endl; cout << "--prefix-run-logserver - run logserver. Default: localhost:id" << endl;
cout << "--prefix-logserver-host ip - listen ip. Default: localhost" << endl; cout << "--prefix-logserver-host ip - listen ip. Default: localhost" << endl;
cout << "--prefix-logserver-port num - listen port. Default: ID" << endl; cout << "--prefix-logserver-port num - listen port. Default: ID" << endl;
cout << LogServer::help_print("prefix-logserver") << endl;
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
std::shared_ptr<MBSlave> MBSlave::init_mbslave( int argc, const char* const* argv, UniSetTypes::ObjectId icID, std::shared_ptr<MBSlave> MBSlave::init_mbslave( int argc, const char* const* argv, UniSetTypes::ObjectId icID,
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
#include "VTypes.h" #include "VTypes.h"
#include "ThreadCreator.h" #include "ThreadCreator.h"
#include "LogServer.h" #include "LogServer.h"
#include "modbus/MBLogSugar.h" #include "LogAgregator.h"
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
/*! /*!
\page page_ModbusSlave Реализация Modbus slave \page page_ModbusSlave Реализация Modbus slave
...@@ -514,6 +514,7 @@ class MBSlave: ...@@ -514,6 +514,7 @@ class MBSlave:
MEIDevIDMap meidev; MEIDevIDMap meidev;
std::shared_ptr<LogAgregator> loga;
std::shared_ptr<DebugStream> mblog; std::shared_ptr<DebugStream> mblog;
std::shared_ptr<LogServer> logserv; std::shared_ptr<LogServer> logserv;
std::string logserv_host = {""}; std::string logserv_host = {""};
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "MBTCPMultiSlave.h" #include "MBTCPMultiSlave.h"
#include "modbus/ModbusRTUSlaveSlot.h" #include "modbus/ModbusRTUSlaveSlot.h"
#include "modbus/ModbusTCPServerSlot.h" #include "modbus/ModbusTCPServerSlot.h"
#include "modbus/MBLogSugar.h"
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
using namespace std; using namespace std;
using namespace UniSetTypes; using namespace UniSetTypes;
......
...@@ -21,7 +21,6 @@ int main(int argc, const char** argv) ...@@ -21,7 +21,6 @@ int main(int argc, const char** argv)
{ {
cout << "--smemory-id objectName - SharedMemory objectID. Default: autodetect" << endl; cout << "--smemory-id objectName - SharedMemory objectID. Default: autodetect" << endl;
cout << "--confile filename - configuration file. Default: configure.xml" << endl; cout << "--confile filename - configuration file. Default: configure.xml" << endl;
cout << "--mbs-logfile filename - logfilename" << endl;
cout << endl; cout << endl;
MBSlave::help_print(argc, argv); MBSlave::help_print(argc, argv);
return 0; return 0;
...@@ -31,17 +30,6 @@ int main(int argc, const char** argv) ...@@ -31,17 +30,6 @@ int main(int argc, const char** argv)
{ {
auto conf = uniset_init(argc, argv); auto conf = uniset_init(argc, argv);
string logfilename(conf->getArgParam("--mbs-logfile"));
if( !logfilename.empty() )
{
std::ostringstream logname;
string dir(conf->getLogDir());
logname << dir << logfilename;
ulog()->logFile( logname.str() );
dlog()->logFile( logname.str() );
}
ObjectId shmID = DefaultObjectId; ObjectId shmID = DefaultObjectId;
string sID = conf->getArgParam("--smemory-id"); string sID = conf->getArgParam("--smemory-id");
......
...@@ -12,14 +12,30 @@ using namespace UniSetTypes; ...@@ -12,14 +12,30 @@ using namespace UniSetTypes;
using namespace UniSetExtensions; using namespace UniSetExtensions;
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
RRDServer::RRDServer( UniSetTypes::ObjectId objId, xmlNode* cnode, UniSetTypes::ObjectId shmId, const std::shared_ptr<SharedMemory> ic, RRDServer::RRDServer( UniSetTypes::ObjectId objId, xmlNode* cnode, UniSetTypes::ObjectId shmId, const std::shared_ptr<SharedMemory> ic,
const string& prefix, std::shared_ptr<DebugStream> log ): const string& prefix ):
UObject_SK(objId, cnode), UObject_SK(objId, cnode),
prefix(prefix) prefix(prefix)
{ {
auto conf = uniset_conf();
shm = make_shared<SMInterface>(shmId, ui, objId, ic); shm = make_shared<SMInterface>(shmId, ui, objId, ic);
mylog = log;
loga = make_shared<LogAgregator>();
loga->add(mylog);
loga->add(ulog());
loga->add(dlog());
UniXML::iterator it(cnode); UniXML::iterator it(cnode);
logserv = make_shared<LogServer>(loga);
logserv->init( prefix+"-logserver", cnode );
if( findArgParam("--" + prefix + "-run-logserver", conf->getArgc(), conf->getArgv()) != -1 )
{
logserv_host = conf->getArg2Param("--" + prefix + "-logserver-host", it.getProp("logserverHost"), "localhost");
logserv_port = conf->getArgPInt("--" + prefix + "-logserver-port", it.getProp("logserverPort"), getId());
}
UniXML::iterator it1(cnode); UniXML::iterator it1(cnode);
if( !it1.goChildren() ) if( !it1.goChildren() )
...@@ -231,6 +247,19 @@ void RRDServer::help_print( int argc, const char* const* argv ) ...@@ -231,6 +247,19 @@ void RRDServer::help_print( int argc, const char* const* argv )
cout << "--prefix-confnode - configuration section name. Default: <NAME name='NAME'...> " << endl; cout << "--prefix-confnode - configuration section name. Default: <NAME name='NAME'...> " << endl;
cout << "--prefix-heartbeat-id name - ID for heartbeat sensor." << endl; cout << "--prefix-heartbeat-id name - ID for heartbeat sensor." << endl;
cout << "--prefix-heartbeat-max val - max value for heartbeat sensor." << endl; cout << "--prefix-heartbeat-max val - max value for heartbeat sensor." << endl;
cout << endl;
cout << " Logs: " << endl;
cout << "--prefix-log-... - log control" << endl;
cout << " add-levels ... " << endl;
cout << " del-levels ... " << endl;
cout << " set-levels ... " << endl;
cout << " logfile filanme " << endl;
cout << " no-debug " << endl;
cout << " LogServer: " << endl;
cout << "--prefix-run-logserver - run logserver. Default: localhost:id" << endl;
cout << "--prefix-logserver-host ip - listen ip. Default: localhost" << endl;
cout << "--prefix-logserver-port num - listen port. Default: ID" << endl;
cout << LogServer::help_print("prefix-logserver") << endl;
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
std::shared_ptr<RRDServer> RRDServer::init_rrdstorage( int argc, const char* const* argv, std::shared_ptr<RRDServer> RRDServer::init_rrdstorage( int argc, const char* const* argv,
...@@ -295,7 +324,13 @@ void RRDServer::sysCommand( const UniSetTypes::SystemMessage* sm ) ...@@ -295,7 +324,13 @@ void RRDServer::sysCommand( const UniSetTypes::SystemMessage* sm )
if( sm->command == SystemMessage::StartUp || sm->command == SystemMessage::WatchDog ) if( sm->command == SystemMessage::StartUp || sm->command == SystemMessage::WatchDog )
{ {
for( auto& it : rrdlist ) if( !logserv_host.empty() && logserv_port != 0 && !logserv->isRunning() )
{
myinfo << myname << "(init): run log server " << logserv_host << ":" << logserv_port << endl;
logserv->run(logserv_host, logserv_port, true);
}
for( auto&& it : rrdlist )
{ {
try try
{ {
......
...@@ -7,6 +7,9 @@ ...@@ -7,6 +7,9 @@
#include "SMInterface.h" #include "SMInterface.h"
#include "SharedMemory.h" #include "SharedMemory.h"
#include "extensions/Extensions.h" #include "extensions/Extensions.h"
#include "LogAgregator.h"
#include "LogServer.h"
#include "LogAgregator.h"
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
/*! /*!
\page page_RRDServer Реализация RRD хранилища \page page_RRDServer Реализация RRD хранилища
...@@ -61,7 +64,7 @@ class RRDServer: ...@@ -61,7 +64,7 @@ class RRDServer:
{ {
public: public:
RRDServer( UniSetTypes::ObjectId objId, xmlNode* cnode, UniSetTypes::ObjectId shmID, const std::shared_ptr<SharedMemory> ic = nullptr, RRDServer( UniSetTypes::ObjectId objId, xmlNode* cnode, UniSetTypes::ObjectId shmID, const std::shared_ptr<SharedMemory> ic = nullptr,
const std::string& prefix = "rrd", std::shared_ptr<DebugStream> log = UniSetExtensions::dlog() ); const std::string& prefix = "rrd" );
virtual ~RRDServer(); virtual ~RRDServer();
/*! глобальная функция для инициализации объекта */ /*! глобальная функция для инициализации объекта */
...@@ -111,6 +114,11 @@ class RRDServer: ...@@ -111,6 +114,11 @@ class RRDServer:
RRDList rrdlist; RRDList rrdlist;
std::shared_ptr<LogAgregator> loga;
std::shared_ptr<LogServer> logserv;
std::string logserv_host = {""};
int logserv_port = {0};
private: private:
std::string prefix; std::string prefix;
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "SharedMemory.h" #include "SharedMemory.h"
#include "Extensions.h" #include "Extensions.h"
#include "ORepHelpers.h" #include "ORepHelpers.h"
#include "SMLogSugar.h"
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
using namespace std; using namespace std;
using namespace UniSetTypes; using namespace UniSetTypes;
...@@ -40,6 +41,7 @@ void SharedMemory::help_print( int argc, const char* const* argv ) ...@@ -40,6 +41,7 @@ void SharedMemory::help_print( int argc, const char* const* argv )
cout << "--sm-run-logserver - run logserver. Default: localhost:id" << endl; cout << "--sm-run-logserver - run logserver. Default: localhost:id" << endl;
cout << "--sm-logserver-host ip - listen ip. Default: localhost" << endl; cout << "--sm-logserver-host ip - listen ip. Default: localhost" << endl;
cout << "--sm-logserver-port num - listen port. Default: ID" << endl; cout << "--sm-logserver-port num - listen port. Default: ID" << endl;
cout << LogServer::help_print("sm-logserver") << endl;
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
SharedMemory::SharedMemory( ObjectId id, const std::string& datafile, const std::string& confname ): SharedMemory::SharedMemory( ObjectId id, const std::string& datafile, const std::string& confname ):
...@@ -69,16 +71,18 @@ SharedMemory::SharedMemory( ObjectId id, const std::string& datafile, const std: ...@@ -69,16 +71,18 @@ SharedMemory::SharedMemory( ObjectId id, const std::string& datafile, const std:
string prefix="sm"; string prefix="sm";
smlog = make_shared<DebugStream>(); smlog = make_shared<DebugStream>();
smlog->setLogName(myname);
conf->initLogStream(smlog,prefix+"-log"); conf->initLogStream(smlog,prefix+"-log");
loga = make_shared<LogAgregator>(); loga = make_shared<LogAgregator>();
loga->add(smlog); loga->add(smlog);
loga->add(ulog()); loga->add(ulog());
loga->add(dlog());
logserv = make_shared<LogServer>(loga);
UniXML::iterator it(confnode); UniXML::iterator it(confnode);
logserv = make_shared<LogServer>(loga);
logserv->init( prefix+"-logserver", confnode );
// ---------------------- // ----------------------
if( findArgParam("--" + prefix + "-run-logserver", conf->getArgc(), conf->getArgv()) != -1 ) if( findArgParam("--" + prefix + "-run-logserver", conf->getArgc(), conf->getArgv()) != -1 )
{ {
......
...@@ -13,7 +13,6 @@ ...@@ -13,7 +13,6 @@
#include "WDTInterface.h" #include "WDTInterface.h"
#include "LogServer.h" #include "LogServer.h"
#include "DebugStream.h" #include "DebugStream.h"
#include "SMLogSugar.h"
#include "LogAgregator.h" #include "LogAgregator.h"
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
......
...@@ -23,14 +23,6 @@ int main(int argc, const char** argv) ...@@ -23,14 +23,6 @@ int main(int argc, const char** argv)
{ {
auto conf = uniset_init(argc, argv); auto conf = uniset_init(argc, argv);
string logfilename = conf->getArgParam("--logfile", "");
if( !logfilename.empty() )
{
string logname( conf->getLogDir() + logfilename );
ulog()->logFile( logname );
dlog()->logFile( logname );
}
auto shm = SharedMemory::init_smemory(argc, argv); auto shm = SharedMemory::init_smemory(argc, argv);
if( !shm ) if( !shm )
......
...@@ -47,12 +47,6 @@ int main( int argc, const char** argv ) ...@@ -47,12 +47,6 @@ int main( int argc, const char** argv )
{ {
auto conf = uniset_init(argc, argv); auto conf = uniset_init(argc, argv);
string logfilename = conf->getArgParam("--logfile", "smemory-plus.log");
string logname( conf->getLogDir() + logfilename );
UniSetExtensions::dlog()->logFile( logname );
ulog()->logFile( logname );
dlog()->logFile( logname );
auto act = UniSetActivator::Instance(); auto act = UniSetActivator::Instance();
//act->signal_terminate_event().connect( &activator_terminate ); //act->signal_terminate_event().connect( &activator_terminate );
// ------------ SharedMemory ---------------- // ------------ SharedMemory ----------------
...@@ -244,18 +238,6 @@ int main( int argc, const char** argv ) ...@@ -244,18 +238,6 @@ int main( int argc, const char** argv )
#endif #endif
auto la = make_shared<LogAgregator>();
la->add(ulog());
la->add(dlog());
auto logserver = run_logserver("smplus", la);
if( logserver == 0 )
{
cerr << "(smemory-plus): run logserver for 'smplus' FAILED" << endl;
return 1;
}
act->run(false); act->run(false);
on_sigchild(SIGTERM); on_sigchild(SIGTERM);
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#include "Exceptions.h" #include "Exceptions.h"
#include "Extensions.h" #include "Extensions.h"
#include "UNetExchange.h" #include "UNetExchange.h"
#include "UNetLogSugar.h"
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
using namespace std; using namespace std;
using namespace UniSetTypes; using namespace UniSetTypes;
...@@ -23,19 +24,36 @@ UNetExchange::UNetExchange( UniSetTypes::ObjectId objId, UniSetTypes::ObjectId s ...@@ -23,19 +24,36 @@ UNetExchange::UNetExchange( UniSetTypes::ObjectId objId, UniSetTypes::ObjectId s
if( cnode == NULL ) if( cnode == NULL )
throw UniSetTypes::SystemError("(UNetExchange): Not found conf-node for " + myname ); throw UniSetTypes::SystemError("(UNetExchange): Not found conf-node for " + myname );
unetlog = make_shared<DebugStream>();
unetlog->setLogName(myname);
conf->initLogStream(unetlog,prefix+"-log");
loga = make_shared<LogAgregator>();
loga->add(unetlog);
loga->add(ulog());
loga->add(dlog());
shm = make_shared<SMInterface>(shmId, ui, objId, ic); shm = make_shared<SMInterface>(shmId, ui, objId, ic);
UniXML::iterator it(cnode); UniXML::iterator it(cnode);
logserv = make_shared<LogServer>(loga);
logserv->init( prefix+"-logserver", cnode );
if( findArgParam("--" + prefix + "-run-logserver", conf->getArgc(), conf->getArgv()) != -1 )
{
logserv_host = conf->getArg2Param("--" + prefix + "-logserver-host", it.getProp("logserverHost"), "localhost");
logserv_port = conf->getArgPInt("--" + prefix + "-logserver-port", it.getProp("logserverPort"), getId());
}
// определяем фильтр // определяем фильтр
s_field = conf->getArgParam("--" + prefix + "-filter-field"); s_field = conf->getArgParam("--" + prefix + "-filter-field");
s_fvalue = conf->getArgParam("--" + prefix + "-filter-value"); s_fvalue = conf->getArgParam("--" + prefix + "-filter-value");
dinfo << myname << "(init): read filter-field='" << s_field unetinfo << myname << "(init): read filter-field='" << s_field
<< "' filter-value='" << s_fvalue << "'" << endl; << "' filter-value='" << s_fvalue << "'" << endl;
const string n_field(conf->getArgParam("--" + prefix + "-nodes-filter-field")); const string n_field(conf->getArgParam("--" + prefix + "-nodes-filter-field"));
const string n_fvalue(conf->getArgParam("--" + prefix + "-nodes-filter-value")); const string n_fvalue(conf->getArgParam("--" + prefix + "-nodes-filter-value"));
dinfo << myname << "(init): read nodes-filter-field='" << n_field unetinfo << myname << "(init): read nodes-filter-field='" << n_field
<< "' nodes-filter-value='" << n_fvalue << "'" << endl; << "' nodes-filter-value='" << n_fvalue << "'" << endl;
int recvTimeout = conf->getArgPInt("--" + prefix + "-recv-timeout", it.getProp("recvTimeout"), 5000); int recvTimeout = conf->getArgPInt("--" + prefix + "-recv-timeout", it.getProp("recvTimeout"), 5000);
...@@ -62,7 +80,7 @@ UNetExchange::UNetExchange( UniSetTypes::ObjectId objId, UniSetTypes::ObjectId s ...@@ -62,7 +80,7 @@ UNetExchange::UNetExchange( UniSetTypes::ObjectId objId, UniSetTypes::ObjectId s
nodes = conf->findNode(xml->getFirstNode(), nconfname); nodes = conf->findNode(xml->getFirstNode(), nconfname);
} }
dinfo << myname << "(init): init from <" << nconfname << ">" << endl; unetinfo << myname << "(init): init from <" << nconfname << ">" << endl;
if( !nodes ) if( !nodes )
throw UniSetTypes::SystemError("(UNetExchange): Not found confnode <" + nconfname +">"); throw UniSetTypes::SystemError("(UNetExchange): Not found confnode <" + nconfname +">");
...@@ -79,7 +97,7 @@ UNetExchange::UNetExchange( UniSetTypes::ObjectId objId, UniSetTypes::ObjectId s ...@@ -79,7 +97,7 @@ UNetExchange::UNetExchange( UniSetTypes::ObjectId objId, UniSetTypes::ObjectId s
{ {
if( n_it.getIntProp("unet_ignore") ) if( n_it.getIntProp("unet_ignore") )
{ {
dinfo << myname << "(init): unet_ignore.. for " << n_it.getProp("name") << endl; unetinfo << myname << "(init): unet_ignore.. for " << n_it.getProp("name") << endl;
continue; continue;
} }
...@@ -108,12 +126,12 @@ UNetExchange::UNetExchange( UniSetTypes::ObjectId objId, UniSetTypes::ObjectId s ...@@ -108,12 +126,12 @@ UNetExchange::UNetExchange( UniSetTypes::ObjectId objId, UniSetTypes::ObjectId s
{ {
ostringstream err; ostringstream err;
err << myname << "(init): Unknown broadcast IP for " << n_it.getProp("name"); err << myname << "(init): Unknown broadcast IP for " << n_it.getProp("name");
dcrit << err.str() << endl; unetcrit << err.str() << endl;
throw UniSetTypes::SystemError(err.str()); throw UniSetTypes::SystemError(err.str());
} }
if( h2.empty() ) if( h2.empty() )
dinfo << myname << "(init): ip2 not used..." << endl; unetinfo << myname << "(init): ip2 not used..." << endl;
// Если указано поле unet_port - используем его // Если указано поле unet_port - используем его
// Иначе port = идентификатору узла // Иначе port = идентификатору узла
...@@ -133,23 +151,25 @@ UNetExchange::UNetExchange( UniSetTypes::ObjectId objId, UniSetTypes::ObjectId s ...@@ -133,23 +151,25 @@ UNetExchange::UNetExchange( UniSetTypes::ObjectId objId, UniSetTypes::ObjectId s
{ {
if( no_sender ) if( no_sender )
{ {
dinfo << myname << "(init): sender OFF for this node...(" unetinfo << myname << "(init): sender OFF for this node...("
<< n_it.getProp("name") << ")" << endl; << n_it.getProp("name") << ")" << endl;
continue; continue;
} }
dinfo << myname << "(init): init sender.. my node " << n_it.getProp("name") << endl; unetinfo << myname << "(init): init sender.. my node " << n_it.getProp("name") << endl;
sender = make_shared<UNetSender>(h, p, shm, s_field, s_fvalue); sender = make_shared<UNetSender>(h, p, shm, s_field, s_fvalue);
sender->setSendPause(sendpause); sender->setSendPause(sendpause);
loga->add(sender->getLog());
try try
{ {
// создаём "писателя" для второго канала если задан // создаём "писателя" для второго канала если задан
if( !h2.empty() ) if( !h2.empty() )
{ {
dinfo << myname << "(init): init sender2.. my node " << n_it.getProp("name") << endl; unetinfo << myname << "(init): init sender2.. my node " << n_it.getProp("name") << endl;
sender2 = make_shared<UNetSender>(h2, p2, shm, s_field, s_fvalue); sender2 = make_shared<UNetSender>(h2, p2, shm, s_field, s_fvalue);
sender2->setSendPause(sendpause); sender2->setSendPause(sendpause);
loga->add(sender2->getLog());
} }
} }
catch(...) catch(...)
...@@ -157,17 +177,17 @@ UNetExchange::UNetExchange( UniSetTypes::ObjectId objId, UniSetTypes::ObjectId s ...@@ -157,17 +177,17 @@ UNetExchange::UNetExchange( UniSetTypes::ObjectId objId, UniSetTypes::ObjectId s
// т.е. это "резервный канал", то игнорируем ошибку его создания // т.е. это "резервный канал", то игнорируем ошибку его создания
// при запуске "интерфейс" может быть и не доступен... // при запуске "интерфейс" может быть и не доступен...
sender2 = 0; sender2 = 0;
dcrit << myname << "(ignore): DON`T CREATE 'UNetSender' for " << h2 << ":" << p2 << endl; unetcrit << myname << "(ignore): DON`T CREATE 'UNetSender' for " << h2 << ":" << p2 << endl;
} }
continue; continue;
} }
dinfo << myname << "(init): add UNetReceiver for " << h << ":" << p << endl; unetinfo << myname << "(init): add UNetReceiver for " << h << ":" << p << endl;
if( checkExistUNetHost(h, p) ) if( checkExistUNetHost(h, p) )
{ {
dinfo << myname << "(init): " << h << ":" << p << " already added! Ignore.." << endl; unetinfo << myname << "(init): " << h << ":" << p << " already added! Ignore.." << endl;
continue; continue;
} }
...@@ -184,7 +204,7 @@ UNetExchange::UNetExchange( UniSetTypes::ObjectId objId, UniSetTypes::ObjectId s ...@@ -184,7 +204,7 @@ UNetExchange::UNetExchange( UniSetTypes::ObjectId objId, UniSetTypes::ObjectId s
{ {
ostringstream err; ostringstream err;
err << myname << ": Unknown RespondID.. Not found id for '" << s_resp_id << "'" << endl; err << myname << ": Unknown RespondID.. Not found id for '" << s_resp_id << "'" << endl;
dcrit << myname << "(init): " << err.str() << endl; unetcrit << myname << "(init): " << err.str() << endl;
throw SystemError(err.str()); throw SystemError(err.str());
} }
} }
...@@ -200,7 +220,7 @@ UNetExchange::UNetExchange( UniSetTypes::ObjectId objId, UniSetTypes::ObjectId s ...@@ -200,7 +220,7 @@ UNetExchange::UNetExchange( UniSetTypes::ObjectId objId, UniSetTypes::ObjectId s
{ {
ostringstream err; ostringstream err;
err << myname << ": Unknown RespondID(2).. Not found id for '" << s_resp2_id << "'" << endl; err << myname << ": Unknown RespondID(2).. Not found id for '" << s_resp2_id << "'" << endl;
dcrit << myname << "(init): " << err.str() << endl; unetcrit << myname << "(init): " << err.str() << endl;
throw SystemError(err.str()); throw SystemError(err.str());
} }
} }
...@@ -216,7 +236,7 @@ UNetExchange::UNetExchange( UniSetTypes::ObjectId objId, UniSetTypes::ObjectId s ...@@ -216,7 +236,7 @@ UNetExchange::UNetExchange( UniSetTypes::ObjectId objId, UniSetTypes::ObjectId s
{ {
ostringstream err; ostringstream err;
err << myname << ": Unknown LostPacketsID.. Not found id for '" << s_lp_id << "'" << endl; err << myname << ": Unknown LostPacketsID.. Not found id for '" << s_lp_id << "'" << endl;
dcrit << myname << "(init): " << err.str() << endl; unetcrit << myname << "(init): " << err.str() << endl;
throw SystemError(err.str()); throw SystemError(err.str());
} }
} }
...@@ -232,7 +252,7 @@ UNetExchange::UNetExchange( UniSetTypes::ObjectId objId, UniSetTypes::ObjectId s ...@@ -232,7 +252,7 @@ UNetExchange::UNetExchange( UniSetTypes::ObjectId objId, UniSetTypes::ObjectId s
{ {
ostringstream err; ostringstream err;
err << myname << ": Unknown LostPacketsID(2).. Not found id for '" << s_lp2_id << "'" << endl; err << myname << ": Unknown LostPacketsID(2).. Not found id for '" << s_lp2_id << "'" << endl;
dcrit << myname << "(init): " << err.str() << endl; unetcrit << myname << "(init): " << err.str() << endl;
throw SystemError(err.str()); throw SystemError(err.str());
} }
} }
...@@ -248,7 +268,7 @@ UNetExchange::UNetExchange( UniSetTypes::ObjectId objId, UniSetTypes::ObjectId s ...@@ -248,7 +268,7 @@ UNetExchange::UNetExchange( UniSetTypes::ObjectId objId, UniSetTypes::ObjectId s
{ {
ostringstream err; ostringstream err;
err << myname << ": Unknown LostPacketsID(comm).. Not found id for '" << s_lp_comm_id << "'" << endl; err << myname << ": Unknown LostPacketsID(comm).. Not found id for '" << s_lp_comm_id << "'" << endl;
dcrit << myname << "(init): " << err.str() << endl; unetcrit << myname << "(init): " << err.str() << endl;
throw SystemError(err.str()); throw SystemError(err.str());
} }
} }
...@@ -264,7 +284,7 @@ UNetExchange::UNetExchange( UniSetTypes::ObjectId objId, UniSetTypes::ObjectId s ...@@ -264,7 +284,7 @@ UNetExchange::UNetExchange( UniSetTypes::ObjectId objId, UniSetTypes::ObjectId s
{ {
ostringstream err; ostringstream err;
err << myname << ": Unknown RespondID(comm).. Not found id for '" << s_resp_comm_id << "'" << endl; err << myname << ": Unknown RespondID(comm).. Not found id for '" << s_resp_comm_id << "'" << endl;
dcrit << myname << "(init): " << err.str() << endl; unetcrit << myname << "(init): " << err.str() << endl;
throw SystemError(err.str()); throw SystemError(err.str());
} }
} }
...@@ -280,15 +300,17 @@ UNetExchange::UNetExchange( UniSetTypes::ObjectId objId, UniSetTypes::ObjectId s ...@@ -280,15 +300,17 @@ UNetExchange::UNetExchange( UniSetTypes::ObjectId objId, UniSetTypes::ObjectId s
{ {
ostringstream err; ostringstream err;
err << myname << ": Unknown NumChannelID.. Not found id for '" << s_numchannel_id << "'" << endl; err << myname << ": Unknown NumChannelID.. Not found id for '" << s_numchannel_id << "'" << endl;
dcrit << myname << "(init): " << err.str() << endl; unetcrit << myname << "(init): " << err.str() << endl;
throw SystemError(err.str()); throw SystemError(err.str());
} }
} }
dinfo << myname << "(init): (node='" << n << "') add receiver " unetinfo << myname << "(init): (node='" << n << "') add receiver "
<< h2 << ":" << p2 << endl; << h2 << ":" << p2 << endl;
auto r = make_shared<UNetReceiver>(h, p, shm); auto r = make_shared<UNetReceiver>(h, p, shm);
loga->add(r->getLog());
// на всякий принудительно разблокируем, // на всякий принудительно разблокируем,
// чтобы не зависеть от значения по умолчанию // чтобы не зависеть от значения по умолчанию
r->setLockUpdate(false); r->setLockUpdate(false);
...@@ -310,11 +332,13 @@ UNetExchange::UNetExchange( UniSetTypes::ObjectId objId, UniSetTypes::ObjectId s ...@@ -310,11 +332,13 @@ UNetExchange::UNetExchange( UniSetTypes::ObjectId objId, UniSetTypes::ObjectId s
{ {
if( !h2.empty() ) // создаём читателя впо второму каналу if( !h2.empty() ) // создаём читателя впо второму каналу
{ {
dinfo << myname << "(init): (node='" << n << "') add reserv receiver " unetinfo << myname << "(init): (node='" << n << "') add reserv receiver "
<< h2 << ":" << p2 << endl; << h2 << ":" << p2 << endl;
r2 = make_shared<UNetReceiver>(h2, p2, shm); r2 = make_shared<UNetReceiver>(h2, p2, shm);
loga->add(r2->getLog());
// т.к. это резервный канал (по началу блокируем его) // т.к. это резервный канал (по началу блокируем его)
r2->setLockUpdate(true); r2->setLockUpdate(true);
...@@ -334,7 +358,7 @@ UNetExchange::UNetExchange( UniSetTypes::ObjectId objId, UniSetTypes::ObjectId s ...@@ -334,7 +358,7 @@ UNetExchange::UNetExchange( UniSetTypes::ObjectId objId, UniSetTypes::ObjectId s
// т.е. это "резервный канал", то игнорируем ошибку его создания // т.е. это "резервный канал", то игнорируем ошибку его создания
// при запуске "интерфейс" может быть и не доступен... // при запуске "интерфейс" может быть и не доступен...
r2 = 0; r2 = 0;
dcrit << myname << "(ignore): DON`T CREATE 'UNetReceiver' for " << h2 << ":" << p2 << endl; unetcrit << myname << "(ignore): DON`T CREATE 'UNetReceiver' for " << h2 << ":" << p2 << endl;
} }
ReceiverInfo ri(r, r2); ReceiverInfo ri(r, r2);
...@@ -356,7 +380,7 @@ UNetExchange::UNetExchange( UniSetTypes::ObjectId objId, UniSetTypes::ObjectId s ...@@ -356,7 +380,7 @@ UNetExchange::UNetExchange( UniSetTypes::ObjectId objId, UniSetTypes::ObjectId s
{ {
ostringstream err; ostringstream err;
err << myname << ": не найден идентификатор для датчика 'HeartBeat' " << heart; err << myname << ": не найден идентификатор для датчика 'HeartBeat' " << heart;
dcrit << myname << "(init): " << err.str() << endl; unetcrit << myname << "(init): " << err.str() << endl;
throw SystemError(err.str()); throw SystemError(err.str());
} }
...@@ -378,12 +402,12 @@ UNetExchange::UNetExchange( UniSetTypes::ObjectId objId, UniSetTypes::ObjectId s ...@@ -378,12 +402,12 @@ UNetExchange::UNetExchange( UniSetTypes::ObjectId objId, UniSetTypes::ObjectId s
{ {
ostringstream err; ostringstream err;
err << myname << "(init): test_id unknown. 'TestMode_S' not found..."; err << myname << "(init): test_id unknown. 'TestMode_S' not found...";
dcrit << myname << "(init): " << err.str() << endl; unetcrit << myname << "(init): " << err.str() << endl;
throw SystemError(err.str()); throw SystemError(err.str());
} }
} }
dinfo << myname << "(init): test_id=" << test_id << endl; unetinfo << myname << "(init): test_id=" << test_id << endl;
activateTimeout = conf->getArgPInt("--" + prefix + "-activate-timeout", 20000); activateTimeout = conf->getArgPInt("--" + prefix + "-activate-timeout", 20000);
} }
...@@ -431,7 +455,7 @@ void UNetExchange::waitSMReady() ...@@ -431,7 +455,7 @@ void UNetExchange::waitSMReady()
{ {
ostringstream err; ostringstream err;
err << myname << "(waitSMReady): Не дождались готовности SharedMemory к работе в течение " << ready_timeout << " мсек"; err << myname << "(waitSMReady): Не дождались готовности SharedMemory к работе в течение " << ready_timeout << " мсек";
dcrit << err.str() << endl; unetcrit << err.str() << endl;
throw SystemError(err.str()); throw SystemError(err.str());
} }
} }
...@@ -459,16 +483,16 @@ void UNetExchange::step() ...@@ -459,16 +483,16 @@ void UNetExchange::step()
} }
catch( const Exception& ex ) catch( const Exception& ex )
{ {
dcrit << myname << "(step): (hb) " << ex << std::endl; unetcrit << myname << "(step): (hb) " << ex << std::endl;
} }
} }
for( auto& it : recvlist ) for( auto&& it : recvlist )
it.step(shm, myname); it.step(shm, myname, unetlog);
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
void UNetExchange::ReceiverInfo::step( const std::shared_ptr<SMInterface> shm, const std::string& myname ) void UNetExchange::ReceiverInfo::step( const std::shared_ptr<SMInterface> shm, const std::string& myname, std::shared_ptr<DebugStream>& unetlog )
{ {
try try
{ {
...@@ -484,7 +508,7 @@ void UNetExchange::ReceiverInfo::step( const std::shared_ptr<SMInterface> shm, c ...@@ -484,7 +508,7 @@ void UNetExchange::ReceiverInfo::step( const std::shared_ptr<SMInterface> shm, c
} }
catch( const Exception& ex ) catch( const Exception& ex )
{ {
dcrit << myname << "(ReceiverInfo::step): (respond): " << ex << std::endl; unetcrit << myname << "(ReceiverInfo::step): (respond): " << ex << std::endl;
} }
try try
...@@ -504,7 +528,7 @@ void UNetExchange::ReceiverInfo::step( const std::shared_ptr<SMInterface> shm, c ...@@ -504,7 +528,7 @@ void UNetExchange::ReceiverInfo::step( const std::shared_ptr<SMInterface> shm, c
} }
catch( const Exception& ex ) catch( const Exception& ex )
{ {
dcrit << myname << "(ReceiverInfo::step): (lostpackets): " << ex << std::endl; unetcrit << myname << "(ReceiverInfo::step): (lostpackets): " << ex << std::endl;
} }
try try
...@@ -524,7 +548,7 @@ void UNetExchange::ReceiverInfo::step( const std::shared_ptr<SMInterface> shm, c ...@@ -524,7 +548,7 @@ void UNetExchange::ReceiverInfo::step( const std::shared_ptr<SMInterface> shm, c
} }
catch( const Exception& ex ) catch( const Exception& ex )
{ {
dcrit << myname << "(ReceiverInfo::step): (channelnum): " << ex << std::endl; unetcrit << myname << "(ReceiverInfo::step): (channelnum): " << ex << std::endl;
} }
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
...@@ -534,6 +558,12 @@ void UNetExchange::sysCommand( const UniSetTypes::SystemMessage* sm ) ...@@ -534,6 +558,12 @@ void UNetExchange::sysCommand( const UniSetTypes::SystemMessage* sm )
{ {
case SystemMessage::StartUp: case SystemMessage::StartUp:
{ {
if( !logserv_host.empty() && logserv_port != 0 && !logserv->isRunning() )
{
unetinfo << myname << "(init): run log server " << logserv_host << ":" << logserv_port << endl;
logserv->run(logserv_host, logserv_port, true);
}
waitSMReady(); waitSMReady();
// подождать пока пройдёт инициализация датчиков // подождать пока пройдёт инициализация датчиков
...@@ -551,7 +581,7 @@ void UNetExchange::sysCommand( const UniSetTypes::SystemMessage* sm ) ...@@ -551,7 +581,7 @@ void UNetExchange::sysCommand( const UniSetTypes::SystemMessage* sm )
} }
if( !activated ) if( !activated )
dcrit << myname << "(sysCommand): ************* don`t activate?! ************" << endl; unetcrit << myname << "(sysCommand): ************* don`t activate?! ************" << endl;
{ {
UniSetTypes::uniset_rwmutex_rlock l(mutex_start); UniSetTypes::uniset_rwmutex_rlock l(mutex_start);
...@@ -594,23 +624,13 @@ void UNetExchange::sysCommand( const UniSetTypes::SystemMessage* sm ) ...@@ -594,23 +624,13 @@ void UNetExchange::sysCommand( const UniSetTypes::SystemMessage* sm )
case SystemMessage::LogRotate: case SystemMessage::LogRotate:
{ {
// переоткрываем логи unetlogany << myname << "(sysCommand): logRotate" << std::endl;
ulogany << myname << "(sysCommand): logRotate" << std::endl; string fname = unetlog->getLogFile();
string fname(ulog()->getLogFile());
if( !fname.empty() )
{
ulog()->logFile(fname, true);
ulogany << myname << "(sysCommand): ***************** ulog LOG ROTATE *****************" << std::endl;
}
dlogany << myname << "(sysCommand): logRotate" << std::endl;
fname = dlog()->getLogFile();
if( !fname.empty() ) if( !fname.empty() )
{ {
dlog()->logFile(fname, true); unetlog->logFile(fname, true);
dlogany << myname << "(sysCommand): ***************** dlog LOG ROTATE *****************" << std::endl; unetlogany << myname << "(sysCommand): ***************** dlog LOG ROTATE *****************" << std::endl;
} }
} }
break; break;
...@@ -629,7 +649,7 @@ void UNetExchange::askSensors( UniversalIO::UIOCommand cmd ) ...@@ -629,7 +649,7 @@ void UNetExchange::askSensors( UniversalIO::UIOCommand cmd )
<< "(askSensors): Не дождались готовности(work) SharedMemory к работе в течение " << "(askSensors): Не дождались готовности(work) SharedMemory к работе в течение "
<< activateTimeout << " мсек"; << activateTimeout << " мсек";
dcrit << err.str() << endl; unetcrit << err.str() << endl;
kill(SIGTERM, getpid()); // прерываем (перезапускаем) процесс... kill(SIGTERM, getpid()); // прерываем (перезапускаем) процесс...
throw SystemError(err.str()); throw SystemError(err.str());
} }
...@@ -668,7 +688,7 @@ bool UNetExchange::activateObject() ...@@ -668,7 +688,7 @@ bool UNetExchange::activateObject()
// ------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------
void UNetExchange::sigterm( int signo ) void UNetExchange::sigterm( int signo )
{ {
dinfo << myname << ": ********* SIGTERM(" << signo << ") ********" << endl; unetinfo << myname << ": ********* SIGTERM(" << signo << ") ********" << endl;
activated = false; activated = false;
for( auto& it : recvlist ) for( auto& it : recvlist )
...@@ -736,6 +756,19 @@ void UNetExchange::help_print( int argc, const char* argv[] ) ...@@ -736,6 +756,19 @@ void UNetExchange::help_print( int argc, const char* argv[] )
cout << "--prefix-sm-ready-timeout msec - Время ожидание я готовности SM к работе. По умолчанию 15000" << endl; cout << "--prefix-sm-ready-timeout msec - Время ожидание я готовности SM к работе. По умолчанию 15000" << endl;
cout << "--prefix-filter-field name - Название фильтрующего поля при формировании списка датчиков посылаемых данным узлом" << endl; cout << "--prefix-filter-field name - Название фильтрующего поля при формировании списка датчиков посылаемых данным узлом" << endl;
cout << "--prefix-filter-value name - Значение фильтрующего поля при формировании списка датчиков посылаемых данным узлом" << endl; cout << "--prefix-filter-value name - Значение фильтрующего поля при формировании списка датчиков посылаемых данным узлом" << endl;
cout << endl;
cout << " Logs: " << endl;
cout << "--prefix-log-... - log control" << endl;
cout << " add-levels ..." << endl;
cout << " del-levels ..." << endl;
cout << " set-levels ..." << endl;
cout << " logfile filaname" << endl;
cout << " no-debug " << endl;
cout << " LogServer: " << endl;
cout << "--prefix-run-logserver - run logserver. Default: localhost:id" << endl;
cout << "--prefix-logserver-host ip - listen ip. Default: localhost" << endl;
cout << "--prefix-logserver-port num - listen port. Default: ID" << endl;
cout << LogServer::help_print("prefix-logserver") << endl;
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
std::shared_ptr<UNetExchange> UNetExchange::init_unetexchange( int argc, const char* const argv[], UniSetTypes::ObjectId icID, std::shared_ptr<UNetExchange> UNetExchange::init_unetexchange( int argc, const char* const argv[], UniSetTypes::ObjectId icID,
......
...@@ -14,6 +14,10 @@ ...@@ -14,6 +14,10 @@
#include "ThreadCreator.h" #include "ThreadCreator.h"
#include "UNetReceiver.h" #include "UNetReceiver.h"
#include "UNetSender.h" #include "UNetSender.h"
#include "LogServer.h"
#include "DebugStream.h"
#include "UNetLogSugar.h"
#include "LogAgregator.h"
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
/*! /*!
\page pageUNetExchangeUDP Сетевой обмен на основе UDP (UNetUDP) \page pageUNetExchangeUDP Сетевой обмен на основе UDP (UNetUDP)
...@@ -160,7 +164,7 @@ class UNetExchange: ...@@ -160,7 +164,7 @@ class UNetExchange:
std::shared_ptr<UNetReceiver> r1; /*!< приём по первому каналу */ std::shared_ptr<UNetReceiver> r1; /*!< приём по первому каналу */
std::shared_ptr<UNetReceiver> r2; /*!< приём по второму каналу */ std::shared_ptr<UNetReceiver> r2; /*!< приём по второму каналу */
void step( const std::shared_ptr<SMInterface> shm, const std::string& myname ); void step( const std::shared_ptr<SMInterface> shm, const std::string& myname, std::shared_ptr<DebugStream>& log );
inline void setRespondID( UniSetTypes::ObjectId id, bool invert = false ) inline void setRespondID( UniSetTypes::ObjectId id, bool invert = false )
{ {
...@@ -202,6 +206,12 @@ class UNetExchange: ...@@ -202,6 +206,12 @@ class UNetExchange:
bool no_sender; /*!< флаг отключения посылки сообщений (создания потока для посылки)*/ bool no_sender; /*!< флаг отключения посылки сообщений (создания потока для посылки)*/
std::shared_ptr<UNetSender> sender; std::shared_ptr<UNetSender> sender;
std::shared_ptr<UNetSender> sender2; std::shared_ptr<UNetSender> sender2;
std::shared_ptr<LogAgregator> loga;
std::shared_ptr<DebugStream> unetlog;
std::shared_ptr<LogServer> logserv;
std::string logserv_host = {""};
int logserv_port = {0};
}; };
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
#endif // UNetExchange_H_ #endif // UNetExchange_H_
......
#ifndef UNETLogSugar_H_
#define UNETLogSugar_H_
// "синтаксический сахар"..для логов
#ifndef unetinfo
#define unetinfo if( unetlog->debugging(Debug::INFO) ) unetlog->info()
#endif
#ifndef unetwarn
#define unetwarn if( unetlog->debugging(Debug::WARN) ) unetlog->warn()
#endif
#ifndef unetcrit
#define unetcrit if( unetlog->debugging(Debug::CRIT) ) unetlog->crit()
#endif
#ifndef unetlog1
#define unetlog1 if( unetlog->debugging(Debug::LEVEL1) ) unetlog->level1()
#endif
#ifndef unetlog2
#define unetlog2 if( unetlog->debugging(Debug::LEVEL2) ) unetlog->level2()
#endif
#ifndef unetlog3
#define unetlog3 if( unetlog->debugging(Debug::LEVEL3) ) unetlog->level3()
#endif
#ifndef unetlog4
#define unetlog4 if( unetlog->debugging(Debug::LEVEL4) ) unetlog->level4()
#endif
#ifndef unetlog5
#define unetlog5 if( unetlog->debugging(Debug::LEVEL5) ) unetlog->level5()
#endif
#ifndef unetlog6
#define unetlog6 if( unetlog->debugging(Debug::LEVEL6) ) unetlog->level6()
#endif
#ifndef unetlog7
#define unetlog7 if( unetlog->debugging(Debug::LEVEL7) ) unetlog->level7()
#endif
#ifndef unetlog8
#define unetlog8 if( unetlog->debugging(Debug::LEVEL8) ) unetlog->level8()
#endif
#ifndef unetlog9
#define unetlog9 if( unetlog->debugging(Debug::LEVEL9) ) unetlog->level9()
#endif
#ifndef unetlogany
#define unetlogany unetlog->any()
#endif
#endif // end of UNETLogSugar
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
#include "Exceptions.h" #include "Exceptions.h"
#include "Extensions.h" #include "Extensions.h"
#include "UNetReceiver.h" #include "UNetReceiver.h"
#include "UNetLogSugar.h"
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
using namespace std; using namespace std;
using namespace UniSetTypes; using namespace UniSetTypes;
...@@ -48,6 +49,9 @@ UNetReceiver::UNetReceiver( const std::string& s_host, const ost::tpport_t port, ...@@ -48,6 +49,9 @@ UNetReceiver::UNetReceiver( const std::string& s_host, const ost::tpport_t port,
myname = s.str(); myname = s.str();
} }
unetlog = make_shared<DebugStream>();
unetlog->setLogName(myname);
ost::Thread::setException(ost::Thread::throwException); ost::Thread::setException(ost::Thread::throwException);
try try
...@@ -62,14 +66,14 @@ UNetReceiver::UNetReceiver( const std::string& s_host, const ost::tpport_t port, ...@@ -62,14 +66,14 @@ UNetReceiver::UNetReceiver( const std::string& s_host, const ost::tpport_t port,
{ {
ostringstream s; ostringstream s;
s << myname << ": " << e.what(); s << myname << ": " << e.what();
dcrit << s.str() << std::endl; unetcrit << s.str() << std::endl;
throw SystemError(s.str()); throw SystemError(s.str());
} }
catch( ... ) catch( ... )
{ {
ostringstream s; ostringstream s;
s << myname << ": catch..."; s << myname << ": catch...";
dcrit << s.str() << std::endl; unetcrit << s.str() << std::endl;
throw SystemError(s.str()); throw SystemError(s.str());
} }
...@@ -166,7 +170,7 @@ void UNetReceiver::start() ...@@ -166,7 +170,7 @@ void UNetReceiver::start()
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
void UNetReceiver::update() void UNetReceiver::update()
{ {
dinfo << myname << "(update): start.." << endl; unetinfo << myname << "(update): start.." << endl;
while(activated) while(activated)
{ {
...@@ -176,11 +180,11 @@ void UNetReceiver::update() ...@@ -176,11 +180,11 @@ void UNetReceiver::update()
} }
catch( UniSetTypes::Exception& ex) catch( UniSetTypes::Exception& ex)
{ {
dcrit << myname << "(update): " << ex << std::endl; unetcrit << myname << "(update): " << ex << std::endl;
} }
catch(...) catch(...)
{ {
dcrit << myname << "(update): catch ..." << std::endl; unetcrit << myname << "(update): catch ..." << std::endl;
} }
if( sidRespond != DefaultObjectId ) if( sidRespond != DefaultObjectId )
...@@ -192,7 +196,7 @@ void UNetReceiver::update() ...@@ -192,7 +196,7 @@ void UNetReceiver::update()
} }
catch( const Exception& ex ) catch( const Exception& ex )
{ {
dcrit << myname << "(step): (respond) " << ex << std::endl; unetcrit << myname << "(step): (respond) " << ex << std::endl;
} }
} }
...@@ -204,7 +208,7 @@ void UNetReceiver::update() ...@@ -204,7 +208,7 @@ void UNetReceiver::update()
} }
catch( const Exception& ex ) catch( const Exception& ex )
{ {
dcrit << myname << "(step): (lostPackets) " << ex << std::endl; unetcrit << myname << "(step): (lostPackets) " << ex << std::endl;
} }
} }
...@@ -315,7 +319,7 @@ void UNetReceiver::real_update() ...@@ -315,7 +319,7 @@ void UNetReceiver::real_update()
if( ii.id != id ) if( ii.id != id )
{ {
dwarn << myname << "(update): reinit cache for sid=" << id << endl; unetwarn << myname << "(update): reinit cache for sid=" << id << endl;
ii.id = id; ii.id = id;
shm->initIterator(ii.ioit); shm->initIterator(ii.ioit);
} }
...@@ -332,11 +336,11 @@ void UNetReceiver::real_update() ...@@ -332,11 +336,11 @@ void UNetReceiver::real_update()
} }
catch( UniSetTypes::Exception& ex) catch( UniSetTypes::Exception& ex)
{ {
dcrit << myname << "(update): " << ex << std::endl; unetcrit << myname << "(update): " << ex << std::endl;
} }
catch(...) catch(...)
{ {
dcrit << myname << "(update): catch ..." << std::endl; unetcrit << myname << "(update): catch ..." << std::endl;
} }
} }
...@@ -350,7 +354,7 @@ void UNetReceiver::real_update() ...@@ -350,7 +354,7 @@ void UNetReceiver::real_update()
if( ii.id != d.id ) if( ii.id != d.id )
{ {
dwarn << myname << "(update): reinit cache for sid=" << d.id << endl; unetwarn << myname << "(update): reinit cache for sid=" << d.id << endl;
ii.id = d.id; ii.id = d.id;
shm->initIterator(ii.ioit); shm->initIterator(ii.ioit);
} }
...@@ -367,11 +371,11 @@ void UNetReceiver::real_update() ...@@ -367,11 +371,11 @@ void UNetReceiver::real_update()
} }
catch( UniSetTypes::Exception& ex) catch( UniSetTypes::Exception& ex)
{ {
dcrit << myname << "(update): " << ex << std::endl; unetcrit << myname << "(update): " << ex << std::endl;
} }
catch(...) catch(...)
{ {
dcrit << myname << "(update): catch ..." << std::endl; unetcrit << myname << "(update): catch ..." << std::endl;
} }
} }
} }
...@@ -385,7 +389,7 @@ void UNetReceiver::stop() ...@@ -385,7 +389,7 @@ void UNetReceiver::stop()
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
void UNetReceiver::receive() void UNetReceiver::receive()
{ {
dinfo << myname << ": ******************* receive start" << endl; unetinfo << myname << ": ******************* receive start" << endl;
{ {
uniset_rwmutex_wrlock l(tmMutex); uniset_rwmutex_wrlock l(tmMutex);
...@@ -406,17 +410,17 @@ void UNetReceiver::receive() ...@@ -406,17 +410,17 @@ void UNetReceiver::receive()
} }
catch( UniSetTypes::Exception& ex) catch( UniSetTypes::Exception& ex)
{ {
dwarn << myname << "(receive): " << ex << std::endl; unetwarn << myname << "(receive): " << ex << std::endl;
} }
catch( const std::exception& e ) catch( const std::exception& e )
{ {
dwarn << myname << "(receive): " << e.what() << std::endl; unetwarn << myname << "(receive): " << e.what() << std::endl;
} }
/* /*
catch(...) catch(...)
{ {
dwarn << myname << "(receive): catch ..." << std::endl; unetwarn << myname << "(receive): catch ..." << std::endl;
} }
*/ */
// делаем через промежуточную переменную // делаем через промежуточную переменную
...@@ -438,7 +442,7 @@ void UNetReceiver::receive() ...@@ -438,7 +442,7 @@ void UNetReceiver::receive()
msleep(recvpause); msleep(recvpause);
} }
dinfo << myname << ": ************* receive FINISH **********" << endl; unetinfo << myname << ": ************* receive FINISH **********" << endl;
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
bool UNetReceiver::recv() bool UNetReceiver::recv()
...@@ -452,7 +456,7 @@ bool UNetReceiver::recv() ...@@ -452,7 +456,7 @@ bool UNetReceiver::recv()
if( sz == 0 ) if( sz == 0 )
{ {
dcrit << myname << "(receive): FAILED RECEIVE DATA ret=" << ret << endl; unetcrit << myname << "(receive): FAILED RECEIVE DATA ret=" << ret << endl;
return false; return false;
} }
...@@ -473,7 +477,7 @@ bool UNetReceiver::recv() ...@@ -473,7 +477,7 @@ bool UNetReceiver::recv()
// Обычно "кольцевой". Т.е. если не успели обработать и "вынуть" из буфера информацию.. он будет переписан новыми данными // Обычно "кольцевой". Т.е. если не успели обработать и "вынуть" из буфера информацию.. он будет переписан новыми данными
if( waitClean ) if( waitClean )
{ {
dcrit << myname << "(receive): reset qtmp.." << endl; unetcrit << myname << "(receive): reset qtmp.." << endl;
while( !qtmp.empty() ) while( !qtmp.empty() )
qtmp.pop(); qtmp.pop();
...@@ -549,7 +553,7 @@ void UNetReceiver::initDCache( UniSetUDP::UDPMessage& pack, bool force ) ...@@ -549,7 +553,7 @@ void UNetReceiver::initDCache( UniSetUDP::UDPMessage& pack, bool force )
if( !force && pack.dcount == d_icache.size() ) if( !force && pack.dcount == d_icache.size() )
return; return;
dinfo << myname << ": init icache.." << endl; unetinfo << myname << ": init icache.." << endl;
d_cache_init_ok = true; d_cache_init_ok = true;
d_icache.resize(pack.dcount); d_icache.resize(pack.dcount);
...@@ -572,7 +576,7 @@ void UNetReceiver::initACache( UniSetUDP::UDPMessage& pack, bool force ) ...@@ -572,7 +576,7 @@ void UNetReceiver::initACache( UniSetUDP::UDPMessage& pack, bool force )
if( !force && pack.acount == a_icache.size() ) if( !force && pack.acount == a_icache.size() )
return; return;
dinfo << myname << ": init icache.." << endl; unetinfo << myname << ": init icache.." << endl;
a_cache_init_ok = true; a_cache_init_ok = true;
a_icache.resize(pack.acount); a_icache.resize(pack.acount);
......
...@@ -119,9 +119,12 @@ class UNetReceiver: ...@@ -119,9 +119,12 @@ class UNetReceiver:
typedef sigc::slot<void, const std::shared_ptr<UNetReceiver>&, Event> EventSlot; typedef sigc::slot<void, const std::shared_ptr<UNetReceiver>&, Event> EventSlot;
void connectEvent( EventSlot sl ); void connectEvent( EventSlot sl );
inline std::shared_ptr<DebugStream> getLog(){ return unetlog; }
protected: protected:
const std::shared_ptr<SMInterface> shm; const std::shared_ptr<SMInterface> shm;
std::shared_ptr<DebugStream> unetlog;
bool recv(); bool recv();
void step(); void step();
...@@ -143,7 +146,6 @@ class UNetReceiver: ...@@ -143,7 +146,6 @@ class UNetReceiver:
}; };
typedef std::priority_queue<UniSetUDP::UDPMessage, std::vector<UniSetUDP::UDPMessage>, PacketCompare> PacketQueue; typedef std::priority_queue<UniSetUDP::UDPMessage, std::vector<UniSetUDP::UDPMessage>, PacketCompare> PacketQueue;
private: private:
UNetReceiver(); UNetReceiver();
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
#include "Exceptions.h" #include "Exceptions.h"
#include "Extensions.h" #include "Extensions.h"
#include "UNetSender.h" #include "UNetSender.h"
#include "UNetLogSugar.h"
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
using namespace std; using namespace std;
using namespace UniSetTypes; using namespace UniSetTypes;
...@@ -28,13 +29,17 @@ UNetSender::UNetSender( const std::string& s_host, const ost::tpport_t port, con ...@@ -28,13 +29,17 @@ UNetSender::UNetSender( const std::string& s_host, const ost::tpport_t port, con
myname = s.str(); myname = s.str();
} }
unetlog = make_shared<DebugStream>();
unetlog->setLogName(myname);
// определяем фильтр // определяем фильтр
// s_field = conf->getArgParam("--udp-filter-field"); // s_field = conf->getArgParam("--udp-filter-field");
// s_fvalue = conf->getArgParam("--udp-filter-value"); // s_fvalue = conf->getArgParam("--udp-filter-value");
dinfo << myname << "(init): read filter-field='" << s_field unetinfo << myname << "(init): read filter-field='" << s_field
<< "' filter-value='" << s_fvalue << "'" << endl; << "' filter-value='" << s_fvalue << "'" << endl;
dinfo << "(UNetSender): UDP set to " << s_host << ":" << port << endl; unetinfo << "(UNetSender): UDP set to " << s_host << ":" << port << endl;
ost::Thread::setException(ost::Thread::throwException); ost::Thread::setException(ost::Thread::throwException);
...@@ -47,14 +52,14 @@ UNetSender::UNetSender( const std::string& s_host, const ost::tpport_t port, con ...@@ -47,14 +52,14 @@ UNetSender::UNetSender( const std::string& s_host, const ost::tpport_t port, con
{ {
ostringstream s; ostringstream s;
s << myname << ": " << e.what(); s << myname << ": " << e.what();
dcrit << s.str() << std::endl; unetcrit << s.str() << std::endl;
throw SystemError(s.str()); throw SystemError(s.str());
} }
catch( ... ) catch( ... )
{ {
ostringstream s; ostringstream s;
s << myname << ": catch..."; s << myname << ": catch...";
dcrit << s.str() << std::endl; unetcrit << s.str() << std::endl;
throw SystemError(s.str()); throw SystemError(s.str());
} }
...@@ -65,7 +70,7 @@ UNetSender::UNetSender( const std::string& s_host, const ost::tpport_t port, con ...@@ -65,7 +70,7 @@ UNetSender::UNetSender( const std::string& s_host, const ost::tpport_t port, con
{ {
readConfiguration(); readConfiguration();
dlist.resize(maxItem); dlist.resize(maxItem);
dinfo << myname << "(init): dlist size = " << dlist.size() << endl; unetinfo << myname << "(init): dlist size = " << dlist.size() << endl;
} }
else else
{ {
...@@ -75,10 +80,10 @@ UNetSender::UNetSender( const std::string& s_host, const ost::tpport_t port, con ...@@ -75,10 +80,10 @@ UNetSender::UNetSender( const std::string& s_host, const ost::tpport_t port, con
ic->addReadItem( sigc::mem_fun(this, &UNetSender::readItem) ); ic->addReadItem( sigc::mem_fun(this, &UNetSender::readItem) );
else else
{ {
dwarn << myname << "(init): Failed to convert the pointer 'IONotifyController' -> 'SharedMemory'" << endl; unetwarn << myname << "(init): Failed to convert the pointer 'IONotifyController' -> 'SharedMemory'" << endl;
readConfiguration(); readConfiguration();
dlist.resize(maxItem); dlist.resize(maxItem);
dinfo << myname << "(init): dlist size = " << dlist.size() << endl; unetinfo << myname << "(init): dlist size = " << dlist.size() << endl;
} }
} }
...@@ -141,7 +146,7 @@ void UNetSender::updateItem( DMap::iterator& it, long value ) ...@@ -141,7 +146,7 @@ void UNetSender::updateItem( DMap::iterator& it, long value )
void UNetSender::send() void UNetSender::send()
{ {
dlist.resize(maxItem); dlist.resize(maxItem);
dinfo << myname << "(send): dlist size = " << dlist.size() << endl; unetinfo << myname << "(send): dlist size = " << dlist.size() << endl;
/* /*
ost::IPV4Broadcast h = s_host.c_str(); ost::IPV4Broadcast h = s_host.c_str();
...@@ -153,7 +158,7 @@ void UNetSender::send() ...@@ -153,7 +158,7 @@ void UNetSender::send()
{ {
ostringstream s; ostringstream s;
s << e.getString() << ": " << e.getSystemErrorString(); s << e.getString() << ": " << e.getSystemErrorString();
dcrit << myname << "(poll): " << s.str() << endl; unetcrit << myname << "(poll): " << s.str() << endl;
throw SystemError(s.str()); throw SystemError(s.str());
} }
*/ */
...@@ -168,25 +173,25 @@ void UNetSender::send() ...@@ -168,25 +173,25 @@ void UNetSender::send()
} }
catch( ost::SockException& e ) catch( ost::SockException& e )
{ {
dwarn << myname << "(send): " << e.getString() << endl; unetwarn << myname << "(send): " << e.getString() << endl;
} }
catch( UniSetTypes::Exception& ex) catch( UniSetTypes::Exception& ex)
{ {
dwarn << myname << "(send): " << ex << std::endl; unetwarn << myname << "(send): " << ex << std::endl;
} }
catch( const std::exception& e ) catch( const std::exception& e )
{ {
dwarn << myname << "(send): " << e.what() << std::endl; unetwarn << myname << "(send): " << e.what() << std::endl;
} }
catch(...) catch(...)
{ {
dwarn << myname << "(send): catch ..." << std::endl; unetwarn << myname << "(send): catch ..." << std::endl;
} }
msleep(sendpause); msleep(sendpause);
} }
dinfo << "************* execute FINISH **********" << endl; unetinfo << "************* execute FINISH **********" << endl;
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// #define UNETUDP_DISABLE_OPTIMIZATION_N1 // #define UNETUDP_DISABLE_OPTIMIZATION_N1
...@@ -217,7 +222,7 @@ void UNetSender::real_send() ...@@ -217,7 +222,7 @@ void UNetSender::real_send()
size_t ret = udp->send( (char*)s_msg.data, s_msg.len ); size_t ret = udp->send( (char*)s_msg.data, s_msg.len );
if( ret < s_msg.len ) if( ret < s_msg.len )
dcrit << myname << "(real_send): FAILED ret=" << ret << " < sizeof=" << s_msg.len << endl; unetcrit << myname << "(real_send): FAILED ret=" << ret << " < sizeof=" << s_msg.len << endl;
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
void UNetSender::stop() void UNetSender::stop()
...@@ -289,7 +294,7 @@ bool UNetSender::initItem( UniXML::iterator& it ) ...@@ -289,7 +294,7 @@ bool UNetSender::initItem( UniXML::iterator& it )
if( sid == DefaultObjectId ) if( sid == DefaultObjectId )
{ {
dcrit << myname << "(readItem): ID not found for " unetcrit << myname << "(readItem): ID not found for "
<< sname << endl; << sname << endl;
return false; return false;
} }
...@@ -299,7 +304,7 @@ bool UNetSender::initItem( UniXML::iterator& it ) ...@@ -299,7 +304,7 @@ bool UNetSender::initItem( UniXML::iterator& it )
if( p.iotype == UniversalIO::UnknownIOType ) if( p.iotype == UniversalIO::UnknownIOType )
{ {
dcrit << myname << "(readItem): Unknown iotype for sid=" << sid << endl; unetcrit << myname << "(readItem): Unknown iotype for sid=" << sid << endl;
return false; return false;
} }
...@@ -311,7 +316,7 @@ bool UNetSender::initItem( UniXML::iterator& it ) ...@@ -311,7 +316,7 @@ bool UNetSender::initItem( UniXML::iterator& it )
if ( p.pack_ind >= UniSetUDP::MaxDCount ) if ( p.pack_ind >= UniSetUDP::MaxDCount )
{ {
dcrit << myname unetcrit << myname
<< "(readItem): OVERFLOW! MAX UDP DIGITAL DATA LIMIT! max=" << "(readItem): OVERFLOW! MAX UDP DIGITAL DATA LIMIT! max="
<< UniSetUDP::MaxDCount << endl; << UniSetUDP::MaxDCount << endl;
...@@ -325,7 +330,7 @@ bool UNetSender::initItem( UniXML::iterator& it ) ...@@ -325,7 +330,7 @@ bool UNetSender::initItem( UniXML::iterator& it )
if ( p.pack_ind >= UniSetUDP::MaxACount ) if ( p.pack_ind >= UniSetUDP::MaxACount )
{ {
dcrit << myname unetcrit << myname
<< "(readItem): OVERFLOW! MAX UDP ANALOG DATA LIMIT! max=" << "(readItem): OVERFLOW! MAX UDP ANALOG DATA LIMIT! max="
<< UniSetUDP::MaxACount << endl; << UniSetUDP::MaxACount << endl;
raise(SIGTERM); raise(SIGTERM);
...@@ -339,7 +344,7 @@ bool UNetSender::initItem( UniXML::iterator& it ) ...@@ -339,7 +344,7 @@ bool UNetSender::initItem( UniXML::iterator& it )
dlist[maxItem] = p; dlist[maxItem] = p;
maxItem++; maxItem++;
dinfo << myname << "(initItem): add " << p << endl; unetinfo << myname << "(initItem): add " << p << endl;
return true; return true;
} }
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "SharedMemory.h" #include "SharedMemory.h"
#include "ThreadCreator.h" #include "ThreadCreator.h"
#include "UDPPacket.h" #include "UDPPacket.h"
#include "DebugStream.h"
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
/* /*
* ОПТИМИЗАЦИЯ N1: Для оптимизации обработки посылаемых пакетов (на стороне UNetReceiver) следана следующая логика: * ОПТИМИЗАЦИЯ N1: Для оптимизации обработки посылаемых пакетов (на стороне UNetReceiver) следана следующая логика:
...@@ -69,12 +70,15 @@ class UNetSender ...@@ -69,12 +70,15 @@ class UNetSender
/*! инициализация итераторов */ /*! инициализация итераторов */
void initIterators(); void initIterators();
inline std::shared_ptr<DebugStream> getLog(){ return unetlog; }
protected: protected:
std::string s_field; std::string s_field;
std::string s_fvalue; std::string s_fvalue;
const std::shared_ptr<SMInterface> shm; const std::shared_ptr<SMInterface> shm;
std::shared_ptr<DebugStream> unetlog;
bool initItem( UniXML::iterator& it ); bool initItem( UniXML::iterator& it );
bool readItem( const std::shared_ptr<UniXML>& xml, UniXML::iterator& it, xmlNode* sec ); bool readItem( const std::shared_ptr<UniXML>& xml, UniXML::iterator& it, xmlNode* sec );
......
...@@ -17,7 +17,6 @@ int main( int argc, const char** argv ) ...@@ -17,7 +17,6 @@ int main( int argc, const char** argv )
{ {
cout << "--smemory-id objectName - SharedMemory objectID. Default: read from <SharedMemory>" << endl; cout << "--smemory-id objectName - SharedMemory objectID. Default: read from <SharedMemory>" << endl;
cout << "--confile filename - configuration file. Default: configure.xml" << endl; cout << "--confile filename - configuration file. Default: configure.xml" << endl;
cout << "--unet-logfile filename - logfilename. Default: udpexchange.log" << endl;
cout << endl; cout << endl;
UNetExchange::help_print(argc, argv); UNetExchange::help_print(argc, argv);
return 0; return 0;
...@@ -25,18 +24,6 @@ int main( int argc, const char** argv ) ...@@ -25,18 +24,6 @@ int main( int argc, const char** argv )
auto conf = uniset_init(argc, argv); auto conf = uniset_init(argc, argv);
string logfilename(conf->getArgParam("--unet-logfile"));
if( logfilename.empty() )
logfilename = "udpexchange.log";
std::ostringstream logname;
string dir(conf->getLogDir());
logname << dir << logfilename;
ulog()->logFile( logname.str() );
UniSetExtensions::dlog()->logFile( logname.str() );
ObjectId shmID = DefaultObjectId; ObjectId shmID = DefaultObjectId;
string sID = conf->getArgParam("--smemory-id"); string sID = conf->getArgParam("--smemory-id");
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <memory> #include <memory>
#include <cc++/socket.h> #include <cc++/socket.h>
#include "Mutex.h" #include "Mutex.h"
#include "UniXML.h"
#include "DebugStream.h" #include "DebugStream.h"
#include "ThreadCreator.h" #include "ThreadCreator.h"
class LogSession; class LogSession;
...@@ -86,6 +87,10 @@ class LogServer ...@@ -86,6 +87,10 @@ class LogServer
return (thr && thr->isRunning()); return (thr && thr->isRunning());
} }
void init( const std::string& prefix, xmlNode* cnode=0 );
static std::string help_print( const std::string& prefix );
protected: protected:
LogServer(); LogServer();
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "Exceptions.h" #include "Exceptions.h"
#include "LogSession.h" #include "LogSession.h"
#include "LogAgregator.h" #include "LogAgregator.h"
#include "Configuration.h"
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
using namespace std; using namespace std;
using namespace UniSetTypes; using namespace UniSetTypes;
...@@ -199,3 +200,28 @@ void LogServer::sessionFinished( std::shared_ptr<LogSession> s ) ...@@ -199,3 +200,28 @@ void LogServer::sessionFinished( std::shared_ptr<LogSession> s )
} }
} }
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
void LogServer::init( const std::string& prefix, xmlNode* cnode )
{
auto conf = uniset_conf();
// можем на cnode==0 не проверять, т.е. UniXML::iterator корректно отрабатывает эту ситуацию
UniXML::iterator it(cnode);
timeout_t sessTimeout = conf->getArgPInt("--" + prefix + "-session-timeout", it.getProp("sessTimeout"), 3600000);
timeout_t cmdTimeout = conf->getArgPInt("--" + prefix + "-cmd-timeout", it.getProp("cmdTimeout"), 2000);
timeout_t outTimeout = conf->getArgPInt("--" + prefix + "-out-timeout", it.getProp("outTimeout"), 2000);
setSessionTimeout(sessTimeout);
setCmdTimeout(cmdTimeout);
setOutTimeout(outTimeout);
}
// -----------------------------------------------------------------------------
std::string LogServer::help_print( const std::string& prefix )
{
ostringstream h;
h << "--" << prefix << "-session-timeout msec - Timeout for session. Default: 10 min." << endl;
h << "--" << prefix << "-cmd-timeout msec - Timeout for wait command. Default: 2000 msec." << endl;
h << "--" << prefix << "-out-timeout msec - Timeout for send to client. Default: 2000 msec." << endl;
return std::move( h.str() );
}
// -----------------------------------------------------------------------------
...@@ -835,7 +835,7 @@ namespace UniSetTypes ...@@ -835,7 +835,7 @@ namespace UniSetTypes
if( dnode == NULL ) if( dnode == NULL )
deb->any() << "(Configuration)(initLogStream): WARNING! Not found conf. section for log '" << _debname << "'" << endl; deb->any() << "(Configuration)(initLogStream): WARNING! Not found conf. section for log '" << _debname << "'" << endl;
else else if( deb->getLogName().empty() )
{ {
if( !getProp(dnode, "name").empty() ) if( !getProp(dnode, "name").empty() )
{ {
...@@ -855,6 +855,8 @@ namespace UniSetTypes ...@@ -855,6 +855,8 @@ namespace UniSetTypes
} }
} }
string debug_file("");
// смотрим настройки файла // смотрим настройки файла
if( dnode ) if( dnode )
{ {
...@@ -865,10 +867,7 @@ namespace UniSetTypes ...@@ -865,10 +867,7 @@ namespace UniSetTypes
else else
deb->addLevel(Debug::NONE); deb->addLevel(Debug::NONE);
string debug_file(getProp(dnode, "file")); debug_file = getProp(dnode, "file");
if( !debug_file.empty() )
deb->logFile(debug_file);
} }
// теперь смотрим командную строку // теперь смотрим командную строку
...@@ -881,7 +880,7 @@ namespace UniSetTypes ...@@ -881,7 +880,7 @@ namespace UniSetTypes
{ {
if( logfile == _argv[i] ) // "--debug-logfile" if( logfile == _argv[i] ) // "--debug-logfile"
{ {
deb->logFile(_argv[i + 1]); debug_file = string(_argv[i + 1]);
} }
else if( add_level == _argv[i] ) // "--debug-add-levels" else if( add_level == _argv[i] ) // "--debug-add-levels"
{ {
...@@ -893,6 +892,9 @@ namespace UniSetTypes ...@@ -893,6 +892,9 @@ namespace UniSetTypes
} }
} }
if( !debug_file.empty() )
deb->logFile(debug_file);
return dnode; return dnode;
} }
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
......
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