Commit 55d31016 authored by Pavel Vainerman's avatar Pavel Vainerman

backported to p8 as 2.7-alt12.M80P.13 (with rpmbph script)

parents fa141b99 b657f2fb
...@@ -18,5 +18,7 @@ with open source third-party libraries. UniSet provide the consistent interface ...@@ -18,5 +18,7 @@ with open source third-party libraries. UniSet provide the consistent interface
add-on components and third-party libraries. Python wrapper helps in using the library add-on components and third-party libraries. Python wrapper helps in using the library
in python scripts. in python scripts.
More information in Russian: More information:
http://wiki.etersoft.ru/UniSet * [RU] https://habr.com/post/278535/
* [RU] https://habr.com/post/171711/
* [RU] https://wiki.etersoft.ru/UniSet2/docs/
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
Name: libuniset2 Name: libuniset2
Version: 2.7 Version: 2.7
Release: alt11.M80P.12 Release: alt12.M80P.13
Summary: UniSet - library for building distributed industrial control systems Summary: UniSet - library for building distributed industrial control systems
License: LGPL License: LGPL
...@@ -54,7 +54,8 @@ BuildRequires: libcomedi-devel ...@@ -54,7 +54,8 @@ BuildRequires: libcomedi-devel
%endif %endif
%if_enabled mysql %if_enabled mysql
BuildRequires: libmysqlclient-devel # build with mariadb
BuildRequires: libmariadb-devel
%endif %endif
%if_enabled sqlite %if_enabled sqlite
...@@ -545,9 +546,13 @@ rm -f %buildroot%_docdir/%oname/html/*.md5 ...@@ -545,9 +546,13 @@ rm -f %buildroot%_docdir/%oname/html/*.md5
# history of current unpublished changes # history of current unpublished changes
%changelog %changelog
* Sun Jun 10 2018 Pavel Vainerman <pv@altlinux.ru> 2.7-alt11.M80P.12 * Wed Jul 11 2018 Pavel Vainerman <pv@altlinux.ru> 2.7-alt12.M80P.13
- backport to ALTLinux p8 (by rpmbph script) - backport to ALTLinux p8 (by rpmbph script)
* Wed Jul 11 2018 Pavel Vainerman <pv@altlinux.ru> 2.7-alt13
- (UActivator): refactoring the program termination process
- minor fixes
* Sun Jun 10 2018 Pavel Vainerman <pv@altlinux.ru> 2.7-alt12 * Sun Jun 10 2018 Pavel Vainerman <pv@altlinux.ru> 2.7-alt12
- spec cleanup - spec cleanup
......
...@@ -180,7 +180,7 @@ ...@@ -180,7 +180,7 @@
<UDPExchange2 name="UDPExchange2"/> <UDPExchange2 name="UDPExchange2"/>
<UNetExchange name="UNetExchange"/> <UNetExchange name="UNetExchange"/>
<HeartBeatTime msec="5000"/> <HeartBeatTime msec="5000"/>
<NCReadyTimeout msec="120000"/> <NCReadyTimeout msec="10000"/>
<TestGen input1_s="Input1_S" input2_s="DumpSensor1_S" name="TestGen" output1_c="DO_C" output2_c="DO1_C"/> <TestGen input1_s="Input1_S" input2_s="DumpSensor1_S" name="TestGen" output1_c="DO_C" output2_c="DO1_C"/>
<RRDServer1 name="RRDServer1"> <RRDServer1 name="RRDServer1">
<rrd filename="rrdtest.rrd" filter_field="rrd" filter_value="1" step="5" ds_field="rrd1_ds" overwrite="0"> <rrd filename="rrdtest.rrd" filter_field="rrd" filter_value="1" step="5" ds_field="rrd1_ds" overwrite="0">
......
...@@ -150,7 +150,7 @@ void PassiveLProcessor::sysCommand( const uniset::SystemMessage* sm ) ...@@ -150,7 +150,7 @@ void PassiveLProcessor::sysCommand( const uniset::SystemMessage* sm )
{ {
if( !shm->waitSMreadyWithCancellation(smReadyTimeout, cannceled) ) if( !shm->waitSMreadyWithCancellation(smReadyTimeout, cannceled) )
{ {
dcrit << myname << "(ERR): SM not ready. Terminated... " << endl; dcrit << myname << "(ERR): SM not ready. Terminated... " << endl << flush;
// std::terminate(); // std::terminate();
uterminate(); uterminate();
return; return;
......
...@@ -3021,7 +3021,7 @@ namespace uniset ...@@ -3021,7 +3021,7 @@ namespace uniset
if( devices.empty() ) if( devices.empty() )
{ {
mbcrit << myname << "(sysCommand): ************* ITEM MAP EMPTY! terminated... *************" << endl; mbcrit << myname << "(sysCommand): ************* ITEM MAP EMPTY! terminated... *************" << endl << flush;
// std::terminate(); // std::terminate();
uterminate(); uterminate();
return; return;
...@@ -3056,7 +3056,7 @@ namespace uniset ...@@ -3056,7 +3056,7 @@ namespace uniset
if( !isProcActive() ) if( !isProcActive() )
{ {
mbcrit << myname << "(sysCommand): ************* don`t activate?! ************" << endl; mbcrit << myname << "(sysCommand): ************* don`t activate?! ************" << endl << flush;
uterminate(); uterminate();
return; return;
} }
...@@ -3132,7 +3132,7 @@ namespace uniset ...@@ -3132,7 +3132,7 @@ namespace uniset
<< "(askSensors): Не дождались готовности(work) SharedMemory к работе в течение " << "(askSensors): Не дождались готовности(work) SharedMemory к работе в течение "
<< activateTimeout << " мсек"; << activateTimeout << " мсек";
mbcrit << err.str() << endl; mbcrit << err.str() << endl << flush;
// std::terminate(); // прерываем (перезапускаем) процесс... // std::terminate(); // прерываем (перезапускаем) процесс...
uterminate(); uterminate();
return; return;
......
...@@ -582,7 +582,7 @@ namespace uniset ...@@ -582,7 +582,7 @@ namespace uniset
if( vaddr.empty() ) if( vaddr.empty() )
{ {
mbcrit << "(execute_rtu): Unknown my modbus addresses!" << endl; mbcrit << "(execute_rtu): Unknown my modbus addresses!" << endl << flush;
//std::terminate(); //std::terminate();
uterminate(); uterminate();
return; return;
...@@ -622,7 +622,7 @@ namespace uniset ...@@ -622,7 +622,7 @@ namespace uniset
{ {
if( !tcpserver ) if( !tcpserver )
{ {
mbcrit << myname << "(execute_tcp): DYNAMIC CAST ERROR (mbslot --> ModbusTCPServerSlot)" << std::endl; mbcrit << myname << "(execute_tcp): DYNAMIC CAST ERROR (mbslot --> ModbusTCPServerSlot)" << std::endl << flush;
// std::terminate(); // std::terminate();
uterminate(); uterminate();
return; return;
...@@ -645,7 +645,7 @@ namespace uniset ...@@ -645,7 +645,7 @@ namespace uniset
if( vaddr.empty() ) if( vaddr.empty() )
{ {
mbcrit << "(execute_tcp): Unknown my modbus addresses!" << endl; mbcrit << "(execute_tcp): Unknown my modbus addresses!" << endl << flush;
// std::terminate(); // std::terminate();
uterminate(); uterminate();
return; return;
...@@ -686,7 +686,8 @@ namespace uniset ...@@ -686,7 +686,8 @@ namespace uniset
{ {
mbcrit << myname << "(execute_tcp): error run tcpserver: " mbcrit << myname << "(execute_tcp): error run tcpserver: "
<< tcpserver->getInetAddress() << tcpserver->getInetAddress()
<< ":" << tcpserver->getInetPort() << " err: not active.." << endl; << ":" << tcpserver->getInetPort() << " err: not active.."
<< endl << flush;
// std::terminate(); // std::terminate();
uterminate(); uterminate();
return; return;
...@@ -947,7 +948,7 @@ namespace uniset ...@@ -947,7 +948,7 @@ namespace uniset
{ {
if( iomap.empty() ) if( iomap.empty() )
{ {
mbcrit << myname << "(sysCommand): iomap EMPTY! terminated..." << endl; mbcrit << myname << "(sysCommand): iomap EMPTY! terminated..." << endl << flush;
// std::terminate(); // std::terminate();
uterminate(); uterminate();
return; return;
...@@ -1049,8 +1050,8 @@ namespace uniset ...@@ -1049,8 +1050,8 @@ namespace uniset
<< "(askSensors): Не дождались готовности(work) SharedMemory к работе в течение " << "(askSensors): Не дождались готовности(work) SharedMemory к работе в течение "
<< activateTimeout << " мсек"; << activateTimeout << " мсек";
mbcrit << err.str() << endl; mbcrit << err.str() << endl << flush;
kill(SIGTERM, getpid()); // прерываем (перезапускаем) процесс... uterminate();
throw SystemError(err.str()); throw SystemError(err.str());
} }
......
...@@ -77,7 +77,6 @@ int main(int argc, const char** argv) ...@@ -77,7 +77,6 @@ int main(int argc, const char** argv)
dlogany << "(main): -------------- MBSlave START -------------------------\n\n"; dlogany << "(main): -------------- MBSlave START -------------------------\n\n";
act->run(false); act->run(false);
// on_sigchild(SIGTERM);
return 0; return 0;
} }
catch( const std::exception& e ) catch( const std::exception& e )
...@@ -91,7 +90,6 @@ int main(int argc, const char** argv) ...@@ -91,7 +90,6 @@ int main(int argc, const char** argv)
cerr << (p ? p.__cxa_exception_type()->name() : "null") << std::endl; cerr << (p ? p.__cxa_exception_type()->name() : "null") << std::endl;
} }
// on_sigchild(SIGTERM);
return 1; return 1;
} }
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
...@@ -270,7 +270,7 @@ namespace uniset ...@@ -270,7 +270,7 @@ namespace uniset
if( !activated ) if( !activated )
{ {
smcrit << myname << "(sysCommand): Don`t activate [timeout=" << activateTimeout << " msec]! TERMINATE.." << endl; smcrit << myname << "(sysCommand): Don`t activate [timeout=" << activateTimeout << " msec]! TERMINATE.." << endl << flush;
// std::terminate(); // std::terminate();
uterminate(); uterminate();
return; return;
...@@ -463,9 +463,9 @@ namespace uniset ...@@ -463,9 +463,9 @@ namespace uniset
<< ") указан неверно (" << ") указан неверно ("
<< it.getProp("iotype") << ") должен быть 'AI'"; << it.getProp("iotype") << ") должен быть 'AI'";
smcrit << msg.str() << endl; smcrit << msg.str() << endl << flush;
kill(getpid(), SIGTERM); uterminate();
// throw NameNotFound(msg.str()); throw SystemError(msg.str());
}; };
HeartBeatInfo hi; HeartBeatInfo hi;
...@@ -478,7 +478,7 @@ namespace uniset ...@@ -478,7 +478,7 @@ namespace uniset
{ {
ostringstream msg; ostringstream msg;
msg << "(SharedMemory::readItem): дискретный датчик (heartbeat_ds_name) связанный с " << it.getProp("name"); msg << "(SharedMemory::readItem): дискретный датчик (heartbeat_ds_name) связанный с " << it.getProp("name");
smwarn << msg.str() << endl; smwarn << msg.str() << endl << flush;
} }
} }
else else
...@@ -492,9 +492,9 @@ namespace uniset ...@@ -492,9 +492,9 @@ namespace uniset
// Если уж задали имя для датчика, то он должен существовать.. // Если уж задали имя для датчика, то он должен существовать..
// поэтому завершаем процесс, если не нашли.. // поэтому завершаем процесс, если не нашли..
smcrit << msg.str() << endl; smcrit << msg.str() << endl << flush;
kill(getpid(), SIGTERM); uterminate();
// throw NameNotFound(msg.str()); throw SystemError(msg.str());
} }
} }
...@@ -507,9 +507,9 @@ namespace uniset ...@@ -507,9 +507,9 @@ namespace uniset
msg << "(SharedMemory::readItem): НЕ УКАЗАН id для " msg << "(SharedMemory::readItem): НЕ УКАЗАН id для "
<< it.getProp("name") << " секция " << sec; << it.getProp("name") << " секция " << sec;
smcrit << msg.str() << endl; smcrit << msg.str() << endl << flush;
kill(getpid(), SIGTERM); uterminate();
// throw NameNotFound(msg.str()); throw SystemError(msg.str());
}; };
// без проверки на дублирование т.к. // без проверки на дублирование т.к.
...@@ -912,7 +912,7 @@ namespace uniset ...@@ -912,7 +912,7 @@ namespace uniset
{ {
ostringstream err; ostringstream err;
err << myname << "(initFromReserv): Not found ID for '" << smName << "'"; err << myname << "(initFromReserv): Not found ID for '" << smName << "'";
smcrit << err.str() << endl; smcrit << err.str() << endl << flush;
// std::terminate(); // std::terminate();
uterminate(); uterminate();
return; return;
...@@ -929,7 +929,7 @@ namespace uniset ...@@ -929,7 +929,7 @@ namespace uniset
{ {
ostringstream err; ostringstream err;
err << myname << "(initFromReserv): Not found NodeID for '" << smNode << "'"; err << myname << "(initFromReserv): Not found NodeID for '" << smNode << "'";
smcrit << err.str() << endl; smcrit << err.str() << endl << flush;
//std::terminate(); //std::terminate();
uterminate(); uterminate();
return; return;
......
...@@ -6,7 +6,7 @@ ulimit -Sc 10000000000 ...@@ -6,7 +6,7 @@ ulimit -Sc 10000000000
./uniset2-start.sh -f ./uniset2-smemory --smemory-id SharedMemory \ ./uniset2-start.sh -f ./uniset2-smemory --smemory-id SharedMemory \
--confile test.xml --datfile test.xml --db-logging 1 --ulog-add-levels system,level1,level9 \ --confile test.xml --datfile test.xml --db-logging 1 --ulog-add-levels system,level1,level9 \
--sm-log-add-levels any $* --sm-run-logserver --activator-run-httpserver \ --heartbeat-node ses --sm-log-add-levels any $* --sm-run-logserver --activator-run-httpserver \
#--pulsar-id DO_C --pulsar-iotype DO --pulsar-msec 100 #--pulsar-id DO_C --pulsar-iotype DO --pulsar-msec 100
......
...@@ -712,8 +712,8 @@ void UNetExchange::askSensors( UniversalIO::UIOCommand cmd ) ...@@ -712,8 +712,8 @@ void UNetExchange::askSensors( UniversalIO::UIOCommand cmd )
<< "(askSensors): Не дождались готовности(work) SharedMemory к работе в течение " << "(askSensors): Не дождались готовности(work) SharedMemory к работе в течение "
<< activateTimeout << " мсек"; << activateTimeout << " мсек";
unetcrit << err.str() << endl; unetcrit << err.str() << endl << flush;
kill(SIGTERM, getpid()); // прерываем (перезапускаем) процесс... uterminate();
throw SystemError(err.str()); throw SystemError(err.str());
} }
......
...@@ -58,7 +58,6 @@ int main( int argc, const char** argv ) ...@@ -58,7 +58,6 @@ int main( int argc, const char** argv )
dlogany << "(main): -------------- UDPReceiver START -------------------------\n\n"; dlogany << "(main): -------------- UDPReceiver START -------------------------\n\n";
act->run(false); act->run(false);
on_sigchild(SIGTERM);
} }
catch( const uniset::Exception& ex ) catch( const uniset::Exception& ex )
{ {
...@@ -69,6 +68,5 @@ int main( int argc, const char** argv ) ...@@ -69,6 +68,5 @@ int main( int argc, const char** argv )
dcrit << "(unetexchange): catch ..." << std::endl; dcrit << "(unetexchange): catch ..." << std::endl;
} }
on_sigchild(SIGTERM);
return 0; return 0;
} }
...@@ -151,7 +151,7 @@ void UniExchange::execute() ...@@ -151,7 +151,7 @@ void UniExchange::execute()
err << myname << "(execute): Не дождались готовности SharedMemory к работе в течение " err << myname << "(execute): Не дождались готовности SharedMemory к работе в течение "
<< smReadyTimeout << " мсек"; << smReadyTimeout << " мсек";
ucrit << err.str() << endl; ucrit << err.str() << endl << flush;
//throw SystemError(err.str()); //throw SystemError(err.str());
//std::terminate(); //std::terminate();
uterminate(); uterminate();
...@@ -223,6 +223,9 @@ void UniExchange::execute() ...@@ -223,6 +223,9 @@ void UniExchange::execute()
ptUpdate.reset(); ptUpdate.reset();
} }
if( cancelled )
break;
msleep(polltime); msleep(polltime);
} }
} }
......
#!/bin/sh #!/bin/sh
export LD_LIBRARY_PATH="../../lib/.libs;../lib/.libs"
ulimit -Sc 10000000000 ulimit -Sc 10000000000
./uniset2-start.sh -f ./uniset2-network --confile test.xml \ ./uniset2-start.sh -f ./uniset2-network --confile test.xml \
--smemory-id SharedMemory \ --smemory-id SharedMemory \
--unet-id UniExchange --unet-id UniExchange $*
../../Utilities/scripts/uniset2-stop.sh
\ No newline at end of file
../../conf/test.xml
\ No newline at end of file
...@@ -68,7 +68,7 @@ int main(int argc, const char** argv) ...@@ -68,7 +68,7 @@ int main(int argc, const char** argv)
act->broadcast( sm.transport_msg() ); act->broadcast( sm.transport_msg() );
act->run(true); act->run(true);
uex->execute(); uex->execute();
on_sigchild(SIGTERM); act->join();
return 0; return 0;
} }
catch( const std::exception& ex ) catch( const std::exception& ex )
...@@ -80,6 +80,5 @@ int main(int argc, const char** argv) ...@@ -80,6 +80,5 @@ int main(int argc, const char** argv)
dcrit << "(uninetwork): catch(...)" << endl; dcrit << "(uninetwork): catch(...)" << endl;
} }
on_sigchild(SIGTERM);
return 1; return 1;
} }
../../Utilities/scripts/uniset2-functions.sh
\ No newline at end of file
../../Utilities/scripts/uniset2-start.sh
\ No newline at end of file
...@@ -97,7 +97,7 @@ namespace uniset ...@@ -97,7 +97,7 @@ namespace uniset
typedef void(ThreadMaster::* Action)(); typedef void(ThreadMaster::* Action)();
OmniThreadCreator( const std::shared_ptr<ThreadMaster>& m, Action a, bool undetached = false ); OmniThreadCreator( const std::shared_ptr<ThreadMaster>& m, Action a, bool undetached = false );
~OmniThreadCreator() {} virtual ~OmniThreadCreator() {}
inline bool isRunning() inline bool isRunning()
{ {
......
...@@ -72,11 +72,15 @@ namespace uniset ...@@ -72,11 +72,15 @@ namespace uniset
// запуск системы // запуск системы
// async = true - асинхронный запуск (создаётся отдельный поток). // async = true - асинхронный запуск (создаётся отдельный поток).
void run( bool async ); // terminate_control = true - управление процессом завершения (обработка сигналов завершения)
void run( bool async, bool terminate_control = true );
// штатное завершение работы // штатное завершение работы
void shutdown(); void shutdown();
// ожидание завершения (если был запуск run(true))
void join();
// прерывание работы // прерывание работы
void terminate(); void terminate();
...@@ -96,7 +100,7 @@ namespace uniset ...@@ -96,7 +100,7 @@ namespace uniset
protected: protected:
void work(); void mainWork();
// уносим в protected, т.к. Activator должен быть только один.. // уносим в protected, т.к. Activator должен быть только один..
UniSetActivator(); UniSetActivator();
...@@ -111,6 +115,7 @@ namespace uniset ...@@ -111,6 +115,7 @@ namespace uniset
std::shared_ptr< OmniThreadCreator<UniSetActivator> > orbthr; std::shared_ptr< OmniThreadCreator<UniSetActivator> > orbthr;
CORBA::ORB_var orb; CORBA::ORB_var orb;
bool termControl = { true };
#ifndef DISABLE_REST_API #ifndef DISABLE_REST_API
std::shared_ptr<uniset::UHttp::UHttpServer> httpserv; std::shared_ptr<uniset::UHttp::UHttpServer> httpserv;
......
...@@ -58,7 +58,7 @@ namespace uniset ...@@ -58,7 +58,7 @@ namespace uniset
bool findName( const std::string& node, const std::string& searchname, bool deepfind = true ) noexcept; bool findName( const std::string& node, const std::string& searchname, bool deepfind = true ) noexcept;
bool find( const std::string& searchnode, bool deepfind = true) noexcept; bool find( const std::string& searchnode, bool deepfind = true) noexcept;
xmlNode* findX( xmlNode* root, const std::string& searchnode, bool deepfind = true ) noexcept; xmlNode* findX( xmlNode* root, const std::string& searchnode, bool deepfind = true ) const noexcept;
/*! Перейти к следующему узлу. Возвращает false, если некуда перейти */ /*! Перейти к следующему узлу. Возвращает false, если некуда перейти */
bool goNext() noexcept; bool goNext() noexcept;
...@@ -159,9 +159,12 @@ namespace uniset ...@@ -159,9 +159,12 @@ namespace uniset
// Добавить новый дочерний узел // Добавить новый дочерний узел
static xmlNode* createChild(xmlNode* node, const std::string& title, const std::string& text); static xmlNode* createChild(xmlNode* node, const std::string& title, const std::string& text);
// Добавить следующий узел // Добавить следующий узел (добавление в конец списка узлов на уровне node)
static xmlNode* createNext(xmlNode* node, const std::string& title, const std::string& text); static xmlNode* createNext(xmlNode* node, const std::string& title, const std::string& text);
// Создать новый узел следующим за node
static xmlNode* insertNext(xmlNode* node, const std::string& title, const std::string& text);
// Удалить указанный узел и все вложенные узлы // Удалить указанный узел и все вложенные узлы
static void removeNode(xmlNode* node); static void removeNode(xmlNode* node);
...@@ -187,7 +190,7 @@ namespace uniset ...@@ -187,7 +190,7 @@ namespace uniset
// Функция поиска по текущему уровню (без рекурсии для дочерних узлов) // Функция поиска по текущему уровню (без рекурсии для дочерних узлов)
// root указывается исходный, внутри функции осуществляется переход к списку дочерних узлов // root указывается исходный, внутри функции осуществляется переход к списку дочерних узлов
// (другими словами делать goChildren() не надо) // (другими словами делать goChildren() не надо)
xmlNode* findNodeLevel1( xmlNode* root, const std::string& nodename, const std::string& nm = "" ); xmlNode* findNodeLevel1( xmlNode* root, const std::string& nodename, const std::string& nm = "" ) const;
protected: protected:
......
...@@ -54,6 +54,14 @@ static std::atomic_bool g_done = ATOMIC_VAR_INIT(0); ...@@ -54,6 +54,14 @@ static std::atomic_bool g_done = ATOMIC_VAR_INIT(0);
static const int TERMINATE_TIMEOUT_SEC = 15; // время отведенное на завершение процесса [сек] static const int TERMINATE_TIMEOUT_SEC = 15; // время отведенное на завершение процесса [сек]
// ------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------
struct ORBThreadDeleter
{
void operator()( OmniThreadCreator<UniSetActivator>* p ) const
{
// не удаляем..
}
};
// ---------------------------------------------------------------------------
namespace uniset namespace uniset
{ {
UniSetActivatorPtr UniSetActivator::inst; UniSetActivatorPtr UniSetActivator::inst;
...@@ -126,10 +134,11 @@ namespace uniset ...@@ -126,10 +134,11 @@ namespace uniset
} }
// ------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------
void UniSetActivator::run( bool thread ) void UniSetActivator::run( bool thread, bool terminate_control )
{ {
ulogsys << myname << "(run): создаю менеджер " << endl; ulogsys << myname << "(run): создаю менеджер " << endl;
termControl = terminate_control;
auto aptr = std::static_pointer_cast<UniSetActivator>(get_ptr()); auto aptr = std::static_pointer_cast<UniSetActivator>(get_ptr());
UniSetManager::initPOA(aptr); UniSetManager::initPOA(aptr);
...@@ -144,6 +153,7 @@ namespace uniset ...@@ -144,6 +153,7 @@ namespace uniset
pman->activate(); pman->activate();
msleep(50); msleep(50);
if( termControl )
set_signals(true); set_signals(true);
#ifndef DISABLE_REST_API #ifndef DISABLE_REST_API
...@@ -168,13 +178,13 @@ namespace uniset ...@@ -168,13 +178,13 @@ namespace uniset
if( thread ) if( thread )
{ {
uinfo << myname << "(run): запускаемся с созданием отдельного потока... " << endl; uinfo << myname << "(run): запускаемся с созданием отдельного потока... " << endl;
orbthr = make_shared< OmniThreadCreator<UniSetActivator> >( aptr, &UniSetActivator::work); orbthr = std::shared_ptr<OmniThreadCreator<UniSetActivator>>(new OmniThreadCreator<UniSetActivator>(aptr, &UniSetActivator::mainWork), ORBThreadDeleter());
orbthr->start(); orbthr->start();
} }
else else
{ {
uinfo << myname << "(run): запускаемся без создания отдельного потока... " << endl; uinfo << myname << "(run): запускаемся без создания отдельного потока... " << endl;
work(); mainWork();
shutdown(); shutdown();
} }
} }
...@@ -189,14 +199,15 @@ namespace uniset ...@@ -189,14 +199,15 @@ namespace uniset
return; return;
active = false; active = false;
if( termControl )
{
set_signals(false); set_signals(false);
{ {
std::unique_lock<std::mutex> lk(g_donemutex); std::unique_lock<std::mutex> lk(g_donemutex);
g_done = false; g_done = false;
g_finish_guard_thread = make_shared<std::thread>(on_finish_timeout); g_finish_guard_thread = make_shared<std::thread>(on_finish_timeout);
} }
}
ulogsys << myname << "(shutdown): deactivate... " << endl; ulogsys << myname << "(shutdown): deactivate... " << endl;
deactivate(); deactivate();
...@@ -238,9 +249,6 @@ namespace uniset ...@@ -238,9 +249,6 @@ namespace uniset
ucrit << myname << "(shutdown): " << ex.what() << endl; ucrit << myname << "(shutdown): " << ex.what() << endl;
} }
if( orbthr )
orbthr->join();
{ {
std::unique_lock<std::mutex> lk(g_donemutex); std::unique_lock<std::mutex> lk(g_donemutex);
g_done = true; g_done = true;
...@@ -252,6 +260,20 @@ namespace uniset ...@@ -252,6 +260,20 @@ namespace uniset
g_finish_guard_thread->join(); g_finish_guard_thread->join();
} }
// ------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------
void UniSetActivator::join()
{
if( g_done )
return;
ulogsys << myname << "(join): ..." << endl;
std::unique_lock<std::mutex> lk(g_donemutex);
g_doneevent.wait(lk, []()
{
return (g_done == true);
} );
}
// ------------------------------------------------------------------------------------------
void UniSetActivator::terminate() void UniSetActivator::terminate()
{ {
ulogsys << myname << "(terminate): ..." << endl; ulogsys << myname << "(terminate): ..." << endl;
...@@ -262,6 +284,7 @@ namespace uniset ...@@ -262,6 +284,7 @@ namespace uniset
{ {
auto act = UniSetActivator::Instance(); auto act = UniSetActivator::Instance();
act->shutdown(); act->shutdown();
ulogsys << "******** activator_terminate finished **** " << endl;
} }
// ------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------
void UniSetActivator::on_finish_timeout() void UniSetActivator::on_finish_timeout()
...@@ -340,7 +363,7 @@ namespace uniset ...@@ -340,7 +363,7 @@ namespace uniset
// sigaction(SIGSEGV, &act, &oact); // sigaction(SIGSEGV, &act, &oact);
} }
// ------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------
void UniSetActivator::work() void UniSetActivator::mainWork()
{ {
ulogsys << myname << "(work): запускаем orb на обработку запросов..." << endl; ulogsys << myname << "(work): запускаем orb на обработку запросов..." << endl;
......
...@@ -760,9 +760,14 @@ namespace uniset ...@@ -760,9 +760,14 @@ namespace uniset
} }
else else
{ {
// выдаём предупреждение только если поток не отключён, но при этом не задан ID
if( threadcreate )
{
uinfo << myname << ": ?? не задан ObjectId...(" uinfo << myname << ": ?? не задан ObjectId...("
<< "myid=" << myid << " threadcreate=" << threadcreate << "myid=" << myid << " threadcreate=" << threadcreate
<< ")" << endl; << ")" << endl;
}
thread(false); thread(false);
} }
......
...@@ -171,6 +171,8 @@ std::ostream& DebugStream::printDate(Debug::type t, char brk) noexcept ...@@ -171,6 +171,8 @@ std::ostream& DebugStream::printDate(Debug::type t, char brk) noexcept
{ {
if(dt && t) if(dt && t)
{ {
uniset::ios_fmt_restorer ifs(*this);
std::time_t tv = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now()); std::time_t tv = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
std::tm tms = *std::localtime(&tv); std::tm tms = *std::localtime(&tv);
......
...@@ -123,7 +123,7 @@ void IOController::activateInit() ...@@ -123,7 +123,7 @@ void IOController::activateInit()
} }
catch( const uniset::Exception& ex ) catch( const uniset::Exception& ex )
{ {
ucrit << myname << "(activateInit): " << ex << endl; ucrit << myname << "(activateInit): " << ex << endl << flush;
//std::terminate(); //std::terminate();
uterminate(); uterminate();
} }
......
...@@ -772,7 +772,7 @@ void IONotifyController::readConf() ...@@ -772,7 +772,7 @@ void IONotifyController::readConf()
// Если дамп не удалось считать, значит что-то не то в configure.xml // Если дамп не удалось считать, значит что-то не то в configure.xml
// и безопаснее "вылететь", чем запустится, т.к. часть датчиков не будет работать // и безопаснее "вылететь", чем запустится, т.к. часть датчиков не будет работать
// как ожидается. // как ожидается.
ucrit << myname << "(IONotifyController::readConf): " << ex.what() << endl; ucrit << myname << "(IONotifyController::readConf): " << ex.what() << endl << flush;
//std::terminate(); // std::abort(); //std::terminate(); // std::abort();
uterminate(); uterminate();
} }
......
...@@ -106,7 +106,7 @@ bool ProxyManager::activateObject() ...@@ -106,7 +106,7 @@ bool ProxyManager::activateObject()
} }
catch( const uniset::Exception& ex ) catch( const uniset::Exception& ex )
{ {
ucrit << myname << "(activate): " << ex << endl; ucrit << myname << "(activate): " << ex << endl << flush;
//std::terminate(); //std::terminate();
uterminate(); uterminate();
} }
......
...@@ -159,10 +159,7 @@ string UniXML::getProp(const xmlNode* node, const string& name) noexcept ...@@ -159,10 +159,7 @@ string UniXML::getProp(const xmlNode* node, const string& name) noexcept
xmlChar* text = ::xmlGetProp((xmlNode*)node, (const xmlChar*)name.c_str()); xmlChar* text = ::xmlGetProp((xmlNode*)node, (const xmlChar*)name.c_str());
if( text == NULL ) if( text == NULL )
{
xmlFree(text);
return ""; return "";
}
try try
{ {
...@@ -224,7 +221,7 @@ xmlNode* UniXML::createChild(xmlNode* node, const string& title, const string& t ...@@ -224,7 +221,7 @@ xmlNode* UniXML::createChild(xmlNode* node, const string& title, const string& t
return ::xmlNewChild(node, NULL, (const xmlChar*)title.c_str(), (const xmlChar*)text.c_str()); return ::xmlNewChild(node, NULL, (const xmlChar*)title.c_str(), (const xmlChar*)text.c_str());
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
xmlNode* UniXML::createNext(xmlNode* node, const string& title, const string& text) xmlNode* UniXML::createNext( xmlNode* node, const string& title, const string& text )
{ {
if( node->parent ) if( node->parent )
return createChild(node->parent, title, text); return createChild(node->parent, title, text);
...@@ -232,6 +229,15 @@ xmlNode* UniXML::createNext(xmlNode* node, const string& title, const string& te ...@@ -232,6 +229,15 @@ xmlNode* UniXML::createNext(xmlNode* node, const string& title, const string& te
return 0; return 0;
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
xmlNode* UniXML::insertNext( xmlNode* node, const string& title, const string& text )
{
xmlNode* newNode = createNext(node,title,text);
if( newNode )
return ::xmlAddNextSibling(node,newNode);
return 0;
}
// -----------------------------------------------------------------------------
/// Удаление указанного узла со всеми вложенными /// Удаление указанного узла со всеми вложенными
void UniXML::removeNode(xmlNode* node) void UniXML::removeNode(xmlNode* node)
{ {
...@@ -379,7 +385,7 @@ xmlNode* UniXML::extFindNode( xmlNode* node, int depth, int width, const string& ...@@ -379,7 +385,7 @@ xmlNode* UniXML::extFindNode( xmlNode* node, int depth, int width, const string&
return NULL; return NULL;
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
xmlNode* UniXML::findNodeLevel1( xmlNode* root, const string& nodename, const string& nm ) xmlNode* UniXML::findNodeLevel1( xmlNode* root, const string& nodename, const string& nm ) const
{ {
UniXML::iterator it(root); UniXML::iterator it(root);
...@@ -628,7 +634,7 @@ bool UniXML_iterator::find( const std::string& searchnode, bool deepfind ) noexc ...@@ -628,7 +634,7 @@ bool UniXML_iterator::find( const std::string& searchnode, bool deepfind ) noexc
return false; return false;
} }
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
xmlNode* UniXML_iterator::findX( xmlNode* root, const std::string& searchnode, bool deepfind ) noexcept xmlNode* UniXML_iterator::findX( xmlNode* root, const std::string& searchnode, bool deepfind ) const noexcept
{ {
if( root == NULL ) if( root == NULL )
return NULL; return NULL;
......
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