tizen beta release
[framework/appfw/aul-1.git] / test / aul_dbus.c
1 /*
2  *  aul
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>, Jaeho Lee <jaeho81.lee@samsung.com>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  */
21
22 #include <glib.h>
23 #include "aul_dbus.h"
24 #include <sys/time.h>
25 #include <stdlib.h>
26
27 #define MAX_LOCAL_BUFSZ 128
28
29 void request_cb(DBusPendingCall *pc, void *user_data)
30 {
31         DBusMessage *reply;
32         DBusError error;
33         char *str;
34
35         reply = dbus_pending_call_steal_reply(pc);
36         dbus_pending_call_unref(pc);
37
38         dbus_error_init(&error);
39
40         if (!dbus_message_get_args(reply, &error,
41                                    DBUS_TYPE_STRING, &str, DBUS_TYPE_INVALID))
42                 _E("Failed to complete call");
43
44         printf("filename = %s\n", str);
45
46         dbus_message_unref(reply);
47
48         exit(0);
49 }
50
51 int main(int argc, char **argv)
52 {
53         DBusConnection *bus;
54         DBusError error;
55         DBusMessage *message;
56         DBusPendingCall *pc;
57         GMainLoop *loop;
58
59         char tmp[MAX_LOCAL_BUFSZ];
60         char *s;
61         struct timeval tv;
62
63         loop = g_main_loop_new(NULL, FALSE);
64
65         dbus_error_init(&error);
66
67         bus = dbus_bus_get(DBUS_BUS_SYSTEM, &error);
68         if (bus == NULL)
69                 _E("Failed to open bus to bus")
70
71                     dbus_connection_setup_with_g_main(bus, NULL);
72
73         message = dbus_message_new_method_call (
74                         SERVICE_NAME,PATH_NAME,INTERFACE_NAME,
75                         METHOD_NAME); 
76
77         gettimeofday(&tv, NULL);
78         snprintf(tmp, MAX_LOCAL_BUFSZ, "%ld/%ld", tv.tv_sec, tv.tv_usec);
79         s = tmp;
80
81         dbus_message_append_args(message,
82                                  DBUS_TYPE_STRING, &s, DBUS_TYPE_INVALID);
83
84         dbus_connection_send_with_reply(bus, message, &pc, INT_MAX);
85         if (!dbus_pending_call_set_notify(pc, request_cb, NULL, NULL))
86                 _E("pending call set fail");
87
88         dbus_message_unref(message);
89
90         printf("wait result\n");
91
92         g_main_loop_run(loop);
93
94         return 0;
95 }
96