Use tzplatform_context_XXX API to support multi-thread 48/161148/1
authorhj kim <backto.kim@samsung.com>
Fri, 17 Nov 2017 05:45:38 +0000 (14:45 +0900)
committerhj kim <backto.kim@samsung.com>
Wed, 22 Nov 2017 02:05:15 +0000 (11:05 +0900)
Change-Id: I9ab581a14d0df2064b5b7e62b9625732d3410255

lib/include/media-util.h
lib/media-util-user.c
packaging/media-server.spec

index 828325c..6751eaf 100755 (executable)
@@ -39,7 +39,7 @@
 #define MEDIA_ROOT_PATH_EXTERNAL       tzplatform_getenv(TZ_SYS_STORAGE)
 #define MEDIA_ROOT_PATH_SDCARD tzplatform_mkpath(TZ_SYS_STORAGE, "SDCard")
 #define MEDIA_ROOT_PATH_USB            tzplatform_getenv(TZ_SYS_STORAGE)
-#define MEDIA_DB_NAME          tzplatform_mkpath(TZ_USER_DB, ".media.db")              /**<  media db name*/
+
 #ifdef _USE_SENIOR_MODE
 #define MEDIA_CONTENT_PATH             "content"               /**<  user content folder name*/
 #else
index f788cba..ff2ea0c 100755 (executable)
 #include <system_info.h>
 #endif
 
+static GMutex tzplatform_mutex;
+
+typedef enum {
+       MEDIA_DB = 0,
+       INTERNAL_ROOT,
+       THUMB_ROOT,
+       THUMB_INTERNAL,
+       THUMB_EXTERNAL
+} ms_user_path_type_e;
+
 #ifdef _USE_SENIOR_MODE
 bool _ms_is_support_senior_mode()
 {
@@ -44,23 +54,69 @@ bool _ms_is_support_senior_mode()
 }
 #endif
 
