added inputsockethandlerfactory

This commit is contained in:
Johannes Wendel
2019-06-15 14:52:42 +02:00
parent e90c3f6695
commit 7146f67169
9 changed files with 91 additions and 12 deletions

View File

@@ -16,6 +16,7 @@ set(CMAKE_CXX_STANDARD 14)
set(BOOST_COMPONENTS program_options thread timer chrono)
project(FlippR-Driver)
################### CROSS_COMPILING ######################
IF(NOT RPI_ROOT)
@@ -74,7 +75,7 @@ file(GLOB_RECURSE SOURCES src/*.cpp)
if(BUILD_SHARED_LIB)
add_library(${PROJECT_NAME} SHARED ${SOURCES})
else()
add_library(${PROJECT_NAME} STATIC ${SOURCES} cli/OutputInterpreter.cpp cli/OutputInterpreter.h src/output/items/detail/DriverBoardItem.cpp src/output/items/detail/DriverBoardItem.h)
add_library(${PROJECT_NAME} STATIC ${SOURCES} cli/OutputInterpreter.cpp cli/OutputInterpreter.h src/output/items/detail/DriverBoardItem.cpp src/output/items/detail/DriverBoardItem.h include/DriverFactory.h)
endif(BUILD_SHARED_LIB)
target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/src)

View File

@@ -5,4 +5,4 @@ set(EXECUTABLE_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/${OUTPUT_PATH}/cli)
add_executable(${PROJECT_NAME} main.cpp PrintHandler.cpp)
target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/include)
target_link_libraries(${PROJECT_NAME} PRIVATE FlippR-Driver)
target_link_libraries(${PROJECT_NAME} PRIVATE FlippR_Driver)

View File

@@ -6,12 +6,14 @@ set(SOURCES
input/InputSocketHandler.cpp
output/OutputRequestHandler.cpp
output/OutputRequestHandlerFactory.cpp
FlippRServer.cpp)
FlippRServer.cpp
input/InputSocketHandlerFactory.cpp)
add_executable(${PROJECT_NAME} ${SOURCES})
target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/include)
target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/src)
target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/include)
target_link_libraries(${PROJECT_NAME} PRIVATE FlippR-Driver)
####################### POCO ##############################

View File

@@ -99,8 +99,8 @@ void FlippRServer::initialize_output_driver()
exit(EXIT_FAILURE);
}
//todo should use DriverFactory from input
// this->input_driver = flippR_driver::get_InputDriver(input_config_stream, matrix_config_stream);
//todo linking errors
this->input_driver = flippR_driver::get_InputDriver(input_config_stream, matrix_config_stream);
}
int FlippRServer::main(const std::vector<std::string>& args)
@@ -111,7 +111,7 @@ int FlippRServer::main(const std::vector<std::string>& args)
std::unique_ptr<HTTPServer> output_server(this->build_output_server());
output_server->start();
std::unique_ptr<TCPServer>
std::unique_ptr<TCPServer> input_server(this->build_input_server());
waitForTerminationRequest();
this->output_driver->deactivate_all_lamps();
@@ -127,9 +127,20 @@ HTTPServer* FlippRServer::build_output_server()
// todo XDG_RUNTIME_DIR
SocketAddress address("/tmp/flippR_driver/S.flippR_driver");
ServerSocket svs(address);
ServerSocket server_socket(address);
return new HTTPServer(new OutputRequestHandlerFactory(this->output_driver), server_socket, new HTTPServerParams);
}
TCPServer* FlippRServer::build_input_server()
{
unsigned short port = (unsigned short) config().getInt("HTTPTimeServer.port", this->output_port);
//TODO adapt path
SocketAddress address("/tmp/flippR_driver/S.flippR_driver");
ServerSocket server_socket(address);
return new HTTPServer(new OutputRequestHandlerFactory(this->output_driver), svs, new HTTPServerParams);
}

View File

@@ -37,6 +37,7 @@ private:
void parse_server_config_file();
Poco::Net::HTTPServer* build_output_server();
Poco::Net::TCPServer* build_input_server();
private:

View File

@@ -0,0 +1,31 @@
//
// Created by johannes on 15.06.19.
//
#include "InputSocketHandlerFactory.h"
#include "InputSocketHandler.h"
namespace flippR_driver
{
namespace networking
{
namespace input
{
using namespace Poco::Net;
InputSocketHandlerFactory::InputSocketHandlerFactory(std::shared_ptr<flippR_driver::input::InputDriver> inputDriver) :
input_driver(inputDriver)
{
}
TCPServerConnection *InputSocketHandlerFactory::createConnection(const Poco::Net::StreamSocket &socket)
{
return new InputSocketHandler(socket, this->input_driver);
}
}
}
}

View File

@@ -0,0 +1,33 @@
//
// Created by johannes on 15.06.19.
//
#ifndef FLIPPR_DRIVER_INPUTSOCKETHANDLERFACTORY_H
#define FLIPPR_DRIVER_INPUTSOCKETHANDLERFACTORY_H
#include <Poco/Net/TCPServerConnectionFactory.h>
#include <input/InputDriver.h>
namespace flippR_driver
{
namespace networking
{
namespace input
{
class InputSocketHandlerFactory : Poco::Net::TCPServerConnectionFactory
{
public:
explicit InputSocketHandlerFactory(std::shared_ptr<flippR_driver::input::InputDriver> inputDriver);
Poco::Net::TCPServerConnection* createConnection(const Poco::Net::StreamSocket &socket) override;
private:
std::shared_ptr<flippR_driver::input::InputDriver> input_driver;
};
}
}
}
#endif //FLIPPR_DRIVER_INPUTSOCKETHANDLERFACTORY_H

View File

@@ -9,12 +9,12 @@
namespace flippR_driver
{
namespace utility
namespace networking
{
using namespace Poco::Net;
OutputHTTPServer::OutputHTTPServer(std::shared_ptr<output::OutputDriver> output_driver, Socket &socket) :
HTTPServer(new OutputRequestHandlerFactory(output_driver), socket, new HTTPServerParams())
HTTPServer(new OutputRequestHandlerFactory(output_driver), socket, new HTTPServerParams())
{}
}

View File

@@ -12,7 +12,7 @@
namespace flippR_driver
{
namespace utility
namespace networking
{
class OutputHTTPServer : public Poco::Net::HTTPServer