1<%
2p_name = property.snake_case
3p_tag = property.snake_case + "_t"
4p_type = property.cppTypeParam(interface.name)
5i_name = interface.classname
6%>\
7    static int _callback_get_${p_name}(
8        sd_bus*, const char*, const char*, const char*,
9        sd_bus_message* reply, void* context,
10        sd_bus_error* error [[maybe_unused]])
11    {
12        auto self = static_cast<${i_name}*>(context);
13
14        try
15        {
16            auto m = sdbusplus::message_t{reply};
17
18            // Set up the transaction.
19            server::transaction::set_id(m);
20
21            // Get property value and add to message.
22            if constexpr (server_details::has_get_property_msg<${p_tag},
23                                                               Instance>)
24            {
25                auto v = self->${p_name}(m);
26                static_assert(std::is_convertible_v<decltype(v), ${p_type}>,
27                              "Property doesn't convert to '${p_type}'.");
28                m.append<${p_type}>(std::move(v));
29            }
30            else
31            {
32                auto v = self->${p_name}();
33                static_assert(std::is_convertible_v<decltype(v), ${p_type}>,
34                              "Property doesn't convert to '${p_type}'.");
35                m.append<${p_type}>(std::move(v));
36            }
37        }
38        % for e in property.errors:
39        catch (const ${interface.errorNamespacedClass(e)}& e)
40        {
41            return sd_bus_error_set(error, e.name(), e.description());
42        }
43        % endfor
44        catch (const std::exception&)
45        {
46            self->_context().get_bus().set_current_exception(
47                std::current_exception());
48            return -EINVAL;
49        }
50
51        return 1;
52    }
53
54% if 'const' not in property.flags and 'readonly' not in property.flags:
55    static int _callback_set_${p_name}(
56        sd_bus*, const char*, const char*, const char*,
57        sd_bus_message* value[[maybe_unused]], void* context [[maybe_unused]],
58        sd_bus_error* error [[maybe_unused]])
59    {
60        auto self = static_cast<${i_name}*>(context);
61
62        try
63        {
64            auto m = sdbusplus::message_t{value};
65
66            // Set up the transaction.
67            server::transaction::set_id(m);
68
69            auto new_value = m.unpack<${p_type}>();
70
71            // Get property value and add to message.
72            if constexpr (server_details::has_set_property_msg<
73                              ${p_tag}, Instance, ${p_type}>)
74            {
75                self->${p_name}(m, std::move(new_value));
76            }
77            else
78            {
79                self->${p_name}(std::move(new_value));
80            }
81        }
82        % for e in property.errors:
83        catch (const ${interface.errorNamespacedClass(e)}& e)
84        {
85            return sd_bus_error_set(error, e.name(), e.description());
86        }
87        % endfor
88        catch (const std::exception&)
89        {
90            self->_context().get_bus().set_current_exception(
91                std::current_exception());
92            return -EINVAL;
93        }
94
95        return 1;
96    }
97% endif
98