summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhj kim <backto.kim@samsung.com>2018-05-24 14:41:22 +0900
committerhj kim <backto.kim@samsung.com>2018-05-24 14:41:22 +0900
commit08d639e60bc6f449331020358c98f1fdd1e92bd7 (patch)
tree9b1d6d5c3f631aaf494fc333d905e33fc65a3c8c
parent0f238dceac0a013b95d3599a934b9a9747956a85 (diff)
downloadmedia-controller-08d639e60bc6f449331020358c98f1fdd1e92bd7.tar.gz
media-controller-08d639e60bc6f449331020358c98f1fdd1e92bd7.tar.bz2
media-controller-08d639e60bc6f449331020358c98f1fdd1e92bd7.zip
Just rearrange the code. remove duplicated code
Change-Id: I242c3b05e514eda582cbd3b5e188ef6a89b08cac
-rwxr-xr-xinclude/media_controller_db.h17
-rwxr-xr-xinclude/media_controller_private.h13
-rwxr-xr-xsrc/media_controller_db.c14
-rwxr-xr-xsvc/include/media_controller_db_util.h3
-rwxr-xr-xsvc/media_controller_db_util.c18
5 files changed, 22 insertions, 43 deletions
diff --git a/include/media_controller_db.h b/include/media_controller_db.h
index dada6c7..72dbf0a 100755
--- a/include/media_controller_db.h
+++ b/include/media_controller_db.h
@@ -17,25 +17,8 @@
#ifndef __TIZEN_MULTIMEDIA_MEDIA_CONTROLLER_DB_H__
#define __TIZEN_MULTIMEDIA_MEDIA_CONTROLLER_DB_H__
-#include <db-util.h>
-#include <sqlite3.h>
-#include <tzplatform_config.h>
#include <bundle.h>
-#define FAT_FILEPATH_LEN_MAX 4096 /* inc null */
-#define MC_FILE_PATH_LEN_MAX FAT_FILEPATH_LEN_MAX /**< File path max length (include file name) on file system */
-
-#define MC_DB_NAME ".media_controller.db"
-
-#define MC_DB_TABLE_SERVER_LIST "server_list"
-#define MC_DB_TABLE_LATEST_SERVER "latest_server"
-
-#define DB_SELECT_METADATA_FROM_DB "SELECT * FROM '%q';"
-#define DB_SELECT_VALUE_OF_KEY "SELECT %s FROM '%q';"
-
-#define DB_SELECT_LATEST_SERVER_NAME "SELECT server_name FROM "MC_DB_TABLE_LATEST_SERVER";"
-#define DB_SELECT_ALL_SERVER_LIST "SELECT server_name FROM "MC_DB_TABLE_SERVER_LIST";"
-
int mc_db_connect(void **db_handle);
int mc_db_disconnect(void *db_handle);
int mc_db_create_server_table(void *handle, const char *server_name);
diff --git a/include/media_controller_private.h b/include/media_controller_private.h
index 03e0923..aba2216 100755
--- a/include/media_controller_private.h
+++ b/include/media_controller_private.h
@@ -27,6 +27,7 @@ extern "C" {
#include <stdlib.h>
#include <string.h>
#include <gio/gio.h>
+#include <sqlite3.h>
#include "media_controller_server.h"
#include "media_controller_client.h"
#include "media_controller_socket.h"
@@ -110,6 +111,18 @@ extern "C" {
#define MC_STRING_VALID(str) ((str != NULL && strlen(str) > 0) ? TRUE : FALSE)
#define MC_STRING_DELIMITER "VAL_SEP"
+#define FAT_FILEPATH_LEN_MAX 4096 /* inc null */
+#define MC_FILE_PATH_LEN_MAX FAT_FILEPATH_LEN_MAX /**< File path max length (include file name) on file system */
+
+#define MC_DB_NAME ".media_controller.db"
+
+#define MC_DB_TABLE_SERVER_LIST "server_list"
+#define MC_DB_TABLE_LATEST_SERVER "latest_server"
+#define MC_DB_TABLE_PLAYLIST "server_playlist"
+
+#define SQLITE3_SAFE_FREE(sql_string) {if (sql_string) { sqlite3_free(sql_string); sql_string = NULL; } }
+#define SQLITE3_FINALIZE(x) {if (x != NULL) sqlite3_finalize(x); }
+
/**
* @ingroup CAPI_MEDIA_CONTROLLER_MODULE
* @brief DBus path for media controller.
diff --git a/src/media_controller_db.c b/src/media_controller_db.c
index 08bd093..08735e2 100755
--- a/src/media_controller_db.c
+++ b/src/media_controller_db.c
@@ -21,6 +21,7 @@
#include <pwd.h>
#include <stdio.h>
#include <tzplatform_config.h>
+#include <db-util.h>
#include "media_controller_private.h"
#include "media_controller_db.h"
@@ -47,11 +48,6 @@ typedef enum {
MC_SERVER_FIELD_REPEAT_MODE,
} server_table_field_e;
-#define MC_DB_TABLE_PLAYLIST "server_playlist"
-
-#define SQLITE3_SAFE_FREE(sql_string) {if (sql_string) { sqlite3_free(sql_string); sql_string = NULL; } }
-#define SQLITE3_FINALIZE(x) {if (x != NULL) sqlite3_finalize(x); }
-
static int __mc_db_busy_handler(void *pData, int count)
{
MC_MILLISEC_SLEEP(50);
@@ -85,7 +81,7 @@ static int __mc_db_get_int_value_of_key(void *handle, const char *server_name, c
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");
- sql_str = sqlite3_mprintf(DB_SELECT_VALUE_OF_KEY, key, server_name);
+ sql_str = sqlite3_mprintf("SELECT %s FROM '%q';", key, server_name);
mc_retvm_if(!MC_STRING_VALID(sql_str), MEDIA_CONTROLLER_ERROR_INVALID_OPERATION, "SQL string is null");
ret = sqlite3_prepare_v2(db_handle, sql_str, strlen(sql_str), &stmt, NULL);
@@ -369,7 +365,7 @@ int mc_db_get_latest_server_name(void *handle, char **latest_server_name)
*latest_server_name = NULL;
- sql_str = sqlite3_mprintf(DB_SELECT_LATEST_SERVER_NAME);
+ sql_str = sqlite3_mprintf("SELECT server_name FROM '%q';", MC_DB_TABLE_LATEST_SERVER);
mc_retvm_if(!MC_STRING_VALID(sql_str), MEDIA_CONTROLLER_ERROR_INVALID_OPERATION, "SQL string is null");
ret = sqlite3_prepare_v2(db_handle, sql_str, strlen(sql_str), &stmt, NULL);
@@ -469,7 +465,7 @@ int mc_db_get_metadata_info(void *handle, const char *server_name, mc_metadata_h
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");
- sql_str = sqlite3_mprintf(DB_SELECT_METADATA_FROM_DB, server_name);
+ sql_str = sqlite3_mprintf("SELECT * FROM '%q';", server_name);
mc_retvm_if(!MC_STRING_VALID(sql_str), MEDIA_CONTROLLER_ERROR_INVALID_OPERATION, "SQL string is null");
ret = sqlite3_prepare_v2(db_handle, sql_str, strlen(sql_str), &stmt, NULL);
@@ -708,7 +704,7 @@ int mc_db_foreach_server_list(void *handle, mc_activated_server_cb callback, voi
mc_retvm_if(db_handle == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Handle is NULL");
- sql_str = sqlite3_mprintf(DB_SELECT_ALL_SERVER_LIST);
+ sql_str = sqlite3_mprintf("SELECT server_name FROM '%q';", MC_DB_TABLE_SERVER_LIST);
mc_retvm_if(!MC_STRING_VALID(sql_str), MEDIA_CONTROLLER_ERROR_INVALID_OPERATION, "SQL string is null");
ret = sqlite3_prepare_v2(db_handle, sql_str, strlen(sql_str), &stmt, NULL);
if (SQLITE_OK != ret) {
diff --git a/svc/include/media_controller_db_util.h b/svc/include/media_controller_db_util.h
index cb8a8bb..63b7e54 100755
--- a/svc/include/media_controller_db_util.h
+++ b/svc/include/media_controller_db_util.h
@@ -17,8 +17,7 @@
#ifndef __TIZEN_MEDIA_CONTROLLER_DB_UTIL_H__
#define __TIZEN_MEDIA_CONTROLLER_DB_UTIL_H__
-#include <db-util.h>
-#include <tzplatform_config.h>
+#include <sys/types.h>
int mc_db_util_connect(void **handle, uid_t uid);
int mc_db_util_disconnect(void *handle);
diff --git a/svc/media_controller_db_util.c b/svc/media_controller_db_util.c
index 637d534..8f7fbbe 100755
--- a/svc/media_controller_db_util.c
+++ b/svc/media_controller_db_util.c
@@ -20,26 +20,14 @@
#include <pwd.h>
#include <sqlite3.h>
#include <tzplatform_config.h>
+#include <db-util.h>
#include "media_controller_private.h"
#include "media_controller_db_util.h"
-#define FAT_FILEPATH_LEN_MAX 4096 /* inc null */
-#define MC_FILE_PATH_LEN_MAX FAT_FILEPATH_LEN_MAX /**< File path max length (include file name) on file system */
-#define MC_DB_NAME ".media_controller.db"
-
-#define MC_DB_TABLE_SERVER_LIST "server_list"
-#define MC_DB_TABLE_LATEST_SERVER "latest_server"
-#define MC_DB_TABLE_PLAYLIST "server_playlist"
#define MC_DB_TRIGGER_PLAYLIST "cleanup_playlist"
-
#define DB_SELECT_ALL_SERVER_LIST_EXCEPT_LATEST "SELECT name FROM SQLITE_MASTER WHERE type='table' AND (name != '%q') AND (name NOT IN (SELECT server_name FROM "MC_DB_TABLE_LATEST_SERVER"));"
-#define DB_SELECT_LATEST_SERVER "SELECT COUNT(*), server_name FROM "MC_DB_TABLE_LATEST_SERVER";"
-#define DB_UPDATE_STATES "UPDATE '%q' SET server_state=%d, playback_state=%d;"
-
-#define SQLITE3_SAFE_FREE(sql_string) {if (sql_string) {sqlite3_free(sql_string); sql_string = NULL; } }
-#define SQLITE3_FINALIZE(x) {if (x != NULL) sqlite3_finalize(x); }
static int __mc_db_util_busy_handler(void *pData, int count)
{
@@ -401,7 +389,7 @@ int mc_db_util_init_latest_server_table(void *handle)
mc_retvm_if(handle == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Handle is NULL");
/* Get latest server name */
- sql_str = sqlite3_mprintf(DB_SELECT_LATEST_SERVER);
+ sql_str = sqlite3_mprintf("SELECT COUNT(*), server_name FROM '%q';", MC_DB_TABLE_LATEST_SERVER);
mc_retvm_if(!MC_STRING_VALID(sql_str), MEDIA_CONTROLLER_ERROR_INVALID_OPERATION, "SQL string is null");
ret = sqlite3_prepare_v2(db_handle, sql_str, strlen(sql_str), &stmt, NULL);
@@ -432,7 +420,7 @@ int mc_db_util_init_latest_server_table(void *handle)
mc_retvm_if(latest_server_name == NULL, MEDIA_CONTROLLER_ERROR_OUT_OF_MEMORY, "latest_server is not exist");
/* Update server_state and playback_state to 0 */
- sql_str = sqlite3_mprintf(DB_UPDATE_STATES, latest_server_name, MC_SERVER_STATE_DEACTIVATE, MC_PLAYBACK_STATE_STOPPED);
+ sql_str = sqlite3_mprintf("UPDATE '%q' SET server_state=%d, playback_state=%d;", latest_server_name, MC_SERVER_STATE_DEACTIVATE, MC_PLAYBACK_STATE_STOPPED);
mc_retvm_if(!MC_STRING_VALID(sql_str), MEDIA_CONTROLLER_ERROR_INVALID_OPERATION, "SQL string is null");
ret = mc_db_util_update_db(handle, sql_str);