From 0dd0ba272f247ca6e9b7948b648e42ff544c71ac Mon Sep 17 00:00:00 2001 From: Aki Date: Thu, 14 Oct 2021 22:51:43 +0200 Subject: Created stub daemon with a communication library --- .gitignore | 1 + CMakeLists.txt | 11 +++++++++++ common/CMakeLists.txt | 6 ++++++ common/include/hwd/internal.h | 7 +++++++ daemon/CMakeLists.txt | 12 ++++++++++++ daemon/src/daemon.cpp | 13 +++++++++++++ library/CMakeLists.txt | 29 +++++++++++++++++++++++++++++ library/include/hwd.h | 4 ++++ library/src/library.cpp | 19 +++++++++++++++++++ sample_client/CMakeLists.txt | 7 +++++++ sample_client/src/client.cpp | 6 ++++++ 11 files changed, 115 insertions(+) create mode 100644 .gitignore create mode 100644 CMakeLists.txt create mode 100644 common/CMakeLists.txt create mode 100644 common/include/hwd/internal.h create mode 100644 daemon/CMakeLists.txt create mode 100644 daemon/src/daemon.cpp create mode 100644 library/CMakeLists.txt create mode 100644 library/include/hwd.h create mode 100644 library/src/library.cpp create mode 100644 sample_client/CMakeLists.txt create mode 100644 sample_client/src/client.cpp diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d163863 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +build/ \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..f28fa63 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,11 @@ +cmake_minimum_required(VERSION 3.18) +project(hwd) +include(GNUInstallDirs) +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_EXTENSIONS No) +find_package(Threads REQUIRED) +find_package(rpclib 2 REQUIRED) +add_subdirectory(common) +add_subdirectory(daemon) +add_subdirectory(library) +add_subdirectory(sample_client) diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt new file mode 100644 index 0000000..5c4c9e1 --- /dev/null +++ b/common/CMakeLists.txt @@ -0,0 +1,6 @@ +project(common CXX) +add_library(${PROJECT_NAME} INTERFACE + ) +target_include_directories(${PROJECT_NAME} + INTERFACE include + ) diff --git a/common/include/hwd/internal.h b/common/include/hwd/internal.h new file mode 100644 index 0000000..614c962 --- /dev/null +++ b/common/include/hwd/internal.h @@ -0,0 +1,7 @@ +namespace hwd +{ +namespace internal +{ +constexpr int default_port = 4236; +} +} diff --git a/daemon/CMakeLists.txt b/daemon/CMakeLists.txt new file mode 100644 index 0000000..831dae3 --- /dev/null +++ b/daemon/CMakeLists.txt @@ -0,0 +1,12 @@ +project(daemon CXX) +add_executable(${PROJECT_NAME} + src/daemon.cpp + ) +target_link_libraries(${PROJECT_NAME} + PRIVATE rpclib::rpc + PRIVATE Threads::Threads + PRIVATE common + ) +install(TARGETS ${PROJECT_NAME} + RUNTIME + ) diff --git a/daemon/src/daemon.cpp b/daemon/src/daemon.cpp new file mode 100644 index 0000000..feb6570 --- /dev/null +++ b/daemon/src/daemon.cpp @@ -0,0 +1,13 @@ +#include +#include + +#include + +int main(int, char **) +{ + rpc::server server(hwd::internal::default_port); + server.bind("stop_server", []{ + rpc::this_server().stop(); + }); + server.run(); +} diff --git a/library/CMakeLists.txt b/library/CMakeLists.txt new file mode 100644 index 0000000..a1e146b --- /dev/null +++ b/library/CMakeLists.txt @@ -0,0 +1,29 @@ +project(library CXX) +add_library(${PROJECT_NAME} SHARED + src/library.cpp + ) +target_link_libraries(${PROJECT_NAME} + PUBLIC rpclib::rpc + PUBLIC Threads::Threads + PRIVATE common + ) +target_include_directories(${PROJECT_NAME} + PUBLIC "$" + PUBLIC "$" + ) +set_target_properties(${PROJECT_NAME} + PROPERTIES OUTPUT_NAME hwd + ) +install(TARGETS ${PROJECT_NAME} + EXPORT HwdTargets + RUNTIME + INCLUDES + ) +install(FILES include/hwd.h + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + ) +install(EXPORT HwdTargets + FILE HwdTargets.cmake + NAMESPACE Hwd:: + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/Hwd + ) diff --git a/library/include/hwd.h b/library/include/hwd.h new file mode 100644 index 0000000..0deba70 --- /dev/null +++ b/library/include/hwd.h @@ -0,0 +1,4 @@ +namespace hwd +{ +void stop_server(); +} diff --git a/library/src/library.cpp b/library/src/library.cpp new file mode 100644 index 0000000..4691849 --- /dev/null +++ b/library/src/library.cpp @@ -0,0 +1,19 @@ +#include + +#include + +namespace hwd +{ + +static rpc::client & get_client() +{ + static rpc::client c("127.0.0.1", hwd::internal::default_port); + return c; +} + +void stop_server() +{ + get_client().call("stop_server"); +} + +} // namespace hwd diff --git a/sample_client/CMakeLists.txt b/sample_client/CMakeLists.txt new file mode 100644 index 0000000..c6166fd --- /dev/null +++ b/sample_client/CMakeLists.txt @@ -0,0 +1,7 @@ +project(sample_client CXX) +add_executable(${PROJECT_NAME} + src/client.cpp + ) +target_link_libraries(${PROJECT_NAME} + PRIVATE library + ) diff --git a/sample_client/src/client.cpp b/sample_client/src/client.cpp new file mode 100644 index 0000000..87421ca --- /dev/null +++ b/sample_client/src/client.cpp @@ -0,0 +1,6 @@ +#include + +int main(int, char **) +{ + hwd::stop_server(); +} -- cgit v1.1