1 #pragma once
2 
3 #include <systemd/sd-bus.h>
4 
5 namespace sdbusplus
6 {
7 
8 namespace vtable
9 {
10 /** Alias typedef for sd_bus_vtable */
11 using vtable_t = sd_bus_vtable;
12 
13 /** Create a SD_BUS_VTABLE_START entry. */
14 constexpr vtable_t start(decltype(vtable_t::flags) flags = 0);
15 
16 /** Create a SD_BUS_VTABLE_END entry. */
17 constexpr vtable_t end();
18 
19 /** Create a SD_BUS_VTABLE_METHOD entry.
20  *
21  *  @param[in] member - Name of method.
22  *  @param[in] signature - Signature of method.
23  *  @param[in] result - Signature of result.
24  *  @param[in] handler - Functor to call on method invocation.
25  *  @param[in] flags - optional sdbusplus::vtable::method_ value.
26  */
27 constexpr vtable_t method(const char* member, const char* signature,
28                           const char* result, sd_bus_message_handler_t handler,
29                           decltype(vtable_t::flags) flags = 0);
30 
31 /** Create a SD_BUS_VTABLE_METHOD_WITH_OFFSET entry.
32  *
33  *  @param[in] member - Name of method.
34  *  @param[in] signature - Signature of method.
35  *  @param[in] result - Signature of result.
36  *  @param[in] handler - Functor to call on method invocation.
37  *  @param[in] offset - Offset.
38  *  @param[in] flags - optional sdbusplus::vtable::method_ value.
39  */
40 constexpr vtable_t method_o(const char* member, const char* signature,
41                             const char* result,
42                             sd_bus_message_handler_t handler, size_t offset,
43                             decltype(vtable_t::flags) flags = 0);
44 
45 /** Create a SD_BUS_SIGNAL entry.
46  *
47  * @param[in] member - Name of signal.
48  * @param[in] signature - Signature of signal.
49  * @param[in] flags - None supported.
50  */
51 constexpr vtable_t signal(const char* member, const char* signature,
52                           decltype(vtable_t::flags) flags = 0);
53 
54 /** Create a SD_BUS_PROPERTY entry.
55  *
56  * @param[in] member - Name of signal.
57  * @param[in] signature - Signature of signal.
58  * @param[in] get - Functor to call on property get.
59  * @param[in] flags - optional sdbusplus::vtable::property_ value.
60  */
61 constexpr vtable_t property(const char* member, const char* signature,
62                             sd_bus_property_get_t get,
63                             decltype(vtable_t::flags) flags = 0);
64 
65 /** Create a SD_BUS_WRITABLE_PROPERTY entry.
66  *
67  * @param[in] member - Name of signal.
68  * @param[in] signature - Signature of signal.
69  * @param[in] get - Functor to call on property get.
70  * @param[in] set - Functor to call on property set.
71  * @param[in] flags - optional sdbusplus::vtable::property_ value.
72  */
73 constexpr vtable_t property(
74     const char* member, const char* signature, sd_bus_property_get_t get,
75     sd_bus_property_set_t set, decltype(vtable_t::flags) flags = 0);
76 
77 /** Create a SD_BUS_PROPERTY entry.
78  *
79  * @param[in] member - Name of signal.
80  * @param[in] signature - Signature of signal.
81  * @param[in] get - Functor to call on property get.
82  * @param[in] offset - Offset within object for property.
83  * @param[in] flags - optional sdbusplus::vtable::property_ value.
84  */
85 constexpr vtable_t property_o(const char* member, const char* signature,
86                               sd_bus_property_get_t get, size_t offset,
87                               decltype(vtable_t::flags) flags = 0);
88 
89 /** Create a SD_BUS_WRITABLE_PROPERTY entry.
90  *
91  * @param[in] member - Name of signal.
92  * @param[in] signature - Signature of signal.
93  * @param[in] get - Functor to call on property get.
94  * @param[in] set - Functor to call on property set.
95  * @param[in] offset - Offset within object for property.
96  * @param[in] flags - optional sdbusplus::vtable::property_ value.
97  */
98 constexpr vtable_t
99     property_o(const char* member, const char* signature,
100                sd_bus_property_get_t get, sd_bus_property_set_t set,
101                size_t offset, decltype(vtable_t::flags) flags = 0);
102 
103 namespace common_
104 {
105 constexpr auto deprecated = SD_BUS_VTABLE_DEPRECATED;
106 constexpr auto hidden = SD_BUS_VTABLE_HIDDEN;
107 constexpr auto unprivileged = SD_BUS_VTABLE_UNPRIVILEGED;
108 } // namespace common_
109 
110 namespace method_
111 {
112 constexpr auto no_reply = SD_BUS_VTABLE_METHOD_NO_REPLY;
113 } // namespace method_
114 
115 namespace property_
116 {
117 constexpr auto const_ = SD_BUS_VTABLE_PROPERTY_CONST;
118 constexpr auto emits_change = SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE;
119 constexpr auto emits_invalidation = SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION;
120 constexpr auto explicit_ = SD_BUS_VTABLE_PROPERTY_EXPLICIT;
121 constexpr auto none = decltype(vtable_t::flags){};
122 } // namespace property_
123 
start(decltype(vtable_t::flags)flags)124 constexpr vtable_t start(decltype(vtable_t::flags) flags)
125 {
126     return vtable_t SD_BUS_VTABLE_START(flags);
127 }
128 
end()129 constexpr vtable_t end()
130 {
131     return vtable_t SD_BUS_VTABLE_END;
132 }
133 
method(const char * member,const char * signature,const char * result,sd_bus_message_handler_t handler,decltype(vtable_t::flags)flags)134 constexpr vtable_t method(const char* member, const char* signature,
135                           const char* result, sd_bus_message_handler_t handler,
136                           decltype(vtable_t::flags) flags)
137 {
138     return vtable_t SD_BUS_METHOD(member, signature, result, handler, flags);
139 }
140 
method_o(const char * member,const char * signature,const char * result,sd_bus_message_handler_t handler,size_t offset,decltype(vtable_t::flags)flags)141 constexpr vtable_t method_o(const char* member, const char* signature,
142                             const char* result,
143                             sd_bus_message_handler_t handler, size_t offset,
144                             decltype(vtable_t::flags) flags)
145 {
146     return vtable_t SD_BUS_METHOD_WITH_OFFSET(member, signature, result,
147                                               handler, offset, flags);
148 }
149 
signal(const char * member,const char * signature,decltype(vtable_t::flags)flags)150 constexpr vtable_t signal(const char* member, const char* signature,
151                           decltype(vtable_t::flags) flags)
152 {
153     return vtable_t SD_BUS_SIGNAL(member, signature, flags);
154 }
155 
property(const char * member,const char * signature,sd_bus_property_get_t get,decltype(vtable_t::flags)flags)156 constexpr vtable_t property(const char* member, const char* signature,
157                             sd_bus_property_get_t get,
158                             decltype(vtable_t::flags) flags)
159 {
160     return vtable_t SD_BUS_PROPERTY(member, signature, get, 0, flags);
161 }
162 
property(const char * member,const char * signature,sd_bus_property_get_t get,sd_bus_property_set_t set,decltype(vtable_t::flags)flags)163 constexpr vtable_t property(
164     const char* member, const char* signature, sd_bus_property_get_t get,
165     sd_bus_property_set_t set, decltype(vtable_t::flags) flags)
166 {
167     return vtable_t SD_BUS_WRITABLE_PROPERTY(member, signature, get, set, 0,
168                                              flags);
169 }
170 
property_o(const char * member,const char * signature,sd_bus_property_get_t get,size_t offset,decltype(vtable_t::flags)flags)171 constexpr vtable_t property_o(const char* member, const char* signature,
172                               sd_bus_property_get_t get, size_t offset,
173                               decltype(vtable_t::flags) flags)
174 {
175     return vtable_t SD_BUS_PROPERTY(member, signature, get, offset, flags);
176 }
177 
property_o(const char * member,const char * signature,sd_bus_property_get_t get,sd_bus_property_set_t set,size_t offset,decltype(vtable_t::flags)flags)178 constexpr vtable_t property_o(
179     const char* member, const char* signature, sd_bus_property_get_t get,
180     sd_bus_property_set_t set, size_t offset, decltype(vtable_t::flags) flags)
181 {
182     return vtable_t SD_BUS_WRITABLE_PROPERTY(member, signature, get, set,
183                                              offset, flags);
184 }
185 
186 } // namespace vtable
187 
188 using vtable_t = vtable::vtable_t;
189 
190 } // namespace sdbusplus
191