From e811b2f7a084ee34e37b6eb79b9dc2f14d9d1dac Mon Sep 17 00:00:00 2001 From: Aki Date: Sat, 16 Oct 2021 14:39:18 +0200 Subject: Added Gpio and Assembly stubs --- daemon/CMakeLists.txt | 2 ++ daemon/src/Assembly-inl.h | 17 +++++++++++++++++ daemon/src/Assembly.cpp | 16 ++++++++++++++++ daemon/src/Assembly.h | 33 +++++++++++++++++++++++++++++++++ daemon/src/Gpio.cpp | 11 +++++++++++ daemon/src/Gpio.h | 12 ++++++++++++ daemon/src/daemon.cpp | 7 +++++++ 7 files changed, 98 insertions(+) create mode 100644 daemon/src/Assembly-inl.h create mode 100644 daemon/src/Assembly.cpp create mode 100644 daemon/src/Assembly.h create mode 100644 daemon/src/Gpio.cpp create mode 100644 daemon/src/Gpio.h (limited to 'daemon') 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 + + +template +void Assembly::add(const std::string & prefix, T & element) +{ + element.apply(AssemblyContext{*this, prefix}); +} + + +template +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 + +#include + + +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 + +#include + + +class Assembly; + + +class AssemblyContext +{ +public: + AssemblyContext(Assembly & parent, const std::string & prefix) noexcept; + template 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 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 + +#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 + +#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 +#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(); }); -- cgit v1.1