diff --git a/.gitignore b/.gitignore index 401f1d8..274ba67 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ CMakeLists.txt.user* *.kdev4 *.swp /build/ /3rdparty/ +compile_commands.json diff --git a/src/blade/CMakeLists.txt b/src/blade/CMakeLists.txt index e3873e8..59076bb 100644 --- a/src/blade/CMakeLists.txt +++ b/src/blade/CMakeLists.txt @@ -1,42 +1,42 @@ include_directories ( ${CMAKE_CURRENT_BUILD_DIR} ) set ( BLADE_COMMON_SRCS - protocol.cpp + Protocol.cpp main.cpp ) if (NOT EXISTS "${CAPNP_EXECUTABLE}") # Workaround for some CMake problems with CapnProto set(CAPNP_EXECUTABLE "/usr/bin/capnp") set(CAPNPC_CXX_EXECUTABLE "/usr/bin/capnpc-c++") set(CAPNP_INCLUDE_DIRECTORY "/usr/include") set(CAPNP_INCLUDE_DIRS "/usr/include") endif() capnp_generate_cpp ( BLADE_CAPNP_SRCS BLADE_CAPNP_HEADERS protocol/ping_message.capnp protocol/query_message.capnp protocol/error_message.capnp protocol/controller_message.capnp ) add_executable ( bladed ${BLADE_COMMON_SRCS} ${BLADE_CAPNP_SRCS} ) target_link_libraries ( bladed ${capnp_LIBRARIES} ${ZMQ_LIBRARIES} Qt5::Core ) diff --git a/src/blade/ControllerMessage.h b/src/blade/ControllerMessage.h index b07d36d..26c71dc 100644 --- a/src/blade/ControllerMessage.h +++ b/src/blade/ControllerMessage.h @@ -1,59 +1,60 @@ /* * Copyright (C) 2018 Ivan Čukić * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) version 3, or any * later version accepted by the membership of KDE e.V. (or its * successor approved by the membership of KDE e.V.), which shall * act as a proxy defined in Section 6 of version 3 of the license. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. * If not, see . */ #ifndef BLADE_CONTROLLER_MESSAGE_H #define BLADE_CONTROLLER_MESSAGE_H #include #include +#include namespace blade { struct PingMessage {}; struct QueryMessage { std::uint64_t id; QString text; }; struct ErrorMessage { std::uint16_t code; QString message; }; struct ControllerMessage { - QString host; - QString controller; + QByteArray host; + QByteArray controller; std::variant< PingMessage, QueryMessage, ErrorMessage > message; }; } // namespace blade #endif // include guard diff --git a/src/blade/protocol.cpp b/src/blade/Protocol.cpp similarity index 82% rename from src/blade/protocol.cpp rename to src/blade/Protocol.cpp index cf04976..42949b9 100644 --- a/src/blade/protocol.cpp +++ b/src/blade/Protocol.cpp @@ -1,72 +1,72 @@ /* * Copyright (C) 2018 Ivan Čukić * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) version 3, or any * later version accepted by the membership of KDE e.V. (or its * successor approved by the membership of KDE e.V.), which shall * act as a proxy defined in Section 6 of version 3 of the license. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. * If not, see . */ -#include "protocol.h" +#include "Protocol.h" #include #include #include #include #include #include #include "protocol/controller_message.capnp.h" namespace blade { void serialize(const ControllerMessage &msg) { capnp::MallocMessageBuilder builder; auto cm = builder.initRoot(); - cm.setHost(msg.host.toUtf8().data()); - cm.setController(msg.controller.toUtf8().data()); + cm.setHost(msg.host.data()); + cm.setController(msg.controller.data()); auto message = cm.initMessage(); std::visit( overloaded{ [&](const PingMessage &) { message.initPing(); }, [&](const QueryMessage &msg) { - auto qm = message.initQuery(); - qm.setId(msg.id); - qm.setText(msg.text.toUtf8().data()); + auto query = message.initQuery(); + query.setId(msg.id); + query.setText(msg.text.toUtf8().data()); }, [&](const ErrorMessage &msg) { - auto qm = message.initError(); - qm.setCode(msg.code); - qm.setMessage(msg.message.toUtf8().data()); + auto error = message.initError(); + error.setCode(msg.code); + error.setMessage(msg.message.toUtf8().data()); }, }, msg.message); std::cout << "----["; kj::std::StdOutputStream out(std::cout); capnp::writeMessage(out, builder); std::cout << "]----\n"; } } // namespace blade diff --git a/src/blade/protocol.h b/src/blade/Protocol.h similarity index 100% rename from src/blade/protocol.h rename to src/blade/Protocol.h diff --git a/src/blade/main.cpp b/src/blade/main.cpp index 82b61ad..410c394 100644 --- a/src/blade/main.cpp +++ b/src/blade/main.cpp @@ -1,45 +1,45 @@ /* * Copyright (C) 2018 Ivan Čukić * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) version 3, or any * later version accepted by the membership of KDE e.V. (or its * successor approved by the membership of KDE e.V.), which shall * act as a proxy defined in Section 6 of version 3 of the license. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. * If not, see . */ #include "ControllerMessage.h" -#include "protocol.h" +#include "Protocol.h" #include using namespace std::literals::string_literals; int main(int argc, char *argv[]) { using blade::ControllerMessage; using blade::PingMessage; using blade::QueryMessage; ControllerMessage cm; - cm.host = "Host"_qs; - cm.controller = "Cler"_qs; - cm.message = QueryMessage{ 1 , "GGG" }; + cm.host = "Host"; + cm.controller = "Cler"; + cm.message = QueryMessage{ 1 , "GGG"_qs }; blade::serialize(cm); return 0; }