Re: Default value for `in` parameter
Charles Wong <[email protected]> Sun, 29 Jan 2023 01:26:18 +0800
| Newsgroups | gmane.comp.freedesktop.dbus |
|---|---|
| Message-ID | <CAAcWGFJ-=6fg3OsHmW0rMdNUDtCd+GjSKw9odWsxuRVU3k0KJQ@mail.gmail.com> |
I'll use this way as a solution. Thank you very much. On Sat, Jan 28, 2023 at 11:22 PM Robert Middleton < [email protected]> wrote: > 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 <[email protected]> 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` >