Split src/common/* into headers and definitions

This commit is contained in:
Robbert van der Helm
2020-03-06 19:18:27 +01:00
parent 7d0bf3e3c4
commit 54d62c6a66
5 changed files with 104 additions and 80 deletions
+30
View File
@@ -0,0 +1,30 @@
#include "communication.h"
intptr_t send_event(boost::asio::local::stream_protocol::socket& socket,
int32_t opcode,
int32_t index,
intptr_t value,
void* data,
float option) {
auto payload =
data == nullptr
? std::nullopt
: std::make_optional(std::string(static_cast<char*>(data)));
const Event event{opcode, index, value, option, payload};
write_object(socket, event);
const auto response = read_object<EventResult>(socket);
if (response.data.has_value()) {
char* char_data = static_cast<char*>(data);
// For correctness we will copy the entire buffer and add a terminating
// null byte ourselves. In practice `response.data` will only ever
// contain C-style strings, but this would work with any other data
// format that can contain null bytes.
std::copy(response.data->begin(), response.data->end(), char_data);
char_data[response.data->size()] = 0;
}
return response.return_value;
}