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");
49 if (update_type == MS_MEDIA_ITEM_INSERT) {
50 media_svc_debug("Noti type : MS_MEDIA_ITEM_INSERT");
51 } else if (update_type == MS_MEDIA_ITEM_DELETE) {
52 media_svc_debug("Noti type : MS_MEDIA_ITEM_DELETE");
53 } else if (update_type == MS_MEDIA_ITEM_UPDATE) {
54 media_svc_debug("Noti type : MS_MEDIA_ITEM_UPDATE");
57 /*media_svc_debug("content type : %d", content_type); */
58 printf("content type : %d\n", content_type);
61 printf("path : %s\n", path);
66 printf("mime_type : %s", mime_type);
70 if (user_data) printf("String : %s\n", (char *)user_data);
78 gboolean _send_noti_batch_operations(gpointer data)
80 int ret = MS_MEDIA_ERR_NONE;
82 /* First of all, noti subscription */
83 char *user_str = strdup("hi");
84 media_db_update_subscribe(_noti_cb, (void *)user_str);
86 /* 1. media_svc_insert_item_immediately */
87 char *path = tzplatform_mkpath(TZ_USER_CONTENT, "test/image1.jpg");
89 media_svc_storage_type_e storage_type;
91 ret = media_svc_get_storage_type(path, &storage_type, tzplatform_getuid(TZ_USER_NAME));
92 if (ret != MS_MEDIA_ERR_NONE) {
93 media_svc_error("media_svc_get_storage_type failed : %d (%s)", ret, path);
101 ret = media_svc_insert_item_begin(100, TRUE, getpid());
102 /*ret = media_svc_insert_item_begin(g_db_handle, 100); */
103 for (idx = 0; idx < 10; idx++) {
104 char filepath[255] = {0, };
105 snprintf(filepath, sizeof(filepath), "%s%d.jpg", tzplatform_mkpath(TZ_USER_CONTENT, "test/image"), idx + 1);
106 media_svc_debug("File : %s\n", filepath);
107 file_list[idx] = strdup(filepath);
108 ret = media_svc_insert_item_bulk(g_db_handle, storage_type, file_list[idx], FALSE);
110 media_svc_error("media_svc_insert_item_bulk[%d] failed", idx);
112 media_svc_debug("media_svc_insert_item_bulk[%d] success", idx);
116 ret = media_svc_insert_item_end(tzplatform_getuid(TZ_USER_NAME));
123 gboolean _send_noti_operations(gpointer data)
125 int ret = MS_MEDIA_ERR_NONE;
127 /* First of all, noti subscription */
128 char *user_str = strdup("hi");
129 media_db_update_subscribe(_noti_cb, (void *)user_str);
131 /* 1. media_svc_insert_item_immediately */
132 char *path = tzplatform_mkpath(TZ_USER_CONTENT, "test/image1.jpg");
133 media_svc_storage_type_e storage_type;
135 ret = media_svc_get_storage_type(path, &storage_type, tzplatform_getuid(TZ_USER_NAME));
136 if (ret != MS_MEDIA_ERR_NONE) {
137 media_svc_error("media_svc_get_storage_type failed : %d (%s)", ret, path);
142 ret = media_svc_insert_item_immediately(g_db_handle, storage_type, path);
143 if (ret != MS_MEDIA_ERR_NONE) {
144 media_svc_error("media_svc_insert_item_immediately failed : %d", ret);
149 media_svc_debug("media_svc_insert_item_immediately success");
151 /* 2. media_svc_refresh_item */
152 ret = media_svc_refresh_item(g_db_handle, storage_type, path);
153 if (ret != MS_MEDIA_ERR_NONE) {
154 media_svc_error("media_svc_refresh_item failed : %d", ret);
157 media_svc_debug("media_svc_refresh_item success");
159 /* 2. media_svc_move_item */
160 const char *dst_path = tzplatform_mkpath(TZ_USER_CONTENT, "test/image11.jpg");
161 ret = media_svc_move_item(g_db_handle, storage_type, path, storage_type, dst_path);
162 if (ret != MS_MEDIA_ERR_NONE) {
163 media_svc_error("media_svc_move_item failed : %d", ret);
166 media_svc_debug("media_svc_move_item success");
168 ret = media_svc_move_item(g_db_handle, storage_type, dst_path, storage_type, path);
169 if (ret != MS_MEDIA_ERR_NONE) {
170 media_svc_error("media_svc_move_item failed : %d", ret);
173 media_svc_debug("media_svc_move_item success");
175 /* 4. media_svc_delete_item_by_path */
176 ret = media_svc_delete_item_by_path(g_db_handle, path);
177 if (ret != MS_MEDIA_ERR_NONE) {
178 media_svc_error("media_svc_delete_item_by_path failed : %d", ret);
181 media_svc_debug("media_svc_delete_item_by_path success");
184 const char *src_folder_path = tzplatform_mkpath(TZ_USER_CONTENT, "test");
185 const char *dst_folder_path = tzplatform_mkpath(TZ_USER_CONTENT, "test_test");
186 ret = media_svc_rename_folder(g_db_handle, src_folder_path, dst_folder_path);
187 if (ret != MS_MEDIA_ERR_NONE) {
188 media_svc_error("media_svc_rename_folder failed : %d", ret);
191 media_svc_debug("media_svc_rename_folder success");
193 /* Rename folder again */
194 ret = media_svc_rename_folder(g_db_handle, dst_folder_path, src_folder_path);
195 if (ret != MS_MEDIA_ERR_NONE) {
196 media_svc_error("media_svc_rename_folder failed : %d", ret);
199 media_svc_debug("media_svc_rename_folder success");
206 GSource *source = NULL;
207 GMainContext *context = NULL;
209 g_loop = g_main_loop_new(NULL, FALSE);
210 context = g_main_loop_get_context(g_loop);
211 source = g_idle_source_new();
213 g_source_set_callback(source, _send_noti_operations, NULL, NULL);
215 g_source_set_callback(source, _send_noti_batch_operations, NULL, NULL);
217 g_source_attach(source, context);
219 g_main_loop_run(g_loop);
221 g_main_loop_unref(g_loop);
222 media_db_update_unsubscribe();
224 return MS_MEDIA_ERR_NONE;
229 int ret = MS_MEDIA_ERR_NONE;
230 ret = media_svc_connect(&g_db_handle, tzplatform_getuid(TZ_USER_NAME), true);
231 if (ret != MS_MEDIA_ERR_NONE) {
232 media_svc_error("media_svc_connect failed : %d", ret);
234 media_svc_debug("media_svc_connect success");
238 if (ret < MS_MEDIA_ERR_NONE) {
239 media_svc_error("test_noti failed : %d", ret);
241 media_svc_debug("test_noti success");
244 media_svc_disconnect(g_db_handle);