summaryrefslogtreecommitdiffstats
path: root/glib/test-thread-client.c
diff options
context:
space:
mode:
authorAlexander Larsson <alexl@redhat.com>2003-02-26 15:52:25 +0000
committerAlexander Larsson <alexl@redhat.com>2003-02-26 15:52:25 +0000
commit89e6dfd29cfbdb92f15e8fb2bde76d94a4c5a7b3 (patch)
tree501540fab4797ab07a4f90e239ac6dabb5bec38d /glib/test-thread-client.c
parent7265423411609c14ddb9e6643463b840afcaa09b (diff)
2003-02-26 Alexander Larsson <alexl@redhat.com>
* configure.in: Set DBUS_GLIB_THREADS_LIBS for apps using gthread-2.0 * dbus/dbus-connection.c: * dbus/dbus-connection.h: Fix _dbus_connection_acquire_io_path and _dbus_connection_acquire_dispatch. Add dbus_connection_set_wakeup_main_function and use it when queueing incoming and outgoing messages. * dbus/dbus-dataslot.c: Threadsafe usage of DBusDataSlotAllocator * dbus/dbus-message.c: (dbus_message_get_args_iter): dbus_new can fail. * dbus/dbus-server-unix.c: Add todo comment * glib/dbus-gmain.c: Implement the new wakeup functions for glib. * glib/Makefile.am: * glib/test-thread-client.c: * glib/test-thread-server.c: * glib/test-thread.h: Initial cut at some thread test code. Not really done yet.
Diffstat (limited to 'glib/test-thread-client.c')
-rw-r--r--glib/test-thread-client.c89
1 files changed, 89 insertions, 0 deletions
diff --git a/glib/test-thread-client.c b/glib/test-thread-client.c
new file mode 100644
index 00000000..ca78dbb8
--- /dev/null
+++ b/glib/test-thread-client.c
@@ -0,0 +1,89 @@
+#include <glib.h>
+#include "dbus-glib.h"
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "test-thread.h"
+
+DBusConnection *connection;
+
+static gpointer
+thread_func (gpointer data)
+{
+ gint32 threadnr = GPOINTER_TO_INT (data);
+ guint32 counter = 0;
+ DBusMessage *message;
+ char *str;
+
+ while (1)
+ {
+ message = dbus_message_new (NULL, "org.freedesktop.ThreadTest");
+
+ if (!dbus_message_append_int32 (message, threadnr))
+ {
+ g_print ("thread %d: append threadnr failed\n", threadnr);
+ }
+
+ if (!dbus_message_append_uint32 (message, counter))
+ {
+ g_print ("thread %d: append counter (%d) failed\n", threadnr, counter);
+ }
+
+ str = g_strdup_printf ("Thread %d-%d\n", threadnr, counter);
+ if (!dbus_message_append_string (message, str))
+ {
+ g_print ("thread %d: append string (%s) failed\n", threadnr, str);
+ }
+ g_free (str);
+
+ if (!dbus_connection_send_message (connection,
+ message,
+ NULL, NULL))
+ {
+ g_print ("thread %d: send message failerd\n", threadnr);
+ }
+ dbus_message_unref (message);
+
+ counter ++;
+ }
+
+ return NULL;
+}
+
+int
+main (int argc, char *argv[])
+{
+ GMainLoop *loop;
+ DBusResultCode result;
+ int i;
+
+ g_thread_init (NULL);
+ dbus_gthread_init ();
+
+ if(argc < 2)
+ {
+ g_error("Need an address as argv[1]\n");
+ return 1;
+ }
+
+ connection = dbus_connection_open (argv[1], &result);
+ if (connection == NULL)
+ {
+ g_printerr ("could not open connection\n");
+ return 1;
+ }
+
+ dbus_connection_setup_with_g_main (connection);
+
+ for (i = 0; i < N_TEST_THREADS; i++)
+ {
+ g_thread_create (thread_func, GINT_TO_POINTER (i), FALSE, NULL);
+ }
+
+ loop = g_main_loop_new (NULL, FALSE);
+ g_main_run (loop);
+
+ return 0;
+}
+