Commit bef704d0 authored by Pavel Vainerman's avatar Pavel Vainerman

(SharedMemory): встроил LogServer..

parent 8d4fbf3b
...@@ -19,7 +19,6 @@ ...@@ -19,7 +19,6 @@
#include "IOBase.h" #include "IOBase.h"
#include "VTypes.h" #include "VTypes.h"
#include "ThreadCreator.h" #include "ThreadCreator.h"
#include "LogAgregator.h"
#include "LogServer.h" #include "LogServer.h"
#include "modbus/MBLogSugar.h" #include "modbus/MBLogSugar.h"
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
......
...@@ -11,6 +11,10 @@ ...@@ -11,6 +11,10 @@
#include "PassiveTimer.h" #include "PassiveTimer.h"
#include "NCRestorer.h" #include "NCRestorer.h"
#include "WDTInterface.h" #include "WDTInterface.h"
#include "LogServer.h"
#include "DebugStream.h"
#include "SMLogSugar.h"
#include "LogAgregator.h"
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
/*! \page page_SharedMemory Реализация разделямой между процессами памяти (SharedMemory) /*! \page page_SharedMemory Реализация разделямой между процессами памяти (SharedMemory)
...@@ -377,7 +381,7 @@ class SharedMemory: ...@@ -377,7 +381,7 @@ class SharedMemory:
virtual void sysCommand( const UniSetTypes::SystemMessage* sm ) override; virtual void sysCommand( const UniSetTypes::SystemMessage* sm ) override;
virtual void timerInfo( const UniSetTypes::TimerMessage* tm ) override; virtual void timerInfo( const UniSetTypes::TimerMessage* tm ) override;
virtual void askSensors( UniversalIO::UIOCommand cmd ); virtual void askSensors( UniversalIO::UIOCommand cmd ){};
void sendEvent( UniSetTypes::SystemMessage& sm ); void sendEvent( UniSetTypes::SystemMessage& sm );
void initFromReserv(); void initFromReserv();
bool initFromSM( UniSetTypes::ObjectId sm_id, UniSetTypes::ObjectId sm_node ); bool initFromSM( UniSetTypes::ObjectId sm_id, UniSetTypes::ObjectId sm_node );
...@@ -385,6 +389,7 @@ class SharedMemory: ...@@ -385,6 +389,7 @@ class SharedMemory:
// действия при завершении работы // действия при завершении работы
virtual void sigterm( int signo ) override; virtual void sigterm( int signo ) override;
virtual bool activateObject() override; virtual bool activateObject() override;
virtual bool deactivateObject() override;
bool readItem( const std::shared_ptr<UniXML>& xml, UniXML::iterator& it, xmlNode* sec ); bool readItem( const std::shared_ptr<UniXML>& xml, UniXML::iterator& it, xmlNode* sec );
void buildEventList( xmlNode* cnode ); void buildEventList( xmlNode* cnode );
...@@ -464,6 +469,12 @@ class SharedMemory: ...@@ -464,6 +469,12 @@ class SharedMemory:
xmlNode* confnode; xmlNode* confnode;
std::shared_ptr<LogAgregator> loga;
std::shared_ptr<DebugStream> smlog;
std::shared_ptr<LogServer> logserv;
std::string logserv_host = {""};
int logserv_port = {0};
private: private:
HistorySlot m_historySignal; HistorySlot m_historySignal;
}; };
......
...@@ -23,10 +23,13 @@ int main(int argc, const char** argv) ...@@ -23,10 +23,13 @@ int main(int argc, const char** argv)
{ {
auto conf = uniset_init(argc, argv); auto conf = uniset_init(argc, argv);
string logfilename = conf->getArgParam("--logfile", "smemory.log"); string logfilename = conf->getArgParam("--logfile", "");
string logname( conf->getLogDir() + logfilename ); if( !logfilename.empty() )
ulog()->logFile( logname ); {
dlog()->logFile( logname ); string logname( conf->getLogDir() + logfilename );
ulog()->logFile( logname );
dlog()->logFile( logname );
}
auto shm = SharedMemory::init_smemory(argc, argv); auto shm = SharedMemory::init_smemory(argc, argv);
......
...@@ -5,6 +5,7 @@ export LD_LIBRARY_PATH="../../lib/.libs;../lib/.libs" ...@@ -5,6 +5,7 @@ export LD_LIBRARY_PATH="../../lib/.libs;../lib/.libs"
ulimit -Sc 10000000000 ulimit -Sc 10000000000
./uniset2-start.sh -f ./uniset2-smemory --smemory-id SharedMemory --pulsar-id DO_C --pulsar-iotype DO --pulsar-msec 100 \ ./uniset2-start.sh -f ./uniset2-smemory --smemory-id SharedMemory --pulsar-id DO_C --pulsar-iotype DO --pulsar-msec 100 \
--confile test.xml --datfile test.xml --db-logging 1 --ulog-add-levels system $* \ --confile test.xml --datfile test.xml --db-logging 1 --ulog-add-levels system \
--sm-log-add-levels any $* \
#--ulog-add-levels info,crit,warn,level9,system \ #--ulog-add-levels info,crit,warn,level9,system \
#--dlog-add-levels info,crit,warn \ #--dlog-add-levels info,crit,warn \
...@@ -106,7 +106,7 @@ class LogServer ...@@ -106,7 +106,7 @@ class LogServer
std::atomic_bool cancelled; std::atomic_bool cancelled;
DebugStream mylog; DebugStream mylog;
ThreadCreator<LogServer>* thr; std::shared_ptr< ThreadCreator<LogServer> > thr;
ost::TCPSocket* tcp; ost::TCPSocket* tcp;
std::shared_ptr<DebugStream> elog; std::shared_ptr<DebugStream> elog;
......
...@@ -24,16 +24,6 @@ ModbusTCPServer::ModbusTCPServer( ost::InetAddress& ia, int port ): ...@@ -24,16 +24,6 @@ ModbusTCPServer::ModbusTCPServer( ost::InetAddress& ia, int port ):
ModbusTCPServer::~ModbusTCPServer() ModbusTCPServer::~ModbusTCPServer()
{ {
terminate(); terminate();
/*
{
uniset_mutex_lock l(sMutex);
for( auto& s: slist )
{
if( s->isRunning() )
s->ost::Thread::join();
}
}
*/
} }
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
void ModbusTCPServer::setMaxSessions( unsigned int num ) void ModbusTCPServer::setMaxSessions( unsigned int num )
...@@ -375,7 +365,7 @@ void ModbusTCPServer::terminate() ...@@ -375,7 +365,7 @@ void ModbusTCPServer::terminate()
uniset_mutex_lock l(sMutex); uniset_mutex_lock l(sMutex);
for( auto& s : slist ) for( const auto& s : slist )
{ {
try try
{ {
...@@ -404,7 +394,7 @@ void ModbusTCPServer::getSessions( Sessions& lst ) ...@@ -404,7 +394,7 @@ void ModbusTCPServer::getSessions( Sessions& lst )
{ {
uniset_mutex_lock l(sMutex); uniset_mutex_lock l(sMutex);
for( auto& i : slist ) for( const auto& i : slist )
{ {
SessionInfo inf( i->getClientAddress(), i->getAskCount() ); SessionInfo inf( i->getClientAddress(), i->getAskCount() );
lst.push_back(inf); lst.push_back(inf);
......
...@@ -12,10 +12,9 @@ LogServer::~LogServer() ...@@ -12,10 +12,9 @@ LogServer::~LogServer()
{ {
if( nullsess ) if( nullsess )
nullsess->cancel(); nullsess->cancel();
{ {
// uniset_rwmutex_wrlock l(mutSList); // uniset_rwmutex_wrlock l(mutSList);
for( auto& i : slist ) for( const auto& i : slist )
{ {
if( i->isRunning() ) if( i->isRunning() )
i->cancel(); i->cancel();
...@@ -24,17 +23,14 @@ LogServer::~LogServer() ...@@ -24,17 +23,14 @@ LogServer::~LogServer()
cancelled = true; cancelled = true;
if( tcp && !slist.empty() )
tcp->reject();
if( thr ) if( thr )
{
thr->stop(); thr->stop();
if( thr->isRunning() )
thr->join();
delete thr;
}
delete tcp; delete tcp;
tcp = 0;
} }
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
LogServer::LogServer( std::shared_ptr<LogAgregator> log ): LogServer::LogServer( std::shared_ptr<LogAgregator> log ):
...@@ -110,7 +106,7 @@ void LogServer::run( const std::string& addr, ost::tpport_t port, bool thread ) ...@@ -110,7 +106,7 @@ void LogServer::run( const std::string& addr, ost::tpport_t port, bool thread )
work(); work();
else else
{ {
thr = new ThreadCreator<LogServer>(this, &LogServer::work); thr = make_shared<ThreadCreator<LogServer>>(this, &LogServer::work);
thr->start(); thr->start();
} }
} }
...@@ -125,6 +121,7 @@ void LogServer::work() ...@@ -125,6 +121,7 @@ void LogServer::work()
{ {
while( !cancelled && tcp->isPendingConnection(timeout) ) while( !cancelled && tcp->isPendingConnection(timeout) )
{ {
if( cancelled ) break;
{ {
uniset_rwmutex_wrlock l(mutSList); uniset_rwmutex_wrlock l(mutSList);
int sz = slist.size(); int sz = slist.size();
...@@ -149,6 +146,8 @@ void LogServer::work() ...@@ -149,6 +146,8 @@ void LogServer::work()
} }
} }
if( cancelled ) break;
auto s = make_shared<LogSession>(*tcp, elog, sessTimeout, cmdTimeout, outTimeout); auto s = make_shared<LogSession>(*tcp, elog, sessTimeout, cmdTimeout, outTimeout);
s->setSessionLogLevel(sessLogLevel); s->setSessionLogLevel(sessLogLevel);
{ {
...@@ -178,7 +177,7 @@ void LogServer::work() ...@@ -178,7 +177,7 @@ void LogServer::work()
{ {
// uniset_rwmutex_wrlock l(mutSList); // uniset_rwmutex_wrlock l(mutSList);
for( auto& i : slist ) for( const auto& i : slist )
i->disconnect(); i->disconnect();
if( nullsess ) if( nullsess )
......
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