2003-09-03 Havoc Pennington <hp@pobox.com>
[platform/upstream/dbus.git] / test / glib / test-dbus-glib.c
1 /* -*- mode: C; c-file-style: "gnu" -*- */
2 #include "dbus-glib.h"
3 #include <stdio.h>
4
5 int
6 main (int argc, char **argv)
7 {
8   DBusConnection *connection;
9   DBusMessage *message, *reply;  
10   GMainLoop *loop;
11   DBusError error;
12   
13   if (argc < 2)
14     {
15       g_printerr ("Give the server address as an argument\n");
16       return 1;
17     }
18
19   loop = g_main_loop_new (NULL, FALSE);
20
21   dbus_error_init (&error);
22   connection = dbus_connection_open (argv[1], &error);
23   if (connection == NULL)
24     {
25       g_printerr ("Failed to open connection to %s: %s\n", argv[1],
26                   error.message);
27       dbus_error_free (&error);
28       return 1;
29     }
30
31   dbus_connection_setup_with_g_main (connection, NULL);
32
33   message = dbus_message_new_method_call (DBUS_SERVICE_ORG_FREEDESKTOP_DBUS,
34                                           DBUS_PATH_ORG_FREEDESKTOP_DBUS,
35                                           DBUS_INTERFACE_ORG_FREEDESKTOP_DBUS,
36                                           "Hello");
37
38   dbus_error_init (&error);
39   reply = dbus_connection_send_with_reply_and_block (connection, message, -1, &error);
40   if (reply == NULL)
41     {
42       g_printerr ("Error on hello message: %s\n", error.message);
43       dbus_error_free (&error);
44       return 1;
45     }
46   
47   g_print ("reply received\n");
48   
49   g_main_loop_run (loop);
50   
51   return 0;
52 }