Commit ea2e7544 authored by Pavel Vainerman's avatar Pavel Vainerman

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

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