add APIs for getting SIM init status and importing SIM contacts by sim slot no
[platform/core/pim/contacts-service.git] / client / ctsvc_client_db.c
1 /*
2  * Contacts Service
3  *
4  * Copyright (c) 2010 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 #include "contacts.h"
22 #include "ctsvc_internal.h"
23 #include "ctsvc_client_handle.h"
24 #include "ctsvc_client_db_helper.h"
25
26 API int contacts_db_insert_record(contacts_record_h record, int *id)
27 {
28         int ret;
29         contacts_h contact = NULL;
30
31         ret = ctsvc_client_handle_get_p(&contact);
32         RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
33
34         ret = ctsvc_client_db_insert_record(contact, record, id);
35
36         return ret;
37 }
38
39 API int contacts_db_get_record(const char *view_uri, int id, contacts_record_h *out_record)
40 {
41         int ret;
42         contacts_h contact = NULL;
43
44         ret = ctsvc_client_handle_get_p(&contact);
45         RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
46
47         ret = ctsvc_client_db_get_record(contact, view_uri, id, out_record);
48
49         return ret;
50 }
51
52 API int contacts_db_update_record(contacts_record_h record)
53 {
54         int ret;
55         contacts_h contact = NULL;
56
57         ret = ctsvc_client_handle_get_p(&contact);
58         RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
59
60         ret = ctsvc_client_db_update_record(contact, record);
61
62         return ret;
63 }
64
65 API int contacts_db_delete_record(const char *view_uri, int id)
66 {
67         int ret;
68         contacts_h contact = NULL;
69
70         ret = ctsvc_client_handle_get_p(&contact);
71         RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
72
73         ret = ctsvc_client_db_delete_record(contact, view_uri, id);
74
75         return ret;
76 }
77
78 API int contacts_db_replace_record(contacts_record_h record, int id)
79 {
80         int ret;
81         contacts_h contact = NULL;
82
83         ret = ctsvc_client_handle_get_p(&contact);
84         RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
85
86         ret = ctsvc_client_db_replace_record(contact, record, id);
87
88         return ret;
89
90 }
91
92 API int contacts_db_get_all_records(const char *view_uri, int offset, int limit, contacts_list_h *out_list)
93 {
94         int ret;
95         contacts_h contact = NULL;
96
97         ret = ctsvc_client_handle_get_p(&contact);
98         RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
99
100         ret = ctsvc_client_db_get_all_records(contact, view_uri, offset, limit, out_list);
101
102         return ret;
103 }
104
105 API int contacts_db_get_records_with_query(contacts_query_h query, int offset, int limit, contacts_list_h *out_list)
106 {
107         int ret;
108         contacts_h contact = NULL;
109
110         ret = ctsvc_client_handle_get_p(&contact);
111         RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
112
113         ret = ctsvc_client_db_get_records_with_query(contact, query, offset, limit, out_list);
114
115         return ret;
116 }
117
118
119 API int contacts_db_get_count(const char *view_uri, int *out_count)
120 {
121         int ret;
122         contacts_h contact = NULL;
123
124         ret = ctsvc_client_handle_get_p(&contact);
125         RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
126
127         ret = ctsvc_client_db_get_count(contact, view_uri, out_count);
128
129         return ret;
130 }
131
132 API int contacts_db_get_count_with_query(contacts_query_h query, int *out_count)
133 {
134         int ret;
135         contacts_h contact = NULL;
136
137         ret = ctsvc_client_handle_get_p(&contact);
138         RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
139
140         ret = ctsvc_client_db_get_count_with_query(contact, query, out_count);
141
142         return ret;
143 }
144
145 API int contacts_db_insert_records(contacts_list_h list, int **ids, int *count)
146 {
147         int ret;
148         contacts_h contact = NULL;
149
150         ret = ctsvc_client_handle_get_p(&contact);
151         RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
152
153         ret = ctsvc_client_db_insert_records(contact, list, ids, count);
154
155         return ret;
156 }
157
158 API int contacts_db_update_records(contacts_list_h list)
159 {
160         int ret;
161         contacts_h contact = NULL;
162
163         ret = ctsvc_client_handle_get_p(&contact);
164         RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
165
166         ret = ctsvc_client_db_update_records(contact, list);
167
168         return ret;
169 }
170
171 API int contacts_db_delete_records(const char *view_uri, int ids[], int count)
172 {
173         int ret;
174         contacts_h contact = NULL;
175
176         ret = ctsvc_client_handle_get_p(&contact);
177         RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
178
179         ret = ctsvc_client_db_delete_records(contact, view_uri, ids, count);
180
181         return ret;
182 }
183
184 API int contacts_db_replace_records(contacts_list_h list, int ids[], int count)
185 {
186         int ret;
187         contacts_h contact = NULL;
188
189         ret = ctsvc_client_handle_get_p(&contact);
190         RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
191
192         ret = ctsvc_client_db_replace_records(contact, list, ids, count);
193
194         return ret;
195 }
196
197 API int contacts_db_get_changes_by_version(const char *view_uri, int addressbook_id,
198                 int contacts_db_version, contacts_list_h *record_list, int *current_contacts_db_version)
199 {
200         int ret;
201         contacts_h contact = NULL;
202
203         ret = ctsvc_client_handle_get_p(&contact);
204         RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
205
206         ret = ctsvc_client_db_get_changes_by_version(contact, view_uri, addressbook_id, contacts_db_version, record_list, current_contacts_db_version);
207
208         return ret;
209 }
210
211 API int contacts_db_get_current_version(int *contacts_db_version)
212 {
213         int ret;
214         contacts_h contact = NULL;
215
216         ret = ctsvc_client_handle_get_p(&contact);
217         RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
218
219         ret = ctsvc_client_db_get_current_version(contact, contacts_db_version);
220
221         return ret;
222
223 }
224
225 API int contacts_db_search_records(const char *view_uri, const char *keyword,
226                 int offset, int limit, contacts_list_h *out_list)
227 {
228         int ret;
229         contacts_h contact = NULL;
230
231         ret = ctsvc_client_handle_get_p(&contact);
232         RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
233
234         ret = ctsvc_client_db_search_records(contact, view_uri, keyword, offset, limit, out_list);
235
236         return ret;
237 }
238
239 API int contacts_db_search_records_with_range(const char *view_uri, const char *keyword,
240                 int offset, int limit, int range, contacts_list_h *out_list)
241 {
242         int ret;
243         contacts_h contact = NULL;
244
245         ret = ctsvc_client_handle_get_p(&contact);
246         RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
247
248         ret = ctsvc_client_db_search_records_with_range(contact, view_uri, keyword, offset, limit, range, out_list);
249
250         return ret;
251 }
252
253 API int contacts_db_search_records_with_query(contacts_query_h query, const char *keyword,
254                 int offset, int limit, contacts_list_h *out_list)
255 {
256         int ret;
257         contacts_h contact = NULL;
258
259         ret = ctsvc_client_handle_get_p(&contact);
260         RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
261
262         ret = ctsvc_client_db_search_records_with_query(contact, query, keyword, offset, limit, out_list);
263
264         return ret;
265 }
266
267 API int contacts_db_search_records_for_snippet(const char *view_uri,
268                 const char *keyword,
269                 int offset,
270                 int limit,
271                 const char *start_match,
272                 const char *end_match,
273                 int token_number,
274                 contacts_list_h *out_list)
275 {
276         int ret;
277         contacts_h contact = NULL;
278
279         ret = ctsvc_client_handle_get_p(&contact);
280         RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
281
282         ret = ctsvc_client_db_search_records_for_snippet(contact, view_uri, keyword,
283                         offset, limit, start_match, end_match, token_number, out_list);
284
285         return ret;
286 }
287
288 API int contacts_db_search_records_with_range_for_snippet(const char *view_uri,
289                 const char *keyword,
290                 int offset,
291                 int limit,
292                 int range,
293                 const char *start_match,
294                 const char *end_match,
295                 int token_number,
296                 contacts_list_h *out_list)
297 {
298         int ret;
299         contacts_h contact = NULL;
300
301         ret = ctsvc_client_handle_get_p(&contact);
302         RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
303
304         ret = ctsvc_client_db_search_records_with_range_for_snippet(contact, view_uri,
305                         keyword, offset, limit, range, start_match, end_match, token_number, out_list);
306
307         return ret;
308 }
309
310 API int contacts_db_search_records_with_query_for_snippet(contacts_query_h query,
311                 const char *keyword,
312                 int offset,
313                 int limit,
314                 const char *start_match,
315                 const char *end_match,
316                 int token_number,
317                 contacts_list_h *out_list)
318 {
319         int ret;
320         contacts_h contact = NULL;
321
322         ret = ctsvc_client_handle_get_p(&contact);
323         RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
324
325         ret = ctsvc_client_db_search_records_with_query_for_snippet(contact, query, keyword,
326                         offset, limit, start_match, end_match, token_number, out_list);
327
328         return ret;
329 }
330
331 API int contacts_db_get_last_change_version(int *last_version)
332 {
333         int ret;
334         contacts_h contact = NULL;
335
336         ret = ctsvc_client_handle_get_p(&contact);
337         RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
338
339         ret = ctsvc_client_db_get_last_change_version(contact, last_version);
340
341         return ret;
342 }
343
344 API int contacts_db_get_status(contacts_db_status_e *status)
345 {
346         int ret;
347         contacts_h contact = NULL;
348
349         ret = ctsvc_client_handle_get_p(&contact);
350         RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
351
352         ret = ctsvc_client_db_get_status(contact, status);
353
354         return ret;
355 }
356
357 API int contacts_db_add_status_changed_cb(
358                 contacts_db_status_changed_cb cb, void *user_data)
359 {
360         int ret;
361         contacts_h contact = NULL;
362
363         ret = ctsvc_client_handle_get_p(&contact);
364         RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
365
366         ret = ctsvc_client_db_add_status_changed_cb(contact, cb, user_data);
367
368         return ret;
369 }
370
371 API int contacts_db_remove_status_changed_cb(
372                 contacts_db_status_changed_cb cb, void *user_data)
373 {
374         int ret;
375         contacts_h contact = NULL;
376
377         ret = ctsvc_client_handle_get_p(&contact);
378         RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
379
380         ret = ctsvc_client_db_remove_status_changed_cb(contact, cb, user_data);
381
382         return ret;
383 }
384