summaryrefslogtreecommitdiff
path: root/src/appMain/life_cycle.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/appMain/life_cycle.cc')
-rw-r--r--src/appMain/life_cycle.cc60
1 files changed, 41 insertions, 19 deletions
diff --git a/src/appMain/life_cycle.cc b/src/appMain/life_cycle.cc
index 8d4926510..ca629e231 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,12 @@ 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(),
+ profile::Profile::instance()->malformed_message_filtering(),
+ profile::Profile::instance()->malformed_frequency_time(),
+ profile::Profile::instance()->malformed_frequency_count());
DCHECK(protocol_handler_ != NULL);
connection_handler_ =
@@ -336,27 +343,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 +383,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();
@@ -421,13 +440,16 @@ void LifeCycle::StopComponents() {
#endif // DBUS_HMIADAPTER
#ifdef MESSAGEBROKER_HMIADAPTER
hmi_handler_->RemoveHMIMessageAdapter(mb_adapter_);
- hmi_message_handler::HMIMessageHandlerImpl::destroy();
if (mb_adapter_) {
mb_adapter_->unregisterController();
mb_adapter_->Close();
mb_adapter_->exitReceivingThread();
+ if (mb_adapter_thread_) {
+ mb_adapter_thread_->Join();
+ }
delete mb_adapter_;
}
+ hmi_message_handler::HMIMessageHandlerImpl::destroy();
if (mb_adapter_thread_) {
mb_adapter_thread_->Stop();
delete mb_adapter_thread_;