1 <refentry id="gdbus-codegen" lang="en">
5 <productname>GIO</productname>
8 <contrib>Developer</contrib>
9 <firstname>David</firstname>
10 <surname>Zeuthen</surname>
11 <email>zeuthen@gmail.com</email>
17 <refentrytitle>gdbus-codegen</refentrytitle>
18 <manvolnum>1</manvolnum>
19 <refmiscinfo class="manual">User Commands</refmiscinfo>
23 <refname>gdbus-codegen</refname>
24 <refpurpose>D-Bus code and documentation generator</refpurpose>
29 <command>gdbus-codegen</command>
30 <arg><option>-h</option>, <option>--help</option></arg>
31 <arg><option>--interface-prefix</option> <replaceable>org.project.Prefix</replaceable></arg>
32 <arg><option>--generate-c-code</option> <replaceable>OUTFILES</replaceable></arg>
33 <arg><option>--c-namespace</option> <replaceable>YourProject</replaceable></arg>
34 <arg><option>--c-generate-object-manager</option></arg>
35 <arg><option>--c-generate-autocleanup</option> none|objects|all</arg>
36 <arg><option>--output-directory</option> <replaceable>OUTDIR</replaceable></arg>
37 <arg><option>--generate-docbook</option> <replaceable>OUTFILES</replaceable></arg>
38 <arg><option>--pragma-once</option></arg>
39 <arg><option>--xml-files</option> <replaceable>FILE</replaceable></arg>
40 <arg><option>--header</option></arg>
41 <arg><option>--body</option></arg>
42 <arg><option>--output</option> <replaceable>OUTFILE</replaceable></arg>
43 <group choice="plain" rep="repeat">
45 <option>--annotate</option>
46 <replaceable>ELEMENT</replaceable>
47 <replaceable>KEY</replaceable>
48 <replaceable>VALUE</replaceable>
51 <arg choice="plain">FILE</arg>
53 <arg choice="plain" rep="repeat">FILE</arg>
59 <title>Description</title>
61 <command>gdbus-codegen</command> is used to generate code and/or
62 documentation for one or more D-Bus interfaces.
65 <command>gdbus-codegen</command> reads
67 url="http://dbus.freedesktop.org/doc/dbus-specification.html#introspection-format">D-Bus
68 Introspection XML</ulink> from files passed as additional
69 arguments on the command line and generates output files.
70 It currently supports generating C source code (via
71 <option>--body</option>) or header (via <option>--header</option>)
72 and Docbook XML (via <option>--generate-docbook</option>).
77 <title>Generating C code</title>
79 When generating C code, a
80 #GInterface<!-- -->-derived type is generated for each D-Bus
81 interface. Additionally, for every generated type,
82 <type>FooBar</type>, two concrete instantiable types,
83 <type>FooBarProxy</type> and <type>FooBarSkeleton</type>, implementing
84 said interface are also generated. The former is derived from
85 #GDBusProxy and intended for use on the client side
86 while the latter is derived from the
87 #GDBusInterfaceSkeleton type making it easy to export on a
88 #GDBusConnection either directly or via a
89 #GDBusObjectManagerServer instance.
92 For C code generation either <option>--body</option> that
93 generates source code, or <option>--header</option> that
94 generates headers, can be used. These options must be used along with
95 <option>--output</option>, which is used to specify the file to output to.
98 Both files can be generated at the same time by using
99 <option>--generate-c-code</option>, but this option is deprecated.
100 In this case <option>--output</option> cannot be used due to the
101 generation of multiple files. Instead pass
102 <option>--output-directory</option> to specify the directory to put
103 the output files in. By default the current directory will be used.
106 The name of each generated C type is derived from the D-Bus
107 interface name stripped with the prefix given with
108 <option>--interface-prefix</option> and with the dots removed and
109 initial characters capitalized. For example, for the D-Bus
110 interface <literal>com.acme.Coyote</literal> the name used is
111 <literal>ComAcmeCoyote</literal>. For the D-Bus interface
112 <literal>org.project.Bar.Frobnicator</literal> with
113 <option>--interface-prefix</option>
114 <literal>org.project.</literal>, the name used is
115 <literal>BarFrobnicator</literal>.
118 For methods, signals and properties, if not specified, the name
119 defaults to the name of the method, signal or property.
122 Two forms of the name are used - the CamelCase form and the
123 lower-case form. The CamelCase form is used for the #GType and
124 struct name, while lower-case form is used in function names. The
125 lower-case form is calculated by converting from CamelCase to
126 lower-case and inserting underscores at word boundaries (using
130 If the value given by the <literal>org.gtk.GDBus.C.Name</literal>
131 annotation or the <option>--c-namespace</option> option contains
132 an underscore (sometimes called <emphasis>Ugly_Case</emphasis>),
133 then the camel-case name is derived by removing all underscores,
134 and the lower-case name is derived by lower-casing the
135 string. This is useful in some situations where abbreviations are
136 used. For example, if the annotation is used on the interface
137 <literal>net.MyCorp.MyApp.iSCSITarget</literal> with the value
138 <literal>iSCSI_Target</literal> the CamelCase form is
139 <literal>iSCSITarget</literal> while the lower-case form is
140 <literal>iscsi_target</literal>. If the annotation is used on the
141 method <literal>EjectTheiPod</literal> with the value
142 <literal>Eject_The_iPod</literal>, the lower-case form is
143 <literal>eject_the_ipod</literal>.
148 <title>Generating Docbook documentation</title>
150 Each generated Docbook XML file (see the
151 <option>--generate-docbook</option> option for details) is a <ulink
152 url="http://www.docbook.org/tdg/en/html/refentry.html"><literal>RefEntry</literal></ulink>
153 article describing the D-Bus interface.
158 <title>Options</title>
160 The following options are supported:
165 <term><option>-h</option>, <option>--help</option></term>
174 <term><option>--xml-files</option> <replaceable>FILE</replaceable></term>
177 This option is deprecated; use positional arguments instead.
178 The D-Bus introspection XML file.
184 <term><option>--interface-prefix</option> <replaceable>org.project.Prefix.</replaceable></term>
187 A prefix to strip from all D-Bus interface names when
188 calculating the typename for the C binding and the Docbook
190 url="http://www.docbook.org/tdg/en/html/primary.html">sortas
197 <term><option>--generate-docbook</option> <replaceable>OUTFILES</replaceable></term>
200 Generate Docbook Documentation for each D-Bus interface and
201 put it in <filename>OUTFILES-NAME.xml</filename> where
202 <literal>NAME</literal> is a place-holder for the interface
203 name, e.g. <literal>net.Corp.FooBar</literal> and so on.
206 Pass <option>--output-directory</option> to specify the directory
207 to put the output files in. By default the current directory
214 <term><option>--generate-c-code</option> <replaceable>OUTFILES</replaceable></term>
217 Generate C code for all D-Bus interfaces and put it in
218 <filename>OUTFILES.c</filename> and
219 <filename>OUTFILES.h</filename> including any sub-directories. If you want the files to
220 be output in a different location use <option>--output-directory</option> as <filename>OUTFILES.h</filename>
221 including sub-directories will be referenced from <filename>OUTFILES.c</filename>.
224 The full paths would then be <literal>$(OUTDIR)/$(dirname $OUTFILES)/$(basename $OUTFILES).{c,h}</literal>.
230 <term><option>--c-namespace</option> <replaceable>YourProject</replaceable></term>
233 The namespace to use for generated C code. This is expected
235 url="http://en.wikipedia.org/wiki/CamelCase">CamelCase</ulink>
236 or <emphasis>Ugly_Case</emphasis> (see above).
242 <term><option>--pragma-once</option></term>
245 If this option is passed, the
246 <ulink url="https://en.wikipedia.org/wiki/Pragma_once">#pragma once</ulink>
247 preprocessor directive is used instead of include guards.
253 <term><option>--c-generate-object-manager</option></term>
256 If this option is passed, suitable #GDBusObject,
257 #GDBusObjectProxy, #GDBusObjectSkeleton and
258 #GDBusObjectManagerClient subclasses are generated.
264 <term><option>--c-generate-autocleanup</option> none|objects|all</term>
267 This option influences what types autocleanup functions are
268 generated for. 'none' means to not generate any autocleanup functions.
269 'objects' means to generate them for object types, and 'all' means to
270 generate them for object types and interfaces. The default is 'objects'
271 due to a corner case in backwards compatibility with a few projects,
272 but you should likely switch your project to use 'all'.
273 This option was added in GLib 2.50.
279 <term><option>--output-directory</option> <replaceable>OUTDIR</replaceable></term>
282 Directory to output generated source to. Equivalent to changing directory before generation.
285 This option cannot be used with neither <option>--body</option> nor
286 <option>--header</option>, and <option>--output</option> must be used.
293 <term><option>--header</option></term>
296 If this option is passed, it will generate the header code and write it to the disk by
297 using the path and file name provided by <option>--output</option>.
300 Using <option>--generate-c-code</option>, <option>--generate-docbook</option> or
301 <option>--output-directory</option> are not allowed to be used along with
302 <option>--header</option> and <option>--body</option> options, because these options
303 are used to generate only one file.
309 <term><option>--body</option></term>
312 If this option is passed, it will generate the source code and write it to the disk by
313 using the path and file name provided by <option>--output</option>.
316 Using <option>--generate-c-code</option>, <option>--generate-docbook</option> or
317 <option>--output-directory</option> are not allowed to be used along with
318 <option>--header</option> and <option>--body</option> options, because these options
319 are used to generate only one file.
325 <term><option>--output</option> <replaceable>OUTFILE</replaceable></term>
328 The full path where the header (<option>--header</option>) or the source code
329 (<option>--body</option>) will be written, using the path and filename provided by
330 <option>--output</option>. The full path could be something like
331 <literal>$($OUTFILE).{c,h}</literal>.
334 Using <option>--generate-c-code</option>, <option>--generate-docbook</option> or
335 <option>--output-directory</option> is not allowed along with
336 <option>--output</option>, because the latter is used to generate only one file.
342 <term><option>--annotate</option> <replaceable>ELEMENT</replaceable> <replaceable>KEY</replaceable> <replaceable>VALUE</replaceable></term>
345 Used to inject D-Bus annotations into the given XML
346 files. It can be used with interfaces, methods, signals,
347 properties and arguments in the following way:
349 <informalexample><programlisting><![CDATA[
350 gdbus-codegen --c-namespace MyApp \
351 --generate-c-code myapp-generated \
352 --annotate "org.project.InterfaceName" \
353 org.gtk.GDBus.C.Name MyFrobnicator \
354 --annotate "org.project.InterfaceName:Property" \
356 --annotate "org.project.InterfaceName.Method()" \
357 org.freedesktop.DBus.Deprecated true \
358 --annotate "org.project.InterfaceName.Method()[arg_name]" \
360 --annotate "org.project.InterfaceName::Signal" \
362 --annotate "org.project.InterfaceName::Signal[arg_name]" \
364 myapp-dbus-interfaces.xml
365 ]]></programlisting></informalexample>
367 Any UTF-8 string can be used for <replaceable>KEY</replaceable> and <replaceable>VALUE</replaceable>.
376 <title>Supported D-Bus Annotations</title>
378 The following D-Bus annotations are supported by
379 <command>gdbus-codegen</command>:
385 <term><literal>org.freedesktop.DBus.Deprecated</literal></term>
388 Can be used on any <literal><interface></literal>,
389 <literal><method></literal>,
390 <literal><signal></literal> and
391 <literal><property></literal> element to specify that
392 the element is deprecated if its value is
393 <literal>true</literal>. Note that this annotation is
394 defined in the <ulink
395 url="http://dbus.freedesktop.org/doc/dbus-specification.html#introspection-format">D-Bus
396 specification</ulink> and can only assume the values
397 <literal>true</literal> and <literal>false</literal>. In
398 particular, you cannot specify the version that the element
399 was deprecated in nor any helpful deprecation message. Such
400 information should be added to the element documentation
404 When generating C code, this annotation is used to add
405 #G_GNUC_DEPRECATED to generated functions for the element.
408 When generating Docbook XML, a deprecation warning will
409 appear along the documentation for the element.
415 <term><literal>org.gtk.GDBus.Since</literal></term>
418 Can be used on any <literal><interface></literal>,
419 <literal><method></literal>,
420 <literal><signal></literal> and
421 <literal><property></literal> element to specify the
422 version (any free-form string but compared using a
423 version-aware sort function) the element appeared in.
426 When generating C code, this field is used to ensure
427 function pointer order for preserving ABI/API, see <xref
428 linkend="gdbus-code-stability"/>.
431 When generating Docbook XML, the value of this tag appears
432 in the documentation.
438 <term><literal>org.gtk.GDBus.DocString</literal></term>
441 A string with Docbook content for documentation. This annotation can
442 be used on <literal><interface></literal>,
443 <literal><method></literal>,
444 <literal><signal></literal>,
445 <literal><property></literal> and
446 <literal><arg></literal> elements.
452 <term><literal>org.gtk.GDBus.DocString.Short</literal></term>
455 A string with Docbook content for short/brief
456 documentation. This annotation can only be used on
457 <literal><interface></literal> elements.
463 <term><literal>org.gtk.GDBus.C.Name</literal></term>
466 Can be used on any <literal><interface></literal>,
467 <literal><method></literal>,
468 <literal><signal></literal> and
469 <literal><property></literal> element to specify the
470 name to use when generating C code. The value is expected to
472 url="http://en.wikipedia.org/wiki/CamelCase">CamelCase</ulink>
473 or <emphasis>Ugly_Case</emphasis> (see above).
479 <term><literal>org.gtk.GDBus.C.ForceGVariant</literal></term>
482 If set to a non-empty string, a #GVariant instance will
483 be used instead of the natural C type. This annotation can
484 be used on any <literal><arg></literal> and
485 <literal><property></literal> element.
491 <term><literal>org.gtk.GDBus.C.UnixFD</literal></term>
494 If set to a non-empty string, the generated code will
495 include parameters to exchange file descriptors using the
496 #GUnixFDList type. This annotation can be used on
497 <literal><method></literal> elements.
505 As an easier alternative to using the
506 <literal>org.gtk.GDBus.DocString</literal> annotation, note that
507 parser used by <command>gdbus-codegen</command> parses XML
508 comments in a way similar to <ulink
509 url="http://www.gtk.org/gtk-doc/">gtk-doc</ulink>:
510 <informalexample><programlisting><![CDATA[
513 @short_description: A short description
515 A <emphasis>longer</emphasis> description.
517 This is a new paragraph.
519 <interface name="net.corp.Bar">
522 @greeting: The docs for greeting parameter.
523 @response: The docs for response parameter.
525 The docs for the actual method.
527 <method name="FooMethod">
528 <arg name="greeting" direction="in" type="s"/>
529 <arg name="response" direction="out" type="s"/>
534 @blah: The docs for blah parameter.
535 @boo: The docs for boo parameter.
538 The docs for the actual signal.
540 <signal name="BarSignal">
541 <arg name="blah" type="s"/>
542 <arg name="boo" type="s"/>
545 <!-- BazProperty: The docs for the property. -->
546 <property name="BazProperty" type="s" access="read"/>
548 ]]></programlisting></informalexample>
551 Note that <literal><![CDATA[@since]]></literal> can be used in any inline
552 documentation bit (e.g. for interfaces, methods, signals and
553 properties) to set the <literal>org.gtk.GDBus.Since</literal>
554 annotation. For the <literal>org.gtk.GDBus.DocString</literal>
555 annotation (and inline comments), note that substrings of the form
556 <literal><![CDATA[#net.Corp.Bar]]></literal>,
557 <literal><![CDATA[net.Corp.Bar.FooMethod()]]></literal>,
558 <literal><![CDATA[#net.Corp.Bar::BarSignal]]></literal> and
559 <literal><![CDATA[#net.Corp.InlineDocs:BazProperty]]></literal> are all
560 expanded to links to the respective interface, method, signal and
562 Additionally, substrings starting with <literal>@</literal> and <literal>%</literal> characters are rendered as
563 <ulink url="http://www.docbook.org/tdg/en/html/parameter.html">parameter</ulink> and
564 <ulink url="http://www.docbook.org/tdg/en/html/constant.html">constant</ulink> respectively.
567 If both XML comments and
568 <literal>org.gtk.GDBus.DocString</literal> or
569 <literal>org.gtk.GDBus.DocString.Short</literal> annotations are
570 present, the latter wins.
575 <title>Example</title>
577 Consider the following D-Bus Introspection XML.
579 <informalexample><programlisting><![CDATA[
581 <interface name="net.Corp.MyApp.Frobber">
582 <method name="HelloWorld">
583 <arg name="greeting" direction="in" type="s"/>
584 <arg name="response" direction="out" type="s"/>
587 <signal name="Notification">
588 <arg name="icon_blob" type="ay"/>
589 <arg name="height" type="i"/>
590 <arg name="messages" type="as"/>
593 <property name="Verbose" type="b" access="readwrite"/>
599 If <command>gdbus-codegen</command> is used on this file like this:
601 <informalexample><programlisting><![CDATA[
602 gdbus-codegen --generate-c-code myapp-generated \
603 --c-namespace MyApp \
604 --interface-prefix net.corp.MyApp. \
605 net.Corp.MyApp.Frobber.xml
606 ]]></programlisting></informalexample>
609 <filename>myapp-generated.[ch]</filename> are
610 generated. The files provide an abstract
611 #GTypeInterface<!-- -->-derived type called
612 <type>MyAppFrobber</type> as well as two instantiable types with
613 the same name but suffixed with <type>Proxy</type> and
614 <type>Skeleton</type>. The generated file, roughly, contains the
615 following facilities:
617 <informalexample><programlisting><![CDATA[
618 /* GType macros for the three generated types */
619 #define MY_APP_TYPE_FROBBER (my_app_frobber_get_type ())
620 #define MY_APP_TYPE_FROBBER_SKELETON (my_app_frobber_skeleton_get_type ())
621 #define MY_APP_TYPE_FROBBER_PROXY (my_app_frobber_proxy_get_type ())
623 typedef struct _MyAppFrobber MyAppFrobber; /* Dummy typedef */
627 GTypeInterface parent_iface;
629 /* Signal handler for the ::notification signal */
630 void (*notification) (MyAppFrobber *proxy,
633 const gchar* const *messages);
635 /* Signal handler for the ::handle-hello-world signal */
636 gboolean (*handle_hello_world) (MyAppFrobber *proxy,
637 GDBusMethodInvocation *invocation,
638 const gchar *greeting);
641 /* Asynchronously calls HelloWorld() */
643 my_app_frobber_call_hello_world (MyAppFrobber *proxy,
644 const gchar *greeting,
645 GCancellable *cancellable,
646 GAsyncReadyCallback callback,
649 my_app_frobber_call_hello_world_finish (MyAppFrobber *proxy,
650 gchar **out_response,
654 /* Synchronously calls HelloWorld(). Blocks calling thread. */
656 my_app_frobber_call_hello_world_sync (MyAppFrobber *proxy,
657 const gchar *greeting,
658 gchar **out_response,
659 GCancellable *cancellable,
662 /* Completes handling the HelloWorld() method call */
664 my_app_frobber_complete_hello_world (MyAppFrobber *object,
665 GDBusMethodInvocation *invocation,
666 const gchar *response);
668 /* Emits the ::notification signal / Notification() D-Bus signal */
670 my_app_frobber_emit_notification (MyAppFrobber *object,
673 const gchar* const *messages);
675 /* Gets the :verbose GObject property / Verbose D-Bus property.
676 * Does no blocking I/O.
678 gboolean my_app_frobber_get_verbose (MyAppFrobber *object);
680 /* Sets the :verbose GObject property / Verbose D-Bus property.
681 * Does no blocking I/O.
683 void my_app_frobber_set_verbose (MyAppFrobber *object,
686 /* Gets the interface info */
687 GDBusInterfaceInfo *my_app_frobber_interface_info (void);
689 /* Creates a new skeleton object, ready to be exported */
690 MyAppFrobber *my_app_frobber_skeleton_new (void);
692 /* Client-side proxy constructors.
694 * Additionally, _new_for_bus(), _new_for_bus_finish() and
695 * _new_for_bus_sync() proxy constructors are also generated.
698 my_app_frobber_proxy_new (GDBusConnection *connection,
699 GDBusProxyFlags flags,
701 const gchar *object_path,
702 GCancellable *cancellable,
703 GAsyncReadyCallback callback,
706 my_app_frobber_proxy_new_finish (GAsyncResult *res,
709 my_app_frobber_proxy_new_sync (GDBusConnection *connection,
710 GDBusProxyFlags flags,
712 const gchar *object_path,
713 GCancellable *cancellable,
715 ]]></programlisting></informalexample>
717 Thus, for every D-Bus method, there will be three C functions for
718 calling the method, one #GObject signal for handling an incoming
719 call and one C function for completing an incoming call. For every
720 D-Bus signal, there's one #GObject signal and one C function for
721 emitting it. For every D-Bus property, two C functions are
722 generated (one setter, one getter) and one #GObject property. The
723 following table summarizes the generated facilities and where they
731 <entry>Client</entry>
732 <entry>Server</entry>
738 <entry>Use <type>MyAppFrobberProxy</type></entry>
739 <entry>Any type implementing the <type>MyAppFrobber</type> interface</entry>
742 <entry>Methods</entry>
743 <entry>Use <function>m_a_f_hello_world()</function> to call.</entry>
744 <entry>Receive via the <function>handle_hello_world()</function> signal handler. Complete the call with <function>m_a_f_complete_hello_world()</function></entry>
747 <entry>Signals</entry>
748 <entry>Connect to the <function>::notification</function> GObject signal.</entry>
749 <entry>Use <function>m_a_f_emit_notification()</function> to emit signal.</entry>
752 <entry>Properties (Reading)</entry>
753 <entry>Use <function>m_a_f_get_verbose()</function> or <parameter>:verbose</parameter>.</entry>
754 <entry>Implement #GObject<!-- -->'s <function>get_property()</function> vfunc.</entry>
757 <entry>Properties (writing)</entry>
758 <entry>Use <function>m_a_f_set_verbose()</function> or <parameter>:verbose</parameter>.</entry>
759 <entry>Implement #GObject<!-- -->'s <function>set_property()</function> vfunc.</entry>
766 <title>Client-side usage</title>
768 You can use the generated proxy type with the generated
771 <informalexample><programlisting><![CDATA[
776 proxy = my_app_frobber_proxy_new_for_bus_sync (
778 G_DBUS_PROXY_FLAGS_NONE,
779 "net.Corp.MyApp", /* bus name */
780 "/net/Corp/MyApp/SomeFrobber", /* object */
781 NULL, /* GCancellable* */
783 /* do stuff with proxy */
784 g_object_unref (proxy);
785 ]]></programlisting></informalexample>
787 Instead of using the generic #GDBusProxy facilities, one can use
788 the generated methods such as
789 <function>my_app_frobber_call_hello_world()</function> to invoke
790 the <function>net.Corp.MyApp.Frobber.HelloWorld()</function>
791 D-Bus method, connect to the
792 <function>::notification</function> GObject signal to receive
793 the <function>net.Corp.MyApp.Frobber::Notication</function>
794 D-Bus signal and get/set the
795 <parameter>net.Corp.MyApp.Frobber:Verbose</parameter> D-Bus
796 Property using either the GObject property
797 <parameter>:verbose</parameter> or the
798 <function>my_app_get_verbose()</function> and
799 <function>my_app_set_verbose()</function> methods. Use the
800 standard #GObject::notify signal to listen to property changes.
803 Note that all property access is via #GDBusProxy<!-- -->'s
804 property cache so no I/O is ever done when reading properties.
805 Also note that setting a property will cause the
806 <ulink url="http://dbus.freedesktop.org/doc/dbus-specification.html#standard-interfaces-properties">org.freedesktop.DBus.Properties.Set</ulink> method to be
807 called on the remote object. This call, however, is asynchronous
808 so setting a property won't block. Further, the change is
809 delayed and no error checking is possible.
814 <title>Server-side usage</title>
816 The generated <type>MyAppFrobber</type> interface is designed so
817 it is easy to implement it in a #GObject
818 subclass. For example, to handle
819 <function>HelloWorld()</function> method invocations, set the
820 vfunc for <function>handle_hello_hello_world()</function> in the
821 <type>MyAppFrobberIface</type> structure. Similary, to handle
822 the <parameter>net.Corp.MyApp.Frobber:Verbose</parameter>
823 property override the <parameter>:verbose</parameter> #GObject
824 property from the subclass. To emit a signal, use
825 e.g. <function>my_app_emit_signal()</function> or
826 g_signal_emit_by_name().
829 Instead of subclassing, it is often easier to use the generated
830 <type>MyAppFrobberSkeleton</type> subclass. To handle incoming
831 method calls, use <function>g_signal_connect()</function> with
832 the <function>::handle-*</function> signals and instead of
833 overriding #GObject<!-- -->'s
834 <function>get_property()</function> and
835 <function>set_property()</function> vfuncs, use
837 g_object_set() or the generated property
838 getters and setters (the generated class has an internal
839 property bag implementation).
841 <informalexample><programlisting><![CDATA[
843 on_handle_hello_world (MyAppFrobber *interface,
844 GDBusMethodInvocation *invocation,
845 const gchar *greeting,
848 if (g_strcmp0 (greeting, "Boo") != 0)
851 response = g_strdup_printf ("Word! You said `%s'.", greeting);
852 my_app_complete_hello_world (interface, invocation, response);
857 g_dbus_method_invocation_return_error (invocation,
859 MY_APP_ERROR_NO_WHINING,
860 "Hey, %s, there will be no whining!",
861 g_dbus_method_invocation_get_sender (invocation));
868 interface = my_app_frobber_skeleton_new ();
869 my_app_frobber_set_verbose (interface, TRUE);
871 g_signal_connect (interface,
872 "handle-hello-world",
873 G_CALLBACK (on_handle_hello_world),
879 if (!g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (interface),
881 "/path/of/dbus_object",
886 ]]></programlisting></informalexample>
888 To facilitate atomic changesets (multiple properties changing at
889 the same time), #GObject::notify signals are queued up when
890 received. The queue is drained in an idle handler (which is called from the
891 <link linkend="g-main-context-push-thread-default">thread-default main loop</link>
892 of the thread where the skeleton object was
893 contructed) and will cause emissions of the <ulink
894 url="http://dbus.freedesktop.org/doc/dbus-specification.html#standard-interfaces-properties">org.freedesktop.DBus.Properties::PropertiesChanged</ulink>
895 signal with all the properties that have changed. Use
896 g_dbus_interface_skeleton_flush() or
897 g_dbus_object_skeleton_flush() to empty the queue
898 immediately. Use g_object_freeze_notify() and
899 g_object_thaw_notify() for atomic changesets if on a different
906 <title>C Type Mapping</title>
910 <link linkend="G-VARIANT-TYPE-BOOLEAN:CAPS">'b'</link>,
911 <link linkend="G-VARIANT-TYPE-BYTE:CAPS">'y'</link>,
912 <link linkend="G-VARIANT-TYPE-INT16:CAPS">'n'</link>,
913 <link linkend="G-VARIANT-TYPE-UINT16:CAPS">'q'</link>,
914 <link linkend="G-VARIANT-TYPE-INT32:CAPS">'i'</link>,
915 <link linkend="G-VARIANT-TYPE-UINT32:CAPS">'u'</link>,
916 <link linkend="G-VARIANT-TYPE-INT64:CAPS">'x'</link>,
917 <link linkend="G-VARIANT-TYPE-UINT64:CAPS">'t'</link> and
918 <link linkend="G-VARIANT-TYPE-DOUBLE:CAPS">'d'</link>)
920 strings (type-strings
921 <link linkend="G-VARIANT-TYPE-STRING:CAPS">'s'</link>,
922 <link linkend="G-VARIANT-TYPE-BYTESTRING:CAPS">'ay'</link>,
923 <link linkend="G-VARIANT-TYPE-OBJECT-PATH:CAPS">'o'</link> and
924 <link linkend="G-VARIANT-TYPE-SIGNATURE:CAPS">'g'</link>) and
925 arrays of string (type-strings
926 <link linkend="G-VARIANT-TYPE-STRING-ARRAY:CAPS">'as'</link>,
927 <link linkend="G-VARIANT-TYPE-OBJECT-PATH-ARRAY:CAPS">'ao'</link> and
928 <link linkend="G-VARIANT-TYPE-BYTESTRING-ARRAY:CAPS">'aay'</link>)
929 are mapped to the natural types,
930 e.g. #gboolean, #gdouble, #gint, <link linkend="gchararray">gchar*</link>,
931 <link linkend="GStrv">gchar**</link> and
932 so on. Everything else is mapped to the #GVariant
936 This automatic mapping can be turned off by using the annotation
937 <literal>org.gtk.GDBus.C.ForceGVariant</literal> - if used then a
938 #GVariant is always exchanged instead of the
939 corresponding native C type. This annotation may be convenient to
941 bytestrings (type-string <link linkend="G-VARIANT-TYPE-BYTESTRING:CAPS">'ay'</link>)
942 for data that could have embedded NUL bytes.
946 <refsect1 id="gdbus-code-stability">
947 <title>Stability Guarantees</title>
949 The generated C functions are guaranteed to not change their ABI
950 that is, if a method, signal or property does not change its
951 signature in the introspection XML, the generated C functions will
952 not change its C ABI either. The ABI of the generated instance and
953 class structures will be preserved as well.
956 The ABI of the generated #GType<!-- -->s will be preserved only if
957 the <literal>org.gtk.GDBus.Since</literal> annotation is used
958 judiciously — this is because the VTable for the #GInterface
959 relies on functions pointers for signal handlers. Specifically, if
960 a D-Bus method, property or signal or is added to a D-Bus
961 interface, then ABI of the generated #GInterface type is preserved
962 if, and only if, each added method, property signal is annotated
963 with they <literal>org.gtk.GDBus.Since</literal> annotation using
964 a greater version number than previous versions.
967 The generated C code currently happens to be annotated with <ulink
968 url="http://www.gtk.org/gtk-doc/">gtk-doc</ulink> / <ulink
969 url="https://wiki.gnome.org/Projects/GObjectIntrospection">GObject
970 Introspection</ulink> comments / annotations. The layout and
971 contents might change in the future so no guarantees about
972 e.g. <literal>SECTION</literal> usage etc. is given.
975 While the generated Docbook for D-Bus interfaces isn't expected to
976 change, no guarantees are given at this point.
979 It is important to note that the generated code should not be
980 checked into revision control systems, nor it should be included
981 in distributed source archives.
988 Please send bug reports to either the distribution bug tracker
989 or the upstream bug tracker at
990 <ulink url="https://bugzilla.gnome.org/enter_bug.cgi?product=glib">https://bugzilla.gnome.org/enter_bug.cgi?product=glib</ulink>.
995 <title>See also</title>
998 <refentrytitle>gdbus</refentrytitle><manvolnum>1</manvolnum>