From b9328855c8d2f431013790d27bb18f37c0c3183a Mon Sep 17 00:00:00 2001 From: Neeflix Date: Thu, 31 May 2018 20:25:06 +0200 Subject: [PATCH 1/5] added logging --- FlippR-Driver/src/input/Detector.cpp | 2 ++ FlippR-Driver/src/input/Event.hpp | 7 ++++++- FlippR-Driver/src/input/EventHandler.hpp | 3 +++ FlippR-Driver/src/input/EventNotifier.cpp | 2 ++ FlippR-Driver/src/input/InputDriver.hpp | 7 ++++++- FlippR-Driver/src/utilities/config.h | 2 ++ 6 files changed, 21 insertions(+), 2 deletions(-) diff --git a/FlippR-Driver/src/input/Detector.cpp b/FlippR-Driver/src/input/Detector.cpp index 75b6fcc..181fb7b 100644 --- a/FlippR-Driver/src/input/Detector.cpp +++ b/FlippR-Driver/src/input/Detector.cpp @@ -19,6 +19,8 @@ Detector::Detector(InputGPIOInterface* input_gpio_interface, std::map #include +#include "../utilities/config.h" + namespace Input { class Event { public: - Event(char address, char priority, std::string name) : address(address), priority(priority), name(name){} + Event(char address, char priority, std::string name) : address(address), priority(priority), name(name) + { + CLOG_IF(VLOG_IS_ON(HIGH_VERBOSITY), INFO, INPUT_LOGGER) << "Created event: " << name << ", address: " << address; + } bool operator==(const Event& other) { diff --git a/FlippR-Driver/src/input/EventHandler.hpp b/FlippR-Driver/src/input/EventHandler.hpp index 630da7d..0c1771a 100644 --- a/FlippR-Driver/src/input/EventHandler.hpp +++ b/FlippR-Driver/src/input/EventHandler.hpp @@ -15,6 +15,7 @@ #include "InputDriver.hpp" #include "Event.hpp" #include "Detector.h" +#include "../utilities/config.h" namespace Input { @@ -26,6 +27,8 @@ public: input_driver(input_driver) { this->input_driver->register_event_handler(this); + + CLOG(INFO, INPUT_LOGGER) << "Created EventHandler"; } virtual ~EventHandler() diff --git a/FlippR-Driver/src/input/EventNotifier.cpp b/FlippR-Driver/src/input/EventNotifier.cpp index f2839df..0446c29 100644 --- a/FlippR-Driver/src/input/EventNotifier.cpp +++ b/FlippR-Driver/src/input/EventNotifier.cpp @@ -18,6 +18,8 @@ EventNotifier::EventNotifier() : is_running(true) { notify_thread = std::thread(&EventNotifier::notify, this); + + CLOG(INFO, INPUT_LOGGER) << "Created EventNotifier and started thread"; } EventNotifier::~EventNotifier() diff --git a/FlippR-Driver/src/input/InputDriver.hpp b/FlippR-Driver/src/input/InputDriver.hpp index 4b82aa2..81a43dc 100644 --- a/FlippR-Driver/src/input/InputDriver.hpp +++ b/FlippR-Driver/src/input/InputDriver.hpp @@ -5,6 +5,9 @@ * Author: Andreas Schneider, Johannes Wendel, Jonas Zeunert, Rafael Vinci, Dr. Franca Rupprecht */ +#include "../utilities/config.h" + + #ifndef SRC_INPUT_INPUTDRIVER_HPP_ #define SRC_INPUT_INPUTDRIVER_HPP_ @@ -23,7 +26,9 @@ class InputDriver public: InputDriver(EventNotifier* event_notifier) : event_notifier(event_notifier) - {} + { + CLOG(INFO, INPUT_LOGGER) << "Created InputDriver"; + } ~InputDriver() { diff --git a/FlippR-Driver/src/utilities/config.h b/FlippR-Driver/src/utilities/config.h index c41788a..cc08fe1 100644 --- a/FlippR-Driver/src/utilities/config.h +++ b/FlippR-Driver/src/utilities/config.h @@ -10,4 +10,6 @@ #define INPUT_LOGGER "driver_logger" #define DRIVER_LOG_FILE "/var/log/flippr_driver.conf" +#define HIGH_VERBOSITY 10 + #define INPUT_MATRIX_SIZE 8 From 010415c4ae866bdaab043fb5ea7efbc1392e4320 Mon Sep 17 00:00:00 2001 From: Neeflix Date: Thu, 31 May 2018 20:26:37 +0200 Subject: [PATCH 2/5] added logging --- FlippR-Driver/src/input/EventHandler.hpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/FlippR-Driver/src/input/EventHandler.hpp b/FlippR-Driver/src/input/EventHandler.hpp index 2792347..ad681d2 100644 --- a/FlippR-Driver/src/input/EventHandler.hpp +++ b/FlippR-Driver/src/input/EventHandler.hpp @@ -38,7 +38,10 @@ public: } // This function is intended to be non pure, if it is called when the derived class doesn't exist anymore - virtual void handle(Event& event); + virtual void handle(Event& event) + { + CLOG(WARNING, INPUT_LOGGER) << "Called EventHandler parent class"; + } private: std::shared_ptr input_driver; From 89a6e04dfa939583e04c6786bb22bf8e8d1d3a8e Mon Sep 17 00:00:00 2001 From: Neeflix Date: Thu, 31 May 2018 20:42:22 +0200 Subject: [PATCH 3/5] made BlockingQueue stable --- FlippR-Driver/src/utilities/BlockingQueue.hpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/FlippR-Driver/src/utilities/BlockingQueue.hpp b/FlippR-Driver/src/utilities/BlockingQueue.hpp index 2e545f3..7515a5f 100644 --- a/FlippR-Driver/src/utilities/BlockingQueue.hpp +++ b/FlippR-Driver/src/utilities/BlockingQueue.hpp @@ -10,8 +10,9 @@ #include #include -#include -#include +#include + +using namespace boost; template class BlockingQueue @@ -19,21 +20,22 @@ class BlockingQueue private: std::mutex d_mutex; std::condition_variable d_condition; - std::priority_queue d_queue; + heap::priority_queue> p_queue; + public: void push(T const& value) { { std::unique_lock lock(this->d_mutex); - d_queue.push_front(value); + p_queue.push_front(value); } this->d_condition.notify_one(); } T pop() { std::unique_lock lock(this->d_mutex); - this->d_condition.wait(lock, [=]{ return !this->d_queue.empty(); }); - T rc(std::move(this->d_queue.back())); - this->d_queue.pop_back(); + this->d_condition.wait(lock, [=]{ return !this->p_queue.empty(); }); + T rc(std::move(this->p_queue.back())); + this->p_queue.pop_back(); return rc; } }; From 8e742662a7d0c460bbfbeb9ff45b6f52350467ee Mon Sep 17 00:00:00 2001 From: Neeflix Date: Thu, 31 May 2018 20:52:08 +0200 Subject: [PATCH 4/5] changed BlockingQueue code style --- FlippR-Driver/src/utilities/BlockingQueue.hpp | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/FlippR-Driver/src/utilities/BlockingQueue.hpp b/FlippR-Driver/src/utilities/BlockingQueue.hpp index 7515a5f..c72573f 100644 --- a/FlippR-Driver/src/utilities/BlockingQueue.hpp +++ b/FlippR-Driver/src/utilities/BlockingQueue.hpp @@ -23,21 +23,21 @@ private: heap::priority_queue> p_queue; public: - void push(T const& value) { - { - std::unique_lock lock(this->d_mutex); - p_queue.push_front(value); - } - this->d_condition.notify_one(); - } + void push(T const& value) + { + std::unique_lock lock(this->d_mutex); + p_queue.push_front(value); + this->d_condition.notify_one(); + } - T pop() { - std::unique_lock lock(this->d_mutex); - this->d_condition.wait(lock, [=]{ return !this->p_queue.empty(); }); - T rc(std::move(this->p_queue.back())); - this->p_queue.pop_back(); - return rc; - } + T pop() + { + std::unique_lock lock(this->d_mutex); + this->d_condition.wait(lock, [=]{ return !this->p_queue.empty(); }); + T rc(std::move(this->p_queue.back())); + this->p_queue.pop_back(); + return rc; + } }; From 424e1fafdef027083e9f57d031e1696f05cf87b8 Mon Sep 17 00:00:00 2001 From: Neeflix Date: Thu, 31 May 2018 20:52:19 +0200 Subject: [PATCH 5/5] changed BlockingQueue code style --- FlippR-Driver/src/utilities/BlockingQueue.hpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/FlippR-Driver/src/utilities/BlockingQueue.hpp b/FlippR-Driver/src/utilities/BlockingQueue.hpp index c72573f..350f6ad 100644 --- a/FlippR-Driver/src/utilities/BlockingQueue.hpp +++ b/FlippR-Driver/src/utilities/BlockingQueue.hpp @@ -18,9 +18,9 @@ template class BlockingQueue { private: - std::mutex d_mutex; - std::condition_variable d_condition; - heap::priority_queue> p_queue; + std::mutex d_mutex; + std::condition_variable d_condition; + heap::priority_queue> p_queue; public: void push(T const& value)