tizen 2.4 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 #define _GNU_SOURCE
23 #include <glib.h>
24 #include "aul_dbus.h"
25 #include <sys/time.h>
26 #include <stdlib.h>
27
28 #define MAX_LOCAL_BUFSZ 128
29
30 void request_cb(DBusPendingCall *pc, void *user_data)
31 {
32         DBusMessage *reply;
33         DBusError error;
34         char *str;
35
36         reply = dbus_pending_call_steal_reply(pc);
37         dbus_pending_call_unref(pc);
38
39         dbus_error_init(&error);
40
41         if (!dbus_message_get_args(reply, &error,
42                                    DBUS_TYPE_STRING, &str, DBUS_TYPE_INVALID))
43                 _E("Failed to complete call");
44
45         printf("filename = %s\n", str);
46
47         dbus_message_unref(reply);
48
49         exit(0);
50 }
51
52 int main(int argc, char **argv)
53 {
54         DBusConnection *bus;
55         DBusError error;
56         DBusMessage *message;
57         DBusPendingCall *pc;
58         GMainLoop *loop;
59         dbus_bool_t ret;
60
61         char tmp[MAX_LOCAL_BUFSZ];
62         char *s;
63         struct timeval tv;
64
65         loop = g_main_loop_new(NULL, FALSE);
66
67         dbus_error_init(&error);
68
69         bus = dbus_bus_get(DBUS_BUS_SYSTEM, &error);
70         if (bus == NULL)
71                 _E("Failed to open bus to bus")
72
73                     dbus_connection_setup_with_g_main(bus, NULL);
74
75         message = dbus_message_new_method_call (
76                         SERVICE_NAME,PATH_NAME,INTERFACE_NAME,
77                         METHOD_NAME);
78
79         gettimeofday(&tv, NULL);
80         snprintf(tmp, MAX_LOCAL_BUFSZ, "%ld/%ld", tv.tv_sec, tv.tv_usec);
81         s = tmp;
82
83         dbus_message_append_args(message,
84                                  DBUS_TYPE_STRING, &s, DBUS_TYPE_INVALID);
85
86         ret = dbus_connection_send_with_reply(bus, message, &pc, INT_MAX);
87         if (!ret) {
88                 _E("dbus_connection_send_with_reply() failed.");
89                 dbus_message_unref(message);
90                 return -1;
91         }
92         if (!dbus_pending_call_set_notify(pc, request_cb, NULL, NULL))
93                 _E("pending call set fail");
94
95         dbus_message_unref(message);
96
97         printf("wait result\n");
98
99         g_main_loop_run(loop);
100
101         return 0;
102 }
103