example:calculator: Add property overrides
Add examples of how to override the get and set property calls.
Change-Id: I1436ed7c286aa141ffb63a6af8c4766bf764f74b
Signed-off-by: Matt Spinler <spinler@us.ibm.com>
diff --git a/example/calculator-aserver.cpp b/example/calculator-aserver.cpp
index 9880e49..b0500de 100644
--- a/example/calculator-aserver.cpp
+++ b/example/calculator-aserver.cpp
@@ -1,6 +1,8 @@
#include <net/poettering/Calculator/aserver.hpp>
#include <sdbusplus/async.hpp>
+#include <iostream>
+
class Calculator :
public sdbusplus::aserver::net::poettering::Calculator<Calculator>
{
@@ -38,6 +40,19 @@
cleared(v);
co_return;
}
+
+ auto get_property(owner_t) const
+ {
+ std::cout << " get_property on owner\n";
+ return owner_;
+ }
+
+ bool set_property(owner_t, auto owner)
+ {
+ std::cout << " set_property on owner\n";
+ std::swap(owner_, owner);
+ return owner_ == owner;
+ }
};
int main()
diff --git a/example/calculator-client.cpp b/example/calculator-client.cpp
index 0ba1438..0c9b3ad 100644
--- a/example/calculator-client.cpp
+++ b/example/calculator-client.cpp
@@ -50,6 +50,15 @@
std::cout << "Should be 1234: " << _ << std::endl;
}
+ {
+ co_await c.owner("client");
+ }
+
+ {
+ auto _ = co_await c.owner();
+ std::cout << "Should be 'client': " << _ << std::endl;
+ }
+
co_return;
}