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 header file of Apprication Framework (Application Manager)
20 #include <sys/types.h>
25 #include "ico_apf_private.h"
26 #include "ico_uxf_conf.h"
28 /*--------------------------------------------------------------------------*/
30 * @brief ico_apf_get_app_id: Get application id(in AppCore) from application process id
32 * @param[in] pid application process id
33 * @param[out] appid application id
35 * @retval ICO_APP_CTL_E_NONE success
36 * @retval ICO_APP_CTL_E_INVALID_PARAM error(pid dose not exist)
38 /*--------------------------------------------------------------------------*/
40 ico_apf_get_app_id(const int pid, char *appid)
48 memset(appid, 0, ICO_UXF_MAX_PROCESS_NAME+1);
54 /* Get applicationId from AppCore(AUL) */
55 if (aul_app_get_appid_bypid(ppid, appid, ICO_UXF_MAX_PROCESS_NAME)
57 snprintf(procpath, sizeof(procpath)-1, "/proc/%d/cmdline", ppid);
58 fd = open(procpath, O_RDONLY);
60 size = read(fd, procpath, sizeof(procpath));
61 for (; size > 0; size--) {
62 if (procpath[size-1]) break;
65 /* Get program base name */
67 for (j = 0; j < size; j++) {
68 if (procpath[j] == 0) break;
69 if (procpath[j] == '/') i = j + 1;
72 for (; i < size; i++) {
73 appid[j] = procpath[i];
74 if ((appid[j] == 0) ||
75 (j >= ICO_UXF_MAX_PROCESS_NAME)) break;
78 /* Search application number */
79 if ((appid[j] == 0) && (j < (ICO_UXF_MAX_PROCESS_NAME-1))) {
80 for (; i < size; i++) {
81 if ((procpath[i] == 0) &&
82 (procpath[i+1] == '@')) {
83 strncpy(&appid[j], &procpath[i+1],
84 ICO_UXF_MAX_PROCESS_NAME - j - 1);
92 apfw_trace("ico_apf_get_app_id: LEAVE(pid=%d dose not exist)", ppid);
93 sprintf(appid, "?%d?", ppid);
94 return ICO_APP_CTL_E_INVALID_PARAM;
97 return ICO_APP_CTL_E_NONE;