Editing Documentation/Maemo 5 Developer Guide/DBus/D-Bus Server Design Issues

Warning: You are not logged in. Your IP address will be recorded in this page's edit history.
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 19: Line 19:
* Close all standard I/O file descriptors (and preferably also files), so that if the terminal device closes (user logs out), it does not cause <code>SIGPIPE</code> signals to the daemon the next time it accesses the file descriptors (by mistake or intentionally because of <code>g_print</code>/<code>printf</code>). Reopening the file descriptors is also possible, so that they are connected to a device, which just ignore all operations (like /dev/null that is used with daemon).
* Close all standard I/O file descriptors (and preferably also files), so that if the terminal device closes (user logs out), it does not cause <code>SIGPIPE</code> signals to the daemon the next time it accesses the file descriptors (by mistake or intentionally because of <code>g_print</code>/<code>printf</code>). Reopening the file descriptors is also possible, so that they are connected to a device, which just ignore all operations (like /dev/null that is used with daemon).
-
The daemon function allows to select whether or not a change of the directory is wanted and to close the open file descriptors. This utilizes in the servers of this example in the following way: [http://vcs.maemo.org/svn/maemoexamples/trunk/glib-dbus-sync/server.c glib-dbus-sync/server.c]
+
The daemon function allows to select whether or not a change of the directory is wanted and to close the open file descriptors. This utilizes in the servers of this example in the following way: glib-dbus-sync/server.c
<source lang="c">
<source lang="c">
Line 39: Line 39:
</source>
</source>
-
This definition is available to the user inside the Makefile: [http://vcs.maemo.org/svn/maemoexamples/trunk/glib-dbus-sync/Makefile glib-dbus-sync/Makefile]
+
This definition is available to the user inside the Makefile: glib-dbus-sync/Makefile
<source lang="c">
<source lang="c">
Line 154: Line 154:
The simplest way to debug servers is the intelligent use of print-out of events in the code sections that are relevant. Tracing everything that goes on rarely makes sense, but having a reliable and working infrastructure (in code level) helps. One such mechanism is utilizing various built-in tricks that gcc and cpp provide. In the server example, a macro called <code>dbg</code> is used, which expands to <code>g_print</code> when the server is built as a non-daemonizing version. If the server becomes a daemon, the macro expands to "nothing", meaning that no code is generated to format the parameters or to even access them. Extending this idea to support multiple levels of debugging is advisable, as is using different "subsystem" identifiers, so that a single subsystem can be switched on or off, depending on the object of the debugging procedure.
The simplest way to debug servers is the intelligent use of print-out of events in the code sections that are relevant. Tracing everything that goes on rarely makes sense, but having a reliable and working infrastructure (in code level) helps. One such mechanism is utilizing various built-in tricks that gcc and cpp provide. In the server example, a macro called <code>dbg</code> is used, which expands to <code>g_print</code> when the server is built as a non-daemonizing version. If the server becomes a daemon, the macro expands to "nothing", meaning that no code is generated to format the parameters or to even access them. Extending this idea to support multiple levels of debugging is advisable, as is using different "subsystem" identifiers, so that a single subsystem can be switched on or off, depending on the object of the debugging procedure.
-
The <code>dbg</code> macro utilizes the <code>__func__</code> symbol, which expands to the function name where the macro is expanded. This is quite useful because the function name does not need to be explicitly added: [http://vcs.maemo.org/svn/maemoexamples/trunk/glib-dbus-sync/server.c glib-dbus-sync/server.c]
+
The <code>dbg</code> macro utilizes the <code>__func__</code> symbol, which expands to the function name where the macro is expanded. This is quite useful because the function name does not need to be explicitly added: glib-dbus-sync/server.c
<source lang="c">
<source lang="c">
Line 171: Line 171:
</source>
</source>
-
Using the macro is quite simple, as it looks and acts like a regular printf-formatting function (<code>g_print</code> included): [http://vcs.maemo.org/svn/maemoexamples/trunk/glib-dbus-sync/server.c glib-dbus-sync/server.c]
+
Using the macro is quite simple, as it looks and acts like a regular printf-formatting function (<code>g_print</code> included): glib-dbus-sync/server.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)