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 "simple_util.h"
31 #include <bundle_internal.h>
35 static gboolean __aul_glib_check(GSource *src);
36 static gboolean __aul_glib_dispatch(GSource *src, GSourceFunc callback,
38 static gboolean __aul_glib_prepare(GSource *src, gint *timeout);
39 static gboolean __app_start_internal(gpointer data);
41 static void __aul_glib_finalize(GSource *src)
46 fd_list = src->poll_fds;
48 tmp = (GPollFD *) fd_list->data;
51 fd_list = fd_list->next;
57 static gboolean __aul_glib_check(GSource *src)
62 fd_list = src->poll_fds;
64 tmp = (GPollFD *) fd_list->data;
65 if ((tmp->revents & (POLLIN | POLLPRI)))
67 fd_list = fd_list->next;
73 static gboolean __aul_glib_dispatch(GSource *src, GSourceFunc callback,
80 static gboolean __aul_glib_prepare(GSource *src, gint *timeout)
85 GSourceFuncs funcs = {
86 .prepare = __aul_glib_prepare,
87 .check = __aul_glib_check,
88 .dispatch = __aul_glib_dispatch,
89 .finalize = __aul_glib_finalize
92 gboolean __aul_glib_handler(gpointer data)
94 GPollFD *gpollfd = (GPollFD *) data;
95 aul_sock_handler(gpollfd->fd);
99 static gboolean __app_start_internal(gpointer data)
103 kb = (bundle *) data;
110 SLPAPI int aul_launch_init(
111 int (*aul_handler) (aul_type type, bundle *, void *), void *data)
117 if (aul_handler != NULL)
118 aul_register_init_callback(aul_handler, data);
120 fd = aul_initialize();
124 src = g_source_new(&funcs, sizeof(GSource));
126 gpollfd = (GPollFD *) g_malloc(sizeof(GPollFD));
127 if (gpollfd == NULL) {
132 gpollfd->events = POLLIN;
135 g_source_add_poll(src, gpollfd);
136 g_source_set_callback(src, (GSourceFunc) __aul_glib_handler,
137 (gpointer) gpollfd, NULL);
138 g_source_set_priority(src, G_PRIORITY_DEFAULT);
140 ret = g_source_attach(src, NULL);
149 SLPAPI int aul_launch_fini()
151 g_source_destroy(src);
155 SLPAPI int aul_launch_argv_handler(int argc, char **argv)
159 if (!aul_is_initialized())
160 return AUL_R_ENOINIT;
162 b = bundle_import_from_argv(argc, argv);
164 _E("bundle for APP_START is NULL");
166 if (g_idle_add_full(G_PRIORITY_DEFAULT, __app_start_internal, b, NULL) > 0)
169 _E("g_idle_add_full() failed.");
174 SLPAPI int aul_launch_argv_handler_for_efl(int argc, char **argv)
178 Ecore_Idler *idler = NULL;
180 if (!aul_is_initialized())
181 return AUL_R_ENOINIT;
183 b = bundle_import_from_argv(argc, argv);
185 _E("bundle for APP_START is NULL");
188 idler = ecore_idler_add((Ecore_Task_Cb)__app_start_internal, b);
195 SLPAPI int aul_launch_local(bundle *b)
197 if (!aul_is_initialized())
198 return AUL_R_ENOINIT;
201 _E("bundle for APP_START is NULL");
203 if (g_idle_add(__app_start_internal, b) > 0)