Change MS_MEDIA_ERR_INVALID_PATH to MS_MEDIA_ERR_INVALID_PARAMETER
[platform/core/api/media-content.git] / src / media_content.c
1 /*
2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17
18 #include <media_info_private.h>
19 #include <media_util_private.h>
20
21 static sqlite3 *db_handle = NULL;
22 static int ref_count = 0;
23 static GMutex db_mutex;
24 static uid_t content_g_uid = 0;
25
26 sqlite3 * _content_get_db_handle(void)
27 {
28         return db_handle;
29 }
30
31 uid_t _content_get_uid(void)
32 {
33         if (content_g_uid == 0)
34                 return tzplatform_getuid(TZ_USER_NAME);
35         else
36                 return content_g_uid;
37 }
38
39 int _content_query_prepare(char *select_query, char *condition_query, char *option_query, sqlite3_stmt **stmt)
40 {
41         int ret = MEDIA_CONTENT_ERROR_NONE;
42         char *query = NULL;
43
44         media_content_retvm_if(!STRING_VALID(select_query), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid select_query");
45
46         if (!STRING_VALID(condition_query))
47                 condition_query = (char *)" ";
48
49         if (!STRING_VALID(option_query))
50                 option_query = (char *)" ";
51
52         query = sqlite3_mprintf("%s %s %s", select_query, condition_query, option_query);
53         ret = _content_get_result(query, stmt);
54         SQLITE3_SAFE_FREE(query);
55
56         return ret;
57 }
58
59 int _content_get_result(char *query, sqlite3_stmt **stmt)
60 {
61         int err = MEDIA_CONTENT_ERROR_NONE;
62
63         media_content_retvm_if(_content_get_db_handle() == NULL, MEDIA_CONTENT_ERROR_DB_FAILED, "database is not connected");
64         media_content_retvm_if(!STRING_VALID(query), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid query");
65
66         media_content_sec_debug("Query[%s]", query);
67
68         err = sqlite3_prepare_v2(_content_get_db_handle(), query, strlen(query), stmt, NULL);
69         if (err != SQLITE_OK) {
70                 media_content_error("Failed to sqlite3_prepare_v2[%s]", sqlite3_errmsg(_content_get_db_handle()));
71                 if (err == SQLITE_BUSY)
72                         return MEDIA_CONTENT_ERROR_DB_BUSY;
73                 else if (err == SQLITE_PERM)
74                         return MEDIA_CONTENT_ERROR_PERMISSION_DENIED;
75                 else
76                         return MEDIA_CONTENT_ERROR_DB_FAILED;
77         }
78
79         return MEDIA_CONTENT_ERROR_NONE;
80 }
81
82 #ifdef _USE_SENIOR_MODE
83 int _content_query_prepare_by_union_select(sqlite3_stmt **stmt, char *select_query1, char *condition_query1, char *option_query1, char *select_query2, char *condition_query2, char *option_query2)
84 {
85         int len = 0;
86         int err = MEDIA_CONTENT_ERROR_NONE;
87         char query[MAX_QUERY_SIZE] = {0, };
88         memset(query, '\0', sizeof(query));
89
90         media_content_retvm_if(_content_get_db_handle() == NULL, MEDIA_CONTENT_ERROR_DB_FAILED, "database is not connected");
91         media_content_retvm_if(!STRING_VALID(select_query1), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid select_query1");
92         media_content_retvm_if(!STRING_VALID(select_query2), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid select_query2");
93
94         if (!STRING_VALID(condition_query1))
95                 condition_query1 = (char *)" ";
96
97         if (!STRING_VALID(option_query1))
98                 option_query1 = (char *)" ";
99
100         if (!STRING_VALID(condition_query2))
101                 condition_query2 = (char *)" ";
102
103         if (!STRING_VALID(option_query2))
104                 option_query2 = (char *)" ";
105
106         len = snprintf(query, sizeof(query), "SELECT * FROM (%s %s %s) as table1 UNION ALL SELECT * FROM (%s %s %s) as table2",
107                         select_query1, condition_query1, option_query1, select_query2, condition_query2, option_query2);
108         if (len > 0 && len < sizeof(query)) {
109                 query[len] = '\0';
110         } else if (len >= sizeof(query)) {
111                 query[MAX_QUERY_SIZE -1] = '\0';
112         } else {
113                 media_content_error("snprintf failed");
114                 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
115         }
116
117         media_content_sec_debug("Query : [%s]", query);
118
119         err = sqlite3_prepare_v2(_content_get_db_handle(), query, strlen(query), stmt, NULL);
120         if (err != SQLITE_OK) {
121                 media_content_error("DB_FAILED(0x%08x) fail to sqlite3_prepare(), %s", MEDIA_CONTENT_ERROR_DB_FAILED, sqlite3_errmsg(_content_get_db_handle()));
122
123                 if (err == SQLITE_BUSY) {
124                         media_content_error(" BUSY ERROR");
125                         return MEDIA_CONTENT_ERROR_DB_BUSY;
126                 } else if (err == SQLITE_PERM) {
127                         media_content_error("PERMISSION EROR");
128                         return MEDIA_CONTENT_ERROR_PERMISSION_DENIED;
129                 } else {
130                         media_content_error("OTHER ERROR");
131                         return MEDIA_CONTENT_ERROR_DB_FAILED;
132                 }
133         }
134
135         return MEDIA_CONTENT_ERROR_NONE;
136 }
137 #endif
138
139 int _content_error_capi(int content_error)
140 {
141         if (content_error != MEDIA_CONTENT_ERROR_NONE)
142                 media_content_error("MS Error[%d]", content_error);
143
144         /*Error None*/
145         if (content_error == MS_MEDIA_ERR_NONE)
146                 return MEDIA_CONTENT_ERROR_NONE;
147
148         /* Internal operation error*/
149         else if (content_error == MS_MEDIA_ERR_INVALID_PARAMETER)
150                 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
151
152         else if (content_error == MS_MEDIA_ERR_OUT_OF_MEMORY)
153                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
154
155         /* DB operation error*/
156         else if (content_error == MS_MEDIA_ERR_DB_BUSY_FAIL)
157                 return MEDIA_CONTENT_ERROR_DB_BUSY;
158
159         else if ((content_error <= MS_MEDIA_ERR_DB_CONNECT_FAIL) && (content_error >= MS_MEDIA_ERR_DB_INTERNAL))
160                 return MEDIA_CONTENT_ERROR_DB_FAILED;
161
162         /* IPC operation error*/
163         else if (content_error == MS_MEDIA_ERR_IPC)
164                 return MEDIA_CONTENT_ERROR_NETWORK;
165
166         /* MEDIA SERVER error*/
167         else if (content_error == MS_MEDIA_ERR_PERMISSION_DENIED)
168                 return MEDIA_CONTENT_ERROR_PERMISSION_DENIED;
169
170         /* Thumbnail error*/
171         else if ((content_error == MS_MEDIA_ERR_THUMB_TOO_BIG) || (content_error == MS_MEDIA_ERR_THUMB_UNSUPPORTED))
172                         return MEDIA_CONTENT_ERROR_UNSUPPORTED_CONTENT;
173
174         /*ETC*/
175         return MEDIA_CONTENT_ERROR_INVALID_OPERATION;
176 }
177
178 int _content_query_sql(char *query_str)
179 {
180         int ret = MEDIA_CONTENT_ERROR_NONE;
181
182         /*DB will be updated by Media Server.*/
183         ret = media_db_request_update_db(query_str, _content_get_uid());
184
185         return _content_error_capi(ret);
186 }
187
188 int media_content_connect(void)
189 {
190         int ret = MEDIA_CONTENT_ERROR_NONE;
191
192         g_mutex_lock(&db_mutex);
193         media_content_info("ref count : %d", ref_count);
194
195         if (ref_count == 0) {
196                 if (db_handle == NULL) {
197                         ret = media_db_connect(&db_handle, _content_get_uid(), false);
198                         ret = _content_error_capi(ret);
199                         if (ret == MEDIA_CONTENT_ERROR_NONE)
200                                 ref_count++;
201                 } else {
202                         media_content_error("Wrong DB Connection status");
203                         ret = MEDIA_CONTENT_ERROR_DB_FAILED;
204                 }
205         } else {
206                 if (db_handle != NULL) {
207                         ref_count++;
208                 } else {
209                         media_content_error("Wrong DB Handle status");
210                         ret = MEDIA_CONTENT_ERROR_DB_FAILED;
211                 }
212         }
213
214         media_content_info("ref count changed to: %d", ref_count);
215         g_mutex_unlock(&db_mutex);
216
217         return ret;
218 }
219
220 int media_content_connect_with_uid(uid_t uid)
221 {
222         media_content_sec_debug("media_content_connect_with_uid [%d]", uid);
223         content_g_uid = uid;
224
225         return media_content_connect();
226 }
227
228 int media_content_disconnect(void)
229 {
230         g_mutex_lock(&db_mutex);
231         media_content_debug("ref count : %d", ref_count);
232
233         if (db_handle && ref_count > 0) {
234                 if (--ref_count == 0) {
235                         media_db_disconnect(db_handle);
236                         db_handle = NULL;
237                 }
238         } else {
239                 media_content_error("Database is not connected");
240                 g_mutex_unlock(&db_mutex);
241                 return MEDIA_CONTENT_ERROR_DB_FAILED;
242         }
243
244         g_mutex_unlock(&db_mutex);
245
246         media_content_info("ref count changed to: %d", ref_count);
247
248         return MEDIA_CONTENT_ERROR_NONE;
249 }
250
251 int media_content_scan_file(const char *path)
252 {
253         int ret = MEDIA_CONTENT_ERROR_NONE;
254         bool ignore_file = FALSE;
255         bool ignore_dir = FALSE;
256         char *folder_path = NULL;
257         int check_file = MEDIA_CONTENT_ERROR_NONE;
258         char storage_id[MEDIA_CONTENT_UUID_SIZE+1] = {0,};
259         char repl_path[MAX_PATH_LEN] = {0,};
260
261         media_content_retvm_if(!STRING_VALID(path), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid path");
262
263         media_content_sec_debug("Path : %s", path);
264
265         memset(repl_path, 0, sizeof(repl_path));
266         ret = _media_content_replace_path(path, repl_path);
267         media_content_retvm_if(!STRING_VALID(repl_path), MEDIA_CONTENT_ERROR_INVALID_OPERATION, "path replacement failed");
268
269         ret = _media_util_check_ignore_file(repl_path, &ignore_file);
270         media_content_retvm_if(ignore_file == TRUE, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid path");
271
272         memset(storage_id, 0x00, sizeof(storage_id));
273         ret = media_svc_get_storage_id(_content_get_db_handle(), repl_path, storage_id, _content_get_uid());
274         if (ret != MS_MEDIA_ERR_NONE) {
275                 media_content_error("media_svc_get_storage_id failed : %d", ret);
276                 return _content_error_capi(ret);
277         }
278
279         check_file = _media_util_check_file_exist(repl_path);
280         if (check_file == MEDIA_CONTENT_ERROR_NONE) {
281                 /* This means this path has to be inserted or refreshed */
282                 folder_path = g_path_get_dirname(repl_path);
283                 ret = _media_util_check_ignore_dir(folder_path, &ignore_dir);
284                 SAFE_FREE(folder_path);
285
286                 media_content_retvm_if(ignore_dir == TRUE, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid folder path");
287                 /* check feature */
288                 media_content_retvm_if(!_media_util_check_support_media_type(repl_path), MEDIA_CONTENT_ERROR_NOT_SUPPORTED, "Unsupported media type");
289
290                 ms_user_storage_type_e storage_type;
291
292                 ret = ms_user_get_storage_type(_content_get_uid(), repl_path, &storage_type);
293                 if (ret != MS_MEDIA_ERR_NONE) {
294                         media_content_sec_error("ms_user_get_storage_type failed : %d (%s)", ret, repl_path);
295                         return _content_error_capi(ret);
296                 }
297                 ret = media_svc_check_item_exist_by_path(_content_get_db_handle(), storage_id, repl_path);
298                 if (ret == MS_MEDIA_ERR_NONE) {
299                         /* Refresh */
300                         ret = media_svc_refresh_item(_content_get_db_handle(), false, storage_id, storage_type, repl_path, _content_get_uid());
301                         if (ret != MS_MEDIA_ERR_NONE) {
302                                 media_content_error("media_svc_refresh_item failed : %d", ret);
303                                 return _content_error_capi(ret);
304                         }
305
306                 } else if (ret == MS_MEDIA_ERR_DB_NO_RECORD) {
307                         /* Insert */
308                         ret = media_svc_insert_item_immediately(_content_get_db_handle(), storage_id, storage_type, repl_path, _content_get_uid());
309                         if (ret != MS_MEDIA_ERR_NONE) {
310                                 if (ret == MS_MEDIA_ERR_DB_CONSTRAINT_FAIL) {
311                                         media_content_sec_error("This item is already inserted. This may be normal operation because other process already did this (%s)", repl_path);
312                                         ret = MEDIA_CONTENT_ERROR_NONE;
313                                 } else {
314                                         media_content_sec_error("media_svc_insert_item_immediately failed : %d (%s)", ret, repl_path);
315                                 }
316
317                                 return _content_error_capi(ret);
318                         }
319                 } else {
320                         media_content_error("media_svc_check_item_exist_by_path failed : %d", ret);
321                         return _content_error_capi(ret);
322                 }
323         } else if (check_file == MEDIA_CONTENT_ERROR_PERMISSION_DENIED) {
324                 media_content_error("You have no permission for this file %d", ret);
325                 return MEDIA_CONTENT_ERROR_PERMISSION_DENIED;
326         } else {
327                 /* This means this path has to be deleted */
328                 media_content_debug("This path doesn't exists in file system... So now start to delete it from DB");
329                 ret = media_svc_delete_item_by_path(_content_get_db_handle(), storage_id, repl_path, _content_get_uid());
330                 if (ret != MS_MEDIA_ERR_NONE) {
331                         if (ret == MS_MEDIA_ERR_DB_NO_RECORD) {
332                                 media_content_error("Does not exist in media DB also... So, this is an invalid parameter");
333                                 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
334                         }
335
336                         media_content_error("media_svc_delete_item_by_path failed : %d", ret);
337                         return _content_error_capi(ret);
338                 }
339         }
340
341         return _content_error_capi(ret);
342 }
343
344 void _media_content_scan_cb(media_request_result_s* result, void *user_data)
345 {
346         int err = -1;
347         media_content_scan_cb_data *cb_data = user_data;
348
349         err = _content_error_capi(result->result);
350 #ifdef _USE_TVPD_MODE
351         if (result->request_type != MEDIA_REQUEST_SCAN_COMPLETE &&
352                 result->request_type != MEDIA_REQUEST_SCAN_PARTIAL) {
353                 if (cb_data && cb_data->callback) {
354                         media_content_debug("begin:User callback is being called now, result=%d", err);
355                         cb_data->callback(err, cb_data->user_data);
356                         media_content_debug("end:User callback is being called now, result=%d", err);
357                 }
358
359                 SAFE_FREE(cb_data);
360         }
361 #else
362         if (cb_data && cb_data->callback) {
363                 media_content_debug("User callback is being called now");
364                 cb_data->callback(err, cb_data->user_data);
365         }
366
367         SAFE_FREE(cb_data);
368 #endif
369
370         return;
371 }
372
373 #ifdef _USE_TVPD_MODE
374 void _media_content_scan_cb_v2(media_request_result_s* result, void *user_data)
375 {
376         int err = -1;
377         media_content_scan_cb_data_v2 *cb_data = user_data;
378         media_content_complete_phase_e complete_phase = -1;
379         if (!cb_data)
380                 media_content_debug("cb_data is NULL");
381         err = _content_error_capi(result->result);
382         media_content_debug("result is %d", err);
383
384         if (result->request_type == MEDIA_REQUEST_SCAN_PARTIAL)
385                 complete_phase = MEDIA_CONTENT_SCAN_PARTIAL_COMPLETE;
386         else if (result->request_type == MEDIA_REQUEST_SCAN_COMPLETE)
387                 complete_phase = MEDIA_CONTENT_SCAN_COMPLETE;
388         else if (result->request_type == MEDIA_REQUEST_EXTRACT_COMPLETE)
389                 complete_phase = MEDIA_CONTENT_EXTRACT_COMPLETE;
390
391         if (cb_data && cb_data->callback)
392                 cb_data->callback(err, complete_phase, cb_data->user_data);
393         else
394                 media_content_debug("run error");
395
396         if ((result->request_type != MEDIA_REQUEST_SCAN_COMPLETE) &&
397         (result->request_type != MEDIA_REQUEST_SCAN_PARTIAL))
398                 SAFE_FREE(cb_data);
399
400         return;
401 }
402 #endif
403
404 int media_content_scan_folder(const char *path, bool is_recursive, media_scan_completed_cb callback, void *user_data)
405 {
406         int ret = MEDIA_CONTENT_ERROR_NONE;
407         bool ignore_dir = FALSE;
408         char storage_id[MEDIA_CONTENT_UUID_SIZE+1] = {0, };
409         char repl_path[MAX_PATH_LEN] = {0, };
410         ms_user_storage_type_e storage_type = MS_USER_STORAGE_INTERNAL;
411
412         media_content_retvm_if(!STRING_VALID(path), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid path");
413         memset(repl_path, 0, sizeof(repl_path));
414         ret = _media_content_replace_path(path, repl_path);
415         media_content_retvm_if(!STRING_VALID(repl_path), MEDIA_CONTENT_ERROR_INVALID_OPERATION, "path replacement failed");
416
417         memset(storage_id, 0x00, sizeof(storage_id));
418
419         ret = _media_content_check_dir(repl_path);
420         media_content_retvm_if(ret == MEDIA_CONTENT_ERROR_PERMISSION_DENIED, ret, "Permission Denied");
421
422         if (ret == MEDIA_CONTENT_ERROR_NONE) {
423                 /* If directory exist check that's ignore directory or not*/
424                 ret = _media_util_check_ignore_dir(repl_path, &ignore_dir);
425                 media_content_retvm_if((ignore_dir == TRUE || ret != MEDIA_CONTENT_ERROR_NONE), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid folder path");
426         } else {
427                 /* This means this folder has to be deleted */
428                 /* Or, it is real invalid path.. check storage type */
429                 ret = ms_user_get_storage_type(_content_get_uid(), repl_path, &storage_type);
430                 if (ret != MS_MEDIA_ERR_NONE) {
431                         media_content_sec_error("ms_user_get_storage_type failed : %d (%s)", ret, repl_path);
432                         return _content_error_capi(ret);
433                 }
434
435                 media_content_debug("This path doesn't exists in file system... So will be deleted it from DB");
436         }
437
438         ret = media_svc_get_storage_id(_content_get_db_handle(), repl_path, storage_id, _content_get_uid());
439         if (ret != MS_MEDIA_ERR_NONE) {
440                 media_content_error("media_svc_get_storage_id failed : %d", ret);
441                 return _content_error_capi(ret);
442         }
443
444         media_content_scan_cb_data *cb_data = NULL;
445         cb_data = (media_content_scan_cb_data *)malloc(sizeof(media_content_scan_cb_data));
446         media_content_retvm_if(cb_data == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
447
448         cb_data->callback = callback;
449         cb_data->user_data = user_data;
450
451         ret = media_directory_scanning_async(repl_path, storage_id, is_recursive, _media_content_scan_cb, cb_data, _content_get_uid());
452         if (ret != MS_MEDIA_ERR_NONE) {
453                 media_content_error("media_directory_scanning_async failed : %d", ret);
454                 SAFE_FREE(cb_data);
455         }
456
457         return _content_error_capi(ret);
458 }
459
460 #ifdef _USE_TVPD_MODE
461 int media_content_scan_folder_v2(const char *path, bool is_recursive, media_scan_completed_cb_v2 callback, void *user_data)
462 {
463         int ret = MEDIA_CONTENT_ERROR_NONE;
464         bool ignore_dir = FALSE;
465         char storage_id[MEDIA_CONTENT_UUID_SIZE+1] = {0, };
466
467         media_content_retvm_if(!STRING_VALID(path), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid path");
468         memset(storage_id, 0x00, sizeof(storage_id));
469
470         ret = _media_util_check_ignore_dir(path, &ignore_dir);
471         media_content_retvm_if(ignore_dir, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid folder path");
472
473         ret = _media_content_check_dir(path);
474         media_content_retvm_if(ret == MEDIA_CONTENT_ERROR_PERMISSION_DENIED, ret, "Permission Denied");
475         media_content_retvm_if(ret == MEDIA_CONTENT_ERROR_INVALID_PARAMETER, ret, "invalid path[%s]", path);
476
477         media_content_scan_cb_data_v2* cb_data = NULL;
478         cb_data = (media_content_scan_cb_data_v2*)malloc(sizeof(media_content_scan_cb_data_v2));
479         media_content_retvm_if(cb_data == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
480
481         cb_data->callback = callback;
482         cb_data->user_data = user_data;
483
484         ret = media_svc_get_storage_id(_content_get_db_handle(), path, storage_id, _content_get_uid());
485         /*FIX ME. need to check ret value?*/
486
487         ret = media_directory_scanning_async(path, storage_id, is_recursive, _media_content_scan_cb_v2, cb_data, _content_get_uid());
488         if (ret != MS_MEDIA_ERR_NONE)
489                 media_content_error("media_directory_scanning_async failed : %d", ret);
490
491         return _content_error_capi(ret);
492 }
493 #endif
494
495 int media_content_cancel_scan_folder(const char *path)
496 {
497         int ret = MEDIA_CONTENT_ERROR_NONE;
498         char repl_path[MAX_PATH_LEN] = {0, };
499
500         media_content_retvm_if(!STRING_VALID(path), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid path");
501
502         memset(repl_path, 0, sizeof(repl_path));
503         ret = _media_content_replace_path(path, repl_path);
504         media_content_retvm_if(!STRING_VALID(repl_path), MEDIA_CONTENT_ERROR_INVALID_OPERATION, "path replacement failed");
505
506         ret = media_directory_scanning_cancel(repl_path, _content_get_uid());
507         if (ret != MS_MEDIA_ERR_NONE)
508                 media_content_error("media_directory_scanning_async failed : %d", ret);
509
510         return _content_error_capi(ret);
511 }
512
513 void _media_content_db_update_noti_cb(
514                                                         int pid,
515                                                         media_item_type_e item,
516                                                         media_item_update_type_e update_type,
517                                                         char* path,
518                                                         char* uuid,
519                                                         media_type_e content_type,
520                                                         char *mime_type,
521                                                         void *user_data)
522 {
523         media_noti_cb_s *_noti_info = (media_noti_cb_s *)user_data;
524
525         if (_noti_info != NULL && _noti_info->update_noti_cb)
526                 _noti_info->update_noti_cb(
527                                         MEDIA_CONTENT_ERROR_NONE,
528                                         pid,
529                                         item,
530                                         update_type,
531                                         content_type,
532                                         uuid,
533                                         path,
534                                         mime_type,
535                                         _noti_info->user_data);
536 }
537
538 int media_content_add_db_updated_cb(media_content_db_update_cb callback, void *user_data, media_content_noti_h *noti_handle)
539 {
540         int ret = MEDIA_CONTENT_ERROR_NONE;
541         media_noti_cb_s *noti_info = NULL;
542
543         media_content_retvm_if(noti_handle == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "handle is NULL");
544         media_content_retvm_if(callback == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "callback is NULL");
545
546         noti_info = (media_noti_cb_s *)calloc(1, sizeof(media_noti_cb_s));
547         media_content_retvm_if(noti_info == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "Failed to create noti info");
548
549         noti_info->update_noti_cb = callback;
550         noti_info->user_data = user_data;
551
552         ret = media_db_update_subscribe_internal((MediaNotiHandle*)noti_handle, _media_content_db_update_noti_cb, (void *)noti_info);
553
554         return _content_error_capi(ret);
555 }
556
557 #ifdef TIZEN_FEATURE_COMPATIBILITY
558 int media_content_set_db_updated_cb(media_content_db_update_cb callback, void *user_data)
559 {
560         media_content_warn("DEPRECATION WARNING: media_content_set_db_updated_cb() is removed from 5.0.");
561
562         return MEDIA_CONTENT_ERROR_NONE;
563 }
564 #endif
565
566 void __media_content_clear_user_data(void *user_data)
567 {
568         media_noti_cb_s *noti_info = user_data;
569
570         SAFE_FREE(noti_info);
571
572         return;
573 }
574
575 int media_content_remove_db_updated_cb(media_content_noti_h noti_handle)
576 {
577         int ret = MEDIA_CONTENT_ERROR_NONE;
578
579         ret = media_db_update_unsubscribe_internal((MediaNotiHandle)noti_handle, __media_content_clear_user_data);
580
581         return _content_error_capi(ret);
582 }
583 #ifdef _USE_TVPD_MODE
584 GMutex* _content_get_db_mutex(void)
585 {
586         return &db_mutex;
587 }
588 #endif