#include "vc_cmd_db.h"
#include "vc_main.h"
-#include "voice_control_command.h"
+#include "vc_command.h"
#include "voice_control_command_expand.h"
while (SQLITE_ROW == ret) {
int temp = 0;
+ int ret = -1;
char* temp_text = NULL;
- vc_cmd_s* temp_cmd = NULL;
- temp_cmd = (vc_cmd_s*)calloc(1, sizeof(vc_cmd_s));
- if (NULL == temp_cmd) {
+ vc_cmd_h temp_cmd;
+ ret = vc_cmd_create(&temp_cmd);
+
+ if (0 != ret) {
SLOG(LOG_ERROR, vc_db_tag(), "[ERROR] Fail to allocate memory");
if (NULL != appid) {
free(appid);
temp_text = (char*)sqlite3_column_text(stmt, 7);
if (NULL != temp_text)
- temp_cmd->appid = strdup(temp_text);
+ vc_cmd_set_appid(temp_cmd, temp_text);
- if (NULL != appid && NULL != temp_cmd->appid) {
- if (VC_COMMAND_TYPE_BACKGROUND == type && 0 == strncmp(appid, temp_cmd->appid, strlen(appid))) {
+ ret = vc_cmd_get_appid(temp_cmd, &temp_text);
+ if (NULL != appid && 0 == ret) {
+ if (VC_COMMAND_TYPE_BACKGROUND == type && 0 == strncmp(appid, temp_text, strlen(appid))) {
SLOG(LOG_DEBUG, vc_db_tag(), "Skip get background commands when app is foreground, appid(%s)", appid);
+ free(temp_text);
+ temp_text = NULL;
+
ret = sqlite3_step(stmt);
if (SQLITE_DONE == ret)
break;
}
}
+ if (NULL != temp_text) {
+ free(temp_text);
+ temp_text = NULL;
+ }
+
temp = sqlite3_column_int(stmt, 0);
- temp_cmd->id = temp;
+ vc_cmd_set_id(temp_cmd, temp);
temp = sqlite3_column_int(stmt, 1);
- temp_cmd->pid = temp;
+ vc_cmd_set_pid(temp_cmd, temp);
temp = sqlite3_column_int(stmt, 2);
- temp_cmd->type = temp;
+ vc_cmd_set_type(temp_cmd, temp);
temp = sqlite3_column_int(stmt, 3);
- temp_cmd->format = temp;
+ vc_cmd_set_format(temp_cmd, temp);
temp = sqlite3_column_int(stmt, 4);
- temp_cmd->domain = temp;
+ vc_cmd_set_domain(temp_cmd, temp);
temp_text = (char*)sqlite3_column_text(stmt, 5);
if (NULL != temp_text)
- temp_cmd->command = strdup(temp_text);
+ vc_cmd_set_command(temp_cmd, temp_text);
temp_text = (char*)sqlite3_column_text(stmt, 6);
if (NULL != temp_text)
- temp_cmd->parameter = strdup(temp_text);
+ vc_cmd_set_unfixed_command(temp_cmd, temp_text);
temp_text = (char*)sqlite3_column_text(stmt, 8);
if (NULL != temp_text)
- temp_cmd->invocation_name = strdup(temp_text);
+ vc_cmd_set_invocation_name(temp_cmd, temp_text);
temp_text = (char*)sqlite3_column_text(stmt, 9);
if (NULL != temp_text)
- temp_cmd->fixed = strdup(temp_text);
+ vc_cmd_set_fixed_command(temp_cmd, temp_text);
- if (type == temp_cmd->type) {
+ ret = vc_cmd_get_type(temp_cmd, &temp);
+ if (0 == ret && type == temp) {
*cmd_list = g_slist_append(*cmd_list, temp_cmd);
} else {
- SLOG(LOG_WARN, vc_db_tag(), "[WARNING] Command type(%d) is NOT valid : request type(%d)", temp_cmd->type, type);
+ SLOG(LOG_WARN, vc_db_tag(), "[WARNING] Command type(%d) is NOT valid : request type(%d)", temp, type);
+
+ vc_cmd_destroy((vc_cmd_h)temp_cmd);
}
ret = sqlite3_step(stmt);
if (SQLITE_DONE == ret)
SLOG(LOG_DEBUG, TAG_VCD, "[Dbus] send dialog : pid(%d), disp_text(%s), utt_text(%s), continue(%d)", pid, disp_text, utt_text, continuous);
- if (NULL == disp_text)
- disp_text = strdup("#NULL");
- if (NULL == utt_text)
- utt_text = strdup("#NULL");
+ char* disp_null = NULL;
+ char* utt_null = NULL;
+ if (NULL == disp_text) {
+ disp_null = strdup("#NULL");
+ disp_text = disp_null;
+ }
+
+ if (NULL == utt_text) {
+ utt_null = strdup("#NULL");
+ utt_text = utt_null;
+ }
dbus_message_append_args(msg,
DBUS_TYPE_INT32, &pid,
dbus_message_unref(msg);
+ if (NULL != disp_null) {
+ free(disp_null);
+ disp_null = NULL;
+ }
+
+ if (NULL != utt_null) {
+ free(utt_null);
+ utt_null = NULL;
+ }
+
return 0;
}