restored OUtputPinController
This commit is contained in:
59
FlippR-Driver/networking/input/SocketHandler.cpp
Normal file
59
FlippR-Driver/networking/input/SocketHandler.cpp
Normal file
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* SocketConnection.cpp
|
||||
*
|
||||
* Created on: Jun 13, 2018
|
||||
* Author: Andreas Schneider, Johannes Wendel, Jonas Zeunert
|
||||
*/
|
||||
|
||||
#include "SocketHandler.h"
|
||||
|
||||
|
||||
using Poco::Net::StreamSocket;
|
||||
using Poco::Net::TCPServerConnection;
|
||||
using flippR_driver::input::InputDriver;
|
||||
using flippR_driver::input::detail::EventHandler;
|
||||
using flippR_driver::input::Event;
|
||||
|
||||
namespace flippR_driver
|
||||
{
|
||||
namespace utility
|
||||
{
|
||||
namespace networking
|
||||
{
|
||||
namespace input
|
||||
{
|
||||
|
||||
SocketHandler::SocketHandler(StreamSocket streamSocket, std::shared_ptr<InputDriver> inputDriver) :
|
||||
TCPServerConnection(streamSocket),
|
||||
EventHandler(inputDriver)
|
||||
{
|
||||
}
|
||||
|
||||
void SocketHandler::run()
|
||||
{
|
||||
StreamSocket& streamSocket = socket();
|
||||
|
||||
while(true)
|
||||
{
|
||||
Event event = this->queue->pop();
|
||||
|
||||
if(event.name == "END")
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
std::string str = event.getJsonString();
|
||||
|
||||
streamSocket.sendBytes(str.c_str(), str.length());
|
||||
}
|
||||
}
|
||||
|
||||
void SocketHandler::handle(Event &event)
|
||||
{
|
||||
this->queue->push(event);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
44
FlippR-Driver/networking/input/SocketHandler.h
Normal file
44
FlippR-Driver/networking/input/SocketHandler.h
Normal file
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* SocketConnection.h
|
||||
*
|
||||
* Created on: Jun 13, 2018
|
||||
* Author: Andreas Schneider, Johannes Wendel, Jonas Zeunert
|
||||
*/
|
||||
|
||||
#ifndef FLIPPR_CODE_INPUTSOCKETCONNECTION_H
|
||||
#define FLIPPR_CODE_INPUTSOCKETCONNECTION_H
|
||||
|
||||
|
||||
#include <Poco/Net/TCPServerConnection.h>
|
||||
|
||||
#include "utility/IBlockingQueue.h"
|
||||
#include "input/InputDriver.h"
|
||||
#include "input/detail/EventHandler.h"
|
||||
#include "input/Event.h"
|
||||
|
||||
namespace flippR_driver
|
||||
{
|
||||
namespace utility
|
||||
{
|
||||
namespace networking
|
||||
{
|
||||
namespace input
|
||||
{
|
||||
class SocketHandler : public Poco::Net::TCPServerConnection, flippR_driver::input::detail::EventHandler
|
||||
{
|
||||
public:
|
||||
SocketHandler(Poco::Net::StreamSocket streamSocket, std::shared_ptr<flippR_driver::input::InputDriver> input_driver);
|
||||
|
||||
void run() override;
|
||||
void handle(flippR_driver::input::Event &event) override;
|
||||
|
||||
private:
|
||||
flippR_driver::utility::IBlockingQueue<flippR_driver::input::Event>* queue;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif //FLIPPR_CODE_INPUTSOCKETCONNECTION_H
|
||||
Reference in New Issue
Block a user