Imported Upstream version 1.7.1
[platform/upstream/edbus.git] / src / bin / async_client_test.c
1 #ifdef HAVE_CONFIG_H
2 #include "config.h"
3 #endif
4
5 #include <Ecore.h>
6 #include "E_DBus.h"
7
8 #define DBUS_NAME "com.profusion"
9 #define OBJECT_PATH "/com/profusion/test"
10 #define IFACE_NAME "com.Profusion.Test"
11
12 static E_DBus_Connection *conn = NULL;
13
14 static void
15 _cb_resp(void *data, DBusMessage *msg, DBusError *error)
16 {
17    DBusError new_error;
18    int size;
19
20    if (dbus_error_is_set(error))
21      {
22         printf("dbus error\nName: %s\nDescription: %s\n", error->name,
23                error->message);
24         ecore_main_loop_quit();
25         return;
26      }
27
28    dbus_error_init(&new_error);
29    dbus_message_get_args(msg, &new_error, DBUS_TYPE_INT32, &size,
30                          DBUS_TYPE_INVALID);
31    if (dbus_error_is_set(&new_error))
32      printf("dbus error\nName: %s\nDescription: %s\n", new_error.name,
33             new_error.message);
34    else printf("size = %d\n", size);
35
36    ecore_main_loop_quit();
37 }
38
39 int
40 main(int argc, char *argv[])
41 {
42    char *string = "lalala";
43    DBusMessage *msg;
44
45    e_dbus_init();
46    conn = e_dbus_bus_get(DBUS_BUS_SESSION);
47
48    msg = dbus_message_new_method_call(DBUS_NAME, OBJECT_PATH,
49                                       IFACE_NAME, "string_len_async");
50    dbus_message_append_args(msg, DBUS_TYPE_STRING, &string, DBUS_TYPE_INVALID);
51    e_dbus_message_send(conn, msg, _cb_resp, -1, NULL);
52    dbus_message_unref(msg);
53
54    ecore_main_loop_begin();
55
56    e_dbus_shutdown();
57    return 0;
58 }