uh the fucking tests are fucking compiling :sigh: ♿ fuck itgit add *git add *git add *git add *git add *
This commit is contained in:
@@ -4,6 +4,7 @@ project(flippr-driver)
|
|||||||
set(CMAKE_BUILD_TYPE Debug)
|
set(CMAKE_BUILD_TYPE Debug)
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") # enable C++11 standard
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") # enable C++11 standard
|
||||||
|
|
||||||
|
add_definitions(-lcrypt)
|
||||||
set(CMAKE_BINARY_DIR ${CMAKE_SOURCE_DIR}/bin)
|
set(CMAKE_BINARY_DIR ${CMAKE_SOURCE_DIR}/bin)
|
||||||
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR})
|
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR})
|
||||||
set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR})
|
set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR})
|
||||||
@@ -18,37 +19,40 @@ add_library(libwiringPi SHARED IMPORTED )
|
|||||||
set_property(TARGET libwiringPi PROPERTY IMPORTED_LOCATION ${LIB_DIR}/libwiringPi.so.2.44)
|
set_property(TARGET libwiringPi PROPERTY IMPORTED_LOCATION ${LIB_DIR}/libwiringPi.so.2.44)
|
||||||
set_property(TARGET libwiringPi PROPERTY INTERFACE_INCLUDE_DIRECTORIES /home/rhetenor/FlippR/flippr-code/FlippR-Driver/src/lib/wiringPi)
|
set_property(TARGET libwiringPi PROPERTY INTERFACE_INCLUDE_DIRECTORIES /home/rhetenor/FlippR/flippr-code/FlippR-Driver/src/lib/wiringPi)
|
||||||
|
|
||||||
find_package(Threads)
|
find_package(Threads REQUIRED)
|
||||||
find_package(Boost)
|
find_package(Boost COMPONENTS system thread timer chrono REQUIRED)
|
||||||
|
|
||||||
include_directories(${SOURCE_DIR}/input)
|
include_directories(${SOURCE_DIR}/input)
|
||||||
include_directories(${SOURCE_DIR}/output)
|
include_directories(${SOURCE_DIR}/output)
|
||||||
include_directories(${SOURCE_DIR}/lib)
|
include_directories(${SOURCE_DIR}/lib)
|
||||||
include_directories(${SOURCE_DIR}/utilities)
|
include_directories(${SOURCE_DIR}/utilities)
|
||||||
|
include_directories(${Boost_INCLUDE_DIRS})
|
||||||
|
|
||||||
file(GLOB SOURCES ${SOURCE_DIR}/*/*.?pp)
|
file(GLOB SOURCES ${SOURCE_DIR}/*/*.cpp)
|
||||||
|
|
||||||
add_library(flippr_driver STATIC ${SOURCES})
|
add_library(flippr_driver STATIC ${SOURCES})
|
||||||
|
|
||||||
|
target_link_libraries(flippr_driver ${CMAKE_THREAD_LIBS_INIT})
|
||||||
|
target_link_libraries(flippr_driver ${Boost_LIBRARIES})
|
||||||
target_link_libraries(flippr_driver libwiringPi)
|
target_link_libraries(flippr_driver libwiringPi)
|
||||||
target_link_libraries(flippr_driver Easylogging)
|
target_link_libraries(flippr_driver Easylogging)
|
||||||
|
|
||||||
# enable_testing(TRUE)
|
enable_testing(TRUE)
|
||||||
#
|
|
||||||
# Prepare "Catch" library for other executables
|
#Prepare "Catch" library for other executables
|
||||||
# set(CATCH_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../src/tests)
|
set(CATCH_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../src/tests)
|
||||||
# add_library(Catch INTERFACE)
|
add_library(Catch INTERFACE)
|
||||||
# target_include_directories(Catch INTERFACE ${CATCH_INCLUDE_DIR}/*)
|
target_include_directories(Catch INTERFACE ${CATCH_INCLUDE_DIR}/*)
|
||||||
#
|
|
||||||
# Make test executable
|
#Make test executable
|
||||||
# set(TEST_SOURCES ${SOURCE_DIR}/../tests)
|
set(TEST_SOURCES ${SOURCE_DIR}/../tests)
|
||||||
# include_directories(${TEST_SOURCES})
|
include_directories(${TEST_SOURCES})
|
||||||
#
|
|
||||||
# file(GLOB SOURCES ${TEST_SOURCES}/*/*.cpp)
|
file(GLOB SOURCES ${TEST_SOURCES}/*/*.cpp)
|
||||||
# file(GLOB HEADER_SOURCES ${TEST_SOURCES}/*/*.hpp)
|
file(GLOB HEADER_SOURCES ${TEST_SOURCES}/*/*.hpp)
|
||||||
#
|
|
||||||
# add_executable(tests ${SOURCES} ${HEADER_SOURCES})
|
add_executable(tests ${SOURCES} ${HEADER_SOURCES})
|
||||||
#
|
|
||||||
# target_link_libraries(tests Easylogging)
|
target_link_libraries(tests Easylogging)
|
||||||
# target_link_libraries(tests flippr_driver)
|
target_link_libraries(tests flippr_driver)
|
||||||
# target_link_libraries(tests Catch)
|
target_link_libraries(tests Catch)
|
||||||
|
|||||||
@@ -16,6 +16,13 @@
|
|||||||
|
|
||||||
#include "IDetector.h"
|
#include "IDetector.h"
|
||||||
|
|
||||||
|
#include <thread>
|
||||||
|
#include <map>
|
||||||
|
|
||||||
|
#include "../utilities/InputGPIOInterface.h"
|
||||||
|
#include "Event.h"
|
||||||
|
#include "IEventNotifier.h"
|
||||||
|
|
||||||
namespace Input
|
namespace Input
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|||||||
@@ -7,19 +7,14 @@
|
|||||||
#include "Event.h"
|
#include "Event.h"
|
||||||
|
|
||||||
using namespace Input;
|
using namespace Input;
|
||||||
Event::Event(char address, char priority, std::string name) :
|
|
||||||
address(address), priority(priority), name(name)
|
|
||||||
{
|
|
||||||
CLOG_IF(VLOG_IS_ON(HIGH_VERBOSITY), INFO, INPUT_LOGGER) << "Created event: " << name << ", address: " << address;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Event::operator==(const Event& other)
|
Event::Event(char address, char priority, std::string name) :
|
||||||
{
|
address(address), priority(priority), name(name)
|
||||||
return this->name == other.name;
|
{
|
||||||
}
|
CLOG_IF(VLOG_IS_ON(HIGH_VERBOSITY), INFO, INPUT_LOGGER) << "Created event: " << name << ", address: " << address;
|
||||||
|
}
|
||||||
friend bool operator<(const Event& left, const Event& right)
|
|
||||||
{
|
|
||||||
return left.priority < right.priority;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
bool Event::operator==(const Event& other)
|
||||||
|
{
|
||||||
|
return this->name == other.name;
|
||||||
|
}
|
||||||
|
|||||||
@@ -21,7 +21,10 @@ class Event
|
|||||||
public:
|
public:
|
||||||
Event(char address, char priority, std::string name);
|
Event(char address, char priority, std::string name);
|
||||||
bool operator==(const Event& other);
|
bool operator==(const Event& other);
|
||||||
friend bool operator<(const Event& left, const Event& right);
|
friend bool operator<(const Event& left, const Event& right)
|
||||||
|
{
|
||||||
|
return left.priority < right.priority;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
char address;
|
char address;
|
||||||
|
|||||||
@@ -16,14 +16,14 @@ using namespace Input;
|
|||||||
CLOG(INFO, INPUT_LOGGER) << "Created EventHandler";
|
CLOG(INFO, INPUT_LOGGER) << "Created EventHandler";
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual EventHandler::~EventHandler()
|
EventHandler::~EventHandler()
|
||||||
{
|
{
|
||||||
this->input_driver->unregister_event_handler(this);
|
this->input_driver->unregister_event_handler(this);
|
||||||
this->input_driver = NULL;
|
this->input_driver = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// This function is intended to be non pure, if it is called when the derived class doesn't exist anymore
|
// This function is intended to be non pure, if it is called when the derived class doesn't exist anymore
|
||||||
virtual void EventHandler::handle(Event& event)
|
void EventHandler::handle(Event& event)
|
||||||
{
|
{
|
||||||
CLOG(WARNING, INPUT_LOGGER) << "Called EventHandler parent class";
|
CLOG(WARNING, INPUT_LOGGER) << "Called EventHandler parent class";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
#include <thread>
|
#include <thread>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
|
|
||||||
#include "../utilities/BlockingQueue.h"
|
#include "../utilities/BlockingQueue.hpp"
|
||||||
#include "Event.h"
|
#include "Event.h"
|
||||||
#include "EventHandler.h"
|
#include "EventHandler.h"
|
||||||
|
|
||||||
|
|||||||
@@ -8,12 +8,6 @@
|
|||||||
#ifndef SRC_INPUT_IDETECTOR_H_
|
#ifndef SRC_INPUT_IDETECTOR_H_
|
||||||
#define SRC_INPUT_IDETECTOR_H_
|
#define SRC_INPUT_IDETECTOR_H_
|
||||||
|
|
||||||
#include <thread>
|
|
||||||
#include <map>
|
|
||||||
|
|
||||||
#include "../utilities/InputGPIOInterface.h"
|
|
||||||
#include "Event.h"
|
|
||||||
#include "EventNotifier.h"
|
|
||||||
|
|
||||||
namespace Input
|
namespace Input
|
||||||
{
|
{
|
||||||
@@ -22,7 +16,7 @@ class IDetector
|
|||||||
{
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual ~IDetector() = 0;
|
virtual ~IDetector(){};
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ namespace Input
|
|||||||
class IEventNotifier
|
class IEventNotifier
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual ~IEventNotifier() = 0;
|
virtual ~IEventNotifier(){};
|
||||||
|
|
||||||
virtual void register_event_handler(IEventHandler* handler) = 0;
|
virtual void register_event_handler(IEventHandler* handler) = 0;
|
||||||
virtual void unregister_event_handler(IEventHandler* handler) = 0;
|
virtual void unregister_event_handler(IEventHandler* handler) = 0;
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ namespace Input {
|
|||||||
class IInputDriver
|
class IInputDriver
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual ~IInputDriver() = 0;
|
virtual ~IInputDriver(){};
|
||||||
virtual void register_event_handler(IEventHandler* handler) = 0;
|
virtual void register_event_handler(IEventHandler* handler) = 0;
|
||||||
virtual void unregister_event_handler(IEventHandler* handler) = 0;
|
virtual void unregister_event_handler(IEventHandler* handler) = 0;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
#include "InputDriver.h"
|
#include "InputDriver.h"
|
||||||
|
|
||||||
using namespace Input;
|
using namespace Input;
|
||||||
|
|
||||||
InputDriver::InputDriver(IEventNotifier* event_notifier, IDetector* detector) :
|
InputDriver::InputDriver(IEventNotifier* event_notifier, IDetector* detector) :
|
||||||
event_notifier(event_notifier), detector(detector)
|
event_notifier(event_notifier), detector(detector)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -22,8 +22,8 @@ public:
|
|||||||
|
|
||||||
InputDriver(IEventNotifier* event_notifier, IDetector* detector);
|
InputDriver(IEventNotifier* event_notifier, IDetector* detector);
|
||||||
~InputDriver();
|
~InputDriver();
|
||||||
void register_event_handler(IEventHandler* handler);
|
virtual void register_event_handler(IEventHandler* handler) override;
|
||||||
void unregister_event_handler(IEventHandler* handler);
|
virtual void unregister_event_handler(IEventHandler* handler) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
IEventNotifier* event_notifier;
|
IEventNotifier* event_notifier;
|
||||||
|
|||||||
@@ -8,77 +8,71 @@
|
|||||||
|
|
||||||
#include "InputDriverFactory.h"
|
#include "InputDriverFactory.h"
|
||||||
|
|
||||||
#include "Detector.h"
|
#include "EventNotifier.h"
|
||||||
|
|
||||||
|
using namespace nlohmann;
|
||||||
using namespace Input;
|
using namespace Input;
|
||||||
|
|
||||||
static shared_ptr<IInputDriver*> InputDriverFactory::get_InputDriver(std::string& input_config_path, std::string& matrix_config_path)
|
std::shared_ptr<InputDriver> InputDriverFactory::get_InputDriver(std::string& input_config_path, std::string& matrix_config_path)
|
||||||
{
|
{
|
||||||
this->ConfigureLogger();
|
ConfigureLogger();
|
||||||
auto event_notifier = new EventNotifier();
|
auto event_notifier = new EventNotifier();
|
||||||
|
|
||||||
auto detector = this->get_detector(input_config_path, matrix_config_path);
|
auto detector = get_detector(input_config_path, matrix_config_path);
|
||||||
|
|
||||||
return shared_ptr<InputDriver*>(new InputDriver(event_notifier, detector));
|
return std::shared_ptr<InputDriver>(new InputDriver(event_notifier, detector));
|
||||||
}
|
}
|
||||||
|
|
||||||
static IDetector* get_detector(std::string& input_config_path, std::string& matrix_config_path)
|
Detector* InputDriverFactory::get_detector(std::string& input_config_path, std::string& matrix_config_path)
|
||||||
{
|
{
|
||||||
std::ifstream input_config_stream(input_config_path);
|
std::ifstream matrix_config_stream(matrix_config_path);
|
||||||
json input_config;
|
json matrix_config;
|
||||||
input_config << input_config_stream;
|
matrix_config_stream >> matrix_config;
|
||||||
|
|
||||||
std::ifstream matrix_config_stream(matrix_config_path);
|
auto input_gpio_interface = new InputGPIOInterface(input_config_path);
|
||||||
json matrix_config;
|
auto input_notifier = new EventNotifier();
|
||||||
matrix_config << matrix_config_stream;
|
|
||||||
|
std::map<char, Event> input_events = create_input_events(matrix_config);
|
||||||
auto input_gpio_interface = new InputGPIOInterface(input_config);
|
|
||||||
auto input_notifier = new InputEventNotifier();
|
return new Detector(input_gpio_interface, input_events, input_notifier);
|
||||||
|
}
|
||||||
std::map<char, Event> input_events = this->create_input_events(matrix_config);
|
|
||||||
|
std::map<char, Event> InputDriverFactory::create_input_events(json matrix_config)
|
||||||
return new Detector(input_gpio_interface, input_events, input_notifier);
|
{
|
||||||
}
|
std::map<char, Event> events;
|
||||||
|
|
||||||
static std::map<char, Event> InputDriverFactory::create_input_events(json matrix_config)
|
for(auto& json_event : matrix_config)
|
||||||
{
|
{
|
||||||
std::map<char, Event> events;
|
|
||||||
|
try
|
||||||
for(auto& json_event : matrix_config)
|
{
|
||||||
{
|
std::string name = json_event.at("name");
|
||||||
|
char address = json_event.at("address").get<json::number_integer_t>();
|
||||||
try
|
int priority = json_event.at("priority").get<json::number_integer_t>();
|
||||||
{
|
|
||||||
std::string name = json_event.at("name");
|
Event event(address, priority, name);
|
||||||
char address = json_event.at("address");
|
|
||||||
int priority = json_event.at("priority");
|
events.emplace(address, event);
|
||||||
|
}
|
||||||
Event event(address, priority, name);
|
catch(json::exception& e)
|
||||||
|
{
|
||||||
events.emplace(address, event);
|
CLOG(ERROR, INPUT_LOGGER) << "Matrix config-file corrupted: " << e.what();
|
||||||
}
|
exit(EXIT_FAILURE);
|
||||||
catch(json::exception& e)
|
}
|
||||||
{
|
}
|
||||||
CLOG(ERROR, INPUT_LOGGER) << "Matrix config-file corrupted: " << e.what();
|
|
||||||
exit(EXIT_FAILURE);
|
return events;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
void InputDriverFactory::ConfigureLogger()
|
||||||
return events;
|
{
|
||||||
}
|
el::Loggers::getLogger(INPUT_LOGGER);
|
||||||
|
|
||||||
static void InputDriverFactory::ConfigureLogger()
|
//TODO may configure?
|
||||||
{
|
el::Configurations conf;
|
||||||
el::Loggers::getLogger(INPUT_LOGGER);
|
conf.setToDefault();
|
||||||
|
conf.set(el::Level::Global, el::ConfigurationType::Filename, DRIVER_LOG_FILE);
|
||||||
//TODO may configure?
|
conf.set(el::Level::Global, el::ConfigurationType::Format, "%datetime [%level] [%func] : %msg");
|
||||||
el::Configurations conf;
|
|
||||||
conf.setToDefault();
|
el::Loggers::reconfigureLogger(INPUT_LOGGER, conf);
|
||||||
conf.set(el::Level::Global, el::ConfigurationType::Filename, DRIVER_LOG_FILE);
|
|
||||||
conf.set(el::Level::Global, el::ConfigurationType::Format, "%datetime [%level] [%func] : %msg");
|
|
||||||
|
|
||||||
el::Loggers::reconfigureLogger(INPUT_LOGGER, conf);
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,8 +9,10 @@
|
|||||||
#define INPUTFACTORY_H_
|
#define INPUTFACTORY_H_
|
||||||
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
#include <atomic>
|
||||||
|
|
||||||
#include "IDetector.h"
|
#include "Detector.h"
|
||||||
|
#include "InputDriver.h"
|
||||||
|
|
||||||
#include "../utilities/InputGPIOInterface.h"
|
#include "../utilities/InputGPIOInterface.h"
|
||||||
#include "../utilities/config.h"
|
#include "../utilities/config.h"
|
||||||
@@ -18,21 +20,21 @@
|
|||||||
#include "../lib/easylogging/easylogging++.h"
|
#include "../lib/easylogging/easylogging++.h"
|
||||||
#include "IEventNotifier.h"
|
#include "IEventNotifier.h"
|
||||||
|
|
||||||
using namespace nlohmann;
|
|
||||||
|
|
||||||
|
|
||||||
INITIALIZE_EASYLOGGINGPP
|
INITIALIZE_EASYLOGGINGPP
|
||||||
|
|
||||||
namespace Input
|
namespace Input
|
||||||
{
|
{
|
||||||
class InputFactory
|
class InputDriverFactory
|
||||||
{
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static shared_ptr<IInputDriver*> get_InputDriver(std::string& input_config_path, std::string& matrix_config_path);
|
static std::shared_ptr<InputDriver> get_InputDriver(std::string& input_config_path, std::string& matrix_config_path);
|
||||||
private:
|
private:
|
||||||
static IDetector* get_detector(std::string& input_config_path, std::string& matrix_config_path);
|
static Detector* get_detector(std::string& input_config_path, std::string& matrix_config_path);
|
||||||
static std::map<char, Event> create_input_events(json matrix_config);
|
static std::map<char, Event> create_input_events(nlohmann::json matrix_config);
|
||||||
static void ConfigureLogger();
|
static void ConfigureLogger();
|
||||||
|
};
|
||||||
|
}
|
||||||
#endif /* INPUTFACTORY_H_ */
|
#endif /* INPUTFACTORY_H_ */
|
||||||
|
|||||||
@@ -1,24 +0,0 @@
|
|||||||
/*
|
|
||||||
* EventHandler.cpp
|
|
||||||
*
|
|
||||||
* Created on: Jun 14, 2018
|
|
||||||
* Author: Andreas Schneider, Johannes Wendel, Jonas Zeunert, Rafael Vinci, Dr. Franca Rupprecht
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "EventHandler.h"
|
|
||||||
|
|
||||||
namespace output
|
|
||||||
{
|
|
||||||
|
|
||||||
EventHandler::EventHandler ()
|
|
||||||
{
|
|
||||||
// TODO Auto-generated constructor stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
EventHandler::~EventHandler ()
|
|
||||||
{
|
|
||||||
// TODO Auto-generated destructor stub
|
|
||||||
}
|
|
||||||
|
|
||||||
} /* namespace output */
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
/*
|
|
||||||
* EventHandler.h
|
|
||||||
*
|
|
||||||
* Created on: Jun 14, 2018
|
|
||||||
* Author: Andreas Schneider, Johannes Wendel, Jonas Zeunert, Rafael Vinci, Dr. Franca Rupprecht
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#include "../utilities/IEventHandler.h"
|
|
||||||
|
|
||||||
#ifndef SRC_OUTPUT_EVENTHANDLER_H_
|
|
||||||
#define SRC_OUTPUT_EVENTHANDLER_H_
|
|
||||||
|
|
||||||
namespace output
|
|
||||||
{
|
|
||||||
|
|
||||||
class EventHandler : public IEventHandler
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
EventHandler();
|
|
||||||
virtual ~EventHandler();
|
|
||||||
|
|
||||||
virtual void handle() override;
|
|
||||||
};
|
|
||||||
|
|
||||||
} /* namespace output */
|
|
||||||
|
|
||||||
#endif /* SRC_OUTPUT_EVENTHANDLER_H_ */
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
/*
|
|
||||||
* BlockingQueue.cpp
|
|
||||||
*
|
|
||||||
* Created on: Jun 15, 2018
|
|
||||||
* Author: Andreas Schneider, Johannes Wendel, Jonas Zeunert, Rafael Vinci, Dr. Franca Rupprecht
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "BlockingQueue.h"
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
void BlockingQueue<T>::push(T const& value)
|
|
||||||
{
|
|
||||||
std::unique_lock<std::mutex> lock(this->d_mutex);
|
|
||||||
p_queue.push(value);
|
|
||||||
this->d_condition.notify_one();
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
T BlockingQueue<T>::pop()
|
|
||||||
{
|
|
||||||
std::unique_lock<std::mutex> lock(this->d_mutex);
|
|
||||||
this->d_condition.wait(lock, [=]{ return !this->p_queue.empty(); });
|
|
||||||
T rc = *this->p_queue.end();
|
|
||||||
this->p_queue.pop();
|
|
||||||
return rc;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
/*
|
|
||||||
* BlockingQueue.hpp
|
|
||||||
*
|
|
||||||
* Created on: May 17, 2018
|
|
||||||
* Author: Andreas Schneider, Johannes Wendel, Jonas Zeunert, Rafael Vinci, Dr. Franca Rupprecht
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef SRC_UTILITIES_BLOCKINGQUEUE_H_
|
|
||||||
#define SRC_UTILITIES_BLOCKINGQUEUE_H_
|
|
||||||
|
|
||||||
#include <mutex>
|
|
||||||
#include <condition_variable>
|
|
||||||
#include <boost/heap/priority_queue.hpp>
|
|
||||||
|
|
||||||
using namespace boost;
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
class BlockingQueue
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
std::mutex d_mutex;
|
|
||||||
std::condition_variable d_condition;
|
|
||||||
heap::priority_queue<T, heap::stable<true>> p_queue;
|
|
||||||
|
|
||||||
public:
|
|
||||||
void push(T const& value);
|
|
||||||
|
|
||||||
T pop();
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif /* SRC_UTILITIES_BLOCKINGQUEUE_H_ */
|
|
||||||
45
FlippR-Driver/src/utilities/BlockingQueue.hpp
Normal file
45
FlippR-Driver/src/utilities/BlockingQueue.hpp
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
* BlockingQueue.hpp
|
||||||
|
*
|
||||||
|
* Created on: May 17, 2018
|
||||||
|
* Author: Andreas Schneider, Johannes Wendel, Jonas Zeunert, Rafael Vinci, Dr. Franca Rupprecht
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef SRC_UTILITIES_BLOCKINGQUEUE_HPP_
|
||||||
|
#define SRC_UTILITIES_BLOCKINGQUEUE_HPP_
|
||||||
|
|
||||||
|
#include <mutex>
|
||||||
|
#include <condition_variable>
|
||||||
|
#include <boost/heap/priority_queue.hpp>
|
||||||
|
|
||||||
|
using namespace boost;
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
class BlockingQueue
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
std::mutex d_mutex;
|
||||||
|
std::condition_variable d_condition;
|
||||||
|
heap::priority_queue<T, heap::stable<true>> p_queue;
|
||||||
|
|
||||||
|
public:
|
||||||
|
void push(T const& value)
|
||||||
|
{
|
||||||
|
std::unique_lock<std::mutex> lock(this->d_mutex);
|
||||||
|
p_queue.push(value);
|
||||||
|
this->d_condition.notify_one();
|
||||||
|
}
|
||||||
|
|
||||||
|
T pop()
|
||||||
|
{
|
||||||
|
std::unique_lock<std::mutex> lock(this->d_mutex);
|
||||||
|
this->d_condition.wait(lock, [=]{ return !this->p_queue.empty(); });
|
||||||
|
T rc = *this->p_queue.end();
|
||||||
|
this->p_queue.pop();
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* SRC_UTILITIES_BLOCKINGQUEUE_HPP_ */
|
||||||
@@ -7,17 +7,17 @@
|
|||||||
|
|
||||||
#include "GPIOInterface.h"
|
#include "GPIOInterface.h"
|
||||||
|
|
||||||
#include "../lib/wiringPi/wiringPi.h"
|
//#include "../lib/wiringPi/wiringPi.h"
|
||||||
#include "../lib/json/json.hpp"
|
#include "../lib/json/json.hpp"
|
||||||
|
|
||||||
|
|
||||||
static void GPIOInterface::write_pin(char address, char data)
|
void GPIOInterface::write_pin(char address, char data)
|
||||||
{
|
{
|
||||||
digitalWrite(address, data);
|
//digitalWrite(address, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static bool GPIOInterface::read_pin(char address)
|
bool GPIOInterface::read_pin(char address)
|
||||||
{
|
{
|
||||||
return digitalRead(address);
|
//return digitalRead(address);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,8 +19,7 @@
|
|||||||
class GPIOInterface
|
class GPIOInterface
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
GPIOInterface();
|
virtual ~GPIOInterface() {};
|
||||||
virtual ~GPIOInterface();
|
|
||||||
|
|
||||||
static void write_pin(char address, char data);
|
static void write_pin(char address, char data);
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
|
|
||||||
#include "../../src/input/InputDriver.h"
|
#include "../../src/input/InputDriver.h"
|
||||||
|
|
||||||
#include "../../src/input/Event.hpp"
|
#include "../../src/input/Event.h"
|
||||||
#include "../../src/input/IEventNotifier.h"
|
#include "../../src/input/IEventNotifier.h"
|
||||||
#include "../../src/input/IDetector.h"
|
#include "../../src/input/IDetector.h"
|
||||||
|
|
||||||
@@ -26,7 +26,7 @@ SCENARIO("An InputDriver gets created", "[construction}")
|
|||||||
Mock<Input::IDetector> detector_mock;
|
Mock<Input::IDetector> detector_mock;
|
||||||
|
|
||||||
Mock<Input::IEventNotifier> event_notifier_mock;
|
Mock<Input::IEventNotifier> event_notifier_mock;
|
||||||
Mock<Input::IEventHandler> event_handler_mock;
|
Mock<IEventHandler> event_handler_mock;
|
||||||
|
|
||||||
WHEN("The InputDriver gets created")
|
WHEN("The InputDriver gets created")
|
||||||
{
|
{
|
||||||
@@ -40,13 +40,13 @@ SCENARIO("An InputDriver gets created", "[construction}")
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SCENARIO("An EventHandler [un]registers at the driver", "[[un]register]")
|
SCENARIO("An EventHandler [un]registers at the driver", "[un-register]")
|
||||||
{
|
{
|
||||||
GIVEN("An InputDriver, EventHandler and an EventNotifier")
|
GIVEN("An InputDriver, EventHandler and an EventNotifier")
|
||||||
{
|
{
|
||||||
Mock<Input::IDetector> detector_mock;
|
Mock<Input::IDetector> detector_mock;
|
||||||
|
|
||||||
Mock<Input::IEventHandler> event_handler_mock;
|
Mock<IEventHandler> event_handler_mock;
|
||||||
Mock<Input::IEventNotifier> event_notifier_mock;
|
Mock<Input::IEventNotifier> event_notifier_mock;
|
||||||
When(Method(event_notifier_mock, register_event_handler));
|
When(Method(event_notifier_mock, register_event_handler));
|
||||||
When(Method(event_notifier_mock, unregister_event_handler));
|
When(Method(event_notifier_mock, unregister_event_handler));
|
||||||
|
|||||||
Reference in New Issue
Block a user