Upload Tizen2.0 source
[framework/appfw/aul-1.git] / test / aul_dbus.c
1 /*
2 Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved 
3 PROPRIETARY/CONFIDENTIAL
4 This software is the confidential and proprietary information of 
5 SAMSUNG ELECTRONICS ("Confidential Information"). You agree and acknowledge that 
6 this software is owned by Samsung and you 
7 shall not disclose such Confidential Information and shall 
8 use it only in accordance with the terms of the license agreement 
9 you entered into with SAMSUNG ELECTRONICS.  SAMSUNG make no 
10 representations or warranties about the suitability 
11 of the software, either express or implied, including but not 
12 limited to the implied warranties of merchantability, fitness for 
13 a particular purpose, or non-infringement. 
14 SAMSUNG shall not be liable for any damages suffered by licensee arising out of or 
15 related to this software.
16 */
17
18 #include <glib.h>
19 #include "aul_dbus.h"
20 #include <sys/time.h>
21 #include <stdlib.h>
22
23 #define MAX_LOCAL_BUFSZ 128
24
25 void request_cb(DBusPendingCall *pc, void *user_data)
26 {
27         DBusMessage *reply;
28         DBusError error;
29         char *str;
30
31         reply = dbus_pending_call_steal_reply(pc);
32         dbus_pending_call_unref(pc);
33
34         dbus_error_init(&error);
35
36         if (!dbus_message_get_args(reply, &error,
37                                    DBUS_TYPE_STRING, &str, DBUS_TYPE_INVALID))
38                 _E("Failed to complete call");
39
40         printf("filename = %s\n", str);
41
42         dbus_message_unref(reply);
43
44         exit(0);
45 }
46
47 int main(int argc, char **argv)
48 {
49         DBusConnection *bus;
50         DBusError error;
51         DBusMessage *message;
52         DBusPendingCall *pc;
53         GMainLoop *loop;
54
55         char tmp[MAX_LOCAL_BUFSZ];
56         char *s;
57         struct timeval tv;
58
59         loop = g_main_loop_new(NULL, FALSE);
60
61         dbus_error_init(&error);
62
63         bus = dbus_bus_get(DBUS_BUS_SYSTEM, &error);
64         if (bus == NULL)
65                 _E("Failed to open bus to bus")
66
67                     dbus_connection_setup_with_g_main(bus, NULL);
68
69         message = dbus_message_new_method_call (
70                         SERVICE_NAME,PATH_NAME,INTERFACE_NAME,
71                         METHOD_NAME); 
72
73         gettimeofday(&tv, NULL);
74         snprintf(tmp, MAX_LOCAL_BUFSZ, "%ld/%ld", tv.tv_sec, tv.tv_usec);
75         s = tmp;
76
77         dbus_message_append_args(message,
78                                  DBUS_TYPE_STRING, &s, DBUS_TYPE_INVALID);
79
80         dbus_connection_send_with_reply(bus, message, &pc, INT_MAX);
81         if (!dbus_pending_call_set_notify(pc, request_cb, NULL, NULL))
82                 _E("pending call set fail");
83
84         dbus_message_unref(message);
85
86         printf("wait result\n");
87
88         g_main_loop_run(loop);
89
90         return 0;
91 }
92