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.
36 #include "media-util.h"
37 #include "media-server-ipc.h"
38 #include "media-common-dbg.h"
39 #include "media-common-drm.h"
40 #include "media-common-utils.h"
44 #define MILLION 1000000L
45 struct timeval g_mmc_start_time;
46 struct timeval g_mmc_end_time;
49 #define MS_DRM_CONTENT_TYPE_LENGTH 100
53 ms_check_start_time(struct timeval *start_time)
55 gettimeofday(start_time, NULL);
59 ms_check_end_time(struct timeval *end_time)
61 gettimeofday(end_time, NULL);
65 ms_check_time_diff(struct timeval *start_time, struct timeval *end_time)
70 time.tv_sec = end_time->tv_sec - start_time->tv_sec;
71 time.tv_usec = end_time->tv_usec - start_time->tv_usec;
72 difftime = MILLION * time.tv_sec + time.tv_usec;
73 MS_DBG("The function_to_time took %ld microseconds or %f seconds.",
74 difftime, difftime / (double)MILLION);
79 ms_is_mmc_inserted(void)
82 ms_config_get_int(VCONFKEY_SYSMAN_MMC_STATUS, &data);
83 if (data != VCONFKEY_SYSMAN_MMC_MOUNTED) {
91 ms_get_storage_type_by_full(const char *path)
93 if (strncmp(path, MEDIA_ROOT_PATH_INTERNAL, strlen(MEDIA_ROOT_PATH_INTERNAL)) == 0) {
94 return MS_STORAGE_INTERNAL;
95 } else if (strncmp(path, MEDIA_ROOT_PATH_SDCARD, strlen(MEDIA_ROOT_PATH_SDCARD)) == 0) {
96 return MS_STORAGE_EXTERNAL;
98 return MS_MEDIA_ERR_INVALID_PATH;
102 ms_get_mime(const char *path, char *mimetype)
104 int ret = MS_MEDIA_ERR_NONE;
107 return MS_MEDIA_ERR_INVALID_PARAMETER;
109 /*get content type and mime type from file. */
110 /*in case of drm file. */
111 if (ms_is_drm_file(path)) {
112 if (ms_get_mime_in_drm_info(path, mimetype) != MS_MEDIA_ERR_NONE) {
113 MS_DBG_ERR("Fail to get mime from drm API");
114 if (aul_get_mime_from_file(path, mimetype, 255) < 0) {
115 MS_DBG_ERR("aul_get_mime_from_file fail");
116 ret = MS_MEDIA_ERR_MIME_GET_FAIL;
118 MS_DBG_ERR("aul_get_mime_from_file success");
119 ret = MS_MEDIA_ERR_NONE;
123 /*in case of normal files */
124 if (aul_get_mime_from_file(path, mimetype, 255) < 0) {
125 MS_DBG_ERR("aul_get_mime_from_file fail");
126 ret = MS_MEDIA_ERR_MIME_GET_FAIL;
134 ms_strappend(char *res, const int size, const char *pattern,
135 const char *str1, const char *str2)
138 int real_size = size - 1;
140 if (!res ||!pattern || !str1 ||!str2 )
141 return MS_MEDIA_ERR_INVALID_PARAMETER;
143 if (real_size < (strlen(str1) + strlen(str2)))
144 return MS_MEDIA_ERR_INVALID_PARAMETER;
146 len = snprintf(res, real_size, pattern, str1, str2);
148 return MS_MEDIA_ERR_INVALID_PARAMETER;
153 return MS_MEDIA_ERR_NONE;
157 ms_strcopy(char *res, const int size, const char *pattern, const char *str1)
160 int real_size = size;
162 if (!res || !pattern || !str1) {
163 MS_DBG_ERR("parameta is invalid");
164 return MS_MEDIA_ERR_INVALID_PARAMETER;
167 if (real_size < strlen(str1)) {
168 MS_DBG_ERR("size is wrong");
169 return MS_MEDIA_ERR_INVALID_PARAMETER;
172 len = snprintf(res, real_size, pattern, str1);
174 MS_DBG_ERR("snprintf failed");
175 return MS_MEDIA_ERR_INVALID_PARAMETER;
180 return MS_MEDIA_ERR_NONE;
184 ms_config_get_int(const char *key, int *value)
188 if (!key || !value) {
189 MS_DBG_ERR("Arguments key or value is NULL");
193 err = vconf_get_int(key, value);
199 MS_DBG_ERR("Unexpected error code: %d", err);
205 ms_config_set_int(const char *key, int value)
210 MS_DBG_ERR("Arguments key is NULL");
214 err = vconf_set_int(key, value);
220 MS_DBG_ERR("Unexpected error code: %d", err);
226 ms_config_get_str(const char *key, char *value)
229 if (!key || !value) {
230 MS_DBG_ERR("Arguments key or value is NULL");
234 res = vconf_get_str(key);
236 strncpy(value, res, strlen(res) + 1);
244 ms_config_set_str(const char *key, const char *value)
248 if (!key || !value) {
249 MS_DBG_ERR("Arguments key or value is NULL");
253 err = vconf_set_str(key, value);
257 MS_DBG_ERR("fail to vconf_set_str %d", err);