2 * Copyright (c) 2013, TOYOTA MOTOR CORPORATION.
4 * This program is licensed under the terms and conditions of the
5 * Apache License, version 2.0. The full text of the Apache License is at
6 * http://www.apache.org/licenses/LICENSE-2.0
10 * @brief user experience library for HomeScreen
21 #include "wayland-client.h"
22 #include "wayland-util.h"
23 #include "ico_uxf.h" /* UX-FW open definition header */
24 #include "ico_uxf_private.h" /* UX-FW inner definition header */
25 #include "ico_uxf_conf.h"
27 /* valiable & table */
28 /* UX-FW API inner management table */
29 extern Ico_Uxf_Api_Mng gIco_Uxf_Api_Mng;
32 /*--------------------------------------------------------------------------*/
34 * @brief ico_uxf_process_execute: launch a program
36 * @param[in] name program name
38 * @retval ICO_UXF_EOK success
39 * @retval ICO_UXF_ESRCH error(not initialized)
40 * @retval ICO_UXF_ENOENT error(does not exist)
41 * @retval ICO_UXF_EBUSY error(already launch)
42 * @retval ICO_UXF_EPERM error(no authority)
44 /*--------------------------------------------------------------------------*/
46 ico_uxf_process_execute(const char *name)
48 Ico_Uxf_Mng_Process *proc; /* process management table */
50 bundle *appBundle = NULL;
51 Ico_Uxf_conf_application *apptbl = NULL;
53 uifw_trace("ico_uxf_process_execute: Enter(%s)", name);
55 if (gIco_Uxf_Api_Mng.Initialized <= 0) {
56 uifw_warn("ico_uxf_process_execute: Leave(ESRCH)");
60 for (hash = 0; hash < ICO_UXF_MISC_HASHSIZE; hash++) {
61 proc = gIco_Uxf_Api_Mng.Hash_ProcessId[hash];
63 if (strcasecmp(proc->attr.process, name) == 0) break;
64 proc = proc->nextidhash;
70 uifw_warn("ico_uxf_process_execute: Leave(ENOENT)");
71 return ICO_UXF_ENOENT;
74 ico_uxf_enter_critical(); /* enter critical section */
76 if (proc->attr.status != ICO_UXF_PROCSTATUS_STOP) {
77 ico_uxf_leave_critical(); /* leave critical section */
78 uifw_warn("ico_uxf_process_execute: Leave(EBUSY)");
82 /* in order to avoid double execute, status set starting */
83 proc->attr.status = ICO_UXF_PROCSTATUS_INIT;
84 ico_uxf_leave_critical(); /* leave critical section */
87 appBundle = bundle_create();
88 apptbl = (Ico_Uxf_conf_application *)ico_uxf_getAppByAppid(name);
89 if ((appBundle != NULL) && (apptbl != NULL)) {
90 char *opt = strdup(apptbl->exec);
91 char *str = strtok(opt, " ");
93 str = strtok(NULL, " ");
95 bundle_add(appBundle, str, "Application");
96 uifw_trace("ico_uxf_process_execute: option(%s)", str);
102 /* execute program */
103 proc->attr.internalid = aul_launch_app(name ,appBundle);
104 if (appBundle != NULL) {
105 bundle_free(appBundle);
107 if (proc->attr.internalid < 0) {
108 uifw_error("ico_uxf_process_execute: Leave(ENOSYS), Launch App Error(%d)",
109 proc->attr.internalid);
110 return ICO_UXF_ENOSYS;
113 proc->attr.status = ICO_UXF_PROCSTATUS_RUN;
115 uifw_trace("ico_uxf_process_execute: Leave(%s)", proc->attr.process);
119 /*--------------------------------------------------------------------------*/
121 * @brief ico_uxf_process_terminate: finish a program
123 * @param[in] process process id
125 * @retval ICO_UXF_EOK success
126 * @retval ICO_UXF_ESRCH error(not initialized)
127 * @retval ICO_UXF_ENOENT error(does not exist)
128 * @retval ICO_UXF_EAGAIN error(already launch)
129 * @retval ICO_UXF_EPERM error(no authority)
131 /*--------------------------------------------------------------------------*/
133 ico_uxf_process_terminate(const char *process)
135 Ico_Uxf_Mng_Process *proc; /* process management table */
136 int ret; /* process management table */
138 uifw_trace("ico_uxf_process_terminate: Enter(%s)", process);
140 if (gIco_Uxf_Api_Mng.Initialized <= 0) {
141 uifw_warn("ico_uxf_process_terminate: Leave(ESRCH)");
142 return ICO_UXF_ESRCH;
145 /* target is other process */
146 proc = ico_uxf_mng_process(process, 0);
148 uifw_warn("ico_uxf_process_terminate: Leave(ENOENT)");
149 return ICO_UXF_ENOENT;
152 ret = aul_terminate_pid(proc->attr.internalid);
154 uifw_warn("ico_uxf_process_terminate: Leave(ENOSYS) cannot terminate pid=%d",
155 proc->attr.internalid);
156 return ICO_UXF_ENOSYS;
159 proc->attr.status = ICO_UXF_PROCSTATUS_STOP;
160 proc->attr.internalid = -1;
161 proc->attr.mainwin.window = 0;
162 ico_uxf_free_procwin(proc);
164 uifw_trace("ico_uxf_process_terminate: Leave(EOK)");
168 /*--------------------------------------------------------------------------*/
170 * @brief ico_uxf_process_attribute_get: get a process's current state
172 * @param[in] process process's identity
173 * @param[out] attr target process's current state
175 * @retval ICO_UXF_EOK success
176 * @retval ICO_UXF_ESRCH error(not initialized)
177 * @retval ICO_UXF_ENOENT error(does not exist)
178 * @retval ICO_UXF_EPERM error(no authority)
180 /*--------------------------------------------------------------------------*/
182 ico_uxf_process_attribute_get(const char *process, Ico_Uxf_ProcessAttr *attr)
184 Ico_Uxf_Mng_Process *proc; /* process management table */
186 uifw_trace("ico_uxf_process_attribute_get: Enter(%s)", process);
188 if (gIco_Uxf_Api_Mng.Initialized <= 0) {
189 uifw_warn("ico_uxf_process_attribute_get: Leave(ESRCH)");
190 return ICO_UXF_ESRCH;
193 proc = ico_uxf_mng_process(process, 0);
195 uifw_warn("ico_uxf_process_attribute_get: Leave(ENOENT)");
196 return ICO_UXF_ENOENT;
199 memcpy((char *)attr, (char *)&(proc->attr), sizeof(Ico_Uxf_ProcessAttr));
201 uifw_trace("ico_uxf_process_attribute_get: Leave(EOK)");
205 /*--------------------------------------------------------------------------*/
207 * @brief ico_uxf_process_is_active: get application activity
209 * @param[in] process process's identity
211 * @retval 2 process is child process
212 * @retval 1 process is active
213 * @retval 0 process is not active
215 /*--------------------------------------------------------------------------*/
217 ico_uxf_process_is_active(const char *process)
219 Ico_Uxf_Mng_Process *proc; /* process management table */
221 if (gIco_Uxf_Api_Mng.Initialized <= 0) {
222 uifw_warn("ico_uxf_process_is_active: False(ESRCH)");
226 proc = ico_uxf_mng_process(process, 0);
228 uifw_warn("ico_uxf_process_is_active: False(ENOENT)");
232 if (proc->attr.child) {
233 uifw_trace("ico_uxf_process_is_active: %s is Child", process);
236 uifw_trace("ico_uxf_process_is_active: %s is %s",
237 process, proc->attr.active ? "Active" : "Inactive");
238 return proc->attr.active;
241 /*--------------------------------------------------------------------------*/
243 * @brief ico_uxf_process_window_get: get a window defined by the process
245 * @param[in] process process identity
246 * @param[out] attr return a window definition
247 * First is main window of the process,
248 * second henceforth is sub window of the process.
249 * At present support only main window.
250 * @param[in] num number of window definition(= array size)
252 * @retval >= 0 success(number of windows)
253 * @retval ICO_UXF_E2BIG The number of the process has exceeded num
254 * The attribute of the process up to a num piece is returned to attr
255 * @retval ICO_UXF_ENOENT error(does not exist)
256 * @retval ICO_UXF_EINVAL error(num is 0 or less)
257 * @retval ICO_UXF_ESRCH error(not initialized)
258 * @retval ICO_UXF_EPERM error(no authority)
260 /*--------------------------------------------------------------------------*/
262 ico_uxf_process_window_get(const char *process, Ico_Uxf_ProcessWin *attr, const int num)
264 Ico_Uxf_Mng_Process *proc; /* process management table */
265 Ico_Uxf_Mng_ProcWin *pwin; /* Process possession window table */
266 int n; /* number of window */
268 uifw_trace("ico_uxf_process_window_get: Enter(%s,,%d)", process, num);
270 if (gIco_Uxf_Api_Mng.Initialized <= 0) {
271 uifw_warn("ico_uxf_process_window_get: Leave(ESRCH)");
272 return ICO_UXF_ESRCH;
276 uifw_warn("ico_uxf_process_window_get: Leave(EINVAL)");
277 return ICO_UXF_EINVAL;
280 proc = ico_uxf_mng_process(process, 0);
282 uifw_trace("ico_uxf_process_window_get: Leave(ENOENT)");
283 return ICO_UXF_ENOENT;
286 memcpy((char *)&(attr[0]), (char *)&(proc->attr.mainwin), sizeof(Ico_Uxf_ProcessWin));
288 pwin = proc->procwin;
289 for (n = 1; n < num; n++) {
291 memcpy((char *)&(attr[n]), (char *)&(pwin->attr), sizeof(Ico_Uxf_ProcessWin));
297 uifw_trace("ico_uxf_process_window_get: Leave(E2BIG)");
300 uifw_trace("ico_uxf_process_window_get: Leave(%d)", n);
305 /*--------------------------------------------------------------------------*/
307 * @brief ico_uxf_process_window_get_one: get a window defined by the process
309 * @param[in] process process identity(appid)
310 * @param[out] attr return a window definition
311 * @param[in] winidx window index(0 is main window, 1-N is sub window)
313 * @retval ICO_UXF_EOK success
314 * @retval ICO_UXF_ENOENT error(does not exist)
315 * @retval ICO_UXF_EINVAL error(winidx is negative)
316 * @retval ICO_UXF_ESRCH error(not initialized)
317 * @retval ICO_UXF_EPERM error(no authority)
319 /*--------------------------------------------------------------------------*/
321 ico_uxf_process_window_get_one(const char *process,
322 Ico_Uxf_ProcessWin *attr, const int winidx)
324 Ico_Uxf_Mng_Process *proc; /* process management table */
325 Ico_Uxf_Mng_ProcWin *pwin; /* Process possession window table */
326 int n; /* number of window */
328 uifw_trace("ico_uxf_process_window_get_one: Enter(%s,,%d)", process, winidx);
330 if (gIco_Uxf_Api_Mng.Initialized <= 0) {
331 uifw_warn("ico_uxf_process_window_get_one: Leave(ESRCH)");
332 return ICO_UXF_ESRCH;
336 uifw_warn("ico_uxf_process_window_get_one: Leave(EINVAL)");
337 return ICO_UXF_EINVAL;
340 proc = ico_uxf_mng_process(process, 0);
342 uifw_warn("ico_uxf_process_window_get_one: Leave(ENOENT, no appid)");
343 return ICO_UXF_ENOENT;
345 if (winidx >= proc->attr.numwindows) {
346 uifw_warn("ico_uxf_process_window_get_one: Leave(ENOENT, winidx over)");
347 return ICO_UXF_ENOENT;
351 memcpy(attr, &proc->attr.mainwin, sizeof(Ico_Uxf_ProcessWin));
354 pwin = proc->procwin;
355 for (n = 1; n < winidx; n++) {
357 uifw_warn("ico_uxf_process_window_get_one: Leave(ENOENT, winidx over)");
358 return ICO_UXF_ENOENT;
362 memcpy(attr, &pwin->attr, sizeof(Ico_Uxf_ProcessWin));
364 uifw_trace("ico_uxf_process_window_get_one: Leave(EOK)");
368 /*--------------------------------------------------------------------------*/
370 * @brief ico_uxf_process_query_processes: get all process current status
372 * @param[out] attr process's current status
374 * @retval >= 0 success(number of process)
375 * @retval ICO_UXF_E2BIG The number of the process has exceeded num
376 * The attribute of the process up to a num piece is returned to attr
377 * @retval ICO_UXF_EOK success
378 * @retval ICO_UXF_ESRCH error(not initialized)
379 * @retval ICO_UXF_EINVAL error(num is 0 or less)
380 * @retval ICO_UXF_EPERM error(no authority)
382 /*--------------------------------------------------------------------------*/
384 ico_uxf_process_query_processes(Ico_Uxf_ProcessAttr attr[], const int num)
386 int n; /* number of process */
387 Ico_Uxf_Mng_Process *mng; /* process management table */
390 uifw_trace("ico_uxf_process_query_processes: Enter(,%d)", num);
392 if (gIco_Uxf_Api_Mng.Initialized <= 0) {
393 uifw_warn("ico_uxf_process_query_processes: Leave(ESRCH)");
394 return ICO_UXF_ESRCH;
398 uifw_warn("ico_uxf_process_query_processes: Leave(EINVAL)");
399 return ICO_UXF_EINVAL;
403 for (hash = 0; hash < ICO_UXF_MISC_HASHSIZE; hash++) {
404 mng = gIco_Uxf_Api_Mng.Hash_ProcessId[hash];
407 memcpy((char *)(&attr[n]), (char *)&(mng->attr), sizeof(Ico_Uxf_ProcessAttr));
409 mng = mng->nextidhash;
416 uifw_trace("ico_uxf_process_query_processes: Leave(E2BIG)");
419 uifw_trace("ico_uxf_process_query_processes: Leave(%d)", n);