diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..77e61eb --- /dev/null +++ b/.clang-format @@ -0,0 +1,12 @@ +BasedOnStyle: LLVM +IndentWidth: 4 +UseTab: Never +ColumnLimit: 100 + +KeepEmptyLinesAtTheStartOfBlocks: true +MaxEmptyLinesToKeep: 2 +AllowShortBlocksOnASingleLine: Never +AllowShortIfStatementsOnASingleLine: Never +AllowShortLoopsOnASingleLine: false +AllowShortFunctionsOnASingleLine: None +ReflowComments: false diff --git a/.gitignore b/.gitignore index 0c7b4e1..b73cefc 100644 --- a/.gitignore +++ b/.gitignore @@ -49,3 +49,4 @@ CMakeCache.txt /CMakeFiles /examples/display/build *.log +/examples/rpc_call/build diff --git a/conanfile.py b/conanfile.py index 4494ef2..00d3a3a 100644 --- a/conanfile.py +++ b/conanfile.py @@ -39,7 +39,7 @@ class MyLibraryConan(ConanFile): def requirements(self): self.requires("flatbuffers/24.12.23") - self.requires("librpc/1.1.6") + self.requires("librpc/1.1.7") self.requires("eigen/3.4.1") self.requires("spdlog/1.16.0") self.requires("sentry-native/0.12.2") diff --git a/examples/display/conanfile.txt b/examples/display/conanfile.txt index c1d715f..a61eff3 100644 --- a/examples/display/conanfile.txt +++ b/examples/display/conanfile.txt @@ -2,7 +2,7 @@ libcontrol/1.0.0 flatbuffers/24.12.23 spdlog/1.16.0 -librpc/1.1.6 +librpc/1.1.7 [generators] CMakeDeps diff --git a/examples/rpc_call/CMakeLists.txt b/examples/rpc_call/CMakeLists.txt new file mode 100644 index 0000000..0c979d2 --- /dev/null +++ b/examples/rpc_call/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 3.15) + +project(RpcCallExample) + +set(CMAKE_CXX_STANDARD 23) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +find_package(libcontrol REQUIRED) +find_package(spdlog REQUIRED) +find_package(librpc REQUIRED) + +add_executable(RpcCallExample main.cpp) + +target_link_libraries(RpcCallExample + PRIVATE + libcontrol::libcontrol + spdlog::spdlog + librpc::librpc +) diff --git a/examples/rpc_call/CMakeUserPresets.json b/examples/rpc_call/CMakeUserPresets.json new file mode 100644 index 0000000..945b382 --- /dev/null +++ b/examples/rpc_call/CMakeUserPresets.json @@ -0,0 +1,9 @@ +{ + "version": 4, + "vendor": { + "conan": {} + }, + "include": [ + "build/CMakePresets.json" + ] +} \ No newline at end of file diff --git a/examples/rpc_call/README.md b/examples/rpc_call/README.md new file mode 100644 index 0000000..f5ab16c --- /dev/null +++ b/examples/rpc_call/README.md @@ -0,0 +1,10 @@ +# RPC Call Example + +## Compiling +``` +conan install . --build=missing --output-folder=build -s build_type=Release +cmake -S . -B "build" -DCMAKE_TOOLCHAIN_FILE="build/conan_toolchain.cmake" -DCMAKE_BUILD_TYPE="Release" +cmake --build "./build" --config "Release" + +./build/RpcCallExample +``` diff --git a/examples/rpc_call/build.sh b/examples/rpc_call/build.sh new file mode 100755 index 0000000..f86fd4d --- /dev/null +++ b/examples/rpc_call/build.sh @@ -0,0 +1,3 @@ +conan install . --build=missing --output-folder=build -s build_type=Release +cmake -S . -B "build" -DCMAKE_TOOLCHAIN_FILE="build/conan_toolchain.cmake" -DCMAKE_BUILD_TYPE="Release" +cmake --build "./build" --config "Release" diff --git a/examples/rpc_call/conanfile.txt b/examples/rpc_call/conanfile.txt new file mode 100644 index 0000000..a61eff3 --- /dev/null +++ b/examples/rpc_call/conanfile.txt @@ -0,0 +1,9 @@ +[requires] +libcontrol/1.0.0 +flatbuffers/24.12.23 +spdlog/1.16.0 +librpc/1.1.7 + +[generators] +CMakeDeps +CMakeToolchain diff --git a/examples/rpc_call/main.cpp b/examples/rpc_call/main.cpp new file mode 100644 index 0000000..1bf0448 --- /dev/null +++ b/examples/rpc_call/main.cpp @@ -0,0 +1,40 @@ +#include +#include +#include +#include +#include +#include +#include + +#include "libcontrol.h" + +int main() { + + const auto messaging_interface = std::make_unique(); + + const auto modules = + messaging_interface->find_connected_modules(std::chrono::seconds(3)); + + std::cout << "Found " << modules.size() << " modules" << std::endl; + + for (const auto module : modules) { + std::cout << "Found ID " << (int)module << std::endl; + } + + const auto function_tag = 100; + const auto module = 98; + std::string msg = "Hello world!"; + std::vector parameters(msg.begin(), msg.end()); + auto maybe_return_value = + messaging_interface->remote_call(function_tag, module, parameters); + + if (maybe_return_value) { + auto return_value = std::move(*maybe_return_value); + std::cout << "Got return value " << (char *)return_value->data() + << std::endl; + } else { + std::cout << "Function call time out" << std::endl; + } + + return 0; +}