From a076f8228ff6fe8a2f9b7ac6634b46fb598fd711 Mon Sep 17 00:00:00 2001 From: Gluzskiy Alexandr Date: Tue, 28 Jul 2015 05:33:02 +0300 Subject: a bit of implementation of client<->server protocol --- protocol/udm.proto | 2 +- server/include/utilities.h | 5 +++++ server/src/utilities.cpp | 26 ++++++++++++++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/protocol/udm.proto b/protocol/udm.proto index 623f2d5..f762a46 100644 --- a/protocol/udm.proto +++ b/protocol/udm.proto @@ -29,7 +29,7 @@ enum MODULE_UI_ELEMENT_TYPE { UI_INTEGER = 2; //numeric only ui elements (use strings instead ?) UI_PROGRESS_BAR = 3; //generic progress bar UI_WINDOW = 4; //ui window ... - UI_GROUP = 5; //empty ui element to group children together in ui + UI_GROUP = 5; //empty ui element to group children together in ui (tabs can be implemented using this type) } message module_ui_element_info { diff --git a/server/include/utilities.h b/server/include/utilities.h index de97f2f..9becc48 100644 --- a/server/include/utilities.h +++ b/server/include/utilities.h @@ -23,9 +23,14 @@ #include +#include std::string replace_home_var(const std::string &path); +class server_msg; + +std::shared_ptr pack_msg(server_msg *msg, int *size); + diff --git a/server/src/utilities.cpp b/server/src/utilities.cpp index 1cebd16..5ea14c1 100644 --- a/server/src/utilities.cpp +++ b/server/src/utilities.cpp @@ -19,6 +19,7 @@ */ #include "utilities.h" +#include "../../protocol/udm.pb.h" std::string replace_home_var(const std::string &path) { @@ -28,3 +29,28 @@ std::string replace_home_var(const std::string &path) return tmp_path; } + + +std::shared_ptr pack_data(const std::string &buf, int *size_) +{ +// BOOST_LOG_TRIVIAL(debug)<<__FILE__<<":"<<__LINE__<<"\t"<<__func__; + std::shared_ptr ptr = std::make_shared(new char[buf.length() + 4]); + int32_t size = buf.length(); + *size_ = size + 4; + (*ptr)[3] = size & 0xff; + (*ptr)[2] = (size>>8) & 0xff; + (*ptr)[1] = (size>>16) & 0xff; + (*ptr)[0] = (size>>24) & 0xff; + char *fck = (*ptr)+4; + memcpy(fck, buf.data(), buf.length()); + return ptr; +} + +std::shared_ptr pack_msg(server_msg *msg, int *size_) +{ +// BOOST_LOG_TRIVIAL(debug)<<__FILE__<<":"<<__LINE__<<"\t"<<__func__; +// BOOST_LOG_TRIVIAL(trace)<<"packing message:\n"<SerializeToString(&msg_buf); + return pack_data(msg_buf, size_); +} -- cgit v1.2.3