summaryrefslogtreecommitdiff
path: root/test/glib/test-dbus-glib.c
blob: beda0a7a32099a56d60505f267fcdec8f5ac0e9c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/* -*- mode: C; c-file-style: "gnu" -*- */
#include "dbus-glib.h"
#include <stdio.h>

int
main (int argc, char **argv)
{
  DBusConnection *connection;
  DBusMessage *message, *reply;  
  GMainLoop *loop;
  DBusError error;
  
  if (argc < 2)
    {
      g_printerr ("Give the server address as an argument\n");
      return 1;
    }

  loop = g_main_loop_new (NULL, FALSE);

  dbus_error_init (&error);
  connection = dbus_connection_open (argv[1], &error);
  if (connection == NULL)
    {
      g_printerr ("Failed to open connection to %s: %s\n", argv[1],
                  error.message);
      dbus_error_free (&error);
      return 1;
    }

  dbus_connection_setup_with_g_main (connection, NULL);

  message = dbus_message_new_method_call (DBUS_SERVICE_ORG_FREEDESKTOP_DBUS,
                                          DBUS_PATH_ORG_FREEDESKTOP_DBUS,
                                          DBUS_INTERFACE_ORG_FREEDESKTOP_DBUS,
                                          "Hello");

  dbus_error_init (&error);
  reply = dbus_connection_send_with_reply_and_block (connection, message, -1, &error);
  if (reply == NULL)
    {
      g_printerr ("Error on hello message: %s\n", error.message);
      dbus_error_free (&error);
      return 1;
    }
  
  g_print ("reply received\n");
  
  g_main_loop_run (loop);
  
  return 0;
}