2 .\" Title: gdbus-codegen
3 .\" Author: [see the "Author" section]
4 .\" Generator: DocBook XSL Stylesheets v1.76.1 <http://docbook.sf.net/>
6 .\" Manual: User Commands
7 .\" Source: User Commands
10 .TH "GDBUS\-CODEGEN" "1" "05/14/2012" "User Commands" "User Commands"
11 .\" -----------------------------------------------------------------
12 .\" * Define some portability stuff
13 .\" -----------------------------------------------------------------
14 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
15 .\" http://bugs.debian.org/507673
16 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
17 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
20 .\" -----------------------------------------------------------------
21 .\" * set default formatting
22 .\" -----------------------------------------------------------------
23 .\" disable hyphenation
25 .\" disable justification (adjust text to left margin only)
27 .\" -----------------------------------------------------------------
28 .\" * MAIN CONTENT STARTS HERE *
29 .\" -----------------------------------------------------------------
31 gdbus-codegen \- D\-Bus code and documentation generator
33 .HP \w'\fBgdbus\-codegen\fR\ 'u
34 \fBgdbus\-codegen\fR [\fB\-\-interface\-prefix\fR\ \fIorg\&.project\&.Prefix\fR] [\fB\-\-generate\-c\-code\fR\ \fIOUTFILES\fR] [\fB\-\-c\-namespace\fR\ \fIYourProject\fR] [\fB\-\-c\-generate\-object\-manager\fR] [\fB\-\-generate\-docbook\fR\ \fIOUTFILES\fR] [\fB\-\-annotate\fR\ \fIELEMENT\fR\ \fIKEY\fR\ \fIVALUE\fR]... FILE [FILE...]
39 is used to generate code and/or documentation for one or more D\-Bus interfaces\&. The tool reads
40 \m[blue]\fBD\-Bus Introspection XML\fR\m[]\&\s-2\u[1]\d\s+2
41 files and generates output files\&. The tool currently supports generating C code (via
42 \fB\-\-generate\-c\-code\fR) and Docbook XML (via
43 \fB\-\-generate\-docbook\fR)\&.
44 .SH "GENERATING C CODE"
46 When generating C code, a #GInterface
47 \-derived type is generated for each D\-Bus interface\&. Additionally, for every generated type,
48 \fBFooBar\fR, two concrete instantiable types,
51 \fBFooBarSkeleton\fR, implementing said interface are also generated\&. The former is derived from #GDBusProxy and intended for use on the client side while the latter is derived from the #GDBusInterfaceSkeleton type making it easy to export on a #GDBusConnection either directly or via a #GDBusObjectManagerServer instance\&.
53 The name of each generated C type is derived from the D\-Bus interface name stripped with the prefix given with
54 \fB\-\-interface\-prefix\fR
55 and with the dots removed and initial characters capitalized\&. For example, for the D\-Bus interface
58 ComAcmeCoyote\&. For the D\-Bus interface
59 org\&.project\&.Bar\&.Frobnicator
61 \fB\-\-interface\-prefix\fR
62 org\&.project\&., the name used is
65 For methods, signals and properties, if not specified, the name defaults to the name of the method, signal or property\&.
67 Two forms of the name are used \- the CamelCase form and the lower\-case form\&. The CamelCase form is used for the #GType and struct name, while lower\-case form is used in function names\&. The lower\-case form is calculated by converting from CamelCase to lower\-case and inserting underscores at word boundaries (using certain heuristics)\&.
69 If the value given by the
70 org\&.gtk\&.GDBus\&.C\&.Name
72 \fB\-\-c\-namespace\fR
73 option contains an underscore (sometimes called
74 \fIUgly_Case\fR), then the camel\-case name is derived by removing all underscores, and the lower\-case name is derived by lower\-casing the string\&. This is useful in some situations where abbreviations are used\&. For example, if the annotation is used on the interface
75 net\&.MyCorp\&.MyApp\&.iSCSITarget
80 while the lower\-case form is
81 iscsi_target\&. If the annotation is used on the method
84 Eject_The_iPod, the lower\-case form is
86 .SH "GENERATING DOCBOOK DOCUMENTATION"
88 Each generated Docbook XML file (see the
89 \fB\-\-generate\-docbook\fR
90 option for details) is a
91 \m[blue]\fBRefEntry\fR\m[]\&\s-2\u[2]\d\s+2
92 article describing the D\-Bus interface\&.
95 The following options are supported:
97 \fB\-\-interface\-prefix\fR \fIorg\&.project\&.Prefix\&.\fR
99 A prefix to strip from all D\-Bus interface names when calculating the typename for the C binding and the Docbook
100 \m[blue]\fBsortas attribute\fR\m[]\&\s-2\u[3]\d\s+2\&.
103 \fB\-\-generate\-docbook\fR \fIOUTFILES\fR
105 Generate Docbook Documentation for each D\-Bus interface and put it in
109 is a place\-holder for the interface name, e\&.g\&.
114 \fB\-\-generate\-c\-code\fR \fIOUTFILES\fR
116 Generate C code for all D\-Bus interfaces and put it in
122 \fB\-\-c\-namespace\fR \fIYourProject\fR
124 The namespace to use for generated C code\&. This is expected to be in
125 \m[blue]\fBCamelCase\fR\m[]\&\s-2\u[4]\d\s+2
131 \fB\-\-c\-generate\-object\-manager\fR
133 If this option is passed, suitable #GDBusObject, #GDBusObjectProxy, #GDBusObjectSkeleton and #GDBusObjectManagerClient subclasses are generated\&.
136 \fB\-\-annotate\fR \fIELEMENT\fR \fIKEY\fR \fIVALUE\fR
138 Used to inject D\-Bus annotations into the given XML files\&. It can be used with interfaces, methods, signals, properties and arguments in the following way:
144 gdbus\-codegen \-\-c\-namespace MyApp \e
145 \-\-generate\-c\-code myapp\-generated \e
146 \-\-annotate "org\&.project\&.InterfaceName" \e
147 org\&.gtk\&.GDBus\&.C\&.Name MyFrobnicator \e
148 \-\-annotate "org\&.project\&.InterfaceName:Property" \e
150 \-\-annotate "org\&.project\&.InterfaceName\&.Method()" \e
151 org\&.freedesktop\&.DBus\&.Deprecated true \e
152 \-\-annotate "org\&.project\&.InterfaceName\&.Method()[arg_name]" \e
154 \-\-annotate "org\&.project\&.InterfaceName::Signal" \e
156 \-\-annotate "org\&.project\&.InterfaceName::Signal[arg_name]" \e
158 myapp\-dbus\-interfaces\&.xml
163 Any UTF\-8 string can be used for
168 .SH "SUPPORTED D-BUS ANNOTATIONS"
170 The following D\-Bus annotations are supported by
171 \fBgdbus\-codegen\fR:
173 org\&.freedesktop\&.DBus\&.Deprecated
181 element to specify that the element is deprecated if its value is
182 true\&. Note that this annotation is defined in the
183 \m[blue]\fBD\-Bus specification\fR\m[]\&\s-2\u[1]\d\s+2
184 and can only assume the values
187 false\&. In particular, you cannot specify the version that the element was deprecated in nor any helpful deprecation message\&. Such information should be added to the element documentation instead\&.
189 When generating C code, this annotation is used to add #G_GNUC_DEPRECATED to generated functions for the element\&.
191 When generating Docbook XML, a deprecation warning will appear along the documentation for the element\&.
194 org\&.gtk\&.GDBus\&.Since
202 element to specify the version (any free\-form string but compared using a version\-aware sort function) the element appeared in\&.
204 When generating C code, this field is used to ensure function pointer order for preserving ABI/API, see
205 the section called \(lqSTABILITY GUARANTEES\(rq\&.
207 When generating Docbook XML, the value of this tag appears in the documentation\&.
210 org\&.gtk\&.GDBus\&.DocString
212 A string with Docbook content for documentation\&. This annotation can be used on
222 org\&.gtk\&.GDBus\&.DocString\&.Short
224 A string with Docbook content for short/brief documentation\&. This annotation can only be used on
229 org\&.gtk\&.GDBus\&.C\&.Name
237 element to specify the name to use when generating C code\&. The value is expected to be in
238 \m[blue]\fBCamelCase\fR\m[]\&\s-2\u[4]\d\s+2
244 org\&.gtk\&.GDBus\&.C\&.ForceGVariant
246 If set to a non\-empty string, a #GVariant instance will be used instead of the natural C type\&. This annotation can be used on any
253 org\&.gtk\&.GDBus\&.C\&.UnixFD
255 If set to a non\-empty string, the generated code will include parameters to exchange file descriptors using the #GUnixFDList type\&. This annotation can be used on
260 As an easier alternative to using the
261 org\&.gtk\&.GDBus\&.DocString
262 annotation, note that parser used by
264 parses XML comments in a way similar to
265 \m[blue]\fBgtk\-doc\fR\m[]\&\s-2\u[5]\d\s+2:
266 .sp .if n \{\ .RS 4 .\} .nf <!\-\- net\&.Corp\&.Bar: @short_description: A short description A <emphasis>longer</emphasis> description\&. This is a new paragraph\&. \-\-> <interface name="net\&.corp\&.Bar"> <!\-\- FooMethod: @greeting: The docs for greeting parameter\&. @response: The docs for response parameter\&. The docs for the actual method\&. \-\-> <method name="FooMethod"> <arg name="greeting" direction="in" type="s"/> <arg name="response" direction="out" type="s"/> </method> <!\-\- BarSignal: @blah: The docs for blah parameter\&. @boo: The docs for boo parameter\&. @since: 2\&.30 The docs for the actual signal\&. \-\-> <signal name="BarSignal"> <arg name="blah" type="s"/> <arg name="boo" type="s"/> </signal> <!\-\- BazProperty: The docs for the property\&. \-\-> <property name="BazProperty" type="s" access="read"/> </interface> .fi .if n \{\ .RE .\}
270 can be used in any inline documentation bit (e\&.g\&. for interfaces, methods, signals and properties) to set the
271 org\&.gtk\&.GDBus\&.Since
272 annotation\&. For the
273 org\&.gtk\&.GDBus\&.DocString
274 annotation (and inline comments), note that substrings of the form
276 net\&.Corp\&.Bar\&.FooMethod(),
277 #net\&.Corp\&.Bar::BarSignal
279 #net\&.Corp\&.InlineDocs:BazProperty
280 are all expanded to links to the respective interface, method, signal and property\&. Additionally, substrings starting with
284 characters are rendered as
285 \m[blue]\fBparameter\fR\m[]\&\s-2\u[6]\d\s+2
287 \m[blue]\fBconstant\fR\m[]\&\s-2\u[7]\d\s+2
290 If both XML comments and
291 org\&.gtk\&.GDBus\&.DocString
293 org\&.gtk\&.GDBus\&.DocString\&.Short
294 annotations are present, the latter wins\&.
297 Consider the following D\-Bus Introspection XML\&.
304 <interface name="net\&.Corp\&.MyApp\&.Frobber">
305 <method name="HelloWorld">
306 <arg name="greeting" direction="in" type="s"/>
307 <arg name="response" direction="out" type="s"/>
310 <signal name="Notification">
311 <arg name="icon_blob" type="ay"/>
312 <arg name="height" type="i"/>
313 <arg name="messages" type="as"/>
316 <property name="Verbose" type="b" access="readwrite"/>
326 is used on this file like this:
332 gdbus\-codegen \-\-generate\-c\-code myapp\-generated \e
333 \-\-c\-namespace MyApp \e
334 \-\-interface\-prefix net\&.corp\&.MyApp\&. \e
335 net\&.Corp\&.MyApp\&.Frobber\&.xml
342 myapp\-generated\&.[ch]
343 are generated\&. The files provide an abstract #GTypeInterface
344 \-derived type called
346 as well as two instantiable types with the same name but suffixed with
349 \fBSkeleton\fR\&. The generated file, roughly, contains the following facilities:
355 /* GType macros for the three generated types */
356 #define MY_APP_TYPE_FROBBER (my_app_frobber_get_type ())
357 #define MY_APP_TYPE_FROBBER_SKELETON (my_app_frobber_skeleton_get_type ())
358 #define MY_APP_TYPE_FROBBER_PROXY (my_app_frobber_proxy_get_type ())
360 typedef struct _MyAppFrobber MyAppFrobber; /* Dummy typedef */
364 GTypeInterface parent_iface;
366 /* Signal handler for the ::notification signal */
367 void (*notification) (MyAppFrobber *proxy,
370 const gchar* const *messages);
372 /* Signal handler for the ::handle\-hello\-world signal */
373 gboolean (*handle_hello_world) (MyAppFrobber *proxy,
374 GDBusMethodInvocation *invocation,
375 const gchar *greeting);
378 /* Asynchronously calls HelloWorld() */
380 my_app_frobber_call_hello_world (MyAppFrobber *proxy,
381 const gchar *greeting,
382 GCancellable *cancellable,
383 GAsyncReadyCallback callback,
386 my_app_frobber_call_hello_world_finish (MyAppFrobber *proxy,
387 gchar **out_response,
391 /* Synchronously calls HelloWorld()\&. Blocks calling thread\&. */
393 my_app_frobber_call_hello_world_sync (MyAppFrobber *proxy,
394 const gchar *greeting,
395 gchar **out_response,
396 GCancellable *cancellable,
399 /* Completes handling the HelloWorld() method call */
401 my_app_frobber_complete_hello_world (MyAppFrobber *object,
402 GDBusMethodInvocation *invocation,
403 const gchar *response);
405 /* Emits the ::notification signal / Notification() D\-Bus signal */
407 my_app_frobber_emit_notification (MyAppFrobber *object,
410 const gchar* const *messages);
412 /* Gets the :verbose GObject property / Verbose D\-Bus property\&.
413 * Does no blocking I/O\&.
415 gboolean my_app_frobber_get_verbose (MyAppFrobber *object);
417 /* Sets the :verbose GObject property / Verbose D\-Bus property\&.
418 * Does no blocking I/O\&.
420 void my_app_frobber_set_verbose (MyAppFrobber *object,
423 /* Gets the interface info */
424 GDBusInterfaceInfo *my_app_frobber_interface_info (void);
426 /* Creates a new skeleton object, ready to be exported */
427 MyAppFrobber *my_app_frobber_skeleton_new (void);
429 /* Client\-side proxy constructors\&.
431 * Additionally, _new_for_bus(), _new_for_bus_finish() and
432 * _new_for_bus_sync() proxy constructors are also generated\&.
435 my_app_frobber_proxy_new (GDBusConnection *connection,
436 GDBusProxyFlags flags,
438 const gchar *object_path,
439 GCancellable *cancellable,
440 GAsyncReadyCallback callback,
443 my_app_frobber_proxy_new_finish (GAsyncResult *res,
446 my_app_frobber_proxy_new_sync (GDBusConnection *connection,
447 GDBusProxyFlags flags,
449 const gchar *object_path,
450 GCancellable *cancellable,
457 Thus, for every D\-Bus method, there will be three C functions for calling the method, one #GObject signal for handling an incoming call and one C function for completing an incoming call\&. For every D\-Bus signal, there\*(Aqs one #GObject signal and one C function for emitting it\&. For every D\-Bus property, two C functions are generated (one setter, one getter) and one #GObject property\&. The following table summarizes the generated facilities and where they are applicable:
477 Use \fBMyAppFrobberProxy\fR
479 Any type implementing the \fBMyAppFrobber\fR interface
484 Use \fBm_a_f_hello_world()\fR to call\&.
486 Receive via the \fBhandle_hello_world()\fR signal handler\&. Complete the call with \fBm_a_f_complete_hello_world()\fR
491 Connect to the \fB::notification\fR GObject signal\&.
493 Use \fBm_a_f_emit_notification()\fR to emit signal\&.
498 Use \fBm_a_f_get_verbose()\fR or \fI:verbose\fR\&.
500 Implement #GObject\*(Aqs \fBget_property()\fR vfunc\&.
505 Use \fBm_a_f_set_verbose()\fR or \fI:verbose\fR\&.
507 Implement #GObject\*(Aqs \fBset_property()\fR vfunc\&.
511 .SS "Client\-side usage"
513 You can use the generated proxy type with the generated constructors:
523 proxy = my_app_frobber_proxy_new_for_bus_sync (
525 G_DBUS_PROXY_FLAGS_NONE,
526 "net\&.Corp\&.MyApp", /* bus name */
527 "/net/Corp/MyApp/SomeFrobber", /* object */
528 NULL, /* GCancellable* */
530 /* do stuff with proxy */
531 g_object_unref (proxy);
537 Instead of using the generic #GDBusProxy facilities, one can use the generated methods such as
538 \fBmy_app_frobber_call_hello_world()\fR
540 \fBnet\&.Corp\&.MyApp\&.Frobber\&.HelloWorld()\fR
541 D\-Bus method, connect to the the
543 GObject signal to receive the
544 \fBnet\&.Corp\&.MyApp\&.Frobber::Notication\fR
545 D\-Bus signal and get/set the
546 \fInet\&.Corp\&.MyApp\&.Frobber:Verbose\fR
547 D\-Bus Property using either the GObject property
550 \fBmy_app_get_verbose()\fR
552 \fBmy_app_set_verbose()\fR
553 methods\&. Use the standard #GObject::notify signal to listen to property changes\&.
555 Note that all property access is via #GDBusProxy
556 \*(Aqs property cache so no I/O is ever done when reading properties\&. Also note that setting a property will cause the
557 \m[blue]\fBorg\&.freedesktop\&.DBus\&.Properties\&.Set\fR\m[]\&\s-2\u[8]\d\s+2
558 method to be called on the remote object\&. This call, however, is asynchronous so setting a property won\*(Aqt block\&. Further, the change is delayed and no error checking is possible\&.
559 .SS "Server\-side usage"
563 interface is designed so it is easy to implement it in a #GObject subclass\&. For example, to handle
565 method invocations, set the vfunc for
566 \fBhandle_hello_hello_world()\fR
568 \fBMyAppFrobberIface\fR
569 structure\&. Similary, to handle the
570 \fInet\&.Corp\&.MyApp\&.Frobber:Verbose\fR
571 property override the
573 #GObject property from the subclass\&. To emit a signal, use e\&.g\&.
574 \fBmy_app_emit_signal()\fR
575 or g_signal_emit_by_name()\&.
577 Instead of subclassing, it is often easier to use the generated
578 \fBMyAppFrobberSkeleton\fR
579 subclass\&. To handle incoming method calls, use
580 \fBg_signal_connect()\fR
583 signals and instead of overriding #GObject
588 vfuncs, use g_object_get() and g_object_set() or the generated property getters and setters (the generated class has an internal property bag implementation)\&.
595 on_handle_hello_world (MyAppFrobber *interface,
596 GDBusMethodInvocation *invocation,
597 const gchar *greeting,
600 if (g_strcmp0 (greeting, "Boo") != 0)
603 response = g_strdup_printf ("Word! You said `%s\*(Aq\&.", greeting);
604 my_app_complete_hello_world (interface, invocation, response);
609 g_dbus_method_invocation_return_error (MY_APP_ERROR,
610 MY_APP_ERROR_NO_WHINING,
611 "Hey, %s, there will be no whining!",
612 g_dbus_method_invocation_get_sender (invocation));
619 interface = my_app_frobber_skeleton_new ();
620 my_app_frobber_set_verbose (interface, TRUE);
622 g_signal_connect (interface,
623 "handle\-hello\-world",
624 G_CALLBACK (on_handle_hello_world),
630 if (!g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (interface),
632 "/path/of/dbus_object",
642 To facilitate atomic changesets (multiple properties changing at the same time), #GObject::notify signals are queued up when received\&. The queue is drained in an idle handler (which is called from the
643 thread\-default main loop
644 of the thread where the skeleton object was contructed) and will cause emissions of the
645 \m[blue]\fBorg\&.freedesktop\&.DBus\&.Properties::PropertiesChanged\fR\m[]\&\s-2\u[8]\d\s+2
646 signal with all the properties that have changed\&. Use g_dbus_interface_skeleton_flush() or g_dbus_object_skeleton_flush() to empty the queue immediately\&. Use g_object_freeze_notify() and g_object_thaw_notify() for atomic changesets if on a different thread\&.
649 Scalar types (type\-strings
659 \*(Aqd\*(Aq) ), strings (type\-strings
664 \*(Aqg\*(Aq) and arrays of string (type\-strings
668 \*(Aqaay\*(Aq) are mapped to the natural types, e\&.g\&. #gboolean, #gdouble, #gint,
671 and so on\&. Everything else is mapped to the #GVariant type\&.
673 This automatic mapping can be turned off by using the annotation
674 org\&.gtk\&.GDBus\&.C\&.ForceGVariant
675 \- if used then a #GVariant is always exchanged instead of the corresponding native C type\&. This annotation may be convenient to use when using bytestrings (type\-string
676 \*(Aqay\*(Aq) for data that could have embedded NUL bytes\&.
677 .SH "STABILITY GUARANTEES"
679 The generated C functions are guaranteed to not change their ABI that is, if a method, signal or property does not change its signature in the introspection XML, the generated C functions will not change its C ABI either\&.
681 The ABI of the generated #GType
682 s will be preserved only if the
683 org\&.gtk\&.GDBus\&.Since
684 annotation is used judiciously \(em this is because the VTable for the #GInterface relies on functions pointers for signal handlers\&. Specifically, if a D\-Bus method, property or signal or is added to a D\-Bus interface, then ABI of the generated #GInterface type is preserved if, and only if, each added method, property signal is annotated with they
685 org\&.gtk\&.GDBus\&.Since
686 annotation using a greater version number than previous versions\&.
688 The generated C code currently happens to be annotated with
689 \m[blue]\fBgtk\-doc\fR\m[]\&\s-2\u[5]\d\s+2
691 \m[blue]\fBGObject Introspection\fR\m[]\&\s-2\u[9]\d\s+2
692 comments / annotations\&. The layout and contents might change in the future so no guarantees about e\&.g\&.
694 usage etc\&. is given\&.
696 While the generated Docbook for D\-Bus interfaces isn\*(Aqt expected to change, no guarantees are given at this point\&.
699 Written by David Zeuthen
701 with a lot of help from many others\&.
704 Please send bug reports to either the distribution bug tracker or the upstream bug tracker at
705 \m[blue]\fBhttps://bugzilla\&.gnome\&.org/enter_bug\&.cgi?product=glib\fR\m[]\&.
712 D-Bus Introspection XML
714 \%http://dbus.freedesktop.org/doc/dbus-specification.html#introspection-format
719 \%http://www.docbook.org/tdg/en/html/refentry.html
724 \%http://www.docbook.org/tdg/en/html/primary.html
729 \%http://en.wikipedia.org/wiki/CamelCase
734 \%http://www.gtk.org/gtk-doc/
739 \%http://www.docbook.org/tdg/en/html/parameter.html
744 \%http://www.docbook.org/tdg/en/html/constant.html
747 org.freedesktop.DBus.Properties.Set
749 \%http://dbus.freedesktop.org/doc/dbus-specification.html#standard-interfaces-properties
752 GObject Introspection
754 \%https://live.gnome.org/GObjectIntrospection