1f84f1117SPatrick Williams<%
2f84f1117SPatrick Williamsp_name = property.snake_case
3f84f1117SPatrick Williamsp_tag = property.snake_case + "_t"
4f84f1117SPatrick Williamsp_type = property.cppTypeParam(interface.name)
5f84f1117SPatrick Williamsi_name = interface.classname
6f84f1117SPatrick Williams%>\
7f84f1117SPatrick Williams    static int _callback_get_${p_name}(
8f84f1117SPatrick Williams        sd_bus*, const char*, const char*, const char*,
9f84f1117SPatrick Williams        sd_bus_message* reply, void* context,
10f84f1117SPatrick Williams        sd_bus_error* error [[maybe_unused]])
11f84f1117SPatrick Williams    {
12f84f1117SPatrick Williams        auto self = static_cast<${i_name}*>(context);
13f84f1117SPatrick Williams
14f84f1117SPatrick Williams        try
15f84f1117SPatrick Williams        {
16f84f1117SPatrick Williams            auto m = sdbusplus::message_t{reply};
17f84f1117SPatrick Williams
18f84f1117SPatrick Williams            // Set up the transaction.
19f84f1117SPatrick Williams            server::transaction::set_id(m);
20f84f1117SPatrick Williams
21f84f1117SPatrick Williams            // Get property value and add to message.
22f84f1117SPatrick Williams            if constexpr (server_details::has_get_property_msg<${p_tag},
23f84f1117SPatrick Williams                                                               Instance>)
24f84f1117SPatrick Williams            {
25f84f1117SPatrick Williams                auto v = self->${p_name}(m);
26f84f1117SPatrick Williams                static_assert(std::is_convertible_v<decltype(v), ${p_type}>,
27f84f1117SPatrick Williams                              "Property doesn't convert to '${p_type}'.");
28f84f1117SPatrick Williams                m.append<${p_type}>(std::move(v));
29f84f1117SPatrick Williams            }
30f84f1117SPatrick Williams            else
31f84f1117SPatrick Williams            {
32f84f1117SPatrick Williams                auto v = self->${p_name}();
33f84f1117SPatrick Williams                static_assert(std::is_convertible_v<decltype(v), ${p_type}>,
34f84f1117SPatrick Williams                              "Property doesn't convert to '${p_type}'.");
35f84f1117SPatrick Williams                m.append<${p_type}>(std::move(v));
36f84f1117SPatrick Williams            }
37f84f1117SPatrick Williams        }
38f84f1117SPatrick Williams        % for e in property.errors:
39f84f1117SPatrick Williams        catch (const ${interface.errorNamespacedClass(e)}& e)
40f84f1117SPatrick Williams        {
41*a4bfefdeSPatrick Williams            return e.set_error(error);
42f84f1117SPatrick Williams        }
43f84f1117SPatrick Williams        % endfor
44f84f1117SPatrick Williams        catch (const std::exception&)
45f84f1117SPatrick Williams        {
46f84f1117SPatrick Williams            self->_context().get_bus().set_current_exception(
47f84f1117SPatrick Williams                std::current_exception());
48f84f1117SPatrick Williams            return -EINVAL;
49f84f1117SPatrick Williams        }
50f84f1117SPatrick Williams
51f84f1117SPatrick Williams        return 1;
52f84f1117SPatrick Williams    }
53f84f1117SPatrick Williams
54f84f1117SPatrick Williams% if 'const' not in property.flags and 'readonly' not in property.flags:
55f84f1117SPatrick Williams    static int _callback_set_${p_name}(
56f84f1117SPatrick Williams        sd_bus*, const char*, const char*, const char*,
57f84f1117SPatrick Williams        sd_bus_message* value[[maybe_unused]], void* context [[maybe_unused]],
58f84f1117SPatrick Williams        sd_bus_error* error [[maybe_unused]])
59f84f1117SPatrick Williams    {
6072f7116aSPatrick Williams        auto self = static_cast<${i_name}*>(context);
6172f7116aSPatrick Williams
6272f7116aSPatrick Williams        try
6372f7116aSPatrick Williams        {
6472f7116aSPatrick Williams            auto m = sdbusplus::message_t{value};
6572f7116aSPatrick Williams
6672f7116aSPatrick Williams            // Set up the transaction.
6772f7116aSPatrick Williams            server::transaction::set_id(m);
6872f7116aSPatrick Williams
6972f7116aSPatrick Williams            auto new_value = m.unpack<${p_type}>();
7072f7116aSPatrick Williams
7172f7116aSPatrick Williams            // Get property value and add to message.
7272f7116aSPatrick Williams            if constexpr (server_details::has_set_property_msg<
7372f7116aSPatrick Williams                              ${p_tag}, Instance, ${p_type}>)
7472f7116aSPatrick Williams            {
7572f7116aSPatrick Williams                self->${p_name}(m, std::move(new_value));
7672f7116aSPatrick Williams            }
7772f7116aSPatrick Williams            else
7872f7116aSPatrick Williams            {
7972f7116aSPatrick Williams                self->${p_name}(std::move(new_value));
8072f7116aSPatrick Williams            }
8172f7116aSPatrick Williams        }
8272f7116aSPatrick Williams        % for e in property.errors:
8372f7116aSPatrick Williams        catch (const ${interface.errorNamespacedClass(e)}& e)
8472f7116aSPatrick Williams        {
85*a4bfefdeSPatrick Williams            return e.set_error(error);
8672f7116aSPatrick Williams        }
8772f7116aSPatrick Williams        % endfor
8872f7116aSPatrick Williams        catch (const std::exception&)
8972f7116aSPatrick Williams        {
9072f7116aSPatrick Williams            self->_context().get_bus().set_current_exception(
9172f7116aSPatrick Williams                std::current_exception());
92f84f1117SPatrick Williams            return -EINVAL;
93f84f1117SPatrick Williams        }
9472f7116aSPatrick Williams
9572f7116aSPatrick Williams        return 1;
9672f7116aSPatrick Williams    }
97f84f1117SPatrick Williams% endif
98