Commit 13719a7b authored by Pavel Vainerman's avatar Pavel Vainerman

(LogServer): ушёл от использования переменной scount (перевёл на vector)

parent 1ff72a00
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
ВСЕ ВАШИ ИЗМЕНЕНИЯ БУДУТ ПОТЕРЯНЫ. ВСЕ ВАШИ ИЗМЕНЕНИЯ БУДУТ ПОТЕРЯНЫ.
*/ */
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
// generate timestamp: 2016-08-25+03:00 // generate timestamp: 2016-09-30+03:00
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
#ifndef UObject_SK_H_ #ifndef UObject_SK_H_
#define UObject_SK_H_ #define UObject_SK_H_
...@@ -29,7 +29,7 @@ class UObject_SK: ...@@ -29,7 +29,7 @@ class UObject_SK:
public UniSetObject public UniSetObject
{ {
public: public:
UObject_SK( UniSetTypes::ObjectId id, xmlNode* node = UniSetTypes::uniset_conf()->getNode("UObject"), const std::string& argprefix = "" ); UObject_SK( UniSetTypes::ObjectId id, xmlNode* node=UniSetTypes::uniset_conf()->getNode("UObject"), const std::string& argprefix="" );
UObject_SK(); UObject_SK();
virtual ~UObject_SK(); virtual ~UObject_SK();
...@@ -41,62 +41,56 @@ class UObject_SK: ...@@ -41,62 +41,56 @@ class UObject_SK:
virtual UniSetTypes::SimpleInfo* getInfo( CORBA::Long userparam = 0 ) override; virtual UniSetTypes::SimpleInfo* getInfo( CORBA::Long userparam = 0 ) override;
virtual bool setMsg( UniSetTypes::ObjectId code, bool state = true ); virtual bool setMsg( UniSetTypes::ObjectId code, bool state = true ) noexcept;
inline std::shared_ptr<DebugStream> log() inline std::shared_ptr<DebugStream> log() noexcept { return mylog; }
{ inline std::shared_ptr<LogAgregator> logAgregator() noexcept { return loga; }
return mylog;
}
inline std::shared_ptr<LogAgregator> logAgregator()
{
return loga;
}
void init_dlog( std::shared_ptr<DebugStream> d ); void init_dlog( std::shared_ptr<DebugStream> d ) noexcept;
// "синтаксический сахар"..для логов // "синтаксический сахар"..для логов
#ifndef myinfo #ifndef myinfo
#define myinfo if( log()->debugging(Debug::INFO) ) log()->info() #define myinfo if( log()->debugging(Debug::INFO) ) log()->info()
#endif #endif
#ifndef mywarn #ifndef mywarn
#define mywarn if( log()->debugging(Debug::WARN) ) log()->warn() #define mywarn if( log()->debugging(Debug::WARN) ) log()->warn()
#endif #endif
#ifndef mycrit #ifndef mycrit
#define mycrit if( log()->debugging(Debug::CRIT) ) log()->crit() #define mycrit if( log()->debugging(Debug::CRIT) ) log()->crit()
#endif #endif
#ifndef mylog1 #ifndef mylog1
#define mylog1 if( log()->debugging(Debug::LEVEL1) ) log()->level1() #define mylog1 if( log()->debugging(Debug::LEVEL1) ) log()->level1()
#endif #endif
#ifndef mylog2 #ifndef mylog2
#define mylog2 if( log()->debugging(Debug::LEVEL2) ) log()->level2() #define mylog2 if( log()->debugging(Debug::LEVEL2) ) log()->level2()
#endif #endif
#ifndef mylog3 #ifndef mylog3
#define mylog3 if( log()->debugging(Debug::LEVEL3) ) log()->level3() #define mylog3 if( log()->debugging(Debug::LEVEL3) ) log()->level3()
#endif #endif
#ifndef mylog4 #ifndef mylog4
#define mylog4 if( log()->debugging(Debug::LEVEL4) ) log()->level4() #define mylog4 if( log()->debugging(Debug::LEVEL4) ) log()->level4()
#endif #endif
#ifndef mylog5 #ifndef mylog5
#define mylog5 if( log()->debugging(Debug::LEVEL5) ) log()->level5() #define mylog5 if( log()->debugging(Debug::LEVEL5) ) log()->level5()
#endif #endif
#ifndef mylog6 #ifndef mylog6
#define mylog6 if( log()->debugging(Debug::LEVEL6) ) log()->level6() #define mylog6 if( log()->debugging(Debug::LEVEL6) ) log()->level6()
#endif #endif
#ifndef mylog7 #ifndef mylog7
#define mylog7 if( log()->debugging(Debug::LEVEL7) ) log()->level7() #define mylog7 if( log()->debugging(Debug::LEVEL7) ) log()->level7()
#endif #endif
#ifndef mylog8 #ifndef mylog8
#define mylog8 if( log()->debugging(Debug::LEVEL8) ) log()->level8() #define mylog8 if( log()->debugging(Debug::LEVEL8) ) log()->level8()
#endif #endif
#ifndef mylog9 #ifndef mylog9
#define mylog9 if( log()->debugging(Debug::LEVEL9) ) log()->level9() #define mylog9 if( log()->debugging(Debug::LEVEL9) ) log()->level9()
#endif #endif
#ifndef mylogany #ifndef mylogany
#define mylogany log()->any() #define mylogany log()->any()
#endif #endif
#ifndef vmonit #ifndef vmonit
#define vmonit( var ) vmon.add( #var, var ) #define vmonit( var ) vmon.add( #var, var )
#endif #endif
// Вспомогательные функции для удобства логирования // Вспомогательные функции для удобства логирования
// ------------------------------------------------------------ // ------------------------------------------------------------
...@@ -113,21 +107,18 @@ class UObject_SK: ...@@ -113,21 +107,18 @@ 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 ) const; std::string str( UniSetTypes::ObjectId id, bool showLinkName=true ) const;
/*! Вывод значения входа/выхода в формате: 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 ) const; std::string strval( UniSetTypes::ObjectId id, bool showLinkName=true ) const;
/*! Вывод состояния внутренних переменных */ /*! Вывод состояния внутренних переменных */
inline std::string dumpVars() inline std::string dumpVars(){ return std::move(vmon.pretty_str()); }
{
return std::move(vmon.pretty_str());
}
// ------------------------------------------------------------ // ------------------------------------------------------------
std::string help(); std::string help() noexcept;
...@@ -152,21 +143,21 @@ class UObject_SK: ...@@ -152,21 +143,21 @@ class UObject_SK:
// ---- end of protected variables ---- // ---- end of protected variables ----
virtual void callback() override; virtual void callback() noexcept override;
virtual void processingMessage( const UniSetTypes::VoidMessage* msg ) override; virtual void processingMessage( const UniSetTypes::VoidMessage* msg ) override;
virtual void sysCommand( const UniSetTypes::SystemMessage* sm ) {}; virtual void sysCommand( const UniSetTypes::SystemMessage* sm ){};
virtual void askSensors( UniversalIO::UIOCommand cmd ) {} virtual void askSensors( UniversalIO::UIOCommand cmd ){}
virtual void sensorInfo( const UniSetTypes::SensorMessage* sm ) override {} virtual void sensorInfo( const UniSetTypes::SensorMessage* sm ) override{}
virtual void timerInfo( const UniSetTypes::TimerMessage* tm ) override {} virtual void timerInfo( const UniSetTypes::TimerMessage* tm ) override{}
virtual void sigterm( int signo ) override; virtual void sigterm( int signo ) override;
virtual bool activateObject() override; virtual bool activateObject() override;
virtual std::string getMonitInfo() virtual std::string getMonitInfo(){ return ""; } /*!< пользовательская информация выводимая в getInfo() */
{
return ""; /*!< пользовательская информация выводимая в getInfo() */
}
// Выполнение очередного шага программы // Выполнение очередного шага программы
virtual void step() {} virtual void step(){}
void preAskSensors( UniversalIO::UIOCommand cmd );
void preSysCommand( const UniSetTypes::SystemMessage* sm );
virtual void testMode( bool state ); virtual void testMode( bool state );
void updateOutputs( bool force ); void updateOutputs( bool force );
...@@ -192,15 +183,9 @@ class UObject_SK: ...@@ -192,15 +183,9 @@ class UObject_SK:
xmlNode* confnode; xmlNode* confnode;
/*! получить числовое свойство из конф. файла по привязанной confnode */ /*! получить числовое свойство из конф. файла по привязанной confnode */
int getIntProp(const std::string& name) int getIntProp(const std::string& name) { return UniSetTypes::uniset_conf()->getIntProp(confnode, name); }
{
return UniSetTypes::uniset_conf()->getIntProp(confnode, name);
}
/*! получить текстовое свойство из конф. файла по привязанной confnode */ /*! получить текстовое свойство из конф. файла по привязанной confnode */
inline const std::string getProp(const std::string& name) inline const std::string getProp(const std::string& name) { return UniSetTypes::uniset_conf()->getProp(confnode, name); }
{
return UniSetTypes::uniset_conf()->getProp(confnode, name);
}
timeout_t smReadyTimeout; /*!< время ожидания готовности SM */ timeout_t smReadyTimeout; /*!< время ожидания готовности SM */
std::atomic_bool activated; std::atomic_bool activated;
...@@ -235,11 +220,9 @@ class UObject_SK: ...@@ -235,11 +220,9 @@ class UObject_SK:
// Используемые идентификаторы сообщений // Используемые идентификаторы сообщений
// ------------ private функции --------------- // ------------ private функции ---------------
void updatePreviousValues(); void updatePreviousValues() noexcept;
void preAskSensors( UniversalIO::UIOCommand cmd );
void preSensorInfo( const UniSetTypes::SensorMessage* sm ); void preSensorInfo( const UniSetTypes::SensorMessage* sm );
void preTimerInfo( const UniSetTypes::TimerMessage* tm ); void preTimerInfo( const UniSetTypes::TimerMessage* tm );
void preSysCommand( const UniSetTypes::SystemMessage* sm );
void initFromSM(); void initFromSM();
void checkSensors(); void checkSensors();
// -------------------------------------------- // --------------------------------------------
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
#ifndef LogServer_H_ #ifndef LogServer_H_
#define LogServer_H_ #define LogServer_H_
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
#include <list> #include <vector>
#include <string> #include <string>
#include <memory> #include <memory>
#include <unordered_map> #include <unordered_map>
...@@ -138,9 +138,8 @@ class LogServer: ...@@ -138,9 +138,8 @@ class LogServer:
std::string onCommand( LogSession* s, LogServerTypes::Command cmd, const std::string& logname ); std::string onCommand( LogSession* s, LogServerTypes::Command cmd, const std::string& logname );
private: private:
typedef std::list< std::shared_ptr<LogSession> > SessionList; typedef std::vector< std::shared_ptr<LogSession> > SessionList;
SessionList slist; SessionList slist;
size_t scount = { 0 };
UniSetTypes::uniset_rwmutex mutSList; UniSetTypes::uniset_rwmutex mutSList;
timeout_t timeout = { UniSetTimer::WaitUpTime }; timeout_t timeout = { UniSetTimer::WaitUpTime };
......
...@@ -46,6 +46,7 @@ LogServer::LogServer( std::shared_ptr<LogAgregator> log ) noexcept: ...@@ -46,6 +46,7 @@ LogServer::LogServer( std::shared_ptr<LogAgregator> log ) noexcept:
} }
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
LogServer::LogServer( std::shared_ptr<DebugStream> log ) noexcept: LogServer::LogServer( std::shared_ptr<DebugStream> log ) noexcept:
slist(sessMaxCount),
timeout(UniSetTimer::WaitUpTime), timeout(UniSetTimer::WaitUpTime),
cmdTimeout(2000), cmdTimeout(2000),
sessLogLevel(Debug::NONE), sessLogLevel(Debug::NONE),
...@@ -55,6 +56,7 @@ LogServer::LogServer( std::shared_ptr<DebugStream> log ) noexcept: ...@@ -55,6 +56,7 @@ LogServer::LogServer( std::shared_ptr<DebugStream> log ) noexcept:
} }
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
LogServer::LogServer() noexcept: LogServer::LogServer() noexcept:
slist(sessMaxCount),
timeout(UniSetTimer::WaitUpTime), timeout(UniSetTimer::WaitUpTime),
cmdTimeout(2000), cmdTimeout(2000),
sessLogLevel(Debug::NONE), sessLogLevel(Debug::NONE),
...@@ -213,7 +215,7 @@ void LogServer::ioAccept( ev::io& watcher, int revents ) ...@@ -213,7 +215,7 @@ void LogServer::ioAccept( ev::io& watcher, int revents )
{ {
uniset_rwmutex_wrlock l(mutSList); uniset_rwmutex_wrlock l(mutSList);
if( scount >= sessMaxCount ) if( slist.size() >= sessMaxCount )
{ {
if( mylog.is_crit() ) if( mylog.is_crit() )
mylog.crit() << myname << "(LogServer::ioAccept): session limit(" << sessMaxCount << ")" << endl; mylog.crit() << myname << "(LogServer::ioAccept): session limit(" << sessMaxCount << ")" << endl;
...@@ -233,13 +235,10 @@ void LogServer::ioAccept( ev::io& watcher, int revents ) ...@@ -233,13 +235,10 @@ void LogServer::ioAccept( ev::io& watcher, int revents )
s->signal_logsession_command().connect( sigc::mem_fun(this, &LogServer::onCommand) ); s->signal_logsession_command().connect( sigc::mem_fun(this, &LogServer::onCommand) );
{ {
uniset_rwmutex_wrlock l(mutSList); uniset_rwmutex_wrlock l(mutSList);
scount++; slist.push_back(s);
// на первой сессии запоминаем состояние логов // на первой сессии запоминаем состояние логов
if( scount == 1 ) if( slist.size() == 1 )
saveDefaultLogLevels("ALL"); saveDefaultLogLevels("ALL");
slist.push_back(s);
} }
s->run(watcher.loop); s->run(watcher.loop);
...@@ -259,14 +258,12 @@ void LogServer::sessionFinished( LogSession* s ) ...@@ -259,14 +258,12 @@ void LogServer::sessionFinished( LogSession* s )
if( i->get() == s ) if( i->get() == s )
{ {
slist.erase(i); slist.erase(i);
scount--;
break; break;
} }
} }
if( slist.empty() ) if( slist.empty() )
{ {
scount = 0;
// восстанавливаем уровни логов по умолчанию // восстанавливаем уровни логов по умолчанию
restoreDefaultLogLevels("ALL"); restoreDefaultLogLevels("ALL");
} }
......
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