Commit 6e06e4a5 authored by Pavel Vainerman's avatar Pavel Vainerman

(LogServer): добавил команду вывода списка подключённых (контролируемых) логов,

edit todo, make style
parent 1f3682ef
...@@ -45,7 +45,6 @@ Version 2.0 ...@@ -45,7 +45,6 @@ Version 2.0
uniset-codegen: добавить ключ --gen-sensor-name для генерирования name_Item.. (чтобы можно было в логах использовать текстовые названия) uniset-codegen: добавить ключ --gen-sensor-name для генерирования name_Item.. (чтобы можно было в логах использовать текстовые названия)
- перевести PassiveTimer на использование crono:: (c++11) - перевести PassiveTimer на использование crono:: (c++11)
- LogServer: добавил команду -l для вывода списка "доступных"(управляемых) логов
SQL: SQL:
==== ====
......
...@@ -21,6 +21,7 @@ static struct option longopts[] = ...@@ -21,6 +21,7 @@ static struct option longopts[] =
{ "set", required_argument, 0, 's' }, { "set", required_argument, 0, 's' },
{ "off", required_argument, 0, 'o' }, { "off", required_argument, 0, 'o' },
{ "on", required_argument, 0, 'n' }, { "on", required_argument, 0, 'n' },
{ "list", no_argument, 0, 'm' },
{ "rotate", required_argument, 0, 'r' }, { "rotate", required_argument, 0, 'r' },
{ "logname", required_argument, 0, 'l' }, { "logname", required_argument, 0, 'l' },
{ "command-only", no_argument, 0, 'b' }, { "command-only", no_argument, 0, 'b' },
...@@ -49,10 +50,13 @@ static void print_help() ...@@ -49,10 +50,13 @@ static void print_help()
printf("--off, -o - Off the write log file (if enabled).\n"); printf("--off, -o - Off the write log file (if enabled).\n");
printf("--on, -n - On the write log file (if before disabled).\n"); printf("--on, -n - On the write log file (if before disabled).\n");
printf("--rotate, -r - rotate log file.\n"); printf("--rotate, -r - rotate log file.\n");
printf("--list, -m - List of managed logs.\n");
} }
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
int main( int argc, char** argv ) int main( int argc, char** argv )
{ {
std::ios::sync_with_stdio(false);
int optindex = 0; int optindex = 0;
int opt = 0; int opt = 0;
int verb = 0; int verb = 0;
...@@ -69,7 +73,7 @@ int main( int argc, char** argv ) ...@@ -69,7 +73,7 @@ int main( int argc, char** argv )
try try
{ {
while( (opt = getopt_long(argc, argv, "hva:p:i:d:s:l:onrbx:w:", longopts, &optindex)) != -1 ) while( (opt = getopt_long(argc, argv, "hvma:p:i:d:s:l:onrbx:w:", longopts, &optindex)) != -1 )
{ {
switch (opt) switch (opt)
{ {
...@@ -98,6 +102,10 @@ int main( int argc, char** argv ) ...@@ -98,6 +102,10 @@ int main( int argc, char** argv )
} }
break; break;
case 'm':
cmd = LogServerTypes::cmdList;
break;
case 'o': case 'o':
cmd = LogServerTypes::cmdOffLogFile; cmd = LogServerTypes::cmdOffLogFile;
break; break;
......
...@@ -34,6 +34,8 @@ static void print_help() ...@@ -34,6 +34,8 @@ static void print_help()
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
int main( int argc, char** argv ) int main( int argc, char** argv )
{ {
std::ios::sync_with_stdio(false);
int optindex = 0; int optindex = 0;
int opt = 0; int opt = 0;
int verb = 0; int verb = 0;
......
...@@ -13,7 +13,7 @@ using namespace UniSetExtensions; ...@@ -13,7 +13,7 @@ using namespace UniSetExtensions;
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
RRDServer::RRDServer( UniSetTypes::ObjectId objId, xmlNode* cnode, UniSetTypes::ObjectId shmId, const std::shared_ptr<SharedMemory> ic, RRDServer::RRDServer( UniSetTypes::ObjectId objId, xmlNode* cnode, UniSetTypes::ObjectId shmId, const std::shared_ptr<SharedMemory> ic,
const string& prefix ): const string& prefix ):
UObject_SK(objId, cnode, string(prefix+"-")), UObject_SK(objId, cnode, string(prefix + "-")),
prefix(prefix) prefix(prefix)
{ {
auto conf = uniset_conf(); auto conf = uniset_conf();
......
...@@ -541,10 +541,10 @@ bool UNetReceiver::recv() ...@@ -541,10 +541,10 @@ bool UNetReceiver::recv()
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
void UNetReceiver::initIterators() void UNetReceiver::initIterators()
{ {
for( auto&& it : d_icache ) for( auto && it : d_icache )
shm->initIterator(it.ioit); shm->initIterator(it.ioit);
for( auto&& it : a_icache ) for( auto && it : a_icache )
shm->initIterator(it.ioit); shm->initIterator(it.ioit);
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
......
...@@ -357,13 +357,13 @@ std::ostream& operator<<( std::ostream& os, UNetSender::UItem& p ) ...@@ -357,13 +357,13 @@ std::ostream& operator<<( std::ostream& os, UNetSender::UItem& p )
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
void UNetSender::initIterators() void UNetSender::initIterators()
{ {
for( auto&& it: dlist ) for( auto && it : dlist )
shm->initIterator(it.ioit); shm->initIterator(it.ioit);
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
void UNetSender::askSensors( UniversalIO::UIOCommand cmd ) void UNetSender::askSensors( UniversalIO::UIOCommand cmd )
{ {
for( auto&& it: dlist ) for( auto && it : dlist )
shm->askSensor(it.id, cmd); shm->askSensor(it.id, cmd);
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
...@@ -28,7 +28,7 @@ class UObject_SK: ...@@ -28,7 +28,7 @@ class UObject_SK:
public LT_Object public LT_Object
{ {
public: public:
UObject_SK( UniSetTypes::ObjectId id, xmlNode* node=UniSetTypes::uniset_conf()->getNode("UObject"), const std::string& argprefix="" ); UObject_SK( UniSetTypes::ObjectId id, xmlNode* node = UniSetTypes::uniset_conf()->getNode("UObject"), const std::string& argprefix = "" );
UObject_SK(); UObject_SK();
virtual ~UObject_SK(); virtual ~UObject_SK();
...@@ -44,45 +44,45 @@ class UObject_SK: ...@@ -44,45 +44,45 @@ class UObject_SK:
void init_dlog( std::shared_ptr<DebugStream> d ); void init_dlog( std::shared_ptr<DebugStream> d );
// "синтаксический сахар"..для логов // "синтаксический сахар"..для логов
#ifndef myinfo #ifndef myinfo
#define myinfo if( mylog->debugging(Debug::INFO) ) mylog->info() #define myinfo if( mylog->debugging(Debug::INFO) ) mylog->info()
#endif #endif
#ifndef mywarn #ifndef mywarn
#define mywarn if( mylog->debugging(Debug::WARN) ) mylog->warn() #define mywarn if( mylog->debugging(Debug::WARN) ) mylog->warn()
#endif #endif
#ifndef mycrit #ifndef mycrit
#define mycrit if( mylog->debugging(Debug::CRIT) ) mylog->crit() #define mycrit if( mylog->debugging(Debug::CRIT) ) mylog->crit()
#endif #endif
#ifndef mylog1 #ifndef mylog1
#define mylog1 if( mylog->debugging(Debug::LEVEL1) ) mylog->level1() #define mylog1 if( mylog->debugging(Debug::LEVEL1) ) mylog->level1()
#endif #endif
#ifndef mylog2 #ifndef mylog2
#define mylog2 if( mylog->debugging(Debug::LEVEL2) ) mylog->level2() #define mylog2 if( mylog->debugging(Debug::LEVEL2) ) mylog->level2()
#endif #endif
#ifndef mylog3 #ifndef mylog3
#define mylog3 if( mylog->debugging(Debug::LEVEL3) ) mylog->level3() #define mylog3 if( mylog->debugging(Debug::LEVEL3) ) mylog->level3()
#endif #endif
#ifndef mylog4 #ifndef mylog4
#define mylog4 if( mylog->debugging(Debug::LEVEL4) ) mylog->level4() #define mylog4 if( mylog->debugging(Debug::LEVEL4) ) mylog->level4()
#endif #endif
#ifndef mylog5 #ifndef mylog5
#define mylog5 if( mylog->debugging(Debug::LEVEL5) ) mylog->level5() #define mylog5 if( mylog->debugging(Debug::LEVEL5) ) mylog->level5()
#endif #endif
#ifndef mylog6 #ifndef mylog6
#define mylog6 if( mylog->debugging(Debug::LEVEL6) ) mylog->level6() #define mylog6 if( mylog->debugging(Debug::LEVEL6) ) mylog->level6()
#endif #endif
#ifndef mylog7 #ifndef mylog7
#define mylog7 if( mylog->debugging(Debug::LEVEL7) ) mylog->level7() #define mylog7 if( mylog->debugging(Debug::LEVEL7) ) mylog->level7()
#endif #endif
#ifndef mylog8 #ifndef mylog8
#define mylog8 if( mylog->debugging(Debug::LEVEL8) ) mylog->level8() #define mylog8 if( mylog->debugging(Debug::LEVEL8) ) mylog->level8()
#endif #endif
#ifndef mylog9 #ifndef mylog9
#define mylog9 if( mylog->debugging(Debug::LEVEL9) ) mylog->level9() #define mylog9 if( mylog->debugging(Debug::LEVEL9) ) mylog->level9()
#endif #endif
#ifndef mylogany #ifndef mylogany
#define mylogany mylog->any() #define mylogany mylog->any()
#endif #endif
// Вспомогательные функции для удобства логирования // Вспомогательные функции для удобства логирования
// ------------------------------------------------------------ // ------------------------------------------------------------
...@@ -99,13 +99,13 @@ class UObject_SK: ...@@ -99,13 +99,13 @@ class UObject_SK:
\param id - идентификатор датчика \param id - идентификатор датчика
\param showLinkName - TRUE - выводить SensorName, FALSE - не выводить \param showLinkName - TRUE - выводить SensorName, FALSE - не выводить
*/ */
std::string str( UniSetTypes::ObjectId id, bool showLinkName=true ); std::string str( UniSetTypes::ObjectId id, bool showLinkName = true );
/*!< Вывод значения входа/выхода в формате: in_xxx(SensorName)=val /*!< Вывод значения входа/выхода в формате: in_xxx(SensorName)=val
\param id - идентификатор датчика \param id - идентификатор датчика
\param showLinkName - TRUE - выводить SensorName, FALSE - не выводить \param showLinkName - TRUE - выводить SensorName, FALSE - не выводить
*/ */
std::string strval( UniSetTypes::ObjectId id, bool showLinkName=true ); std::string strval( UniSetTypes::ObjectId id, bool showLinkName = true );
// ------------------------------------------------------------ // ------------------------------------------------------------
...@@ -133,10 +133,10 @@ class UObject_SK: ...@@ -133,10 +133,10 @@ class UObject_SK:
virtual void callback() override; virtual void callback() override;
virtual void processingMessage( UniSetTypes::VoidMessage* msg ) override; virtual void processingMessage( UniSetTypes::VoidMessage* msg ) override;
virtual void sysCommand( const UniSetTypes::SystemMessage* sm ){}; virtual void sysCommand( const UniSetTypes::SystemMessage* sm ) {};
virtual void askSensors( UniversalIO::UIOCommand cmd ){} virtual void askSensors( UniversalIO::UIOCommand cmd ) {}
virtual void sensorInfo( const UniSetTypes::SensorMessage* sm ) override{} virtual void sensorInfo( const UniSetTypes::SensorMessage* sm ) override {}
virtual void timerInfo( const UniSetTypes::TimerMessage* tm ) override{} virtual void timerInfo( const UniSetTypes::TimerMessage* tm ) override {}
virtual void sigterm( int signo ) override; virtual void sigterm( int signo ) override;
virtual bool activateObject() override; virtual bool activateObject() override;
virtual void testMode( bool state ); virtual void testMode( bool state );
...@@ -156,7 +156,7 @@ class UObject_SK: ...@@ -156,7 +156,7 @@ class UObject_SK:
int resetMsgTime; int resetMsgTime;
// Выполнение очередного шага программы // Выполнение очередного шага программы
virtual void step(){} virtual void step() {}
int sleep_msec; /*!< пауза между итерациями */ int sleep_msec; /*!< пауза между итерациями */
bool active; bool active;
...@@ -171,9 +171,15 @@ class UObject_SK: ...@@ -171,9 +171,15 @@ class UObject_SK:
xmlNode* confnode; xmlNode* confnode;
/*! получить числовое свойство из конф. файла по привязанной confnode */ /*! получить числовое свойство из конф. файла по привязанной confnode */
int getIntProp(const std::string& name) { return UniSetTypes::uniset_conf()->getIntProp(confnode, name); } int getIntProp(const std::string& name)
{
return UniSetTypes::uniset_conf()->getIntProp(confnode, name);
}
/*! получить текстовое свойство из конф. файла по привязанной confnode */ /*! получить текстовое свойство из конф. файла по привязанной confnode */
inline const std::string getProp(const std::string& name) { return UniSetTypes::uniset_conf()->getProp(confnode, name); } inline const std::string getProp(const std::string& name)
{
return UniSetTypes::uniset_conf()->getProp(confnode, name);
}
int smReadyTimeout; /*!< время ожидания готовности SM */ int smReadyTimeout; /*!< время ожидания готовности SM */
std::atomic_bool activated; std::atomic_bool activated;
......
...@@ -31,26 +31,26 @@ using namespace UniSetTypes; ...@@ -31,26 +31,26 @@ using namespace UniSetTypes;
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
UObject_SK::UObject_SK(): UObject_SK::UObject_SK():
// Инициализация идентификаторов (имена берутся из конф. файла) // Инициализация идентификаторов (имена берутся из конф. файла)
// Используемые идентификаторы сообщений (имена берутся из конф. файла) // Используемые идентификаторы сообщений (имена берутся из конф. файла)
// variables // variables
active(false), active(false),
idHeartBeat(DefaultObjectId), idHeartBeat(DefaultObjectId),
maxHeartBeat(10), maxHeartBeat(10),
confnode(0), confnode(0),
smReadyTimeout(0), smReadyTimeout(0),
activated(false), activated(false),
askPause(2000), askPause(2000),
forceOut(false), forceOut(false),
end_private(false) end_private(false)
{ {
ucrit << "UObject: init failed!!!!!!!!!!!!!!!" << endl; ucrit << "UObject: init failed!!!!!!!!!!!!!!!" << endl;
throw Exception( string(myname+": init failed!!!") ); throw Exception( string(myname + ": init failed!!!") );
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// ( val, confval, default val ) // ( val, confval, default val )
...@@ -58,6 +58,7 @@ static const std::string init3_str( const std::string& s1, const std::string& s2 ...@@ -58,6 +58,7 @@ static const std::string init3_str( const std::string& s1, const std::string& s2
{ {
if( !s1.empty() ) if( !s1.empty() )
return s1; return s1;
if( !s2.empty() ) if( !s2.empty() )
return s2; return s2;
...@@ -65,34 +66,34 @@ static const std::string init3_str( const std::string& s1, const std::string& s2 ...@@ -65,34 +66,34 @@ static const std::string init3_str( const std::string& s1, const std::string& s2
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
UObject_SK::UObject_SK( ObjectId id, xmlNode* cnode, const std::string& _argprefix ): UObject_SK::UObject_SK( ObjectId id, xmlNode* cnode, const std::string& _argprefix ):
UniSetObject(id), UniSetObject(id),
argprefix( (_argprefix.empty() ? myname+"-" : _argprefix) ), argprefix( (_argprefix.empty() ? myname + "-" : _argprefix) ),
// Инициализация идентификаторов (имена берутся из конф. файла) // Инициализация идентификаторов (имена берутся из конф. файла)
// Используемые идентификаторы сообщений (имена берутся из конф. файла) // Используемые идентификаторы сообщений (имена берутся из конф. файла)
// variables // variables
sleep_msec(150), sleep_msec(150),
active(true), active(true),
idHeartBeat(DefaultObjectId), idHeartBeat(DefaultObjectId),
maxHeartBeat(10), maxHeartBeat(10),
confnode(cnode), confnode(cnode),
smReadyTimeout(0), smReadyTimeout(0),
activated(false), activated(false),
askPause(uniset_conf()->getPIntProp(cnode,"askPause",2000)), askPause(uniset_conf()->getPIntProp(cnode, "askPause", 2000)),
forceOut(false), forceOut(false),
end_private(false) end_private(false)
{ {
auto conf = uniset_conf(); auto conf = uniset_conf();
if( UniSetTypes::findArgParam("--print-id-list",uniset_conf()->getArgc(),uniset_conf()->getArgv()) != -1 ) if( UniSetTypes::findArgParam("--print-id-list", uniset_conf()->getArgc(), uniset_conf()->getArgv()) != -1 )
{ {
// abort(); // abort();
} }
...@@ -108,7 +109,7 @@ end_private(false) ...@@ -108,7 +109,7 @@ end_private(false)
{ {
ostringstream s; ostringstream s;
s << argprefix << "log"; s << argprefix << "log";
conf->initLogStream(mylog,s.str()); conf->initLogStream(mylog, s.str());
} }
loga = make_shared<LogAgregator>(); loga = make_shared<LogAgregator>();
...@@ -129,12 +130,14 @@ end_private(false) ...@@ -129,12 +130,14 @@ end_private(false)
logserv_port = conf->getArgPInt("--" + argprefix + "-logserver-port", it.getProp("logserverPort"), getId()); logserv_port = conf->getArgPInt("--" + argprefix + "-logserver-port", it.getProp("logserverPort"), getId());
} }
forceOut = conf->getArgPInt("--" + argprefix + "force-out",it.getProp("forceOut"),false); forceOut = conf->getArgPInt("--" + argprefix + "force-out", it.getProp("forceOut"), false);
string heart = conf->getArgParam("--" + argprefix + "heartbeat-id", it.getProp("heartbeat_id"));
string heart = conf->getArgParam("--" + argprefix + "heartbeat-id",it.getProp("heartbeat_id"));
if( !heart.empty() ) if( !heart.empty() )
{ {
idHeartBeat = conf->getSensorID(heart); idHeartBeat = conf->getSensorID(heart);
if( idHeartBeat == DefaultObjectId ) if( idHeartBeat == DefaultObjectId )
{ {
ostringstream err; ostringstream err;
...@@ -142,34 +145,37 @@ end_private(false) ...@@ -142,34 +145,37 @@ end_private(false)
throw SystemError(err.str()); throw SystemError(err.str());
} }
int heartbeatTime = conf->getArgPInt("--" + argprefix + "heartbeat-time",it.getProp("heartbeatTime"),conf->getHeartBeatTime()); int heartbeatTime = conf->getArgPInt("--" + argprefix + "heartbeat-time", it.getProp("heartbeatTime"), conf->getHeartBeatTime());
if( heartbeatTime>0 )
if( heartbeatTime > 0 )
ptHeartBeat.setTiming(heartbeatTime); ptHeartBeat.setTiming(heartbeatTime);
else else
ptHeartBeat.setTiming(UniSetTimer::WaitUpTime); ptHeartBeat.setTiming(UniSetTimer::WaitUpTime);
maxHeartBeat = conf->getArgPInt("--" + argprefix + "heartbeat-max",it.getProp("heartbeat_max"), 10); maxHeartBeat = conf->getArgPInt("--" + argprefix + "heartbeat-max", it.getProp("heartbeat_max"), 10);
} }
// Инициализация значений // Инициализация значений
sleep_msec = conf->getArgPInt("--" + argprefix + "sleep-msec","150", 150); sleep_msec = conf->getArgPInt("--" + argprefix + "sleep-msec", "150", 150);
string s_resetTime(""); string s_resetTime("");
if( s_resetTime.empty() ) if( s_resetTime.empty() )
s_resetTime = "500"; s_resetTime = "500";
resetMsgTime = uni_atoi(init3_str(conf->getArgParam("--" + argprefix + "resetMsgTime"),conf->getProp(cnode,"resetMsgTime"),s_resetTime)); resetMsgTime = uni_atoi(init3_str(conf->getArgParam("--" + argprefix + "resetMsgTime"), conf->getProp(cnode, "resetMsgTime"), s_resetTime));
ptResetMsg.setTiming(resetMsgTime); ptResetMsg.setTiming(resetMsgTime);
smReadyTimeout = conf->getArgInt("--" + argprefix + "sm-ready-timeout",""); smReadyTimeout = conf->getArgInt("--" + argprefix + "sm-ready-timeout", "");
if( smReadyTimeout == 0 ) if( smReadyTimeout == 0 )
smReadyTimeout = 60000; smReadyTimeout = 60000;
else if( smReadyTimeout < 0 ) else if( smReadyTimeout < 0 )
smReadyTimeout = UniSetTimer::WaitUpTime; smReadyTimeout = UniSetTimer::WaitUpTime;
smTestID = conf->getSensorID(init3_str(conf->getArgParam("--" + argprefix + "sm-test-id"),conf->getProp(cnode,"smTestID"),"")); smTestID = conf->getSensorID(init3_str(conf->getArgParam("--" + argprefix + "sm-test-id"), conf->getProp(cnode, "smTestID"), ""));
activateTimeout = conf->getArgPInt("--" + argprefix + "activate-timeout", 20000); activateTimeout = conf->getArgPInt("--" + argprefix + "activate-timeout", 20000);
...@@ -226,7 +232,7 @@ bool UObject_SK::setMsg( UniSetTypes::ObjectId _code, bool _state ) ...@@ -226,7 +232,7 @@ bool UObject_SK::setMsg( UniSetTypes::ObjectId _code, bool _state )
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
void UObject_SK::resetMsg() void UObject_SK::resetMsg()
{ {
// reset messages // reset messages
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
...@@ -304,11 +310,13 @@ void UObject_SK::preSysCommand( const SystemMessage* _sm ) ...@@ -304,11 +310,13 @@ void UObject_SK::preSysCommand( const SystemMessage* _sm )
{ {
case SystemMessage::WatchDog: case SystemMessage::WatchDog:
ulogany << myname << "(preSysCommand): WatchDog" << endl; ulogany << myname << "(preSysCommand): WatchDog" << endl;
if( !active || !ptStartUpTimeout.checkTime() ) if( !active || !ptStartUpTimeout.checkTime() )
{ {
uwarn << myname << "(preSysCommand): игнорируем WatchDog, потому-что только-что стартанули" << endl; uwarn << myname << "(preSysCommand): игнорируем WatchDog, потому-что только-что стартанули" << endl;
break; break;
} }
case SystemMessage::StartUp: case SystemMessage::StartUp:
{ {
if( !logserv_host.empty() && logserv_port != 0 && !logserv->isRunning() ) if( !logserv_host.empty() && logserv_port != 0 && !logserv->isRunning() )
...@@ -340,9 +348,10 @@ void UObject_SK::preSysCommand( const SystemMessage* _sm ) ...@@ -340,9 +348,10 @@ void UObject_SK::preSysCommand( const SystemMessage* _sm )
// переоткрываем логи // переоткрываем логи
mylogany << myname << "(preSysCommand): logRotate" << endl; mylogany << myname << "(preSysCommand): logRotate" << endl;
string fname( mylog->getLogFile() ); string fname( mylog->getLogFile() );
if( !fname.empty() ) if( !fname.empty() )
{ {
mylog->logFile(fname.c_str(),true); mylog->logFile(fname.c_str(), true);
mylogany << myname << "(preSysCommand): ***************** mylog LOG ROTATE *****************" << endl; mylogany << myname << "(preSysCommand): ***************** mylog LOG ROTATE *****************" << endl;
} }
} }
...@@ -395,7 +404,7 @@ void UObject_SK::waitSM( int wait_msec, ObjectId _testID ) ...@@ -395,7 +404,7 @@ void UObject_SK::waitSM( int wait_msec, ObjectId _testID )
<< wait_msec << " msec" << wait_msec << " msec"
<< " testID=" << _testID << endl; << " testID=" << _testID << endl;
if( !ui->waitReady(_testID,wait_msec) ) if( !ui->waitReady(_testID, wait_msec) )
{ {
ostringstream err; ostringstream err;
err << myname err << myname
...@@ -403,11 +412,11 @@ void UObject_SK::waitSM( int wait_msec, ObjectId _testID ) ...@@ -403,11 +412,11 @@ void UObject_SK::waitSM( int wait_msec, ObjectId _testID )
<< wait_msec << " мсек"; << wait_msec << " мсек";
ucrit << err.str() << endl; ucrit << err.str() << endl;
// terminate(); // terminate();
// abort(); // abort();
raise(SIGTERM); raise(SIGTERM);
terminate(); terminate();
// throw SystemError(err.str()); // throw SystemError(err.str());
} }
...@@ -419,35 +428,37 @@ void UObject_SK::callback() ...@@ -419,35 +428,37 @@ void UObject_SK::callback()
{ {
if( !active ) if( !active )
return; return;
try try
{ {
// проверка таймеров // проверка таймеров
checkTimers(this); checkTimers(this);
if( resetMsgTime>0 && trResetMsg.hi(ptResetMsg.checkTime()) ) if( resetMsgTime > 0 && trResetMsg.hi(ptResetMsg.checkTime()) )
{ {
// cout << myname << ": ********* reset messages *********" << endl; // cout << myname << ": ********* reset messages *********" << endl;
resetMsg(); resetMsg();
} }
// обработка сообщений (таймеров и т.п.) // обработка сообщений (таймеров и т.п.)
for( unsigned int i=0; i<20; i++ ) for( unsigned int i = 0; i < 20; i++ )
{ {
if( !receiveMessage(msg) ) if( !receiveMessage(msg) )
break; break;
processingMessage(&msg); processingMessage(&msg);
updateOutputs(forceOut); updateOutputs(forceOut);
// updatePreviousValues(); // updatePreviousValues();
} }
// Выполнение шага программы // Выполнение шага программы
step(); step();
// "сердцебиение" // "сердцебиение"
if( idHeartBeat!=DefaultObjectId && ptHeartBeat.checkTime() ) if( idHeartBeat != DefaultObjectId && ptHeartBeat.checkTime() )
{ {
ui->setValue(idHeartBeat,maxHeartBeat,UniversalIO::AI); ui->setValue(idHeartBeat, maxHeartBeat, UniversalIO::AI);
ptHeartBeat.reset(); ptHeartBeat.reset();
} }
...@@ -464,7 +475,7 @@ void UObject_SK::callback() ...@@ -464,7 +475,7 @@ void UObject_SK::callback()
ucrit << myname << "(execute): СORBA::SystemException: " ucrit << myname << "(execute): СORBA::SystemException: "
<< ex.NP_minorString() << endl; << ex.NP_minorString() << endl;
} }
catch( const std::exception&ex ) catch( const std::exception& ex )
{ {
ucrit << myname << "(execute): catch " << ex.what() << endl; ucrit << myname << "(execute): catch " << ex.what() << endl;
} }
...@@ -479,7 +490,7 @@ void UObject_SK::setValue( UniSetTypes::ObjectId _sid, long _val ) ...@@ -479,7 +490,7 @@ void UObject_SK::setValue( UniSetTypes::ObjectId _sid, long _val )
{ {
ui->setValue(_sid,_val); ui->setValue(_sid, _val);
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
void UObject_SK::updateOutputs( bool _force ) void UObject_SK::updateOutputs( bool _force )
...@@ -496,7 +507,7 @@ void UObject_SK::preSensorInfo( const UniSetTypes::SensorMessage* _sm ) ...@@ -496,7 +507,7 @@ void UObject_SK::preSensorInfo( const UniSetTypes::SensorMessage* _sm )
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
void UObject_SK::askSensor( UniSetTypes::ObjectId _sid, UniversalIO::UIOCommand _cmd, UniSetTypes::ObjectId _node ) void UObject_SK::askSensor( UniSetTypes::ObjectId _sid, UniversalIO::UIOCommand _cmd, UniSetTypes::ObjectId _node )
{ {
ui->askRemoteSensor(_sid,_cmd,_node,getId()); ui->askRemoteSensor(_sid, _cmd, _node, getId());
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
long UObject_SK::getValue( UniSetTypes::ObjectId _sid ) long UObject_SK::getValue( UniSetTypes::ObjectId _sid )
...@@ -518,10 +529,12 @@ long UObject_SK::getValue( UniSetTypes::ObjectId _sid ) ...@@ -518,10 +529,12 @@ long UObject_SK::getValue( UniSetTypes::ObjectId _sid )
void UObject_SK::preAskSensors( UniversalIO::UIOCommand _cmd ) void UObject_SK::preAskSensors( UniversalIO::UIOCommand _cmd )
{ {
PassiveTimer ptAct(activateTimeout); PassiveTimer ptAct(activateTimeout);
while( !activated && !ptAct.checkTime() ) while( !activated && !ptAct.checkTime() )
{ {
cout << myname << "(preAskSensors): wait activate..." << endl; cout << myname << "(preAskSensors): wait activate..." << endl;
msleep(300); msleep(300);
if( activated ) if( activated )
break; break;
} }
...@@ -541,7 +554,7 @@ void UObject_SK::preAskSensors( UniversalIO::UIOCommand _cmd ) ...@@ -541,7 +554,7 @@ void UObject_SK::preAskSensors( UniversalIO::UIOCommand _cmd )
{ {
ucrit << myname << "(preAskSensors): " << ex << endl; ucrit << myname << "(preAskSensors): " << ex << endl;
} }
catch( const std::exception&ex ) catch( const std::exception& ex )
{ {
ucrit << myname << "(execute): catch " << ex.what() << endl; ucrit << myname << "(execute): catch " << ex.what() << endl;
} }
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
#include <string> #include <string>
#include <memory> #include <memory>
#include <list>
#include <unordered_map> #include <unordered_map>
#include "DebugStream.h" #include "DebugStream.h"
#include "LogServerTypes.h" #include "LogServerTypes.h"
...@@ -39,6 +40,8 @@ class LogAgregator: ...@@ -39,6 +40,8 @@ class LogAgregator:
std::shared_ptr<DebugStream> getLog( const std::string& logname ); std::shared_ptr<DebugStream> getLog( const std::string& logname );
LogInfo getLogInfo( const std::string& logname ); LogInfo getLogInfo( const std::string& logname );
std::list<std::shared_ptr<DebugStream>> getLogList();
protected: protected:
void logOnEvent( const std::string& s ); void logOnEvent( const std::string& s );
......
...@@ -16,7 +16,8 @@ namespace LogServerTypes ...@@ -16,7 +16,8 @@ namespace LogServerTypes
cmdDelLevel, /*!< удалить уровень вывода */ cmdDelLevel, /*!< удалить уровень вывода */
cmdRotate, /*!< пересоздать файл с логами */ cmdRotate, /*!< пересоздать файл с логами */
cmdOffLogFile, /*!< отключить запись файла логов (если включена) */ cmdOffLogFile, /*!< отключить запись файла логов (если включена) */
cmdOnLogFile /*!< включить запись файла логов (если была отключена) */ cmdOnLogFile, /*!< включить запись файла логов (если была отключена) */
cmdList /*!< вывести список контролируемых логов */
// cmdSetLogFile // cmdSetLogFile
}; };
......
...@@ -66,7 +66,7 @@ namespace UniSetTypes ...@@ -66,7 +66,7 @@ namespace UniSetTypes
void initLocalNode( const UniSetTypes::ObjectId nodeid ); void initLocalNode( const UniSetTypes::ObjectId nodeid );
protected: protected:
std::string nmLocalNode={""}; // поле для оптимизации получения LocalNode std::string nmLocalNode = {""}; // поле для оптимизации получения LocalNode
private: private:
......
...@@ -44,7 +44,7 @@ class UniXML_iterator: ...@@ -44,7 +44,7 @@ class UniXML_iterator:
UniXML_iterator(xmlNode* node) : UniXML_iterator(xmlNode* node) :
curNode(node) curNode(node)
{} {}
UniXML_iterator():curNode(0) {} UniXML_iterator(): curNode(0) {}
std::string getProp2( const std::string& name, const std::string& defval = "" ); std::string getProp2( const std::string& name, const std::string& defval = "" );
std::string getProp( const std::string& name ); std::string getProp( const std::string& name );
......
...@@ -108,3 +108,13 @@ LogAgregator::LogInfo LogAgregator::getLogInfo( const std::string& logname ) ...@@ -108,3 +108,13 @@ LogAgregator::LogInfo LogAgregator::getLogInfo( const std::string& logname )
return LogInfo(); return LogInfo();
} }
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
std::list<std::shared_ptr<DebugStream>> LogAgregator::getLogList()
{
std::list< std::shared_ptr<DebugStream> > l;
for( auto && i : lmap )
l.push_back(i.second.log);
return std::move(l);
}
// -------------------------------------------------------------------------
...@@ -150,6 +150,8 @@ void LogReader::readlogs( const std::string& _addr, ost::tpport_t _port, LogServ ...@@ -150,6 +150,8 @@ void LogReader::readlogs( const std::string& _addr, ost::tpport_t _port, LogServ
while( n > 0 ) while( n > 0 )
{ {
try
{
if( !isConnection() ) if( !isConnection() )
connect(_addr, _port, reconDelay); connect(_addr, _port, reconDelay);
...@@ -209,6 +211,15 @@ void LogReader::readlogs( const std::string& _addr, ost::tpport_t _port, LogServ ...@@ -209,6 +211,15 @@ void LogReader::readlogs( const std::string& _addr, ost::tpport_t _port, LogServ
rlog.warn() << "(LogReader): ...connection timeout..." << endl; rlog.warn() << "(LogReader): ...connection timeout..." << endl;
send_ok = false; // ??!! делать ли? send_ok = false; // ??!! делать ли?
disconnect(); disconnect();
}
catch( const ost::SockException& e )
{
cerr << "(LogReader): " << e.getString() << " (" << _addr << ")" << endl;
}
catch( const std::exception& ex )
{
cerr << "(LogReader): " << ex.what() << endl;
}
if( readcount > 0 ) if( readcount > 0 )
n--; n--;
......
...@@ -168,6 +168,35 @@ void LogSession::run() ...@@ -168,6 +168,35 @@ void LogSession::run()
break; break;
case LogServerTypes::cmdList:
{
if( isPending(Socket::pendingOutput, cmdTimeout) )
{
ostringstream s;
s << "List of managed logs:" << endl;
s << "=====================" << endl;
auto lag = dynamic_pointer_cast<LogAgregator>(log);
if( !lag )
{
s << log->getLogName() << endl;
}
else
{
auto lst = lag->getLogList();
for( const auto& i : lst )
s << i->getLogName() << endl;
}
s << "=====================" << endl;
*tcp() << s.str();
tcp()->sync();
}
}
break;
case LogServerTypes::cmdOffLogFile: case LogServerTypes::cmdOffLogFile:
{ {
if( !logfile.empty() ) if( !logfile.empty() )
......
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