changed to boost optional instead of errorevent
This commit is contained in:
@@ -8,8 +8,10 @@
|
|||||||
#ifndef SRC_INPUT_IINPUTDRIVER_H_
|
#ifndef SRC_INPUT_IINPUTDRIVER_H_
|
||||||
#define SRC_INPUT_IINPUTDRIVER_H_
|
#define SRC_INPUT_IINPUTDRIVER_H_
|
||||||
|
|
||||||
#include "input/IEventHandler.h"
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <boost/optional.hpp>
|
||||||
|
|
||||||
|
#include "input/IEventHandler.h"
|
||||||
|
|
||||||
namespace flippR_driver
|
namespace flippR_driver
|
||||||
{
|
{
|
||||||
@@ -23,7 +25,7 @@ namespace input
|
|||||||
|
|
||||||
virtual void unregister_event_handler(IEventHandler *handler) = 0;
|
virtual void unregister_event_handler(IEventHandler *handler) = 0;
|
||||||
|
|
||||||
virtual std::shared_ptr<Event> get_event(std::string name) = 0;
|
virtual boost::optional<std::shared_ptr<Event>> get_event(std::string name) = 0;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,9 +42,9 @@ private:
|
|||||||
void check_inputs();
|
void check_inputs();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unique_ptr<IInputGPIOInterface> input_gpio_interface;
|
const std::unique_ptr<IInputGPIOInterface> input_gpio_interface;
|
||||||
|
|
||||||
std::vector<std::shared_ptr<DistributingEvent>> events;
|
const std::vector<std::shared_ptr<DistributingEvent>> events;
|
||||||
|
|
||||||
bool is_running;
|
bool is_running;
|
||||||
std::thread detect_thread;
|
std::thread detect_thread;
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ private:
|
|||||||
void distribute();
|
void distribute();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
std::chrono::milliseconds bounce_time;
|
const std::chrono::milliseconds bounce_time;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
enum ActivationState
|
enum ActivationState
|
||||||
@@ -36,7 +36,8 @@ private:
|
|||||||
FIRST_ACTIVATED,
|
FIRST_ACTIVATED,
|
||||||
ACTIVATED
|
ACTIVATED
|
||||||
};
|
};
|
||||||
std::shared_ptr<IEventNotifier> event_notifier;
|
|
||||||
|
const std::shared_ptr<IEventNotifier> event_notifier;
|
||||||
|
|
||||||
ActivationState activation_state;
|
ActivationState activation_state;
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
|
||||||
@@ -7,7 +7,6 @@
|
|||||||
#include "InputDriver.h"
|
#include "InputDriver.h"
|
||||||
|
|
||||||
#include "utility/config.h"
|
#include "utility/config.h"
|
||||||
#include "ErrorEvent.hpp"
|
|
||||||
|
|
||||||
namespace flippR_driver
|
namespace flippR_driver
|
||||||
{
|
{
|
||||||
@@ -31,18 +30,17 @@ void InputDriver::unregister_event_handler(IEventHandler *handler)
|
|||||||
this->event_notifier->unregister_event_handler(handler);
|
this->event_notifier->unregister_event_handler(handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<Event> InputDriver::get_event(std::string name)
|
boost::optional<std::shared_ptr<Event>> InputDriver::get_event(std::string name)
|
||||||
{
|
{
|
||||||
std::shared_ptr<Event> event(new ErrorEvent());
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
event = this->events.at(name);
|
return this->events.at(name);
|
||||||
}
|
}
|
||||||
catch(std::out_of_range &e)
|
catch(std::out_of_range &e)
|
||||||
{
|
{
|
||||||
CLOG_N_TIMES(1, WARNING, OUTPUT_LOGGER) << "Did not found event " << name << " please check config file!";
|
CLOG_N_TIMES(1, WARNING, OUTPUT_LOGGER) << "Did not found event " << name << " please check config file!";
|
||||||
}
|
}
|
||||||
return event;
|
return boost::optional<std::shared_ptr<Event>>{};
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,10 +7,11 @@
|
|||||||
#ifndef SRC_INPUT_INPUTDRIVER_H_
|
#ifndef SRC_INPUT_INPUTDRIVER_H_
|
||||||
#define SRC_INPUT_INPUTDRIVER_H_
|
#define SRC_INPUT_INPUTDRIVER_H_
|
||||||
|
|
||||||
|
#include "input/IInputDriver.h"
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
#include "IEventNotifier.h"
|
#include "IEventNotifier.h"
|
||||||
#include "input/IInputDriver.h"
|
|
||||||
#include "IDetector.h"
|
#include "IDetector.h"
|
||||||
|
|
||||||
namespace flippR_driver
|
namespace flippR_driver
|
||||||
@@ -27,13 +28,13 @@ public:
|
|||||||
void register_event_handler(IEventHandler* handler) override;
|
void register_event_handler(IEventHandler* handler) override;
|
||||||
void unregister_event_handler(IEventHandler* handler) override;
|
void unregister_event_handler(IEventHandler* handler) override;
|
||||||
|
|
||||||
std::shared_ptr<Event> get_event(std::string name) override;
|
boost::optional<std::shared_ptr<Event>> get_event(std::string name) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<IEventNotifier> event_notifier;
|
const std::shared_ptr<IEventNotifier> event_notifier;
|
||||||
std::unique_ptr<IDetector> detector;
|
const std::unique_ptr<IDetector> detector;
|
||||||
|
|
||||||
std::map<std::string, std::shared_ptr<Event>> events;
|
const std::map<std::string, std::shared_ptr<Event>> events;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,8 +53,6 @@ void InputGPIOInterface::write_col(char data) const
|
|||||||
write_pin(this->pins.at("col_address_C"), data & 0b100);
|
write_pin(this->pins.at("col_address_C"), data & 0b100);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void InputGPIOInterface::init_pins() const
|
void InputGPIOInterface::init_pins() const
|
||||||
{
|
{
|
||||||
initialize_output_pin(this->pins.at("col_address_A"));
|
initialize_output_pin(this->pins.at("col_address_A"));
|
||||||
|
|||||||
@@ -18,8 +18,8 @@
|
|||||||
#include "input/IEventNotifier.h"
|
#include "input/IEventNotifier.h"
|
||||||
#include "input/DistributingEvent.h"
|
#include "input/DistributingEvent.h"
|
||||||
#include "input/Detector.h"
|
#include "input/Detector.h"
|
||||||
|
#include "input/IInputGPIOInterface.h"
|
||||||
#include "utility/LoggerFactory.h"
|
#include "utility/LoggerFactory.h"
|
||||||
#include "utility/InputGPIOInterface.h"
|
|
||||||
|
|
||||||
|
|
||||||
using namespace fakeit;
|
using namespace fakeit;
|
||||||
|
|||||||
Reference in New Issue
Block a user