return mc_ipc_send_message_to_server(MC_MSG_DB_UPDATE, priv_type, sql_str);
}
-static int __mc_db_get_int_value_of_key(sqlite3 *handle, const char *server_name, const char *key, int *value)
+static int __mc_db_get_single_result(sqlite3 *handle, char *sql_str, sqlite3_stmt **stmt)
{
- int ret = MEDIA_CONTROLLER_ERROR_NONE;
- char *sql_str = NULL;
- sqlite3_stmt *stmt = NULL;
+ int ret = SQLITE_OK;
- mc_retvm_if(handle == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Handle is NULL");
- mc_retvm_if(server_name == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "server_name is NULL");
- mc_retvm_if(key == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "key is NULL");
- mc_retvm_if(value == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "value is NULL");
-
- sql_str = sqlite3_mprintf(SELECT_KEY_FROM_SERVER_INFO, key, server_name);
- mc_retvm_if(!MC_STRING_VALID(sql_str), MEDIA_CONTROLLER_ERROR_INVALID_OPERATION, "SQL string is null");
-
- ret = sqlite3_prepare_v2(handle, sql_str, strlen(sql_str), &stmt, NULL);
- SQLITE3_SAFE_FREE(sql_str);
- mc_retvm_if(SQLITE_OK != ret, MEDIA_CONTROLLER_ERROR_INVALID_OPERATION, "prepare error [%s]", sqlite3_errmsg(handle));
-
- if (sqlite3_step(stmt) == SQLITE_ROW) {
- *value = sqlite3_column_int(stmt, 0);
- } else {
- mc_error("end of row [%s]", sqlite3_errmsg(handle));
- SQLITE3_FINALIZE(stmt);
- return MEDIA_CONTROLLER_ERROR_INVALID_OPERATION;
- }
-
- SQLITE3_FINALIZE(stmt);
-
- return MEDIA_CONTROLLER_ERROR_NONE;
-}
-
-static int __mc_db_get_ulonglong_value_of_key(sqlite3 *handle, const char *server_name, const char *key, unsigned long long *value)
-{
- int ret = MEDIA_CONTROLLER_ERROR_NONE;
- char *sql_str = NULL;
- sqlite3_stmt *stmt = NULL;
-
- mc_retvm_if(handle == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Handle is NULL");
- mc_retvm_if(server_name == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "server_name is NULL");
- mc_retvm_if(key == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "key is NULL");
- mc_retvm_if(value == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "value is NULL");
-
- sql_str = sqlite3_mprintf(SELECT_KEY_FROM_SERVER_INFO, key, server_name);
- mc_retvm_if(!MC_STRING_VALID(sql_str), MEDIA_CONTROLLER_ERROR_INVALID_OPERATION, "SQL string is null");
-
- ret = sqlite3_prepare_v2(handle, sql_str, strlen(sql_str), &stmt, NULL);
- SQLITE3_SAFE_FREE(sql_str);
- mc_retvm_if(SQLITE_OK != ret, MEDIA_CONTROLLER_ERROR_INVALID_OPERATION, "prepare error [%s]", sqlite3_errmsg(handle));
-
- if (sqlite3_step(stmt) == SQLITE_ROW) {
- *value = (unsigned long long)sqlite3_column_int64(stmt, 0);
- } else {
- mc_error("end of row [%s]", sqlite3_errmsg(handle));
- SQLITE3_FINALIZE(stmt);
- return MEDIA_CONTROLLER_ERROR_INVALID_OPERATION;
- }
-
- SQLITE3_FINALIZE(stmt);
-
- return MEDIA_CONTROLLER_ERROR_NONE;
-}
-
-static int __mc_db_get_text_value_of_key(sqlite3 *handle, const char *server_name, const char *key, char **value)
-{
- int ret = MEDIA_CONTROLLER_ERROR_NONE;
- char *sql_str = NULL;
- sqlite3_stmt *stmt = NULL;
-
- mc_retvm_if(handle == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Handle is NULL");
- mc_retvm_if(server_name == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "server_name is NULL");
- mc_retvm_if(key == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "key is NULL");
- mc_retvm_if(value == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "value is NULL");
-
- sql_str = sqlite3_mprintf(SELECT_KEY_FROM_SERVER_INFO, key, server_name);
+ mc_retvm_if(handle == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "invalid handle");
+ mc_retvm_if(stmt == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "sqlite3_stmt is null");
mc_retvm_if(!MC_STRING_VALID(sql_str), MEDIA_CONTROLLER_ERROR_INVALID_OPERATION, "SQL string is null");
- ret = sqlite3_prepare_v2(handle, sql_str, strlen(sql_str), &stmt, NULL);
+ ret = sqlite3_prepare_v2(handle, sql_str, strlen(sql_str), stmt, NULL);
SQLITE3_SAFE_FREE(sql_str);
- mc_retvm_if(SQLITE_OK != ret, MEDIA_CONTROLLER_ERROR_INVALID_OPERATION, "prepare error [%s]", sqlite3_errmsg(handle));
+ mc_retvm_if(ret != SQLITE_OK, MEDIA_CONTROLLER_ERROR_INVALID_OPERATION, "prepare error [%s]", sqlite3_errmsg(handle));
- if (sqlite3_step(stmt) == SQLITE_ROW) {
- *value = g_strdup((const char *)sqlite3_column_text(stmt, 0));
- } else {
+ if (sqlite3_step(*stmt) != SQLITE_ROW) {
mc_error("end of row [%s]", sqlite3_errmsg(handle));
- SQLITE3_FINALIZE(stmt);
+ SQLITE3_FINALIZE(*stmt);
return MEDIA_CONTROLLER_ERROR_INVALID_OPERATION;
}
- SQLITE3_FINALIZE(stmt);
-
return MEDIA_CONTROLLER_ERROR_NONE;
}
sql_str = sqlite3_mprintf("SELECT playback_state, playback_position, playlist_name, playlist_index, playback_content_type, age_rating FROM %q WHERE name=%Q",
MC_DB_TABLE_SERVER_INFO, server_name);
- mc_retvm_if(!MC_STRING_VALID(sql_str), MEDIA_CONTROLLER_ERROR_INVALID_OPERATION, "SQL string is null");
+ ret = __mc_db_get_single_result(handle, sql_str, &stmt);
+ mc_retvm_if(ret != MEDIA_CONTROLLER_ERROR_NONE, ret, "__mc_db_get_single_result failed [%d]", ret);
- ret = sqlite3_prepare_v2(handle, sql_str, strlen(sql_str), &stmt, NULL);
- SQLITE3_SAFE_FREE(sql_str);
- mc_retvm_if(SQLITE_OK != ret, MEDIA_CONTROLLER_ERROR_INVALID_OPERATION, "prepare error [%s]", sqlite3_errmsg(handle));
+ _playback = (media_controller_playback_s *)calloc(1, sizeof(media_controller_playback_s));
+ if (!_playback) {
+ mc_error("OUT_OF_MEMORY");
+ SQLITE3_FINALIZE(stmt);
- if (sqlite3_step(stmt) == SQLITE_ROW) {
- _playback = (media_controller_playback_s *)calloc(1, sizeof(media_controller_playback_s));
- mc_retvm_if(!_playback, MEDIA_CONTROLLER_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
+ return MEDIA_CONTROLLER_ERROR_OUT_OF_MEMORY;
+ }
- _playback->state = sqlite3_column_int(stmt, 0);
- _playback->position = (unsigned long long)sqlite3_column_int64(stmt, 1);
- _playback->playlist_name = g_strdup((const char *)sqlite3_column_text(stmt, 2));
- _playback->index = g_strdup((const char *)sqlite3_column_text(stmt, 3));
- _playback->content_type = sqlite3_column_int(stmt, 4);
- _playback->age_rating = sqlite3_column_int(stmt, 5);
+ _playback->state = sqlite3_column_int(stmt, 0);
+ _playback->position = (unsigned long long)sqlite3_column_int64(stmt, 1);
+ _playback->playlist_name = g_strdup((const char *)sqlite3_column_text(stmt, 2));
+ _playback->index = g_strdup((const char *)sqlite3_column_text(stmt, 3));
+ _playback->content_type = sqlite3_column_int(stmt, 4);
+ _playback->age_rating = sqlite3_column_int(stmt, 5);
- *playback = (mc_playback_h)_playback;
- } else {
- mc_error("end of row [%s]", sqlite3_errmsg(handle));
- SQLITE3_FINALIZE(stmt);
- return MEDIA_CONTROLLER_ERROR_INVALID_OPERATION;
- }
+ *playback = (mc_playback_h)_playback;
SQLITE3_FINALIZE(stmt);
mc_retvm_if(metadata == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "metadata is NULL");
sql_str = sqlite3_mprintf("SELECT %s FROM %q WHERE name=%Q", META_LIST, MC_DB_TABLE_LATEST_META, server_name);
- mc_retvm_if(!MC_STRING_VALID(sql_str), MEDIA_CONTROLLER_ERROR_INVALID_OPERATION, "SQL string is null");
- ret = sqlite3_prepare_v2(handle, sql_str, strlen(sql_str), &stmt, NULL);
- SQLITE3_SAFE_FREE(sql_str);
- mc_retvm_if(SQLITE_OK != ret, MEDIA_CONTROLLER_ERROR_INVALID_OPERATION, "prepare error [%s]", sqlite3_errmsg(handle));
-
- if (sqlite3_step(stmt) == SQLITE_ROW) {
- ret = __mc_db_get_metadata(stmt, 0, metadata);
- } else {
- mc_error("end of row [%s]", sqlite3_errmsg(handle));
- ret = MEDIA_CONTROLLER_ERROR_NONE;
- }
+ ret = __mc_db_get_single_result(handle, sql_str, &stmt);
+ mc_retvm_if(ret != MEDIA_CONTROLLER_ERROR_NONE, ret, "__mc_db_get_single_result failed [%d]", ret);
+ ret = __mc_db_get_metadata(stmt, 0, metadata);
SQLITE3_FINALIZE(stmt);
return ret;
int mc_db_get_shuffle_mode(sqlite3 *handle, const char *server_name, mc_shuffle_mode_e *mode)
{
- return __mc_db_get_int_value_of_key(handle, server_name, "shuffle_mode", (int *)mode);
+ int ret = MEDIA_CONTROLLER_ERROR_NONE;
+ char *sql_str = NULL;
+ sqlite3_stmt *stmt = NULL;
+
+ mc_retvm_if(handle == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Handle is NULL");
+ mc_retvm_if(server_name == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "server_name is NULL");
+ mc_retvm_if(mode == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "mode is NULL");
+
+ sql_str = sqlite3_mprintf("SELECT shuffle_mode FROM %q WHERE name=%Q", MC_DB_TABLE_SERVER_INFO, server_name);
+
+ ret = __mc_db_get_single_result(handle, sql_str, &stmt);
+ mc_retvm_if(ret != MEDIA_CONTROLLER_ERROR_NONE, ret, "__mc_db_get_single_result failed [%d]", ret);
+
+ *mode = sqlite3_column_int(stmt, 0);
+ SQLITE3_FINALIZE(stmt);
+
+ return MEDIA_CONTROLLER_ERROR_NONE;
}
int mc_db_get_repeat_mode(sqlite3 *handle, const char *server_name, mc_repeat_mode_e *mode)
{
- return __mc_db_get_int_value_of_key(handle, server_name, "repeat_mode", (int *)mode);
+ int ret = MEDIA_CONTROLLER_ERROR_NONE;
+ char *sql_str = NULL;
+ sqlite3_stmt *stmt = NULL;
+
+ mc_retvm_if(handle == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Handle is NULL");
+ mc_retvm_if(server_name == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "server_name is NULL");
+ mc_retvm_if(mode == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "mode is NULL");
+
+ sql_str = sqlite3_mprintf("SELECT repeat_mode FROM %q WHERE name=%Q", MC_DB_TABLE_SERVER_INFO, server_name);
+
+ ret = __mc_db_get_single_result(handle, sql_str, &stmt);
+ mc_retvm_if(ret != MEDIA_CONTROLLER_ERROR_NONE, ret, "__mc_db_get_single_result failed [%d]", ret);
+
+ *mode = sqlite3_column_int(stmt, 0);
+ SQLITE3_FINALIZE(stmt);
+
+ return MEDIA_CONTROLLER_ERROR_NONE;
}
int mc_db_get_icon_uri(sqlite3 *handle, const char *server_name, char **uri)
{
- return __mc_db_get_text_value_of_key(handle, server_name, "icon_uri", uri);
+ int ret = MEDIA_CONTROLLER_ERROR_NONE;
+ char *sql_str = NULL;
+ sqlite3_stmt *stmt = NULL;
+
+ mc_retvm_if(handle == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Handle is NULL");
+ mc_retvm_if(server_name == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "server_name is NULL");
+ mc_retvm_if(uri == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "uri is NULL");
+
+ sql_str = sqlite3_mprintf("SELECT icon_uri FROM %q WHERE name=%Q", MC_DB_TABLE_SERVER_INFO, server_name);
+
+ ret = __mc_db_get_single_result(handle, sql_str, &stmt);
+ mc_retvm_if(ret != MEDIA_CONTROLLER_ERROR_NONE, ret, "__mc_db_get_single_result failed [%d]", ret);
+
+ *uri = g_strdup((const char *)sqlite3_column_text(stmt, 0));
+ SQLITE3_FINALIZE(stmt);
+
+ return MEDIA_CONTROLLER_ERROR_NONE;
}
static int __mc_db_get_ability(sqlite3 *handle, const char *server_name, unsigned long long *decided, unsigned long long *supported)
{
int ret = MEDIA_CONTROLLER_ERROR_NONE;
- unsigned long long _decided = 0;
- unsigned long long _supported = 0;
+ char *sql_str = NULL;
+ sqlite3_stmt *stmt = NULL;
mc_retvm_if(!handle, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "invalid handle");
mc_retvm_if(!server_name, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "invalid server_name");
+ mc_retvm_if(!decided, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "invalid decided");
+ mc_retvm_if(!supported, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "invalid supported");
- ret = __mc_db_get_ulonglong_value_of_key(handle, server_name, "ability_decided", &_decided);
- mc_retvm_if(ret != MEDIA_CONTROLLER_ERROR_NONE, ret, "__mc_db_get_text_value_of_key failed");
+ sql_str = sqlite3_mprintf("SELECT ability_decided, ability_supported FROM %q WHERE name=%Q", MC_DB_TABLE_SERVER_INFO, server_name);
- ret = __mc_db_get_ulonglong_value_of_key(handle, server_name, "ability_supported", &_supported);
- mc_retvm_if(ret != MEDIA_CONTROLLER_ERROR_NONE, ret, "__mc_db_get_text_value_of_key failed");
+ ret = __mc_db_get_single_result(handle, sql_str, &stmt);
+ mc_retvm_if(ret != MEDIA_CONTROLLER_ERROR_NONE, ret, "__mc_db_get_single_result failed [%d]", ret);
- *decided = _decided;
- *supported = _supported;
+ *decided = (unsigned long long)sqlite3_column_int64(stmt, 0);
+ *supported = (unsigned long long)sqlite3_column_int64(stmt, 1);
+ SQLITE3_FINALIZE(stmt);
- return ret;
+ return MEDIA_CONTROLLER_ERROR_NONE;
}