diff options
Diffstat (limited to 'src/appMain/life_cycle.cc')
-rw-r--r-- | src/appMain/life_cycle.cc | 55 |
1 files changed, 37 insertions, 18 deletions
diff --git a/src/appMain/life_cycle.cc b/src/appMain/life_cycle.cc index 8d4926510b..2769d19417 100644 --- a/src/appMain/life_cycle.cc +++ b/src/appMain/life_cycle.cc @@ -40,7 +40,9 @@ #include "security_manager/crypto_manager_impl.h" #endif // ENABLE_SECURITY -#include "utils/threads/thread_manager.h" +#ifdef ENABLE_LOG +#include "utils/log_message_loop_thread.h" +#endif using threads::Thread; @@ -51,7 +53,7 @@ CREATE_LOGGERPTR_GLOBAL(logger_, "appMain") namespace { void NameMessageBrokerThread(const System::Thread& thread, const std::string& name) { - Thread::SetNameForId(Thread::Id(thread.GetId()), name); + Thread::SetNameForId(thread.GetId(), name); } } // namespace @@ -92,7 +94,9 @@ bool LifeCycle::StartComponents() { DCHECK(transport_manager_ != NULL); protocol_handler_ = - new protocol_handler::ProtocolHandlerImpl(transport_manager_); + new protocol_handler::ProtocolHandlerImpl(transport_manager_, + profile::Profile::instance()->message_frequency_time(), + profile::Profile::instance()->message_frequency_count()); DCHECK(protocol_handler_ != NULL); connection_handler_ = @@ -336,27 +340,35 @@ bool LifeCycle::InitMessageSystem() { #endif // MQUEUE_HMIADAPTER namespace { + void sig_handler(int sig) { - MessageQueue<threads::ThreadManager::ThreadDesc>& threads = ::threads::ThreadManager::instance()->threads_to_terminate; - threads.Shutdown(); + // Do nothing } -} + + void agony(int sig) { +// these actions are not signal safe +// (in case logger is on) +// but they cannot be moved to a separate thread +// because the application most probably will crash as soon as this handler returns +// +// the application is anyway about to crash + LOG4CXX_FATAL(logger_, "Stopping application due to segmentation fault"); +#ifdef ENABLE_LOG + logger::LogMessageLoopThread::destroy(); +#endif + } + +} // namespace void LifeCycle::Run() { - // First, register signal handler + // First, register signal handlers ::utils::SubscribeToTerminateSignal(&sig_handler); - // Then run main loop until signal caught - MessageQueue<threads::ThreadManager::ThreadDesc>& threads = ::threads::ThreadManager::instance()->threads_to_terminate; - while(!threads.IsShuttingDown()) { - while (!threads.empty()) { - ::threads::ThreadManager::ThreadDesc desc = threads.pop(); - pthread_join(desc.handle, NULL); - delete desc.delegate; - } - threads.wait(); - } + ::utils::SubscribeToFaultSignal(&agony); + // Now wait for any signal + pause(); } + void LifeCycle::StopComponents() { if (!components_started_) { LOG4CXX_TRACE(logger_, "exit"); @@ -368,15 +380,19 @@ void LifeCycle::StopComponents() { protocol_handler_->RemoveProtocolObserver(app_manager_); app_manager_->Stop(); - LOG4CXX_INFO(logger_, "Destroying Media Manager"); + LOG4CXX_INFO(logger_, "Stopping Protocol Handler"); protocol_handler_->RemoveProtocolObserver(media_manager_); #ifdef ENABLE_SECURITY protocol_handler_->RemoveProtocolObserver(security_manager_); #endif // ENABLE_SECURITY + protocol_handler_->Stop(); + + LOG4CXX_INFO(logger_, "Destroying Media Manager"); media_manager_->SetProtocolHandler(NULL); media_manager::MediaManagerImpl::destroy(); LOG4CXX_INFO(logger_, "Destroying Transport Manager."); + transport_manager_->Visibility(false); transport_manager_->Stop(); transport_manager::TransportManagerDefault::destroy(); @@ -426,6 +442,9 @@ void LifeCycle::StopComponents() { mb_adapter_->unregisterController(); mb_adapter_->Close(); mb_adapter_->exitReceivingThread(); + if (mb_adapter_thread_) { + mb_adapter_thread_->Join(); + } delete mb_adapter_; } if (mb_adapter_thread_) { |