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.
24 #include <media-svc.h>
25 #include <media-svc-noti.h>
27 #define SAFE_FREE(src) { if (src) { free(src); src = NULL; } }
29 GMainLoop *g_loop = NULL;
30 MediaSvcHandle *g_db_handle = NULL;
32 void _noti_cb(int pid,
33 media_item_type_e update_item,
34 media_item_update_type_e update_type,
37 media_type_e content_type,
41 media_svc_debug("Noti from PID(%d)", pid);
43 if (update_item == MS_MEDIA_ITEM_FILE)
44 media_svc_debug("Noti item : MS_MEDIA_ITEM_FILE");
45 else if (update_item == MS_MEDIA_ITEM_DIRECTORY)
46 media_svc_debug("Noti item : MS_MEDIA_ITEM_DIRECTORY");
48 if (update_type == MS_MEDIA_ITEM_INSERT)
49 media_svc_debug("Noti type : MS_MEDIA_ITEM_INSERT");
50 else if (update_type == MS_MEDIA_ITEM_DELETE)
51 media_svc_debug("Noti type : MS_MEDIA_ITEM_DELETE");
52 else if (update_type == MS_MEDIA_ITEM_UPDATE)
53 media_svc_debug("Noti type : MS_MEDIA_ITEM_UPDATE");
55 /*media_svc_debug("content type : %d", content_type); */
56 printf("content type : %d\n", content_type);
59 printf("path : %s\n", path);
64 printf("mime_type : %s", mime_type);
68 if (user_data) printf("String : %s\n", (char *)user_data);
76 gboolean _send_noti_batch_operations(gpointer data)
78 int ret = MS_MEDIA_ERR_NONE;
80 /* First of all, noti subscription */
81 char *user_str = strdup("hi");
82 media_db_update_subscribe(_noti_cb, (void *)user_str);
84 /* 1. media_svc_insert_item_immediately */
85 char *path = tzplatform_mkpath(TZ_USER_CONTENT, "test/image1.jpg");
87 media_svc_storage_type_e storage_type;
89 ret = media_svc_get_storage_type(path, &storage_type, tzplatform_getuid(TZ_USER_NAME));
90 if (ret != MS_MEDIA_ERR_NONE) {
91 media_svc_error("media_svc_get_storage_type failed : %d (%s)", ret, path);
99 ret = media_svc_insert_item_begin(100, TRUE, getpid());
100 /*ret = media_svc_insert_item_begin(g_db_handle, 100); */
101 for (idx = 0; idx < 10; idx++) {
102 char filepath[255] = {0, };
103 snprintf(filepath, sizeof(filepath), "%s%d.jpg", tzplatform_mkpath(TZ_USER_CONTENT, "test/image"), idx + 1);
104 media_svc_debug("File : %s\n", filepath);
105 file_list[idx] = strdup(filepath);
106 ret = media_svc_insert_item_bulk(g_db_handle, storage_type, file_list[idx], FALSE);
108 media_svc_error("media_svc_insert_item_bulk[%d] failed", idx);
110 media_svc_debug("media_svc_insert_item_bulk[%d] success", idx);
113 ret = media_svc_insert_item_end(tzplatform_getuid(TZ_USER_NAME));
120 gboolean _send_noti_operations(gpointer data)
122 int ret = MS_MEDIA_ERR_NONE;
124 /* First of all, noti subscription */
125 char *user_str = strdup("hi");
126 media_db_update_subscribe(_noti_cb, (void *)user_str);
128 /* 1. media_svc_insert_item_immediately */
129 char *path = tzplatform_mkpath(TZ_USER_CONTENT, "test/image1.jpg");
130 media_svc_storage_type_e storage_type;
132 ret = media_svc_get_storage_type(path, &storage_type, tzplatform_getuid(TZ_USER_NAME));
133 if (ret != MS_MEDIA_ERR_NONE) {
134 media_svc_error("media_svc_get_storage_type failed : %d (%s)", ret, path);
139 ret = media_svc_insert_item_immediately(g_db_handle, storage_type, path);
140 if (ret != MS_MEDIA_ERR_NONE) {
141 media_svc_error("media_svc_insert_item_immediately failed : %d", ret);
146 media_svc_debug("media_svc_insert_item_immediately success");
148 /* 2. media_svc_refresh_item */
149 ret = media_svc_refresh_item(g_db_handle, storage_type, path);
150 if (ret != MS_MEDIA_ERR_NONE) {
151 media_svc_error("media_svc_refresh_item failed : %d", ret);
154 media_svc_debug("media_svc_refresh_item success");
156 /* 2. media_svc_move_item */
157 const char *dst_path = tzplatform_mkpath(TZ_USER_CONTENT, "test/image11.jpg");
158 ret = media_svc_move_item(g_db_handle, storage_type, path, storage_type, dst_path);
159 if (ret != MS_MEDIA_ERR_NONE) {
160 media_svc_error("media_svc_move_item failed : %d", ret);
163 media_svc_debug("media_svc_move_item success");
165 ret = media_svc_move_item(g_db_handle, storage_type, dst_path, storage_type, path);
166 if (ret != MS_MEDIA_ERR_NONE) {
167 media_svc_error("media_svc_move_item failed : %d", ret);
170 media_svc_debug("media_svc_move_item success");
172 /* 4. media_svc_delete_item_by_path */
173 ret = media_svc_delete_item_by_path(g_db_handle, path);
174 if (ret != MS_MEDIA_ERR_NONE) {
175 media_svc_error("media_svc_delete_item_by_path failed : %d", ret);
178 media_svc_debug("media_svc_delete_item_by_path success");
181 const char *src_folder_path = tzplatform_mkpath(TZ_USER_CONTENT, "test");
182 const char *dst_folder_path = tzplatform_mkpath(TZ_USER_CONTENT, "test_test");
183 ret = media_svc_rename_folder(g_db_handle, src_folder_path, dst_folder_path);
184 if (ret != MS_MEDIA_ERR_NONE) {
185 media_svc_error("media_svc_rename_folder failed : %d", ret);
188 media_svc_debug("media_svc_rename_folder success");
190 /* Rename folder again */
191 ret = media_svc_rename_folder(g_db_handle, dst_folder_path, src_folder_path);
192 if (ret != MS_MEDIA_ERR_NONE) {
193 media_svc_error("media_svc_rename_folder failed : %d", ret);
196 media_svc_debug("media_svc_rename_folder success");
203 GSource *source = NULL;
204 GMainContext *context = NULL;
206 g_loop = g_main_loop_new(NULL, FALSE);
207 context = g_main_loop_get_context(g_loop);
208 source = g_idle_source_new();
210 g_source_set_callback(source, _send_noti_operations, NULL, NULL);
212 g_source_set_callback(source, _send_noti_batch_operations, NULL, NULL);
214 g_source_attach(source, context);
216 g_main_loop_run(g_loop);
218 g_main_loop_unref(g_loop);
219 media_db_update_unsubscribe();
221 return MS_MEDIA_ERR_NONE;
226 int ret = MS_MEDIA_ERR_NONE;
227 ret = media_svc_connect(&g_db_handle, tzplatform_getuid(TZ_USER_NAME), true);
228 if (ret != MS_MEDIA_ERR_NONE)
229 media_svc_error("media_svc_connect failed : %d", ret);
231 media_svc_debug("media_svc_connect success");
234 if (ret < MS_MEDIA_ERR_NONE)
235 media_svc_error("test_noti failed : %d", ret);
237 media_svc_debug("test_noti success");
239 media_svc_disconnect(g_db_handle);