Add media db open options 42/46542/3 accepted/tizen/mobile/20150822.064630 accepted/tizen/tv/20150822.065205 accepted/tizen/wearable/20150822.065631 submit/tizen/20150821.141418
authorMinje Ahn <minje.ahn@samsung.com>
Fri, 21 Aug 2015 10:57:06 +0000 (19:57 +0900)
committerMinje Ahn <minje.ahn@samsung.com>
Fri, 21 Aug 2015 11:05:53 +0000 (20:05 +0900)
Change-Id: Ifc7b831873683d8c5bae2faecb2d52e7a53322ef
Signed-off-by: Minje Ahn <minje.ahn@samsung.com>
capi-media-controller.manifest
include/media_controller_db.h
src/media_controller_client.c
src/media_controller_db.c
src/media_controller_server.c
svc/media_controller_db_util.c
svc/media_controller_db_util.h
svc/media_controller_svc.c

index c00c25b..b1ebd13 100755 (executable)
@@ -2,4 +2,7 @@
         <request>
                 <domain name="_" />
         </request>
+        <assign>
+                <filesystem path="/usr/bin/media-controller_create_db.sh" exec_label="System" />
+        </assign>
 </manifest>
index 1bdb956..67d3be5 100755 (executable)
@@ -59,7 +59,7 @@
 #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);}}
 
-int mc_db_connect(void **db_handle);
+int mc_db_connect(void **db_handle, bool needWrite);
 int mc_db_disconnect(void *db_handle);
 int mc_db_create_tables(void *handle);
 int mc_db_create_server_table(void *handle, const char *server_name);
index a263c1c..b875441 100755 (executable)
@@ -174,7 +174,7 @@ static int __mc_client_create(media_controller_client_s **mc_client)
                goto Error;
        }
 
-       ret = mc_db_connect(&_client->db_handle);
+       ret = mc_db_connect(&_client->db_handle, false);
        if (ret != MEDIA_CONTROLLER_ERROR_NONE) {
                mc_error("error in connecting to DB %d", ret);
                goto Error;
index 09b8d97..b71923a 100755 (executable)
@@ -177,7 +177,7 @@ static int __mc_db_get_ulong_value_of_key(void *handle, const char *server_name,
        return MEDIA_CONTROLLER_ERROR_NONE;
 }
 
-int mc_db_connect(void **handle)
+int mc_db_connect(void **handle, bool needWrite)
 {
        int ret = MEDIA_CONTROLLER_ERROR_NONE;
        sqlite3 *db_handle = NULL;
@@ -187,7 +187,11 @@ int mc_db_connect(void **handle)
        mc_retvm_if(handle == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Handle is NULL");
 
        /*Connect DB*/
-       ret = db_util_open(tzplatform_mkpath(TZ_USER_DB, MC_DB_NAME), &db_handle, DB_UTIL_REGISTER_HOOK_METHOD);
+       if(needWrite) {
+               ret = db_util_open_with_options(tzplatform_mkpath(TZ_USER_DB, MC_DB_NAME), &db_handle, SQLITE_OPEN_READWRITE, NULL);
+       } else {
+               ret = db_util_open_with_options(tzplatform_mkpath(TZ_USER_DB, MC_DB_NAME), &db_handle, SQLITE_OPEN_READONLY, NULL);
+       }
        if (SQLITE_OK != ret) {
                mc_error("error when db open");
                *handle = NULL;
index bb1346a..baefc59 100755 (executable)
@@ -46,7 +46,7 @@ static int __mc_server_create(media_controller_server_s **mc_server)
                goto ERROR;
        }
 
-       ret = mc_db_connect(&(_server->db_handle));
+       ret = mc_db_connect(&(_server->db_handle), false);
        if (ret != MEDIA_CONTROLLER_ERROR_NONE) {
                mc_error("fail mc_db_connect [%d]", ret);
                goto ERROR;
index 2e1eb7f..4da7dd3 100755 (executable)
@@ -93,7 +93,7 @@ static char* __mc_get_db_name(uid_t uid)
        return result_psswd_rtn;
 }
 
-int mc_db_util_connect(void **handle, uid_t uid)
+int mc_db_util_connect(void **handle, uid_t uid, bool needWrite)
 {
        int ret = MEDIA_CONTROLLER_ERROR_NONE;
        sqlite3 *db_handle = NULL;
@@ -101,7 +101,11 @@ int mc_db_util_connect(void **handle, uid_t uid)
        mc_retvm_if(handle == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Handle is NULL");
 
        /*Connect DB*/
-       ret = db_util_open(__mc_get_db_name(uid), &db_handle, DB_UTIL_REGISTER_HOOK_METHOD);
+       if(needWrite) {
+               ret = db_util_open_with_options(__mc_get_db_name(uid), &db_handle, SQLITE_OPEN_READWRITE, NULL);
+       } else {
+               ret = db_util_open_with_options(__mc_get_db_name(uid), &db_handle, SQLITE_OPEN_READONLY, NULL);
+       }
        if (SQLITE_OK != ret) {
                mc_error("error when db open");
                *handle = NULL;
index 4f602fb..6a7e421 100755 (executable)
@@ -26,7 +26,7 @@
 #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);}}
 
-int mc_db_util_connect(void **handle, uid_t uid);
+int mc_db_util_connect(void **handle, uid_t uid, bool needWrite);
 int mc_db_util_update_db(void *handle, const char *sql_str);
 int mc_db_util_disconnect(void *handle);
 
index 79bbee8..4b999cb 100755 (executable)
@@ -93,7 +93,7 @@ gboolean _mc_read_service_request_tcp_socket(GIOChannel *src, GIOCondition condi
 
        if (recv_msg.msg_type == MC_MSG_DB_UPDATE) {
                /* Connect media controller DB*/
-               if(mc_db_util_connect(&(mc_svc_data->db_handle), recv_msg.uid) != MEDIA_CONTROLLER_ERROR_NONE) {
+               if(mc_db_util_connect(&(mc_svc_data->db_handle), recv_msg.uid, true) != MEDIA_CONTROLLER_ERROR_NONE) {
                        mc_error("Failed to connect DB");
                        goto ERROR;
                }