|
#include <sdbusplus/server.hpp> |
|
#include <net/poettering/Calculator/server.hpp> |
|
|
|
namespace sdbusplus |
|
{ |
|
namespace server |
|
{ |
|
namespace net |
|
{ |
|
namespace poettering |
|
{ |
|
|
|
Calculator::Calculator(bus::bus& bus, const char* path) |
|
: _net_poettering_Calculator_interface( |
|
bus, path, _interface, _vtable, this) |
|
{ |
|
} |
|
|
|
|
|
int Calculator::_callback_Multiply( |
|
sd_bus_message* msg, void* context, sd_bus_error* error) |
|
{ |
|
auto m = message::message(sd_bus_message_ref(msg)); |
|
|
|
int64_t x{}; |
|
int64_t y{}; |
|
|
|
m.read(x, y); |
|
|
|
auto o = static_cast<Calculator*>(context); |
|
auto r = o->multiply(x, y); |
|
|
|
auto reply = m.new_method_return(); |
|
reply.append(std::move(r)); |
|
|
|
reply.method_return(); |
|
|
|
return 0; |
|
} |
|
|
|
namespace details |
|
{ |
|
namespace Calculator |
|
{ |
|
static const auto _param_Multiply = |
|
utility::tuple_to_array(message::types::type_id< |
|
int64_t, int64_t>()); |
|
static const auto _return_Multiply = |
|
utility::tuple_to_array(message::types::type_id< |
|
int64_t>()); |
|
} |
|
} |
|
|
|
int Calculator::_callback_Divide( |
|
sd_bus_message* msg, void* context, sd_bus_error* error) |
|
{ |
|
auto m = message::message(sd_bus_message_ref(msg)); |
|
|
|
int64_t x{}; |
|
int64_t y{}; |
|
|
|
m.read(x, y); |
|
|
|
auto o = static_cast<Calculator*>(context); |
|
auto r = o->divide(x, y); |
|
|
|
auto reply = m.new_method_return(); |
|
reply.append(std::move(r)); |
|
|
|
reply.method_return(); |
|
|
|
return 0; |
|
} |
|
|
|
namespace details |
|
{ |
|
namespace Calculator |
|
{ |
|
static const auto _param_Divide = |
|
utility::tuple_to_array(message::types::type_id< |
|
int64_t, int64_t>()); |
|
static const auto _return_Divide = |
|
utility::tuple_to_array(message::types::type_id< |
|
int64_t>()); |
|
} |
|
} |
|
|
|
int Calculator::_callback_Clear( |
|
sd_bus_message* msg, void* context, sd_bus_error* error) |
|
{ |
|
auto m = message::message(sd_bus_message_ref(msg)); |
|
|
|
|
|
auto o = static_cast<Calculator*>(context); |
|
o->clear(); |
|
|
|
auto reply = m.new_method_return(); |
|
// No data to append on reply. |
|
|
|
reply.method_return(); |
|
|
|
return 0; |
|
} |
|
|
|
namespace details |
|
{ |
|
namespace Calculator |
|
{ |
|
static const auto _param_Clear = |
|
utility::tuple_to_array(std::make_tuple('\0')); |
|
static const auto _return_Clear = |
|
utility::tuple_to_array(std::make_tuple('\0')); |
|
} |
|
} |
|
|
|
|
|
void Calculator::cleared( |
|
int64_t unnamed) |
|
{ |
|
auto& i = _net_poettering_Calculator_interface; |
|
auto m = i.new_signal("Cleared"); |
|
|
|
m.append(unnamed); |
|
m.signal_send(); |
|
|
|
} |
|
|
|
namespace details |
|
{ |
|
namespace Calculator |
|
{ |
|
static const auto _signal_Cleared = |
|
utility::tuple_to_array(message::types::type_id< |
|
int64_t>()); |
|
} |
|
} |
|
|
|
int64_t Calculator::lastResult() const |
|
{ |
|
return _lastResult; |
|
} |
|
|
|
int Calculator::_callback_get_LastResult( |
|
sd_bus* bus, const char* path, const char* interface, |
|
const char* property, sd_bus_message* reply, void* context, |
|
sd_bus_error* error) |
|
{ |
|
auto m = message::message(sd_bus_message_ref(reply)); |
|
|
|
auto o = static_cast<Calculator*>(context); |
|
m.append(o->lastResult()); |
|
|
|
return 0; |
|
} |
|
|
|
int64_t Calculator::lastResult(int64_t value) |
|
{ |
|
if (_lastResult != value) |
|
{ |
|
_lastResult = value; |
|
_net_poettering_Calculator_interface.property_changed("LastResult"); |
|
} |
|
|
|
return _lastResult; |
|
} |
|
|
|
int Calculator::_callback_set_LastResult( |
|
sd_bus* bus, const char* path, const char* interface, |
|
const char* property, sd_bus_message* value, void* context, |
|
sd_bus_error* error) |
|
{ |
|
auto m = message::message(sd_bus_message_ref(value)); |
|
|
|
auto o = static_cast<Calculator*>(context); |
|
|
|
decltype(_lastResult) v{}; |
|
m.read(v); |
|
o->lastResult(v); |
|
|
|
return 0; |
|
} |
|
|
|
namespace details |
|
{ |
|
namespace Calculator |
|
{ |
|
static const auto _property_LastResult = |
|
utility::tuple_to_array(message::types::type_id< |
|
int64_t>()); |
|
} |
|
} |
|
|
|
const vtable::vtable_t Calculator::_vtable[] = { |
|
vtable::start(), |
|
|
|
vtable::method("Multiply", |
|
details::Calculator::_param_Multiply |
|
.data(), |
|
details::Calculator::_return_Multiply |
|
.data(), |
|
_callback_Multiply), |
|
|
|
vtable::method("Divide", |
|
details::Calculator::_param_Divide |
|
.data(), |
|
details::Calculator::_return_Divide |
|
.data(), |
|
_callback_Divide), |
|
|
|
vtable::method("Clear", |
|
details::Calculator::_param_Clear |
|
.data(), |
|
details::Calculator::_return_Clear |
|
.data(), |
|
_callback_Clear), |
|
|
|
vtable::signal("Cleared", |
|
details::Calculator::_signal_Cleared |
|
.data()), |
|
vtable::property("LastResult", |
|
details::Calculator::_property_LastResult |
|
.data(), |
|
_callback_get_LastResult, |
|
_callback_set_LastResult, |
|
vtable::property_::emits_change), |
|
vtable::end() |
|
}; |
|
|
|
} // namespace poettering |
|
} // namespace net |
|
} // namespace server |
|
} // namespace sdbusplus |
|
|