fix code for coding convention
[platform/core/api/libaccount-service.git] / include / account_PG.h
1 /*
2  * Account
3  *
4  * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Wonyoung Lee <wy1115.lee@samsung.com>, Sungchan Kim <sungchan81.kim@samsung.com>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  */
21
22 /**
23  *
24  * @ingroup   SLP_PG
25  * @defgroup  Account_PG Account
26
27
28 <h1 class="pg">Introduction</h1>
29         <h2 class="pg">Purpose of this document</h2>
30
31 The purpose of this document is to describe how applications can use account APIs for handling Account's information. This document gives programming guidelines to application engineers and examples of using Account data.
32
33         <h2 class="pg">Scope</h2>
34
35 The scope of this document is limited to Account API usage.
36
37
38 <h1 class="pg">Account Architecture</h1>
39         <h2 class="pg"> Overview</h2>
40
41 Account is responsible for inserting, deleting, and updating Account data in order to accommodate the needs for application's Account data.
42 Users can access Account data without knowing DB schema, SQLite, relations of data
43
44 <h1 class="pg">Account Features</h1>
45         - Similar to Sqlite3
46         - Handle information of Account
47
48         <h2 class="pg">Similar to Sqlite3</h2>
49 Account API is similar to Sqlite3.
50
51         <h2 class="pg">Handle information of Account</h2>
52 Account supports to insert/update/delete/get/set/query information of Account.
53 The Information of Account includes user name, package name, email, access token, icon path, source, display name, capability informatio etc.
54
55 <h1 class="pg">Account API Description</h1>
56
57 you can refer @ref ACCOUNT_SVC
58
59 <h1 class="pg">Sample Code</h1>
60
61         <h2 class="pg">Connect to Account Database</h2>
62
63 Before using Account information from Account API, caller module should connect to the Account database, and after finishing with the account information, should disconnect from the Account database
64
65 @code
66 int account_connect(void);
67
68 int account_disconnect(void);
69 @endcode
70
71         <h2 class="pg">Insert information of account</h2>
72
73 @code
74 void insert_test(void)
75 {
76         int ret = -1;
77         account_h account;
78
79         ret = account_connect();
80         if(ret != ACCOUNT_ERROR_NONE)
81         {
82                 SECURE_LOGD("(%d)-[Account] ret = %d, account=%p\n", __LINE__, ret, account);
83         }
84
85         ret = account_create(&account);
86         if(ret != ACCOUNT_ERROR_NONE)
87         {
88                 SECURE_LOGD("(%d)-[Account] ret = %d, account=%p\n", __LINE__, ret, account);
89         }
90
91         ret = account_set_user_name(account, "tarun.kr");
92
93         if(ret != ACCOUNT_ERROR_NONE)
94         {
95                 SECURE_LOGD("(%d)-[Account] ret = %d, account=%p\n", __LINE__, ret, account);
96         }
97
98         ret = account_set_display_name(account, "Tarun Kumar");
99
100         if(ret != ACCOUNT_ERROR_NONE)
101         {
102                 SECURE_LOGD("(%d)-[Account] ret = %d, account=%p\n", __LINE__, ret, account);
103         }
104
105         ret = account_set_domain_name(account, "Samsung electronics");
106         if(ret != ACCOUNT_ERROR_NONE)
107         {
108                 SECURE_LOGD("(%d)-[Account] ret = %d, account=%p\n", __LINE__, ret, account);
109         }
110
111         ret = account_set_email_address(account, "tarun@gmail.com");
112         if(ret != ACCOUNT_ERROR_NONE)
113         {
114                 SECURE_LOGD("(%d)-[Account] ret = %d, account=%p\n", __LINE__, ret, account);
115         }
116
117         ret = account_set_package_name(account, "com.samsung.twiter");
118         if(ret != ACCOUNT_ERROR_NONE)
119         {
120                 SECURE_LOGD("(%d)-[Account] ret = %d, account=%p\n", __LINE__, ret, account);
121         }
122
123         ret = account_set_icon_path(account, "icon-path");
124         if(ret != ACCOUNT_ERROR_NONE)
125         {
126                 SECURE_LOGD("(%d)-[Account] ret = %d, account=%p\n", __LINE__, ret, account);
127         }
128
129         ret = account_set_access_token(account, "ACCESSTOKEN");
130         if(ret != ACCOUNT_ERROR_NONE)
131         {
132                 SECURE_LOGD("(%d)-[Account] ret = %d, account=%p\n", __LINE__, ret, account);
133         }
134
135         ret = account_set_auth_type( account, ACCOUNT_AUTH_TYPE_OAUTH );
136         if(ret != ACCOUNT_ERROR_NONE)
137         {
138                 SECURE_LOGD("(%d)-[Account] ret = %d, account=%p\n", __LINE__, ret, account);
139         }
140
141         ret = account_set_secret( account, ACCOUNT_SECRECY_INVISIBLE );
142         if(ret != ACCOUNT_ERROR_NONE)
143         {
144                 SECURE_LOGD("(%d)-[Account] ret = %d, account=%p\n", __LINE__, ret, account);
145         }
146         ret = account_set_source(account, "URUSA inc.");
147
148         int i;
149
150         for(i=0;i<USER_TXT_CNT;i++)
151         {
152                 ret = account_set_user_text(account, i, "user txt");
153                 if(ret != ACCOUNT_ERROR_NONE)
154                 {
155                         SECURE_LOGD("(%d)-[Account] ret = %d, account=%p, i=%d\n", __LINE__, ret, account, i);
156                 }
157
158         }
159
160         for(i=0;i<USER_INT_CNT;i++)
161         {
162                 ret = account_set_user_int(account, i, 888);
163                 if(ret != ACCOUNT_ERROR_NONE)
164                 {
165                         SECURE_LOGD("(%d)-[Account] ret = %d, account=%p, i=%d\n", __LINE__, ret, account, i);
166                 }
167         }
168
169         ret = account_set_capability(account, ACCOUNT_CAPABILITY_CONTACT, ACCOUNT_CAPABILITY_ENABLED);
170         ret = account_set_capability(account, ACCOUNT_CAPABILITY_CALENDAR, ACCOUNT_CAPABILITY_ENABLED);
171         ret = account_set_capability(account, ACCOUNT_CAPABILITY_PHOTO, ACCOUNT_CAPABILITY_ENABLED);
172         ret = account_set_capability(account, ACCOUNT_CAPABILITY_VIDEO, ACCOUNT_CAPABILITY_ENABLED);
173         ret = account_set_capability(account, ACCOUNT_CAPABILITY_EMAIL, ACCOUNT_CAPABILITY_ENABLED);
174         ret = account_set_capability(account, ACCOUNT_CAPABILITY_STATUS_POST, ACCOUNT_CAPABILITY_ENABLED);
175         ret = account_set_capability(account, ACCOUNT_CAPABILITY_VOIP, ACCOUNT_CAPABILITY_ENABLED);
176         ret = account_set_capability(account, ACCOUNT_CAPABILITY_SAMSUNG_APPS, ACCOUNT_CAPABILITY_ENABLED);
177         ret = account_set_capability(account, ACCOUNT_CAPABILITY_MOBILE_TRACKER, ACCOUNT_CAPABILITY_ENABLED);
178
179         int account_id = -1;
180         ret = account_insert_to_db(account, &account_id);
181         if(ret != ACCOUNT_ERROR_NONE)
182         {
183                 SECURE_LOGD("(%d)-[Account] ret = %d, account=%p\n", __LINE__, ret, account);
184                 return;
185         }
186
187         ret = account_destroy(account);
188         if(ret != ACCOUNT_ERROR_NONE)
189         {
190                 SECURE_LOGD("(%d)-[Account] ret = %d, account=%p\n", __LINE__, ret, account);
191         }
192
193         ret = account_disconnect();
194         if(ret != ACCOUNT_ERROR_NONE)
195         {
196                 SECURE_LOGD("(%d)-[Account] ret = %d, account=%p\n", __LINE__, ret, account);
197         }
198
199         return;
200 }
201 @endcode
202
203         <h2 class="pg">Get account by id</h2>
204
205 @code
206 bool _capability_get_callback(const char* capability_type, account_capability_state_e capability_value, void* user_data)
207 {
208         char* test_type = capability_type;
209         int test_value = capability_value;
210
211         SECURE_LOGD("_capability_get_callback test_type = : %s\n", test_type);
212         SECURE_LOGD("_capability_get_callback test_value = : %d\n", test_value);
213         return TRUE;
214 }
215
216 static void _account_free_text(char *text)
217 {
218         if (text) {
219                 free(text);
220                 text = NULL;
221         }
222 }
223
224 void get_account_by_id(int account_id)
225 {
226         int ret = - 1;
227         account_h account;
228
229         ret = account_connect();
230         if(ret != ACCOUNT_ERROR_NONE)
231         {
232                 SECURE_LOGD("(%d)-[Account] ret = %d, \n", __LINE__, ret);
233         }
234
235         ret = account_create(&account);
236         if(ret != ACCOUNT_ERROR_NONE)
237         {
238                 SECURE_LOGD("(%d)-[Account] ret = %d, account=%p\n", __LINE__, ret, account);
239         }
240
241         ret = account_query_account_by_account_id(account_id, &account);
242         if(ret != ACCOUNT_ERROR_NONE)
243         {
244                 SECURE_LOGD("(%d)-[Account] ret = %d, account=%p\n", __LINE__, ret, account);
245         }
246
247         char *test_text = NULL;
248
249         account_get_user_name(handle, &test_text);
250         SECURE_LOGD("_account_get_callback : %s\n", test_text);
251
252         _account_free_text(test_text);
253
254         account_get_display_name(handle, &test_text);
255         SECURE_LOGD("_account_get_callback : %s\n", test_text);
256
257         _account_free_text(test_text);
258
259         account_get_email_address(handle, &test_text);
260         SECURE_LOGD("_account_get_callback : %s\n", test_text);
261
262         _account_free_text(test_text);
263
264         account_get_icon_path(handle, &test_text);
265         SECURE_LOGD("_account_get_callback : %s\n", test_text);
266
267         _account_free_text(test_text);
268
269         account_get_source(handle, &test_text);
270         SECURE_LOGD("_account_get_callback : %s\n", test_text);
271
272         _account_free_text(test_text);
273
274         account_get_package_name(handle, &test_text);
275         SECURE_LOGD("_account_get_callback : %s\n", test_text);
276
277         _account_free_text(test_text);
278
279         account_get_domain_name(handle, &test_text);
280         SECURE_LOGD("_account_get_callback : %s\n", test_text);
281
282         _account_free_text(test_text);
283
284         account_get_access_token(handle, &test_text);
285         SECURE_LOGD("_account_get_callback : %s\n", test_text);
286
287         int i;
288
289         for(i=0;i<USER_TXT_CNT;i++)
290         {
291                 _account_free_text(test_text);
292
293                 account_get_user_text(handle, i, &test_text);
294                 SECURE_LOGD("_account_get_callback : %s\n", test_text);
295         }
296
297         int test_int  = -1;
298
299         account_auth_type_e auth_type;
300         account_get_auth_type(handle, &auth_type);
301         SECURE_LOGD("account_get_auth_type : %d\n", auth_type);
302
303         account_secrecy_state_e secret;
304         account_get_secret(handle, &secret);
305         SECURE_LOGD("account_get_secret : %d\n", secret);
306
307         account_sync_state_e sync_support;
308         account_get_sync_support(handle, &sync_support);
309         SECURE_LOGD("account_get_sync_support : %d\n", sync_support);
310
311         for(i=0;i<USER_INT_CNT;i++)
312         {
313                 test_int  = -1;
314                 account_get_user_int(handle, i, &test_int);
315                 SECURE_LOGD("_account_get_callback : %d\n", test_int);
316         }
317
318         account_get_capability(handle, _capability_get_callback, NULL);
319
320         ret = account_destroy(account);
321         if(ret != ACCOUNT_ERROR_NONE)
322         {
323                 SECURE_LOGD("(%d)-[Account] ret = %d, account=%p\n", __LINE__, ret, account);
324         }
325
326         ret = account_disconnect();
327         if(ret != ACCOUNT_ERROR_NONE)
328         {
329                 SECURE_LOGD("(%d)-[Account] ret = %d, \n", __LINE__, ret);
330         }
331 }
332 @endcode
333
334
335         <h2 class="pg">Get account list by user name</h2>
336
337 @code
338 static void _account_free_text(char *text)
339 {
340         if (text) {
341                 free(text);
342                 text = NULL;
343         }
344 }
345
346 bool _account_get_callback(account_h handle, void* user_data)
347 {
348         SECURE_LOGD("_account_get_callback\n");
349
350         char *test_text = NULL;
351
352         account_get_user_name(handle, &test_text);
353         SECURE_LOGD("_account_get_callback : %s\n", test_text);
354
355         _account_free_text(test_text);
356
357         account_get_display_name(handle, &test_text);
358         SECURE_LOGD("_account_get_callback : %s\n", test_text);
359
360         _account_free_text(test_text);
361
362         account_get_email_address(handle, &test_text);
363         SECURE_LOGD("_account_get_callback : %s\n", test_text);
364
365         _account_free_text(test_text);
366
367         account_get_icon_path(handle, &test_text);
368         SECURE_LOGD("_account_get_callback : %s\n", test_text);
369
370         _account_free_text(test_text);
371
372         account_get_source(handle, &test_text);
373         SECURE_LOGD("_account_get_callback : %s\n", test_text);
374
375         _account_free_text(test_text);
376
377         account_get_package_name(handle, &test_text);
378         SECURE_LOGD("_account_get_callback : %s\n", test_text);
379
380         _account_free_text(test_text);
381
382         account_get_domain_name(handle, &test_text);
383         SECURE_LOGD("_account_get_callback : %s\n", test_text);
384
385         _account_free_text(test_text);
386
387         account_get_access_token(handle, &test_text);
388         SECURE_LOGD("_account_get_callback : %s\n", test_text);
389
390         int i;
391
392         for(i=0;i<USER_TXT_CNT;i++)
393         {
394                 _account_free_text(test_text);
395
396                 account_get_user_text(handle, i, &test_text);
397                 SECURE_LOGD("_account_get_callback : %s\n", test_text);
398         }
399
400         int test_int  = -1;
401
402         account_auth_type_e auth_type;
403         account_get_auth_type(handle, &auth_type);
404         SECURE_LOGD("account_get_auth_type : %d\n", auth_type);
405
406         account_secrecy_state_e secret;
407         account_get_secret(handle, &secret);
408         SECURE_LOGD("account_get_secret : %d\n", secret);
409
410         account_sync_state_e sync_support;
411         account_get_sync_support(handle, &sync_support);
412         SECURE_LOGD("account_get_sync_support : %d\n", sync_support);
413
414         for(i=0;i<USER_INT_CNT;i++)
415         {
416                 test_int  = -1;
417                 account_get_user_int(handle, i, &test_int);
418                 SECURE_LOGD("_account_get_callback : %d\n", test_int);
419         }
420
421         account_get_capability(handle, _capability_get_callback, NULL);
422
423         return TRUE;
424 }
425
426
427 void get_account_list_by_user_name(char * user_name)
428 {
429         int ret = - 1;
430         account_h account;
431
432         ret = account_connect();
433         if(ret != ACCOUNT_ERROR_NONE)
434         {
435                 SECURE_LOGD("(%d)-[Account] ret = %d, \n", __LINE__, ret);
436         }
437
438         ret = account_query_account_by_user_name(_account_get_callback, user_name, NULL);
439         if(ret != ACCOUNT_ERROR_NONE)
440         {
441                 SECURE_LOGD("(%d)-[Account] ret = %d, account=%p\n", __LINE__, ret, account);
442         }
443
444         ret = account_disconnect();
445         if(ret != ACCOUNT_ERROR_NONE)
446         {
447                 SECURE_LOGD("(%d)-[Account] ret = %d, \n", __LINE__, ret);
448         }
449 }
450 @endcode
451
452         <h2 class="pg">Get account list by package name</h2>
453
454 @code
455 static void _account_free_text(char *text)
456 {
457         if (text) {
458                 free(text);
459                 text = NULL;
460         }
461 }
462
463 bool _account_get_callback(account_h handle, void* user_data)
464 {
465         SECURE_LOGD("_account_get_callback\n");
466
467         char *test_text = NULL;
468
469         account_get_user_name(handle, &test_text);
470         SECURE_LOGD("_account_get_callback : %s\n", test_text);
471
472         _account_free_text(test_text);
473
474         account_get_display_name(handle, &test_text);
475         SECURE_LOGD("_account_get_callback : %s\n", test_text);
476
477         _account_free_text(test_text);
478
479         account_get_email_address(handle, &test_text);
480         SECURE_LOGD("_account_get_callback : %s\n", test_text);
481
482         _account_free_text(test_text);
483
484         account_get_icon_path(handle, &test_text);
485         SECURE_LOGD("_account_get_callback : %s\n", test_text);
486
487         _account_free_text(test_text);
488
489         account_get_source(handle, &test_text);
490         SECURE_LOGD("_account_get_callback : %s\n", test_text);
491
492         _account_free_text(test_text);
493
494         account_get_package_name(handle, &test_text);
495         SECURE_LOGD("_account_get_callback : %s\n", test_text);
496
497         _account_free_text(test_text);
498
499         account_get_domain_name(handle, &test_text);
500         SECURE_LOGD("_account_get_callback : %s\n", test_text);
501
502         _account_free_text(test_text);
503
504         account_get_access_token(handle, &test_text);
505         SECURE_LOGD("_account_get_callback : %s\n", test_text);
506
507         int i;
508
509         for(i=0;i<USER_TXT_CNT;i++)
510         {
511                 _account_free_text(test_text);
512
513                 account_get_user_text(handle, i, &test_text);
514                 SECURE_LOGD("_account_get_callback : %s\n", test_text);
515         }
516
517         int test_int  = -1;
518
519         account_auth_type_e auth_type;
520         account_get_auth_type(handle, &auth_type);
521         SECURE_LOGD("account_get_auth_type : %d\n", auth_type);
522
523         account_secrecy_state_e secret;
524         account_get_secret(handle, &secret);
525         SECURE_LOGD("account_get_secret : %d\n", secret);
526
527         account_sync_state_e sync_support;
528         account_get_sync_support(handle, &sync_support);
529         SECURE_LOGD("account_get_sync_support : %d\n", sync_support);
530
531         for(i=0;i<USER_INT_CNT;i++)
532         {
533                 test_int  = -1;
534                 account_get_user_int(handle, i, &test_int);
535                 SECURE_LOGD("_account_get_callback : %d\n", test_int);
536         }
537
538         account_get_capability(handle, _capability_get_callback, NULL);
539
540         return TRUE;
541 }
542
543 void get_account_list_by_package_name(char * package_name)
544 {
545         int ret = - 1;
546         account_h account;
547
548         ret = account_connect();
549         if(ret != ACCOUNT_ERROR_NONE)
550         {
551                 SECURE_LOGD("(%d)-[Account] ret = %d, \n", __LINE__, ret);
552         }
553
554         ret = account_query_account_by_package_name(_account_get_callback, package_name, NULL);
555         if(ret != ACCOUNT_ERROR_NONE)
556         {
557                 SECURE_LOGD("(%d)-[Account] ret = %d, account=%p\n", __LINE__, ret, account);
558         }
559
560         ret = account_disconnect();
561         if(ret != ACCOUNT_ERROR_NONE)
562         {
563                 SECURE_LOGD("(%d)-[Account] ret = %d, \n", __LINE__, ret);
564         }
565 }
566 @endcode
567
568         <h2 class="pg">Get all account list</h2>
569
570 @code
571 static void _account_free_text(char *text)
572 {
573         if (text) {
574                 free(text);
575                 text = NULL;
576         }
577 }
578
579 bool _account_get_callback(account_h handle, void* user_data)
580 {
581         SECURE_LOGD("_account_get_callback\n");
582
583         char *test_text = NULL;
584
585         account_get_user_name(handle, &test_text);
586         SECURE_LOGD("_account_get_callback : %s\n", test_text);
587
588         _account_free_text(test_text);
589
590         account_get_display_name(handle, &test_text);
591         SECURE_LOGD("_account_get_callback : %s\n", test_text);
592
593         _account_free_text(test_text);
594
595         account_get_email_address(handle, &test_text);
596         SECURE_LOGD("_account_get_callback : %s\n", test_text);
597
598         _account_free_text(test_text);
599
600         account_get_icon_path(handle, &test_text);
601         SECURE_LOGD("_account_get_callback : %s\n", test_text);
602
603         _account_free_text(test_text);
604
605         account_get_source(handle, &test_text);
606         SECURE_LOGD("_account_get_callback : %s\n", test_text);
607
608         _account_free_text(test_text);
609
610         account_get_package_name(handle, &test_text);
611         SECURE_LOGD("_account_get_callback : %s\n", test_text);
612
613         _account_free_text(test_text);
614
615         account_get_domain_name(handle, &test_text);
616         SECURE_LOGD("_account_get_callback : %s\n", test_text);
617
618         _account_free_text(test_text);
619
620         account_get_access_token(handle, &test_text);
621         SECURE_LOGD("_account_get_callback : %s\n", test_text);
622
623         int i;
624
625         for(i=0;i<USER_TXT_CNT;i++)
626         {
627                 _account_free_text(test_text);
628
629                 account_get_user_text(handle, i, &test_text);
630                 SECURE_LOGD("_account_get_callback : %s\n", test_text);
631         }
632
633         int test_int  = -1;
634
635         account_auth_type_e auth_type;
636         account_get_auth_type(handle, &auth_type);
637         SECURE_LOGD("account_get_auth_type : %d\n", auth_type);
638
639         account_secrecy_state_e secret;
640         account_get_secret(handle, &secret);
641         SECURE_LOGD("account_get_secret : %d\n", secret);
642
643         account_sync_state_e sync_support;
644         account_get_sync_support(handle, &sync_support);
645         SECURE_LOGD("account_get_sync_support : %d\n", sync_support);
646
647         for(i=0;i<USER_INT_CNT;i++)
648         {
649                 test_int  = -1;
650                 account_get_user_int(handle, i, &test_int);
651                 SECURE_LOGD("_account_get_callback : %d\n", test_int);
652         }
653
654         account_get_capability(handle, _capability_get_callback, NULL);
655
656         return TRUE;
657 }
658
659 void get_all_account()
660 {
661         int ret = - 1;
662         account_h account;
663
664         ret = account_connect();
665         if(ret != ACCOUNT_ERROR_NONE)
666         {
667                 SECURE_LOGD("(%d)-[Account] ret = %d, \n", __LINE__, ret);
668         }
669
670         ret = account_foreach_account_from_db(_account_get_callback, NULL);
671         if(ret != ACCOUNT_ERROR_NONE)
672         {
673                 SECURE_LOGD("(%d)-[Account] ret = %d, account=%p\n", __LINE__, ret, account);
674         }
675
676         ret = account_disconnect();
677         if(ret != ACCOUNT_ERROR_NONE)
678         {
679                 SECURE_LOGD("(%d)-[Account] ret = %d, \n", __LINE__, ret);
680         }
681 }
682 @endcode
683
684         <h2 class="pg">Update information of account by account id</h2>
685
686 @code
687 void update_accont_by_id(int account_id)
688 {
689         int ret = -1;
690         account_h account;
691
692         ret = account_connect();
693         if(ret != ACCOUNT_ERROR_NONE)
694         {
695                 SECURE_LOGD("(%d)-[Account] ret = %d, account=%p\n", __LINE__, ret, account);
696         }
697
698         ret = account_create(&account);
699         if(ret != ACCOUNT_ERROR_NONE)
700         {
701                 SECURE_LOGD("(%d)-[Account] ret = %d, account=%p\n", __LINE__, ret, account);
702         }
703
704         ret = account_set_user_name(account, "update-tarun.kr");
705
706         if(ret != ACCOUNT_ERROR_NONE)
707         {
708                 SECURE_LOGD("(%d)-[Account] ret = %d, account=%p\n", __LINE__, ret, account);
709         }
710
711         ret = account_set_display_name(account, "update-Tarun Kumar");
712         if(ret != ACCOUNT_ERROR_NONE)
713         {
714                 SECURE_LOGD("(%d)-[Account] ret = %d, account=%p\n", __LINE__, ret, account);
715         }
716
717         ret = account_set_domain_name(account, "update-Samsung electronics");
718         if(ret != ACCOUNT_ERROR_NONE)
719         {
720                 SECURE_LOGD("(%d)-[Account] ret = %d, account=%p\n", __LINE__, ret, account);
721         }
722
723         ret = account_set_email_address(account, "update-tarun@gmail.com");
724         if(ret != ACCOUNT_ERROR_NONE)
725         {
726                 SECURE_LOGD("(%d)-[Account] ret = %d, account=%p\n", __LINE__, ret, account);
727         }
728
729         ret = account_set_package_name(account, "update-com.samsung.twiter");
730         if(ret != ACCOUNT_ERROR_NONE)
731         {
732                 SECURE_LOGD("(%d)-[Account] ret = %d, account=%p\n", __LINE__, ret, account);
733         }
734
735         ret = account_set_icon_path(account, "update-icon-path");
736         if(ret != ACCOUNT_ERROR_NONE)
737         {
738                 SECURE_LOGD("(%d)-[Account] ret = %d, account=%p\n", __LINE__, ret, account);
739         }
740
741         ret = account_set_access_token(account, "update-ACCESSTOKEN");
742         if(ret != ACCOUNT_ERROR_NONE)
743         {
744                 SECURE_LOGD("(%d)-[Account] ret = %d, account=%p\n", __LINE__, ret, account);
745         }
746
747         ret = account_set_auth_type( account, ACCOUNT_AUTH_TYPE_OAUTH );
748         if(ret != ACCOUNT_ERROR_NONE)
749         {
750                 SECURE_LOGD("(%d)-[Account] ret = %d, account=%p\n", __LINE__, ret, account);
751         }
752         ret = account_set_secret( account, ACCOUNT_SECRECY_INVISIBLE );
753         if(ret != ACCOUNT_ERROR_NONE)
754         {
755                 SECURE_LOGD("(%d)-[Account] ret = %d, account=%p\n", __LINE__, ret, account);
756         }
757         ret = account_set_source(account, "update-URUSA inc.");
758
759         int i;
760
761         for(i=0;i<USER_TXT_CNT;i++)
762         {
763                 ret = account_set_user_text(account, i, "update-user txt");
764                 if(ret != ACCOUNT_ERROR_NONE)
765                 {
766                         SECURE_LOGD("(%d)-[Account] ret = %d, account=%p, i=%d\n", __LINE__, ret, account, i);
767                 }
768         }
769
770         for(i=0;i<USER_INT_CNT;i++)
771         {
772                 ret = account_set_user_int(account, i, 999);
773                 if(ret != ACCOUNT_ERROR_NONE)
774                 {
775                         SECURE_LOGD("(%d)-[Account] ret = %d, account=%p, i=%d\n", __LINE__, ret, account, i);
776                 }
777         }
778
779         ret = account_set_capability(account, ACCOUNT_CAPABILITY_CONTACT, ACCOUNT_CAPABILITY_DISABLED);
780         ret = account_set_capability(account, ACCOUNT_CAPABILITY_CALENDAR, ACCOUNT_CAPABILITY_DISABLED);
781         ret = account_set_capability(account, ACCOUNT_CAPABILITY_PHOTO, ACCOUNT_CAPABILITY_DISABLED);
782         ret = account_set_capability(account, ACCOUNT_CAPABILITY_VIDEO, ACCOUNT_CAPABILITY_DISABLED);
783         ret = account_set_capability(account, ACCOUNT_CAPABILITY_EMAIL, ACCOUNT_CAPABILITY_DISABLED);
784         ret = account_set_capability(account, ACCOUNT_CAPABILITY_STATUS_POST, ACCOUNT_CAPABILITY_DISABLED);
785         ret = account_set_capability(account, ACCOUNT_CAPABILITY_VOIP, ACCOUNT_CAPABILITY_DISABLED);
786         ret = account_set_capability(account, ACCOUNT_CAPABILITY_SAMSUNG_APPS, ACCOUNT_CAPABILITY_DISABLED);
787         ret = account_set_capability(account, ACCOUNT_CAPABILITY_MOBILE_TRACKER, ACCOUNT_CAPABILITY_DISABLED);
788
789         ret = account_update_to_db_by_id(account, account_id);
790         if(ret != ACCOUNT_ERROR_NONE)
791         {
792            SECURE_LOGD("(%d)-[Account] ret = %d, account=%p\n", __LINE__, ret, account);
793            return;
794         }
795
796         ret = account_destroy(account);
797         if(ret != ACCOUNT_ERROR_NONE)
798         {
799                 SECURE_LOGD("(%d)-[Account] ret = %d, account=%p\n", __LINE__, ret, account);
800         }
801
802         ret = account_disconnect();
803         if(ret != ACCOUNT_ERROR_NONE)
804         {
805                 SECURE_LOGD("(%d)-[Account] ret = %d, account=%p\n", __LINE__, ret, account);
806         }
807 }
808 @endcode
809
810         <h2 class="pg">Update information of account by user name</h2>
811
812 @code
813 void update_accont_by_user_name(char *user_name, char *package_name)
814 {
815         int ret = -1;
816         account_h account;
817
818         ret = account_connect();
819         if(ret != ACCOUNT_ERROR_NONE)
820         {
821                 SECURE_LOGD("(%d)-[Account] ret = %d, account=%p\n", __LINE__, ret, account);
822         }
823
824         ret = account_create(&account);
825         if(ret != ACCOUNT_ERROR_NONE)
826         {
827                 SECURE_LOGD("(%d)-[Account] ret = %d, account=%p\n", __LINE__, ret, account);
828         }
829
830         ret = account_set_user_name(account, "update-tarun.kr");
831         if(ret != ACCOUNT_ERROR_NONE)
832         {
833                 SECURE_LOGD("(%d)-[Account] ret = %d, account=%p\n", __LINE__, ret, account);
834         }
835
836         ret = account_set_display_name(account, "update-Tarun Kumar");
837         if(ret != ACCOUNT_ERROR_NONE)
838         {
839                 SECURE_LOGD("(%d)-[Account] ret = %d, account=%p\n", __LINE__, ret, account);
840         }
841
842         ret = account_set_domain_name(account, "update-Samsung electronics");
843         if(ret != ACCOUNT_ERROR_NONE)
844         {
845                 SECURE_LOGD("(%d)-[Account] ret = %d, account=%p\n", __LINE__, ret, account);
846         }
847
848         ret = account_set_email_address(account, "update-tarun@gmail.com");
849         if(ret != ACCOUNT_ERROR_NONE)
850         {
851                 SECURE_LOGD("(%d)-[Account] ret = %d, account=%p\n", __LINE__, ret, account);
852         }
853
854         ret = account_set_package_name(account, "update-com.samsung.twiter");
855         if(ret != ACCOUNT_ERROR_NONE)
856         {
857                 SECURE_LOGD("(%d)-[Account] ret = %d, account=%p\n", __LINE__, ret, account);
858         }
859
860         ret = account_set_icon_path(account, "update-icon-path");
861         if(ret != ACCOUNT_ERROR_NONE)
862         {
863                 SECURE_LOGD("(%d)-[Account] ret = %d, account=%p\n", __LINE__, ret, account);
864         }
865
866         ret = account_set_access_token(account, "update-ACCESSTOKEN");
867         if(ret != ACCOUNT_ERROR_NONE)
868         {
869                 SECURE_LOGD("(%d)-[Account] ret = %d, account=%p\n", __LINE__, ret, account);
870         }
871
872         ret = account_set_auth_type( account, ACCOUNT_AUTH_TYPE_OAUTH );
873         if(ret != ACCOUNT_ERROR_NONE)
874         {
875                 SECURE_LOGD("(%d)-[Account] ret = %d, account=%p\n", __LINE__, ret, account);
876         }
877         ret = account_set_secret( account, ACCOUNT_SECRECY_INVISIBLE );
878         if(ret != ACCOUNT_ERROR_NONE)
879         {
880                 SECURE_LOGD("(%d)-[Account] ret = %d, account=%p\n", __LINE__, ret, account);
881         }
882
883         ret = account_set_source(account, "update-URUSA inc.");
884         if(ret != ACCOUNT_ERROR_NONE)
885         {
886                 SECURE_LOGD("(%d)-[Account] ret = %d, account=%p\n", __LINE__, ret, account);
887         }
888
889         int i;
890
891         for(i=0;i<USER_TXT_CNT;i++)
892         {
893                 ret = account_set_user_text(account, i, "update-user txt");
894                 if(ret != ACCOUNT_ERROR_NONE)
895                 {
896                         SECURE_LOGD("(%d)-[Account] ret = %d, account=%p, i=%d\n", __LINE__, ret, account, i);
897                 }
898         }
899
900         for(i=0;i<USER_INT_CNT;i++)
901         {
902                 ret = account_set_user_int(account, i, 999);
903                 if(ret != ACCOUNT_ERROR_NONE)
904                 {
905                         SECURE_LOGD("(%d)-[Account] ret = %d, account=%p, i=%d\n", __LINE__, ret, account, i);
906                 }
907         }
908
909         ret = account_set_capability(account, ACCOUNT_CAPABILITY_CONTACT, ACCOUNT_CAPABILITY_DISABLED);
910         ret = account_set_capability(account, ACCOUNT_CAPABILITY_CALENDAR, ACCOUNT_CAPABILITY_DISABLED);
911         ret = account_set_capability(account, ACCOUNT_CAPABILITY_PHOTO, ACCOUNT_CAPABILITY_DISABLED);
912         ret = account_set_capability(account, ACCOUNT_CAPABILITY_VIDEO, ACCOUNT_CAPABILITY_DISABLED);
913         ret = account_set_capability(account, ACCOUNT_CAPABILITY_EMAIL, ACCOUNT_CAPABILITY_DISABLED);
914         ret = account_set_capability(account, ACCOUNT_CAPABILITY_STATUS_POST, ACCOUNT_CAPABILITY_DISABLED);
915         ret = account_set_capability(account, ACCOUNT_CAPABILITY_VOIP, ACCOUNT_CAPABILITY_DISABLED);
916         ret = account_set_capability(account, ACCOUNT_CAPABILITY_SAMSUNG_APPS, ACCOUNT_CAPABILITY_DISABLED);
917         ret = account_set_capability(account, ACCOUNT_CAPABILITY_MOBILE_TRACKER, ACCOUNT_CAPABILITY_DISABLED);
918
919         ret = account_update_to_db_by_user_name(account, user_name, package_name);
920         if(ret != ACCOUNT_ERROR_NONE)
921         {
922                 SECURE_LOGD("(%d)-[Account] ret = %d, account=%p\n", __LINE__, ret, account);
923                 return;
924         }
925
926         ret = account_destroy(account);
927         if(ret != ACCOUNT_ERROR_NONE)
928         {
929                 SECURE_LOGD("(%d)-[Account] ret = %d, account=%p\n", __LINE__, ret, account);
930         }
931
932         ret = account_disconnect();
933         if(ret != ACCOUNT_ERROR_NONE)
934         {
935                 SECURE_LOGD("(%d)-[Account] ret = %d, account=%p\n", __LINE__, ret, account);
936         }
937 }
938 @endcode
939
940         <h2 class="pg">Delete account by id </h2>
941
942 @code
943 void delete_account_by_id(int account_id)
944 {
945         int ret = -1;
946
947         ret = account_connect();
948         if(ret != ACCOUNT_ERROR_NONE)
949         {
950                 SECURE_LOGD("(%d)-[Account] ret = %d, \n", __LINE__, ret);
951         }
952
953         ret = account_delete(account_id);
954         if(ret != ACCOUNT_ERROR_NONE)
955         {
956                 SECURE_LOGD("(%d)-[Account] ret = %d, \n", __LINE__, ret);
957         }
958
959         ret = account_disconnect();
960         if(ret != ACCOUNT_ERROR_NONE)
961         {
962                 SECURE_LOGD("(%d)-[Account] ret = %d, \n", __LINE__, ret);
963         }
964         return;
965 }
966 @endcode
967
968         <h2 class="pg">Update sync status by id </h2>
969
970 @code
971 void update_sync_status_by_id(int account_id, const account_sync_state_e sync_status)
972 {
973         int ret = -1;
974
975         ret = account_connect();
976         if(ret != ACCOUNT_ERROR_NONE)
977         {
978                 SECURE_LOGD("(%d)-[Account] ret = %d, \n", __LINE__, ret);
979         }
980
981         ret = account_update_sync_status_by_id(account_id, sync_status);
982         if(ret != ACCOUNT_ERROR_NONE)
983         {
984                 SECURE_LOGD("(%d)-[Account] ret = %d, \n", __LINE__, ret);
985         }
986
987         ret = account_disconnect();
988         if(ret != ACCOUNT_ERROR_NONE)
989         {
990                 SECURE_LOGD("(%d)-[Account] ret = %d, \n", __LINE__, ret);
991         }
992         return;
993 }
994 @endcode
995
996         <h2 class="pg">Delete account by user name </h2>
997
998 @code
999 void delete_account_by_user_name(char *user_name, char *package_name)
1000 {
1001         int ret = -1;
1002         ret = account_connect();
1003         if(ret != ACCOUNT_ERROR_NONE)
1004         {
1005                 SECURE_LOGD("(%d)-[Account] ret = %d, \n", __LINE__, ret);
1006         }
1007
1008         ret = account_delete_from_db_by_user_name(user_name, package_name);
1009         if(ret != ACCOUNT_ERROR_NONE)
1010         {
1011                 SECURE_LOGD("(%d)-[Account] ret = %d \n", __LINE__, ret);
1012         }
1013
1014         ret = account_disconnect();
1015         if(ret != ACCOUNT_ERROR_NONE)
1016         {
1017                 SECURE_LOGD("(%d)-[Account] ret = %d, \n", __LINE__, ret);
1018         }
1019         return;
1020 }
1021 @endcode
1022
1023         <h2 class="pg">Delete account by package name </h2>
1024
1025 @code
1026 void delete_account_by_package_name(char *package_name)
1027 {
1028         int ret = -1;
1029         ret = account_connect();
1030         if(ret != ACCOUNT_ERROR_NONE)
1031         {
1032                 SECURE_LOGD("(%d)-[Account] ret = %d, \n", __LINE__, ret);
1033         }
1034
1035         ret = account_delete_from_db_by_package_name(package_name);
1036         if(ret != ACCOUNT_ERROR_NONE)
1037         {
1038                 SECURE_LOGD("(%d)-[Account] ret = %d \n", __LINE__, ret);
1039         }
1040
1041         ret = account_disconnect();
1042         if(ret != ACCOUNT_ERROR_NONE)
1043         {
1044                 SECURE_LOGD("(%d)-[Account] ret = %d, \n", __LINE__, ret);
1045         }
1046         return;
1047 }
1048 @endcode
1049
1050         <h2 class="pg">Get account insert dbus notification </h2>
1051
1052 @code
1053 void notify_account_insert()
1054 {
1055         DBusMessage* msg;
1056     DBusConnection* conn;
1057     DBusError err;
1058
1059     SECURE_LOGD("Listening for signals\n");
1060
1061     dbus_error_init(&err);
1062
1063     conn = dbus_bus_get(DBUS_BUS_SYSTEM, &err);
1064     if (dbus_error_is_set(&err)) {
1065                 dbus_error_free(&err);
1066     }
1067     if (NULL == conn) {
1068                 exit(1);
1069     }
1070
1071     dbus_bus_add_match(conn, "type='signal',interface='account.signal.Type'", &err);
1072     dbus_connection_flush(conn);
1073     if (dbus_error_is_set(&err)) {
1074                 exit(1);
1075     }
1076     SECURE_LOGD("Match rule sent\n");
1077
1078     while (true) {
1079                 dbus_connection_read_write(conn, 0);
1080                 msg = dbus_connection_pop_message(conn);
1081
1082                 if (NULL == msg) {
1083                         sleep(1);
1084                         continue;
1085                 }
1086
1087                 if (dbus_message_is_signal(msg, ACCOUNT_DBUS_SIGNAL_INTERFACE, ACCOUNT_DBUS_NOTI_NAME_INSERT)) {
1088                         SECURE_LOGD("Got Signal with name insert\n");
1089                 }
1090
1091                 dbus_message_unref(msg);
1092     }
1093     dbus_connection_close(conn);
1094 }
1095 @endcode
1096
1097         <h2 class="pg">Get account update dbus notification </h2>
1098
1099 @code
1100 void notify_account_update()
1101 {
1102     DBusMessage* msg;
1103     DBusConnection* conn;
1104     DBusError err;
1105
1106     SECURE_LOGD("Listening for signals\n");
1107
1108     dbus_error_init(&err);
1109
1110     conn = dbus_bus_get(DBUS_BUS_SYSTEM, &err);
1111     if  (dbus_error_is_set(&err)) {
1112                 dbus_error_free(&err);
1113     }
1114     if (NULL == conn) {
1115                 exit(1);
1116     }
1117
1118     dbus_bus_add_match(conn, "type='signal',interface='account.signal.Type'", &err);
1119     dbus_connection_flush(conn);
1120     if (dbus_error_is_set(&err)) {
1121                 exit(1);
1122     }
1123     SECURE_LOGD("Match rule sent\n");
1124
1125         while (true) {
1126                 dbus_connection_read_write(conn, 0);
1127                 msg = dbus_connection_pop_message(conn);
1128
1129                 if (NULL == msg) {
1130                         sleep(1);
1131                         continue;
1132                 }
1133
1134                 if (dbus_message_is_signal(msg, ACCOUNT_DBUS_SIGNAL_INTERFACE, ACCOUNT_DBUS_NOTI_NAME_UPDATE)) {
1135                         SECURE_LOGD("Got Signal with name update\n");
1136                 }
1137
1138                 dbus_message_unref(msg);
1139     }
1140     dbus_connection_close(conn);
1141 }
1142 @endcode
1143
1144         <h2 class="pg">Get account delete dbus notification </h2>
1145
1146 @code
1147 void notify_account_delete()
1148 {
1149     DBusMessage* msg;
1150     DBusConnection* conn;
1151     DBusError err;
1152
1153     SECURE_LOGD("Listening for signals\n");
1154
1155     dbus_error_init(&err);
1156
1157     conn = dbus_bus_get(DBUS_BUS_SYSTEM, &err);
1158     if (dbus_error_is_set(&err)) {
1159                 dbus_error_free(&err);
1160     }
1161     if (NULL == conn) {
1162                 exit(1);
1163     }
1164
1165     dbus_bus_add_match(conn, "type='signal',interface='account.signal.Type'", &err);
1166     dbus_connection_flush(conn);
1167     if  (dbus_error_is_set(&err)) {
1168                 exit(1);
1169     }
1170     SECURE_LOGD("Match rule sent\n");
1171
1172     while (true) {
1173                 dbus_connection_read_write(conn, 0);
1174                 msg = dbus_connection_pop_message(conn);
1175
1176                 if (NULL == msg) {
1177                         sleep(1);
1178                         continue;
1179                 }
1180
1181                 if (dbus_message_is_signal(msg, ACCOUNT_DBUS_SIGNAL_INTERFACE, ACCOUNT_DBUS_NOTI_NAME_DELETE)) {
1182                 SECURE_LOGD("Got Signal with name delete\n");
1183                 }
1184
1185                 dbus_message_unref(msg);
1186     }
1187     dbus_connection_close(conn);
1188 }
1189 @endcode
1190
1191         <h2 class="pg">Get capability by acccount id</h2>
1192
1193 @code
1194 bool _capability_get_callback(const char* capability_type, account_capability_state_e capability_value, void* user_data)
1195 {
1196         char* test_type = capability_type;
1197         int test_value = capability_value;
1198
1199         SECURE_LOGD("_capability_get_callback test_type = : %s\n", test_type);
1200         SECURE_LOGD("_capability_get_callback test_value = : %d\n", test_value);
1201         return TRUE;
1202 }
1203
1204 void capability_by_account_id(int account_id)
1205 {
1206         int ret = -1;
1207         ret = account_connect();
1208         if(ret != ACCOUNT_ERROR_NONE)
1209         {
1210                 SECURE_LOGD("(%d)-[Account] ret = %d, \n", __LINE__, ret);
1211         }
1212
1213         ret = account_query_capability_by_account_id(_capability_get_callback, account_id, NULL);
1214         if(ret != ACCOUNT_ERROR_NONE)
1215         {
1216                 SECURE_LOGD("(%d)-[Account] ret = %d \n", __LINE__, ret);
1217         }
1218
1219         ret = account_disconnect();
1220         if(ret != ACCOUNT_ERROR_NONE)
1221         {
1222                 SECURE_LOGD("(%d)-[Account] ret = %d, \n", __LINE__, ret);
1223         }
1224         return;
1225 }
1226 @endcode
1227  * @}
1228  */
1229