4 * Copyright (c) 2010 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
21 #ifndef __TIZEN_SOCIAL_CONTACTS_DOC_H__
22 #define __TIZEN_SOCIAL_CONTACTS_DOC_H__
26 * @ingroup CAPI_SOCIAL_FRAMEWORK
27 * @defgroup CAPI_SOCIAL_CONTACTS_SVC_MODULE Contacts
28 * @brief The Contacts Service API provides methods for managing contact information for people.
29 * A contact object is always associated with a specific address book.
30 * A person object is an aggregation of one or more contacts associated with the same person.
31 * @section CAPI_SOCIAL_CONTACTS_SVC_MODULE_HEADER Required Header
32 * \#include <contacts.h>
34 * @section CAPI_SOCIAL_CONTACTS_SVC_MODULE_OVERVIEW Overview
35 * The Contacts-service provides functions for managing contact information for people.
36 * A contact object is always associated with a specific address book.
37 * A person object is an aggregation of one or more contacts associated with the same person.
38 * Contacts-service has a relationship between Entities.
40 * @image html Contact_structure.png "Figure: Contact structure"
41 * There are three same contacts made from different address book.
42 * Person1 is an aggregation of Contact1, Contact2 and Contact3.
43 * The contacts-service provides an interface to manage the information
47 * - Managing contacts information stored in database <br>
48 * - Aggregating contacts information from various accounts <br>
49 * - Notifying changes of contacts information <br>
50 * - Searching contacts information <br>
51 * - vCard supports <br>
56 * @section CAPI_SOCIAL_CONTACTS_SVC_MODULE_FEATURE Related Features
57 * This API is related with the following features:\n
58 * - %http://tizen.org/feature/contact\n
59 * It is recommended to design feature related codes in your application for reliability.\n
60 * You can check if a device supports the related features for this API by using @ref CAPI_SYSTEM_SYSTEM_INFO_MODULE, thereby controlling the procedure of your application.\n
61 * To ensure your application is only running on the device with specific features, please define the features in your manifest file using the manifest editor in the SDK.\n
62 * More details on featuring your application can be found from <a href="https://docs.tizen.org/application/tizen-studio/native-tools/manifest-text-editor#feature-element"><b>Feature Element</b>.</a>
64 * @section CAPI_SOCIAL_CONTACTS_SVC_MODULE_ENTITIES Entities
65 * Contacts-Service manages information related to following entities.
67 * - Information for individuals, like name, phone number, email, address, job, instant messenger, company, etc.
69 * - Accounts are handled by account module. Contacts-service should use account ID which is created in the module.
70 * - Exceptionally, Local device address book has no account and its related account ID is zero.
71 * - Each account can create only one address book.
73 * - Represents where contacts and groups should belong to
74 * - Created by one of contacts sources below
75 * - Local device, which has no account.
76 * - Service providers such as Google or Yahoo, with account.
77 * - Applications like ChatON, Joyn, Facebook, etc.
79 * - Grouped contacts on a same address book.
80 * - Groups and contacts have many-to-many relationship.
82 * - A virtual contact that keeps merged information of contacts linked together.
83 * - When more than one contact from different sources designate same individual, then instead of showing each contacts separately, by Person concept, they can be shown and managed as one virtual contact.
84 * - Every contact becomes linked to at least one person.
86 * - My information which has almost same properties as contact information but it has no properties such as group relation, ringtone and message alert.
87 * - Single entry can be available on each address book.
89 * - Social activities are stored.
91 * - Shortcut dialing number key information.
93 * - Call or message logs are stored.
95 * @subsection CAPI_SOCIAL_CONTACTS_SVC_MODULE_ENTITIES_RELATIONSHIP Relationship between entities
96 * Contacts-service has a relationship between Entities.
98 * @image html Relationship_between_entities.png "Figure: Relationship between entities"
100 * @subsection CAPI_SOCIAL_CONTACTS_SVC_MODULE_RELATIONSHIP_BETWEEN_CONTACT_AND_PERSON Relationship between Contact and Person
101 * Person will be created automatically when inserting a contact record. Cannot create person record directly.
103 * Sample code: Insert a contact record
105 * // create contact record
106 * contacts_record_h contact = NULL;
107 * contacts_record_create(_contacts_contact._uri, &contact);
110 * contacts_record_h name = NULL;
111 * contacts_record_create(_contacts_name._uri, &name);
112 * contacts_record_set_str(name, _contacts_name.first, “test”);
113 * contacts_record_add_child_record(contact, _contacts_contact.name, name);
116 * contacts_record_h number = NULL;
117 * contacts_record_create(_contacts_number._uri, &number);
118 * contacts_record_set_str(number, _contacts_number.number, “1234”);
119 * contacts_record_add_child_record(contact, _contacts_contact.number, number);
121 * // insert to database
122 * int contact_id = 0;
123 * contacts_db_insert_record(contact, &contact_id);
126 * contacts_record_destroy(contact, true);
129 * @image html Creating_a_person_record.png "Figure: Creating a person record"
130 * Person record can be link to another person. Even though contacts address book is different, link is possible.
132 * Sample code: Link contact
134 * int person_id1 = ... // acquire ID of Person1 record
135 * int person_id2 = ... // acquire ID of Person2 record
137 * contacts_person_link_person(person_id1, person_id2);
140 * @image html Link_person.png "Figure: Link person"
141 * Contact record can be separate from person record. New person will be created when unlinking contact record.
143 * Sample code: Unlink contact
145 * int person_id1 = ... // acquire ID of Person1 record
146 * int contact_id3 = ... // acquire ID of Contact3 record
148 * contacts_person_unlink_contact(person_id1, contact_id3);
151 * @image html Unlink_contact.png "Figure: Unlink contact"
153 * @section CAPI_SOCIAL_CONTACTS_SVC_MODULE_VIEWS Views
154 * To access and handle entities, views are provided.
155 * According to data-view declarations, generic access functions are used (contacts_db_insert_record(), contacts_record_get_int(), …).
156 * Data-View is almost same as database “VIEW” which limits access and guarantees the performance by offering various views for the proper purpose.
157 * “Record” represents a single row of the data-views. <br>
158 * A data-view is a structure, which has property elements.
159 * For example, the _contacts_contact view describes the properties of the contact record.
160 * Its properties include name, company, nickname of the contact and many more.
162 * <caption> Table: Contact editable views </caption>
164 * <th>View (Editable)</th>
165 * <th>Description</th>
167 * <tr> <td> _contacts_address_book </td> <td> Describes the properties of the address book </td> </tr>
168 * <tr> <td> _contacts_group </td> <td> Describes the properties of the group </td> </tr>
169 * <tr> <td> _contacts_person </td> <td> Describes the properties of the person </td> </tr>
170 * <tr> <td> _contacts_simple_contact </td> <td> Describes the properties of the contact </td> </tr>
171 * <tr> <td> _contacts_contact </td> <td> Describes the properties of the contact </td> </tr>
172 * <tr> <td> _contacts_my_profile </td> <td> Describes the properties of my profile </td> </tr>
173 * <tr> <td> _contacts_name </td> <td> Describes the properties of the contacts name </td> </tr>
174 * <tr> <td> _contacts_number </td> <td> Describes the properties of the contacts number </td> </tr>
175 * <tr> <td> _contacts_email </td> <td> Describes the properties of the contacts email </td> </tr>
176 * <tr> <td> _contacts_address </td> <td> Describes the properties of the contacts address </td> </tr>
177 * <tr> <td> _contacts_note </td> <td> Describes the properties of the contacts note </td> </tr>
178 * <tr> <td> _contacts_url </td> <td> Describes the properties of the contacts url </td> </tr>
179 * <tr> <td> _contacts_event </td> <td> Describes the properties of the contacts birthday and anniversary </td> </tr>
180 * <tr> <td> _contacts_group_relation </td> <td> Describes the properties of the contacts group relation </td> </tr>
181 * <tr> <td> _contacts_relationship </td> <td> Describes the properties of the contacts relationship </td> </tr>
182 * <tr> <td> _contacts_image </td> <td> Describes the properties of the contacts image </td> </tr>
183 * <tr> <td> _contacts_company </td> <td> Describes the properties of the contacts company </td> </tr>
184 * <tr> <td> _contacts_nickname </td> <td> Describes the properties of the contacts nickname </td> </tr>
185 * <tr> <td> _contacts_messenger </td> <td> Describes the properties of the contacts messenger </td> </tr>
186 * <tr> <td> _contacts_extension </td> <td> Describes the properties of the extension </td> </tr>
187 * <tr> <td> _contacts_sdn </td> <td> Describes the properties of the service description number </td> </tr>
188 * <tr> <td> _contacts_profile </td> <td> Describes the properties of the profile </td> </tr>
189 * <tr> <td> _contacts_activity_photo </td> <td> Describes the properties of the photo of contacts activity </td> </tr>
190 * <tr> <td> _contacts_activity </td> <td> Describes the properties of the contacts activity </td> </tr>
191 * <tr> <td> _contacts_speeddial </td> <td> Describes the properties of the speed dial </td> </tr>
192 * <tr> <td> _contacts_phone_log </td> <td> Describes the properties of the log </td> </tr>
195 * <caption> Table: Contact read only views </caption>
197 * <th>View (Read only)</th>
198 * <th>Description</th>
200 * <tr> <td> _contacts_contact_updated_info </td> <td> used when identifying contact changes depending on version </td> </tr>
201 * <tr> <td> _contacts_my_profile_updated_info </td> <td> used when identifying my profile changes depending on version </td> </tr>
202 * <tr> <td> _contacts_group_updated_info </td> <td> used when identifying group changes depending on version </td> </tr>
203 * <tr> <td> _contacts_group_member_updated_info </td> <td> used when identifying group member changes depending on version </td> </tr>
204 * <tr> <td> _contacts_grouprel_updated_info </td> <td> used when identifying group relation profile changes depending on version </td> </tr>
205 * <tr> <td> _contacts_person_contact </td> <td> used when querying to merge information of person and contact </td> </tr>
206 * <tr> <td> _contacts_person_number </td> <td> used when querying to merge information of person and number </td> </tr>
207 * <tr> <td> _contacts_person_email </td> <td> used when querying to merge information of person and email </td> </tr>
208 * <tr> <td> _contacts_person_grouprel </td> <td> used when querying to merge information of person and group relation </td> </tr>
209 * <tr> <td> _contacts_person_group_assigned </td> <td> used when querying for information of person who is assigned to group </td> </tr>
210 * <tr> <td> _contacts_person_group_not_assigned </td> <td> used when querying for information of person who is not assigned to group </td> </tr>
211 * <tr> <td> _contacts_person_phone_log </td> <td> used when querying to merge information of person and phone log </td> </tr>
212 * <tr> <td> _contacts_person_usage </td> <td> used when querying for information of person usage </td> </tr>
213 * <tr> <td> _contacts_contact_number </td> <td> used when querying to merge information of contact and number </td> </tr>
214 * <tr> <td> _contacts_contact_email </td> <td> used when querying to merge information of contact and email </td> </tr>
215 * <tr> <td> _contacts_contact_grouprel </td> <td> used when querying to merge information of contact and group relation </td> </tr>
216 * <tr> <td> _contacts_contact_activity </td> <td> used when querying to merge information of contact and activity </td> </tr>
217 * <tr> <td> _contacts_phone_log_stat </td> <td> used when querying for information of phone log status </td> </tr>
220 * @subsection CAPI_SOCIAL_CONTACTS_SVC_MODULE_VIEWS_PROPERTIES Properties
221 * Property elements have their data types and name. <br>
222 * Record types which have *_id as their properties, hold identifiers of other records - e.g. name, number and email views hold ID of their corresponding contacts in contact_id property (as children of the corresponding contacts record). <br>
223 * A type of some property is ‘record’.
224 * It means that the parent record can have child records.
225 * For example, a contact record has 'name', 'number' and 'email' properties, which means that records of those types can be children of contact type records.<br>
226 * In contacts_view.h header file, view macros are found and below figure shows what the macro means.
228 * @image html Properties.png "Figure: Properties"
230 * Sample code: Create a contact record then set caller ID
232 * contacts_record_h contact = NULL;
233 * contacts_record_create(_contacts_contact._uri, &contact);
235 * // set image to _contacts_contact view.
236 * contacts_record_h image = NULL;
237 * contacts_record_create(_contacts_image._uri, &image);
239 * char *resource_path = app_get_resource_path();
240 * char caller_id_path[1024] = {0};
241 * snprintf(caller_id_path, sizeof(caller_id_path), "%s/caller_id.jpg", resource_path);
242 * free(resource_path);
243 * contacts_record_set_str(image, _contacts_image.path, caller_id_path);
245 * // add image record to contact
246 * contacts_record_add_child_record(contact, _contacts_contact.image, image);
249 * <table class="note">
251 * <th class="note">Note</th>
254 * <td class="note">For an application to insert private images in contacts, it needs to follow below conditions:<br/>
255 * 1. Application must have privilege of %http://tizen.org/privilege/contact.write to use APIs such as contacts_db_insert_record().<br/>
256 * 2. Application's private directory and files must have 'read' permission of others, '644' for example. SMACK protects read permission from the other applications.<br/>
257 * 3. Application may erase the image after destroying the contact record (contacts_record_destroy).<br/>
261 * @section CAPI_SOCIAL_CONTACTS_SVC_MODULE_RECORDS Records
262 * In contacts-service, one of the basic concept is a record.
263 * It may be helpful to know that a record represents an actual record in the internal database, but in general,
264 * you can think of a record as a piece of information, like an address, phone number or group of contacts.
265 * A record can be a complex set of data, containing other data, e.g. an address record contains country, region, and street, among others.<br>
266 * Also, the contained data can be a reference to another record.
267 * For example, a contact record contains the 'address' property, which is a reference to an address record.
268 * An address record belongs to a contact record - its 'contact_id' property is set to identifier of the corresponding contact (more on IDs later).
269 * In this case, the address is the contacts child record and the contact is the parent record.<br>
270 * Effectively, a record can be a node in a tree or graph of relations between records.
272 * @subsection CAPI_SOCIAL_CONTACTS_SVC_MODULE_RECORDS_URI URI
273 * Each record type has a special structure defined for it, called 'view', which contains identifiers of its properties. <br>
274 * Every view has a special field - _uri - that uniquely identifies the view.
275 * In many cases you need to use the _uri value to indicate what type of record you wish to create or operate on.
277 * APIs which needs _uri
279 * API int contacts_record_create(const char* view_uri, ...)
280 * API int contacts_filter_create(const char* view_uri, ...)
281 * API int contacts_query_create(const char* view_uri, ...)
282 * API int contacts_db_get_record(const char* view_uri, ...)
283 * API int contacts_db_delete_record(const char* view_uri, ...)
284 * API int contacts_db_get_all_records(const char* view_uri, ...)
285 * API int contacts_db_delete_records(const char* view_uri, ...)
286 * API int contacts_db_add_changed_cb(const char* view_uri, ...)
287 * API int contacts_db_remove_changed_cb(const char* view_uri, ...)
288 * API int contacts_db_get_changes_by_version(const char* view_uri, ...)
289 * API int contacts_db_search_records(const char* view_uri, ...)
290 * API int contacts_db_search_records_with_range(const char* view_uri, ...)
291 * API int contacts_db_get_count(const char* view_uri, ...)
294 * @subsection CAPI_SOCIAL_CONTACTS_SVC_MODULE_RECORDS_HANDLE Record handle
295 * To use a record, you must obtain its handle.
296 * There are many ways to obtains it, including creating a new record and referring to child records of a record. <br>
297 * When creating a record, you need to specify what type of record you want to create.
298 * This is where you should use the URI property.
300 * Sample code: Creates a contact record
302 * contacts_record_h contact = NULL;
303 * contacts_record_create(_contacts_contact._uri, &contact);
306 * Sample code: Gets a contact record with id
308 * contacts_record_h contact = NULL;
309 * contacts_db_get_record(_contacts_contact._uri, id, &contact);
312 * @subsection CAPI_SOCIAL_CONTACTS_SVC_MODULE_RECORDS_BASIC_TYPES Basic types
313 * A record can have basic properties of five types: integer, string, boolean, long integer, lli (long long int), double.
314 * Each property of basic type has functions to operate on it:
316 * <caption> Table: Setter and getter functions </caption>
318 * <th>Property type</th>
324 * <td> @ref contacts_record_set_str </td>
325 * <td> @ref contacts_record_get_str </td>
329 * <td> @ref contacts_record_set_int </td>
330 * <td> @ref contacts_record_get_int </td>
334 * <td> @ref contacts_record_set_bool </td>
335 * <td> @ref contacts_record_get_bool </td>
338 * <td> long long integer </td>
339 * <td> @ref contacts_record_set_lli </td>
340 * <td> @ref contacts_record_get_lli </td>
344 * <td> @ref contacts_record_set_double </td>
345 * <td> @ref contacts_record_get_double </td>
348 * Above functions also require specifying which property you wish to get/set.
349 * Every getter and setter functions need record and property ID.
350 * You can make property ID by combine data-view name and property name.
351 * (.e.g. property ID of a contact display_name property : _contacts_contact.display_name)
353 * Sample code : Sets the ‘ringtone_path’ property of a contact record.
355 * char *resource_path = app_get_resource_path();
356 * char ringtone_path[1024] = {0};
357 * snprintf(ringtone_path, sizeof(ringtone_path), "%s/ringtone.mp3", resource_path);
358 * free(resource_path);
359 * contacts_record_set_str(contact, _contacts_contact.ringtone_path, ringtone_path);
362 * Note on returned values ownership: string getter function have the "_p" postfix.
363 * It means that the returned value should not be freed by the application, as it is a pointer to data in an existing record.
365 * Sample code: Two ways of getting string property
367 * contacts_record_get_str(record, _contacts_person.display_name, &display_name);
368 * contacts_record_get_str_p(record, _contacts_person.display_name, &display_name);
371 * In the first case, the returned string should be freed by the application.
372 * In second one, display_name value will freed automatically when destroying the record handle.
374 * @subsection CAPI_SOCIAL_CONTACTS_SVC_MODULE_RECORDS_CHILD Child
375 * A record can have properties of type 'record' called child records.
376 * A record can contain several records of a given type. For example, a ‘contact record’(parent) can contain many ‘address records’(children).
377 * The code below inserts an address record into a contact record.
378 * Note that it is not necessary to insert all records - just the contact record needs to be inserted into the database, it is enough for all information to be stored.
379 * Both records are then destroyed.
381 * Sample code: Add child record
383 * contacts_record_h address = NULL;
384 * contacts_record_h image = NULL;
385 * int contact_id = 0;
387 * // image, address record can be child record of contact record
388 * contacts_record_create(_contacts_contact._uri, &contact);
390 * contacts_record_create(_contacts_image._uri, &image);
391 * char *resource_path = app_get_resource_path();
392 * char caller_id_path[1024] = {0};
393 * snprintf(caller_id_path, sizeof(caller_id_path), "%s/caller_id.jpg", resource_path);
394 * free(resource_path);
395 * contacts_record_set_str(image, _contacts_image.path, caller_id_path);
396 * contacts_record_add_child_record(contact, _contacts_contact.image, image);
398 * contacts_record_create(_contacts_address._uri, &address);
399 * contacts_record_set_str(address, _contacts_address.country, "Korea");
400 * contacts_record_add_child_record(contact, _contacts_contact.address, address);
402 * // insert contact to DBs
403 * contacts_db_insert_record(contact, &contact_id);
404 * contacts_record_destroy(contact, true);
407 * @subsection CAPI_SOCIAL_CONTACTS_SVC_MODULE_RECORDS_RECORD_ID_PROPERTY Record ID property
408 * ID is unique number which can identify a record Therefore, if you know the ID of a record, you can directly handle the record.
409 * The ID is read-only property, which is available after the record has been inserted into the database.
411 * Sample code: Gets a contact record with id
413 * contacts_record_h contact = NULL;
414 * contacts_record_create(_contacts_contact._uri, &contact);
416 * contacts_record_h name = NULL;
417 * contacts_record_create(_contacts_name._uri, &name);
418 * contacts_record_set_str(name, _contacts_name.first, “first name”);
419 * contacts_record_add_child_record(contact, _contacts_contact.name, name);
421 * int contact_id = 0;
422 * contacts_db_insert_record(contact, &contact_id); // contact_id is unique number of contact record
423 * contacts_record_destroy(contact, true); // contact is no longer usable
425 * contacts_db_get_record(_contacts_contact._uri, contact_id, &contact); // contact is now a handle to the same record as before
426 * char *display_name = NULL;
427 * contacts_record_get_str(contact, _contacts_contact.display_name, &display_name);
428 * contacts_record_destroy(contact, true); // contact is no longer usable
431 * Identifiers can also be used to establish a relation between two records. The following code sets an address record's 'contact_id' property to the ID of the contact. contact_id make relate between the address record and the contact which is identified by the contact_id. After that is done, the address becomes one of the addresses connected to the contact. The address is now the contacts child record, the contact is the parent record.
433 * Sample code: Insert a address record with contact_id
435 * int contact_id = ... // acquire id of created contact
436 * int address_id = 0;
437 * contacts_record_create(_contacts_address._uri, &address);
438 * contacts_record_set_int(address, _contacts_address.contact_id, contact_id);
439 * // set other address properties
441 * contacts_db_insert_record(address, &address_id);
443 * Having a record handle, you can access all records of a specific type related to the given record.
445 * Sample code: Gets a contact record
447 * int contact_id = ... // acquire id of created contact
448 * int address_num = 0;
450 * contacts_db_get_record(_contacts_contact._uri, contact_id, &contact);
451 * contacts_record_get_child_record_count(contact, _contacts_contact.address, &address_num);
452 * for (i = 0; i < address_num; i++) {
453 * contacts_record_h address = NULL;
454 * contacts_record_get_child_record_at_p(contact, _contacts_contact.address, i, &address);
455 * contacts_record_set_str(address, _contacts_address.country, "Korea");
457 * contacts_db_update_record(contact);
458 * contacts_record_destroy(contact, true);
461 * This example is to change a country of addresses which are child records of a contact. Each address can be traversed by using contacts_record_get_child_record_at_p(). It is possible to apply the changes by updating the contact which is the parent record.
462 * @section CAPI_SOCIAL_CONTACTS_SVC_MODULE_LISTS Lists
463 * The contacts-service provides functions which can handle list of same type records. Lists concept is based on standard doubly linked list.
464 * To operate a list, you must obtain its handle. The handle is provided during creation of the list. List handle must destroy after use.
467 * API int contacts_list_create(contacts_list_h* contacts_list);
468 * API int contacts_list_destroy(contacts_list_h contacts_list, bool delete_child);
471 * If ‘delete_child’ parameter is the true, child resources will destroy automatically.
473 * Sample code: Create a list handle
475 * // get list handle with query
476 * contacts_list_h list = NULL;
477 * contacts_list_create(&list);
482 * contacts_list_destroy(list, true);
485 * Sample code: Gets person list handle from database.
487 * // get list handle with query
488 * contacts_list_h list = NULL;
489 * contacts_db_get_all_records(_contacts_person._uri, 0, 0, &list);
494 * contacts_list_destroy(list, true);
497 * @subsection CAPI_SOCIAL_CONTACTS_SVC_MODULE_LISTS_CURSOR Cursor
498 * The list can be traversed by using cursor.
501 * API int contacts_list_first(contacts_list_h contacts_list);
502 * API int contacts_list_last(contacts_list_h contacts_list);
503 * API int contacts_list_next(contacts_list_h contacts_list);
504 * API int contacts_list_prev(contacts_list_h contacts_list);
507 * You can get a record of current cursor.
510 * API int contacts_list_get_current_record_p(contacts_list_h contacts_list, contacts_record_h* record);
513 * Sample code: Loop list
515 * contacts_list_h list = NULL;
516 * contacts_record_h record = NULL;
517 * contacts_db_get_all_records(_contacts_person._uri, 0, 0, &list);
519 * contacts_list_get_current_record_p(list, &record);
520 * if (NULL == record)
523 * contacts_record_get_str_p(record, _contacts_person.display_name, &name);
524 * printf(“name=%s\n”, name);
525 * } while (CONTACTS_ERROR_NONE == contacts_list_next(list));
526 * contacts_list_destroy(list, true); // destroy child records automatically
529 * @subsection CAPI_SOCIAL_CONTACTS_SVC_MODULE_LISTS_ADD_REMOVE Add / Remove
530 * The contacts-service provides functions for adding/removing child record on list.
532 * API int contacts_list_add(contacts_list_h contacts_list, contacts_record_h record);
533 * API int contacts_list_remove(contacts_list_h contacts_list, contacts_record_h record);
536 * Sample code: Adds records to the list
538 * contacts_record_h group1 = NULL;
539 * contacts_record_create(_contacts_group._uri, &group1);
540 * contacts_record_set_str(group1, _contacts_group.name, “group test1”);
542 * contacts_record_h group2 = NULL;
543 * contacts_record_create(_contacts_group._uri, &group2);
544 * contacts_record_set_str(group2, _contacts_group.name, “group test2”);
546 * contacts_list_h list = NULL;
547 * contacts_list_create(&list);
549 * // Adds records to the list
550 * contacts_list_add(list, group1);
551 * contacts_list_add(list, group2);
553 * contacts_db_insert_records(list, NULL, NULL);
554 * contacts_list_destroy(list, true);
557 * @section CAPI_SOCIAL_CONTACTS_SVC_MODULE_BULK_APIS Bulk APIs
558 * Bulk APIs provide to insert/update/delete multiple records. There is no limit of record count on bulk API, but it causes a process to hang during the time the API is operated. Bulk APIs guarantee atomicity. That is, the API operating either all, or nothing.
561 * API int contacts_db_insert_records(contacts_list_h record_list, int **ids, int *count);
562 * API int contacts_db_update_records(contacts_list_h record_list);
563 * API int contacts_db_delete_records(const char* view_uri, int record_id_array[], int count);
564 * API int contacts_db_replace_records(contacts_list_h list, int record_id_array[], int count);
567 * Sample code: Insert two contact records using bulk API.
569 * contacts_record_h contact1;
570 * contacts_record_create(_contacts_contact.uri, &contact1);
572 * // fill contact record
575 * contacts_record_h contact2;
576 * contacts_record_create(_contacts_contact._uri, &contact2);
578 * // fill contact record
581 * contacts_list_h list = NULL;
582 * contacts_list_create(&list);
584 * contacts_list_add(list, contact1);
585 * contacts_list_add(list, contact2);
590 * // Insert contact records using bulk API
591 * contacts_db_insert_records(list, &ids, &count);
596 * contacts_list_destroy(list, true);
600 * @section CAPI_SOCIAL_CONTACTS_SVC_MODULE_FILTER_AND_QUERIES Queries
601 * Queries are used to retrieve data which satisfies given criteria, like an integer property being greater than a given value, or a string property containing a given substring. Query needs a filter which can set the condition for search. The contacts-service provides query APIs for sorting, set projection and removing duplicated results.
603 * @subsection CAPI_SOCIAL_CONTACTS_SVC_MODULE_FILTER_AND_QUERIES_FILTER Filter
604 * The contacts Filter API provides the set of definitions and interfaces that enable application developers to make filters to set query. <br>
605 * When creating a filter, you need to specify what type of filter you want to create using _uri property. Filter handle must destroy after use.
608 * API int contacts_filter_create(const char* view_uri, contacts_filter_h* filter);
609 * API int contacts_filter_destroy(contacts_filter_h filter);
612 * Sample code: Set filter condition to contain a given substring.
614 * contacts_filter_add_str(filter, _contacts_person.display_name, CONTACTS_MATCH_CONTAINS, “1234”);
617 * Sample code: Set filter condition to property value is true.
619 * contacts_filter_add_bool(filter, _contacts_person.is_favorite, true);
622 * Conditions can be added to a filter. The conditions SHOULD be joined by using a AND and OR logical operator.
624 * Sample code: Creates composite filter with OR operator.
626 * contacts_filter_add_str(filter1, _contacts_person.display_name, CONTACTS_MATCH_CONTAINS, “1234”);
627 * contacts_filter_add_operator(filter1, CONTACTS_FILTER_OPERATOR_OR);
628 * contacts_filter_add_str(filter1, _contacts_person.display_name, CONTACTS_MATCH_CONTAINS, “5678”);
631 * Additionally, filters can join each other by using a AND and OR logical operator.
633 * Sample code: Creates joined filter with AND operator.
635 * contacts_filter_add_str(filter1, _contacts_person.display_name, CONTACTS_MATCH_CONTAINS, “1234”);
636 * contacts_filter_add_operator(filter1, CONTACTS_FILTER_OPERATOR_OR);
637 * contacts_filter_add_str(filter1, _contacts_person.display_name, CONTACTS_MATCH_CONTAINS, “5678”);
639 * contacts_filter_add_bool(filter2, _contacts_person.is_fovorite, true);
641 * contacts_filter_add_operator(filter1, CONTACTS_FILTER_OPERATOR_AND);
642 * contacts_filter_add_filter(filter1, filter2);
645 * Operator precedence in filters is determined by the order in which the conditions and filters are added. For example, if the following sequence is added:
647 * <caption> Table: Filter and conditions </caption>
649 * <th> Filter with conditions </th>
660 * <td> (C1 OR C2) AND C3 </td>
667 * Condition C2 <br><br>
671 * Condition C4 <br><br>
680 * (C5 AND F1) AND F2 <br>
682 * (C5 AND (C1 OR C2)) AND (C3 OR C4)
687 * Sample code: Create a filter which will accept addresses with their contact's id equal to a given id (integer filter), or their country property equal to "Korea" (string filter). Create a query and add the filter to it. Results are received in a list.
689 * contacts_filter_h filter = NULL;
690 * contacts_list_h list = NULL;
691 * contacts_query_h query = NULL;
693 * contacts_filter_create(_contacts_address._uri, &filter);
694 * contacts_filter_add_int(filter, _contacts_address.contact_id, CONTACTS_MATCH_EQUAL, id);
695 * contacts_filter_add_operator(filter, CONTACTS_FILTER_OPERATOR_OR);
696 * contacts_filter_add_str(filter, _contacts_address.country, CONTACTS_MATCH_EXACTLY, "Korea");
697 * contacts_query_create(_contacts_address._uri, &query);
698 * contacts_query_set_filter(query, filter);
700 * contacts_db_get_records_with_query(query, 0, 0, &list);
702 * contacts_filter_destroy(filter);
703 * contacts_query_destroy(query);
708 * contacts_list_destroy(list, true);
712 * @subsection CAPI_SOCIAL_CONTACTS_SVC_MODULE_FILTER_AND_QUERIES_SORT Sort
713 * Query results list can sort by property id.
716 * API int contacts_query_set_sort(contacts_query_h query, unsigned int property_id, bool is_ascending);
719 * Sample code: Sort to query result by person id
721 * contacts_filter_add_str(filter, _contacts_person.display_name, CONTACTS_MATCH_CONTAINS, “Joe”);
722 * contacts_query_set_filter(query, filter);
723 * contacts_query_set_sort(query, _contacts_person.id, true);
725 * contacts_db_get_records_with_query(query, 0, 0, &list);
727 * contacts_query_destroy(query);
728 * contacts_filter_destroy(filter);
729 * contacts_list_destroy(person_list, true);
732 * @subsection CAPI_SOCIAL_CONTACTS_SVC_MODULE_FILTER_AND_QUERIES_PROJECTION Projection
733 * Projection allows you to query the Data for just those specific properties of a record that you actually need, at lower latency and cost than retrieving the entire properties.
736 * API int contacts_query_set_projection(contacts_query_h query, unsigned int property_ids[], int count)
739 * Sample code: Creates a filter which will get only person id, display name, image thumbnail path from the person record with its vibration path has “test” (string filter). Create a query and add the filter to it. Results are received in a list.
741 * contacts_filter_add_str(filter, _contacts_person.vibration, CONTACTS_MATCH_CONTAINS, "test");
742 * contacts_query_set_filter(query, filter);
744 * //set projections to get
745 * unsigned int person_projection[] = {
746 * _contacts_person.id,
747 * _contacts_person.display_name,
748 * _contacts_person.image_thumbnail_path,
750 * contacts_query_set_projection(query, person_projection, sizeof(person_projection)/sizeof(int));
752 * contacts_db_get_records_with_query(query, 0, 0, &person_list);
757 * contacts_query_destroy(query);
758 * contacts_filter_destroy(filter);
759 * contacts_list_destroy(person_list, true);
762 * @subsection CAPI_SOCIAL_CONTACTS_SVC_MODULE_FILTER_AND_QUERIES_DISTINCT Distinct
763 * If you query to some read-only view with set projection, result list can contain duplicates. You can remove duplicates using _contacts_query_set_distinct.
766 * API int contacts_query_set_distinct(contacts_query_h query, bool set)
769 * Sample code: Remove duplicates
771 * unsigned int projection[] = {
772 * _contacts_person_number.person_id,
773 * _contacts_person_number.display_name,
775 * contacts_filter_create(_contacts_person_number._uri, &filter);
776 * contacts_filter_add_bool(filter, _contacts_person_number.has_phonenumber, true);
778 * contacts_query_create(_contacts_person_number._uri, &query);
779 * contacts_query_set_projection(query, projection, sizeof(projection)/sizeof(int));
780 * contacts_query_set_filter(query, filter);
782 * // set distinct (remove duplicates)
783 * contacts_query_set_distinct(query, true);
785 * contacts_db_get_records_with_query(query, 0, 0, &list);
790 * contacts_list_destroy(list, true);
791 * contacts_query_destroy(query);
792 * contacts_filter_destroy(filter);
795 * @section CAPI_SOCIAL_CONTACTS_SVC_MODULE_DATABASE_CHANGE_NOTIFICATIONS Database Change Notifications
796 * Applications add/remove callback function to detect/ignore the contacts DB changes with contacts_db_add_changed_cb() / contacts_db_remove_changed_cb(). <br>
797 * Clients wait contacts change notification on client side. <br>
798 * If contact is changed by another module, server publishes notification. The notification will be broadcast to subscribed modules. Finally, user callback function is called with user data.
800 * Sample code: Register person changes notification callback
802 * // callback function
803 * static void __person_changed_cb(const char *view_uri, void *user_data)
805 * // jobs for callback
807 * // add changed noti callback
808 * contacts_db_add_changed_cb(_contacts_person._uri, __person_changed_cb, NULL);
811 * @section CAPI_SOCIAL_CONTACTS_SVC_MODULE_VCARD vCard
812 * Contacts-service provides methods for parsing and making vCard . vCard APIs based on vCard v3.0 specification. For more information about vCard, refer to rfc2426 (http://www.ietf.org/rfc/rfc2426.txt)
814 * @subsection CAPI_SOCIAL_CONTACTS_SVC_MODULE_VCARD_PARSING_VCARD Parsing vCard
815 * There are two ways for parsing vCard.
817 * Sample code: Parsing vCard from stream then insert to database.
819 * // make contact record list from vcard stream
820 * contacts_list_h list = NULL;
821 * contacts_vcard_parse_to_contacts(vcard_stream, &list);
825 * contacts_db_insert_records(list, &ids, &count);
831 * contacts_list_destroy(list, true);
834 * Sample code: Parsing vCard from file then insert to database
836 * // called to get a record handle of _contacts_contact view
837 * static bool __vcard_parse_cb(contacts_record_h record, void *user_data)
840 * contacts_db_insert_record(record, &id);
842 * // return false to break out of the loop
843 * // return true to continue with the next iteration of the loop
847 * // parse vCard from file
848 * char *resource_path = app_get_resource_path();
849 * char vcard_path[1024] = {0};
850 * snprintf(vcard_path, sizeof(vcard_path), "%s/vcard.vcf", resource_path);
851 * free(resource_path);
852 * contacts_vcard_parse_to_contact_foreach(vcard_path, __vcard_parse_cb, NULL);
855 * @subsection CAPI_SOCIAL_CONTACTS_SVC_MODULE_VCARD_MAKING_VCARD_STREAM Making vCard stream
856 * You can make vcard stream from contact, person or my profile record.
858 * Sample code: Makes vCard stream using contact record.
860 * contacts_record_h contact;
861 * char *vcard_stream = NULL;
863 * contacts_db_get_record(_contacts_contact._uri, contact_id, &contact);
864 * contacts_vcard_make_from_contact(contact, &vcard_stream);
866 * // use the vcard stream
869 * free(vcard_stream);
870 * contacts_record_destroy(contact, true);
875 #endif /* __TIZEN_SOCIAL_CONTACTS_DOC_H__ */