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.
25 #define MAX_LOCAL_BUFSZ 128
27 gboolean result_func(gpointer data)
37 dbus_error_init(&error);
39 bus = dbus_bus_get(DBUS_BUS_SYSTEM, &error);
41 reply = dbus_message_new_method_return(msg);
42 dbus_message_unref(msg);
45 dbus_message_append_args(reply, DBUS_TYPE_STRING,
46 &str, DBUS_TYPE_INVALID);
48 dbus_connection_send(bus, reply, NULL);
49 dbus_message_unref(reply);
54 void create_take_picture_ui(DBusMessage *msg)
56 /* simulate, take photo and save time is 30 sec.*/
57 g_timeout_add(5 * 1000, result_func, msg);
60 static DBusHandlerResult
61 dbus_handler(DBusConnection *connection,
62 DBusMessage *message, void *user_data)
71 if (dbus_message_is_method_call(message, INTERFACE_NAME, METHOD_NAME)) {
72 dbus_error_init(&error);
73 msg = dbus_message_ref(message);
75 if (dbus_message_get_args
76 (message, &error, DBUS_TYPE_STRING, &s,
78 sscanf(s, "%ld/%ld", &tv.tv_sec, &tv.tv_usec);
79 gettimeofday(&cur, NULL);
80 timersub(&cur, &tv, &res);
81 printf("=================================\n");
82 printf("launched time = %ld sec %ld msec\n", res.tv_sec,
84 printf("=================================\n");
86 create_take_picture_ui(msg);
87 return DBUS_HANDLER_RESULT_HANDLED;
89 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
92 static int init_dbus()
96 char rules[MAX_LOCAL_BUFSZ];
98 dbus_error_init(&error);
100 bus = dbus_bus_get(DBUS_BUS_SYSTEM, &error);
102 _E("couldn't access session bus");
104 dbus_connection_setup_with_g_main(bus, NULL);
106 dbus_bus_request_name(bus, SERVICE_NAME, 0, &error);
107 if (dbus_error_is_set(&error))
108 _E("couldn't request name");
110 snprintf(rules, MAX_LOCAL_BUFSZ,
111 "path='%s',type='method_call',interface='%s'",
112 PATH_NAME, INTERFACE_NAME);
113 dbus_bus_add_match(bus, rules, &error);
115 if (!dbus_connection_add_filter(bus, dbus_handler, NULL, NULL))
116 _E("couldn't add filter");
121 static int aul_handler(aul_type type, bundle *kb, void *data)
130 printf("app start & add dbus\n");
131 tmp = bundle_get_val(kb, AUL_K_STARTTIME);
133 sscanf(tmp, "%ld/%ld", &tv.tv_sec, &tv.tv_usec);
134 gettimeofday(&cur, NULL);
135 timersub(&cur, &tv, &res);
136 printf("=================================\n");
137 printf("launched time by aul= %ld sec %ld msec\n",
138 res.tv_sec, res.tv_usec / 1000);
139 printf("=================================\n");
141 /* DONOT draw if auto-activated by dbus */
153 int main(int argc, char *argv[])
157 loop = g_main_loop_new(NULL, FALSE);
159 aul_launch_init(aul_handler, NULL);
160 aul_launch_argv_handler(argc, argv);
162 g_main_loop_run(loop);