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 { 41f84f1117SPatrick Williams return sd_bus_error_set(error, e.name(), e.description()); 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 { 60*72f7116aSPatrick Williams auto self = static_cast<${i_name}*>(context); 61*72f7116aSPatrick Williams 62*72f7116aSPatrick Williams try 63*72f7116aSPatrick Williams { 64*72f7116aSPatrick Williams auto m = sdbusplus::message_t{value}; 65*72f7116aSPatrick Williams 66*72f7116aSPatrick Williams // Set up the transaction. 67*72f7116aSPatrick Williams server::transaction::set_id(m); 68*72f7116aSPatrick Williams 69*72f7116aSPatrick Williams auto new_value = m.unpack<${p_type}>(); 70*72f7116aSPatrick Williams 71*72f7116aSPatrick Williams // Get property value and add to message. 72*72f7116aSPatrick Williams if constexpr (server_details::has_set_property_msg< 73*72f7116aSPatrick Williams ${p_tag}, Instance, ${p_type}>) 74*72f7116aSPatrick Williams { 75*72f7116aSPatrick Williams self->${p_name}(m, std::move(new_value)); 76*72f7116aSPatrick Williams } 77*72f7116aSPatrick Williams else 78*72f7116aSPatrick Williams { 79*72f7116aSPatrick Williams self->${p_name}(std::move(new_value)); 80*72f7116aSPatrick Williams } 81*72f7116aSPatrick Williams } 82*72f7116aSPatrick Williams % for e in property.errors: 83*72f7116aSPatrick Williams catch (const ${interface.errorNamespacedClass(e)}& e) 84*72f7116aSPatrick Williams { 85*72f7116aSPatrick Williams return sd_bus_error_set(error, e.name(), e.description()); 86*72f7116aSPatrick Williams } 87*72f7116aSPatrick Williams % endfor 88*72f7116aSPatrick Williams catch (const std::exception&) 89*72f7116aSPatrick Williams { 90*72f7116aSPatrick Williams self->_context().get_bus().set_current_exception( 91*72f7116aSPatrick Williams std::current_exception()); 92f84f1117SPatrick Williams return -EINVAL; 93f84f1117SPatrick Williams } 94*72f7116aSPatrick Williams 95*72f7116aSPatrick Williams return 1; 96*72f7116aSPatrick Williams } 97f84f1117SPatrick Williams% endif 98