26#ifndef SDBUS_CPP_VTABLEITEMS_INL_
27#define SDBUS_CPP_VTABLEITEMS_INL_
42 template <
typename _Function>
43 MethodVTableItem& MethodVTableItem::implementedAs(_Function&& callback)
45 inputSignature = signature_of_function_input_arguments_v<_Function>;
46 outputSignature = signature_of_function_output_arguments_v<_Function>;
47 callbackHandler = [callback = std::forward<_Function>(callback)](MethodCall call)
51 tuple_of_function_input_arg_types_t<_Function> inputArgs;
56 if constexpr (!is_async_method_v<_Function>)
59 auto ret = sdbus::apply(callback, inputArgs);
62 auto reply = call.createReply();
69 using AsyncResult =
typename function_traits<_Function>::async_result_t;
70 sdbus::apply(callback, AsyncResult{std::move(call)}, std::move(inputArgs));
77 inline MethodVTableItem& MethodVTableItem::withInputParamNames(std::vector<std::string> names)
79 inputParamNames = std::move(names);
84 template <
typename... _String>
85 inline MethodVTableItem& MethodVTableItem::withInputParamNames(_String... names)
87 static_assert(std::conjunction_v<std::is_convertible<_String, std::string>...>,
"Parameter names must be (convertible to) strings");
89 return withInputParamNames({names...});
92 inline MethodVTableItem& MethodVTableItem::withOutputParamNames(std::vector<std::string> names)
94 outputParamNames = std::move(names);
99 template <
typename... _String>
100 inline MethodVTableItem& MethodVTableItem::withOutputParamNames(_String... names)
102 static_assert(std::conjunction_v<std::is_convertible<_String, std::string>...>,
"Parameter names must be (convertible to) strings");
104 return withOutputParamNames({names...});
107 inline MethodVTableItem& MethodVTableItem::markAsDeprecated()
109 flags.set(Flags::DEPRECATED);
114 inline MethodVTableItem& MethodVTableItem::markAsPrivileged()
116 flags.set(Flags::PRIVILEGED);
121 inline MethodVTableItem& MethodVTableItem::withNoReply()
123 flags.set(Flags::METHOD_NO_REPLY);
128 inline MethodVTableItem registerMethod(MethodName methodName)
130 return {std::move(methodName), {}, {}, {}, {}, {}, {}};
133 inline MethodVTableItem registerMethod(std::string methodName)
135 return registerMethod(MethodName{std::move(methodName)});
142 template <
typename... _Args>
143 inline SignalVTableItem& SignalVTableItem::withParameters()
145 signature = signature_of_function_input_arguments_v<void(_Args...)>;
150 template <
typename... _Args>
151 inline SignalVTableItem& SignalVTableItem::withParameters(std::vector<std::string> names)
153 paramNames = std::move(names);
155 return withParameters<_Args...>();
158 template <
typename... _Args,
typename... _String>
159 inline SignalVTableItem& SignalVTableItem::withParameters(_String... names)
161 static_assert(std::conjunction_v<std::is_convertible<_String, std::string>...>,
"Parameter names must be (convertible to) strings");
162 static_assert(
sizeof...(_Args) ==
sizeof...(_String),
"Numbers of signal parameters and their names don't match");
164 return withParameters<_Args...>({names...});
167 inline SignalVTableItem& SignalVTableItem::markAsDeprecated()
169 flags.set(Flags::DEPRECATED);
174 inline SignalVTableItem registerSignal(SignalName signalName)
176 return {std::move(signalName), {}, {}, {}};
179 inline SignalVTableItem registerSignal(std::string signalName)
181 return registerSignal(SignalName{std::move(signalName)});
188 template <
typename _Function>
189 inline PropertyVTableItem& PropertyVTableItem::withGetter(_Function&& callback)
191 static_assert(function_argument_count_v<_Function> == 0,
"Property getter function must not take any arguments");
192 static_assert(!std::is_void<function_result_t<_Function>>::value,
"Property getter function must return property value");
194 if (signature.empty())
195 signature = signature_of_function_output_arguments_v<_Function>;
197 getter = [callback = std::forward<_Function>(callback)](PropertyGetReply& reply)
206 template <
typename _Function>
207 inline PropertyVTableItem& PropertyVTableItem::withSetter(_Function&& callback)
209 static_assert(function_argument_count_v<_Function> == 1,
"Property setter function must take one parameter - the property value");
210 static_assert(std::is_void<function_result_t<_Function>>::value,
"Property setter function must not return any value");
212 if (signature.empty())
213 signature = signature_of_function_input_arguments_v<_Function>;
215 setter = [callback = std::forward<_Function>(callback)](PropertySetCall call)
218 using property_type = function_argument_t<_Function, 0>;
219 std::decay_t<property_type> property;
231 inline PropertyVTableItem& PropertyVTableItem::markAsDeprecated()
233 flags.set(Flags::DEPRECATED);
238 inline PropertyVTableItem& PropertyVTableItem::markAsPrivileged()
240 flags.set(Flags::PRIVILEGED);
245 inline PropertyVTableItem& PropertyVTableItem::withUpdateBehavior(Flags::PropertyUpdateBehaviorFlags behavior)
252 inline PropertyVTableItem registerProperty(PropertyName propertyName)
254 return {std::move(propertyName), {}, {}, {}, {}};
257 inline PropertyVTableItem registerProperty(std::string propertyName)
259 return registerProperty(PropertyName{std::move(propertyName)});
266 inline InterfaceFlagsVTableItem& InterfaceFlagsVTableItem::markAsDeprecated()
268 flags.set(Flags::DEPRECATED);
273 inline InterfaceFlagsVTableItem& InterfaceFlagsVTableItem::markAsPrivileged()
275 flags.set(Flags::PRIVILEGED);
280 inline InterfaceFlagsVTableItem& InterfaceFlagsVTableItem::withNoReplyMethods()
282 flags.set(Flags::METHOD_NO_REPLY);
287 inline InterfaceFlagsVTableItem& InterfaceFlagsVTableItem::withPropertyUpdateBehavior(Flags::PropertyUpdateBehaviorFlags behavior)
294 inline InterfaceFlagsVTableItem setInterfaceFlags()