refactored namespaces and added driverfactory

This commit is contained in:
Jonas Zeunert
2018-09-13 23:05:49 +02:00
parent 7b3327f5ef
commit 9f0bad92a1
29 changed files with 68 additions and 55 deletions

View File

@@ -4,7 +4,7 @@
#include <iostream> #include <iostream>
#include <fstream> #include <fstream>
#include "IInputDriverFactory.h" #include "DriverFactory.h"
#include "IInputDriver.h" #include "IInputDriver.h"
int main (int argc, char *argv[]) int main (int argc, char *argv[])
@@ -28,5 +28,4 @@ int main (int argc, char *argv[])
} }

View 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

View File

@@ -12,7 +12,7 @@
#include <string> #include <string>
namespace Input namespace FlippR_Driver::Input
{ {
class Event class Event

View File

@@ -15,7 +15,7 @@ class IEventHandler
public: public:
virtual ~IEventHandler(){}; virtual ~IEventHandler(){};
virtual void handle(Input::Event& event) = 0; virtual void handle(FlippR_Driver::Input::Event& event) = 0;
}; };
#endif /* SRC_IEVENTHANDLER_H_ */ #endif /* SRC_IEVENTHANDLER_H_ */

View File

@@ -11,7 +11,7 @@
#include "IEventHandler.h" #include "IEventHandler.h"
#include <memory> #include <memory>
namespace Input { namespace FlippR_Driver::Input {
class IInputDriver class IInputDriver
{ {

View File

@@ -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_ */

View 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);
}
}

View File

@@ -12,7 +12,7 @@
#include "utilities/config.h" #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) : Detector::Detector(std::unique_ptr<IInputGPIOInterface> input_gpio_interface, std::map<char, std::shared_ptr<Event>> events, std::shared_ptr<IEventNotifier> event_notifier) :

View File

@@ -24,7 +24,7 @@
#include "Event.h" #include "Event.h"
#include "IEventNotifier.h" #include "IEventNotifier.h"
namespace Input namespace FlippR_Driver::Input
{ {
class Detector : public IDetector class Detector : public IDetector

View File

@@ -10,7 +10,7 @@
#include "Event.h" #include "Event.h"
namespace Input namespace FlippR_Driver::Input
{ {
class ErrorEvent : public Event class ErrorEvent : public Event

View File

@@ -8,7 +8,7 @@
#include "utilities/config.h" #include "utilities/config.h"
namespace Input namespace FlippR_Driver::Input
{ {
Event::Event(char address, int priority, std::string name) : Event::Event(char address, int priority, std::string name) :

View File

@@ -6,7 +6,7 @@
*/ */
#include "EventHandler.h" #include "EventHandler.h"
namespace Input namespace FlippR_Driver::Input
{ {
EventHandler::EventHandler(std::shared_ptr<IInputDriver> input_driver) : EventHandler::EventHandler(std::shared_ptr<IInputDriver> input_driver) :

View File

@@ -18,7 +18,7 @@
#include "utilities/config.h" #include "utilities/config.h"
#include "Event.h" #include "Event.h"
namespace Input namespace FlippR_Driver::Input
{ {
class EventHandler; class EventHandler;

View File

@@ -11,7 +11,7 @@
#include "EventNotifier.h" #include "EventNotifier.h"
namespace Input namespace FlippR_Driver::Input
{ {
EventNotifier::EventNotifier(IBlockingQueue<Event>* queue) : EventNotifier::EventNotifier(IBlockingQueue<Event>* queue) :

View File

@@ -21,7 +21,7 @@
#define HANDLER_TIMEOUT 2000 #define HANDLER_TIMEOUT 2000
namespace Input namespace FlippR_Driver::Input
{ {
class EventNotifier : public IEventNotifier class EventNotifier : public IEventNotifier

View File

@@ -9,7 +9,7 @@
#define SRC_INPUT_IDETECTOR_H_ #define SRC_INPUT_IDETECTOR_H_
namespace Input namespace FlippR_Driver::Input
{ {
class IDetector class IDetector

View File

@@ -12,7 +12,7 @@
#include "IEventHandler.h" #include "IEventHandler.h"
#include <memory> #include <memory>
namespace Input namespace FlippR_Driver::Input
{ {
class IEventNotifier class IEventNotifier

View File

@@ -7,7 +7,7 @@
#include <input/ErrorEvent.hpp> #include <input/ErrorEvent.hpp>
#include "InputDriver.h" #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) : InputDriver::InputDriver(std::shared_ptr<IEventNotifier> event_notifier, std::unique_ptr<IDetector> detector, std::map<std::string, std::shared_ptr<Event>> events) :

View File

@@ -13,7 +13,7 @@
#include "IInputDriver.h" #include "IInputDriver.h"
#include "IDetector.h" #include "IDetector.h"
namespace Input namespace FlippR_Driver::Input
{ {
class InputDriver : public IInputDriver class InputDriver : public IInputDriver

View File

@@ -7,16 +7,17 @@
#include "InputDriverFactory.h" #include "InputDriverFactory.h"
#include "InputDriver.h"
#include "utilities/LoggerFactory.hpp" #include "utilities/LoggerFactory.hpp"
#include "EventNotifier.h" #include "EventNotifier.h"
using namespace nlohmann; 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(); LoggerFactory::CreateInputLogger();

View File

@@ -12,7 +12,7 @@
#include <atomic> #include <atomic>
#include "Detector.h" #include "Detector.h"
#include "InputDriver.h" #include "IInputDriver.h"
#include "utilities/InputGPIOInterface.h" #include "utilities/InputGPIOInterface.h"
#include "utilities/config.h" #include "utilities/config.h"
@@ -24,13 +24,13 @@
INITIALIZE_EASYLOGGINGPP INITIALIZE_EASYLOGGINGPP
namespace Input namespace FlippR_Driver::Input
{ {
class InputDriverFactory class InputDriverFactory
{ {
public: 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: 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); 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);

View File

@@ -23,7 +23,7 @@
using namespace fakeit; using namespace fakeit;
using namespace Input; using namespace FlippR_Driver::Input;
SCENARIO("Creating a Detector object", "") SCENARIO("Creating a Detector object", "")

View File

@@ -25,15 +25,15 @@ SCENARIO("An EventHandler gets created", "[construction}")
{ {
LoggerFactory::CreateInputTestLogger(); LoggerFactory::CreateInputTestLogger();
Mock<Input::IInputDriver> input_driver_mock; Mock<FlippR_Driver::Input::IInputDriver> input_driver_mock;
Fake(Dtor(input_driver_mock)); Fake(Dtor(input_driver_mock));
When(Method(input_driver_mock, register_event_handler)).AlwaysReturn(); When(Method(input_driver_mock, register_event_handler)).AlwaysReturn();
When(Method(input_driver_mock, unregister_event_handler)).AlwaysReturn(); When(Method(input_driver_mock, unregister_event_handler)).AlwaysReturn();
WHEN("the event handler gets created") WHEN("the event handler gets created")
{ {
std::shared_ptr<Input::IInputDriver> driver_ptr(&input_driver_mock.get()); std::shared_ptr<FlippR_Driver::Input::IInputDriver> driver_ptr(&input_driver_mock.get());
Input::EventHandler handler(driver_ptr); FlippR_Driver::Input::EventHandler handler(driver_ptr);
THEN("It should register itself at the input_driver") THEN("It should register itself at the input_driver")
{ {

View File

@@ -20,7 +20,7 @@
#include "input/EventNotifier.h" #include "input/EventNotifier.h"
using namespace Input; using namespace FlippR_Driver::Input;
using namespace fakeit; using namespace fakeit;
SCENARIO("An EventNotifier gets created", "[construction]") SCENARIO("An EventNotifier gets created", "[construction]")

View File

@@ -19,7 +19,7 @@
using namespace fakeit; using namespace fakeit;
using namespace Input; using namespace FlippR_Driver::Input;
SCENARIO("An InputDriver gets created", "[construction}") SCENARIO("An InputDriver gets created", "[construction}")
{ {
@@ -56,14 +56,14 @@ SCENARIO("An EventHandler [un]registers at the driver", "[un-register]")
{ {
LoggerFactory::CreateInputTestLogger(); LoggerFactory::CreateInputTestLogger();
Mock<Input::IDetector> detector_mock; Mock<FlippR_Driver::Input::IDetector> detector_mock;
Fake(Dtor(detector_mock)); Fake(Dtor(detector_mock));
Mock<IEventHandler> event_handler_mock; Mock<IEventHandler> event_handler_mock;
Fake(Method(event_handler_mock, handle)); Fake(Method(event_handler_mock, handle));
Fake(Dtor(event_handler_mock)); 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, register_event_handler));
Fake(Method(event_notifier_mock, unregister_event_handler)); Fake(Method(event_notifier_mock, unregister_event_handler));
Fake(Dtor(event_notifier_mock)); Fake(Dtor(event_notifier_mock));
@@ -103,13 +103,13 @@ SCENARIO("An Input Driver is created normally", "")
{ {
LoggerFactory::CreateInputTestLogger(); LoggerFactory::CreateInputTestLogger();
Mock<Input::IDetector> detector_mock; Mock<FlippR_Driver::Input::IDetector> detector_mock;
Fake(Dtor(detector_mock)); Fake(Dtor(detector_mock));
Mock<IEventHandler> event_handler_mock; Mock<IEventHandler> event_handler_mock;
Fake(Dtor(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)); Fake(Dtor(event_notifier_mock));
std::shared_ptr<IEventNotifier> event_notifier_ptr(&event_notifier_mock.get()); std::shared_ptr<IEventNotifier> event_notifier_ptr(&event_notifier_mock.get());

View File

@@ -16,7 +16,7 @@
#include "input/EventNotifier.h" #include "input/EventNotifier.h"
using namespace Input; using namespace FlippR_Driver::Input;
using namespace fakeit; using namespace fakeit;
SCENARIO("The factory creates a InputDriver") SCENARIO("The factory creates a InputDriver")

View File

@@ -8,7 +8,7 @@
#ifndef SRC_TESTS_INPUT_MOCKS_EVENTHANDLERMOCK_HPP_ #ifndef SRC_TESTS_INPUT_MOCKS_EVENTHANDLERMOCK_HPP_
#define SRC_TESTS_INPUT_MOCKS_EVENTHANDLERMOCK_HPP_ #define SRC_TESTS_INPUT_MOCKS_EVENTHANDLERMOCK_HPP_
namespace Input namespace FlippR_Driver::Input
{ {
class EventHandler; class EventHandler;
class Event; class Event;

View File

@@ -8,7 +8,7 @@
#ifndef SRC_TESTS_INPUT_MOCKS_EVENTNOTIFIERMOCK_HPP_ #ifndef SRC_TESTS_INPUT_MOCKS_EVENTNOTIFIERMOCK_HPP_
#define SRC_TESTS_INPUT_MOCKS_EVENTNOTIFIERMOCK_HPP_ #define SRC_TESTS_INPUT_MOCKS_EVENTNOTIFIERMOCK_HPP_
namespace Input namespace FlippR_Driver::Input
{ {
class EventNotifier; class EventNotifier;
class EventHandler; class EventHandler;

View File

@@ -8,7 +8,7 @@
#ifndef SRC_TESTS_INPUT_MOCKS_INPUTDRIVERMOCK_HPP_ #ifndef SRC_TESTS_INPUT_MOCKS_INPUTDRIVERMOCK_HPP_
#define SRC_TESTS_INPUT_MOCKS_INPUTDRIVERMOCK_HPP_ #define SRC_TESTS_INPUT_MOCKS_INPUTDRIVERMOCK_HPP_
namespace Input namespace FlippR_Driver::Input
{ {
class InputDriver; class InputDriver;
class EventHandler; class EventHandler;