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 33 } // namespace server 34 35 template <typename Instance, template <typename, typename> typename... Types> 36 using server_t = server::server<Instance, Types...>; 37 38 namespace server::details 39 { 40 /* Indirect so that the generated Types can access the server_t's context. 41 * 42 * If P2893 gets into C++26 we could eliminate this because we can set all 43 * the Types as friends directly. 44 */ 45 struct server_context_friend 46 { 47 template <typename Client, typename Self> contextsdbusplus::async::server::details::server_context_friend48 static sdbusplus::async::context& context(Self* self) 49 { 50 return static_cast<Client*>(self)->ctx; 51 } 52 }; 53 54 /* Determine if a type has a get_property call. */ 55 template <typename Tag, typename Instance> 56 concept has_get_property_nomsg = 57 requires(const Instance& i) { i.get_property(Tag{}); }; 58 59 /* Determine if a type has a get property call that requires a msg. */ 60 template <typename Tag, typename Instance> 61 concept has_get_property_msg = 62 requires(const Instance& i, sdbusplus::message_t& m) { 63 i.get_property(Tag{}, m); 64 }; 65 66 /* Determine if a type has any get_property call. */ 67 template <typename Tag, typename Instance> 68 concept has_get_property = has_get_property_nomsg<Tag, Instance> || 69 has_get_property_msg<Tag, Instance>; 70 71 /* Determine if a type is missing the 'const' on get-property calls. */ 72 template <typename Tag, typename Instance> 73 concept has_get_property_missing_const = 74 !has_get_property<Tag, Instance> && 75 ( 76 requires(Instance& i) { i.get_property(Tag{}); } || 77 requires(Instance& i, sdbusplus::message_t& m) { 78 i.get_property(Tag{}, m); 79 }); 80 81 /* Determine if a type has a set_property call. */ 82 template <typename Tag, typename Instance, typename Arg> 83 concept has_set_property_nomsg = 84 requires(Instance& i, Arg&& a) { 85 i.set_property(Tag{}, std::forward<Arg>(a)); 86 }; 87 88 /* Determine if a type has a set property call that requires a msg. */ 89 template <typename Tag, typename Instance, typename Arg> 90 concept has_set_property_msg = 91 requires(Instance& i, sdbusplus::message_t& m, Arg&& a) { 92 i.set_property(Tag{}, m, std::forward<Arg>(a)); 93 }; 94 95 /* Determine if a type has any set_property call. */ 96 template <typename Tag, typename Instance, typename Arg> 97 concept has_set_property = has_set_property_nomsg<Tag, Instance, Arg> || 98 has_set_property_msg<Tag, Instance, Arg>; 99 100 /* Determine if a type has a method call. */ 101 template <typename Tag, typename Instance, typename... Args> 102 concept has_method_nomsg = requires(Instance& i, Args&&... a) { 103 i.method_call(Tag{}, std::forward<Args>(a)...); 104 }; 105 106 /* Determine if a type has a method call that requires a msg. */ 107 template <typename Tag, typename Instance, typename... Args> 108 concept has_method_msg = 109 requires(Instance& i, sdbusplus::message_t& m, Args&&... a) { 110 i.method_call(Tag{}, m, std::forward<Args>(a)...); 111 }; 112 113 /* Determine if a type has any method call. */ 114 template <typename Tag, typename Instance, typename... Args> 115 concept has_method = has_method_nomsg<Tag, Instance, Args...> || 116 has_method_msg<Tag, Instance, Args...>; 117 118 } // namespace server::details 119 120 } // namespace sdbusplus::async 121