4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Hyunjun Ko <zzoon.ko@samsung.com>, Haejeong Kim <backto.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 #include "media-svc-noti.h"
24 #include "media-svc-util.h"
26 static __thread GSList *g_inserted_noti_list = NULL;
27 static __thread int g_noti_from_pid = -1;
29 static void __media_svc_publish_noti_by_item(gpointer data, gpointer user_data)
31 int ret = MS_MEDIA_ERR_NONE;
32 media_svc_noti_item *item = (media_svc_noti_item *)data;
34 if (item && item->path) {
35 ret = media_db_update_send_internal(item->pid, item->update_item, item->update_type, item->path, item->media_uuid, item->media_type, item->mime_type);
36 if (ret != MS_MEDIA_ERR_NONE) {
37 media_svc_sec_error("media_db_update_send_internal failed : %d [%s]", ret, item->path);
39 media_svc_debug("media_db_update_send_internal success");
42 media_svc_debug("invalid path");
46 static void __media_svc_destroy_noti_item(gpointer data)
48 media_svc_noti_item *item = (media_svc_noti_item *)data;
50 SAFE_FREE(item->media_uuid);
51 SAFE_FREE(item->path);
52 SAFE_FREE(item->mime_type);
56 int _media_svc_publish_noti(media_item_update_type_e update_type, const char *path, media_type_e media_type, const char *uuid, const char *mime_type)
58 int ret = MS_MEDIA_ERR_NONE;
59 media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid path");
61 ret = media_db_update_send_internal(getpid(), MS_MEDIA_ITEM_FILE, update_type, (char *)path, (char *)uuid, media_type, (char *)mime_type);
62 media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "Send noti failed[%d][%s]", ret, path);
64 media_svc_debug("Send noti [%s]", path);
69 int _media_svc_publish_dir_noti(media_item_update_type_e update_type, const char *path, const char *uuid, int pid)
71 int ret = MS_MEDIA_ERR_NONE;
72 media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid path");
74 ret = media_db_update_send_internal(pid, MS_MEDIA_ITEM_DIRECTORY, update_type, (char *)path, (char *)uuid, MS_MEDIA_UNKNOWN, NULL);
75 media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "Send dir noti failed[%d][%s]", ret, path);
77 media_svc_debug("Send dir noti [%s]", path);
83 void _media_svc_set_noti_from_pid(int pid)
85 g_noti_from_pid = pid;
88 void _media_svc_initialize_noti_list(void)
90 if (g_inserted_noti_list)
91 g_slist_free_full(g_inserted_noti_list, __media_svc_destroy_noti_item);
93 g_inserted_noti_list = NULL;
96 void _media_svc_insert_item_to_noti_list(media_svc_content_info_s *content_info)
98 media_svc_noti_item *item = NULL;
103 item = (media_svc_noti_item *) malloc(sizeof(media_svc_noti_item));
105 item->pid = g_noti_from_pid;
106 item->update_item = MS_MEDIA_ITEM_INSERT; /* INSERT */
107 item->update_type = MS_MEDIA_ITEM_FILE;
108 item->media_type = content_info->media_type;
109 item->media_uuid = g_strdup(content_info->media_uuid);
110 item->path = g_strdup(content_info->path);
111 item->mime_type = g_strdup(content_info->mime_type);
113 g_inserted_noti_list = g_slist_append(g_inserted_noti_list, (gpointer)item);
115 media_svc_error("Allocation failed");
119 void _media_svc_publish_noti_list(void)
121 g_slist_foreach(g_inserted_noti_list, __media_svc_publish_noti_by_item, NULL);
124 int _media_svc_destroy_noti_item(media_svc_noti_item *item)
127 SAFE_FREE(item->media_uuid);
128 SAFE_FREE(item->path);
129 SAFE_FREE(item->mime_type);
134 return MS_MEDIA_ERR_NONE;