From dc0dfd732a68d4be4aff63db478f576db3e1813e Mon Sep 17 00:00:00 2001 From: Jonas Zeunert Date: Fri, 7 Dec 2018 14:34:10 +0100 Subject: [PATCH] changed to boost optional instead of errorevent --- FlippR-Driver/include/input/IInputDriver.h | 6 +++-- FlippR-Driver/src/input/Detector.h | 4 +-- FlippR-Driver/src/input/DistributingEvent.h | 5 ++-- FlippR-Driver/src/input/ErrorEvent.hpp | 25 ------------------- FlippR-Driver/src/input/InputDriver.cpp | 8 +++--- FlippR-Driver/src/input/InputDriver.h | 11 ++++---- .../src/input/InputGPIOInterface.cpp | 2 -- FlippR-Driver/tests/input/TestDetector.cpp | 2 +- 8 files changed, 19 insertions(+), 44 deletions(-) delete mode 100644 FlippR-Driver/src/input/ErrorEvent.hpp diff --git a/FlippR-Driver/include/input/IInputDriver.h b/FlippR-Driver/include/input/IInputDriver.h index df52ce0..0fe16cf 100644 --- a/FlippR-Driver/include/input/IInputDriver.h +++ b/FlippR-Driver/include/input/IInputDriver.h @@ -8,8 +8,10 @@ #ifndef SRC_INPUT_IINPUTDRIVER_H_ #define SRC_INPUT_IINPUTDRIVER_H_ -#include "input/IEventHandler.h" #include +#include + +#include "input/IEventHandler.h" namespace flippR_driver { @@ -23,7 +25,7 @@ namespace input virtual void unregister_event_handler(IEventHandler *handler) = 0; - virtual std::shared_ptr get_event(std::string name) = 0; + virtual boost::optional> get_event(std::string name) = 0; }; } } diff --git a/FlippR-Driver/src/input/Detector.h b/FlippR-Driver/src/input/Detector.h index 93ccb4d..7432eaa 100644 --- a/FlippR-Driver/src/input/Detector.h +++ b/FlippR-Driver/src/input/Detector.h @@ -42,9 +42,9 @@ private: void check_inputs(); private: - std::unique_ptr input_gpio_interface; + const std::unique_ptr input_gpio_interface; - std::vector> events; + const std::vector> events; bool is_running; std::thread detect_thread; diff --git a/FlippR-Driver/src/input/DistributingEvent.h b/FlippR-Driver/src/input/DistributingEvent.h index 6a5814f..915ade7 100644 --- a/FlippR-Driver/src/input/DistributingEvent.h +++ b/FlippR-Driver/src/input/DistributingEvent.h @@ -27,7 +27,7 @@ private: void distribute(); public: - std::chrono::milliseconds bounce_time; + const std::chrono::milliseconds bounce_time; private: enum ActivationState @@ -36,7 +36,8 @@ private: FIRST_ACTIVATED, ACTIVATED }; - std::shared_ptr event_notifier; + + const std::shared_ptr event_notifier; ActivationState activation_state; diff --git a/FlippR-Driver/src/input/ErrorEvent.hpp b/FlippR-Driver/src/input/ErrorEvent.hpp deleted file mode 100644 index 81a31b7..0000000 --- a/FlippR-Driver/src/input/ErrorEvent.hpp +++ /dev/null @@ -1,25 +0,0 @@ -/* - * ErrorEvent.h - * - * Created on: Aug 8, 2018 - * Author: Andreas Schneider, Johannes Wendel, Jonas Zeunert - */ - -#ifndef SRC_INPUT_ERROREVENT_HPP_ -#define SRC_INPUT_ERROREVENT_HPP_ - -#include "input/Event.h" - -namespace flippR_driver { -namespace input { - -class ErrorEvent : public Event -{ -public: - ErrorEvent() : Event(0, 0, "ERROR") {} -}; - -} -} - -#endif diff --git a/FlippR-Driver/src/input/InputDriver.cpp b/FlippR-Driver/src/input/InputDriver.cpp index 4816b1a..01519f8 100644 --- a/FlippR-Driver/src/input/InputDriver.cpp +++ b/FlippR-Driver/src/input/InputDriver.cpp @@ -7,7 +7,6 @@ #include "InputDriver.h" #include "utility/config.h" -#include "ErrorEvent.hpp" namespace flippR_driver { @@ -31,18 +30,17 @@ void InputDriver::unregister_event_handler(IEventHandler *handler) this->event_notifier->unregister_event_handler(handler); } -std::shared_ptr InputDriver::get_event(std::string name) +boost::optional> InputDriver::get_event(std::string name) { - std::shared_ptr event(new ErrorEvent()); try { - event = this->events.at(name); + return this->events.at(name); } catch(std::out_of_range &e) { CLOG_N_TIMES(1, WARNING, OUTPUT_LOGGER) << "Did not found event " << name << " please check config file!"; } - return event; + return boost::optional>{}; } } diff --git a/FlippR-Driver/src/input/InputDriver.h b/FlippR-Driver/src/input/InputDriver.h index f1a218a..8296e2b 100644 --- a/FlippR-Driver/src/input/InputDriver.h +++ b/FlippR-Driver/src/input/InputDriver.h @@ -7,10 +7,11 @@ #ifndef SRC_INPUT_INPUTDRIVER_H_ #define SRC_INPUT_INPUTDRIVER_H_ +#include "input/IInputDriver.h" + #include #include "IEventNotifier.h" -#include "input/IInputDriver.h" #include "IDetector.h" namespace flippR_driver @@ -27,13 +28,13 @@ public: void register_event_handler(IEventHandler* handler) override; void unregister_event_handler(IEventHandler* handler) override; - std::shared_ptr get_event(std::string name) override; + boost::optional> get_event(std::string name) override; private: - std::shared_ptr event_notifier; - std::unique_ptr detector; + const std::shared_ptr event_notifier; + const std::unique_ptr detector; - std::map> events; + const std::map> events; }; } diff --git a/FlippR-Driver/src/input/InputGPIOInterface.cpp b/FlippR-Driver/src/input/InputGPIOInterface.cpp index 89f5ef5..ce216bb 100644 --- a/FlippR-Driver/src/input/InputGPIOInterface.cpp +++ b/FlippR-Driver/src/input/InputGPIOInterface.cpp @@ -53,8 +53,6 @@ void InputGPIOInterface::write_col(char data) const write_pin(this->pins.at("col_address_C"), data & 0b100); } - - void InputGPIOInterface::init_pins() const { initialize_output_pin(this->pins.at("col_address_A")); diff --git a/FlippR-Driver/tests/input/TestDetector.cpp b/FlippR-Driver/tests/input/TestDetector.cpp index 0c19601..ab3a167 100644 --- a/FlippR-Driver/tests/input/TestDetector.cpp +++ b/FlippR-Driver/tests/input/TestDetector.cpp @@ -18,8 +18,8 @@ #include "input/IEventNotifier.h" #include "input/DistributingEvent.h" #include "input/Detector.h" +#include "input/IInputGPIOInterface.h" #include "utility/LoggerFactory.h" -#include "utility/InputGPIOInterface.h" using namespace fakeit;