Editing Documentation/Maemo 5 Developer Guide/DBus/Using GLib Wrappers For D-Bus

Warning: You are not logged in. Your IP address will be recorded in this page's edit history.

Warning: This page is 51 kilobytes long; some browsers may have problems editing pages approaching or longer than 32kb. Please consider breaking the page into smaller sections.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision Your text
Line 13: Line 13:
Because the primary objective here is to make the object available over D-Bus, the example starts by covering one of the easiest way of achieving this: the dbus-bindings-tool. The tool generates a lot of the bindings code for both the client and server side. As input the uses an XML file describing the interface for the service that is being implemented.
Because the primary objective here is to make the object available over D-Bus, the example starts by covering one of the easiest way of achieving this: the dbus-bindings-tool. The tool generates a lot of the bindings code for both the client and server side. As input the uses an XML file describing the interface for the service that is being implemented.
-
The first step is to describe one method in XML. Each method is described with a separate method element, whose name attribute is the name of the method to be generated (this name is copied into the generated stub code automatically by the tool). The first method is <code>setvalue1</code>, which gets one argument, <code>new_value</code>, which is an 32-bit signed integer: [http://vcs.maemo.org/svn/maemoexamples/trunk/glib-dbus-sync/value-dbus-interface.xml glib-dbus-sync/value-dbus-interface.xml]
+
The first step is to describe one method in XML. Each method is described with a separate method element, whose name attribute is the name of the method to be generated (this name is copied into the generated stub code automatically by the tool). The first method is setvalue1, which gets one argument, new_value, which is an 32-bit signed integer: glib-dbus-sync/value-dbus-interface.xml
<source lang="xml">
<source lang="xml">
Line 22: Line 22:
</source>
</source>
-
Define each argument explicitly with the arg element. The type attribute is required because it defines the data type for the argument. Arguments are sometimes called parameters when they are used with D-Bus methods. Each argument needs to specify the "direction" of the argument. Parameters for method calls are "going into" the service, hence the correct content for the direction attribute is in. Return values from method calls are "coming out" of the service. Hence, their direction is out. If a method call does not return any value (returns <code>void</code>), no argument with the direction out needs to be specified.
+
Define each argument explicitly with the arg element. The type attribute is required because it defines the data type for the argument. Arguments are sometimes called parameters when they are used with D-Bus methods. Each argument needs to specify the "direction" of the argument. Parameters for method calls are "going into" the service, hence the correct content for the direction attribute is in. Return values from method calls are "coming out" of the service. Hence, their direction is out. If a method call does not return any value (returns void), no argument with the direction out needs to be specified.
D-Bus by itself does not limit the number of return arguments. C language supports only one return value from a function, but a lot of the higher level languages do not have this restriction.
D-Bus by itself does not limit the number of return arguments. C language supports only one return value from a function, but a lot of the higher level languages do not have this restriction.
Line 40: Line 40:
From the above list, it can be seen that setvalue1 accepts one 32-bit signed integer argument (<code>new_value</code>). The name of the argument affects the generated stub code prototypes (not the implementation), but is quite useful for documentation, and also for D-Bus introspection.
From the above list, it can be seen that setvalue1 accepts one 32-bit signed integer argument (<code>new_value</code>). The name of the argument affects the generated stub code prototypes (not the implementation), but is quite useful for documentation, and also for D-Bus introspection.
-
The next step is the interface specification of another method: <code>getvalue1</code>, which returns the current integer value of the object. It has no method call parameters (no arguments with direction="in"), and only returns one 32-bit signed integer: [http://vcs.maemo.org/svn/maemoexamples/trunk/glib-dbus-sync/value-dbus-interface.xml glib-dbus-sync/value-dbus-interface.xml]
+
The next step is the interface specification of another method: <code>getvalue1</code>, which returns the current integer value of the object. It has no method call parameters (no arguments with direction="in"), and only returns one 32-bit signed integer: glib-dbus-sync/value-dbus-interface.xml
<source lang="xml">
<source lang="xml">
Line 53: Line 53:
Bind the methods to a specific (D-Bus) interface by placing the method elements within an interface element. The interface name attribute is optional but recommended, otherwise the interface is unnamed and provides less useful information on introspection.
Bind the methods to a specific (D-Bus) interface by placing the method elements within an interface element. The interface name attribute is optional but recommended, otherwise the interface is unnamed and provides less useful information on introspection.
-
Multiple interfaces can be implemented in the same object, and if this is the case, the multiple interface elements are listed within the node element. The node element is the "top-level" element. In this case, only one explicit interface is implemented (the binding tools add the introspection interfaces automatically, so specifying them is not necessary in the XML). And so, the result is the minimum required interface XML file: [http://vcs.maemo.org/svn/maemoexamples/trunk/glib-dbus-sync/value-dbus-interface.xml glib-dbus-sync/value-dbus-interface.xml]
+
Multiple interfaces can be implemented in the same object, and if this is the case, the multiple interface elements are listed within the node element. The node element is the "top-level" element. In this case, only one explicit interface is implemented (the binding tools add the introspection interfaces automatically, so specifying them is not necessary in the XML). And so, the result is the minimum required interface XML file: glib-dbus-sync/value-dbus-interface.xml
<source lang="xml">
<source lang="xml">
Line 71: Line 71:
</source>
</source>
-
Extend the minimal interface specification by adding the correct reference to the proper DTD. This allows validation tools to work automatically with the XML file. Methods are also added to manipulate the second value. The full interface file now contains comments, describing the purpose of the interface and the methods. This is highly recommended, if publishing the interface is planned at some point, as the bare XML does not carry semantic information. [http://vcs.maemo.org/svn/maemoexamples/trunk/glib-dbus-sync/value-dbus-interface.xml glib-dbus-sync/value-dbus-interface.xml]
+
Extend the minimal interface specification by adding the correct reference to the proper DTD. This allows validation tools to work automatically with the XML file. Methods are also added to manipulate the second value. The full interface file now contains comments, describing the purpose of the interface and the methods. This is highly recommended, if publishing the interface is planned at some point, as the bare XML does not carry semantic information. glib-dbus-sync/value-dbus-interface.xml
<source lang="xml">
<source lang="xml">
Line 120: Line 120:
</source>
</source>
-
When dealing with automatic code generation, it is quite useful to also automate testing of the "source files" (in this case, XML). One important validation technique for XML is verifying for well-formedness (all XML files need to satisfy the rules in XML spec 1.0), another is validating the structure of XML (that elements are nested correctly, that only correct elements are present and that the element attributes and data are legal). Structural validation rules are described by a DTD (Document Type Definition) document for the XML format that the file is supposed to adhere to. The DTD is specified in the XML, within the <code>DOCTYPE</code> processing directive.
+
When dealing with automatic code generation, it is quite useful to also automate testing of the "source files" (in this case, XML). One important validation technique for XML is verifying for well-formedness (all XML files need to satisfy the rules in XML spec 1.0), another is validating the structure of XML (that elements are nested correctly, that only correct elements are present and that the element attributes and data are legal). Structural validation rules are described by a DTD (Document Type Definition) document for the XML format that the file is supposed to adhere to. The DTD is specified in the XML, within the DOCTYPE processing directive.
This is still not perfect, because DTD validation can only check for syntax and structure, but not for meaning or semantics.
This is still not perfect, because DTD validation can only check for syntax and structure, but not for meaning or semantics.
-
The next step is to add a target called <code>checkxml</code> to the <code>Makefile</code>, so that it can be run whenever the validity of the interface XML is to be checked. [http://vcs.maemo.org/svn/maemoexamples/trunk/glib-dbus-sync/Makefile glib-dbus-sync/Makefile]
+
The next step is to add a target called checkxml to the '''Makefile''', so that it can be run whenever the validity of the interface XML is to be checked. glib-dbus-sync/Makefile
-
<source lang="make">
+
<source lang="c">
# One extra target (which requires xmllint, from package libxml2-utils)
# One extra target (which requires xmllint, from package libxml2-utils)
# is available to verify the well-formedness and the structure of the
# is available to verify the well-formedness and the structure of the
Line 177: Line 177:
The first error (validity error) is detected, because the file does not adhere to the DTD. The other errors (parser errors) are detected, because the file is no longer a well-formed XML document.
The first error (validity error) is detected, because the file does not adhere to the DTD. The other errors (parser errors) are detected, because the file is no longer a well-formed XML document.
-
If the makefile targets depend on <code>checkxml</code>, the validation can be integrated into the process of the build. However, it is not always the best solution.
+
If the makefile targets depend on checkxml, the validation can be integrated into the process of the build. However, it is not always the best solution.
==Generating Automatic Stub Code ==
==Generating Automatic Stub Code ==
-
The following step is to generate the "glue" code that implements the mapping from GLib into D-Bus. The generated code is used later on, but it is useful to see at this point what the <code>dbus-binding-tool</code> program generates.
+
The following step is to generate the "glue" code that implements the mapping from GLib into D-Bus. The generated code is used later on, but it is useful to see at this point what the dbus-binding-tool program generates.
-
Expand the <code>Makefile</code> to invoke the tool whenever the interface XML changes and store the resulting glue code separately for both the client and server. [http://vcs.maemo.org/svn/maemoexamples/trunk/glib-dbus-sync/Makefile glib-dbus-sync/Makefile]
+
Expand the '''Makefile''' to invoke the tool whenever the interface XML changes and store the resulting glue code separately for both the client and server. glib-dbus-sync/Makefile
-
<source lang="make">
+
<source lang="c">
# Define a list of generated files so that they can be cleaned as well
# Define a list of generated files so that they can be cleaned as well
cleanfiles := value-client-stub.h \
cleanfiles := value-client-stub.h \
Line 210: Line 210:
</source>
</source>
-
Pass two parameters for the <code>dbus-binding-tool</code> program. Use the <code>--prefix</code> parameter to tell which text is prefixed to all generated structure and function names. This helps to avoid namespace collisions when pulling the generated glue files back into the programs. The <code>value_object</code> is used because it seems like a logical prefix for the project. Use a prefix that is not used in the code (even in the object implementation in server). This way, there is no risk of reusing the same names that are generated with the tool.
+
Pass two parameters for the <code>dbus-binding-tool</code> program. Use the <code>--prefix</code> parameter to tell which text is prefixed to all generated structure and function names. This helps to avoid namespace collisions when pulling the generated glue files back into the programs. The value_object is used because it seems like a logical prefix for the project. Use a prefix that is not used in the code (even in the object implementation in server). This way, there is no risk of reusing the same names that are generated with the tool.
The second parameter selects what kind of output the tool generates. At the moment, the tool only supports generating GLib/D-Bus bindings, but this might change in the future. Furthermore, select which "side" of the D-Bus the bindings are generated for. The -client side is for code that wishes to use GLib to access the Value object implementation over D-Bus. The -server side is respectively for the implementation of the Value object.
The second parameter selects what kind of output the tool generates. At the moment, the tool only supports generating GLib/D-Bus bindings, but this might change in the future. Furthermore, select which "side" of the D-Bus the bindings are generated for. The -client side is for code that wishes to use GLib to access the Value object implementation over D-Bus. The -server side is respectively for the implementation of the Value object.
Line 217: Line 217:
<pre>
<pre>
-
[sbox-DIABLO_X86: ~/glib-dbus-sync] > make value-server-stub.h value-client-stub.h
+
[sbox-DIABLO_X86: ~/glib-dbus-sync] &gt; make value-server-stub.h value-client-stub.h
dbus-binding-tool --prefix=value_object --mode=glib-server \
dbus-binding-tool --prefix=value_object --mode=glib-server \
-
   value-dbus-interface.xml > value-server-stub.h
+
   value-dbus-interface.xml &gt; value-server-stub.h
dbus-binding-tool --prefix=value_object --mode=glib-client \
dbus-binding-tool --prefix=value_object --mode=glib-client \
-
   value-dbus-interface.xml > value-client-stub.h
+
   value-dbus-interface.xml &gt; value-client-stub.h
-
[sbox-DIABLO_X86: ~/glib-dbus-sync] > ls -la value*stub.h
+
[sbox-DIABLO_X86: ~/glib-dbus-sync] &gt; ls -la value*stub.h
-rw-rw-r-- 1 user user  5184 Nov 21 14:02 value-client-stub.h
-rw-rw-r-- 1 user user  5184 Nov 21 14:02 value-client-stub.h
-rw-rw-r-- 1 user user 10603 Nov 21 14:02 value-server-stub.h
-rw-rw-r-- 1 user user 10603 Nov 21 14:02 value-server-stub.h
</pre>
</pre>
-
Check what the tool produced, starting with the server stub file: [http://vcs.maemo.org/svn/maemoexamples/trunk/glib-dbus-sync/value-server-stub.h glib-dbus-sync/value-server-stub.h]
+
Check what the tool produced, starting with the server stub file: glib-dbus-sync/value-server-stub.h
<source lang="c">
<source lang="c">
Line 271: Line 271:
== Creating Simple GObject for D-Bus ==
== Creating Simple GObject for D-Bus ==
-
The starting point here is with the per-instance and per-class state structures for the object. The per-class structure contains only the bare minimum contents, which are required from all classes in <code>GObject</code>. The per-instance structure contains the required "parent object" state (<code>GObject</code>), but also includes the two internal values (<code>value1</code> and <code>value2</code>), with which the rest of this example is concerned: [http://vcs.maemo.org/svn/maemoexamples/trunk/glib-dbus-sync/server.c glib-dbus-sync/server.c]
+
The starting point here is with the per-instance and per-class state structures for the object. The per-class structure contains only the bare minimum contents, which are required from all classes in GObject. The per-instance structure contains the required "parent object" state (GObject), but also includes the two internal values (<code>value1</code> and <code>value2</code>), with which the rest of this example is concerned: glib-dbus-sync/server.c
<source lang="c">
<source lang="c">
Line 296: Line 296:
The convenience macros are defined in a way expected for all <code>GType</code>s. The <code>G_TYPE_</code> macros are defined in <code>GType</code> and include the magic by which the object implementation does not need to know much about the internal specifics of <code>GType</code>. The <code>GType</code> macros are described in the [http://maemo.org/api_refs/5.0/beta/gobject/ GObject API reference for GType].
The convenience macros are defined in a way expected for all <code>GType</code>s. The <code>G_TYPE_</code> macros are defined in <code>GType</code> and include the magic by which the object implementation does not need to know much about the internal specifics of <code>GType</code>. The <code>GType</code> macros are described in the [http://maemo.org/api_refs/5.0/beta/gobject/ GObject API reference for GType].
-
Some of the macros are used internally in this implementation later on. [http://vcs.maemo.org/svn/maemoexamples/trunk/glib-dbus-sync/server.c glib-dbus-sync/server.c]
+
Some of the macros are used internally in this implementation later on. glib-dbus-sync/server.c
<source lang="c">
<source lang="c">
Line 331: Line 331:
The <code>dbus_g_object_type_install_info</code> function takes a pointer to the structure describing the D-Bus integration (<code>dbus_glib_value_object_object_info</code>), which is generated by <code>dbus-bindings-tool</code>. This function creates all the necessary runtime information for the <code>GType</code>, so the details can be left alone. It also attaches the introspection data to the <code>GType</code>, so that D-Bus introspection may return information on the interface that the object implements.
The <code>dbus_g_object_type_install_info</code> function takes a pointer to the structure describing the D-Bus integration (<code>dbus_glib_value_object_object_info</code>), which is generated by <code>dbus-bindings-tool</code>. This function creates all the necessary runtime information for the <code>GType</code>, so the details can be left alone. It also attaches the introspection data to the <code>GType</code>, so that D-Bus introspection may return information on the interface that the object implements.
-
The next functions to be implemented are the get and set functions, which allow us to inspect the interface as well. The names of the functions and their prototypes are ultimately dictated by <code>dbus-bindings-tool</code> generated stub header files. This means that if the interface XML is sufficiently changed, the code fails to build (because the generated stubs yield different prototypes): [http://vcs.maemo.org/svn/maemoexamples/trunk/glib-dbus-sync/server.c glib-dbus-sync/server.c]
+
The next functions to be implemented are the get and set functions, which allow us to inspect the interface as well. The names of the functions and their prototypes are ultimately dictated by <code>dbus-bindings-tool</code> generated stub header files. This means that if the interface XML is sufficiently changed, the code fails to build (because the generated stubs yield different prototypes): glib-dbus-sync/server.c
<source lang="c">
<source lang="c">
Line 403: Line 403:
The GLib/D-Bus wrapper logic implements all the necessary parameter conversion from D-Bus into the functions, so it is only necessary to handle the GLib corresponding types (<code>gint</code> and <code>gdouble</code>). The method implementations always receive an object reference to the object as their first parameter, and a pointer to a place where to store new <code>GError</code> objects if the method decides that an error should be created. This error is then to be propagated back to the caller of the D-Bus method. This simple get/set example never sets errors, so the last parameter can be ignored here.
The GLib/D-Bus wrapper logic implements all the necessary parameter conversion from D-Bus into the functions, so it is only necessary to handle the GLib corresponding types (<code>gint</code> and <code>gdouble</code>). The method implementations always receive an object reference to the object as their first parameter, and a pointer to a place where to store new <code>GError</code> objects if the method decides that an error should be created. This error is then to be propagated back to the caller of the D-Bus method. This simple get/set example never sets errors, so the last parameter can be ignored here.
-
Do not return the values in the conventional C way (by using <code>return someVal</code>), but instead the return values are written using the given pointers. The return value of the method is always a <code>gboolean</code>, signifying either success or failure. If failure (<code>FALSE</code>) is returned, create and setup a <code>GError</code> object, and store its address to the error location.
+
Do not return the values in the conventional C way (by using return someVal), but instead the return values are written using the given pointers. The return value of the method is always a gboolean, signifying either success or failure. If failure (<code>FALSE</code>) is returned, create and setup a <code>GError</code> object, and store its address to the error location.
== Publishing GType on D-Bus ==
== Publishing GType on D-Bus ==
Line 409: Line 409:
Once the implementation is complete, an instance of the class must be published onto the D-Bus. This is done inside the main of the server example and involves performing a D-Bus method call on the bus.
Once the implementation is complete, an instance of the class must be published onto the D-Bus. This is done inside the main of the server example and involves performing a D-Bus method call on the bus.
-
To ensure that the server and the client do not have to be changed, if the object or well-known names are changed later, the server and the client are put into a common header file that is used by both: [http://vcs.maemo.org/svn/maemoexamples/trunk/glib-dbus-sync/common-defs.h glib-dbus-sync/common-defs.h]
+
To ensure that the server and the client do not have to be changed, if the object or well-known names are changed later, the server and the client are put into a common header file that is used by both: glib-dbus-sync/common-defs.h
<source lang="c">
<source lang="c">
Line 425: Line 425:
Before using any of the <code>GType</code> functions, the runtime system must be initialized by calling <code>g_type_init</code>. This creates the built-in types and sets up all the machinery necessary for creating custom types. When using GTK+, the function is called automatically if GTK+ is initialized. Because this example only uses GLib, the function must be called manually.
Before using any of the <code>GType</code> functions, the runtime system must be initialized by calling <code>g_type_init</code>. This creates the built-in types and sets up all the machinery necessary for creating custom types. When using GTK+, the function is called automatically if GTK+ is initialized. Because this example only uses GLib, the function must be called manually.
-
After initializing the <code>GType</code> system, the next step is to open a connection to the session bus, which is used for the remainder of the publishing sequence: [http://vcs.maemo.org/svn/maemoexamples/trunk/glib-dbus-sync/ glib-dbus-sync/server.c]
+
After initializing the <code>GType</code> system, the next step is to open a connection to the session bus, which is used for the remainder of the publishing sequence: glib-dbus-sync/server.c
<source lang="c">
<source lang="c">
Line 451: Line 451:
</source>
</source>
-
For prospective clients to find the object on the session bus, attach the server to a well-known name by using the <code>RequestName</code> method call on the D-Bus server (over D-Bus). To target the server, create a GLib/D-Bus proxy object first: [http://vcs.maemo.org/svn/maemoexamples/trunk/glib-dbus-sync/server.c glib-dbus-sync/server.c]
+
For prospective clients to find the object on the session bus, attach the server to a well-known name by using the <code>RequestName</code> method call on the D-Bus server (over D-Bus). To target the server, create a GLib/D-Bus proxy object first: glib-dbus-sync/server.c
<source lang="c">
<source lang="c">
Line 551: Line 551:
Be careful with the order and correctness of the parameters to the function call, as it is easy to get something wrong, and the C compiler cannot really check for parameter type validity here.
Be careful with the order and correctness of the parameters to the function call, as it is easy to get something wrong, and the C compiler cannot really check for parameter type validity here.
-
After the successful name registration, an instance of the <code>ValueObject</code> is created and published on the D-Bus: [http://vcs.maemo.org/svn/maemoexamples/trunk/glib-dbus-sync/server.c glib-dbus-sync/server.c]
+
After the successful name registration, an instance of the <code>ValueObject</code> is created and published on the D-Bus: glib-dbus-sync/server.c
<source lang="c">
<source lang="c">
Line 592: Line 592:
All callback registration is performed automatically by the GLib/D-Bus wrappers on object publication, so there is no need to worry about them.
All callback registration is performed automatically by the GLib/D-Bus wrappers on object publication, so there is no need to worry about them.
-
Implementing the dependencies and rules for the server and the generated stub code gives this snippet: [http://vcs.maemo.org/svn/maemoexamples/trunk/glib-dbus-sync/Makefile glib-dbus-sync/Makefile]
+
Implementing the dependencies and rules for the server and the generated stub code gives this snippet: glib-dbus-sync/Makefile
<source lang="c">
<source lang="c">
Line 607: Line 607:
</source>
</source>
-
When implementing makefiles that separate compilation from linking, passing the target name (automatic variable <code>$@</code>) directly is not possible as the <code>PROGNAME</code>-define (because that expands into <code>server.o</code>, and it would look slightly silly if all the messages were prefixed with the name). Instead, use a GNU make function (<code>basename</code>) to strip any prefixes and suffixes out of the parameter. This way, the <code>PROGNAME</code> is set to server.
+
When implementing makefiles that separate compilation from linking, passing the target name (automatic variable $@) directly is not possible as the PROGNAME-define (because that expands into server.o, and it would look slightly silly if all the messages were prefixed with the name). Instead, use a GNU make function (basename) to strip any prefixes and suffixes out of the parameter. This way, the PROGNAME is set to server.
The next step is to build the server and start it:
The next step is to build the server and start it:
<pre>
<pre>
-
  [sbox-DIABLO_X86: ~/glib-dbus-sync] > make server
+
  [sbox-DIABLO_X86: ~/glib-dbus-sync] &gt; make server
dbus-binding-tool --prefix=value_object --mode=glib-server \
dbus-binding-tool --prefix=value_object --mode=glib-server \
-
   value-dbus-interface.xml > value-server-stub.h
+
   value-dbus-interface.xml &gt; value-server-stub.h
cc -I/usr/include/dbus-1.0 -I/usr/lib/dbus-1.0/include
cc -I/usr/include/dbus-1.0 -I/usr/lib/dbus-1.0/include
   -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -g -Wall
   -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -g -Wall
Line 620: Line 620:
   -c server.c -o server.o
   -c server.c -o server.o
cc server.o -o server -ldbus-glib-1 -ldbus-1 -lgobject-2.0 -lglib-2.0
cc server.o -o server -ldbus-glib-1 -ldbus-1 -lgobject-2.0 -lglib-2.0
-
[sbox-DIABLO_X86: ~/glib-dbus-sync] > run-standalone.sh ./server
+
[sbox-DIABLO_X86: ~/glib-dbus-sync] &gt; run-standalone.sh ./server
server:main Connecting to the Session D-Bus.
server:main Connecting to the Session D-Bus.
server:main Registering the well-known name (org.maemo.Platdev_ex)
server:main Registering the well-known name (org.maemo.Platdev_ex)
Line 694: Line 694:
The <code>dbus-bindings-tool</code> (when run with the <code>--mode=glib-client</code> parameter) generates functions for each of the interface methods, and the functions handle data marshaling operations internally.
The <code>dbus-bindings-tool</code> (when run with the <code>--mode=glib-client</code> parameter) generates functions for each of the interface methods, and the functions handle data marshaling operations internally.
-
Two generated stub functions are presented below, and they are used shortly: [http://vcs.maemo.org/svn/maemoexamples/trunk/glib-dbus-sync/value-client-stub.h glib-dbus-sync/value-client-stub.h]
+
Two generated stub functions are presented below, and they are used shortly: glib-dbus-sync/value-client-stub.h
<source lang="c">
<source lang="c">
Line 729: Line 729:
For now, it is important to notice how the prototypes of the functions are named, and what are the parameters that they expect to be passed to them.
For now, it is important to notice how the prototypes of the functions are named, and what are the parameters that they expect to be passed to them.
-
The <code>org_maemo_Value</code> prefix is taken from the interface XML file, from the name attribute of the interface element. All dots are converted into underscores (because C reserves the dot character for other uses), but otherwise the name is preserved (barring dashes in the name).
+
The org_maemo_Value prefix is taken from the interface XML file, from the name attribute of the interface element. All dots are converted into underscores (because C reserves the dot character for other uses), but otherwise the name is preserved (barring dashes in the name).
The rest of the function name is the method name for each method defined in the interface XML file.
The rest of the function name is the method name for each method defined in the interface XML file.
-
The first parameter for all the generated stub functions is always a pointer to a <code>DBusProxy</code> object, which is necessary to use with the GLib/D-Bus wrapper functions. After the proxy, a list of method parameters is passed. The binding tool prefixes the parameter names with either <code>IN_</code> or <code>OUT_</code> depending on the "direction" of the parameter. The rest of the parameter name is taken from the name attributed of the arg element for the method, or if not given, is automatically generated as arg0, arg1, etc. Input parameters are passed as values (unless they are complex or strings, in which case they are passed as pointers). Output parameters are always passed as pointers.
+
The first parameter for all the generated stub functions is always a pointer to a <code>DBusProxy</code> object, which is necessary to use with the GLib/D-Bus wrapper functions. After the proxy, a list of method parameters is passed. The binding tool prefixes the parameter names with either IN_ or OUT_ depending on the "direction" of the parameter. The rest of the parameter name is taken from the name attributed of the arg element for the method, or if not given, is automatically generated as arg0, arg1, etc. Input parameters are passed as values (unless they are complex or strings, in which case they are passed as pointers). Output parameters are always passed as pointers.
-
The functions always returns a <code>gboolean</code>, indicating failure or success, and if they fail, they also create and set the error pointer to an <code>GError</code> object which can then be checked for the reason for the error (unless the caller passed a <code>NULL</code> pointer for <code>error</code>, in which case the error object is not created). [http://vcs.maemo.org/svn/maemoexamples/trunk/glib-dbus-sync/client.c glib-dbus-sync/client.c]
+
The functions always returns a gboolean, indicating failure or success, and if they fail, they also create and set the error pointer to an <code>GError</code> object which can then be checked for the reason for the error (unless the caller passed a <code>NULL</code> pointer for <code>error</code>, in which case the error object is not created). glib-dbus-sync/client.c
<source lang="c">
<source lang="c">
Line 749: Line 749:
</source>
</source>
-
This allows the client code to use the stub code directly as follows: [http://vcs.maemo.org/svn/maemoexamples/trunk/glib-dbus-sync/client.c glib-dbus-sync/client.c]
+
This allows the client code to use the stub code directly as follows: glib-dbus-sync/client.c
<source lang="c">
<source lang="c">
Line 808: Line 808:
</source>
</source>
-
What is left is connecting to the correct D-Bus, creating a <code>GProxy</code> object which are done in the test program: [http://vcs.maemo.org/svn/maemoexamples/trunk/glib-dbus-sync/client.c glib-dbus-sync/client.c]
+
What is left is connecting to the correct D-Bus, creating a <code>GProxy</code> object which are done in the test program: glib-dbus-sync/client.c
<source lang="c">
<source lang="c">

Learn more about Contributing to the wiki.


Please note that all contributions to maemo.org wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see maemo.org wiki:Copyrights for details). Do not submit copyrighted work without permission!


Cancel | Editing help (opens in new window)