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)
......
......@@ -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);
......
......@@ -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