reworked eventhandler
This commit is contained in:
@@ -9,6 +9,9 @@
|
|||||||
#define SRC_IEVENTHANDLER_H_
|
#define SRC_IEVENTHANDLER_H_
|
||||||
|
|
||||||
#include "input/Event.h"
|
#include "input/Event.h"
|
||||||
|
#include "InputDriver.h"
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
namespace flippR_driver
|
namespace flippR_driver
|
||||||
{
|
{
|
||||||
@@ -18,9 +21,21 @@ namespace input
|
|||||||
class EventHandler
|
class EventHandler
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual ~EventHandler() = default;
|
explicit EventHandler(std::shared_ptr<InputDriver> input_driver) :
|
||||||
|
input_driver(std::move(input_driver))
|
||||||
|
{
|
||||||
|
this->input_driver->register_event_handler(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual ~EventHandler()
|
||||||
|
{
|
||||||
|
this->input_driver->unregister_event_handler(this);
|
||||||
|
};
|
||||||
|
|
||||||
virtual void handle(flippR_driver::input::Event &event) = 0;
|
virtual void handle(flippR_driver::input::Event &event) = 0;
|
||||||
|
|
||||||
|
private:
|
||||||
|
const std::shared_ptr<InputDriver> input_driver;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,17 +8,19 @@
|
|||||||
#ifndef SRC_INPUT_IINPUTDRIVER_H_
|
#ifndef SRC_INPUT_IINPUTDRIVER_H_
|
||||||
#define SRC_INPUT_IINPUTDRIVER_H_
|
#define SRC_INPUT_IINPUTDRIVER_H_
|
||||||
|
|
||||||
|
#include "Event.h"
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#include <boost/optional/optional_io.hpp>
|
#include <boost/optional/optional_io.hpp>
|
||||||
|
|
||||||
#include "input/EventHandler.h"
|
|
||||||
|
|
||||||
namespace flippR_driver
|
namespace flippR_driver
|
||||||
{
|
{
|
||||||
namespace input
|
namespace input
|
||||||
{
|
{
|
||||||
|
|
||||||
|
class EventHandler;
|
||||||
|
|
||||||
class InputDriver {
|
class InputDriver {
|
||||||
public:
|
public:
|
||||||
virtual ~InputDriver() = default;
|
virtual ~InputDriver() = default;
|
||||||
|
|||||||
@@ -11,9 +11,8 @@
|
|||||||
|
|
||||||
#include <Poco/Net/TCPServerConnection.h>
|
#include <Poco/Net/TCPServerConnection.h>
|
||||||
|
|
||||||
#include "utility/IBlockingQueue.h"
|
|
||||||
#include "input/InputDriver.h"
|
#include "input/InputDriver.h"
|
||||||
#include "input/detail/EventHandler.h"
|
#include "input/EventHandler.h"
|
||||||
#include "input/Event.h"
|
#include "input/Event.h"
|
||||||
|
|
||||||
namespace flippR_driver
|
namespace flippR_driver
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ std::string Event::getJsonString()
|
|||||||
json["address"] = this->address;
|
json["address"] = this->address;
|
||||||
json["priority"] = this->priority;
|
json["priority"] = this->priority;
|
||||||
|
|
||||||
json.dump();
|
return json.dump();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator==(const Event& left, const Event& right)
|
bool operator==(const Event& left, const Event& right)
|
||||||
|
|||||||
@@ -1,38 +0,0 @@
|
|||||||
/*
|
|
||||||
* EventHandler.cpp
|
|
||||||
*
|
|
||||||
* Created on: Jun 14, 2018
|
|
||||||
* Author: Andreas Schneider, Johannes Wendel, Jonas Zeunert
|
|
||||||
*/
|
|
||||||
#include "EventHandler.h"
|
|
||||||
#include "utility/config.h"
|
|
||||||
|
|
||||||
namespace flippR_driver
|
|
||||||
{
|
|
||||||
namespace input
|
|
||||||
{
|
|
||||||
namespace detail
|
|
||||||
{
|
|
||||||
|
|
||||||
EventHandler::EventHandler(std::shared_ptr<InputDriver> input_driver) :
|
|
||||||
input_driver(std::move(input_driver))
|
|
||||||
{
|
|
||||||
this->input_driver->register_event_handler(this);
|
|
||||||
|
|
||||||
CLOG(INFO, INPUT_LOGGER) << "Created EventHandler";
|
|
||||||
}
|
|
||||||
|
|
||||||
EventHandler::~EventHandler()
|
|
||||||
{
|
|
||||||
this->input_driver->unregister_event_handler(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
// This function is intended to be non pure, if it is called when the derived class doesn't exist anymore
|
|
||||||
void EventHandler::handle(Event &event)
|
|
||||||
{
|
|
||||||
CLOG(WARNING, INPUT_LOGGER) << "Called EventHandler parent class";
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,43 +0,0 @@
|
|||||||
/*
|
|
||||||
* InputEventHandler.h
|
|
||||||
*
|
|
||||||
* This interface must be implemented to be informed about input events.
|
|
||||||
*
|
|
||||||
* Please be aware that handle must be implemented thread safe!
|
|
||||||
*
|
|
||||||
* Created on: Apr 5, 2018
|
|
||||||
* Author: Andreas Schneider, Johannes Wendel, Jonas Zeunert
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef INPUT_IMPL_EVENTHANDLER_H_
|
|
||||||
#define INPUT_IMPL_EVENTHANDLER_H_
|
|
||||||
|
|
||||||
#include "input/InputDriver.h"
|
|
||||||
|
|
||||||
#include "input/EventHandler.h"
|
|
||||||
#include "input/Event.h"
|
|
||||||
|
|
||||||
namespace flippR_driver
|
|
||||||
{
|
|
||||||
namespace input
|
|
||||||
{
|
|
||||||
namespace detail
|
|
||||||
{
|
|
||||||
|
|
||||||
class EventHandler;
|
|
||||||
|
|
||||||
class EventHandler : public input::EventHandler
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
explicit EventHandler(std::shared_ptr<InputDriver> input_driver);
|
|
||||||
~EventHandler() override;
|
|
||||||
void handle(Event &event) override;
|
|
||||||
|
|
||||||
private:
|
|
||||||
const std::shared_ptr<InputDriver> input_driver;
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
@@ -12,13 +12,12 @@
|
|||||||
#define private public
|
#define private public
|
||||||
|
|
||||||
#include "utility/LoggerFactory.h"
|
#include "utility/LoggerFactory.h"
|
||||||
#include "input/detail/EventHandler.h"
|
|
||||||
#include "input/InputDriver.h"
|
#include "input/InputDriver.h"
|
||||||
|
|
||||||
|
|
||||||
using namespace fakeit;
|
using namespace fakeit;
|
||||||
using namespace flippR_driver::utility;
|
using namespace flippR_driver::utility;
|
||||||
|
/* todo ?
|
||||||
SCENARIO("An EventHandler gets created", "[construction}")
|
SCENARIO("An EventHandler gets created", "[construction}")
|
||||||
{
|
{
|
||||||
GIVEN("An IInputDriver")
|
GIVEN("An IInputDriver")
|
||||||
@@ -42,3 +41,4 @@ SCENARIO("An EventHandler gets created", "[construction}")
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
Reference in New Issue
Block a user