chiark / gitweb /
77871b048fed67a3d6f61ef8c35d9a817a97cea6
[elogind.git] / man / sd_bus_request_name.xml
1 <?xml version='1.0'?> <!--*-nxml-*-->
2 <!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
3   "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
4
5 <!--
6   SPDX-License-Identifier: LGPL-2.1+
7
8   Copyright 2013 Lennart Poettering
9 -->
10
11 <refentry id="sd_bus_request_name">
12
13   <refentryinfo>
14     <title>sd_bus_request_name</title>
15     <productname>systemd</productname>
16
17     <authorgroup>
18       <author>
19         <contrib>Developer</contrib>
20         <firstname>Lennart</firstname>
21         <surname>Poettering</surname>
22         <email>lennart@poettering.net</email>
23       </author>
24     </authorgroup>
25   </refentryinfo>
26
27   <refmeta>
28     <refentrytitle>sd_bus_request_name</refentrytitle>
29     <manvolnum>3</manvolnum>
30   </refmeta>
31
32   <refnamediv>
33     <refname>sd_bus_request_name</refname>
34     <refname>sd_bus_request_name_async</refname>
35     <refname>sd_bus_release_name</refname>
36     <refname>sd_bus_release_name_async</refname>
37     <refpurpose>Request or release a well-known service name on a bus</refpurpose>
38   </refnamediv>
39
40   <refsynopsisdiv>
41     <funcsynopsis>
42       <funcsynopsisinfo>#include &lt;systemd/sd-bus.h&gt;</funcsynopsisinfo>
43
44       <funcprototype>
45         <funcdef>int <function>sd_bus_request_name</function></funcdef>
46         <paramdef>sd_bus *<parameter>bus</parameter></paramdef>
47         <paramdef>const char *<parameter>name</parameter></paramdef>
48         <paramdef>uint64_t <parameter>flags</parameter></paramdef>
49       </funcprototype>
50
51       <funcprototype>
52         <funcdef>int <function>sd_bus_request_name_async</function></funcdef>
53         <paramdef>sd_bus *<parameter>bus</parameter></paramdef>
54         <paramdef>sd_bus_slot **<parameter>slot</parameter></paramdef>
55         <paramdef>const char *<parameter>name</parameter></paramdef>
56         <paramdef>uint64_t <parameter>flags</parameter></paramdef>
57         <paramdef>sd_bus_message_handler_t <parameter>callback</parameter></paramdef>
58         <paramdef>void *<parameter>userdata</parameter></paramdef>
59       </funcprototype>
60
61       <funcprototype>
62         <funcdef>int <function>sd_bus_release_name</function></funcdef>
63         <paramdef>sd_bus *<parameter>bus</parameter></paramdef>
64         <paramdef>const char *<parameter>name</parameter></paramdef>
65       </funcprototype>
66
67       <funcprototype>
68         <funcdef>int <function>sd_bus_release_name_async</function></funcdef>
69         <paramdef>sd_bus *<parameter>bus</parameter></paramdef>
70         <paramdef>sd_bus_slot **<parameter>slot</parameter></paramdef>
71         <paramdef>const char *<parameter>name</parameter></paramdef>
72         <paramdef>sd_bus_message_handler_t <parameter>callback</parameter></paramdef>
73         <paramdef>void *<parameter>userdata</parameter></paramdef>
74       </funcprototype>
75     </funcsynopsis>
76   </refsynopsisdiv>
77
78   <refsect1>
79     <title>Description</title>
80
81     <para><function>sd_bus_request_name()</function> requests a well-known service name on a bus. It takes a bus
82     connection, a valid bus name and a flags parameter. The flags parameter is a combination of the following
83     flags:</para>
84
85     <variablelist>
86       <varlistentry>
87         <term><varname>SD_BUS_NAME_ALLOW_REPLACEMENT</varname></term>
88
89         <listitem><para>After acquiring the name successfully, permit other peers to take over the name when they try
90         to acquire it with the <varname>SD_BUS_NAME_REPLACE_EXISTING</varname> flag set. If
91         <varname>SD_BUS_NAME_ALLOW_REPLACEMENT</varname> is not set on the original request, such a request by other
92         peers will be denied.</para></listitem>
93       </varlistentry>
94
95       <varlistentry>
96         <term><varname>SD_BUS_NAME_REPLACE_EXISTING</varname></term>
97
98         <listitem><para>Take over the name if it is already acquired by another peer, and that other peer has permitted
99         takeover by setting <varname>SD_BUS_NAME_ALLOW_REPLACEMENT</varname> while acquiring it.</para></listitem>
100       </varlistentry>
101
102       <varlistentry>
103         <term><varname>SD_BUS_NAME_QUEUE</varname></term>
104
105         <listitem><para>Queue the acquisition of the name when the name is already taken.</para></listitem>
106       </varlistentry>
107     </variablelist>
108
109     <para><function>sd_bus_request_name()</function> operates in a synchronous fashion: a message requesting the name
110     is sent to the bus broker, and the call waits until the broker responds.</para>
111
112     <para><function>sd_bus_request_name_async()</function> is an asynchronous version of
113     <function>sd_bus_release_name()</function>. Instead of waiting for the request to complete, the request message is
114     enqueued. The specified <parameter>callback</parameter> will be called when the broker's response is received. If
115     the parameter is specified as <constant>NULL</constant> a default implementation is used instead which will
116     terminate the connection when the name cannot be acquired. The function returns a slot object in its
117     <parameter>slot</parameter> parameter — if it is passed as non-<constant>NULL</constant> — which may be used as a
118     reference to the name request operation. Use
119     <citerefentry><refentrytitle>sd_bus_slot_unref</refentrytitle><manvolnum>3</manvolnum></citerefentry> to destroy
120     this reference. Note that destroying the reference will not unregister the name, but simply ensure the specified
121     callback is no longer called.</para>
122
123     <para><function>sd_bus_release_name()</function> releases an acquired well-known name. It takes a bus connection
124     and a valid bus name as parameters. This function operates synchronously, sending a release request message to the
125     bus broker and waiting for it to reply.</para>
126
127     <para><function>sd_bus_release_name_async()</function> is an asynchronous version of
128     <function>sd_bus_release_name()</function>. The specified <parameter>callback</parameter> function is called when
129     the name has been released successfully. If specified as <constant>NULL</constant> a generic implementation is used
130     that ignores the result of the operation. As above, the <parameter>slot</parameter> (if
131     non-<constant>NULL</constant>) is set to an object that may be used to reference the operation.</para>
132
133     <para>These functions are supported only on bus connections, i.e. connections to a bus broker and not on direct
134     connections.</para>
135   </refsect1>
136
137   <refsect1>
138     <title>Return Value</title>
139
140     <para>On success, these calls return 0 or a positive integer. On failure, these calls return a negative errno-style
141     error code.</para>
142
143     <para>If <varname>SD_BUS_NAME_QUEUE</varname> is specified, <function>sd_bus_request_name()</function> will return
144     0 when the name is already taken by another peer and the client has been added to the queue for the name. In that
145     case, the caller can subscribe to <literal>NameOwnerChanged</literal> signals to be notified when the name is
146     successfully acquired.  <function>sd_bus_request_name()</function> returns &gt; 0 when the name has immediately
147     been acquired successfully.</para>
148   </refsect1>
149
150   <refsect1>
151     <title>Errors</title>
152
153     <para>Returned errors may indicate the following problems:</para>
154
155     <variablelist>
156       <varlistentry>
157         <term><constant>-EALREADY</constant></term>
158
159         <listitem><para>The caller already is the owner of the specified name.</para></listitem>
160       </varlistentry>
161
162       <varlistentry>
163         <term><constant>-EEXIST</constant></term>
164
165         <listitem><para>The name has already been acquired by a different peer, and SD_BUS_NAME_REPLACE_EXISTING was
166         not specified or the other peer did not specify SD_BUS_NAME_ALLOW_REPLACEMENT while acquiring the
167         name.</para></listitem>
168       </varlistentry>
169
170       <varlistentry>
171         <term><constant>-ESRCH</constant></term>
172
173         <listitem><para>It was attempted to release a name that is currently not registered on the
174         bus.</para></listitem>
175       </varlistentry>
176
177       <varlistentry>
178         <term><constant>-EADDRINUSE</constant></term>
179
180         <listitem><para>It was attempted to release a name that is owned by a different peer on the
181         bus.</para></listitem>
182       </varlistentry>
183
184       <varlistentry>
185         <term><constant>-EINVAL</constant></term>
186
187         <listitem><para>A specified parameter is invalid. This is also generated when the requested name is a special
188         service name reserved by the D-Bus specification, or when the operation is requested on a connection that does
189         not refer to a bus.</para></listitem>
190       </varlistentry>
191
192       <varlistentry>
193         <term><constant>-ENOTCONN</constant></term>
194
195         <listitem><para>The bus connection has been disconnected.</para></listitem>
196       </varlistentry>
197
198       <varlistentry>
199         <term><constant>-ECHILD</constant></term>
200
201         <listitem><para>The bus connection has been created in a different process than the current
202         one.</para></listitem>
203       </varlistentry>
204     </variablelist>
205   </refsect1>
206
207   <refsect1>
208     <title>Notes</title>
209
210     <para>The <function>sd_bus_acquire_name()</function> and the other interfaces described here are available as a
211     shared library, which can be compiled and linked to with the <constant>libelogind</constant> <citerefentry
212     project='die-net'><refentrytitle>pkg-config</refentrytitle><manvolnum>1</manvolnum></citerefentry> file.</para>
213   </refsect1>
214
215   <refsect1>
216     <title>See Also</title>
217
218     <para>
219       <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
220       <citerefentry><refentrytitle>sd-bus</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
221       <citerefentry><refentrytitle>sd_bus_new</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
222       <citerefentry><refentrytitle>sd_bus_slot_unref</refentrytitle><manvolnum>3</manvolnum></citerefentry>
223     </para>
224   </refsect1>
225
226 </refentry>