2 * Copyright (c) 2018 Samsung Electronics Co., Ltd.
4 * Licensed under the Flora License, Version 1.1 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://floralicense.org/license/
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include <app_control.h>
26 #define WORKER_PKG_MGR "org.tizen.package-manager-worker"
27 #define WORKER_INFO_SYS "ttd-worker-system"
28 #define WORKER_INFO_TASK "org.tizen.task-worker"
29 #define WORKER_INFO_TASK_NAME "task-worker"
30 #define WORKER_INFO_TASK_PATH "/usr/bin/task-worker"
32 static int _exec_application_sysinfo(const char *cmd_id)
34 app_control_h ac_h = NULL;
35 int ac_ret = app_control_create(&ac_h);
36 if (ac_ret != APP_CONTROL_ERROR_NONE) {
39 app_control_set_operation(ac_h, APP_CONTROL_OPERATION_DEFAULT);
40 app_control_set_app_id(ac_h, WORKER_INFO_SYS);
42 app_control_add_extra_data(ac_h, "id", cmd_id);
44 ac_ret = app_control_send_launch_request(ac_h, NULL, NULL);
45 if (ac_ret != APP_CONTROL_ERROR_NONE) {
47 app_control_destroy(ac_h);
53 static int _exec_application_pkgmgr(const char *cmd_id,const char *op,const char *extra)
55 app_control_h ac_h = NULL;
56 int ac_ret = app_control_create(&ac_h);
58 if (ac_ret != APP_CONTROL_ERROR_NONE) {
61 app_control_set_operation(ac_h, APP_CONTROL_OPERATION_DEFAULT);
62 app_control_set_app_id(ac_h, WORKER_PKG_MGR);
63 app_control_add_extra_data(ac_h, "operation", op);
64 app_control_add_extra_data(ac_h, "id", cmd_id);
67 app_control_add_extra_data(ac_h, "meta", extra);
69 ac_ret = app_control_send_launch_request(ac_h, NULL, NULL);
70 if (ac_ret != APP_CONTROL_ERROR_NONE) {
72 app_control_destroy(ac_h);
78 static int _exec_process(const char *path, const char *name, const char *cmd_id, const char *data)
80 const char * const args[4] = {name, cmd_id, data, NULL};
90 _D("Forked succesfully");
95 execv(path, (char * const*) args);
96 _D("Failed to exec %s", path);
101 int ttd_worker_handle_info(ttd_cmd_data *c_data)
104 const char *cmd_id = NULL;
108 cmd_id = ttd_cmd_get_id(c_data);
109 retv_if(!cmd_id, -1);
111 switch (ttd_cmd_get_command(c_data)) {
112 case TTD_CMD_INFO_GET_SYSINFO:
113 ret = _exec_application_sysinfo(cmd_id);
115 case TTD_CMD_INFO_GET_TASKINFO:
116 ttd_cmd_get_data(c_data, &data, &l);
117 ret = _exec_process(WORKER_INFO_TASK_PATH, WORKER_INFO_TASK_NAME, cmd_id, data);
119 case TTD_CMD_INFO_GET_MAX:
127 int ttd_worker_handle_pkgmgr(ttd_cmd_data *c_data)
129 const char *op = NULL;
131 unsigned int length = 0;
132 const char *cmd_id = NULL;
135 cmd_id = ttd_cmd_get_id(c_data);
136 retv_if(!cmd_id, -1);
138 switch (ttd_cmd_get_command(c_data)) {
139 case TTD_CMD_PACKAGE_INSTALL:
141 ttd_cmd_get_data(c_data, (void *)&extra, &length);
143 case TTD_CMD_PACKAGE_REMOVE:
146 case TTD_CMD_PACKAGE_GET_APP_LIST:
149 case TTD_CMD_PACKAGE_GET_PACKAGE_LIST:
152 case TTD_CMD_PACKAGE_MAX:
154 _E("unknown command - %d", ttd_cmd_get_command(c_data));
158 ret = _exec_application_pkgmgr(cmd_id, op, extra);