4 #include <media-svc-noti.h>
6 GMainLoop *g_loop = NULL;
7 MediaSvcHandle *g_db_handle = NULL;
10 media_item_type_e update_item,
11 media_item_update_type_e update_type,
14 media_type_e content_type,
18 media_svc_debug("Noti from PID(%d)", pid);
20 if (update_item == MS_MEDIA_ITEM_FILE) {
21 media_svc_debug("Noti item : MS_MEDIA_ITEM_FILE");
22 } else if (update_item == MS_MEDIA_ITEM_DIRECTORY) {
23 media_svc_debug("Noti item : MS_MEDIA_ITEM_DIRECTORY");
26 if (update_type == MS_MEDIA_ITEM_INSERT) {
27 media_svc_debug("Noti type : MS_MEDIA_ITEM_INSERT");
28 } else if (update_type == MS_MEDIA_ITEM_DELETE) {
29 media_svc_debug("Noti type : MS_MEDIA_ITEM_DELETE");
30 } else if (update_type == MS_MEDIA_ITEM_UPDATE) {
31 media_svc_debug("Noti type : MS_MEDIA_ITEM_UPDATE");
34 //media_svc_debug("content type : %d", content_type);
35 printf("content type : %d\n", content_type);
38 printf("path : %s\n", path);
43 printf("mime_type : %s", mime_type);
47 if (user_data) printf("String : %s\n", (char *)user_data);
55 gboolean _send_noti_batch_operations(gpointer data)
57 int ret = MEDIA_INFO_ERROR_NONE;
59 /* First of all, noti subscription */
60 char *user_str = strdup("hi");
61 media_db_update_subscribe(_noti_cb, (void*)user_str);
63 /* 1. media_svc_insert_item_immediately */
64 char *path = tzplatform_mkpath(TZ_USER_CONTENT, "test/image1.jpg");
66 media_svc_storage_type_e storage_type;
68 ret = media_svc_get_storage_type(path, &storage_type);
69 if (ret < MEDIA_INFO_ERROR_NONE) {
70 media_svc_error("media_svc_get_storage_type failed : %d (%s)", ret, path);
77 ret = media_svc_insert_item_begin(g_db_handle, 100, TRUE, getpid());
78 //ret = media_svc_insert_item_begin(g_db_handle, 100);
79 for (i = 0; i < 16; i++) {
80 char filepath[255] = {0,};
81 snprintf(filepath, sizeof(filepath), "%s%d.jpg", tzplatform_mkpath(TZ_USER_CONTENT,"test/image"), i+1);
82 media_svc_debug("File : %s\n", filepath);
83 file_list[i] = strdup(filepath);
84 ret = media_svc_insert_item_bulk(g_db_handle, storage_type, file_list[i], FALSE);
86 media_svc_error("media_svc_insert_item_bulk[%d] failed", i);
88 media_svc_debug("media_svc_insert_item_bulk[%d] success", i);
92 ret = media_svc_insert_item_end(g_db_handle);
98 gboolean _send_noti_operations(gpointer data)
100 int ret = MEDIA_INFO_ERROR_NONE;
102 /* First of all, noti subscription */
103 char *user_str = strdup("hi");
104 media_db_update_subscribe(_noti_cb, (void*)user_str);
106 /* 1. media_svc_insert_item_immediately */
107 char *path = tzplatform_mkpath(TZ_USER_CONTENT,"test/image1.jpg");
108 media_svc_storage_type_e storage_type;
110 ret = media_svc_get_storage_type(path, &storage_type);
111 if (ret < MEDIA_INFO_ERROR_NONE) {
112 media_svc_error("media_svc_get_storage_type failed : %d (%s)", ret, path);
116 ret = media_svc_insert_item_immediately(g_db_handle, storage_type, path);
117 if (ret < MEDIA_INFO_ERROR_NONE) {
118 media_svc_error("media_svc_insert_item_immediately failed : %d", ret);
122 media_svc_debug("media_svc_insert_item_immediately success");
124 /* 2. media_svc_refresh_item */
125 ret = media_svc_refresh_item(g_db_handle, storage_type, path);
126 if (ret < MEDIA_INFO_ERROR_NONE) {
127 media_svc_error("media_svc_refresh_item failed : %d", ret);
130 media_svc_debug("media_svc_refresh_item success");
132 /* 2. media_svc_move_item */
133 const char *dst_path = tzplatform_mkpath(TZ_USER_CONTENT, "test/image11.jpg");
134 ret = media_svc_move_item(g_db_handle, storage_type, path, storage_type, dst_path);
135 if (ret < MEDIA_INFO_ERROR_NONE) {
136 media_svc_error("media_svc_move_item failed : %d", ret);
139 media_svc_debug("media_svc_move_item success");
141 ret = media_svc_move_item(g_db_handle, storage_type, dst_path, storage_type, path);
142 if (ret < MEDIA_INFO_ERROR_NONE) {
143 media_svc_error("media_svc_move_item failed : %d", ret);
146 media_svc_debug("media_svc_move_item success");
148 /* 4. media_svc_delete_item_by_path */
149 ret = media_svc_delete_item_by_path(g_db_handle, path);
150 if (ret < MEDIA_INFO_ERROR_NONE) {
151 media_svc_error("media_svc_delete_item_by_path failed : %d", ret);
154 media_svc_debug("media_svc_delete_item_by_path success");
157 const char *src_folder_path = tzplatform_mkpath(TZ_USER_CONTENT, "test");
158 const char *dst_folder_path = tzplatform_mkpath(TZ_USER_CONTENT,"test_test");
159 ret = media_svc_rename_folder(g_db_handle, src_folder_path, dst_folder_path);
160 if (ret < MEDIA_INFO_ERROR_NONE) {
161 media_svc_error("media_svc_rename_folder failed : %d", ret);
164 media_svc_debug("media_svc_rename_folder success");
166 /* Rename folder again */
167 ret = media_svc_rename_folder(g_db_handle, dst_folder_path, src_folder_path);
168 if (ret < MEDIA_INFO_ERROR_NONE) {
169 media_svc_error("media_svc_rename_folder failed : %d", ret);
172 media_svc_debug("media_svc_rename_folder success");
179 GSource *source = NULL;
180 GMainContext *context = NULL;
182 g_loop = g_main_loop_new(NULL, FALSE);
183 context = g_main_loop_get_context(g_loop);
184 source = g_idle_source_new();
186 g_source_set_callback (source, _send_noti_operations, NULL, NULL);
188 g_source_set_callback (source, _send_noti_batch_operations, NULL, NULL);
190 g_source_attach (source, context);
192 g_main_loop_run(g_loop);
194 g_main_loop_unref(g_loop);
195 media_db_update_unsubscribe();
197 return MEDIA_INFO_ERROR_NONE;
202 int ret = MEDIA_INFO_ERROR_NONE;
203 ret = media_svc_connect(&g_db_handle);
204 if (ret < MEDIA_INFO_ERROR_NONE) {
205 media_svc_error("media_svc_connect failed : %d", ret);
207 media_svc_debug("media_svc_connect success");
211 if (ret < MEDIA_INFO_ERROR_NONE) {
212 media_svc_error("test_noti failed : %d", ret);
214 media_svc_debug("test_noti success");
217 media_svc_disconnect(g_db_handle);