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_getenv(TZ_SYS_STORAGE)
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");
59 if (!svc_connect || !svc_disconnect || !svc_insert_item_immediately || !svc_set_folder_item_validity || !svc_delete_all_invalid_items_in_folder || !svc_check_item_exist) {
60 fprintf(stderr, "error: %s\n", dlerror());
67 int __unload_functions(void)
69 msg_print(__LINE__, "__unload_functions");
81 MediaSvcHandle *db_handle = NULL;
83 char path[1024] = {0, };
84 char type[1024] = {0, };
86 ret = __load_functions();
88 msg_print(__LINE__, "__load_functions error");
91 msg_print(__LINE__, "__load_functions success");
94 /*db open ================================================== */
95 ret = svc_connect(&db_handle, &err_msg);
97 msg_print(__LINE__, "svc_connect error");
98 if (err_msg != NULL) {
99 printf("err_msg[%s]\n", err_msg);
103 __unload_functions();
106 msg_print(__LINE__, "svc_connect success");
110 ret = media_svc_create_table(db_handle);
112 msg_print(__LINE__, "table already exists");
114 msg_print(__LINE__, "table create success");
121 printf("Enter path and mimetype ( ex. %s image ) : ", tzplatform_mkpath(TZ_USER_CONTENT, "a.jpg"));
122 scanf("%s %s", path, type);
123 bool modified = false;
124 /*check_item_exist ============================================ */
125 ret = svc_check_item_exist(db_handle, path, &modified, &err_msg);
127 msg_print(__LINE__, "svc_check_item_exist error");
128 if (err_msg != NULL) {
129 printf("err_msg[%s]\n", err_msg);
133 /*__unload_functions(); */
137 msg_print(__LINE__, "svc_check_item_exist success. Modified");
139 msg_print(__LINE__, "svc_check_item_exist success. Not modified");
142 /* svc_check_item_exist ============================================ */
143 ret = svc_insert_item_immediately(db_handle, path, 0, type, &err_msg);
145 msg_print(__LINE__, "svc_insert_item_immediately error");
146 if (err_msg != NULL) {
147 printf("err_msg[%s]\n", err_msg);
151 /*__unload_functions(); */
154 msg_print(__LINE__, "svc_insert_item_immediately success");
158 ret = media_svc_insert_folder(db_handle, 0, path);
160 msg_print(__LINE__, "media_svc_insert_folder error ");
162 msg_print(__LINE__, "media_svc_insert_folder success");
166 /*folder test ================================================== */
167 char *folder_path = tzplatform_mkpath(TZ_USER_CONTENT, "Sounds");
168 ret = svc_set_folder_item_validity(db_handle, folder_path, 0, 1, &err_msg);
170 msg_print(__LINE__, "svc_set_folder_item_validity error");
171 if (err_msg != NULL) {
172 printf("err_msg[%s]\n", err_msg);
177 msg_print(__LINE__, "svc_insert_item_immediately success");
180 ret = svc_delete_all_invalid_items_in_folder(db_handle, folder_path, &err_msg);
182 msg_print(__LINE__, "svc_delete_all_invalid_items_in_folder error");
183 if (err_msg != NULL) {
184 printf("err_msg[%s]\n", err_msg);
189 msg_print(__LINE__, "svc_insert_item_immediately success");
192 /*db close ================================================== */
193 ret = svc_disconnect(db_handle, &err_msg);
195 msg_print(__LINE__, "svc_disconnect error");
196 if (err_msg != NULL) {
197 printf("err_msg[%s]\n", err_msg);
201 __unload_functions();
204 msg_print(__LINE__, "svc_disconnect success");
207 __unload_functions();
213 static void msg_print(int line, char *msg)
215 fprintf(stderr, "[%d]%s\n", line, msg);