Integrate IPC related errors
[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                 (content_error == MS_MEDIA_ERR_INVALID_PATH))
151                 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
152
153         else if (content_error == MS_MEDIA_ERR_OUT_OF_MEMORY)
154                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
155
156         /* DB operation error*/
157         else if (content_error == MS_MEDIA_ERR_DB_BUSY_FAIL)
158                 return MEDIA_CONTENT_ERROR_DB_BUSY;
159
160         else if ((content_error <= MS_MEDIA_ERR_DB_CONNECT_FAIL) && (content_error >= MS_MEDIA_ERR_DB_INTERNAL))
161                 return MEDIA_CONTENT_ERROR_DB_FAILED;
162
163         /* IPC operation error*/
164         else if (content_error == MS_MEDIA_ERR_IPC)
165                 return MEDIA_CONTENT_ERROR_NETWORK;
166
167         /* MEDIA SERVER error*/
168         else if (content_error == MS_MEDIA_ERR_PERMISSION_DENIED)
169                 return MEDIA_CONTENT_ERROR_PERMISSION_DENIED;
170
171         /* Thumbnail error*/
172         else if ((content_error == MS_MEDIA_ERR_THUMB_TOO_BIG) || (content_error == MS_MEDIA_ERR_THUMB_UNSUPPORTED))
173                         return MEDIA_CONTENT_ERROR_UNSUPPORTED_CONTENT;
174
175         /*ETC*/
176         return MEDIA_CONTENT_ERROR_INVALID_OPERATION;
177 }
178
179 int _content_query_sql(char *query_str)
180 {
181         int ret = MEDIA_CONTENT_ERROR_NONE;
182
183         /*DB will be updated by Media Server.*/
184         ret = media_db_request_update_db(query_str, _content_get_uid());
185
186         return _content_error_capi(ret);
187 }
188
189 int media_content_connect(void)
190 {
191         int ret = MEDIA_CONTENT_ERROR_NONE;
192
193         g_mutex_lock(&db_mutex);
194         media_content_info("ref count : %d", ref_count);
195
196         if (ref_count == 0) {
197                 if (db_handle == NULL) {
198                         ret = media_db_connect(&db_handle, _content_get_uid(), false);
199                         ret = _content_error_capi(ret);
200                         if (ret == MEDIA_CONTENT_ERROR_NONE)
201                                 ref_count++;
202                 } else {
203                         media_content_error("Wrong DB Connection status");
204                         ret = MEDIA_CONTENT_ERROR_DB_FAILED;
205                 }
206         } else {
207                 if (db_handle != NULL) {
208                         ref_count++;
209                 } else {
210                         media_content_error("Wrong DB Handle status");
211                         ret = MEDIA_CONTENT_ERROR_DB_FAILED;
212                 }
213         }
214
215         media_content_info("ref count changed to: %d", ref_count);
216         g_mutex_unlock(&db_mutex);
217
218         return ret;
219 }
220
221 int media_content_connect_with_uid(uid_t uid)
222 {
223         media_content_sec_debug("media_content_connect_with_uid [%d]", uid);
224         content_g_uid = uid;
225
226         return media_content_connect();
227 }
228
229 int media_content_disconnect(void)
230 {
231         g_mutex_lock(&db_mutex);
232         media_content_debug("ref count : %d", ref_count);
233
234         if (db_handle && ref_count > 0) {
235                 if (--ref_count == 0) {
236                         media_db_disconnect(db_handle);
237                         db_handle = NULL;
238                 }
239         } else {
240                 media_content_error("Database is not connected");
241                 g_mutex_unlock(&db_mutex);
242                 return MEDIA_CONTENT_ERROR_DB_FAILED;
243         }
244
245         g_mutex_unlock(&db_mutex);
246
247         media_content_info("ref count changed to: %d", ref_count);
248
249         return MEDIA_CONTENT_ERROR_NONE;
250 }
251
252 int media_content_scan_file(const char *path)
253 {
254         int ret = MEDIA_CONTENT_ERROR_NONE;
255         bool ignore_file = FALSE;
256         bool ignore_dir = FALSE;
257         char *folder_path = NULL;
258         int check_file = MEDIA_CONTENT_ERROR_NONE;
259         char storage_id[MEDIA_CONTENT_UUID_SIZE+1] = {0,};
260         char repl_path[MAX_PATH_LEN] = {0,};
261
262         media_content_retvm_if(!STRING_VALID(path), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid path");
263
264         media_content_sec_debug("Path : %s", path);
265
266         memset(repl_path, 0, sizeof(repl_path));
267         ret = _media_content_replace_path(path, repl_path);
268         media_content_retvm_if(!STRING_VALID(repl_path), MEDIA_CONTENT_ERROR_INVALID_OPERATION, "path replacement failed");
269
270         ret = _media_util_check_ignore_file(repl_path, &ignore_file);
271         media_content_retvm_if(ignore_file == TRUE, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid path");
272
273         memset(storage_id, 0x00, sizeof(storage_id));
274         ret = media_svc_get_storage_id(_content_get_db_handle(), repl_path, storage_id, _content_get_uid());
275         if (ret != MS_MEDIA_ERR_NONE) {
276                 media_content_error("media_svc_get_storage_id failed : %d", ret);
277                 return _content_error_capi(ret);
278         }
279
280         check_file = _media_util_check_file_exist(repl_path);
281         if (check_file == MEDIA_CONTENT_ERROR_NONE) {
282                 /* This means this path has to be inserted or refreshed */
283                 folder_path = g_path_get_dirname(repl_path);
284                 ret = _media_util_check_ignore_dir(folder_path, &ignore_dir);
285                 SAFE_FREE(folder_path);
286
287                 media_content_retvm_if(ignore_dir == TRUE, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid folder path");
288                 /* check feature */
289                 media_content_retvm_if(!_media_util_check_support_media_type(repl_path), MEDIA_CONTENT_ERROR_NOT_SUPPORTED, "Unsupported media type");
290
291                 ms_user_storage_type_e storage_type;
292
293                 ret = ms_user_get_storage_type(_content_get_uid(), repl_path, &storage_type);
294                 if (ret != MS_MEDIA_ERR_NONE) {
295                         media_content_sec_error("ms_user_get_storage_type failed : %d (%s)", ret, repl_path);
296                         return _content_error_capi(ret);
297                 }
298                 ret = media_svc_check_item_exist_by_path(_content_get_db_handle(), storage_id, repl_path);
299                 if (ret == MS_MEDIA_ERR_NONE) {
300                         /* Refresh */
301                         ret = media_svc_refresh_item(_content_get_db_handle(), false, storage_id, storage_type, repl_path, _content_get_uid());
302                         if (ret != MS_MEDIA_ERR_NONE) {
303                                 media_content_error("media_svc_refresh_item failed : %d", ret);
304                                 return _content_error_capi(ret);
305                         }
306
307                 } else if (ret == MS_MEDIA_ERR_DB_NO_RECORD) {
308                         /* Insert */
309                         ret = media_svc_insert_item_immediately(_content_get_db_handle(), storage_id, storage_type, repl_path, _content_get_uid());
310                         if (ret != MS_MEDIA_ERR_NONE) {
311                                 if (ret == MS_MEDIA_ERR_DB_CONSTRAINT_FAIL) {
312                                         media_content_sec_error("This item is already inserted. This may be normal operation because other process already did this (%s)", repl_path);
313                                         ret = MEDIA_CONTENT_ERROR_NONE;
314                                 } else {
315                                         media_content_sec_error("media_svc_insert_item_immediately failed : %d (%s)", ret, repl_path);
316                                 }
317
318                                 return _content_error_capi(ret);
319                         }
320                 } else {
321                         media_content_error("media_svc_check_item_exist_by_path failed : %d", ret);
322                         return _content_error_capi(ret);
323                 }
324         } else if (check_file == MEDIA_CONTENT_ERROR_PERMISSION_DENIED) {
325                 media_content_error("You have no permission for this file %d", ret);
326                 return MEDIA_CONTENT_ERROR_PERMISSION_DENIED;
327         } else {
328                 /* This means this path has to be deleted */
329                 media_content_debug("This path doesn't exists in file system... So now start to delete it from DB");
330                 ret = media_svc_delete_item_by_path(_content_get_db_handle(), storage_id, repl_path, _content_get_uid());
331                 if (ret != MS_MEDIA_ERR_NONE) {
332                         if (ret == MS_MEDIA_ERR_DB_NO_RECORD) {
333                                 media_content_error("Does not exist in media DB also... So, this is an invalid parameter");
334                                 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
335                         }
336
337                         media_content_error("media_svc_delete_item_by_path failed : %d", ret);
338                         return _content_error_capi(ret);
339                 }
340         }
341
342         return _content_error_capi(ret);
343 }
344
345 void _media_content_scan_cb(media_request_result_s* result, void *user_data)
346 {
347         int err = -1;
348         media_content_scan_cb_data *cb_data = user_data;
349
350         err = _content_error_capi(result->result);
351 #ifdef _USE_TVPD_MODE
352         if (result->request_type != MEDIA_REQUEST_SCAN_COMPLETE &&
353                 result->request_type != MEDIA_REQUEST_SCAN_PARTIAL) {
354                 if (cb_data && cb_data->callback) {
355                         media_content_debug("begin:User callback is being called now, result=%d", err);
356                         cb_data->callback(err, cb_data->user_data);
357                         media_content_debug("end:User callback is being called now, result=%d", err);
358                 }
359
360                 SAFE_FREE(cb_data);
361         }
362 #else
363         if (cb_data && cb_data->callback) {
364                 media_content_debug("User callback is being called now");
365                 cb_data->callback(err, cb_data->user_data);
366         }
367
368         SAFE_FREE(cb_data);
369 #endif
370
371         return;
372 }
373
374 #ifdef _USE_TVPD_MODE
375 void _media_content_scan_cb_v2(media_request_result_s* result, void *user_data)
376 {
377         int err = -1;
378         media_content_scan_cb_data_v2 *cb_data = user_data;
379         media_content_complete_phase_e complete_phase = -1;
380         if (!cb_data)
381                 media_content_debug("cb_data is NULL");
382         err = _content_error_capi(result->result);
383         media_content_debug("result is %d", err);
384
385         if (result->request_type == MEDIA_REQUEST_SCAN_PARTIAL)
386                 complete_phase = MEDIA_CONTENT_SCAN_PARTIAL_COMPLETE;
387         else if (result->request_type == MEDIA_REQUEST_SCAN_COMPLETE)
388                 complete_phase = MEDIA_CONTENT_SCAN_COMPLETE;
389         else if (result->request_type == MEDIA_REQUEST_EXTRACT_COMPLETE)
390                 complete_phase = MEDIA_CONTENT_EXTRACT_COMPLETE;
391
392         if (cb_data && cb_data->callback)
393                 cb_data->callback(err, complete_phase, cb_data->user_data);
394         else
395                 media_content_debug("run error");
396
397         if ((result->request_type != MEDIA_REQUEST_SCAN_COMPLETE) &&
398         (result->request_type != MEDIA_REQUEST_SCAN_PARTIAL))
399                 SAFE_FREE(cb_data);
400
401         return;
402 }
403 #endif
404
405 int media_content_scan_folder(const char *path, bool is_recursive, media_scan_completed_cb callback, void *user_data)
406 {
407         int ret = MEDIA_CONTENT_ERROR_NONE;
408         bool ignore_dir = FALSE;
409         char storage_id[MEDIA_CONTENT_UUID_SIZE+1] = {0, };
410         char repl_path[MAX_PATH_LEN] = {0, };
411         ms_user_storage_type_e storage_type = MS_USER_STORAGE_INTERNAL;
412
413         media_content_retvm_if(!STRING_VALID(path), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid path");
414         memset(repl_path, 0, sizeof(repl_path));
415         ret = _media_content_replace_path(path, repl_path);
416         media_content_retvm_if(!STRING_VALID(repl_path), MEDIA_CONTENT_ERROR_INVALID_OPERATION, "path replacement failed");
417
418         memset(storage_id, 0x00, sizeof(storage_id));
419
420         ret = _media_content_check_dir(repl_path);
421         media_content_retvm_if(ret == MEDIA_CONTENT_ERROR_PERMISSION_DENIED, ret, "Permission Denied");
422
423         if (ret == MEDIA_CONTENT_ERROR_NONE) {
424                 /* If directory exist check that's ignore directory or not*/
425                 ret = _media_util_check_ignore_dir(repl_path, &ignore_dir);
426                 media_content_retvm_if((ignore_dir == TRUE || ret != MEDIA_CONTENT_ERROR_NONE), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid folder path");
427         } else {
428                 /* This means this folder has to be deleted */
429                 /* Or, it is real invalid path.. check storage type */
430                 ret = ms_user_get_storage_type(_content_get_uid(), repl_path, &storage_type);
431                 if (ret != MS_MEDIA_ERR_NONE) {
432                         media_content_sec_error("ms_user_get_storage_type failed : %d (%s)", ret, repl_path);
433                         return _content_error_capi(ret);
434                 }
435
436                 media_content_debug("This path doesn't exists in file system... So will be deleted it from DB");
437         }
438
439         ret = media_svc_get_storage_id(_content_get_db_handle(), repl_path, storage_id, _content_get_uid());
440         if (ret != MS_MEDIA_ERR_NONE) {
441                 media_content_error("media_svc_get_storage_id failed : %d", ret);
442                 return _content_error_capi(ret);
443         }
444
445         media_content_scan_cb_data *cb_data = NULL;
446         cb_data = (media_content_scan_cb_data *)malloc(sizeof(media_content_scan_cb_data));
447         media_content_retvm_if(cb_data == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
448
449         cb_data->callback = callback;
450         cb_data->user_data = user_data;
451
452         ret = media_directory_scanning_async(repl_path, storage_id, is_recursive, _media_content_scan_cb, cb_data, _content_get_uid());
453         if (ret != MS_MEDIA_ERR_NONE) {
454                 media_content_error("media_directory_scanning_async failed : %d", ret);
455                 SAFE_FREE(cb_data);
456         }
457
458         return _content_error_capi(ret);
459 }
460
461 #ifdef _USE_TVPD_MODE
462 int media_content_scan_folder_v2(const char *path, bool is_recursive, media_scan_completed_cb_v2 callback, void *user_data)
463 {
464         int ret = MEDIA_CONTENT_ERROR_NONE;
465         bool ignore_dir = FALSE;
466         char storage_id[MEDIA_CONTENT_UUID_SIZE+1] = {0, };
467
468         media_content_retvm_if(!STRING_VALID(path), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid path");
469         memset(storage_id, 0x00, sizeof(storage_id));
470
471         ret = _media_util_check_ignore_dir(path, &ignore_dir);
472         media_content_retvm_if(ignore_dir, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid folder path");
473
474         ret = _media_content_check_dir(path);
475         media_content_retvm_if(ret == MEDIA_CONTENT_ERROR_PERMISSION_DENIED, ret, "Permission Denied");
476         media_content_retvm_if(ret == MEDIA_CONTENT_ERROR_INVALID_PARAMETER, ret, "invalid path[%s]", path);
477
478         media_content_scan_cb_data_v2* cb_data = NULL;
479         cb_data = (media_content_scan_cb_data_v2*)malloc(sizeof(media_content_scan_cb_data_v2));
480         media_content_retvm_if(cb_data == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
481
482         cb_data->callback = callback;
483         cb_data->user_data = user_data;
484
485         ret = media_svc_get_storage_id(_content_get_db_handle(), path, storage_id, _content_get_uid());
486         /*FIX ME. need to check ret value?*/
487
488         ret = media_directory_scanning_async(path, storage_id, is_recursive, _media_content_scan_cb_v2, cb_data, _content_get_uid());
489         if (ret != MS_MEDIA_ERR_NONE)
490                 media_content_error("media_directory_scanning_async failed : %d", ret);
491
492         return _content_error_capi(ret);
493 }
494 #endif
495
496 int media_content_cancel_scan_folder(const char *path)
497 {
498         int ret = MEDIA_CONTENT_ERROR_NONE;
499         char repl_path[MAX_PATH_LEN] = {0, };
500
501         media_content_retvm_if(!STRING_VALID(path), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid path");
502
503         memset(repl_path, 0, sizeof(repl_path));
504         ret = _media_content_replace_path(path, repl_path);
505         media_content_retvm_if(!STRING_VALID(repl_path), MEDIA_CONTENT_ERROR_INVALID_OPERATION, "path replacement failed");
506
507         ret = media_directory_scanning_cancel(repl_path, _content_get_uid());
508         if (ret != MS_MEDIA_ERR_NONE)
509                 media_content_error("media_directory_scanning_async failed : %d", ret);
510
511         return _content_error_capi(ret);
512 }
513
514 void _media_content_db_update_noti_cb(
515                                                         int pid,
516                                                         media_item_type_e item,
517                                                         media_item_update_type_e update_type,
518                                                         char* path,
519                                                         char* uuid,
520                                                         media_type_e content_type,
521                                                         char *mime_type,
522                                                         void *user_data)
523 {
524         media_noti_cb_s *_noti_info = (media_noti_cb_s *)user_data;
525
526         if (_noti_info != NULL && _noti_info->update_noti_cb)
527                 _noti_info->update_noti_cb(
528                                         MEDIA_CONTENT_ERROR_NONE,
529                                         pid,
530                                         item,
531                                         update_type,
532                                         content_type,
533                                         uuid,
534                                         path,
535                                         mime_type,
536                                         _noti_info->user_data);
537 }
538
539 int media_content_add_db_updated_cb(media_content_db_update_cb callback, void *user_data, media_content_noti_h *noti_handle)
540 {
541         int ret = MEDIA_CONTENT_ERROR_NONE;
542         media_noti_cb_s *noti_info = NULL;
543
544         media_content_retvm_if(noti_handle == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "handle is NULL");
545         media_content_retvm_if(callback == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "callback is NULL");
546
547         noti_info = (media_noti_cb_s *)calloc(1, sizeof(media_noti_cb_s));
548         media_content_retvm_if(noti_info == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "Failed to create noti info");
549
550         noti_info->update_noti_cb = callback;
551         noti_info->user_data = user_data;
552
553         ret = media_db_update_subscribe_internal((MediaNotiHandle*)noti_handle, _media_content_db_update_noti_cb, (void *)noti_info);
554
555         return _content_error_capi(ret);
556 }
557
558 #ifdef TIZEN_FEATURE_COMPATIBILITY
559 int media_content_set_db_updated_cb(media_content_db_update_cb callback, void *user_data)
560 {
561         media_content_warn("DEPRECATION WARNING: media_content_set_db_updated_cb() is removed from 5.0.");
562
563         return MEDIA_CONTENT_ERROR_NONE;
564 }
565 #endif
566
567 void __media_content_clear_user_data(void *user_data)
568 {
569         media_noti_cb_s *noti_info = user_data;
570
571         SAFE_FREE(noti_info);
572
573         return;
574 }
575
576 int media_content_remove_db_updated_cb(media_content_noti_h noti_handle)
577 {
578         int ret = MEDIA_CONTENT_ERROR_NONE;
579
580         ret = media_db_update_unsubscribe_internal((MediaNotiHandle)noti_handle, __media_content_clear_user_data);
581
582         return _content_error_capi(ret);
583 }
584 #ifdef _USE_TVPD_MODE
585 GMutex* _content_get_db_mutex(void)
586 {
587         return &db_mutex;
588 }
589 #endif