4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
21 #include "media-svc-noti.h"
22 #include "media-svc-util.h"
23 #include "media-svc-debug.h"
25 static __thread GSList *g_inserted_noti_list = NULL;
26 static __thread int g_noti_from_pid = -1;
28 static void __media_svc_publish_noti_by_item(gpointer data, gpointer user_data)
30 int ret = MS_MEDIA_ERR_NONE;
31 media_svc_noti_item *item = (media_svc_noti_item *)data;
33 if (item && item->path) {
34 ret = media_db_update_send(item->pid, item->update_item, item->update_type, item->path, item->media_uuid, item->media_type, item->mime_type);
35 if (ret != MS_MEDIA_ERR_NONE) {
36 media_svc_sec_error("media_db_update_send failed : %d [%s]", ret, item->path);
38 media_svc_debug("media_db_update_send success");
41 media_svc_debug("invalid path");
45 static void __media_svc_destroy_noti_item(gpointer data)
47 media_svc_noti_item *item = (media_svc_noti_item *)data;
49 g_free(item->media_uuid);
51 g_free(item->mime_type);
55 int _media_svc_publish_noti(media_item_update_type_e update_type, const char *path, int media_type, const char *uuid, const char *mime_type)
57 int ret = MS_MEDIA_ERR_NONE;
58 media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid path");
60 ret = media_db_update_send(getpid(), MS_MEDIA_ITEM_FILE, update_type, path, uuid, media_type, mime_type);
61 media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "Send noti failed[%d][%s]", ret, path);
63 media_svc_sec_debug("Send noti [%s]", path);
68 int _media_svc_publish_dir_noti(media_item_update_type_e update_type, const char *path, const char *uuid, int pid)
70 int ret = MS_MEDIA_ERR_NONE;
71 media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid path");
73 ret = media_db_update_send(pid, MS_MEDIA_ITEM_DIRECTORY, update_type, path, uuid, 0, NULL);
74 media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "Send dir noti failed[%d][%s]", ret, path);
76 media_svc_sec_debug("Send dir noti [%s]", path);
81 void _media_svc_set_noti_from_pid(int pid)
83 g_noti_from_pid = pid;
86 void _media_svc_initialize_noti_list(void)
88 if (g_inserted_noti_list)
89 g_slist_free_full(g_inserted_noti_list, __media_svc_destroy_noti_item);
91 g_inserted_noti_list = NULL;
94 void _media_svc_insert_item_to_noti_list(media_svc_content_info_s *content_info)
96 media_svc_noti_item *item = NULL;
101 item = g_new0(media_svc_noti_item, 1);
103 item->pid = g_noti_from_pid;
104 item->update_item = MS_MEDIA_ITEM_INSERT; /* INSERT */
105 item->update_type = MS_MEDIA_ITEM_FILE;
106 item->media_type = content_info->media_type;
107 item->media_uuid = g_strdup(content_info->media_uuid);
108 item->path = g_strdup(content_info->path);
109 item->mime_type = g_strdup(content_info->mime_type);
111 g_inserted_noti_list = g_slist_append(g_inserted_noti_list, (gpointer)item);
114 void _media_svc_publish_noti_list(void)
116 g_slist_foreach(g_inserted_noti_list, __media_svc_publish_noti_by_item, NULL);
118 _media_svc_initialize_noti_list();
121 void _media_svc_destroy_noti_item(media_svc_noti_item *item)
126 g_free(item->media_uuid);
128 g_free(item->mime_type);