Editing Documentation/Maemo 5 Developer Guide/DBus/Implementing and Using D-Bus Signals

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

Warning: This page is 38 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 17: Line 17:
A signal is also emitted whenever a value is changed (making the binary content of the new value different from the old one).
A signal is also emitted whenever a value is changed (making the binary content of the new value different from the old one).
-
In order to make the signals available to introspection data, the interface XML file is modified accordingly: [http://vcs.maemo.org/svn/maemoexamples/trunk/glib-dbus-signals/value-dbus-interface.xml glib-dbus-signals/value-dbus-interface.xml]
+
In order to make the signals available to introspection data, the interface XML file is modified accordingly: glib-dbus-signals/value-dbus-interface.xml
<source lang="xml">
<source lang="xml">
Line 55: Line 55:
== Emitting Signals from GObject ==
== Emitting Signals from GObject ==
-
The signal names are defined in a header file so that they can easily be changed later, and the header file is used in both the server and the client. The following is the section with the signal names: [http://vcs.maemo.org/svn/maemoexamples/trunk/glib-dbus-signals/common-defs.h glib-dbus-signals/common-defs.h]
+
The signal names are defined in a header file so that they can easily be changed later, and the header file is used in both the server and the client. The following is the section with the signal names: glib-dbus-signals/common-defs.h
<source lang="c">
<source lang="c">
Line 66: Line 66:
</source>
</source>
-
Before a <code>GObject</code> can emit a GLib signal, the signal itself needs to be defined and created. The best way to do this is to use the class constructor code (because the signal types need to be created only once): [http://vcs.maemo.org/svn/maemoexamples/trunk/glib-dbus-signals/server.c glib-dbus-signals/server.c]
+
Before a <code>GObject</code> can emit a GLib signal, the signal itself needs to be defined and created. The best way to do this is to use the class constructor code (because the signal types need to be created only once): glib-dbus-signals/server.c
<source lang="c">
<source lang="c">
Line 188: Line 188:
The signal types are kept in the class structure, so that they can be referenced easily by the signal emitting utility. The class constructor code also sets up the threshold limits, which in this implementation are immutable (meaning that they cannot be changed). Experiment with the implementation and add more methods to adjust the thresholds as necessary.
The signal types are kept in the class structure, so that they can be referenced easily by the signal emitting utility. The class constructor code also sets up the threshold limits, which in this implementation are immutable (meaning that they cannot be changed). Experiment with the implementation and add more methods to adjust the thresholds as necessary.
-
Emitting the signals is quite easy, but in order to reduce code amount, a utility function is created to launch a given signal based on its enumeration: [http://vcs.maemo.org/svn/maemoexamples/trunk/glib-dbus-signals/server.c glib-dbus-signals/server.c]
+
Emitting the signals is quite easy, but in order to reduce code amount, a utility function is created to launch a given signal based on its enumeration: glib-dbus-signals/server.c
<source lang="c">
<source lang="c">
Line 232: Line 232:
</source>
</source>
-
To avoid having to check the threshold values in multiple places in the source code, the threshold value is also implemented as a separate function. Emitting the "threshold exceeded" signal is still up to the caller. [http://vcs.maemo.org/svn/maemoexamples/trunk/glib-dbus-signals/server.c glib-dbus-signals/server.c]
+
To avoid having to check the threshold values in multiple places in the source code, the threshold value is also implemented as a separate function. Emitting the "threshold exceeded" signal is still up to the caller. glib-dbus-signals/server.c
<source lang="c">
<source lang="c">
Line 250: Line 250:
</source>
</source>
-
Both utility functions are then used from within the respective set functions, one of which is presented below: [http://vcs.maemo.org/svn/maemoexamples/trunk/glib-dbus-signals/server.c glib-dbus-signals/server.c]
+
Both utility functions are then used from within the respective set functions, one of which is presented below: glib-dbus-signals/server.c
<source lang="c">
<source lang="c">
Line 362: Line 362:
In order to receive D-Bus signals in the client, you need to perform several tasks per signal. This is because <code>dbus-bindings-tool</code> does not generate any code for signals. The aim is to make the GLib wrappers emit GLib signals whenever an interesting D-Bus signal arrives. This also means that registering the interest for a particular D-Bus signal is necessary.
In order to receive D-Bus signals in the client, you need to perform several tasks per signal. This is because <code>dbus-bindings-tool</code> does not generate any code for signals. The aim is to make the GLib wrappers emit GLib signals whenever an interesting D-Bus signal arrives. This also means that registering the interest for a particular D-Bus signal is necessary.
-
When implementing the callbacks for the signals, the prototype must be implemented correctly. Because the signals are sent with one attached string value, the callbacks receive at least the string parameter. Besides the signal attached arguments, the callback receives the proxy object, through which the signal was received, and optional user-specified data (which is not used in this example, so it is always <code>NULL</code>). [http://vcs.maemo.org/svn/maemoexamples/trunk/glib-dbus-signals/client.c glib-dbus-signals/client.c]
+
When implementing the callbacks for the signals, the prototype must be implemented correctly. Because the signals are sent with one attached string value, the callbacks receive at least the string parameter. Besides the signal attached arguments, the callback receives the proxy object, through which the signal was received, and optional user-specified data (which is not used in this example, so it is always <code>NULL</code>). glib-dbus-signals/client.c
<source lang="c">
<source lang="c">
Line 422: Line 422:
The code for the <code>outOfRangeSignalHandler</code> callback has been omitted, because it does not contain anything beyond what <code>valueChangedSignalHandler</code> demonstrates.
The code for the <code>outOfRangeSignalHandler</code> callback has been omitted, because it does not contain anything beyond what <code>valueChangedSignalHandler</code> demonstrates.
-
Registering for the signals is a two-step process. First, it is necessary to register the interest in the D-Bus signals, and then install the callbacks for the respective GLib signals. This is done within main: [http://vcs.maemo.org/svn/maemoexamples/trunk/glib-dbus-signals/client.c glib-dbus-signals/client.c]
+
Registering for the signals is a two-step process. First, it is necessary to register the interest in the D-Bus signals, and then install the callbacks for the respective GLib signals. This is done within main: glib-dbus-signals/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)