summaryrefslogtreecommitdiff
path: root/daemon
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2021-10-16 14:39:18 +0200
committerAki <please@ignore.pl>2021-10-16 14:39:18 +0200
commite811b2f7a084ee34e37b6eb79b9dc2f14d9d1dac (patch)
treed1abd73302bba47e97bf98debd20d263a2447556 /daemon
parentf68fb3b96b593f56ec70ad17f216fe3aedbc020d (diff)
downloadhwd-e811b2f7a084ee34e37b6eb79b9dc2f14d9d1dac.zip
hwd-e811b2f7a084ee34e37b6eb79b9dc2f14d9d1dac.tar.gz
hwd-e811b2f7a084ee34e37b6eb79b9dc2f14d9d1dac.tar.bz2
Added Gpio and Assembly stubs
Diffstat (limited to 'daemon')
-rw-r--r--daemon/CMakeLists.txt2
-rw-r--r--daemon/src/Assembly-inl.h17
-rw-r--r--daemon/src/Assembly.cpp16
-rw-r--r--daemon/src/Assembly.h33
-rw-r--r--daemon/src/Gpio.cpp11
-rw-r--r--daemon/src/Gpio.h12
-rw-r--r--daemon/src/daemon.cpp7
7 files changed, 98 insertions, 0 deletions
diff --git a/daemon/CMakeLists.txt b/daemon/CMakeLists.txt
index c027047..a68394c 100644
--- a/daemon/CMakeLists.txt
+++ b/daemon/CMakeLists.txt
@@ -1,6 +1,8 @@
project(daemon CXX)
add_executable(${PROJECT_NAME}
+ src/Assembly.cpp
src/daemon.cpp
+ src/Gpio.cpp
)
target_link_libraries(${PROJECT_NAME}
PRIVATE rpclib::rpc
diff --git a/daemon/src/Assembly-inl.h b/daemon/src/Assembly-inl.h
new file mode 100644
index 0000000..5cfd026
--- /dev/null
+++ b/daemon/src/Assembly-inl.h
@@ -0,0 +1,17 @@
+#pragma once
+
+#include <string>
+
+
+template <typename T>
+void Assembly::add(const std::string & prefix, T & element)
+{
+ element.apply(AssemblyContext{*this, prefix});
+}
+
+
+template <typename T>
+void AssemblyContext::bind(const std::string & name, const T & function)
+{
+ assembly.server.bind(prefix + name, function);
+}
diff --git a/daemon/src/Assembly.cpp b/daemon/src/Assembly.cpp
new file mode 100644
index 0000000..1c534b4
--- /dev/null
+++ b/daemon/src/Assembly.cpp
@@ -0,0 +1,16 @@
+#include "Assembly.h"
+
+#include <string>
+
+#include <rpc/server.h>
+
+
+AssemblyContext::AssemblyContext(Assembly & parent, const std::string & prfx) noexcept :
+ assembly {parent},
+ prefix {prfx}
+{}
+
+
+Assembly::Assembly(rpc::server & srv) :
+ server {srv}
+{}
diff --git a/daemon/src/Assembly.h b/daemon/src/Assembly.h
new file mode 100644
index 0000000..8ffc038
--- /dev/null
+++ b/daemon/src/Assembly.h
@@ -0,0 +1,33 @@
+#pragma once
+
+#include <string>
+
+#include <rpc/server.h>
+
+
+class Assembly;
+
+
+class AssemblyContext
+{
+public:
+ AssemblyContext(Assembly & parent, const std::string & prefix) noexcept;
+ template <typename T> void bind(const std::string & name, const T & function);
+private:
+ Assembly & assembly;
+ const std::string & prefix;
+};
+
+
+class Assembly
+{
+ friend AssemblyContext;
+public:
+ explicit Assembly(rpc::server & server);
+ template <typename T> void add(const std::string & prefix, T & element);
+private:
+ rpc::server & server;
+};
+
+
+#include "Assembly-inl.h"
diff --git a/daemon/src/Gpio.cpp b/daemon/src/Gpio.cpp
new file mode 100644
index 0000000..656c585
--- /dev/null
+++ b/daemon/src/Gpio.cpp
@@ -0,0 +1,11 @@
+#include "Gpio.h"
+
+#include <rpc/server.h>
+
+#include "Assembly.h"
+
+
+void Gpio::apply(AssemblyContext ctx)
+{
+ ctx.bind("nothing", []{});
+}
diff --git a/daemon/src/Gpio.h b/daemon/src/Gpio.h
new file mode 100644
index 0000000..ef77631
--- /dev/null
+++ b/daemon/src/Gpio.h
@@ -0,0 +1,12 @@
+#pragma once
+
+#include <rpc/server.h>
+
+#include "Assembly.h"
+
+
+class Gpio
+{
+public:
+ void apply(AssemblyContext ctx);
+};
diff --git a/daemon/src/daemon.cpp b/daemon/src/daemon.cpp
index 352218d..99da92c 100644
--- a/daemon/src/daemon.cpp
+++ b/daemon/src/daemon.cpp
@@ -3,9 +3,16 @@
#include <hwd/internal.h>
+#include "Assembly.h"
+#include "Gpio.h"
+
+
int main(int, char **)
{
rpc::server server(hwd::internal::default_port);
+ Assembly assembly {server};
+ Gpio gpio;
+ assembly.add("gpio", gpio);
server.bind("stop_server", []{
rpc::this_server().stop();
});