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 media_svc_noti_item *g_inserted_noti_list = NULL;
27 static __thread int g_noti_from_pid = -1;
29 static int __media_svc_publish_noti_by_item(media_svc_noti_item *noti_item)
31 int ret = MS_MEDIA_ERR_NONE;
33 if (noti_item && noti_item->path)
35 ret = media_db_update_send(noti_item->pid,
36 noti_item->update_item,
37 noti_item->update_type,
39 noti_item->media_uuid,
40 noti_item->media_type,
41 noti_item->mime_type);
42 if(ret != MS_MEDIA_ERR_NONE)
44 media_svc_error("media_db_update_send failed : %d [%s]", ret, noti_item->path);
45 ret = MS_MEDIA_ERR_SEND_NOTI_FAIL;
49 media_svc_debug("media_db_update_send success");
54 media_svc_debug("invalid path");
55 ret = MS_MEDIA_ERR_INVALID_PARAMETER;
61 int _media_svc_publish_noti(media_item_type_e update_item,
62 media_item_update_type_e update_type,
64 media_type_e media_type,
69 int ret = MS_MEDIA_ERR_NONE;
72 ret = media_db_update_send(getpid(), update_item, update_type, (char *)path, (char *)uuid, media_type, (char *)mime_type);
73 if(ret != MS_MEDIA_ERR_NONE) {
74 media_svc_error("Send noti failed : %d [%s]", ret, path);
75 ret = MS_MEDIA_ERR_SEND_NOTI_FAIL;
77 media_svc_debug("media_db_update_send success");
80 media_svc_debug("invalid path");
81 ret = MS_MEDIA_ERR_INVALID_PARAMETER;
87 media_svc_noti_item *_media_svc_get_noti_list()
89 return g_inserted_noti_list;
92 void _media_svc_set_noti_from_pid(int pid)
94 g_noti_from_pid = pid;
97 int _media_svc_create_noti_list(int count)
99 SAFE_FREE(g_inserted_noti_list);
101 g_inserted_noti_list = calloc(count, sizeof(media_svc_noti_item));
102 if (g_inserted_noti_list == NULL) {
103 media_svc_error("Failed to prepare noti items");
104 return MS_MEDIA_ERR_OUT_OF_MEMORY;
107 return MS_MEDIA_ERR_NONE;
110 int _media_svc_insert_item_to_noti_list(media_svc_content_info_s *content_info, int cnt)
112 media_svc_noti_item *noti_list = g_inserted_noti_list;
114 if (noti_list && content_info) {
115 noti_list[cnt].pid = g_noti_from_pid;
116 noti_list[cnt].update_item = MS_MEDIA_ITEM_INSERT; // INSERT
117 noti_list[cnt].update_type = MS_MEDIA_ITEM_FILE;
118 noti_list[cnt].media_type = content_info->media_type;
119 if (content_info->media_uuid)
120 noti_list[cnt].media_uuid = strdup(content_info->media_uuid);
121 if (content_info->path)
122 noti_list[cnt].path = strdup(content_info->path);
123 if (content_info->mime_type)
124 noti_list[cnt].mime_type = strdup(content_info->mime_type);
127 return MS_MEDIA_ERR_NONE;
130 int _media_svc_destroy_noti_list(int all_cnt)
133 media_svc_noti_item *noti_list = g_inserted_noti_list;
136 for (i = 0; i < all_cnt; i++) {
137 SAFE_FREE(noti_list[i].media_uuid);
138 SAFE_FREE(noti_list[i].path);
139 SAFE_FREE(noti_list[i].mime_type);
142 SAFE_FREE(g_inserted_noti_list);
143 g_inserted_noti_list = NULL;
146 return MS_MEDIA_ERR_NONE;
149 int _media_svc_publish_noti_list(int all_cnt)
151 int ret = MS_MEDIA_ERR_NONE;
153 media_svc_noti_item *noti_list = g_inserted_noti_list;
156 for (idx = 0; idx < all_cnt; idx++) {
157 ret = __media_svc_publish_noti_by_item(&(noti_list[idx]));
165 int _media_svc_create_noti_item(media_svc_content_info_s *content_info,
167 media_item_type_e update_item,
168 media_item_update_type_e update_type,
169 media_svc_noti_item **item)
171 media_svc_noti_item *_item = NULL;
173 if (item == NULL || content_info == NULL) {
174 media_svc_error("_media_svc_create_noti_item : invalid param");
175 return MS_MEDIA_ERR_INVALID_PARAMETER;
178 _item = calloc(1, sizeof(media_svc_noti_item));
181 media_svc_error("Failed to prepare noti items");
182 return MS_MEDIA_ERR_OUT_OF_MEMORY;
186 _item->update_item = update_item;
187 _item->update_type = update_type;
188 _item->media_type = content_info->media_type;
190 if (content_info->media_uuid)
191 _item->media_uuid = strdup(content_info->media_uuid);
192 if (content_info->path)
193 _item->path = strdup(content_info->path);
194 if (content_info->mime_type)
195 _item->mime_type = strdup(content_info->mime_type);
199 return MS_MEDIA_ERR_NONE;
202 int _media_svc_destroy_noti_item(media_svc_noti_item *item)
205 SAFE_FREE(item->media_uuid);
206 SAFE_FREE(item->path);
207 SAFE_FREE(item->mime_type);
212 return MS_MEDIA_ERR_NONE;