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 #define MAX_LOCAL_BUFSZ 128
31 gboolean result_func(gpointer data)
41 dbus_error_init(&error);
43 bus = dbus_bus_get(DBUS_BUS_SYSTEM, &error);
45 reply = dbus_message_new_method_return(msg);
46 dbus_message_unref(msg);
49 dbus_message_append_args(reply, DBUS_TYPE_STRING,
50 &str, DBUS_TYPE_INVALID);
52 dbus_connection_send(bus, reply, NULL);
53 dbus_message_unref(reply);
58 void create_take_picture_ui(DBusMessage *msg)
60 /* simulate, take photo and save time is 30 sec.*/
61 g_timeout_add(5 * 1000, result_func, msg);
64 static DBusHandlerResult
65 dbus_handler(DBusConnection *connection,
66 DBusMessage *message, void *user_data)
75 if (dbus_message_is_method_call(message, INTERFACE_NAME, METHOD_NAME)) {
76 dbus_error_init(&error);
77 msg = dbus_message_ref(message);
79 if (dbus_message_get_args
80 (message, &error, DBUS_TYPE_STRING, &s,
82 sscanf(s, "%ld/%ld", &tv.tv_sec, &tv.tv_usec);
83 gettimeofday(&cur, NULL);
84 timersub(&cur, &tv, &res);
85 printf("=================================\n");
86 printf("launched time = %ld sec %ld msec\n", res.tv_sec,
88 printf("=================================\n");
90 create_take_picture_ui(msg);
91 return DBUS_HANDLER_RESULT_HANDLED;
93 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
96 static int init_dbus()
100 char rules[MAX_LOCAL_BUFSZ];
102 dbus_error_init(&error);
104 bus = dbus_bus_get(DBUS_BUS_SYSTEM, &error);
106 _E("couldn't access session bus");
108 dbus_connection_setup_with_g_main(bus, NULL);
110 dbus_bus_request_name(bus, SERVICE_NAME, 0, &error);
111 if (dbus_error_is_set(&error))
112 _E("couldn't request name");
114 snprintf(rules, MAX_LOCAL_BUFSZ,
115 "path='%s',type='method_call',interface='%s'",
116 PATH_NAME, INTERFACE_NAME);
117 dbus_bus_add_match(bus, rules, &error);
119 if (!dbus_connection_add_filter(bus, dbus_handler, NULL, NULL))
120 _E("couldn't add filter");
125 static int aul_handler(aul_type type, bundle *kb, void *data)
134 printf("app start & add dbus\n");
135 tmp = bundle_get_val(kb, AUL_K_STARTTIME);
137 sscanf(tmp, "%ld/%ld", &tv.tv_sec, &tv.tv_usec);
138 gettimeofday(&cur, NULL);
139 timersub(&cur, &tv, &res);
140 printf("=================================\n");
141 printf("launched time by aul= %ld sec %ld msec\n",
142 res.tv_sec, res.tv_usec / 1000);
143 printf("=================================\n");
145 /* DONOT draw if auto-activated by dbus */
157 int main(int argc, char *argv[])
161 loop = g_main_loop_new(NULL, FALSE);
163 aul_launch_init(aul_handler, NULL);
164 aul_launch_argv_handler(argc, argv);
166 g_main_loop_run(loop);