1 #pragma once 2 3 #include <sdbusplus/async/context.hpp> 4 #include <sdbusplus/server/manager.hpp> 5 #include <sdbusplus/vtable.hpp> 6 7 namespace sdbusplus::async 8 { 9 10 namespace server 11 { 12 13 namespace details 14 { 15 struct server_context_friend; 16 } 17 18 template <typename Instance, template <typename, typename> typename... Types> 19 class server : 20 public sdbusplus::async::context_ref, 21 public Types<Instance, server<Instance, Types...>>... 22 { 23 public: 24 using Self = server<Instance, Types...>; 25 friend details::server_context_friend; 26 27 server() = delete; server(sdbusplus::async::context & ctx,const char * path)28 explicit server(sdbusplus::async::context& ctx, const char* path) : 29 context_ref(ctx), Types<Instance, Self>(path)... 30 {} 31 32 // This constructor accepting one properties_t per interface: server(sdbusplus::async::context & ctx,const char * path,typename Types<Instance,Self>::properties_t...propValues)33 explicit server( 34 sdbusplus::async::context& ctx, const char* path, 35 typename Types<Instance, Self>::properties_t... propValues) : 36 context_ref(ctx), Types<Instance, Self>(path, propValues)... 37 {} 38 }; 39 40 } // namespace server 41 42 template <typename Instance, template <typename, typename> typename... Types> 43 using server_t = server::server<Instance, Types...>; 44 45 namespace server::details 46 { 47 /* Indirect so that the generated Types can access the server_t's context. 48 * 49 * If P2893 gets into C++26 we could eliminate this because we can set all 50 * the Types as friends directly. 51 */ 52 struct server_context_friend 53 { 54 template <typename Client, typename Self> contextsdbusplus::async::server::details::server_context_friend55 static sdbusplus::async::context& context(Self* self) 56 { 57 return static_cast<Client*>(self)->ctx; 58 } 59 }; 60 61 /* Determine if a type has a get_property call. */ 62 template <typename Tag, typename Instance> 63 concept has_get_property_nomsg = 64 requires(const Instance& i) { i.get_property(Tag{}); }; 65 66 /* Determine if a type has a get property call that requires a msg. */ 67 template <typename Tag, typename Instance> 68 concept has_get_property_msg = 69 requires(const Instance& i, sdbusplus::message_t& m) { 70 i.get_property(Tag{}, m); 71 }; 72 73 /* Determine if a type has any get_property call. */ 74 template <typename Tag, typename Instance> 75 concept has_get_property = has_get_property_nomsg<Tag, Instance> || 76 has_get_property_msg<Tag, Instance>; 77 78 /* Determine if a type is missing the 'const' on get-property calls. */ 79 template <typename Tag, typename Instance> 80 concept has_get_property_missing_const = 81 !has_get_property<Tag, Instance> && 82 ( 83 requires(Instance& i) { i.get_property(Tag{}); } || 84 requires(Instance& i, sdbusplus::message_t& m) { 85 i.get_property(Tag{}, m); 86 }); 87 88 /* Determine if a type has a set_property call. */ 89 template <typename Tag, typename Instance, typename Arg> 90 concept has_set_property_nomsg = 91 requires(Instance& i, Arg&& a) { 92 i.set_property(Tag{}, std::forward<Arg>(a)); 93 }; 94 95 /* Determine if a type has a set property call that requires a msg. */ 96 template <typename Tag, typename Instance, typename Arg> 97 concept has_set_property_msg = 98 requires(Instance& i, sdbusplus::message_t& m, Arg&& a) { 99 i.set_property(Tag{}, m, std::forward<Arg>(a)); 100 }; 101 102 /* Determine if a type has any set_property call. */ 103 template <typename Tag, typename Instance, typename Arg> 104 concept has_set_property = has_set_property_nomsg<Tag, Instance, Arg> || 105 has_set_property_msg<Tag, Instance, Arg>; 106 107 /* Determine if a type has a method call. */ 108 template <typename Tag, typename Instance, typename... Args> 109 concept has_method_nomsg = requires(Instance& i, Args&&... a) { 110 i.method_call(Tag{}, std::forward<Args>(a)...); 111 }; 112 113 /* Determine if a type has a method call that requires a msg. */ 114 template <typename Tag, typename Instance, typename... Args> 115 concept has_method_msg = 116 requires(Instance& i, sdbusplus::message_t& m, Args&&... a) { 117 i.method_call(Tag{}, m, std::forward<Args>(a)...); 118 }; 119 120 /* Determine if a type has any method call. */ 121 template <typename Tag, typename Instance, typename... Args> 122 concept has_method = has_method_nomsg<Tag, Instance, Args...> || 123 has_method_msg<Tag, Instance, Args...>; 124 125 } // namespace server::details 126 127 } // namespace sdbusplus::async 128