From d1308d1c87ff7176258fe43d14e70f04894e0494 Mon Sep 17 00:00:00 2001 From: Andriy Byzhynar Date: Wed, 27 Jun 2018 14:53:12 +0300 Subject: Initial implementation of Low Voltage feature Implemented Low Voltage feature based on POSIX real-time signals --- src/appMain/CMakeLists.txt | 11 +- src/appMain/life_cycle.h | 18 ++ src/appMain/life_cycle_impl.cc | 33 +++- src/appMain/life_cycle_impl.h | 35 ++-- src/appMain/low_voltage_signals_handler.cc | 185 +++++++++++++++++++++ src/appMain/low_voltage_signals_handler.h | 143 ++++++++++++++++ src/appMain/main.cc | 17 ++ src/appMain/smartDeviceLink.ini | 6 + .../src/application_manager_impl.cc | 5 +- .../test/commands/CMakeLists.txt | 1 + .../include/config_profile/profile.h | 24 +++ src/components/config_profile/src/profile.cc | 49 +++++- src/components/include/utils/typed_enum_print.h | 52 ++++++ .../src/transport_manager_impl.cc | 2 + src/components/utils/CMakeLists.txt | 1 + src/components/utils/include/utils/signals.h | 3 + src/components/utils/src/signals_posix.cc | 17 ++ 17 files changed, 584 insertions(+), 18 deletions(-) create mode 100644 src/appMain/low_voltage_signals_handler.cc create mode 100644 src/appMain/low_voltage_signals_handler.h create mode 100644 src/components/include/utils/typed_enum_print.h diff --git a/src/appMain/CMakeLists.txt b/src/appMain/CMakeLists.txt index 51b6a947e8..41d3d4202e 100644 --- a/src/appMain/CMakeLists.txt +++ b/src/appMain/CMakeLists.txt @@ -73,7 +73,16 @@ include_directories( ${CMAKE_SOURCE_DIR}/src ) -collect_sources(SOURCES "${CMAKE_CURRENT_SOURCE_DIR}") +# Create object library +add_library("LowVoltageHandlerObjLibrary" OBJECT ${CMAKE_CURRENT_SOURCE_DIR}/low_voltage_signals_handler.cc +) + +set (SOURCES + ${CMAKE_CURRENT_SOURCE_DIR}/main.cc + ${CMAKE_CURRENT_SOURCE_DIR}/life_cycle_impl.cc + ${CMAKE_CURRENT_SOURCE_DIR}/signal_handlers.cc + $ +) cmake_policy(PUSH) # make link_directories() treat paths relative to the source dir diff --git a/src/appMain/life_cycle.h b/src/appMain/life_cycle.h index d14b91d13f..ff8fa2cc40 100644 --- a/src/appMain/life_cycle.h +++ b/src/appMain/life_cycle.h @@ -67,7 +67,25 @@ class LifeCycle { */ virtual void StopComponents() = 0; + /** + * Makes appropriate actions when Low Voltage signal received: + * Stops all SDL activities except of waiting of UNIX signals + * from HMI + */ + virtual void LowVoltage() = 0; + /** + * Makes appropriate actions when Wake Up signal received: + * Restores all SDL activities stopped due to LOW VOLTAGE + * from HMI + */ + virtual void WakeUp() = 0; + + /** + * Makes appropriate actions when Ignition Off signal received: + * Triggers all SDL components stop and deletion + */ + virtual void IgnitionOff() = 0; }; } // namespace main_namespace diff --git a/src/appMain/life_cycle_impl.cc b/src/appMain/life_cycle_impl.cc index bf55a1f346..d211771a39 100644 --- a/src/appMain/life_cycle_impl.cc +++ b/src/appMain/life_cycle_impl.cc @@ -32,7 +32,6 @@ #include "appMain/life_cycle_impl.h" #include "utils/signals.h" -#include "utils/make_shared.h" #include "config_profile/profile.h" #include "application_manager/system_time/system_time_handler_impl.h" #include "resumption/last_state_impl.h" @@ -48,13 +47,15 @@ #include "utils/log_message_loop_thread.h" #endif // ENABLE_LOG +#include "appMain/low_voltage_signals_handler.h" + using threads::Thread; namespace main_namespace { CREATE_LOGGERPTR_GLOBAL(logger_, "SDLMain") -LifeCycle::LifeCycle(const profile::Profile& profile) +LifeCycleImpl::LifeCycleImpl(const profile::Profile& profile) : transport_manager_(NULL) , protocol_handler_(NULL) , connection_handler_(NULL) @@ -166,9 +167,34 @@ bool LifeCycleImpl::StartComponents() { // start transport manager transport_manager_->Visibility(true); + LowVoltageSignalsOffset signals_offset{profile_.low_voltage_signal_offset(), + profile_.wake_up_signal_offset(), + profile_.ignition_off_signal_offset()}; + + low_voltage_signals_handler_.reset( + new LowVoltageSignalsHandler(*this, signals_offset)); + return true; } +void LifeCycleImpl::LowVoltage() { + LOG4CXX_AUTO_TRACE(logger_); + transport_manager_->Visibility(false); + app_manager_->OnLowVoltage(); +} + +void LifeCycleImpl::IgnitionOff() { + LOG4CXX_AUTO_TRACE(logger_); + kill(getpid(), SIGINT); +} + +void LifeCycleImpl::WakeUp() { + LOG4CXX_AUTO_TRACE(logger_); + app_manager_->OnWakeUp(); + transport_manager_->Reinit(); + transport_manager_->Visibility(true); +} + #ifdef MESSAGEBROKER_HMIADAPTER bool LifeCycleImpl::InitMessageSystem() { mb_adapter_ = new hmi_message_handler::MessageBrokerAdapter( @@ -285,6 +311,9 @@ void LifeCycleImpl::StopComponents() { delete app_manager_; app_manager_ = NULL; + LOG4CXX_INFO(logger_, "Destroying Low Voltage Signals Handler."); + low_voltage_signals_handler_.reset(); + LOG4CXX_INFO(logger_, "Destroying HMI Message Handler and MB adapter."); #ifdef MESSAGEBROKER_HMIADAPTER diff --git a/src/appMain/life_cycle_impl.h b/src/appMain/life_cycle_impl.h index a190a5734d..b898f0c589 100644 --- a/src/appMain/life_cycle_impl.h +++ b/src/appMain/life_cycle_impl.h @@ -39,21 +39,13 @@ #include #include #include "utils/macro.h" -#include "utils/shared_ptr.h" #include "config_profile/profile.h" #include "hmi_message_handler/hmi_message_handler_impl.h" -#ifdef DBUS_HMIADAPTER -#include "hmi_message_handler/dbus_message_adapter.h" -#endif // DBUS_HMIADAPTER #if (defined(MESSAGEBROKER_HMIADAPTER) || defined(PASA_HMI)) #include "hmi_message_handler/messagebroker_adapter.h" #endif // #if ( defined (MESSAGEBROKER_HMIADAPTER) || defined(PASA_HMI) ) #include "application_manager/application_manager_impl.h" -#ifdef SDL_REMOTE_CONTROL -#include "application_manager/core_service.h" -#include "functional_module/plugin_manager.h" -#endif // SDL_REMOTE_CONTROL #include "connection_handler/connection_handler_impl.h" #include "protocol_handler/protocol_handler_impl.h" #include "transport_manager/transport_manager.h" @@ -76,6 +68,8 @@ class SystemTimeHandler; namespace main_namespace { +class LowVoltageSignalsHandler; + class LifeCycleImpl : public LifeCycle { public: explicit LifeCycleImpl(const profile::Profile& profile); @@ -102,11 +96,32 @@ class LifeCycleImpl : public LifeCycle { */ void StopComponents() OVERRIDE; + /** + * Makes appropriate actions when Low Voltage signal received: + * Stops all SDL activities except of waiting of UNIX signals + * from HMI + */ + void LowVoltage() OVERRIDE; + + /** + * Makes appropriate actions when Wake Up signal received: + * Restores all SDL activities stopped due to LOW VOLTAGE + * from HMI + */ + void WakeUp() OVERRIDE; + + /** + * Makes appropriate actions when Ignition Off signal received: + * Triggers all SDL components stop and deletion + */ + void IgnitionOff() OVERRIDE; + private: transport_manager::TransportManagerImpl* transport_manager_; protocol_handler::ProtocolHandlerImpl* protocol_handler_; connection_handler::ConnectionHandlerImpl* connection_handler_; application_manager::ApplicationManagerImpl* app_manager_; + std::unique_ptr low_voltage_signals_handler_; #ifdef ENABLE_SECURITY security_manager::CryptoManager* crypto_manager_; security_manager::SecurityManager* security_manager_; @@ -118,10 +133,6 @@ class LifeCycleImpl : public LifeCycle { #ifdef TELEMETRY_MONITOR telemetry_monitor::TelemetryMonitor* telemetry_monitor_; #endif // TELEMETRY_MONITOR -#ifdef DBUS_HMIADAPTER - hmi_message_handler::DBusMessageAdapter* dbus_adapter_; - std::thread* dbus_adapter_thread_; -#endif // DBUS_HMIADAPTER #ifdef MESSAGEBROKER_HMIADAPTER hmi_message_handler::MessageBrokerAdapter* mb_adapter_; diff --git a/src/appMain/low_voltage_signals_handler.cc b/src/appMain/low_voltage_signals_handler.cc new file mode 100644 index 0000000000..b514ac6d55 --- /dev/null +++ b/src/appMain/low_voltage_signals_handler.cc @@ -0,0 +1,185 @@ +/* + * Copyright (c) 2018, Ford Motor Company + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Ford Motor Company nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "appMain/low_voltage_signals_handler.h" + +#include +#include "appMain/life_cycle.h" +#include "utils/logger.h" +#include "utils/typed_enum_print.h" +#include "config_profile/profile.h" + +namespace main_namespace { + +CREATE_LOGGERPTR_GLOBAL(logger_, "LowVoltageSignalsHandler") + +LowVoltageSignalsHandler::LowVoltageSignalsHandler( + LifeCycle& life_cycle, const LowVoltageSignalsOffset& offset_data) + : state_(SDLState::kRun) + , notifications_delegate_(new NotificationThreadDelegate(*this)) + , signals_handler_thread_(threads::CreateThread( + "LV_SIGNALS_HANDLER_THREAD", notifications_delegate_.get())) + , life_cycle_(life_cycle) + , SIGLOWVOLTAGE_(offset_data.low_voltage_signal_offset + SIGRTMIN) + , SIGWAKEUP_(offset_data.wake_up_signal_offset + SIGRTMIN) + , SIGIGNOFF_(offset_data.ignition_off_signal_offset + SIGRTMIN) { + signals_handler_thread_->start(); +} + +SDLState LowVoltageSignalsHandler::get_current_sdl_state() const { + return state_; +} + +int LowVoltageSignalsHandler::low_voltage_signo() const { + return SIGLOWVOLTAGE_; +} + +int LowVoltageSignalsHandler::wake_up_signo() const { + return SIGWAKEUP_; +} + +int LowVoltageSignalsHandler::ignition_off_signo() const { + return SIGIGNOFF_; +} + +void LowVoltageSignalsHandler::Destroy() { + state_ = SDLState::kStop; + if (signals_handler_thread_) { + signals_handler_thread_->join(); + } + notifications_delegate_.reset(); + threads::DeleteThread(signals_handler_thread_); +} + +LowVoltageSignalsHandler::~LowVoltageSignalsHandler() { + Destroy(); +} + +void LowVoltageSignalsHandler::HandleSignal(const int signo) { + using utils::operator<<; + LOG4CXX_DEBUG(logger_, "Received Signal: " << signo); + LOG4CXX_DEBUG(logger_, "Current state is : " << get_current_sdl_state()); + + auto handle_run_state = [this, signo]() { + + if (SIGLOWVOLTAGE_ == signo) { + LOG4CXX_DEBUG(logger_, "Received LOW_VOLTAGE signal"); + state_ = SDLState::kSleep; + life_cycle_.LowVoltage(); + return; + } + + if (SIGIGNOFF_ == signo) { + LOG4CXX_DEBUG(logger_, + "Received IGNITION_OFF signal. But SDL is in active state"); + // Do nothing + return; + } + + if (SIGWAKEUP_ == signo) { + LOG4CXX_DEBUG(logger_, + "Received WAKE_UP signal. But SDL is in active state"); + // Do nothing + return; + } + LOG4CXX_DEBUG(logger_, "Received UNKNOWN signal"); + }; + + auto handle_sleep_state = [this, signo]() { + + if (SIGWAKEUP_ == signo) { + LOG4CXX_DEBUG(logger_, "Received WAKE UP signal"); + state_ = SDLState::kRun; + life_cycle_.WakeUp(); + return; + } + + if (SIGIGNOFF_ == signo) { + LOG4CXX_DEBUG(logger_, "Received IGNITION_OFF signal"); + state_ = SDLState::kStop; + life_cycle_.IgnitionOff(); + return; + } + + if (SIGLOWVOLTAGE_ == signo) { + LOG4CXX_DEBUG( + logger_, + "Received LOW VOLTAGE signal. But SDL is already in sleep state"); + // Do nothing + return; + } + LOG4CXX_DEBUG(logger_, "Received UNKNOWN signal"); + }; + + switch (state_) { + case SDLState::kRun: + handle_run_state(); + break; + case SDLState::kSleep: + handle_sleep_state(); + break; + case SDLState::kStop: /* nothing to do here */ + LOG4CXX_DEBUG(logger_, "SDL is in stopping state"); + break; + } +} + +bool LowVoltageSignalsHandler::IsActive() const { + return SDLState::kStop != state_; +} + +void NotificationThreadDelegate::threadMain() { + sigset_t lv_mask; + sigemptyset(&lv_mask); + sigaddset(&lv_mask, low_voltage_signals_handler_.low_voltage_signo()); + sigaddset(&lv_mask, low_voltage_signals_handler_.wake_up_signo()); + sigaddset(&lv_mask, low_voltage_signals_handler_.ignition_off_signo()); + + while (low_voltage_signals_handler_.IsActive()) { + int signo = 0; + const int err = sigwait(&lv_mask, &signo); + if (0 != err) { + LOG4CXX_ERROR( + logger_, + "Sigwait() error! Signals set contains an invalid signal number!"); + continue; + } + low_voltage_signals_handler_.HandleSignal(signo); + } +} + +void NotificationThreadDelegate::exitThreadMain() { + LOG4CXX_AUTO_TRACE(logger_); + ThreadDelegate::exitThreadMain(); +} + +} // namespace main_namespace diff --git a/src/appMain/low_voltage_signals_handler.h b/src/appMain/low_voltage_signals_handler.h new file mode 100644 index 0000000000..4b2902659e --- /dev/null +++ b/src/appMain/low_voltage_signals_handler.h @@ -0,0 +1,143 @@ +/* + * Copyright (c) 2018, Ford Motor Company + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Ford Motor Company nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef SRC_APPMAIN_LOW_VOLTAGE_SIGNALS_HANDLER_H_ +#define SRC_APPMAIN_LOW_VOLTAGE_SIGNALS_HANDLER_H_ + +#include +#include +#include "utils/threads/thread_delegate.h" +#include "utils/threads/thread.h" + +namespace main_namespace { + +typedef struct LowVoltageSignalsOffset { + int low_voltage_signal_offset; + int wake_up_signal_offset; + int ignition_off_signal_offset; +} LowVoltageSignalsOffset; + +class LifeCycle; +class NotificationThreadDelegate; + +/** + * @brief The SDLState enum defines current Smartdevicelink app state + * which can be changed due to received UNIX RT signals dedicated for + * Low Voltage functionality handling + * e.g. LowVoltage, WakeUp, IgnitionOff signals + */ +enum class SDLState { kRun, kSleep, kStop }; + +/** + * @brief Class which handles real-time POSIX signals + * dedicated for LOW VOLTAGE functionality + */ +class LowVoltageSignalsHandler { + public: + /** + * @brief Constructor + * @param life_cycle - life_cycle object to interact with other system + * components + * @param offset_data offset data needed to calculate correct SIGNAL numbers + * used for LOW VOLTAGE functionality (as offset from SIGRTMIN) + */ + LowVoltageSignalsHandler(LifeCycle& life_cycle, + const LowVoltageSignalsOffset& offset_data); + /** + * @brief Handles RT signals related to Low Voltage functionality + */ + void HandleSignal(const int signo); + + /** + * @brief Checks if SDL is in active state + * therefore not yet in sleep state due to Low Voltage event + */ + bool IsActive() const; + + /** + * @brief Returns current LOW VOLTAGE SDL state + */ + SDLState get_current_sdl_state() const; + + /** + * @brief Returns LOW VOLTAGE signal number + */ + int low_voltage_signo() const; + + /** + * @brief Returns WAKE UP signal number + */ + int wake_up_signo() const; + + /** + * @brief Returns IGNITION OFF signal number + */ + int ignition_off_signo() const; + + /** + * @brief Destructor + */ + ~LowVoltageSignalsHandler(); + + private: + /** + * @brief Destroys all parts of Low Voltage signals handler + * Invoked from destructor + */ + void Destroy(); + SDLState state_; + std::unique_ptr notifications_delegate_; + threads::Thread* signals_handler_thread_; + LifeCycle& life_cycle_; + int SIGLOWVOLTAGE_; + int SIGWAKEUP_; + int SIGIGNOFF_; +}; + +class NotificationThreadDelegate : public threads::ThreadDelegate { + public: + NotificationThreadDelegate( + LowVoltageSignalsHandler& low_voltage_signals_handler) + : low_voltage_signals_handler_(low_voltage_signals_handler) {} + + ~NotificationThreadDelegate() {} + + void threadMain() OVERRIDE; + void exitThreadMain() OVERRIDE; + + private: + LowVoltageSignalsHandler& low_voltage_signals_handler_; +}; + +} // namespace main_namespace + +#endif // SRC_APPMAIN_LOW_VOLTAGE_SIGNALS_HANDLER_H_ diff --git a/src/appMain/main.cc b/src/appMain/main.cc index e9625cc33a..d1f0594daf 100644 --- a/src/appMain/main.cc +++ b/src/appMain/main.cc @@ -106,12 +106,29 @@ int32_t main(int32_t argc, char** argv) { profile::Profile profile_instance; std::unique_ptr life_cycle( new main_namespace::LifeCycleImpl(profile_instance)); + if ((argc > 1) && (0 != argv)) { profile_instance.set_config_file_name(argv[1]); } else { profile_instance.set_config_file_name("smartDeviceLink.ini"); } + // Reading profile offsets for real-time signals dedicated + // for Low Voltage functionality handling + main_namespace::LowVoltageSignalsOffset signals_offset{ + profile_instance.low_voltage_signal_offset(), + profile_instance.wake_up_signal_offset(), + profile_instance.ignition_off_signal_offset()}; + + // Unsubscribe once for all threads + // except specific thread dedicated for + // Low Voltage signals handling + // Thread will be created later + if (!utils::UnsubscribeFromLowVoltageSignals(signals_offset)) { + // Can't use internal logger here + exit(EXIT_FAILURE); + } + // -------------------------------------------------------------------------- // Logger initialization INIT_LOGGER("log4cxx.properties", profile_instance.logs_enabled()); diff --git a/src/appMain/smartDeviceLink.ini b/src/appMain/smartDeviceLink.ini index 444affc06c..037a6efb14 100644 --- a/src/appMain/smartDeviceLink.ini +++ b/src/appMain/smartDeviceLink.ini @@ -96,6 +96,12 @@ AppTransportChangeTimer = 500 ; The time used as addition for AppTransportChangeTimer AppTransportChangeTimerAddition = 0 +; Signal offsets used by SDL for setting up real time signals +; used by LOW VOLTAGE functionality +LowVoltageSignal = 1 ; Offset from SIGRTMIN +WakeUpSignal = 2 ; Offset from SIGRTMIN +IgnitionOffSignal = 3 ; Offset from SIGRTMIN + [MEDIA MANAGER] ; where 3 is a number of retries and 1000 is a timeout in milliseconds for request frequency StartStreamRetry = 3, 1000 diff --git a/src/components/application_manager/src/application_manager_impl.cc b/src/components/application_manager/src/application_manager_impl.cc index 386bfe4825..374b5bb8b2 100644 --- a/src/components/application_manager/src/application_manager_impl.cc +++ b/src/components/application_manager/src/application_manager_impl.cc @@ -2429,7 +2429,10 @@ void ApplicationManagerImpl::ClearAppsPersistentData() { void ApplicationManagerImpl::SendOnSDLClose() { LOG4CXX_AUTO_TRACE(logger_); - + if (IsLowVoltage()) { + LOG4CXX_TRACE(logger_, "SDL is in Low Voltage State"); + return; + } // must be sent to PASA HMI on shutdown synchronously smart_objects::SmartObjectSPtr msg = std::make_shared( diff --git a/src/components/application_manager/test/commands/CMakeLists.txt b/src/components/application_manager/test/commands/CMakeLists.txt index 165b5fc0fb..33258e60db 100644 --- a/src/components/application_manager/test/commands/CMakeLists.txt +++ b/src/components/application_manager/test/commands/CMakeLists.txt @@ -35,6 +35,7 @@ include_directories( ${COMPONENTS_DIR}/application_manager/include/ ${COMPONENTS_DIR}/application_manager/include/application_manager/ ${COMPONENTS_DIR}/application_manager/include/application_manager/commands/ + ${CMAKE_SOURCE_DIR}/src ) set(COMMANDS_TEST_DIR ${AM_TEST_DIR}/commands) diff --git a/src/components/config_profile/include/config_profile/profile.h b/src/components/config_profile/include/config_profile/profile.h index 4c2be53228..17437a04a3 100644 --- a/src/components/config_profile/include/config_profile/profile.h +++ b/src/components/config_profile/include/config_profile/profile.h @@ -109,6 +109,27 @@ class Profile : public protocol_handler::ProtocolHandlerSettings, */ const std::string& app_resource_folder() const; + /** + * @brief Returns offset from SIGRTMIN for user defined signal + * SIGLOWVOLTAGE + * which is used for handling LOW Voltage functionality + */ + int low_voltage_signal_offset() const; + + /** + * @brief Returns offset from SIGRTMIN for user defined signal + * SIGWAKEUP + * which is used for handling LOW Voltage functionality + */ + int wake_up_signal_offset() const; + + /** + * @brief Returns offset from SIGRTMIN for user defined signal + * SIGIGNITIONOFF + * which is used for handling LOW Voltage functionality + */ + int ignition_off_signal_offset() const; + /** * @brief Returns true, if SDL 4.0 is enabled * @deprecated use max_supported_protocol_version instead @@ -1018,6 +1039,9 @@ class Profile : public protocol_handler::ProtocolHandlerSettings, std::vector video_service_transports_; bool error_occured_; std::string error_description_; + int low_voltage_signal_offset_; + int wake_up_signal_offset_; + int ignition_off_signal_offset_; DISALLOW_COPY_AND_ASSIGN(Profile); }; diff --git a/src/components/config_profile/src/profile.cc b/src/components/config_profile/src/profile.cc index 3f3ec7eb63..d869d6b65e 100644 --- a/src/components/config_profile/src/profile.cc +++ b/src/components/config_profile/src/profile.cc @@ -222,6 +222,9 @@ const char* kEnableAppLaunchIOSKey = "EnableAppLaunchIOS"; const char* kAppTransportChangeTimerKey = "AppTransportChangeTimer"; const char* kAppTransportChangeTimerAdditionKey = "AppTransportChangeTimerAddition"; +const char* kLowVoltageSignalOffsetKey = "LowVoltageSignal"; +const char* kWakeUpSignalOffsetKey = "WakeUpSignal"; +const char* kIgnitionOffSignalOffsetKey = "IgnitionOffSignal"; const char* kMultipleTransportsEnabledKey = "MultipleTransportsEnabled"; const char* kSecondaryTransportForBluetoothKey = "SecondaryTransportForBluetooth"; @@ -372,6 +375,9 @@ const uint16_t kDefaultWaitTimeBetweenApps = 4000; const bool kDefaultEnableAppLaunchIOS = true; const uint32_t kDefaultAppTransportChangeTimer = 500u; const uint32_t kDefaultAppTransportChangeTimerAddition = 0u; +const int32_t kDefaultLowVoltageSignalOffset = 1; +const int32_t kDefaultWakeUpSignalOffset = 2; +const int32_t kDefaultIgnitionOffSignalOffset = 3; const std::string kAllowedSymbols = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890_.-"; const bool kDefaultMultipleTransportsEnabled = false; @@ -485,7 +491,10 @@ Profile::Profile() kDefaultAppTransportChangeTimerAddition) , multiple_transports_enabled_(kDefaultMultipleTransportsEnabled) , error_occured_(false) - , error_description_() { + , error_description_() + , low_voltage_signal_offset_(kDefaultLowVoltageSignalOffset) + , wake_up_signal_offset_(kDefaultWakeUpSignalOffset) + , ignition_off_signal_offset_(kDefaultIgnitionOffSignalOffset) { // SDL version ReadStringValue( &sdl_version_, kDefaultSDLVersion, kMainSection, kSDLVersionKey); @@ -530,6 +539,18 @@ const std::string& Profile::app_resource_folder() const { return app_resource_folder_; } +int Profile::low_voltage_signal_offset() const { + return low_voltage_signal_offset_; +} + +int Profile::wake_up_signal_offset() const { + return wake_up_signal_offset_; +} + +int Profile::ignition_off_signal_offset() const { + return ignition_off_signal_offset_; +} + bool Profile::enable_protocol_4() const { return max_supported_protocol_version_ >= 4; } @@ -2124,7 +2145,31 @@ void Profile::UpdateValues() { kAppTransportChangeTimerAdditionKey, kMainSection); - ReadBoolValue(&multiple_transports_enabled_, + ReadIntValue(&low_voltage_signal_offset_, + kDefaultLowVoltageSignalOffset, + kMainSection, + kLowVoltageSignalOffsetKey); + + LOG_UPDATED_VALUE( + low_voltage_signal_offset_, kLowVoltageSignalOffsetKey, kMainSection); + + ReadIntValue(&wake_up_signal_offset_, + kDefaultWakeUpSignalOffset, + kMainSection, + kWakeUpSignalOffsetKey); + + LOG_UPDATED_VALUE( + wake_up_signal_offset_, kWakeUpSignalOffsetKey, kMainSection); + + ReadIntValue(&ignition_off_signal_offset_, + kDefaultIgnitionOffSignalOffset, + kMainSection, + kIgnitionOffSignalOffsetKey); + + LOG_UPDATED_VALUE( + ignition_off_signal_offset_, kIgnitionOffSignalOffsetKey, kMainSection); + + ReadBoolValue(&multiple_transports_enabled_, kDefaultMultipleTransportsEnabled, kMultipleTransportsSection, kMultipleTransportsEnabledKey); diff --git a/src/components/include/utils/typed_enum_print.h b/src/components/include/utils/typed_enum_print.h new file mode 100644 index 0000000000..e2b903c948 --- /dev/null +++ b/src/components/include/utils/typed_enum_print.h @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2018, Ford Motor Company + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Ford Motor Company nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef SRC_COMPONENTS_INCLUDE_UTILS_TYPED_ENUM_PRINT_H_ +#define SRC_COMPONENTS_INCLUDE_UTILS_TYPED_ENUM_PRINT_H_ + +#include +#include + +namespace utils { + +// Generic overloaded operator "<<" to be able to send enum class values to +// std::ostream +template +std::ostream& operator<<( + typename std::enable_if::value, std::ostream>::type& stream, + const T& e) { + return stream << static_cast(e); +} + +} // namespace utils + +#endif // SRC_COMPONENTS_INCLUDE_UTILS_TYPED_ENUM_PRINT_H_ diff --git a/src/components/transport_manager/src/transport_manager_impl.cc b/src/components/transport_manager/src/transport_manager_impl.cc index abe4edd812..143498205c 100644 --- a/src/components/transport_manager/src/transport_manager_impl.cc +++ b/src/components/transport_manager/src/transport_manager_impl.cc @@ -532,6 +532,8 @@ int TransportManagerImpl::Reinit() { LOG4CXX_AUTO_TRACE(logger_); DisconnectAllDevices(); TerminateAllAdapters(); + device_to_adapter_map_.clear(); + connection_id_counter_ = 0; int ret = InitAllAdapters(); return ret; } diff --git a/src/components/utils/CMakeLists.txt b/src/components/utils/CMakeLists.txt index ed90c6fb45..a6ded9a186 100644 --- a/src/components/utils/CMakeLists.txt +++ b/src/components/utils/CMakeLists.txt @@ -40,6 +40,7 @@ include_directories ( ${COMPONENTS_DIR}/protocol_handler/include ${JSONCPP_INCLUDE_DIRECTORY} ${LOG4CXX_INCLUDE_DIRECTORY} + ${CMAKE_SOURCE_DIR}/src ) # dbms diff --git a/src/components/utils/include/utils/signals.h b/src/components/utils/include/utils/signals.h index e413a2576f..4efdaaa4e8 100644 --- a/src/components/utils/include/utils/signals.h +++ b/src/components/utils/include/utils/signals.h @@ -38,11 +38,14 @@ typedef void (*sighandler_t)(int); #else #include #endif +#include "appMain/low_voltage_signals_handler.h" namespace utils { bool UnsubscribeFromTermination(); bool WaitTerminationSignals(sighandler_t sig_handler); +bool UnsubscribeFromLowVoltageSignals( + const main_namespace::LowVoltageSignalsOffset& offset_data); } // namespace utils diff --git a/src/components/utils/src/signals_posix.cc b/src/components/utils/src/signals_posix.cc index 45923e4f9b..dd569a96d6 100644 --- a/src/components/utils/src/signals_posix.cc +++ b/src/components/utils/src/signals_posix.cc @@ -51,6 +51,23 @@ bool utils::UnsubscribeFromTermination() { return !pthread_sigmask(SIG_BLOCK, &signal_set, NULL); } +bool utils::UnsubscribeFromLowVoltageSignals( + const main_namespace::LowVoltageSignalsOffset& offset_data) { + // Disable Low Voltage signals in main thread + // due to all further threads will inherit signals mask + sigset_t signal_set; + sigemptyset(&signal_set); + const int SIGLOWVOLTAGE = SIGRTMIN + offset_data.low_voltage_signal_offset; + const int SIGWAKEUP = SIGRTMIN + offset_data.wake_up_signal_offset; + const int SIGIGNOFF = SIGRTMIN + offset_data.ignition_off_signal_offset; + sigaddset(&signal_set, SIGLOWVOLTAGE); + sigaddset(&signal_set, SIGWAKEUP); + sigaddset(&signal_set, SIGIGNOFF); + + // Set signals mask to be blocked by thread + return !pthread_sigmask(SIG_BLOCK, &signal_set, nullptr); +} + namespace { bool CatchSIGSEGV(sighandler_t handler) { struct sigaction act; -- cgit v1.2.1