Patrick Williams | bf0283a | 2023-08-19 07:18:04 -0500 | [diff] [blame] | 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; |
| 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 | { |
Patrick Williams | fdbc18f | 2023-11-28 11:37:30 -0600 | [diff] [blame] | 47 | template <typename Client, typename Self> |
| 48 | static sdbusplus::async::context& context(Self* self) |
Patrick Williams | bf0283a | 2023-08-19 07:18:04 -0500 | [diff] [blame] | 49 | { |
Patrick Williams | fdbc18f | 2023-11-28 11:37:30 -0600 | [diff] [blame] | 50 | return static_cast<Client*>(self)->ctx; |
Patrick Williams | bf0283a | 2023-08-19 07:18:04 -0500 | [diff] [blame] | 51 | } |
| 52 | }; |
Patrick Williams | f84f111 | 2023-08-20 19:03:08 -0500 | [diff] [blame] | 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 | |
Manojkiran Eda | 3baa304 | 2024-06-17 15:05:29 +0530 | [diff] [blame^] | 59 | /* Determine if a type has a get property call that requires a msg. */ |
Patrick Williams | f84f111 | 2023-08-20 19:03:08 -0500 | [diff] [blame] | 60 | template <typename Tag, typename Instance> |
| 61 | concept has_get_property_msg = requires( |
| 62 | const Instance& i, sdbusplus::message_t& m) { i.get_property(Tag{}, m); }; |
| 63 | |
| 64 | /* Determine if a type has any get_property call. */ |
| 65 | template <typename Tag, typename Instance> |
| 66 | concept has_get_property = has_get_property_nomsg<Tag, Instance> || |
| 67 | has_get_property_msg<Tag, Instance>; |
| 68 | |
| 69 | /* Determine if a type is missing the 'const' on get-property calls. */ |
| 70 | template <typename Tag, typename Instance> |
| 71 | concept has_get_property_missing_const = |
| 72 | !has_get_property<Tag, Instance> && |
| 73 | ( |
| 74 | requires(Instance& i) { i.get_property(Tag{}); } || |
| 75 | requires(Instance& i, sdbusplus::message_t& m) { |
| 76 | i.get_property(Tag{}, m); |
| 77 | }); |
| 78 | |
Patrick Williams | 72f7116 | 2023-08-20 21:36:14 -0500 | [diff] [blame] | 79 | /* Determine if a type has a set_property call. */ |
| 80 | template <typename Tag, typename Instance, typename Arg> |
| 81 | concept has_set_property_nomsg = requires( |
| 82 | Instance& i, Arg&& a) { i.set_property(Tag{}, std::forward<Arg>(a)); }; |
| 83 | |
Manojkiran Eda | 3baa304 | 2024-06-17 15:05:29 +0530 | [diff] [blame^] | 84 | /* Determine if a type has a set property call that requires a msg. */ |
Patrick Williams | 72f7116 | 2023-08-20 21:36:14 -0500 | [diff] [blame] | 85 | template <typename Tag, typename Instance, typename Arg> |
| 86 | concept has_set_property_msg = |
| 87 | requires(Instance& i, sdbusplus::message_t& m, Arg&& a) { |
| 88 | i.set_property(Tag{}, m, std::forward<Arg>(a)); |
| 89 | }; |
| 90 | |
| 91 | /* Determine if a type has any set_property call. */ |
| 92 | template <typename Tag, typename Instance, typename Arg> |
| 93 | concept has_set_property = has_set_property_nomsg<Tag, Instance, Arg> || |
| 94 | has_set_property_msg<Tag, Instance, Arg>; |
| 95 | |
Patrick Williams | e15ff88 | 2023-08-22 16:59:16 -0500 | [diff] [blame] | 96 | /* Determine if a type has a method call. */ |
| 97 | template <typename Tag, typename Instance, typename... Args> |
| 98 | concept has_method_nomsg = requires(Instance& i, Args&&... a) { |
| 99 | i.method_call(Tag{}, std::forward<Args>(a)...); |
| 100 | }; |
| 101 | |
| 102 | /* Determine if a type has a method call that requires a msg. */ |
| 103 | template <typename Tag, typename Instance, typename... Args> |
| 104 | concept has_method_msg = |
| 105 | requires(Instance& i, sdbusplus::message_t& m, Args&&... a) { |
| 106 | i.method_call(Tag{}, m, std::forward<Args>(a)...); |
| 107 | }; |
| 108 | |
| 109 | /* Determine if a type has any method call. */ |
| 110 | template <typename Tag, typename Instance, typename... Args> |
| 111 | concept has_method = has_method_nomsg<Tag, Instance, Args...> || |
| 112 | has_method_msg<Tag, Instance, Args...>; |
| 113 | |
Patrick Williams | bf0283a | 2023-08-19 07:18:04 -0500 | [diff] [blame] | 114 | } // namespace server::details |
| 115 | |
| 116 | } // namespace sdbusplus::async |