Removing unnecessary HTML link for feature/privilege
[platform/core/pim/contacts-service.git] / doc / contacts_doc.h
1 /*
2  * Contacts Service
3  *
4  * Copyright (c) 2010 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
5  *
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
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
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.
17  *
18  */
19
20
21 #ifndef __TIZEN_SOCIAL_CONTACTS_DOC_H__
22 #define __TIZEN_SOCIAL_CONTACTS_DOC_H__
23
24
25 /**
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>
33  *
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.
39  *
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
44  * <table>
45  * <tr>
46  * <td>
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>
52  * </td>
53  * </tr>
54  * </table>
55  *
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>
63  *
64  * @section CAPI_SOCIAL_CONTACTS_SVC_MODULE_ENTITIES Entities
65  * Contacts-Service manages information related to following entities.
66  * - Contact
67  *   - Information for individuals, like name, phone number, email, address, job, instant messenger, company, etc.
68  * - Account
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.
72  * - 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.
78  * - Group
79  *   - Grouped contacts on a same address book.
80  *   - Groups and contacts have many-to-many relationship.
81  * - Person
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.
85  * - My profile
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.
88  * - Activity
89  *   - Social activities are stored.
90  * - Speed Dial
91  *   - Shortcut dialing number key information.
92  * - Phone Log
93  *   - Call or message logs are stored.
94  *
95  * @subsection CAPI_SOCIAL_CONTACTS_SVC_MODULE_ENTITIES_RELATIONSHIP Relationship between entities
96  * Contacts-service has a relationship between Entities.
97  *
98  * @image html Relationship_between_entities.png "Figure: Relationship between entities"
99  *
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.
102  *
103  * Sample code: Insert a contact record
104  * @code
105  * // create contact record
106  * contacts_record_h contact = NULL;
107  * contacts_record_create(_contacts_contact._uri, &contact);
108  *
109  * // add name
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);
114  *
115  * // add number
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);
120  *
121  * // insert to database
122  * int contact_id = 0;
123  * contacts_db_insert_record(contact, &contact_id);
124  *
125  * // destroy record
126  * contacts_record_destroy(contact, true);
127  * @endcode
128  *
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.
131  *
132  * Sample code: Link contact
133  * @code
134  * int person_id1 = ... // acquire ID of Person1 record
135  * int person_id2 = ... // acquire ID of Person2 record
136  *
137  * contacts_person_link_person(person_id1, person_id2);
138  * @endcode
139  *
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.
142  *
143  * Sample code: Unlink contact
144  * @code
145  * int person_id1 = ... // acquire ID of Person1 record
146  * int contact_id3 = ... // acquire ID of Contact3 record
147  *
148  * contacts_person_unlink_contact(person_id1, contact_id3);
149  * @endcode
150  *
151  * @image html Unlink_contact.png "Figure: Unlink contact"
152  *
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.
161  * <table>
162  * <caption> Table: Contact editable views </caption>
163  * <tr>
164  * <th>View (Editable)</th>
165  * <th>Description</th>
166  * </tr>
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>
193  * </table>
194  * <table>
195  * <caption> Table: Contact read only views </caption>
196  * <tr>
197  * <th>View (Read only)</th>
198  * <th>Description</th>
199  * </tr>
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>
218  * </table>
219  *
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.
227  *
228  * @image html Properties.png "Figure: Properties"
229  *
230  * Sample code: Create a contact record then set caller ID
231  * @code
232  * contacts_record_h contact = NULL;
233  * contacts_record_create(_contacts_contact._uri, &contact);
234  *
235  * // set image to _contacts_contact view.
236  * contacts_record_h image = NULL;
237  * contacts_record_create(_contacts_image._uri, &image);
238  *
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);
244  *
245  * // add image record to contact
246  * contacts_record_add_child_record(contact, _contacts_contact.image, image);
247  * @endcode
248  *
249  * <table class="note">
250  *    <tr>
251  *     <th class="note">Note</th>
252  *    </tr>
253  *    <tr>
254  *     <td class="note">For an application to insert private images in contacts, it needs to follow below conditions:<br/>
255  * &nbsp;&nbsp;&nbsp;1. Application must have privilege of %http://tizen.org/privilege/contact.write to use APIs such as contacts_db_insert_record().<br/>
256  * &nbsp;&nbsp;&nbsp;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  * &nbsp;&nbsp;&nbsp;3. Application may erase the image after destroying the contact record (contacts_record_destroy).<br/>
258  *     </td>
259  *    </tr>
260  * </table>
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.
271  *
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.
276  *
277  * APIs which needs _uri
278  * @code
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, ...)
292  * @endcode
293  *
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.
299  *
300  * Sample code: Creates a contact record
301  * @code
302  * contacts_record_h contact = NULL;
303  * contacts_record_create(_contacts_contact._uri, &contact);
304  * @endcode
305  *
306  * Sample code: Gets a contact record with id
307  * @code
308  * contacts_record_h contact = NULL;
309  * contacts_db_get_record(_contacts_contact._uri, id, &contact);
310  * @endcode
311  *
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:
315  * <table>
316  * <caption> Table: Setter and getter functions </caption>
317  * <tr>
318  *    <th>Property type</th>
319  *    <th>Setter</th>
320  *    <th>Getter</th>
321  * </tr>
322  * <tr>
323  *    <td> string </td>
324  *    <td> @ref contacts_record_set_str </td>
325  *    <td> @ref contacts_record_get_str </td>
326  * </tr>
327  * <tr>
328  *    <td> integer </td>
329  *    <td> @ref contacts_record_set_int </td>
330  *    <td> @ref contacts_record_get_int </td>
331  * </tr>
332  * <tr>
333  *    <td> boolean </td>
334  *    <td> @ref contacts_record_set_bool </td>
335  *    <td> @ref contacts_record_get_bool </td>
336  * </tr>
337  * <tr>
338  *    <td> long long integer </td>
339  *    <td> @ref contacts_record_set_lli </td>
340  *    <td> @ref contacts_record_get_lli </td>
341  * </tr>
342  * <tr>
343  *    <td> double </td>
344  *    <td> @ref contacts_record_set_double </td>
345  *    <td> @ref contacts_record_get_double </td>
346  * </tr>
347  * </table>
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)
352  *
353  * Sample code : Sets the ‘ringtone_path’ property of a contact record.
354  * @code
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);
360  * @endcode
361  *
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.
364  *
365  * Sample code: Two ways of getting string property
366  * @code
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);
369  * @endcode
370  *
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.
373  *
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.
380  *
381  * Sample code: Add child record
382  * @code
383  * contacts_record_h address = NULL;
384  * contacts_record_h image = NULL;
385  * int contact_id = 0;
386  *
387  * // image, address record can be child record of contact record
388  * contacts_record_create(_contacts_contact._uri, &contact);
389  *
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);
397  *
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);
401  *
402  * // insert contact to DBs
403  * contacts_db_insert_record(contact, &contact_id);
404  * contacts_record_destroy(contact, true);
405  * @endcode
406  *
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.
410  *
411  * Sample code: Gets a contact record with id
412  * @code
413  * contacts_record_h contact = NULL;
414  * contacts_record_create(_contacts_contact._uri, &contact);
415  *
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);
420  *
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
424  *
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
429  * @endcode
430  *
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.
432  *
433  * Sample code: Insert a address record with contact_id
434  * @code
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
440  * // ...
441  * contacts_db_insert_record(address, &address_id);
442  * @endcode
443  * Having a record handle, you can access all records of a specific type related to the given record.
444  *
445  * Sample code: Gets a contact record
446  * @code
447  * int contact_id = ... // acquire id of created contact
448  * int address_num = 0;
449  * int i = 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");
456  * }
457  * contacts_db_update_record(contact);
458  * contacts_record_destroy(contact, true);
459  * @endcode
460  *
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.
465  *
466  * @code
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);
469  * @endcode
470  *
471  * If ‘delete_child’ parameter is the true, child resources will destroy automatically.
472  *
473  * Sample code: Create a list handle
474  * @code
475  * // get list handle with query
476  * contacts_list_h list = NULL;
477  * contacts_list_create(&list);
478  *
479  * // use list
480  * //  ...
481  *
482  * contacts_list_destroy(list, true);
483  * @endcode
484  *
485  * Sample code: Gets person list handle from database.
486  * @code
487  * // get list handle with query
488  * contacts_list_h list = NULL;
489  * contacts_db_get_all_records(_contacts_person._uri, 0, 0, &list);
490  *
491  * // use list
492  * // ...
493  *
494  * contacts_list_destroy(list, true);
495  * @endcode
496  *
497  * @subsection CAPI_SOCIAL_CONTACTS_SVC_MODULE_LISTS_CURSOR Cursor
498  * The list can be traversed by using cursor.
499  *
500  * @code
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);
505  * @endcode
506  *
507  * You can get a record of current cursor.
508  *
509  * @code
510  * API int contacts_list_get_current_record_p(contacts_list_h contacts_list, contacts_record_h* record);
511  * @endcode
512  *
513  * Sample code: Loop list
514  * @code
515  * contacts_list_h list = NULL;
516  * contacts_record_h record = NULL;
517  * contacts_db_get_all_records(_contacts_person._uri, 0, 0, &list);
518  * do {
519  *  contacts_list_get_current_record_p(list, &record);
520  *  if (NULL == record)
521  *   break;
522  *  char *name = NULL;
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
527  * @endcode
528  *
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.
531  * @code
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);
534  * @endcode
535  *
536  * Sample code: Adds records to the list
537  * @code
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”);
541  *
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”);
545  *
546  * contacts_list_h list = NULL;
547  * contacts_list_create(&list);
548  *
549  * // Adds records to the list
550  * contacts_list_add(list, group1);
551  * contacts_list_add(list, group2);
552  *
553  * contacts_db_insert_records(list, NULL, NULL);
554  * contacts_list_destroy(list, true);
555  * @endcode
556  *
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.
559  *
560  * @code
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);
565  * @endcode
566  *
567  * Sample code: Insert two contact records using bulk API.
568  * @code
569  * contacts_record_h contact1;
570  * contacts_record_create(_contacts_contact.uri, &contact1);
571  *
572  * // fill contact record
573  * // ...
574  *
575  * contacts_record_h contact2;
576  * contacts_record_create(_contacts_contact._uri, &contact2);
577  *
578  * // fill contact record
579  * // ...
580  *
581  * contacts_list_h list = NULL;
582  * contacts_list_create(&list);
583  *
584  * contacts_list_add(list, contact1);
585  * contacts_list_add(list, contact2);
586  *
587  * int **ids = NULL;
588  * int count = 0;
589  *
590  * // Insert contact records using bulk API
591  * contacts_db_insert_records(list, &ids, &count);
592  *
593  * // use ids
594  * // ...
595  *
596  * contacts_list_destroy(list, true);
597  * free(ids);
598  * @endcode
599  *
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.
602  *
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.
606  *
607  * @code
608  * API int contacts_filter_create(const char* view_uri, contacts_filter_h* filter);
609  * API int contacts_filter_destroy(contacts_filter_h filter);
610  * @endcode
611  *
612  * Sample code: Set filter condition to contain a given substring.
613  * @code
614  * contacts_filter_add_str(filter, _contacts_person.display_name, CONTACTS_MATCH_CONTAINS, “1234”);
615  * @endcode
616  *
617  * Sample code: Set filter condition to property value is true.
618  * @code
619  * contacts_filter_add_bool(filter, _contacts_person.is_favorite, true);
620  * @endcode
621  *
622  * Conditions can be added to a filter. The conditions SHOULD be joined by using a AND and OR logical operator.
623  *
624  * Sample code: Creates composite filter with OR operator.
625  * @code
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”);
629  * @endcode
630  *
631  * Additionally, filters can join each other by using a AND and OR logical operator.
632  *
633  * Sample code: Creates joined filter with AND operator.
634  * @code
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”);
638  *
639  * contacts_filter_add_bool(filter2, _contacts_person.is_fovorite, true);
640  *
641  * contacts_filter_add_operator(filter1, CONTACTS_FILTER_OPERATOR_AND);
642  * contacts_filter_add_filter(filter1, filter2);
643  * @endcode
644  *
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:
646  * <table>
647  * <caption> Table: Filter and conditions </caption>
648  * <tr>
649  *      <th> Filter with conditions </th>
650  *      <th> Result </th>
651  * </tr>
652  * <tr>
653  *      <td>
654  *              Contidion C1 <br>
655  *              OR <br>
656  *              Contidion C2 <br>
657  *              AND <br>
658  *              Condition C3
659  *      </td>
660  *      <td> (C1 OR C2) AND C3 </td>
661  * </tr>
662  * <tr>
663  *      <td>
664  *              Filter F1: <br>
665  *                      Condition C1 <br>
666  *                      OR <br>
667  *                      Condition C2 <br><br>
668  *              Filter F2: <br>
669  *                      Condition C3 <br>
670  *                      OR <br>
671  *                      Condition C4 <br><br>
672  *              Filter F3: <br>
673  *                      Condition C5 <br>
674  *                      AND <br>
675  *                      F1 <br>
676  *                      AND <br>
677  *                      F2
678  *      </td>
679  *      <td>
680  *              (C5 AND F1) AND F2 <br>
681  *              Which is: <br>
682  *              (C5 AND (C1 OR C2)) AND (C3 OR C4)
683  *      </td>
684  * </tr>
685  * </table>
686  *
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.
688  * @code
689  * contacts_filter_h filter = NULL;
690  * contacts_list_h list = NULL;
691  * contacts_query_h query = NULL;
692  *
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);
699  *
700  * contacts_db_get_records_with_query(query, 0, 0, &list);
701  *
702  * contacts_filter_destroy(filter);
703  * contacts_query_destroy(query);
704  *
705  * // use the list
706  * // ...
707  *
708  * contacts_list_destroy(list, true);
709  *
710  * @endcode
711  *
712  * @subsection CAPI_SOCIAL_CONTACTS_SVC_MODULE_FILTER_AND_QUERIES_SORT Sort
713  * Query results list can sort by property id.
714  *
715  * @code
716  * API int contacts_query_set_sort(contacts_query_h query, unsigned int property_id, bool is_ascending);
717  * @endcode
718  *
719  * Sample code: Sort to query result by person id
720  * @code
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);
724  *
725  * contacts_db_get_records_with_query(query, 0, 0, &list);
726  *
727  * contacts_query_destroy(query);
728  * contacts_filter_destroy(filter);
729  * contacts_list_destroy(person_list, true);
730  * @endcode
731  *
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.
734  *
735  * @code
736  * API int contacts_query_set_projection(contacts_query_h query, unsigned int property_ids[], int count)
737  * @endcode
738  *
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.
740  * @code
741  * contacts_filter_add_str(filter, _contacts_person.vibration, CONTACTS_MATCH_CONTAINS, "test");
742  * contacts_query_set_filter(query, filter);
743  *
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,
749  * };
750  * contacts_query_set_projection(query, person_projection, sizeof(person_projection)/sizeof(int));
751  *
752  * contacts_db_get_records_with_query(query, 0, 0, &person_list);
753  *
754  * // use list
755  * // ...
756  *
757  * contacts_query_destroy(query);
758  * contacts_filter_destroy(filter);
759  * contacts_list_destroy(person_list, true);
760  * @endcode
761  *
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.
764  *
765  * @code
766  * API int contacts_query_set_distinct(contacts_query_h query, bool set)
767  * endcode
768  *
769  * Sample code: Remove duplicates
770  * @code
771  * unsigned int projection[] = {
772  * _contacts_person_number.person_id,
773  * _contacts_person_number.display_name,
774  * };
775  * contacts_filter_create(_contacts_person_number._uri, &filter);
776  * contacts_filter_add_bool(filter, _contacts_person_number.has_phonenumber, true);
777  *
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);
781  *
782  * // set distinct (remove duplicates)
783  * contacts_query_set_distinct(query, true);
784  *
785  * contacts_db_get_records_with_query(query, 0, 0, &list);
786  *
787  * // use list
788  * // ...
789  *
790  * contacts_list_destroy(list, true);
791  * contacts_query_destroy(query);
792  * contacts_filter_destroy(filter);
793  * @endcode
794  *
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.
799  *
800  * Sample code: Register person changes notification callback
801  * @code
802  * // callback function
803  * static void __person_changed_cb(const char *view_uri, void *user_data)
804  * {
805  * // jobs for callback
806  * }
807  * // add changed noti callback
808  * contacts_db_add_changed_cb(_contacts_person._uri,  __person_changed_cb,  NULL);
809  * @endcode
810  *
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)
813  *
814  * @subsection CAPI_SOCIAL_CONTACTS_SVC_MODULE_VCARD_PARSING_VCARD Parsing vCard
815  * There are two ways for parsing vCard.
816  *
817  * Sample code: Parsing vCard from stream then insert to database.
818  * @code
819  * // make contact record list from vcard stream
820  * contacts_list_h list = NULL;
821  * contacts_vcard_parse_to_contacts(vcard_stream, &list);
822  *
823  * int *ids = NULL;
824  * int count = 0;
825  * contacts_db_insert_records(list, &ids, &count);
826  *
827  * // use ids, count
828  * // ...
829  *
830  * free(ids);
831  * contacts_list_destroy(list, true);
832  * @endcode
833  *
834  * Sample code: Parsing vCard from file then insert to database
835  * @code
836  * // called to get a record handle of _contacts_contact view
837  * static bool __vcard_parse_cb(contacts_record_h record, void *user_data)
838  * {
839  * int id = 0;
840  * contacts_db_insert_record(record, &id);
841  *
842  * // return false to break out of the loop
843  * // return true to continue with the next iteration of the loop
844  * return true;
845  * }
846  *
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);
853  * @endcode
854  *
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.
857  *
858  * Sample code: Makes vCard stream using contact record.
859  * @code
860  * contacts_record_h contact;
861  * char *vcard_stream = NULL;
862  *
863  * contacts_db_get_record(_contacts_contact._uri, contact_id, &contact);
864  * contacts_vcard_make_from_contact(contact, &vcard_stream);
865  *
866  * // use the vcard stream
867  * // ...
868  *
869  * free(vcard_stream);
870  * contacts_record_destroy(contact, true);
871  * @endcode
872  */
873
874
875 #endif /* __TIZEN_SOCIAL_CONTACTS_DOC_H__ */
876