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");
86 MediaSvcHandle *db_handle = NULL;
88 char path[1024] = {0, };
89 char type[1024] = {0, };
91 ret = __load_functions();
93 msg_print(__LINE__, "__load_functions error");
96 msg_print(__LINE__, "__load_functions success");
99 /*db open ================================================== */
100 ret = svc_connect(&db_handle, &err_msg);
102 msg_print(__LINE__, "svc_connect error");
103 if (err_msg != NULL) {
104 printf("err_msg[%s]\n", err_msg);
108 __unload_functions();
111 msg_print(__LINE__, "svc_connect success");
115 ret = media_svc_create_table(db_handle);
117 msg_print(__LINE__, "table already exists");
119 msg_print(__LINE__, "table create success");
126 printf("Enter path and mimetype ( ex. %s image ) : ", tzplatform_mkpath(TZ_USER_CONTENT, "a.jpg"));
127 scanf("%s %s", path, type);
128 bool modified = false;
129 /*check_item_exist ============================================ */
130 ret = svc_check_item_exist(db_handle, path, &modified, &err_msg);
132 msg_print(__LINE__, "svc_check_item_exist error");
133 if (err_msg != NULL) {
134 printf("err_msg[%s]\n", err_msg);
138 /*__unload_functions(); */
142 msg_print(__LINE__, "svc_check_item_exist success. Modified");
144 msg_print(__LINE__, "svc_check_item_exist success. Not modified");
147 /* svc_check_item_exist ============================================ */
148 ret = svc_insert_item_immediately(db_handle, path, 0, type, &err_msg);
150 msg_print(__LINE__, "svc_insert_item_immediately error");
151 if (err_msg != NULL) {
152 printf("err_msg[%s]\n", err_msg);
156 /*__unload_functions(); */
159 msg_print(__LINE__, "svc_insert_item_immediately success");
163 ret = media_svc_insert_folder(db_handle, 0, path);
165 msg_print(__LINE__, "media_svc_insert_folder error ");
167 msg_print(__LINE__, "media_svc_insert_folder success");
171 /*folder test ================================================== */
172 char *folder_path = tzplatform_mkpath(TZ_USER_CONTENT, "Sounds");
173 ret = svc_set_folder_item_validity(db_handle, folder_path, 0, 1, &err_msg);
175 msg_print(__LINE__, "svc_set_folder_item_validity error");
176 if (err_msg != NULL) {
177 printf("err_msg[%s]\n", err_msg);
182 msg_print(__LINE__, "svc_insert_item_immediately success");
185 ret = svc_delete_all_invalid_items_in_folder(db_handle, folder_path, &err_msg);
187 msg_print(__LINE__, "svc_delete_all_invalid_items_in_folder error");
188 if (err_msg != NULL) {
189 printf("err_msg[%s]\n", err_msg);
194 msg_print(__LINE__, "svc_insert_item_immediately success");
197 /*db close ================================================== */
198 ret = svc_disconnect(db_handle, &err_msg);
200 msg_print(__LINE__, "svc_disconnect error");
201 if (err_msg != NULL) {
202 printf("err_msg[%s]\n", err_msg);
206 __unload_functions();
209 msg_print(__LINE__, "svc_disconnect success");
212 __unload_functions();
218 static void msg_print(int line, char *msg)
220 fprintf(stderr, "[%d]%s\n", line, msg);