Skip to content

Instantly share code, notes, and snippets.

@williamspatrick
Created May 1, 2023 19:34
Show Gist options
  • Save williamspatrick/a4ffa6bc9154d5fe460d46c1654c04bf to your computer and use it in GitHub Desktop.
Save williamspatrick/a4ffa6bc9154d5fe460d46c1654c04bf to your computer and use it in GitHub Desktop.
#pragma once
#include <sdbusplus/async/client.hpp>
#include <type_traits>
#include <net/poettering/Calculator/common.hpp>
#ifndef SDBUSPP_REMOVE_DEPRECATED_NAMESPACE
namespace sdbusplus::net::poettering::client::Calculator
{
constexpr auto interface =
sdbusplus::common::net::poettering::Calculator::interface;
} // namespace sdbusplus::net::poettering::client::Calculator
#endif
namespace sdbusplus::client::net::poettering
{
namespace details
{
template <typename Proxy>
class Calculator :
public sdbusplus::common::net::poettering::Calculator
{
public:
template <bool S, bool P, bool Preserved,
template <typename> typename... Types>
friend class sdbusplus::async::client::client;
// Delete default constructor as these should only be constructed
// indirectly through sdbusplus::async::client_t.
Calculator() = delete;
/** @brief Multiply
* Multiplies two integers 'x' and 'y' and returns the result.
*
* @param[in] x - The first integer to multiply.
* @param[in] y - The second integer to multiply.
*
* @return z[int64_t] - The result of (x*y).
*/
auto multiply(int64_t x, int64_t y)
{
return proxy.template call<int64_t>(ctx, "Multiply", x, y);
}
/** @brief Divide
* Divides two integers 'x' and 'y' and returns the result.
*
* @param[in] x - The first integer to divide.
* @param[in] y - The second integer to divide.
*
* @return z[int64_t] - The result of (x/y).
*/
auto divide(int64_t x, int64_t y)
{
return proxy.template call<int64_t>(ctx, "Divide", x, y);
}
/** @brief Clear
* Reset the LastResult property to zero.
*/
auto clear()
{
return proxy.template call<>(ctx, "Clear");
}
/** Get value of LastResult
* The result of the most recent calculation.
*/
auto lastResult()
{
return proxy.template get_property<int64_t>(ctx, "LastResult");
}
/** Set value of LastResult
* The result of the most recent calculation.
*/
auto lastResult(auto value)
{
return proxy.template set_property<int64_t>(
ctx, "LastResult", std::forward<decltype(value)>(value));
}
/** Get value of Status
* The current state of the Calculator.
*/
auto status()
{
return proxy.template get_property<State>(ctx, "Status");
}
/** Set value of Status
* The current state of the Calculator.
*/
auto status(auto value)
{
return proxy.template set_property<State>(
ctx, "Status", std::forward<decltype(value)>(value));
}
/** Get value of Owner
* The name of the owner of the Calculator.
*/
auto owner()
{
return proxy.template get_property<std::string>(ctx, "Owner");
}
/** Set value of Owner
* The name of the owner of the Calculator.
*/
auto owner(auto value)
{
return proxy.template set_property<std::string>(
ctx, "Owner", std::forward<decltype(value)>(value));
}
private:
// Conversion constructor from proxy used by client_t.
constexpr Calculator(sdbusplus::async::context& ctx, Proxy p) :
ctx(ctx), proxy(p.interface(interface)) {}
sdbusplus::async::context& ctx{};
decltype(std::declval<Proxy>().interface(interface)) proxy = {};
};
} // namespace details
/** Alias class so we can use the client in both a client_t aggregation
* and individually.
*
* sdbusplus::async::client_t<Calculator>() or
* Calculator() both construct an equivalent instance.
*/
template <typename Proxy = void>
struct Calculator : public
std::conditional_t<
std::is_void_v<Proxy>,
sdbusplus::async::client_t<details::Calculator>,
details::Calculator<Proxy>>
{
template <typename... Args>
Calculator(Args&&... args) :
std::conditional_t<std::is_void_v<Proxy>,
sdbusplus::async::client_t<details::Calculator>,
details::Calculator<Proxy>>(
std::forward<Args>(args)...)
{}
};
} // namespace sdbusplus::client::net::poettering::Calculator
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment