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 media_svc_noti_item *_media_svc_get_noti_list()
31 return g_inserted_noti_list;
34 void _media_svc_set_noti_from_pid(int pid)
36 g_noti_from_pid = pid;
39 int _media_svc_create_noti_list(int count)
41 SAFE_FREE(g_inserted_noti_list);
43 g_inserted_noti_list = calloc(count, sizeof(media_svc_noti_item));
44 if (g_inserted_noti_list == NULL) {
45 media_svc_error("Failed to prepare noti items");
46 return MS_MEDIA_ERR_OUT_OF_MEMORY;
49 return MS_MEDIA_ERR_NONE;
52 int _media_svc_insert_item_to_noti_list(media_svc_content_info_s *content_info, int cnt)
54 media_svc_noti_item *noti_list = g_inserted_noti_list;
56 if (noti_list && content_info) {
57 noti_list[cnt].pid = g_noti_from_pid;
58 noti_list[cnt].update_item = MS_MEDIA_ITEM_INSERT; // INSERT
59 noti_list[cnt].update_type = MS_MEDIA_ITEM_FILE;
60 noti_list[cnt].media_type = content_info->media_type;
61 if (content_info->media_uuid)
62 noti_list[cnt].media_uuid = strdup(content_info->media_uuid);
63 if (content_info->path)
64 noti_list[cnt].path = strdup(content_info->path);
65 if (content_info->mime_type)
66 noti_list[cnt].mime_type = strdup(content_info->mime_type);
69 return MS_MEDIA_ERR_NONE;
72 int _media_svc_destroy_noti_list(int all_cnt)
75 media_svc_noti_item *noti_list = g_inserted_noti_list;
78 for (i = 0; i < all_cnt; i++) {
79 SAFE_FREE(noti_list[i].media_uuid);
80 SAFE_FREE(noti_list[i].path);
81 SAFE_FREE(noti_list[i].mime_type);
84 SAFE_FREE(g_inserted_noti_list);
85 g_inserted_noti_list = NULL;
88 return MS_MEDIA_ERR_NONE;
91 int _media_svc_publish_noti_list(int all_cnt)
93 int ret = MS_MEDIA_ERR_NONE;
95 media_svc_noti_item *noti_list = g_inserted_noti_list;
98 for (idx = 0; idx < all_cnt; idx++) {
99 ret = _media_svc_publish_noti_by_item(&(noti_list[idx]));
107 int _media_svc_create_noti_item(media_svc_content_info_s *content_info,
109 media_item_type_e update_item,
110 media_item_update_type_e update_type,
111 media_svc_noti_item **item)
113 media_svc_noti_item *_item = NULL;
115 if (item == NULL || content_info == NULL) {
116 media_svc_error("_media_svc_create_noti_item : invalid param");
117 return MS_MEDIA_ERR_INVALID_PARAMETER;
120 _item = calloc(1, sizeof(media_svc_noti_item));
123 media_svc_error("Failed to prepare noti items");
124 return MS_MEDIA_ERR_OUT_OF_MEMORY;
128 _item->update_item = update_item;
129 _item->update_type = update_type;
130 _item->media_type = content_info->media_type;
132 if (content_info->media_uuid)
133 _item->media_uuid = strdup(content_info->media_uuid);
134 if (content_info->path)
135 _item->path = strdup(content_info->path);
136 if (content_info->mime_type)
137 _item->mime_type = strdup(content_info->mime_type);
141 return MS_MEDIA_ERR_NONE;
144 int _media_svc_destroy_noti_item(media_svc_noti_item *item)
147 SAFE_FREE(item->media_uuid);
148 SAFE_FREE(item->path);
149 SAFE_FREE(item->mime_type);
154 return MS_MEDIA_ERR_NONE;
157 int _media_svc_publish_noti_by_item(media_svc_noti_item *noti_item)
159 int err = MS_MEDIA_ERR_NONE;
161 if (noti_item && noti_item->path) {
162 err = media_db_update_send(noti_item->pid,
163 noti_item->update_item,
164 noti_item->update_type,
166 noti_item->media_uuid,
167 noti_item->media_type,
168 noti_item->mime_type);
170 media_svc_error("media_db_update_send failed : %d [%s]", err, noti_item->path);
172 media_svc_debug("media_db_update_send success");
179 int _media_svc_publish_noti(media_item_type_e update_item,
180 media_item_update_type_e update_type,
182 media_type_e media_type,
184 const char *mime_type
187 int err = MS_MEDIA_ERR_NONE;
190 err = media_db_update_send(getpid(),
198 media_svc_error("media_db_update_send failed : %d [%s]", err, path);
199 return MS_MEDIA_ERR_SEND_NOTI_FAIL;
201 media_svc_debug("media_db_update_send success");