Default value for `in` parameter

Robert Middleton robert.middleton at rm5248.com
Sat Jan 28 15:22:26 UTC 2023


DBus methods are similar to C in that all defined arguments are
required to methods.  It is possible that specific
implementations/language bindings may allow you to have default
values, but that is not something that I am aware of.

If you have optional arguments, the best way to implement that would
be to send a map<string,variant>(or a{sv} in dbus-speak) that lets you
test for arguments that may or may not exist.  This mechanism is used
by DBus itself for messages, as well as some standard services like
the org.freedesktop.Notifications[1].

-Robert Middleton

[1]: https://specifications.freedesktop.org/notification-spec/notification-spec-latest.html

On Sat, Jan 28, 2023 at 7:01 AM Charles Wong <ymqiuyu at gmail.com> wrote:
>
> Hi,
>
> Is this the  right place to ask dbus questions?
>
> For example, there is a dbus config (is from https://gjs.guide/guides/gio/dbus.html#high-level-proxies):
> ```xml
> <method name="ComplexMethod">
>     <arg type="b" direction="in" name="input"/>
>     <arg type="u" direction="out" name="length"/>
> </method>
> ```
>
> Is it possible to set a default value to parameter `input` and mark it as unrequired?
>
> Just like in spring mvc, we can set a parameter `required=false` and set `default` value too:
> `@RequestParam(required = false, defaultValue = "default value") String parameter`


More information about the dbus mailing list