summaryrefslogtreecommitdiff
path: root/test/plugin/media_svc_plugin_test.c
blob: 31797fad69cc1c9640595ef0e34fccad1725948b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
/*
 * libmedia-service
 *
 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
 *
 * Contact: Hyunjun Ko <zzoon.ko@samsung.com>, Haejeong Kim <backto.kim@samsung.com>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

#include <stdlib.h>
#include <stdio.h>
#include <dlfcn.h>
#include <stdbool.h>
#include <media-svc.h>

#include <tzplatform_config.h>

#define PLUGIN_SO_FILE_NAME  "/usr/lib/libmedia-content-plugin.so"
#define MEDIA_ROOT_PATH_SDCARD	tzplatform_mkpath(TZ_SYS_STORAGE,"sdcard")
void *funcHandle = NULL;

static void msg_print(int line, char *msg);

int (*svc_connect)				(void ** handle, char ** err_msg);
int (*svc_disconnect)			(void * handle, char ** err_msg);
int (*svc_check_item_exist)		(void* handle, const char *file_path, bool *modified, char ** err_msg);
int (*svc_insert_item_immediately)	(void* handle, const char *file_path, int storage_type, const char * mime_type, char ** err_msg);
int (*svc_set_folder_item_validity) (void * handle, const char * folder_path, int validity, int recursive, char ** err_msg);
int (*svc_delete_all_invalid_items_in_folder) (void * handle, const char *folder_path, char ** err_msg);

int __load_functions()
{
	msg_print(__LINE__, "__load_functions");

	funcHandle = dlopen (PLUGIN_SO_FILE_NAME, RTLD_LAZY);
	if (!funcHandle) {
		fprintf (stderr,"error: %s\n", dlerror());
	}

	svc_connect			= dlsym (funcHandle, "connect");
	svc_disconnect		= dlsym (funcHandle, "disconnect");
	svc_check_item_exist	= dlsym (funcHandle, "check_item_exist");
	svc_insert_item_immediately	= dlsym (funcHandle, "insert_item_immediately");
	svc_set_folder_item_validity	= dlsym (funcHandle, "set_folder_item_validity");
	svc_delete_all_invalid_items_in_folder	= dlsym (funcHandle, "delete_all_invalid_items_in_folder");

	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) {
		fprintf(stderr,"error: %s\n", dlerror());
		return -1;
	}

	return 0;
}

int __unload_functions(void)
{
	msg_print(__LINE__, "__unload_functions");

	if (funcHandle)
	{
		dlclose (funcHandle);
	}

	return 0;
}

int main()
{
	int ret = 0;
	MediaSvcHandle * db_handle = NULL;
	char * err_msg = NULL;
	char path[1024] = {0,};
	char type[1024] = {0,};

	ret = __load_functions();
	if(ret < 0) {
		msg_print(__LINE__, "__load_functions error");
		return -1;
	} else {
		msg_print(__LINE__, "__load_functions success");
	}

	//db open ==================================================
	ret = svc_connect(&db_handle, &err_msg);
	if(ret < 0) {
		msg_print(__LINE__, "svc_connect error");
		if(err_msg != NULL) {
			printf("err_msg[%s]\n", err_msg);
			free(err_msg);
			err_msg = NULL;
		}
		__unload_functions();
		return -1;
	} else {
		msg_print(__LINE__, "svc_connect success");
	}

#if 1
	ret = media_svc_create_table(db_handle);
	if (ret < 0) {
		msg_print(__LINE__, "table already exists");
	} else {
		msg_print(__LINE__, "table create success");
	}
#endif

#if 1
	while (1) {

	printf("Enter path and mimetype ( ex. %s image ) : ", tzplatform_mkpath(TZ_USER_CONTENT, "a.jpg"));
	scanf("%s %s", path, type);
	bool modified = false;
	//check_item_exist ============================================
	ret = svc_check_item_exist(db_handle, path, &modified, &err_msg);
	if(ret < 0) {
		msg_print(__LINE__, "svc_check_item_exist error");
		if(err_msg != NULL) {
			printf("err_msg[%s]\n", err_msg);
			free(err_msg);
			err_msg = NULL;
		}
		//__unload_functions();
		//return -1;
	} else {
		if(modified)
			msg_print(__LINE__, "svc_check_item_exist success. Modified");
		else
			msg_print(__LINE__, "svc_check_item_exist success. Not modified");
	}

	// svc_check_item_exist ============================================
	ret = svc_insert_item_immediately(db_handle, path, 0, type, &err_msg);
	if(ret < 0) {
		msg_print(__LINE__, "svc_insert_item_immediately error");
		if(err_msg != NULL) {
			printf("err_msg[%s]\n", err_msg);
			free(err_msg);
			err_msg = NULL;
		}
		//__unload_functions();
		//return -1;
	} else {
		msg_print(__LINE__, "svc_insert_item_immediately success");
	}
	} // End of While

	ret = media_svc_insert_folder(db_handle, 0,  path);
	if(ret < 0) {
		msg_print(__LINE__, "media_svc_insert_folder error ");
	} else {
		msg_print(__LINE__, "media_svc_insert_folder success");
	}
#endif

	//folder test ==================================================
	char *folder_path = tzplatform_mkpath(TZ_USER_CONTENT,"Sounds"));
	ret = svc_set_folder_item_validity(db_handle, folder_path, 0, 1, &err_msg);
	if(ret < 0) {
		msg_print(__LINE__, "svc_set_folder_item_validity error");
		if(err_msg != NULL) {
			printf("err_msg[%s]\n", err_msg);
			free(err_msg);
			err_msg = NULL;
		}
	} else {
		msg_print(__LINE__, "svc_insert_item_immediately success");
	}

	ret = svc_delete_all_invalid_items_in_folder(db_handle, folder_path, &err_msg);
	if(ret < 0) {
		msg_print(__LINE__, "svc_delete_all_invalid_items_in_folder error");
		if(err_msg != NULL) {
			printf("err_msg[%s]\n", err_msg);
			free(err_msg);
			err_msg = NULL;
		}
	} else {
		msg_print(__LINE__, "svc_insert_item_immediately success");
	}

	//db close ==================================================
	ret = svc_disconnect(db_handle, &err_msg);
	if(ret < 0) {
		msg_print(__LINE__, "svc_disconnect error");
		if(err_msg != NULL) {
			printf("err_msg[%s]\n", err_msg);
			free(err_msg);
			err_msg = NULL;
		}
		__unload_functions();
		return -1;
	} else {
		msg_print(__LINE__, "svc_disconnect success");
	}

	__unload_functions();

	return 0;
}


static void msg_print(int line, char *msg)
{
	fprintf(stderr, "[%d]%s\n", line, msg);
}