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 int __media_svc_publish_noti_by_item(media_svc_noti_item *noti_item);
28 static __thread media_svc_noti_item *g_inserted_noti_list = NULL;
29 static __thread int g_noti_from_pid = -1;
31 static int __media_svc_publish_noti_by_item(media_svc_noti_item *noti_item)
33 int ret = MS_MEDIA_ERR_NONE;
35 if (noti_item && noti_item->path) {
36 ret = media_db_update_send(noti_item->pid, noti_item->update_item, noti_item->update_type, noti_item->path, noti_item->media_uuid, noti_item->media_type, noti_item->mime_type);
37 if (ret != MS_MEDIA_ERR_NONE) {
38 media_svc_error("media_db_update_send failed : %d [%s]", ret, noti_item->path);
39 ret = MS_MEDIA_ERR_SEND_NOTI_FAIL;
41 media_svc_debug("media_db_update_send success");
44 media_svc_debug("invalid path");
45 ret = MS_MEDIA_ERR_INVALID_PARAMETER;
51 int _media_svc_publish_noti(media_item_type_e update_item,
52 media_item_update_type_e update_type,
54 media_type_e media_type,
59 int ret = MS_MEDIA_ERR_NONE;
61 if (STRING_VALID(path)) {
62 ret = media_db_update_send(getpid(), update_item, update_type, (char *)path, (char *)uuid, media_type, (char *)mime_type);
63 if (ret != MS_MEDIA_ERR_NONE) {
64 media_svc_error("Send noti failed : %d [%s]", ret, path);
65 ret = MS_MEDIA_ERR_SEND_NOTI_FAIL;
67 media_svc_debug("Send noti success [%d][%d]", update_item, update_type);
70 media_svc_debug("invalid path");
71 ret = MS_MEDIA_ERR_INVALID_PARAMETER;
77 int _media_svc_publish_dir_noti(media_item_type_e update_item,
78 media_item_update_type_e update_type,
80 media_type_e media_type,
82 const char *mime_type,
86 int ret = MS_MEDIA_ERR_NONE;
88 if (STRING_VALID(path)) {
89 ret = media_db_update_send(pid, update_item, update_type, (char *)path, (char *)uuid, media_type, (char *)mime_type);
90 if (ret != MS_MEDIA_ERR_NONE) {
91 media_svc_error("Send noti failed : %d [%s]", ret, path);
92 ret = MS_MEDIA_ERR_SEND_NOTI_FAIL;
94 media_svc_debug("Send noti success [%d][%d]", update_item, update_type);
97 media_svc_debug("invalid path");
98 ret = MS_MEDIA_ERR_INVALID_PARAMETER;
104 int _media_svc_publish_dir_noti_v2(media_item_type_e update_item,
105 media_item_update_type_e update_type,
107 media_type_e media_type,
109 const char *mime_type,
113 int ret = MS_MEDIA_ERR_NONE;
115 if (STRING_VALID(path)) {
116 ret = media_db_update_send_internal(pid, update_item, update_type, (char *)path, (char *)uuid, media_type, (char *)mime_type);
117 if (ret != MS_MEDIA_ERR_NONE) {
118 media_svc_error("Send noti failed : %d [%s]", ret, path);
119 ret = MS_MEDIA_ERR_SEND_NOTI_FAIL;
121 media_svc_debug("Send noti success [%d][%d]", update_item, update_type);
124 media_svc_debug("invalid path");
125 ret = MS_MEDIA_ERR_INVALID_PARAMETER;
132 void _media_svc_set_noti_from_pid(int pid)
134 g_noti_from_pid = pid;
137 int _media_svc_create_noti_list(int count)
139 SAFE_FREE(g_inserted_noti_list);
141 g_inserted_noti_list = calloc(count, sizeof(media_svc_noti_item));
142 if (g_inserted_noti_list == NULL) {
143 media_svc_error("Failed to prepare noti items");
144 return MS_MEDIA_ERR_OUT_OF_MEMORY;
147 return MS_MEDIA_ERR_NONE;
150 int _media_svc_insert_item_to_noti_list(media_svc_content_info_s *content_info, int cnt)
152 media_svc_noti_item *noti_list = g_inserted_noti_list;
154 if (noti_list && content_info) {
155 noti_list[cnt].pid = g_noti_from_pid;
156 noti_list[cnt].update_item = MS_MEDIA_ITEM_INSERT; /* INSERT */
157 noti_list[cnt].update_type = MS_MEDIA_ITEM_FILE;
158 noti_list[cnt].media_type = content_info->media_type;
159 if (content_info->media_uuid)
160 noti_list[cnt].media_uuid = strdup(content_info->media_uuid);
161 if (content_info->path)
162 noti_list[cnt].path = strdup(content_info->path);
163 if (content_info->mime_type)
164 noti_list[cnt].mime_type = strdup(content_info->mime_type);
167 return MS_MEDIA_ERR_NONE;
170 int _media_svc_destroy_noti_list(int all_cnt)
173 media_svc_noti_item *noti_list = g_inserted_noti_list;
176 for (i = 0; i < all_cnt; i++) {
177 SAFE_FREE(noti_list[i].media_uuid);
178 SAFE_FREE(noti_list[i].path);
179 SAFE_FREE(noti_list[i].mime_type);
182 SAFE_FREE(g_inserted_noti_list);
183 g_inserted_noti_list = NULL;
186 return MS_MEDIA_ERR_NONE;
189 int _media_svc_publish_noti_list(int all_cnt)
191 int ret = MS_MEDIA_ERR_NONE;
193 media_svc_noti_item *noti_list = g_inserted_noti_list;
196 for (idx = 0; idx < all_cnt; idx++) {
197 ret = __media_svc_publish_noti_by_item(&(noti_list[idx]));
204 int _media_svc_destroy_noti_item(media_svc_noti_item *item)
207 SAFE_FREE(item->media_uuid);
208 SAFE_FREE(item->path);
209 SAFE_FREE(item->mime_type);
214 return MS_MEDIA_ERR_NONE;