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 Ico_Uxf_conf_application *apptbl = NULL;
52 uifw_trace("ico_uxf_process_execute: Enter(%s)", name);
54 if (gIco_Uxf_Api_Mng.Initialized <= 0) {
55 uifw_warn("ico_uxf_process_execute: Leave(ESRCH)");
59 for (hash = 0; hash < ICO_UXF_MISC_HASHSIZE; hash++) {
60 proc = gIco_Uxf_Api_Mng.Hash_ProcessId[hash];
62 if (strcasecmp(proc->attr.process, name) == 0) break;
63 proc = proc->nextidhash;
69 uifw_warn("ico_uxf_process_execute: Leave(ENOENT)");
70 return ICO_UXF_ENOENT;
73 ico_uxf_enter_critical(); /* enter critical section */
75 if (proc->attr.status != ICO_UXF_PROCSTATUS_STOP) {
76 ico_uxf_leave_critical(); /* leave critical section */
77 uifw_warn("ico_uxf_process_execute: Leave(EBUSY)");
81 /* in order to avoid double execute, status set starting */
82 proc->attr.status = ICO_UXF_PROCSTATUS_INIT;
83 ico_uxf_leave_critical(); /* leave critical section */
86 proc->attr.internalid = aul_launch_app(name , NULL);
87 if (proc->attr.internalid < 0) {
88 uifw_error("ico_uxf_process_execute: Leave(ENOSYS), Launch App Error(%d)",
89 proc->attr.internalid);
90 return ICO_UXF_ENOSYS;
93 proc->attr.status = ICO_UXF_PROCSTATUS_RUN;
95 uifw_trace("ico_uxf_process_execute: Leave(%s)", proc->attr.process);
99 /*--------------------------------------------------------------------------*/
101 * @brief ico_uxf_process_terminate: finish a program
103 * @param[in] process process id
105 * @retval ICO_UXF_EOK success
106 * @retval ICO_UXF_ESRCH error(not initialized)
107 * @retval ICO_UXF_ENOENT error(does not exist)
108 * @retval ICO_UXF_EAGAIN error(already launch)
109 * @retval ICO_UXF_EPERM error(no authority)
111 /*--------------------------------------------------------------------------*/
113 ico_uxf_process_terminate(const char *process)
115 Ico_Uxf_Mng_Process *proc; /* process management table */
116 int ret; /* process management table */
118 uifw_trace("ico_uxf_process_terminate: Enter(%s)", process);
120 if (gIco_Uxf_Api_Mng.Initialized <= 0) {
121 uifw_warn("ico_uxf_process_terminate: Leave(ESRCH)");
122 return ICO_UXF_ESRCH;
125 /* target is other process */
126 proc = ico_uxf_mng_process(process, 0);
128 uifw_warn("ico_uxf_process_terminate: Leave(ENOENT)");
129 return ICO_UXF_ENOENT;
132 ret = aul_terminate_pid(proc->attr.internalid);
134 uifw_warn("ico_uxf_process_terminate: Leave(ENOSYS) cannot terminate pid=%d",
135 proc->attr.internalid);
136 return ICO_UXF_ENOSYS;
139 proc->attr.status = ICO_UXF_PROCSTATUS_STOP;
140 proc->attr.internalid = -1;
141 proc->attr.mainwin.window = 0;
142 ico_uxf_free_procwin(proc);
144 uifw_trace("ico_uxf_process_terminate: Leave(EOK)");
148 /*--------------------------------------------------------------------------*/
150 * @brief ico_uxf_process_attribute_get: get a process's current state
152 * @param[in] process process's identity
153 * @param[out] attr target process's current state
155 * @retval ICO_UXF_EOK success
156 * @retval ICO_UXF_ESRCH error(not initialized)
157 * @retval ICO_UXF_ENOENT error(does not exist)
158 * @retval ICO_UXF_EPERM error(no authority)
160 /*--------------------------------------------------------------------------*/
162 ico_uxf_process_attribute_get(const char *process, Ico_Uxf_ProcessAttr *attr)
164 Ico_Uxf_Mng_Process *proc; /* process management table */
166 uifw_trace("ico_uxf_process_attribute_get: Enter(%s)", process);
168 if (gIco_Uxf_Api_Mng.Initialized <= 0) {
169 uifw_warn("ico_uxf_process_attribute_get: Leave(ESRCH)");
170 return ICO_UXF_ESRCH;
173 proc = ico_uxf_mng_process(process, 0);
175 uifw_warn("ico_uxf_process_attribute_get: Leave(ENOENT)");
176 return ICO_UXF_ENOENT;
179 memcpy((char *)attr, (char *)&(proc->attr), sizeof(Ico_Uxf_ProcessAttr));
181 uifw_trace("ico_uxf_process_attribute_get: Leave(EOK)");
185 /*--------------------------------------------------------------------------*/
187 * @brief ico_uxf_process_is_active: get application activity
189 * @param[in] process process's identity
191 * @retval 2 process is child process
192 * @retval 1 process is active
193 * @retval 0 process is not active
195 /*--------------------------------------------------------------------------*/
197 ico_uxf_process_is_active(const char *process)
199 Ico_Uxf_Mng_Process *proc; /* process management table */
201 if (gIco_Uxf_Api_Mng.Initialized <= 0) {
202 uifw_warn("ico_uxf_process_is_active: False(ESRCH)");
206 proc = ico_uxf_mng_process(process, 0);
208 uifw_warn("ico_uxf_process_is_active: False(ENOENT)");
212 if (proc->attr.child) {
213 uifw_trace("ico_uxf_process_is_active: %s is Child", process);
216 uifw_trace("ico_uxf_process_is_active: %s is %s",
217 process, proc->attr.active ? "Active" : "Inactive");
218 return proc->attr.active;
221 /*--------------------------------------------------------------------------*/
223 * @brief ico_uxf_process_window_get: get a window defined by the process
225 * @param[in] process process identity
226 * @param[out] attr return a window definition
227 * First is main window of the process,
228 * second henceforth is sub window of the process.
229 * At present support only main window.
230 * @param[in] num number of window definition(= array size)
232 * @retval >= 0 success(number of windows)
233 * @retval ICO_UXF_E2BIG The number of the process has exceeded num
234 * The attribute of the process up to a num piece is returned to attr
235 * @retval ICO_UXF_ENOENT error(does not exist)
236 * @retval ICO_UXF_EINVAL error(num is 0 or less)
237 * @retval ICO_UXF_ESRCH error(not initialized)
238 * @retval ICO_UXF_EPERM error(no authority)
240 /*--------------------------------------------------------------------------*/
242 ico_uxf_process_window_get(const char *process, Ico_Uxf_ProcessWin *attr, const int num)
244 Ico_Uxf_Mng_Process *proc; /* process management table */
245 Ico_Uxf_Mng_ProcWin *pwin; /* Process possession window table */
246 int n; /* number of window */
248 uifw_trace("ico_uxf_process_window_get: Enter(%s,,%d)", process, num);
250 if (gIco_Uxf_Api_Mng.Initialized <= 0) {
251 uifw_warn("ico_uxf_process_window_get: Leave(ESRCH)");
252 return ICO_UXF_ESRCH;
256 uifw_warn("ico_uxf_process_window_get: Leave(EINVAL)");
257 return ICO_UXF_EINVAL;
260 proc = ico_uxf_mng_process(process, 0);
262 uifw_trace("ico_uxf_process_window_get: Leave(ENOENT)");
263 return ICO_UXF_ENOENT;
266 memcpy((char *)&(attr[0]), (char *)&(proc->attr.mainwin), sizeof(Ico_Uxf_ProcessWin));
268 pwin = proc->procwin;
269 for (n = 1; n < num; n++) {
271 memcpy((char *)&(attr[n]), (char *)&(pwin->attr), sizeof(Ico_Uxf_ProcessWin));
277 uifw_trace("ico_uxf_process_window_get: Leave(E2BIG)");
280 uifw_trace("ico_uxf_process_window_get: Leave(%d)", n);
285 /*--------------------------------------------------------------------------*/
287 * @brief ico_uxf_process_window_get_one: get a window defined by the process
289 * @param[in] process process identity(appid)
290 * @param[out] attr return a window definition
291 * @param[in] winidx window index(0 is main window, 1-N is sub window)
293 * @retval ICO_UXF_EOK success
294 * @retval ICO_UXF_ENOENT error(does not exist)
295 * @retval ICO_UXF_EINVAL error(winidx is negative)
296 * @retval ICO_UXF_ESRCH error(not initialized)
297 * @retval ICO_UXF_EPERM error(no authority)
299 /*--------------------------------------------------------------------------*/
301 ico_uxf_process_window_get_one(const char *process,
302 Ico_Uxf_ProcessWin *attr, const int winidx)
304 Ico_Uxf_Mng_Process *proc; /* process management table */
305 Ico_Uxf_Mng_ProcWin *pwin; /* Process possession window table */
306 int n; /* number of window */
308 uifw_trace("ico_uxf_process_window_get_one: Enter(%s,,%d)", process, winidx);
310 if (gIco_Uxf_Api_Mng.Initialized <= 0) {
311 uifw_warn("ico_uxf_process_window_get_one: Leave(ESRCH)");
312 return ICO_UXF_ESRCH;
316 uifw_warn("ico_uxf_process_window_get_one: Leave(EINVAL)");
317 return ICO_UXF_EINVAL;
320 proc = ico_uxf_mng_process(process, 0);
322 uifw_warn("ico_uxf_process_window_get_one: Leave(ENOENT, no appid)");
323 return ICO_UXF_ENOENT;
325 if (winidx >= proc->attr.numwindows) {
326 uifw_warn("ico_uxf_process_window_get_one: Leave(ENOENT, winidx over)");
327 return ICO_UXF_ENOENT;
331 memcpy(attr, &proc->attr.mainwin, sizeof(Ico_Uxf_ProcessWin));
334 pwin = proc->procwin;
335 for (n = 1; n < winidx; n++) {
337 uifw_warn("ico_uxf_process_window_get_one: Leave(ENOENT, winidx over)");
338 return ICO_UXF_ENOENT;
342 memcpy(attr, &pwin->attr, sizeof(Ico_Uxf_ProcessWin));
344 uifw_trace("ico_uxf_process_window_get_one: Leave(EOK)");
348 /*--------------------------------------------------------------------------*/
350 * @brief ico_uxf_process_query_processes: get all process current status
352 * @param[out] attr process's current status
354 * @retval >= 0 success(number of process)
355 * @retval ICO_UXF_E2BIG The number of the process has exceeded num
356 * The attribute of the process up to a num piece is returned to attr
357 * @retval ICO_UXF_EOK success
358 * @retval ICO_UXF_ESRCH error(not initialized)
359 * @retval ICO_UXF_EINVAL error(num is 0 or less)
360 * @retval ICO_UXF_EPERM error(no authority)
362 /*--------------------------------------------------------------------------*/
364 ico_uxf_process_query_processes(Ico_Uxf_ProcessAttr attr[], const int num)
366 int n; /* number of process */
367 Ico_Uxf_Mng_Process *mng; /* process management table */
370 uifw_trace("ico_uxf_process_query_processes: Enter(,%d)", num);
372 if (gIco_Uxf_Api_Mng.Initialized <= 0) {
373 uifw_warn("ico_uxf_process_query_processes: Leave(ESRCH)");
374 return ICO_UXF_ESRCH;
378 uifw_warn("ico_uxf_process_query_processes: Leave(EINVAL)");
379 return ICO_UXF_EINVAL;
383 for (hash = 0; hash < ICO_UXF_MISC_HASHSIZE; hash++) {
384 mng = gIco_Uxf_Api_Mng.Hash_ProcessId[hash];
387 memcpy((char *)(&attr[n]), (char *)&(mng->attr), sizeof(Ico_Uxf_ProcessAttr));
389 mng = mng->nextidhash;
396 uifw_trace("ico_uxf_process_query_processes: Leave(E2BIG)");
399 uifw_trace("ico_uxf_process_query_processes: Leave(%d)", n);