4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Yong Yeon Kim <yy9875.kim@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
23 * This file defines api utilities of contents manager engines.
25 * @file media-server-utils.c
26 * @author Yong Yeon Kim(yy9875.kim@samsung.com)
28 * @brief This file implements main database operation.
35 #include "media-util.h"
36 #include "media-server-ipc.h"
37 #include "media-common-dbg.h"
38 #include "media-common-drm.h"
39 #include "media-common-utils.h"
43 #define MILLION 1000000L
44 struct timeval g_mmc_start_time;
45 struct timeval g_mmc_end_time;
48 #define MS_DRM_CONTENT_TYPE_LENGTH 100
52 ms_check_start_time(struct timeval *start_time)
54 gettimeofday(start_time, NULL);
58 ms_check_end_time(struct timeval *end_time)
60 gettimeofday(end_time, NULL);
64 ms_check_time_diff(struct timeval *start_time, struct timeval *end_time)
69 time.tv_sec = end_time->tv_sec - start_time->tv_sec;
70 time.tv_usec = end_time->tv_usec - start_time->tv_usec;
71 difftime = MILLION * time.tv_sec + time.tv_usec;
72 MS_DBG("The function_to_time took %ld microseconds or %f seconds.",
73 difftime, difftime / (double)MILLION);
78 ms_is_mmc_inserted(void)
81 ms_config_get_int(VCONFKEY_SYSMAN_MMC_STATUS, &data);
82 if (data != VCONFKEY_SYSMAN_MMC_MOUNTED) {
90 ms_get_storage_type_by_full(const char *path)
92 if (strncmp(path, MEDIA_ROOT_PATH_INTERNAL, strlen(MEDIA_ROOT_PATH_INTERNAL)) == 0) {
93 return MS_STORAGE_INTERNAL;
94 } else if (strncmp(path, MEDIA_ROOT_PATH_SDCARD, strlen(MEDIA_ROOT_PATH_SDCARD)) == 0) {
95 return MS_STORAGE_EXTERNAL;
97 return MS_MEDIA_ERR_INVALID_PATH;
101 ms_get_mime(const char *path, char *mimetype)
103 int ret = MS_MEDIA_ERR_NONE;
106 return MS_MEDIA_ERR_INVALID_PARAMETER;
108 /*get content type and mime type from file. */
109 /*in case of drm file. */
110 if (ms_is_drm_file(path)) {
111 if (ms_get_mime_in_drm_info(path, mimetype) != MS_MEDIA_ERR_NONE) {
112 MS_DBG_ERR("Fail to get mime from drm API");
113 if (aul_get_mime_from_file(path, mimetype, 255) < 0) {
114 MS_DBG_ERR("aul_get_mime_from_file fail");
115 ret = MS_MEDIA_ERR_MIME_GET_FAIL;
117 MS_DBG_ERR("aul_get_mime_from_file success");
118 ret = MS_MEDIA_ERR_NONE;
122 /*in case of normal files */
123 if (aul_get_mime_from_file(path, mimetype, 255) < 0) {
124 MS_DBG_ERR("aul_get_mime_from_file fail");
125 ret = MS_MEDIA_ERR_MIME_GET_FAIL;
133 ms_strappend(char *res, const int size, const char *pattern,
134 const char *str1, const char *str2)
137 int real_size = size - 1;
139 if (!res ||!pattern || !str1 ||!str2 )
140 return MS_MEDIA_ERR_INVALID_PARAMETER;
142 if (real_size < (strlen(str1) + strlen(str2)))
143 return MS_MEDIA_ERR_INVALID_PARAMETER;
145 len = snprintf(res, real_size, pattern, str1, str2);
147 return MS_MEDIA_ERR_INVALID_PARAMETER;
152 return MS_MEDIA_ERR_NONE;
156 ms_strcopy(char *res, const int size, const char *pattern, const char *str1)
159 int real_size = size;
161 if (!res || !pattern || !str1) {
162 MS_DBG_ERR("parameta is invalid");
163 return MS_MEDIA_ERR_INVALID_PARAMETER;
166 if (real_size < strlen(str1)) {
167 MS_DBG_ERR("size is wrong");
168 return MS_MEDIA_ERR_INVALID_PARAMETER;
171 len = snprintf(res, real_size, pattern, str1);
173 MS_DBG_ERR("snprintf failed");
174 return MS_MEDIA_ERR_INVALID_PARAMETER;
179 return MS_MEDIA_ERR_NONE;
183 ms_config_get_int(const char *key, int *value)
187 if (!key || !value) {
188 MS_DBG_ERR("Arguments key or value is NULL");
192 err = vconf_get_int(key, value);
198 MS_DBG_ERR("Unexpected error code: %d", err);
204 ms_config_set_int(const char *key, int value)
209 MS_DBG_ERR("Arguments key is NULL");
213 err = vconf_set_int(key, value);
219 MS_DBG_ERR("Unexpected error code: %d", err);
225 ms_config_get_str(const char *key, char *value)
228 if (!key || !value) {
229 MS_DBG_ERR("Arguments key or value is NULL");
233 res = vconf_get_str(key);
235 strncpy(value, res, strlen(res) + 1);
243 ms_config_set_str(const char *key, const char *value)
247 if (!key || !value) {
248 MS_DBG_ERR("Arguments key or value is NULL");
252 err = vconf_set_str(key, value);
256 MS_DBG_ERR("fail to vconf_set_str %d", err);