summaryrefslogtreecommitdiff
path: root/src/components/utils
diff options
context:
space:
mode:
authorAndriy Byzhynar <abyzhynar@luxoft.com>2018-06-27 14:53:12 +0300
committerAlexander <akutsan@luxoft.com>2018-08-21 12:30:03 +0300
commitd1308d1c87ff7176258fe43d14e70f04894e0494 (patch)
tree42e338c03c8b446239af18aedf477f815ed43d96 /src/components/utils
parentaf2f7dfa77e92694095104fe6949c412f8edf12e (diff)
downloadsdl_core-d1308d1c87ff7176258fe43d14e70f04894e0494.tar.gz
Initial implementation of Low Voltage feature
Implemented Low Voltage feature based on POSIX real-time signals
Diffstat (limited to 'src/components/utils')
-rw-r--r--src/components/utils/CMakeLists.txt1
-rw-r--r--src/components/utils/include/utils/signals.h3
-rw-r--r--src/components/utils/src/signals_posix.cc17
3 files changed, 21 insertions, 0 deletions
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 <signal.h>
#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;