This commit is contained in:
Neeflix
2018-09-13 23:41:09 +02:00
31 changed files with 123 additions and 62 deletions

View File

@@ -2,6 +2,7 @@
option(BUILD_SHARED_LIB "Build a shared lib instead of a static." OFF)
option(ENABLE_TESTING "Enables testing." ON)
option(CROSS_COMPILE "Enables crosscompiling for raspberry pi" OFF)
option(BUILD_CLI "Makes a basic testing cli" OFF)
#################### CONFIGURATION ######################
set(OUTPUT_PATH bin)
@@ -143,4 +144,8 @@ target_link_libraries(${PROJECT_NAME} PRIVATE ${Threads_LIBRARIES})
if(ENABLE_TESTING)
add_subdirectory(tests)
endif(ENABLE_TESTING)
if(BUILD_CLI)
add_subdirectory(cli)
endif(BUILD_CLI)
####################### END_CMAKE ########################

View File

@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.6.2)
project(FlippR_Driver_CLI)
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/${OUTPUT_PATH}/cli)
add_executable(${PROJECT_NAME} main.cpp)
target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/include)
target_link_libraries(${PROJECT_NAME} PRIVATE FlippR-Driver)

View File

@@ -0,0 +1,31 @@
//
// Created by rhetenor on 13.09.18.
//
#include <iostream>
#include <fstream>
#include "DriverFactory.h"
#include "IInputDriver.h"
int main (int argc, char *argv[])
{
if(argc != 2)
{
std::cout << "Usage: " << argv[0] << " <config_file>";
}
std::string config_file = argv[1];
std::ifstream config;
try
{
config.open(config_file);
}
catch(const std::exception& e)
{
std::cout << e.what();
exit(1);
}
}

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

@@ -11,9 +11,8 @@
#include <set>
#include <string>
#include "utilities/config.h"
namespace Input
namespace FlippR_Driver::Input
{
class Event

View File

@@ -8,14 +8,14 @@
#ifndef SRC_IEVENTHANDLER_H_
#define SRC_IEVENTHANDLER_H_
#include "input/Event.h"
#include "Event.h"
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_ */

View File

@@ -8,10 +8,10 @@
#ifndef SRC_INPUT_IINPUTDRIVER_H_
#define SRC_INPUT_IINPUTDRIVER_H_
#include "utilities/IEventHandler.h"
#include "input/IEventNotifier.h"
#include "IEventHandler.h"
#include <memory>
namespace Input {
namespace FlippR_Driver::Input {
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"
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) :

View File

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

View File

@@ -10,14 +10,14 @@
#include "Event.h"
namespace Input
namespace FlippR_Driver::Input
{
class ErrorEvent : public Event
{
public:
ErrorEvent() :
Event(0, HIGHEST_INPUT_EVENT_PRIORITY, "ERROR")
Event(0, 0, "ERROR")
{}
};
}

View File

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

View File

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

View File

@@ -14,11 +14,11 @@
#include "IInputDriver.h"
#include "utilities/IEventHandler.h"
#include "IEventHandler.h"
#include "utilities/config.h"
#include "Event.h"
namespace Input
namespace FlippR_Driver::Input
{
class EventHandler;

View File

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

View File

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

View File

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

View File

@@ -9,9 +9,10 @@
#define SRC_INPUT_IEVENTNOTIFIER_H_
#include "Event.h"
#include "utilities/IEventHandler.h"
#include "IEventHandler.h"
#include <memory>
namespace Input
namespace FlippR_Driver::Input
{
class IEventNotifier

View File

@@ -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) :

View File

@@ -9,10 +9,11 @@
#include "utilities/config.h"
#include "IEventNotifier.h"
#include "IInputDriver.h"
#include "IDetector.h"
namespace Input
namespace FlippR_Driver::Input
{
class InputDriver : public IInputDriver

View File

@@ -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();

View File

@@ -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);

View File

@@ -16,14 +16,14 @@
#define private public
#include "input/IEventNotifier.h"
#include "input/Event.h"
#include "Event.h"
#include "input/Detector.h"
#include "utilities/LoggerFactory.hpp"
#include "utilities/InputGPIOInterface.h"
using namespace fakeit;
using namespace Input;
using namespace FlippR_Driver::Input;
SCENARIO("Creating a Detector object", "")

View File

@@ -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")
{

View File

@@ -11,7 +11,7 @@
#include "utilities/LoggerFactory.hpp"
#include "utilities/IEventHandler.h"
#include "IEventHandler.h"
#include "utilities/IBlockingQueue.h"
@@ -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]")

View File

@@ -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());

View File

@@ -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")

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;