Commit bef704d0 authored by Pavel Vainerman's avatar Pavel Vainerman

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

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