summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--CMakeLists.txt11
-rw-r--r--common/CMakeLists.txt6
-rw-r--r--common/include/hwd/internal.h7
-rw-r--r--daemon/CMakeLists.txt12
-rw-r--r--daemon/src/daemon.cpp13
-rw-r--r--library/CMakeLists.txt29
-rw-r--r--library/include/hwd.h4
-rw-r--r--library/src/library.cpp19
-rw-r--r--sample_client/CMakeLists.txt7
-rw-r--r--sample_client/src/client.cpp6
11 files changed, 115 insertions, 0 deletions
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 <rpc/server.h>
+#include <rpc/this_server.h>
+
+#include <hwd/internal.h>
+
+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 "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
+ PUBLIC "$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>"
+ )
+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 <rpc/client.h>
+
+#include <hwd/internal.h>
+
+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 <hwd.h>
+
+int main(int, char **)
+{
+ hwd::stop_server();
+}