Start on unix socket server on c++ side
This commit is contained in:
parent
0bef6035ae
commit
1a033c8b03
8 changed files with 300 additions and 9 deletions
29
server_v2/include/communication/MessageBuilder.hpp
Normal file
29
server_v2/include/communication/MessageBuilder.hpp
Normal file
|
@ -0,0 +1,29 @@
|
|||
#ifndef COMPLIB_SERVER_MESSAGEBUILDER_HPP
|
||||
#define COMPLIB_SERVER_MESSAGEBUILDER_HPP
|
||||
|
||||
|
||||
#include "CompLib.pb.h"
|
||||
#include "include/Robot.hpp"
|
||||
|
||||
class MessageBuilder {
|
||||
public:
|
||||
static CompLib::Header *header(const std::string &message_type);
|
||||
|
||||
static CompLib::Status *status(bool successful, const std::string &error_message);
|
||||
|
||||
static CompLib::GenericResponse *generic_response(bool successful, const std::string &error_message);
|
||||
|
||||
static CompLib::Status *default_successful_status();
|
||||
|
||||
static CompLib::GenericResponse *default_successful_generic_response();
|
||||
|
||||
static CompLib::EncoderReadPositionsResponse *encoder_read_positions_response(std::array<int32_t, ROBOT_MOTOR_COUNT> positions);
|
||||
|
||||
static CompLib::EncoderReadVelocitiesResponse *encoder_read_velocities_response(std::array<double, ROBOT_MOTOR_COUNT> velocities);
|
||||
|
||||
static CompLib::IRSensorsReadAllResponse *ir_sensors_read_all_response(std::array<uint16_t, ROBOT_IR_SENSOR_COUNT> data);
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif //COMPLIB_SERVER_MESSAGEBUILDER_HPP
|
15
server_v2/include/communication/MessageProcessor.hpp
Normal file
15
server_v2/include/communication/MessageProcessor.hpp
Normal file
|
@ -0,0 +1,15 @@
|
|||
#ifndef COMPLIB_SERVER_MESSAGEPROCESSOR_HPP
|
||||
#define COMPLIB_SERVER_MESSAGEPROCESSOR_HPP
|
||||
|
||||
#include <CompLib.pb.h>
|
||||
|
||||
#define ERROR_MESSAGE_HEADER_UNKNOWN "Header.message_type unknown"
|
||||
|
||||
class MessageProcessor {
|
||||
public:
|
||||
static google::protobuf::Message *process_message(const std::string &serializedMessage);
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif //COMPLIB_SERVER_MESSAGEPROCESSOR_HPP
|
20
server_v2/include/communication/UnixSocketServer.hpp
Normal file
20
server_v2/include/communication/UnixSocketServer.hpp
Normal file
|
@ -0,0 +1,20 @@
|
|||
#ifndef COMPLIB_SERVER_UNIXSOCKETSERVER_HPP
|
||||
#define COMPLIB_SERVER_UNIXSOCKETSERVER_HPP
|
||||
|
||||
#include <thread>
|
||||
|
||||
#define SOCKET_PATH "/tmp/compLib"
|
||||
#define SOCKET_BUFFER_SIZE 64
|
||||
|
||||
class UnixSocketServer {
|
||||
public:
|
||||
UnixSocketServer();
|
||||
|
||||
private:
|
||||
[[noreturn]] void server_loop();
|
||||
|
||||
std::thread server_thread;
|
||||
};
|
||||
|
||||
|
||||
#endif //COMPLIB_SERVER_UNIXSOCKETSERVER_HPP
|
Reference in a new issue