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 {
24 ttd_cmd_power_e pwr_cmd;
25 ttd_cmd_config_e cfg_cmd;
26 ttd_cmd_package_e pkg_cmd;
27 ttd_cmd_diagnosis_e diag_cmd;
28 ttd_cmd_info_e info_cmd;
29 ttd_cmd_local_e local_cmd;
33 unsigned int data_len;
36 ttd_cmd_data *ttd_cmd_new(void)
38 ttd_cmd_data *data = NULL;
40 data = g_malloc0(sizeof(struct _ttd_cmd_data_s));
45 int ttd_cmd_set_type(ttd_cmd_data *cmd, ttd_cmd_type_e type)
54 int ttd_cmd_set_id(ttd_cmd_data *cmd, const char *id)
61 cmd->cmd_id = g_strdup(id);
66 int ttd_cmd_set_command(ttd_cmd_data *cmd, int command)
71 case TTD_CMD_TYPE_POWER:
72 cmd->command.pwr_cmd = command;
74 case TTD_CMD_TYPE_CONFIG:
75 cmd->command.cfg_cmd = command;
77 case TTD_CMD_TYPE_PACKAGE:
78 cmd->command.pkg_cmd = command;
80 case TTD_CMD_TYPE_DIAGNOSIS:
81 cmd->command.diag_cmd = command;
83 case TTD_CMD_TYPE_INFO:
84 cmd->command.info_cmd = command;
86 case TTD_CMD_TYPE_LOCAL:
87 cmd->command.local_cmd = command;
89 case TTD_CMD_TYPE_MAX:
91 _E("Unknown cmd type : %d", cmd->type);
98 int ttd_cmd_set_data(ttd_cmd_data *cmd, void *data, unsigned int length)
103 cmd->data_len = length;
108 void ttd_cmd_free(ttd_cmd_data *cmd)
113 _D("free cmd type - %d", cmd->type);
115 _D("free cmd id - %s", cmd->cmd_id);
122 ttd_cmd_type_e ttd_cmd_get_type(ttd_cmd_data *cmd)
124 retv_if(!cmd, TTD_CMD_TYPE_UNKNOWN);
129 const char *ttd_cmd_get_id(ttd_cmd_data *cmd)
136 int ttd_cmd_get_command(ttd_cmd_data *cmd)
142 case TTD_CMD_TYPE_POWER:
143 command = cmd->command.pwr_cmd;
145 case TTD_CMD_TYPE_CONFIG:
146 command = cmd->command.cfg_cmd;
148 case TTD_CMD_TYPE_PACKAGE:
149 command = cmd->command.pkg_cmd;
151 case TTD_CMD_TYPE_DIAGNOSIS:
152 command = cmd->command.diag_cmd;
154 case TTD_CMD_TYPE_INFO:
155 command = cmd->command.info_cmd;
157 case TTD_CMD_TYPE_LOCAL:
158 command = cmd->command.local_cmd;
160 case TTD_CMD_TYPE_MAX:
162 _E("Unknown cmd type : %d", cmd->type);
169 int ttd_cmd_get_data(ttd_cmd_data *cmd, void **data, unsigned int *length)
174 *length = cmd->data_len;