<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"> <title>test-thread-client.c Source File</title> <link href="doxygen.css" rel="stylesheet" type="text/css"> </head><body> <!-- Generated by Doxygen 1.2.15 --> <center> <a class="qindex" href="index.html">Main Page</a> <a class="qindex" href="modules.html">Modules</a> <a class="qindex" href="annotated.html">Data Structures</a> <a class="qindex" href="files.html">File List</a> <a class="qindex" href="functions.html">Data Fields</a> <a class="qindex" href="pages.html">Related Pages</a> </center> <hr><h1>test-thread-client.c</h1><div class="fragment"><pre>00001 <font class="preprocessor">#include <glib.h></font> 00002 <font class="preprocessor">#include "dbus-glib.h"</font> 00003 <font class="preprocessor">#include <stdio.h></font> 00004 <font class="preprocessor">#include <string.h></font> 00005 <font class="preprocessor">#include <unistd.h></font> 00006 00007 <font class="preprocessor">#include "test-thread.h"</font> 00008 00009 <a class="code" href="structDBusConnection.html">DBusConnection</a> *connection; 00010 00011 <font class="keyword">static</font> gpointer 00012 thread_func (gpointer data) 00013 { 00014 gint32 threadnr = GPOINTER_TO_INT (data); 00015 guint32 counter = 0; 00016 <a class="code" href="structDBusMessageIter.html">DBusMessageIter</a> iter; 00017 <a class="code" href="structDBusMessage.html">DBusMessage</a> *message; 00018 <font class="keywordtype">char</font> *str; 00019 00020 <font class="keywordflow">while</font> (1) 00021 { 00022 message = dbus_message_new (<font class="stringliteral">"org.freedesktop.ThreadTest"</font>, NULL); 00023 00024 dbus_message_append_iter_init (message, &iter); 00025 00026 <font class="keywordflow">if</font> (!dbus_message_iter_append_int32 (&iter, threadnr)) 00027 { 00028 g_print (<font class="stringliteral">"thread %d: append threadnr failed\n"</font>, threadnr); 00029 } 00030 00031 <font class="keywordflow">if</font> (!dbus_message_iter_append_uint32 (&iter, counter)) 00032 { 00033 g_print (<font class="stringliteral">"thread %d: append counter (%d) failed\n"</font>, threadnr, counter); 00034 } 00035 00036 str = g_strdup_printf (<font class="stringliteral">"Thread %d-%d\n"</font>, threadnr, counter); 00037 <font class="keywordflow">if</font> (!dbus_message_iter_append_string (&iter, str)) 00038 { 00039 g_print (<font class="stringliteral">"thread %d: append string (%s) failed\n"</font>, threadnr, str); 00040 } 00041 g_free (str); 00042 00043 <font class="keywordflow">if</font> (!dbus_connection_send (connection, 00044 message, 00045 NULL)) 00046 { 00047 g_print (<font class="stringliteral">"thread %d: send message failed\n"</font>, threadnr); 00048 } 00049 00050 dbus_message_unref (message); 00051 00052 counter ++; 00053 } 00054 00055 <font class="keywordflow">return</font> NULL; 00056 } 00057 00058 <font class="keywordtype">int</font> 00059 main (<font class="keywordtype">int</font> argc, <font class="keywordtype">char</font> *argv[]) 00060 { 00061 GMainLoop *loop; 00062 <a class="code" href="structDBusError.html">DBusError</a> error; 00063 <font class="keywordtype">int</font> i; 00064 00065 g_thread_init (NULL); 00066 dbus_gthread_init (); 00067 00068 <font class="keywordflow">if</font>(argc < 2) 00069 { 00070 g_error(<font class="stringliteral">"Need an address as argv[1]\n"</font>); 00071 <font class="keywordflow">return</font> 1; 00072 } 00073 00074 dbus_error_init (&error); 00075 connection = dbus_connection_open (argv[1], &error); 00076 <font class="keywordflow">if</font> (connection == NULL) 00077 { 00078 g_printerr (<font class="stringliteral">"could not open connection: %s\n"</font>, error.<a class="code" href="structDBusError.html#m1">message</a>); 00079 dbus_error_free (&error); 00080 <font class="keywordflow">return</font> 1; 00081 } 00082 00083 dbus_connection_setup_with_g_main (connection, NULL); 00084 00085 <font class="keywordflow">for</font> (i = 0; i < N_TEST_THREADS; i++) 00086 { 00087 g_thread_create (thread_func, GINT_TO_POINTER (i), FALSE, NULL); 00088 } 00089 00090 loop = g_main_loop_new (NULL, FALSE); 00091 g_main_run (loop); 00092 00093 <font class="keywordflow">return</font> 0; 00094 } 00095 </pre></div><hr><address align="right"><small>Generated on Wed Jun 2 06:01:34 2004 for D-BUS by <a href="http://www.doxygen.org/index.html"> <img src="doxygen.png" alt="doxygen" align="middle" border=0 width=110 height=53></a>1.2.15 </small></address> </body> </html>