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.
26 #include <media-svc.h>
28 #include <tzplatform_config.h>
30 #define PLUGIN_SO_FILE_NAME "/usr/lib/libmedia-content-plugin.so"
31 #define MEDIA_ROOT_PATH_SDCARD tzplatform_mkpath(TZ_SYS_STORAGE,"sdcard")
32 void *funcHandle = NULL;
34 static void msg_print(int line, char *msg);
36 int (*svc_connect) (void ** handle, char ** err_msg);
37 int (*svc_disconnect) (void * handle, char ** err_msg);
38 int (*svc_check_item_exist) (void* handle, const char *file_path, bool *modified, char ** err_msg);
39 int (*svc_insert_item_immediately) (void* handle, const char *file_path, int storage_type, const char * mime_type, char ** err_msg);
40 int (*svc_set_folder_item_validity) (void * handle, const char * folder_path, int validity, int recursive, char ** err_msg);
41 int (*svc_delete_all_invalid_items_in_folder) (void * handle, const char *folder_path, char ** err_msg);
43 int __load_functions()
45 msg_print(__LINE__, "__load_functions");
47 funcHandle = dlopen (PLUGIN_SO_FILE_NAME, RTLD_LAZY);
49 fprintf (stderr,"error: %s\n", dlerror());
52 svc_connect = dlsym (funcHandle, "connect");
53 svc_disconnect = dlsym (funcHandle, "disconnect");
54 svc_check_item_exist = dlsym (funcHandle, "check_item_exist");
55 svc_insert_item_immediately = dlsym (funcHandle, "insert_item_immediately");
56 svc_set_folder_item_validity = dlsym (funcHandle, "set_folder_item_validity");
57 svc_delete_all_invalid_items_in_folder = dlsym (funcHandle, "delete_all_invalid_items_in_folder");
61 !svc_insert_item_immediately ||
62 !svc_set_folder_item_validity ||
63 !svc_delete_all_invalid_items_in_folder ||
64 !svc_check_item_exist) {
65 fprintf(stderr,"error: %s\n", dlerror());
72 int __unload_functions(void)
74 msg_print(__LINE__, "__unload_functions");
87 MediaSvcHandle * db_handle = NULL;
88 char * err_msg = NULL;
89 char path[1024] = {0,};
90 char type[1024] = {0,};
92 ret = __load_functions();
94 msg_print(__LINE__, "__load_functions error");
97 msg_print(__LINE__, "__load_functions success");
100 //db open ==================================================
101 ret = svc_connect(&db_handle, &err_msg);
103 msg_print(__LINE__, "svc_connect error");
104 if(err_msg != NULL) {
105 printf("err_msg[%s]\n", err_msg);
109 __unload_functions();
112 msg_print(__LINE__, "svc_connect success");
116 ret = media_svc_create_table(db_handle);
118 msg_print(__LINE__, "table already exists");
120 msg_print(__LINE__, "table create success");
127 printf("Enter path and mimetype ( ex. %s image ) : ", tzplatform_mkpath(TZ_USER_CONTENT, "a.jpg"));
128 scanf("%s %s", path, type);
129 bool modified = false;
130 //check_item_exist ============================================
131 ret = svc_check_item_exist(db_handle, path, &modified, &err_msg);
133 msg_print(__LINE__, "svc_check_item_exist error");
134 if(err_msg != NULL) {
135 printf("err_msg[%s]\n", err_msg);
139 //__unload_functions();
143 msg_print(__LINE__, "svc_check_item_exist success. Modified");
145 msg_print(__LINE__, "svc_check_item_exist success. Not modified");
148 // svc_check_item_exist ============================================
149 ret = svc_insert_item_immediately(db_handle, path, 0, type, &err_msg);
151 msg_print(__LINE__, "svc_insert_item_immediately error");
152 if(err_msg != NULL) {
153 printf("err_msg[%s]\n", err_msg);
157 //__unload_functions();
160 msg_print(__LINE__, "svc_insert_item_immediately success");
164 ret = media_svc_insert_folder(db_handle, 0, path);
166 msg_print(__LINE__, "media_svc_insert_folder error ");
168 msg_print(__LINE__, "media_svc_insert_folder success");
172 //folder test ==================================================
173 char *folder_path = tzplatform_mkpath(TZ_USER_CONTENT,"Sounds"));
174 ret = svc_set_folder_item_validity(db_handle, folder_path, 0, 1, &err_msg);
176 msg_print(__LINE__, "svc_set_folder_item_validity error");
177 if(err_msg != NULL) {
178 printf("err_msg[%s]\n", err_msg);
183 msg_print(__LINE__, "svc_insert_item_immediately success");
186 ret = svc_delete_all_invalid_items_in_folder(db_handle, folder_path, &err_msg);
188 msg_print(__LINE__, "svc_delete_all_invalid_items_in_folder error");
189 if(err_msg != NULL) {
190 printf("err_msg[%s]\n", err_msg);
195 msg_print(__LINE__, "svc_insert_item_immediately success");
198 //db close ==================================================
199 ret = svc_disconnect(db_handle, &err_msg);
201 msg_print(__LINE__, "svc_disconnect error");
202 if(err_msg != NULL) {
203 printf("err_msg[%s]\n", err_msg);
207 __unload_functions();
210 msg_print(__LINE__, "svc_disconnect success");
213 __unload_functions();
219 static void msg_print(int line, char *msg)
221 fprintf(stderr, "[%d]%s\n", line, msg);