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 <glib/gstdio.h>
21 #include "ttd-config.h"
22 #include "ttd-worker-handle.h"
25 #include "ttd-cmd-mgr.h"
27 static int __config_write(ttd_cmd_data *c_data)
30 unsigned int data_len = 0;
35 ret = ttd_cmd_get_data(c_data, &data, &data_len);
38 switch (ttd_cmd_get_command(c_data))
40 case TTD_CMD_CONFIG_SET_SERVER_URL:
41 ret = ttd_config_write_string("url", "server", (char *)data);
43 _E("Failed to set server url[%s]", (char *)data);
47 case TTD_CMD_CONFIG_SET_APP_ID:
48 ret = ttd_config_write_string("worker", "appid", (char *)data);
50 _E("Failed to set app id[%s]", (char *)data);
60 ttd_cmd_mgr_push_result(
61 ttd_cmd_get_id(c_data), TTD_CMD_RESULT_SUCCESS, NULL);
66 static int __worker_launch(ttd_cmd_data *c_data)
69 ttd_cmd_type_e cmd_type = TTD_CMD_TYPE_UNKNOWN;
73 cmd_type = ttd_cmd_get_type(c_data);
75 if (cmd_type == TTD_CMD_TYPE_PACKAGE) {
76 ret = ttd_worker_handle_pkgmgr(c_data);
77 } else if (cmd_type == TTD_CMD_TYPE_INFO) {
78 ret = ttd_worker_handle_info(c_data);
80 _E("not supported cmd type - %d", cmd_type);
86 static int __diagnosis_run(ttd_cmd_data *c_data)
89 ttd_cmd_diagnosis_e diag_type;
90 char *zip_file = NULL;
93 char *result_json = NULL;
97 diag_type = ttd_cmd_get_command(c_data);
99 if (diag_type != TTD_CMD_DIAGNOSIS_GET_LOG)
102 zip_file = ttd_diag_collect_log_to_zip();
103 retv_if(!zip_file, -1);
105 ret = ttd_http_logfile_post(zip_file, &res_code, &res_msg);
106 if (ret || (res_code != TTD_HTTP_OK)) {
107 _E("failed to upload logfile[%s]", zip_file);
108 _E("res_code [%ls] with res_msg[%s]", res_code, res_msg);
115 result_json = g_strdup_printf("{ \"url\" : \"%s\" }", res_msg);
119 ttd_cmd_mgr_push_result(
120 ttd_cmd_get_id(c_data), TTD_CMD_RESULT_SUCCESS, result_json);
129 ttd_cmd_launch_func ttd_cmd_get_launch_func(ttd_cmd_type_e type)
131 ttd_cmd_launch_func func = NULL;
134 case TTD_CMD_TYPE_POWER:
136 case TTD_CMD_TYPE_CONFIG:
137 func = __config_write;
139 case TTD_CMD_TYPE_PACKAGE:
140 case TTD_CMD_TYPE_INFO:
141 func = __worker_launch;
143 case TTD_CMD_TYPE_DIAGNOSIS:
144 func = __diagnosis_run;
146 case TTD_CMD_TYPE_LOCAL:
148 case TTD_CMD_TYPE_UNKNOWN:
149 case TTD_CMD_TYPE_MAX: