building detector
This commit is contained in:
54
FlippR-Driver/src/Input/Detector.cpp
Normal file
54
FlippR-Driver/src/Input/Detector.cpp
Normal file
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Detector.cpp
|
||||
*
|
||||
* Created on: Apr 5, 2018
|
||||
* Author: Andreas Schneider, Johannes Wendel, Jonas Zeunert, Rafael Vinci, Dr. Franca Rupprecht
|
||||
*/
|
||||
|
||||
#include "Detector.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
namespace Input
|
||||
{
|
||||
|
||||
Detector::Detector(std::vector<InputEvent*> events) :
|
||||
input_events(events), is_running(true)
|
||||
{
|
||||
detect_thread = std::thread(&Detector::detect, this);
|
||||
}
|
||||
|
||||
|
||||
Detector::~Detector()
|
||||
{
|
||||
is_running = false;
|
||||
detect_thread.join();
|
||||
}
|
||||
|
||||
void Detector::register_input_event_handler(InputEventHandler* handler)
|
||||
{
|
||||
event_handler.insert(handler);
|
||||
}
|
||||
|
||||
void Detector::unregister_input_event_handler(InputEventHandler* handler)
|
||||
{
|
||||
event_handler.erase(handler);
|
||||
}
|
||||
|
||||
void Detector::detect()
|
||||
{
|
||||
while(is_running)
|
||||
{
|
||||
std::cout << "hallo_thread\n";
|
||||
}
|
||||
}
|
||||
|
||||
void Detector::notify_handlers(InputEvent& event)
|
||||
{
|
||||
for(auto* handler : event_handler)
|
||||
{
|
||||
handler->handle(event);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
45
FlippR-Driver/src/Input/Detector.h
Normal file
45
FlippR-Driver/src/Input/Detector.h
Normal file
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Detector.h
|
||||
*
|
||||
* Created on: Apr 5, 2018
|
||||
* Author: Andreas Schneider, Johannes Wendel, Jonas Zeunert, Rafael Vinci, Dr. Franca Rupprecht
|
||||
*/
|
||||
|
||||
#ifndef DETECTOR_H_
|
||||
#define DETECTOR_H_
|
||||
|
||||
#include <vector>
|
||||
#include <thread>
|
||||
|
||||
#include "InputEvent.h"
|
||||
|
||||
namespace Input
|
||||
{
|
||||
|
||||
class Detector
|
||||
{
|
||||
public:
|
||||
Detector(std::vector<InputEvent*> events);
|
||||
~Detector();
|
||||
|
||||
void register_input_event_handler(InputEventHandler* handler);
|
||||
void unregister_input_event_handler(InputEventHandler* handler);
|
||||
|
||||
private:
|
||||
void detect();
|
||||
|
||||
void notify_handlers(InputEvent& event);
|
||||
|
||||
private:
|
||||
std::vector<InputEvent*> input_events;
|
||||
std::set<InputEventHandler*> event_handler;
|
||||
|
||||
std::thread detect_thread;
|
||||
bool is_running;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif /* DETECTOR_H_ */
|
||||
33
FlippR-Driver/src/Input/InputEvent.h
Normal file
33
FlippR-Driver/src/Input/InputEvent.h
Normal file
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* InputEvent.h
|
||||
*
|
||||
* Created on: Apr 5, 2018
|
||||
* Author: Andreas Schneider, Johannes Wendel, Jonas Zeunert, Rafael Vinci, Dr. Franca Rupprecht
|
||||
*/
|
||||
|
||||
#ifndef INPUTEVENT_H_
|
||||
#define INPUTEVENT_H_
|
||||
|
||||
#include <set>
|
||||
#include <string>
|
||||
|
||||
#include "InputEventHandler.h"
|
||||
|
||||
namespace Input
|
||||
{
|
||||
|
||||
class InputEvent
|
||||
{
|
||||
public:
|
||||
InputEvent();
|
||||
~InputEvent();
|
||||
|
||||
private:
|
||||
char address;
|
||||
std::string name;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif /* INPUTEVENT_H_ */
|
||||
26
FlippR-Driver/src/Input/InputEventHandler.h
Normal file
26
FlippR-Driver/src/Input/InputEventHandler.h
Normal file
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* InputEventHandler.h
|
||||
*
|
||||
* Created on: Apr 5, 2018
|
||||
* Author: Andreas Schneider, Johannes Wendel, Jonas Zeunert, Rafael Vinci, Dr. Franca Rupprecht
|
||||
*/
|
||||
|
||||
#ifndef INPUTEVENTHANDLER_H_
|
||||
#define INPUTEVENTHANDLER_H_
|
||||
|
||||
#include "InputEvent.h"
|
||||
|
||||
namespace Input
|
||||
{
|
||||
|
||||
|
||||
class InputEventHandler
|
||||
{
|
||||
public:
|
||||
virtual ~InputEventHandler(){};
|
||||
virtual void handle(InputEvent& event) = 0;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif /* INPUTEVENTHANDLER_H_ */
|
||||
33
FlippR-Driver/src/Input/InputFactory.h
Normal file
33
FlippR-Driver/src/Input/InputFactory.h
Normal file
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* InputFactory.h
|
||||
*
|
||||
* Created on: Apr 5, 2018
|
||||
* Author: Andreas Schneider, Johannes Wendel, Jonas Zeunert, Rafael Vinci, Dr. Franca Rupprecht
|
||||
*/
|
||||
|
||||
#ifndef INPUTFACTORY_H_
|
||||
#define INPUTFACTORY_H_
|
||||
#include <vector>
|
||||
|
||||
#include "InputEvent.h"
|
||||
|
||||
namespace Input
|
||||
{
|
||||
class InputFactory
|
||||
{
|
||||
|
||||
public:
|
||||
InputFactory();
|
||||
~InputFactory();
|
||||
|
||||
std::vector<InputEvent*> get_input_events();
|
||||
|
||||
private:
|
||||
std::vector<InputEvent*> input_events;
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif /* INPUTFACTORY_H_ */
|
||||
12
FlippR-Driver/src/Input/main.cpp
Normal file
12
FlippR-Driver/src/Input/main.cpp
Normal file
@@ -0,0 +1,12 @@
|
||||
#include <vector>
|
||||
#include "InputEvent.h"
|
||||
#include "Detector.h"
|
||||
#include <iostream>
|
||||
int main()
|
||||
{
|
||||
Input::Detector(std::vector<Input::InputEvent*>());
|
||||
|
||||
std::printf("hallo");
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user