refactored namespaces and added driverfactory
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
#include "IInputDriverFactory.h"
|
||||
#include "DriverFactory.h"
|
||||
#include "IInputDriver.h"
|
||||
|
||||
int main (int argc, char *argv[])
|
||||
@@ -28,5 +28,4 @@ int main (int argc, char *argv[])
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
18
FlippR-Driver/include/DriverFactory.h
Normal file
18
FlippR-Driver/include/DriverFactory.h
Normal file
@@ -0,0 +1,18 @@
|
||||
//
|
||||
// Created by rhetenor on 13.09.18.
|
||||
//
|
||||
|
||||
#ifndef FLIPPR_DRIVER_DRIVERFACTORY_H
|
||||
#define FLIPPR_DRIVER_DRIVERFACTORY_H
|
||||
|
||||
#include <fstream>
|
||||
#include <memory>
|
||||
|
||||
#include "IInputDriver.h"
|
||||
|
||||
namespace FlippR_Driver
|
||||
{
|
||||
static std::shared_ptr<FlippR_Driver::Input::IInputDriver> get_InputDriver(std::istream& input_config_stream, std::istream& matrix_config_stream);
|
||||
}
|
||||
|
||||
#endif //FLIPPR_DRIVER_DRIVERFACTORY_H
|
||||
@@ -12,7 +12,7 @@
|
||||
#include <string>
|
||||
|
||||
|
||||
namespace Input
|
||||
namespace FlippR_Driver::Input
|
||||
{
|
||||
|
||||
class Event
|
||||
|
||||
@@ -15,7 +15,7 @@ class IEventHandler
|
||||
public:
|
||||
virtual ~IEventHandler(){};
|
||||
|
||||
virtual void handle(Input::Event& event) = 0;
|
||||
virtual void handle(FlippR_Driver::Input::Event& event) = 0;
|
||||
};
|
||||
|
||||
#endif /* SRC_IEVENTHANDLER_H_ */
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
#include "IEventHandler.h"
|
||||
#include <memory>
|
||||
|
||||
namespace Input {
|
||||
namespace FlippR_Driver::Input {
|
||||
|
||||
class IInputDriver
|
||||
{
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
/*
|
||||
* IInputDriverFactory.h
|
||||
*
|
||||
* Created on: Jun 13, 2018
|
||||
* Author: Andreas Schneider, Johannes Wendel, Jonas Zeunert, Rafael Vinci, Dr. Franca Rupprecht
|
||||
*/
|
||||
|
||||
#ifndef SRC_INPUT_IINPUTDRIVERFACTORY_H_
|
||||
#define SRC_INPUT_IINPUTDRIVERFACTORY_H_
|
||||
|
||||
namespace Input {
|
||||
|
||||
class IInputDriverFactory
|
||||
{
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
#endif /* SRC_INPUT_IINPUTDRIVERFACTORY_H_ */
|
||||
14
FlippR-Driver/src/DriverFactory.cpp
Normal file
14
FlippR-Driver/src/DriverFactory.cpp
Normal file
@@ -0,0 +1,14 @@
|
||||
//
|
||||
// Created by rhetenor on 13.09.18.
|
||||
//
|
||||
|
||||
#include "DriverFactory.h"
|
||||
#include "input/InputDriverFactory.h"
|
||||
|
||||
namespace FlippR_Driver
|
||||
{
|
||||
static std::shared_ptr<FlippR_Driver::Input::IInputDriver> get_InputDriver(std::istream& input_config_stream, std::istream& matrix_config_stream)
|
||||
{
|
||||
return FlippR_Driver::Input::InputDriverFactory::get_InputDriver(input_config_stream, matrix_config_stream);
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,7 @@
|
||||
|
||||
#include "utilities/config.h"
|
||||
|
||||
namespace Input
|
||||
namespace FlippR_Driver::Input
|
||||
{
|
||||
|
||||
Detector::Detector(std::unique_ptr<IInputGPIOInterface> input_gpio_interface, std::map<char, std::shared_ptr<Event>> events, std::shared_ptr<IEventNotifier> event_notifier) :
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
#include "Event.h"
|
||||
#include "IEventNotifier.h"
|
||||
|
||||
namespace Input
|
||||
namespace FlippR_Driver::Input
|
||||
{
|
||||
|
||||
class Detector : public IDetector
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
|
||||
#include "Event.h"
|
||||
|
||||
namespace Input
|
||||
namespace FlippR_Driver::Input
|
||||
{
|
||||
|
||||
class ErrorEvent : public Event
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
#include "utilities/config.h"
|
||||
|
||||
namespace Input
|
||||
namespace FlippR_Driver::Input
|
||||
{
|
||||
|
||||
Event::Event(char address, int priority, std::string name) :
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
*/
|
||||
#include "EventHandler.h"
|
||||
|
||||
namespace Input
|
||||
namespace FlippR_Driver::Input
|
||||
{
|
||||
|
||||
EventHandler::EventHandler(std::shared_ptr<IInputDriver> input_driver) :
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
#include "utilities/config.h"
|
||||
#include "Event.h"
|
||||
|
||||
namespace Input
|
||||
namespace FlippR_Driver::Input
|
||||
{
|
||||
class EventHandler;
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
|
||||
#include "EventNotifier.h"
|
||||
|
||||
namespace Input
|
||||
namespace FlippR_Driver::Input
|
||||
{
|
||||
|
||||
EventNotifier::EventNotifier(IBlockingQueue<Event>* queue) :
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
|
||||
#define HANDLER_TIMEOUT 2000
|
||||
|
||||
namespace Input
|
||||
namespace FlippR_Driver::Input
|
||||
{
|
||||
|
||||
class EventNotifier : public IEventNotifier
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
#define SRC_INPUT_IDETECTOR_H_
|
||||
|
||||
|
||||
namespace Input
|
||||
namespace FlippR_Driver::Input
|
||||
{
|
||||
|
||||
class IDetector
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
#include "IEventHandler.h"
|
||||
#include <memory>
|
||||
|
||||
namespace Input
|
||||
namespace FlippR_Driver::Input
|
||||
{
|
||||
|
||||
class IEventNotifier
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#include <input/ErrorEvent.hpp>
|
||||
#include "InputDriver.h"
|
||||
|
||||
namespace Input
|
||||
namespace FlippR_Driver::Input
|
||||
{
|
||||
|
||||
InputDriver::InputDriver(std::shared_ptr<IEventNotifier> event_notifier, std::unique_ptr<IDetector> detector, std::map<std::string, std::shared_ptr<Event>> events) :
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
#include "IInputDriver.h"
|
||||
#include "IDetector.h"
|
||||
|
||||
namespace Input
|
||||
namespace FlippR_Driver::Input
|
||||
{
|
||||
|
||||
class InputDriver : public IInputDriver
|
||||
|
||||
@@ -7,16 +7,17 @@
|
||||
|
||||
|
||||
#include "InputDriverFactory.h"
|
||||
#include "InputDriver.h"
|
||||
#include "utilities/LoggerFactory.hpp"
|
||||
#include "EventNotifier.h"
|
||||
|
||||
using namespace nlohmann;
|
||||
|
||||
|
||||
namespace Input
|
||||
namespace FlippR_Driver::Input
|
||||
{
|
||||
|
||||
std::shared_ptr<InputDriver> InputDriverFactory::get_InputDriver(std::istream& input_config_stream, std::istream& matrix_config_stream)
|
||||
std::shared_ptr<IInputDriver> InputDriverFactory::get_InputDriver(std::istream& input_config_stream, std::istream& matrix_config_stream)
|
||||
{
|
||||
LoggerFactory::CreateInputLogger();
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
#include <atomic>
|
||||
|
||||
#include "Detector.h"
|
||||
#include "InputDriver.h"
|
||||
#include "IInputDriver.h"
|
||||
|
||||
#include "utilities/InputGPIOInterface.h"
|
||||
#include "utilities/config.h"
|
||||
@@ -24,13 +24,13 @@
|
||||
|
||||
INITIALIZE_EASYLOGGINGPP
|
||||
|
||||
namespace Input
|
||||
namespace FlippR_Driver::Input
|
||||
{
|
||||
class InputDriverFactory
|
||||
{
|
||||
|
||||
public:
|
||||
static std::shared_ptr<InputDriver> get_InputDriver(std::istream& input_config_stream, std::istream& matrix_config_stream);
|
||||
static std::shared_ptr<IInputDriver> get_InputDriver(std::istream& input_config_stream, std::istream& matrix_config_stream);
|
||||
|
||||
private:
|
||||
static void create_input_events(nlohmann::json matrix_config, std::map<char, std::shared_ptr<Event>> address_event_map, std::map<std::string, std::shared_ptr<Event>> name_event_map);
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
|
||||
|
||||
using namespace fakeit;
|
||||
using namespace Input;
|
||||
using namespace FlippR_Driver::Input;
|
||||
|
||||
|
||||
SCENARIO("Creating a Detector object", "")
|
||||
|
||||
@@ -25,15 +25,15 @@ SCENARIO("An EventHandler gets created", "[construction}")
|
||||
{
|
||||
LoggerFactory::CreateInputTestLogger();
|
||||
|
||||
Mock<Input::IInputDriver> input_driver_mock;
|
||||
Mock<FlippR_Driver::Input::IInputDriver> input_driver_mock;
|
||||
Fake(Dtor(input_driver_mock));
|
||||
When(Method(input_driver_mock, register_event_handler)).AlwaysReturn();
|
||||
When(Method(input_driver_mock, unregister_event_handler)).AlwaysReturn();
|
||||
|
||||
WHEN("the event handler gets created")
|
||||
{
|
||||
std::shared_ptr<Input::IInputDriver> driver_ptr(&input_driver_mock.get());
|
||||
Input::EventHandler handler(driver_ptr);
|
||||
std::shared_ptr<FlippR_Driver::Input::IInputDriver> driver_ptr(&input_driver_mock.get());
|
||||
FlippR_Driver::Input::EventHandler handler(driver_ptr);
|
||||
|
||||
THEN("It should register itself at the input_driver")
|
||||
{
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
|
||||
#include "input/EventNotifier.h"
|
||||
|
||||
using namespace Input;
|
||||
using namespace FlippR_Driver::Input;
|
||||
using namespace fakeit;
|
||||
|
||||
SCENARIO("An EventNotifier gets created", "[construction]")
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
|
||||
|
||||
using namespace fakeit;
|
||||
using namespace Input;
|
||||
using namespace FlippR_Driver::Input;
|
||||
|
||||
SCENARIO("An InputDriver gets created", "[construction}")
|
||||
{
|
||||
@@ -56,14 +56,14 @@ SCENARIO("An EventHandler [un]registers at the driver", "[un-register]")
|
||||
{
|
||||
LoggerFactory::CreateInputTestLogger();
|
||||
|
||||
Mock<Input::IDetector> detector_mock;
|
||||
Mock<FlippR_Driver::Input::IDetector> detector_mock;
|
||||
Fake(Dtor(detector_mock));
|
||||
|
||||
Mock<IEventHandler> event_handler_mock;
|
||||
Fake(Method(event_handler_mock, handle));
|
||||
Fake(Dtor(event_handler_mock));
|
||||
|
||||
Mock<Input::IEventNotifier> event_notifier_mock;
|
||||
Mock<FlippR_Driver::Input::IEventNotifier> event_notifier_mock;
|
||||
Fake(Method(event_notifier_mock, register_event_handler));
|
||||
Fake(Method(event_notifier_mock, unregister_event_handler));
|
||||
Fake(Dtor(event_notifier_mock));
|
||||
@@ -103,13 +103,13 @@ SCENARIO("An Input Driver is created normally", "")
|
||||
{
|
||||
LoggerFactory::CreateInputTestLogger();
|
||||
|
||||
Mock<Input::IDetector> detector_mock;
|
||||
Mock<FlippR_Driver::Input::IDetector> detector_mock;
|
||||
Fake(Dtor(detector_mock));
|
||||
|
||||
Mock<IEventHandler> event_handler_mock;
|
||||
Fake(Dtor(event_handler_mock));
|
||||
|
||||
Mock<Input::IEventNotifier> event_notifier_mock;
|
||||
Mock<FlippR_Driver::Input::IEventNotifier> event_notifier_mock;
|
||||
Fake(Dtor(event_notifier_mock));
|
||||
|
||||
std::shared_ptr<IEventNotifier> event_notifier_ptr(&event_notifier_mock.get());
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
#include "input/EventNotifier.h"
|
||||
|
||||
using namespace Input;
|
||||
using namespace FlippR_Driver::Input;
|
||||
using namespace fakeit;
|
||||
|
||||
SCENARIO("The factory creates a InputDriver")
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#ifndef SRC_TESTS_INPUT_MOCKS_EVENTHANDLERMOCK_HPP_
|
||||
#define SRC_TESTS_INPUT_MOCKS_EVENTHANDLERMOCK_HPP_
|
||||
|
||||
namespace Input
|
||||
namespace FlippR_Driver::Input
|
||||
{
|
||||
class EventHandler;
|
||||
class Event;
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#ifndef SRC_TESTS_INPUT_MOCKS_EVENTNOTIFIERMOCK_HPP_
|
||||
#define SRC_TESTS_INPUT_MOCKS_EVENTNOTIFIERMOCK_HPP_
|
||||
|
||||
namespace Input
|
||||
namespace FlippR_Driver::Input
|
||||
{
|
||||
class EventNotifier;
|
||||
class EventHandler;
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#ifndef SRC_TESTS_INPUT_MOCKS_INPUTDRIVERMOCK_HPP_
|
||||
#define SRC_TESTS_INPUT_MOCKS_INPUTDRIVERMOCK_HPP_
|
||||
|
||||
namespace Input
|
||||
namespace FlippR_Driver::Input
|
||||
{
|
||||
class InputDriver;
|
||||
class EventHandler;
|
||||
|
||||
Reference in New Issue
Block a user