Remove unneeded re-definition of EAPI
[framework/uifw/edbus.git] / src / bin / test.c
1 #ifdef HAVE_CONFIG_H
2 #include "config.h"
3 #endif
4
5 #ifdef _WIN32
6 # define DBUS_API_SUBJECT_TO_CHANGE
7 #endif
8
9 #include <stdio.h>
10 #include <string.h>
11
12 #include <Ecore.h>
13
14 #include "E_DBus.h"
15
16 void
17 copy_message(DBusMessageIter *from, DBusMessageIter *to)
18 {
19   int type;
20   printf("  copy message\n");
21   while((type = dbus_message_iter_get_arg_type(from)) != DBUS_TYPE_INVALID)
22   {
23     printf("  copy type: %c\n", type);
24     if (dbus_type_is_basic(type))
25     {
26       /* XXX is int64 big enough to hold all basic types? */
27       dbus_int64_t val;
28       dbus_message_iter_get_basic(from, &val);
29       dbus_message_iter_append_basic(to, type, &val);
30     }
31     else if (dbus_type_is_container(type))
32     {
33       int subtype;
34
35       subtype = dbus_message_iter_get_element_type(from);
36       if (type == DBUS_TYPE_ARRAY && dbus_type_is_fixed(subtype))
37       {
38         int n;
39         void *val;
40         dbus_message_iter_get_fixed_array(from, &val, &n);
41         dbus_message_iter_append_fixed_array(to, subtype, val, n);
42       }
43       else
44       {
45         DBusMessageIter fsub, tsub;
46         char *sig;
47         dbus_message_iter_recurse(from, &fsub);
48         sig = dbus_message_iter_get_signature(&fsub);
49         dbus_message_iter_open_container(to, type, sig, &tsub);
50         copy_message(&fsub, &tsub);
51         dbus_message_iter_close_container(to, &tsub);
52       }
53     }
54     dbus_message_iter_next(from);
55   }
56 }
57
58 DBusMessage *
59 cb_repeat(E_DBus_Object *obj __UNUSED__, DBusMessage *msg)
60 {
61   DBusMessage *reply;
62   DBusMessageIter from, to;
63
64   printf("\n\nREPEAT\n--------\n");
65   reply = dbus_message_new_method_return(msg);
66   dbus_message_iter_init(msg, &from);
67   dbus_message_iter_init_append(reply, &to);
68
69   copy_message(&from, &to);
70   return reply;
71 }
72
73 void
74 cb_request_name(void *data __UNUSED__, DBusMessage *msg __UNUSED__, DBusError *err __UNUSED__)
75 {
76   // XXX check that this actually succeeded and handle errors...
77   printf("request name\n");
78 }
79
80 int
81 _setup(E_DBus_Connection *conn)
82 {
83   E_DBus_Object *repeater;
84   E_DBus_Interface *iface;
85   e_dbus_request_name(conn, "org.e.Repeater", 0, cb_request_name, NULL);
86   repeater = e_dbus_object_add(conn, "/org/e/Repeater", NULL);
87   iface = e_dbus_interface_new("org.e.Repeater");
88   e_dbus_interface_method_add(iface, "Repeat", NULL, NULL, cb_repeat);
89   e_dbus_object_interface_attach(repeater, iface);
90   return 1;
91 }
92
93 int
94 main ()
95 {
96   E_DBus_Connection *conn;
97   ecore_init();
98   e_dbus_init();
99
100   conn = e_dbus_bus_get(DBUS_BUS_SESSION);
101  
102   if (conn)
103   {
104     if (_setup(conn)) ecore_main_loop_begin();
105     e_dbus_connection_close(conn);
106   }
107
108   e_dbus_shutdown();
109   ecore_shutdown();
110
111   return 0;
112 }