4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>, Jaeho Lee <jaeho81.lee@samsung.com>
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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.
29 #include <bundle_internal.h>
31 #define MAX_LOCAL_BUFSZ 128
33 gboolean result_func(gpointer data)
43 dbus_error_init(&error);
45 bus = dbus_bus_get(DBUS_BUS_SYSTEM, &error);
47 reply = dbus_message_new_method_return(msg);
48 dbus_message_unref(msg);
51 dbus_message_append_args(reply, DBUS_TYPE_STRING,
52 &str, DBUS_TYPE_INVALID);
54 if (dbus_connection_send(bus, reply, NULL) == FALSE)
55 _E("Failed to reply");
57 dbus_message_unref(reply);
62 void create_take_picture_ui(DBusMessage *msg)
64 /* simulate, take photo and save time is 30 sec.*/
65 g_timeout_add(5 * 1000, result_func, msg);
68 static DBusHandlerResult
69 dbus_handler(DBusConnection *connection,
70 DBusMessage *message, void *user_data)
79 if (dbus_message_is_method_call(message, INTERFACE_NAME, METHOD_NAME)) {
80 dbus_error_init(&error);
81 msg = dbus_message_ref(message);
83 if (dbus_message_get_args
84 (message, &error, DBUS_TYPE_STRING, &s,
86 sscanf(s, "%ld/%ld", &tv.tv_sec, &tv.tv_usec);
87 gettimeofday(&cur, NULL);
88 timersub(&cur, &tv, &res);
89 printf("=================================\n");
90 printf("launched time = %ld sec %ld msec\n", res.tv_sec,
92 printf("=================================\n");
94 create_take_picture_ui(msg);
95 return DBUS_HANDLER_RESULT_HANDLED;
97 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
100 static int init_dbus()
104 char rules[MAX_LOCAL_BUFSZ];
106 dbus_error_init(&error);
108 bus = dbus_bus_get(DBUS_BUS_SYSTEM, &error);
110 _E("couldn't access session bus");
112 dbus_connection_setup_with_g_main(bus, NULL);
114 dbus_bus_request_name(bus, SERVICE_NAME, 0, &error);
115 if (dbus_error_is_set(&error))
116 _E("couldn't request name");
118 snprintf(rules, MAX_LOCAL_BUFSZ,
119 "path='%s',type='method_call',interface='%s'",
120 PATH_NAME, INTERFACE_NAME);
121 dbus_bus_add_match(bus, rules, &error);
123 if (!dbus_connection_add_filter(bus, dbus_handler, NULL, NULL))
124 _E("couldn't add filter");
129 static int aul_handler(aul_type type, bundle *kb, void *data)
138 printf("app start & add dbus\n");
139 tmp = bundle_get_val(kb, AUL_K_STARTTIME);
141 sscanf(tmp, "%ld/%ld", &tv.tv_sec, &tv.tv_usec);
142 gettimeofday(&cur, NULL);
143 timersub(&cur, &tv, &res);
144 printf("=================================\n");
145 printf("launched time by aul= %ld sec %ld msec\n",
146 res.tv_sec, res.tv_usec / 1000);
147 printf("=================================\n");
149 /* DONOT draw if auto-activated by dbus */
163 int main(int argc, char *argv[])
167 loop = g_main_loop_new(NULL, FALSE);
169 if (aul_launch_init(aul_handler, NULL) != AUL_R_OK)
172 if (aul_launch_argv_handler(argc, argv) < 0)
175 g_main_loop_run(loop);