summaryrefslogtreecommitdiff
path: root/src/appMain/life_cycle.cc
diff options
context:
space:
mode:
authorAnton Hrytsevich <ahrytsevich>2016-01-25 17:01:36 +0200
committerAnton Hrytsevich <ahrytsevich>2016-01-25 17:01:36 +0200
commit51873ff94fb9459754f4ad8f1ad03a43f473b3fd (patch)
tree39cc057c598f09871a4961d0a8781fb7a22851ab /src/appMain/life_cycle.cc
parentefdef7c9f294da3462b021ef8c71f2b1581e7ec7 (diff)
downloadsdl_core-51873ff94fb9459754f4ad8f1ad03a43f473b3fd.tar.gz
Fix style issues by beautifier
Diffstat (limited to 'src/appMain/life_cycle.cc')
-rw-r--r--src/appMain/life_cycle.cc254
1 files changed, 134 insertions, 120 deletions
diff --git a/src/appMain/life_cycle.cc b/src/appMain/life_cycle.cc
index 538a3b34f5..15a78ff40c 100644
--- a/src/appMain/life_cycle.cc
+++ b/src/appMain/life_cycle.cc
@@ -59,64 +59,61 @@ void NameMessageBrokerThread(const System::Thread& thread,
} // namespace
LifeCycle::LifeCycle()
- : transport_manager_(NULL)
- , protocol_handler_(NULL)
- , connection_handler_(NULL)
- , app_manager_(NULL)
+ : transport_manager_(NULL)
+ , protocol_handler_(NULL)
+ , connection_handler_(NULL)
+ , app_manager_(NULL)
#ifdef ENABLE_SECURITY
- , crypto_manager_(NULL)
- , security_manager_(NULL)
+ , crypto_manager_(NULL)
+ , security_manager_(NULL)
#endif // ENABLE_SECURITY
- , hmi_handler_(NULL)
- , hmi_message_adapter_(NULL)
- , media_manager_(NULL)
+ , hmi_handler_(NULL)
+ , hmi_message_adapter_(NULL)
+ , media_manager_(NULL)
#ifdef TIME_TESTER
- , time_tester_(NULL)
+ , time_tester_(NULL)
#endif // TIME_TESTER
#ifdef DBUS_HMIADAPTER
- , dbus_adapter_(NULL)
- , dbus_adapter_thread_(NULL)
+ , dbus_adapter_(NULL)
+ , dbus_adapter_thread_(NULL)
#endif // DBUS_HMIADAPTER
#ifdef MESSAGEBROKER_HMIADAPTER
- , mb_adapter_(NULL)
- , message_broker_(NULL)
- , message_broker_server_(NULL)
- , mb_thread_(NULL)
- , mb_server_thread_(NULL)
- , mb_adapter_thread_(NULL)
+ , mb_adapter_(NULL)
+ , message_broker_(NULL)
+ , message_broker_server_(NULL)
+ , mb_thread_(NULL)
+ , mb_server_thread_(NULL)
+ , mb_adapter_thread_(NULL)
#endif // MESSAGEBROKER_HMIADAPTER
-{ }
+{
+}
bool LifeCycle::StartComponents() {
LOG4CXX_AUTO_TRACE(logger_);
- transport_manager_ =
- transport_manager::TransportManagerDefault::instance();
+ transport_manager_ = transport_manager::TransportManagerDefault::instance();
DCHECK(transport_manager_ != NULL);
- protocol_handler_ =
- 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(),
- profile::Profile::instance()->multiframe_waiting_timeout());
+ protocol_handler_ = 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(),
+ profile::Profile::instance()->multiframe_waiting_timeout());
DCHECK(protocol_handler_ != NULL);
- connection_handler_ =
- connection_handler::ConnectionHandlerImpl::instance();
+ connection_handler_ = connection_handler::ConnectionHandlerImpl::instance();
DCHECK(connection_handler_ != NULL);
- app_manager_ =
- application_manager::ApplicationManagerImpl::instance();
+ app_manager_ = application_manager::ApplicationManagerImpl::instance();
DCHECK(app_manager_ != NULL);
if (!app_manager_->Init()) {
LOG4CXX_ERROR(logger_, "Application manager init failed.");
return false;
}
- hmi_handler_ =
- hmi_message_handler::HMIMessageHandlerImpl::instance();
+ hmi_handler_ = hmi_message_handler::HMIMessageHandlerImpl::instance();
DCHECK(hmi_handler_ != NULL)
#ifdef ENABLE_SECURITY
@@ -125,29 +122,46 @@ bool LifeCycle::StartComponents() {
// FIXME(EZamakhov): move to Config or in Sm initialization method
std::string cert_filename;
profile::Profile::instance()->ReadStringValue(
- &cert_filename, "",
- security_manager::SecurityManagerImpl::ConfigSection(), "CertificatePath");
+ &cert_filename,
+ "",
+ security_manager::SecurityManagerImpl::ConfigSection(),
+ "CertificatePath");
std::string ssl_mode;
profile::Profile::instance()->ReadStringValue(
- &ssl_mode, "CLIENT", security_manager::SecurityManagerImpl::ConfigSection(), "SSLMode");
+ &ssl_mode,
+ "CLIENT",
+ security_manager::SecurityManagerImpl::ConfigSection(),
+ "SSLMode");
crypto_manager_ = new security_manager::CryptoManagerImpl();
std::string key_filename;
profile::Profile::instance()->ReadStringValue(
- &key_filename, "", security_manager::SecurityManagerImpl::ConfigSection(), "KeyPath");
+ &key_filename,
+ "",
+ security_manager::SecurityManagerImpl::ConfigSection(),
+ "KeyPath");
std::string ciphers_list;
profile::Profile::instance()->ReadStringValue(
- &ciphers_list, SSL_TXT_ALL, security_manager::SecurityManagerImpl::ConfigSection(), "CipherList");
+ &ciphers_list,
+ SSL_TXT_ALL,
+ security_manager::SecurityManagerImpl::ConfigSection(),
+ "CipherList");
bool verify_peer;
profile::Profile::instance()->ReadBoolValue(
- &verify_peer, false, security_manager::SecurityManagerImpl::ConfigSection(), "VerifyPeer");
+ &verify_peer,
+ false,
+ security_manager::SecurityManagerImpl::ConfigSection(),
+ "VerifyPeer");
std::string protocol_name;
profile::Profile::instance()->ReadStringValue(
- &protocol_name, "TLSv1.2", security_manager::SecurityManagerImpl::ConfigSection(), "Protocol");
+ &protocol_name,
+ "TLSv1.2",
+ security_manager::SecurityManagerImpl::ConfigSection(),
+ "Protocol");
security_manager::Protocol protocol;
if (protocol_name == "TLSv1.0") {
@@ -164,14 +178,14 @@ bool LifeCycle::StartComponents() {
}
if (!crypto_manager_->Init(
- ssl_mode == "SERVER" ? security_manager::SERVER : security_manager::CLIENT,
- protocol,
- policy::PolicyHandler::instance()->RetrieveCertificate(),
- profile::Profile::instance()->ciphers_list(),
- profile::Profile::instance()->verify_peer(),
- profile::Profile::instance()->ca_cert_path(),
- profile::Profile::instance()->update_before_hours())
- ) {
+ ssl_mode == "SERVER" ? security_manager::SERVER
+ : security_manager::CLIENT,
+ protocol,
+ policy::PolicyHandler::instance()->RetrieveCertificate(),
+ profile::Profile::instance()->ciphers_list(),
+ profile::Profile::instance()->verify_peer(),
+ profile::Profile::instance()->ca_cert_path(),
+ profile::Profile::instance()->update_before_hours())) {
LOG4CXX_ERROR(logger_, "CryptoManager initialization fail.");
return false;
}
@@ -197,7 +211,7 @@ bool LifeCycle::StartComponents() {
connection_handler_->set_protocol_handler(protocol_handler_);
connection_handler_->set_connection_handler_observer(app_manager_);
- // it is important to initialise TimeTester before TM to listen TM Adapters
+// it is important to initialise TimeTester before TM to listen TM Adapters
#ifdef TIME_TESTER
time_tester_ = new time_tester::TimeManager();
time_tester_->Start();
@@ -226,18 +240,16 @@ bool LifeCycle::StartComponents() {
#ifdef MESSAGEBROKER_HMIADAPTER
bool LifeCycle::InitMessageSystem() {
- message_broker_ =
- NsMessageBroker::CMessageBroker::getInstance();
+ message_broker_ = NsMessageBroker::CMessageBroker::getInstance();
if (!message_broker_) {
LOG4CXX_FATAL(logger_, " Wrong pMessageBroker pointer!");
return false;
}
- message_broker_server_ =
- new NsMessageBroker::TcpServer(
- profile::Profile::instance()->server_address(),
- profile::Profile::instance()->server_port(),
- message_broker_);
+ message_broker_server_ = new NsMessageBroker::TcpServer(
+ profile::Profile::instance()->server_address(),
+ profile::Profile::instance()->server_port(),
+ message_broker_);
if (!message_broker_server_) {
LOG4CXX_FATAL(logger_, " Wrong pJSONRPC20Server pointer!");
return false;
@@ -262,43 +274,45 @@ bool LifeCycle::InitMessageSystem() {
LOG4CXX_INFO(logger_, " Message broker server listen successful!");
}
- mb_adapter_ =
- new hmi_message_handler::MessageBrokerAdapter(
- hmi_message_handler::HMIMessageHandlerImpl::instance(),
- profile::Profile::instance()->server_address(),
- profile::Profile::instance()->server_port());
-
- hmi_message_handler::HMIMessageHandlerImpl::instance()->AddHMIMessageAdapter(
- mb_adapter_);
- if (!mb_adapter_->Connect()) {
- LOG4CXX_FATAL(logger_, "Cannot connect to remote peer!");
- return false;
- }
+ mb_adapter_ = new hmi_message_handler::MessageBrokerAdapter(
+ hmi_message_handler::HMIMessageHandlerImpl::instance(),
+ profile::Profile::instance()->server_address(),
+ profile::Profile::instance()->server_port());
+
+ hmi_message_handler::HMIMessageHandlerImpl::instance()->AddHMIMessageAdapter(
+ mb_adapter_);
+ if (!mb_adapter_->Connect()) {
+ LOG4CXX_FATAL(logger_, "Cannot connect to remote peer!");
+ return false;
+ }
LOG4CXX_INFO(logger_, "Start CMessageBroker thread!");
mb_thread_ = new System::Thread(
- new System::ThreadArgImpl<NsMessageBroker::CMessageBroker>(
- *message_broker_, &NsMessageBroker::CMessageBroker::MethodForThread,
- NULL));
+ new System::ThreadArgImpl<NsMessageBroker::CMessageBroker>(
+ *message_broker_,
+ &NsMessageBroker::CMessageBroker::MethodForThread,
+ NULL));
mb_thread_->Start(false);
// Thread can be named only when started because before that point
// thread doesn't have valid Id to associate name with
NameMessageBrokerThread(*mb_thread_, "MessageBroker");
LOG4CXX_INFO(logger_, "Start MessageBroker TCP server thread!");
- mb_server_thread_ = new System::Thread(
- new System::ThreadArgImpl<NsMessageBroker::TcpServer>(
- *message_broker_server_, &NsMessageBroker::TcpServer::MethodForThread,
- NULL));
+ mb_server_thread_ =
+ new System::Thread(new System::ThreadArgImpl<NsMessageBroker::TcpServer>(
+ *message_broker_server_,
+ &NsMessageBroker::TcpServer::MethodForThread,
+ NULL));
mb_server_thread_->Start(false);
NameMessageBrokerThread(*mb_server_thread_, "MB TCPServer");
LOG4CXX_INFO(logger_, "StartAppMgr JSONRPC 2.0 controller receiver thread!");
- mb_adapter_thread_ = new System::Thread(
- new System::ThreadArgImpl<hmi_message_handler::MessageBrokerAdapter>(
- *mb_adapter_,
- &hmi_message_handler::MessageBrokerAdapter::SubscribeAndBeginReceiverThread,
- NULL));
+ mb_adapter_thread_ = new System::Thread(
+ new System::ThreadArgImpl<hmi_message_handler::MessageBrokerAdapter>(
+ *mb_adapter_,
+ &hmi_message_handler::MessageBrokerAdapter::
+ SubscribeAndBeginReceiverThread,
+ NULL));
mb_adapter_thread_->Start(false);
NameMessageBrokerThread(*mb_adapter_thread_, "MB Adapter");
@@ -313,10 +327,10 @@ bool LifeCycle::InitMessageSystem() {
*/
bool LifeCycle::InitMessageSystem() {
dbus_adapter_ = new hmi_message_handler::DBusMessageAdapter(
- hmi_message_handler::HMIMessageHandlerImpl::instance());
+ hmi_message_handler::HMIMessageHandlerImpl::instance());
hmi_message_handler::HMIMessageHandlerImpl::instance()->AddHMIMessageAdapter(
- dbus_adapter_);
+ dbus_adapter_);
if (!dbus_adapter_->Init()) {
LOG4CXX_FATAL(logger_, "Cannot init DBus service!");
return false;
@@ -326,10 +340,10 @@ bool LifeCycle::InitMessageSystem() {
LOG4CXX_INFO(logger_, "Start DBusMessageAdapter thread!");
dbus_adapter_thread_ = new System::Thread(
- new System::ThreadArgImpl<hmi_message_handler::DBusMessageAdapter>(
- *dbus_adapter_,
- &hmi_message_handler::DBusMessageAdapter::MethodForReceiverThread,
- NULL));
+ new System::ThreadArgImpl<hmi_message_handler::DBusMessageAdapter>(
+ *dbus_adapter_,
+ &hmi_message_handler::DBusMessageAdapter::MethodForReceiverThread,
+ NULL));
dbus_adapter_thread_->Start(false);
return true;
@@ -339,64 +353,64 @@ bool LifeCycle::InitMessageSystem() {
#ifdef MQUEUE_HMIADAPTER
bool LifeCycle::InitMessageSystem() {
hmi_message_adapter_ = new hmi_message_handler::MqueueAdapter(
- hmi_message_handler::HMIMessageHandlerImpl::instance());
+ hmi_message_handler::HMIMessageHandlerImpl::instance());
hmi_message_handler::HMIMessageHandlerImpl::instance()->AddHMIMessageAdapter(
- hmi_message_adapter_);
+ hmi_message_adapter_);
return true;
}
#endif // MQUEUE_HMIADAPTER
namespace {
- pthread_t main_thread;
- void sig_handler(int sig) {
- switch(sig) {
- case SIGINT:
- LOG4CXX_DEBUG(logger_, "SIGINT signal has been caught");
- break;
- case SIGTERM:
- LOG4CXX_DEBUG(logger_, "SIGTERM signal has been caught");
- break;
- case SIGSEGV:
- LOG4CXX_DEBUG(logger_, "SIGSEGV signal has been caught");
- break;
- default:
- LOG4CXX_DEBUG(logger_, "Unexpected signal has been caught");
- break;
- }
- /*
- * Resend signal to the main thread in case it was
- * caught by another thread
- */
- if(pthread_equal(pthread_self(), main_thread) == 0) {
- LOG4CXX_DEBUG(logger_, "Resend signal to the main thread");
- if(pthread_kill(main_thread, sig) != 0) {
- LOG4CXX_FATAL(logger_, "Send signal to thread error");
- }
+pthread_t main_thread;
+void sig_handler(int sig) {
+ switch (sig) {
+ case SIGINT:
+ LOG4CXX_DEBUG(logger_, "SIGINT signal has been caught");
+ break;
+ case SIGTERM:
+ LOG4CXX_DEBUG(logger_, "SIGTERM signal has been caught");
+ break;
+ case SIGSEGV:
+ LOG4CXX_DEBUG(logger_, "SIGSEGV signal has been caught");
+ break;
+ default:
+ LOG4CXX_DEBUG(logger_, "Unexpected signal has been caught");
+ break;
+ }
+ /*
+ * Resend signal to the main thread in case it was
+ * caught by another thread
+ */
+ if (pthread_equal(pthread_self(), main_thread) == 0) {
+ LOG4CXX_DEBUG(logger_, "Resend signal to the main thread");
+ if (pthread_kill(main_thread, sig) != 0) {
+ LOG4CXX_FATAL(logger_, "Send signal to thread error");
}
}
+}
} // namespace
void LifeCycle::Run() {
LOG4CXX_AUTO_TRACE(logger_);
main_thread = pthread_self();
// First, register signal handlers
- if(!::utils::SubscribeToInterruptSignal(&sig_handler) ||
- !::utils::SubscribeToTerminateSignal(&sig_handler) ||
- !::utils::SubscribeToFaultSignal(&sig_handler)) {
+ if (!::utils::SubscribeToInterruptSignal(&sig_handler) ||
+ !::utils::SubscribeToTerminateSignal(&sig_handler) ||
+ !::utils::SubscribeToFaultSignal(&sig_handler)) {
LOG4CXX_FATAL(logger_, "Subscribe to system signals error");
}
// Now wait for any signal
pause();
}
-
void LifeCycle::StopComponents() {
LOG4CXX_AUTO_TRACE(logger_);
hmi_message_handler::HMIMessageHandlerImpl::instance()->set_message_observer(
NULL);
- connection_handler::ConnectionHandlerImpl::instance()->set_connection_handler_observer(NULL);
+ connection_handler::ConnectionHandlerImpl::instance()
+ ->set_connection_handler_observer(NULL);
if (protocol_handler_)
protocol_handler_->RemoveProtocolObserver(app_manager_);
app_manager_->Stop();