-int ms_user_get_internal_root_path(uid_t uid, char **path)
+static int __ms_user_get_path(ms_user_path_type_e type, uid_t uid, char **path)
 {
        int ret = MS_MEDIA_ERR_NONE;
+       const char *result = NULL;
+       struct tzplatform_context *context[128];
 
-       if (uid == getuid()) {
-               if (MS_STRING_VALID(MEDIA_ROOT_PATH_INTERNAL))
-                       *path = g_strndup(MEDIA_ROOT_PATH_INTERNAL, strlen(MEDIA_ROOT_PATH_INTERNAL));
-       } else {
-               ret = tzplatform_set_user(uid);
-               MSAPI_RETVM_IF(ret != 0, MS_MEDIA_ERR_INTERNAL, "Invalid UID[%d]", uid);
+       g_mutex_lock(&tzplatform_mutex);
 
-               if (MS_STRING_VALID(MEDIA_ROOT_PATH_INTERNAL))
-                       *path = g_strndup(MEDIA_ROOT_PATH_INTERNAL, strlen(MEDIA_ROOT_PATH_INTERNAL));
+       ret = tzplatform_context_create(&context[uid-5000]);
+       if (ret != 0) {
+               MSAPI_DBG_ERR("Fail tzplatform_context_create");
+               ret = MS_MEDIA_ERR_INTERNAL;
+               goto ERROR;
+       }
+
+       ret = tzplatform_context_set_user(context[uid-5000], uid);
+       if (ret != 0) {
+               MSAPI_DBG_ERR("Fail tzplatform_context_set_user");
+               ret = MS_MEDIA_ERR_INTERNAL;
+               goto ERROR;
+       }
 
-               tzplatform_reset_user();
+       switch (type) {
+       case MEDIA_DB:
+               result = tzplatform_context_mkpath(context[uid-5000], TZ_USER_DB, ".media.db");
+               break;
+       case INTERNAL_ROOT:
+               result = tzplatform_context_getenv(context[uid-5000], TZ_USER_CONTENT);
+               break;
+       case THUMB_ROOT:
+               result = tzplatform_context_mkpath(context[uid-5000], TZ_USER_SHARE, "media/.thumb");
+               break;
+       case THUMB_INTERNAL:
+               result = tzplatform_context_mkpath(context[uid-5000], TZ_USER_SHARE, "media/.thumb/phone");
+               break;
+       case THUMB_EXTERNAL:
+               result = tzplatform_context_mkpath(context[uid-5000], TZ_USER_SHARE, "media/.thumb/mmc");
+               break;
+       default:
+               MSAPI_DBG_ERR("Invalid type");
+               ret = MS_MEDIA_ERR_INTERNAL;
+               break;
        }
 
+       *path = g_strdup(result);
+
+ERROR:
+       tzplatform_context_destroy(context[uid-5000]);
+
+       g_mutex_unlock(&tzplatform_mutex);
+
+       return ret;
+}
+
+int ms_user_get_internal_root_path(uid_t uid, char **path)
+{
+       int ret = MS_MEDIA_ERR_NONE;
+
+       if (uid == getuid())
+               *path = g_strndup(MEDIA_ROOT_PATH_INTERNAL, strlen(MEDIA_ROOT_PATH_INTERNAL));
+       else
+               ret = __ms_user_get_path(INTERNAL_ROOT, uid, path);
+
        //MSAPI_DBG_SLOG("internal root path [%s]", *path);
 
        return ret;
@@ -113,18 +169,10 @@ int ms_user_get_root_thumb_store_path(uid_t uid, char **path)
 {
        int ret = MS_MEDIA_ERR_NONE;
 
-       if (uid == getuid()) {
-               const char *result = tzplatform_mkpath(TZ_USER_SHARE, "media/.thumb");
-               *path = g_strndup(result, strlen(result));
-       } else {
-               ret = tzplatform_set_user(uid);
-               MSAPI_RETVM_IF(ret != 0, MS_MEDIA_ERR_INTERNAL, "Invalid UID[%d]", uid);
-
-               const char *result = tzplatform_mkpath(TZ_USER_SHARE, "media/.thumb");
-               *path = g_strndup(result, strlen(result));
-
-               tzplatform_reset_user();
-       }
+       if (uid == getuid())
+               *path = g_strdup(tzplatform_mkpath(TZ_USER_SHARE, "media/.thumb"));
+       else
+               ret = __ms_user_get_path(THUMB_ROOT, uid, path);
 
        //MSAPI_DBG_SLOG("thumb path [%s]", *path);
 
@@ -141,15 +189,10 @@ int ms_user_get_thumb_store_path(uid_t uid, ms_user_storage_type_e storage_type,
                else
                        *path = g_strdup(tzplatform_mkpath(TZ_USER_SHARE, "media/.thumb/mmc"));
        } else {
-               ret = tzplatform_set_user(uid);
-               MSAPI_RETVM_IF(ret != 0, MS_MEDIA_ERR_INTERNAL, "Invalid UID[%d]", uid);
-
                if (storage_type == MS_USER_STORAGE_INTERNAL)
-                       *path = g_strdup(tzplatform_mkpath(TZ_USER_SHARE, "media/.thumb/phone"));
+                       ret = __ms_user_get_path(THUMB_INTERNAL, uid, path);
                else
-                       *path = g_strdup(tzplatform_mkpath(TZ_USER_SHARE, "media/.thumb/mmc"));
-
-               tzplatform_reset_user();
+                       ret = __ms_user_get_path(THUMB_EXTERNAL, uid, path);
        }
 
        //MSAPI_DBG_SLOG("thumb path [%s]", *path);
@@ -161,18 +204,10 @@ int ms_user_get_media_db_path(uid_t uid, char **path)
 {
        int ret = MS_MEDIA_ERR_NONE;
 
-       if (uid == getuid()) {
-               if (MS_STRING_VALID(MEDIA_DB_NAME))
-                       *path = g_strndup(MEDIA_DB_NAME, strlen(MEDIA_DB_NAME));
-       } else {
-               ret = tzplatform_set_user(uid);
-               MSAPI_RETVM_IF(ret != 0, MS_MEDIA_ERR_INTERNAL, "Invalid UID[%d]", uid);
-
-               if (MS_STRING_VALID(MEDIA_DB_NAME))
-                       *path = g_strndup(MEDIA_DB_NAME, strlen(MEDIA_DB_NAME));
-
-               tzplatform_reset_user();
-       }
+       if (uid == getuid())
+               *path = g_strdup(tzplatform_mkpath(TZ_USER_DB, ".media.db"));
+       else
+               ret = __ms_user_get_path(MEDIA_DB, uid, path);
 
        //MSAPI_DBG_SLOG("DB path [%s]", *path);
 
index 0741f9a..ade40f9 100755 (executable)
@@ -1,6 +1,6 @@
 Name:       media-server
 Summary:    A server for media content management
-Version:    0.3.59
+Version:    0.3.60
 Release:    0
 Group:      Multimedia/Service
 License:    Apache-2.0