summaryrefslogtreecommitdiffstats
path: root/man/sd_bus_message_new.xml
blob: c56df615a6b0019b9efc037b5de2b7815ffcd905 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
<?xml version='1.0'?>
<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
  "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
<!-- SPDX-License-Identifier: LGPL-2.1-or-later -->

<refentry id="sd_bus_message_new" xmlns:xi="http://www.w3.org/2001/XInclude">
  <refentryinfo>
    <title>sd_bus_message_new</title>
    <productname>systemd</productname>
  </refentryinfo>

  <refmeta>
    <refentrytitle>sd_bus_message_new</refentrytitle>
    <manvolnum>3</manvolnum>
  </refmeta>

  <refnamediv>
    <refname>sd_bus_message_new</refname>
    <refname>sd_bus_message_ref</refname>
    <refname>sd_bus_message_unref</refname>
    <refname>sd_bus_message_unrefp</refname>
    <refname>SD_BUS_MESSAGE_METHOD_CALL</refname>
    <refname>SD_BUS_MESSAGE_METHOD_RETURN</refname>
    <refname>SD_BUS_MESSAGE_METHOD_ERROR</refname>
    <refname>SD_BUS_MESSAGE_SIGNAL</refname>
    <refname>sd_bus_message_get_bus</refname>

    <refpurpose>Create a new bus message object and create or destroy references to it</refpurpose>
  </refnamediv>

  <refsynopsisdiv>
    <funcsynopsis>
      <funcsynopsisinfo>#include &lt;systemd/sd-bus.h&gt;</funcsynopsisinfo>

      <funcsynopsisinfo><token>enum</token> {
      <constant>SD_BUS_MESSAGE_METHOD_CALL</constant>,
      <constant>SD_BUS_MESSAGE_METHOD_RETURN</constant>,
      <constant>SD_BUS_MESSAGE_METHOD_ERROR</constant>,
      <constant>SD_BUS_MESSAGE_SIGNAL</constant>,
};</funcsynopsisinfo>

      <funcprototype>
        <funcdef>int <function>sd_bus_message_new</function></funcdef>
        <paramdef>sd_bus *<parameter>bus</parameter></paramdef>
        <paramdef>sd_bus_message **<parameter>m</parameter></paramdef>
        <paramdef>uint8_t <parameter>type</parameter></paramdef>
      </funcprototype>

      <funcprototype>
        <funcdef>sd_bus_message *<function>sd_bus_message_ref</function></funcdef>
        <paramdef>sd_bus_message *<parameter>m</parameter></paramdef>
      </funcprototype>

      <funcprototype>
        <funcdef>sd_bus_message *<function>sd_bus_message_unref</function></funcdef>
        <paramdef>sd_bus_message *<parameter>m</parameter></paramdef>
      </funcprototype>

      <funcprototype>
        <funcdef>void <function>sd_bus_message_unrefp</function></funcdef>
        <paramdef>sd_bus_message **<parameter>mp</parameter></paramdef>
      </funcprototype>

      <funcprototype>
        <funcdef>sd_bus *<function>sd_bus_message_get_bus</function></funcdef>
        <paramdef>sd_bus_message *<parameter>m</parameter></paramdef>
      </funcprototype>
    </funcsynopsis>
  </refsynopsisdiv>

  <refsect1>
    <title>Description</title>

    <para><function>sd_bus_message_new()</function> creates a new bus message object attached to the
    bus <parameter>bus</parameter> and returns it in the output parameter <parameter>m</parameter>.
    This object is reference-counted, and will be destroyed when all references are gone. Initially,
    the caller of this function owns the sole reference to the message object. Note that the message
    object holds a reference to the bus object, so the bus object will not be destroyed as long as
    the message exists.</para>

    <para>Note: this is a low-level call. In most cases functions like
    <citerefentry><refentrytitle>sd_bus_message_new_method_call</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
    <citerefentry><refentrytitle>sd_bus_message_new_method_error</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
    <citerefentry><refentrytitle>sd_bus_message_new_method_return</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
    and <citerefentry><refentrytitle>sd_bus_message_new_signal</refentrytitle><manvolnum>3</manvolnum></citerefentry>
    that create a message of a certain type and initialize various fields are easier to use.</para>

    <para>The <parameter>type</parameter> parameter specifies the type of the message.  It must be
    one of <constant>SD_BUS_MESSAGE_METHOD_CALL</constant>  a method call,
    <constant>SD_BUS_MESSAGE_METHOD_RETURN</constant>  a method call reply,
    <constant>SD_BUS_MESSAGE_METHOD_ERROR</constant>  an error reply to a method call,
    <constant>SD_BUS_MESSAGE_SIGNAL</constant>  a broadcast message with no reply.
    </para>

    <para>The flag to allow interactive authorization is initialized based on the current value set
    in the bus object, see
    <citerefentry><refentrytitle>sd_bus_set_allow_interactive_authorization</refentrytitle><manvolnum>3</manvolnum></citerefentry>.
    This may be changed using
    <citerefentry><refentrytitle>sd_bus_message_set_allow_interactive_authorization</refentrytitle><manvolnum>3</manvolnum></citerefentry>.
    </para>

    <para><function>sd_bus_message_ref()</function> increases the internal reference counter of
    <parameter>m</parameter> by one.</para>

    <para><function>sd_bus_message_unref()</function> decreases the internal reference counter of
    <parameter>m</parameter> by one. Once the reference count has dropped to zero, message object is
    destroyed and cannot be used anymore, so further calls to <function>sd_bus_message_ref()</function> or
    <function>sd_bus_message_unref()</function> are illegal.</para>

    <para><function>sd_bus_message_unrefp()</function> is similar to
    <function>sd_bus_message_unref()</function> but takes a pointer to a
    pointer to an <type>sd_bus_message</type> object. This call is useful in
    conjunction with GCC's and LLVM's <ulink
    url="https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html">Clean-up
    Variable Attribute</ulink>. See
    <citerefentry><refentrytitle>sd_bus_new</refentrytitle><manvolnum>3</manvolnum></citerefentry>
    for an example how to use the cleanup attribute.</para>

    <para><function>sd_bus_message_ref()</function> and <function>sd_bus_message_unref()</function>
    execute no operation if the passed in bus message object address is
    <constant>NULL</constant>. <function>sd_bus_message_unrefp()</function> will first dereference
    its argument, which must not be <constant>NULL</constant>, and will execute no operation if
    <emphasis>that</emphasis> is <constant>NULL</constant>.
    </para>

    <para><function>sd_bus_message_get_bus()</function> returns the bus object that message
    <parameter>m</parameter> is attached to.</para>
  </refsect1>

  <refsect1>
    <title>Return Value</title>

    <para>On success, <function>sd_bus_message_new()</function> returns 0 or a positive integer. On
    failure, it returns a negative errno-style error code.</para>

    <para><function>sd_bus_message_ref()</function> always returns the argument.
    </para>

    <para><function>sd_bus_message_unref()</function> always returns
    <constant>NULL</constant>.</para>

    <para><function>sd_bus_message_get_bus()</function> always returns the bus object.</para>

    <refsect2>
      <title>Errors</title>

      <para>Returned errors may indicate the following problems:</para>

      <variablelist>
        <varlistentry>
          <term><constant>-EINVAL</constant></term>

          <listitem><para>Specified <parameter>type</parameter> is invalid.</para></listitem>
        </varlistentry>

        <varlistentry>
          <term><constant>-ENOTCONN</constant></term>

          <listitem><para>The bus parameter <parameter>bus</parameter> is <constant>NULL</constant> or
          the bus is not connected.</para></listitem>
        </varlistentry>

        <varlistentry>
          <term><constant>-ENOMEM</constant></term>

          <listitem><para>Memory allocation failed.</para></listitem>
        </varlistentry>
      </variablelist>
    </refsect2>
  </refsect1>

  <xi:include href="libsystemd-pkgconfig.xml" />

  <refsect1>
    <title>See Also</title>

    <para>
      <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
      <citerefentry><refentrytitle>sd-bus</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
      <citerefentry><refentrytitle>sd_bus_new</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
      <citerefentry><refentrytitle>sd_bus_message_new_method_call</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
      <citerefentry><refentrytitle>sd_bus_message_new_method_error</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
      <citerefentry><refentrytitle>sd_bus_message_new_method_return</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
      <citerefentry><refentrytitle>sd_bus_message_new_signal</refentrytitle><manvolnum>3</manvolnum></citerefentry>
    </para>
  </refsect1>

</refentry>