summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--daemon/src/daemon.cpp7
-rw-r--r--library/include/hwd.h2
-rw-r--r--library/src/library.cpp10
-rw-r--r--sample_client/src/client.cpp50
4 files changed, 67 insertions, 2 deletions
diff --git a/daemon/src/daemon.cpp b/daemon/src/daemon.cpp
index feb6570..352218d 100644
--- a/daemon/src/daemon.cpp
+++ b/daemon/src/daemon.cpp
@@ -9,5 +9,12 @@ int main(int, char **)
server.bind("stop_server", []{
rpc::this_server().stop();
});
+ int value = 0;
+ server.bind("set_value", [&value](int a){
+ value = a;
+ });
+ server.bind("get_value", [&value](){
+ return value;
+ });
server.run();
}
diff --git a/library/include/hwd.h b/library/include/hwd.h
index afb7b20..197b44b 100644
--- a/library/include/hwd.h
+++ b/library/include/hwd.h
@@ -3,4 +3,6 @@
namespace hwd
{
void stop_server();
+void set_value(int value);
+int get_value();
}
diff --git a/library/src/library.cpp b/library/src/library.cpp
index 4691849..73f40f9 100644
--- a/library/src/library.cpp
+++ b/library/src/library.cpp
@@ -16,4 +16,14 @@ void stop_server()
get_client().call("stop_server");
}
+void set_value(const int value)
+{
+ get_client().call("set_value", value);
+}
+
+int get_value()
+{
+ return get_client().call("get_value").as<int>();
+}
+
} // namespace hwd
diff --git a/sample_client/src/client.cpp b/sample_client/src/client.cpp
index 87421ca..c0125c2 100644
--- a/sample_client/src/client.cpp
+++ b/sample_client/src/client.cpp
@@ -1,6 +1,52 @@
+#include <cstdlib>
+#include <iostream>
+#include <stdexcept>
+#include <string_view>
+
#include <hwd.h>
-int main(int, char **)
+int main(int argc, char ** argv)
{
- hwd::stop_server();
+ if (2 > argc)
+ {
+ std::cerr << "missing operation" << std::endl;
+ return 1;
+ }
+ std::string_view op {argv[1]};
+ if (0 == op.compare("shutdown"))
+ {
+ hwd::stop_server();
+ }
+ else if (0 == op.compare("set"))
+ {
+ if (3 > argc)
+ {
+ std::cerr << "missing int argument to set" << std::endl;
+ return 1;
+ }
+ std::string input {argv[2]};
+ try
+ {
+ hwd::set_value(std::stoi(input));
+ }
+ catch (const std::invalid_argument &)
+ {
+ std::cerr << "bad argument to set" << std::endl;
+ return 1;
+ }
+ catch (const std::out_of_range &)
+ {
+ std::cerr << "int argument is too large" << std::endl;
+ return 1;
+ }
+ }
+ else if (0 == op.compare("get"))
+ {
+ std::cout << hwd::get_value() << std::endl;
+ }
+ else
+ {
+ std::cerr << "invalid operation" << std::endl;
+ return 1;
+ }
}