implemented socket handler
This commit is contained in:
42
FlippR-Driver/src/utility/InputSocketHandler.cpp
Normal file
42
FlippR-Driver/src/utility/InputSocketHandler.cpp
Normal file
@@ -0,0 +1,42 @@
|
||||
//
|
||||
// Created by rhetenor on 27.11.18.
|
||||
//
|
||||
|
||||
#include "InputSocketHandler.h"
|
||||
|
||||
#include "boost/date_time/posix_time/posix_time.hpp"
|
||||
#include <chrono>
|
||||
|
||||
namespace flippR_driver
|
||||
{
|
||||
namespace utility
|
||||
{
|
||||
using namespace nlohmann;
|
||||
|
||||
InputSocketHandler::InputSocketHandler(boost::asio::io_service &service, std::string socket_file) : SocketHandler(service, socket_file) {}
|
||||
|
||||
void InputSocketHandler::handle(flippR_driver::input::Event &event)
|
||||
{
|
||||
json event_serialization = serialize_event(event);
|
||||
|
||||
write_to_socket(event_serialization);
|
||||
}
|
||||
|
||||
json InputSocketHandler::serialize_event(input::Event &event)
|
||||
{
|
||||
json serialized_event = json("event");
|
||||
|
||||
serialized_event["name"] = event.name;
|
||||
|
||||
std::time_t activation_time = std::chrono::system_clock::to_time_t(event.last_activation);
|
||||
boost::posix_time::ptime posix_time = boost::posix_time::from_time_t(activation_time);
|
||||
serialized_event["activation_time"] = boost::posix_time::to_simple_string(posix_time); // todo learn to write time right
|
||||
|
||||
serialized_event["priority"] = event.priority;
|
||||
|
||||
return serialized_event;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user