xref: /openbmc/sdbusplus/tools/sdbusplus/templates/property.server.cpp.mako (revision 3a1d8b97bbb95cb912a6827a891f057d1c6709bb)
1auto ${interface.classname}::${property.camelCase}() const ->
2        ${property.cppTypeParam(interface.name)}
3{
4    return _${property.camelCase};
5}
6
7int ${interface.classname}::_callback_get_${property.name}(
8        sd_bus* /*bus*/, const char* /*path*/, const char* /*interface*/,
9        const char* /*property*/, sd_bus_message* reply, void* context,
10        sd_bus_error* error)
11{
12    auto o = static_cast<${interface.classname}*>(context);
13
14    try
15    {
16        return sdbusplus::sdbuspp::property_callback(
17                reply, o->get_bus().getInterface(), error,
18                std::function(
19                    [=]()
20                    {
21                        return o->${property.camelCase}();
22                    }
23                ));
24    }
25    % for e in property.errors:
26    catch(const ${interface.errorNamespacedClass(e)}& e)
27    {
28        return o->get_bus().getInterface()->sd_bus_error_set(error, e.name(), e.description());
29    }
30    % endfor
31    catch (const std::exception&)
32    {
33        o->get_bus().set_current_exception(std::current_exception());
34        return 1;
35    }
36}
37
38auto ${interface.classname}::${property.camelCase}(${property.cppTypeParam(interface.name)} value,
39                                         bool skipSignal) ->
40        ${property.cppTypeParam(interface.name)}
41{
42    if (_${property.camelCase} != value)
43    {
44        _${property.camelCase} = value;
45        if (!skipSignal)
46        {
47            _${interface.joinedName("_", "interface")}.property_changed("${property.name}");
48        }
49    }
50
51    return _${property.camelCase};
52}
53
54auto ${interface.classname}::${property.camelCase}(${property.cppTypeParam(interface.name)} val) ->
55        ${property.cppTypeParam(interface.name)}
56{
57    return ${property.camelCase}(val, false);
58}
59
60% if 'const' not in property.flags and 'readonly' not in property.flags:
61int ${interface.classname}::_callback_set_${property.name}(
62        sd_bus* /*bus*/, const char* /*path*/, const char* /*interface*/,
63        const char* /*property*/, sd_bus_message* value, void* context,
64        sd_bus_error* error)
65{
66    auto o = static_cast<${interface.classname}*>(context);
67
68    try
69    {
70        return sdbusplus::sdbuspp::property_callback(
71                value, o->get_bus().getInterface(), error,
72                std::function(
73                    [=](${property.cppTypeParam(interface.name)}&& arg)
74                    {
75                        o->${property.camelCase}(std::move(arg));
76                    }
77                ));
78    }
79    % for e in property.errors:
80    catch(const ${interface.errorNamespacedClass(e)}& e)
81    {
82        return o->get_bus().getInterface()->sd_bus_error_set(error, e.name(), e.description());
83    }
84    % endfor
85    catch (const std::exception&)
86    {
87        o->get_bus().set_current_exception(std::current_exception());
88        return 1;
89    }
90}
91% endif
92
93namespace details
94{
95namespace ${interface.classname}
96{
97static const auto _property_${property.name} =
98    utility::tuple_to_array(message::types::type_id<
99            ${property.cppTypeParam(interface.name, full=True)}>());
100}
101}
102