[prev in list] [next in list] [prev in thread] [next in thread] 

List:       freedesktop-dbus
Subject:    Re: Default value for `in` parameter
From:       Charles Wong <ymqiuyu () gmail ! com>
Date:       2023-01-28 17:26:18
Message-ID: CAAcWGFJ-=6fg3OsHmW0rMdNUDtCd+GjSKw9odWsxuRVU3k0KJQ () mail ! gmail ! com
[Download RAW message or body]

I'll use this way as a solution.

Thank you very much.

On Sat, Jan 28, 2023 at 11:22 PM Robert Middleton <
robert.middleton@rm5248.com> 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 <ymqiuyu@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`
>

[Attachment #3 (text/html)]

<div dir="ltr">I&#39;ll use this way as a solution.<br><br>Thank you very \
much.<br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, \
Jan 28, 2023 at 11:22 PM Robert Middleton &lt;<a \
href="mailto:robert.middleton@rm5248.com">robert.middleton@rm5248.com</a>&gt; \
wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px \
0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">DBus methods are \
similar to C in that all defined arguments are<br> required to methods.   It is \
possible that specific<br> implementations/language bindings may allow you to have \
default<br> values, but that is not something that I am aware of.<br>
<br>
If you have optional arguments, the best way to implement that would<br>
be to send a map&lt;string,variant&gt;(or a{sv} in dbus-speak) that lets you<br>
test for arguments that may or may not exist.   This mechanism is used<br>
by DBus itself for messages, as well as some standard services like<br>
the org.freedesktop.Notifications[1].<br>
<br>
-Robert Middleton<br>
<br>
[1]: <a href="https://specifications.freedesktop.org/notification-spec/notification-spec-latest.html" \
rel="noreferrer" target="_blank">https://specifications.freedesktop.org/notification-spec/notification-spec-latest.html</a><br>
 <br>
On Sat, Jan 28, 2023 at 7:01 AM Charles Wong &lt;<a href="mailto:ymqiuyu@gmail.com" \
target="_blank">ymqiuyu@gmail.com</a>&gt; wrote:<br> &gt;<br>
&gt; Hi,<br>
&gt;<br>
&gt; Is this the   right place to ask dbus questions?<br>
&gt;<br>
&gt; For example, there is a dbus config (is from <a \
href="https://gjs.guide/guides/gio/dbus.html#high-level-proxies" rel="noreferrer" \
target="_blank">https://gjs.guide/guides/gio/dbus.html#high-level-proxies</a>):<br> \
&gt; ```xml<br> &gt; &lt;method name=&quot;ComplexMethod&quot;&gt;<br>
&gt;        &lt;arg type=&quot;b&quot; direction=&quot;in&quot; \
name=&quot;input&quot;/&gt;<br> &gt;        &lt;arg type=&quot;u&quot; \
direction=&quot;out&quot; name=&quot;length&quot;/&gt;<br> &gt; &lt;/method&gt;<br>
&gt; ```<br>
&gt;<br>
&gt; Is it possible to set a default value to parameter `input` and mark it as \
unrequired?<br> &gt;<br>
&gt; Just like in spring mvc, we can set a parameter `required=false` and set \
`default` value too:<br> &gt; `@RequestParam(required = false, defaultValue = \
&quot;default value&quot;) String parameter`<br> </blockquote></div>



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic