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.
19 #include "ttd-cmd-type.h"
21 struct _ttd_cmd_data_s {
22 ttd_cmd_state_e state;
25 ttd_cmd_power_e pwr_cmd;
26 ttd_cmd_config_e cfg_cmd;
27 ttd_cmd_package_e pkg_cmd;
28 ttd_cmd_diagnosis_e diag_cmd;
29 ttd_cmd_info_e info_cmd;
30 ttd_cmd_local_e local_cmd;
34 unsigned int data_len;
35 cmd_data_free_func data_free_func;
38 ttd_cmd_data *ttd_cmd_new(const char *cmd_id)
40 ttd_cmd_data *data = NULL;
43 retv_if(!cmd_id, NULL);
45 id = g_strdup(cmd_id);
48 data = g_try_malloc0(sizeof(struct _ttd_cmd_data_s));
50 _E("failed to malloc");
55 data->state = TTD_CMD_STATE_UNKNOWN;
56 data->type = TTD_CMD_TYPE_UNKNOWN;
62 int ttd_cmd_set_state(ttd_cmd_data *cmd, ttd_cmd_state_e state)
65 retvm_if(state == TTD_CMD_STATE_UNKNOWN, -1, "invaild state");
72 int ttd_cmd_set_type(ttd_cmd_data *cmd, ttd_cmd_type_e type)
75 retvm_if((type == TTD_CMD_TYPE_UNKNOWN) | (type == TTD_CMD_TYPE_MAX),
83 int ttd_cmd_set_command(ttd_cmd_data *cmd, int command)
88 case TTD_CMD_TYPE_POWER:
89 cmd->command.pwr_cmd = command;
91 case TTD_CMD_TYPE_CONFIG:
92 cmd->command.cfg_cmd = command;
94 case TTD_CMD_TYPE_PACKAGE:
95 cmd->command.pkg_cmd = command;
97 case TTD_CMD_TYPE_DIAGNOSIS:
98 cmd->command.diag_cmd = command;
100 case TTD_CMD_TYPE_INFO:
101 cmd->command.info_cmd = command;
103 case TTD_CMD_TYPE_LOCAL:
104 cmd->command.local_cmd = command;
106 case TTD_CMD_TYPE_MAX:
108 _E("Unknown cmd type : %d", cmd->type);
115 int ttd_cmd_set_data(ttd_cmd_data *cmd,
116 void *data, unsigned int length, cmd_data_free_func free_fn)
121 cmd->data_len = length;
122 cmd->data_free_func = free_fn;
127 void ttd_cmd_free(ttd_cmd_data *cmd)
132 _D("free cmd type - %d", cmd->type);
134 _D("free cmd id - %s", cmd->cmd_id);
138 if (cmd->data_free_func)
139 cmd->data_free_func(cmd->data);
146 ttd_cmd_state_e ttd_cmd_get_state(ttd_cmd_data *cmd)
148 retv_if(!cmd, TTD_CMD_STATE_UNKNOWN);
153 ttd_cmd_type_e ttd_cmd_get_type(ttd_cmd_data *cmd)
155 retv_if(!cmd, TTD_CMD_TYPE_UNKNOWN);
160 const char *ttd_cmd_get_id(ttd_cmd_data *cmd)
167 int ttd_cmd_get_command(ttd_cmd_data *cmd)
173 case TTD_CMD_TYPE_POWER:
174 command = cmd->command.pwr_cmd;
176 case TTD_CMD_TYPE_CONFIG:
177 command = cmd->command.cfg_cmd;
179 case TTD_CMD_TYPE_PACKAGE:
180 command = cmd->command.pkg_cmd;
182 case TTD_CMD_TYPE_DIAGNOSIS:
183 command = cmd->command.diag_cmd;
185 case TTD_CMD_TYPE_INFO:
186 command = cmd->command.info_cmd;
188 case TTD_CMD_TYPE_LOCAL:
189 command = cmd->command.local_cmd;
191 case TTD_CMD_TYPE_MAX:
193 _E("Unknown cmd type : %d", cmd->type);
200 int ttd_cmd_get_data(ttd_cmd_data *cmd, void **data, unsigned int *length)
205 *length = cmd->data_len;