Initial commit
[platform/core/appfw/vconf-buxton.git] / src / vconf-buxton.h
1 /*
2  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
3  * Copyright (C) 2014 Intel Corporation
4  *
5  * Author: José Bollo <jose.bollo@open.eurogiciel.org>
6  * Author: Hakjoo Ko <hakjoo.ko@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 #ifndef __VCONF_BUXTON_H__
23 #define __VCONF_BUXTON_H__
24
25 #define VCONF_BUXTON  "1.0"
26
27 /**
28  * @addtogroup APPLICATION_FRAMEWORK
29  * @{
30  *
31  * @defgroup    VCONF VConf
32  * @author      Sangjung Woo (sangjung.woo@samsung.com)
33  * @version     0.2
34  * @brief       A library for reading/writing Configuration Data
35  *
36  * @section Header To use Them:
37  * @code
38  * #include <vconf.h>
39  * @endcode
40  *
41  * @section Properties
42  * - Convenient API
43  * - Guarantee Transaction(db backend only)
44  * - Apply Key-List concept
45  * - Changeable Backend
46  * - Simple Notification based on inotify
47  *
48  * @section Backend key has below backend.
49  * - db => use libsqlfs ex) db/a/b
50  * \n Lowest speed, highest robustness, correctly sync
51  * - memory => use tmpfs ex) memory/a/b
52  * \n Highest speed, volitile
53  * - file => use basic file system(not support atomicity) ex) file/a/b
54  * \n Higher speed, lower robustness(Not guarantee atomicity)
55  *
56  * @section example Simple Example
57  * @code
58  #include <stdio.h>
59  #include <vconf.h>
60
61  const char *key1_name="db/test/key1";
62
63  int main(int argc, char **argv)
64  {
65    int key1_value;
66
67    if(vconf_set_int(key1_name,1))
68       fprintf(stderr, "vconf_set_int FAIL\n");
69    else
70       printf("vconf_set_int OK\n");
71
72    if(vconf_get_int(key1_name, &key1_value))
73       fprintf(stderr, "vconf_get_int FAIL\n");
74    else
75       printf("vconf_get_int OK(key1 value is %d)\n", key1_value);
76
77    return 0;
78  }
79  * @endcode
80  *
81  */
82
83 /**
84  * @addtogroup VCONF
85  * @{
86  */
87
88 #include "vconf-buxton-keys.h"
89
90 #ifdef __cplusplus
91 extern          "C" {
92 #endif
93
94 /**
95  * VCONF_GET_KEY, VCONF_GET_ALL, VCONF_GET_DIR
96  * \n Use for vconf_get()
97  * @see vconf_get()
98  */
99     enum get_option_t {
100         VCONF_GET_KEY = 0,
101             /**< get only keys */
102         VCONF_GET_ALL,
103             /**< get keys and directorys */
104         VCONF_GET_DIR,
105            /**< get only directorys */
106         VCONF_REFRESH_ONLY,
107             /**< get only keys */
108         VCONF_GET_KEY_REC,
109             /**< get only keys recursively */
110         VCONF_GET_ALL_REC,
111             /**< get keys and directorys recursively */
112         VCONF_GET_DIR_REC
113            /**< get only directorys recursively */
114     };
115
116     typedef enum get_option_t get_option_t;
117
118     enum vconf_t {
119         VCONF_TYPE_NONE = 0,
120                    /**< Vconf none type for Error detection */
121         VCONF_TYPE_STRING = 40,
122                    /**< Vconf string type */
123         VCONF_TYPE_INT = 41,
124                    /**< Vconf integer type */
125         VCONF_TYPE_DOUBLE = 42,
126                    /**< Vconf double type */
127         VCONF_TYPE_BOOL = 43,
128                    /**< Vconf boolean type */
129         VCONF_TYPE_DIR
130                    /**< Vconf directory type */
131     };
132
133
134 /**
135  * keynode_t is an opaque type, it must be
136  * used via accessor functions.
137  * @see vconf_keynode_get_name(), vconf_keynode_get_type()
138  * @see vconf_keynode_get_bool(), vconf_keynode_get_dbl(), vconf_keynode_get_int(), vconf_keynode_get_str()
139  */
140     typedef struct _keynode_t keynode_t;
141
142 /**
143  * keylist_t is an opaque type, it must be
144  * used via accessor functions.
145  * @see vconf_keylist_new(), vconf_keylist_free()
146  * @see vconf_keylist_add_bool(),vconf_keylist_add_str(), vconf_keylist_add_dbl(), vconf_keylist_add_int()
147  * @see vconf_keylist_del(), vconf_keylist_add_null()
148  * @see vconf_keylist_lookup(), vconf_keylist_nextnode(), vconf_keylist_rewind()
149  */
150     typedef struct _keylist_t keylist_t;
151
152
153 /**
154  * This is the signature of a callback function added with vconf_notify_key_changed().
155  * \n The callback function is invoked when the key is set.
156  * @see keynode_t
157  */
158     typedef void    (*vconf_callback_fn) (keynode_t * node,
159                                           void *user_data);
160
161 /************************************************
162  * keynode handling APIs                        *
163  ************************************************/
164
165 /**
166  * This function gets Key name of the keynode.
167  * @param[in] keynode The Key
168  * @return Key Name of the keynode
169  * @pre Nome
170  * @post None
171  * @remarks None
172  * @see vconf_notify_key_changed(), vconf_keynode_get_bool, vconf_keynode_get_type, vconf_keynode_get_str, vconf_keynode_get_int, vconf_keynode_get_dbl, keynode_t, vconf_t
173  */
174     const char     *vconf_keynode_get_name(keynode_t * keynode);
175
176 /**
177  * This function gets value type of the keynode.
178  * @param[in] keynode The Key
179  * @return Type of the keynode
180  * @pre Nome
181  * @post None
182  * @remarks None
183  * @see vconf_notify_key_changed(), vconf_keynode_get_name, vconf_keynode_get_bool, vconf_keynode_get_str, vconf_keynode_get_int, vconf_keynode_get_dbl, keynode_t, vconf_t
184  */
185     int             vconf_keynode_get_type(keynode_t * keynode);
186
187 /**
188  * This function gets Integer value of the keynode.
189  * @param[in] keynode The Key
190  * @return Integer value, or 0 if no value is obtained
191  ** @pre Nome
192  * @post None
193  * @remarks None
194  * @see vconf_notify_key_changed(), vconf_keynode_get_name, vconf_keynode_get_bool, vconf_keynode_get_type, vconf_keynode_get_str, vconf_keynode_get_dbl, keynode_t, vconf_t
195  */
196     int             vconf_keynode_get_int(keynode_t * keynode);
197
198 /**
199  * This function gets Double value of the keynode.
200  * @param[in] keynode The Key
201  * @return Double value, or 0.0 if no value is obtained
202  * @pre Nome
203  * @post None
204  * @remarks None
205  * @see vconf_notify_key_changed(), vconf_keynode_get_name, vconf_keynode_get_bool, vconf_keynode_get_type, vconf_keynode_get_str, vconf_keynode_get_int, keynode_t, vconf_t
206  */
207     double          vconf_keynode_get_dbl(keynode_t * keynode);
208
209 /**
210  * This function gets Boolean value of the keynode.
211  * @param[in] keynode The Key
212  * @return Boolean value, -1 on error (Integer value 1 is 'True', and 0 is 'False')
213  * @pre Nome
214  * @post None
215  * @remarks None
216  * @see vconf_notify_key_changed(), vconf_keynode_get_name, vconf_keynode_get_type, vconf_keynode_get_str, vconf_keynode_get_int, vconf_keynode_get_dbl, keynode_t, vconf_t
217  */
218     int             vconf_keynode_get_bool(keynode_t * keynode);
219
220 /**
221  * This function gets String value of the keynode.
222  * @param[in] keynode The Key
223  * @return String value, or NULL if no value is obtained
224  * @pre Nome
225  * @post None
226  * @remarks None
227  * @see vconf_notify_key_changed(), vconf_keynode_get_name, vconf_keynode_get_bool, vconf_keynode_get_type, vconf_keynode_get_int, vconf_keynode_get_dbl, keynode_t, vconf_t
228  */
229     char           *vconf_keynode_get_str(keynode_t * keynode);
230
231
232 /************************************************
233  * keylist handling APIs
234  ************************************************/
235
236 /**
237  * Set the default group of key lists created using vconf_keylist_new.
238  * @param[in] groupname The name of the default group to bind to
239  * @return 0 in case of success or -1 in case of error of allocation
240  * @see vconf_keylist_new()
241  */
242     int             vconf_set_default_group(const char *groupname);
243
244 /**
245  * Allocate, initialize and return a new Keylist object bound to the default group.
246  * Return value keylist_t* pointer must be relised by calling vconf_keylist_free()
247  * @return The pointer of New keylist, NULL on error
248  * @pre None
249  * @post None
250  * @see vconf_set(), vconf_get(), vconf_keylist_create(), vconf_keylist_free(), vconf_set_default_group()
251  */
252     keylist_t      *vconf_keylist_new(void);
253
254 /**
255  * A destructor for Keylist objects.<br>
256  * After calling vconf_keylist_new(), developer have to call this function for release internal memory.
257  * @param[in] keylist Key List
258  * @return 0 on success, -1 on error
259  * @pre None
260  * @post None
261  * @remarks None
262  * @see vconf_set(), vconf_get(), vconf_keylist_new()
263  */
264     int             vconf_keylist_free(keylist_t * keylist);
265
266 /**
267  * This function moves the current Keynode position to the first items.
268  * @param[in] keylist Key List
269  * @return 0 on success, -1 on error
270  * @pre None
271  * @post None
272  * @remarks None
273  * @see vconf_set(), vconf_get(), vconf_keylist_nextnode(), vconf_keylist_rewind(), vconf_keylist_nextnode()
274  * @par example
275  * @code
276     int r =0;
277     keylist_t* pKeyList = NULL;
278     pKeyList = vconf_keylist_new();
279
280     r = vconf_get(pKeyList, KEY_PARENT, VCONF_GET_KEY);
281     if (r) {
282         tet_infoline("vconf_get() failed in positive test case");
283         tet_result(TET_FAIL);
284         return;
285     }
286
287     vconf_keylist_nextnode(pKeyList);
288     vconf_keylist_nextnode(pKeyList);
289
290     // Move first position from KeyList
291     r = vconf_keylist_rewind(pKeyList);
292     if (r<0) {
293         tet_infoline("vconf_keylist_rewind() failed in positive test case");
294         tet_result(TET_FAIL);
295         return;
296     }
297
298     while(vconf_keylist_nextnode(pKeyList)) ;
299  * @endcode
300  */
301     int             vconf_keylist_rewind(keylist_t * keylist);
302
303 /**
304  * This function looks for a Keynode contained in keylist that matches keyname.
305  * @param[in] keylist Key List
306  * @param[in] keyname Key to find
307  * @param[out] return_node pointer of keynode to set
308  * @return Type of the found key that is vconf_t enumeration value
309  * @pre None
310  * @post None
311  * @remarks None
312  * @see vconf_set(), vconf_get(), keynode_t, vconf_t
313  * @par example
314  * @code
315 #include <stdio.h>
316 #include <vconf.h>
317
318 int main()
319 {
320         int r = 0;
321         int nResult = 0;
322         keylist_t* pKeyList = NULL;
323         keynode_t *pKeyNode;
324
325         pKeyList = vconf_keylist_new();
326         r = vconf_get(pKeyList, KEY_PARENT, VCONF_GET_KEY);
327         if (r<0) {
328                 printf("vconf_get() failed in positive test case");
329                 return -1;
330         }
331
332         r = vconf_keylist_lookup(pKeyList, KEY_02, &pKeyNode);
333         if (r<0) {
334                 printf("vconf_get() failed in positive test case");
335                 return -1;
336         }
337
338         nResult = vconf_keynode_get_int(pKeyNode);
339         if(nResult !=KEY_02_INT_VALUE)
340         {
341                 printf("vconf_get() failed in positive test case");
342                 return -1;
343
344         }
345
346         vconf_keylist_free(pKeyList);
347         return 0;
348 }
349  * @endcode
350  */
351     int             vconf_keylist_lookup(keylist_t * keylist,
352                                          const char *keyname,
353                                          keynode_t ** return_node);
354
355 /**
356  * This function returns the next Key in a Keylist.
357  * Next key is known by the keylist internal cursor.
358  * @param[in] keylist Key List
359  * @return The next Keynode, NULL on error
360  * @pre None
361  * @post None
362  * @remarks None
363  * @see vconf_set(), vconf_get(), vconf_keylist_rewind(), vconf_keylist_nextnode(), keynode_t
364  */
365     keynode_t      *vconf_keylist_nextnode(keylist_t * keylist);
366
367 /**
368  * This function sorts the list in alphabetical order (with LANG=C)
369  * @param[in] keylist Key List
370  * @return 0 if done, -1 on error
371  * @pre None
372  * @post None
373  * @remarks None
374  */
375     int             vconf_keylist_sort(keylist_t * keylist);
376
377 /**
378  * This function appends a new Keynode included integer value to the keylist.
379  * \n If same keyname exist, the keynode will change.
380  * @param[in] keylist Key List
381  * @param[in] keyname Key
382  * @param[in] value The integer value
383  * @return Number of keynode included in the keylist, -1 on error
384  * @see vconf_set(), vconf_get()
385  */
386     int             vconf_keylist_add_int(keylist_t * keylist,
387                                           const char *keyname,
388                                           const int value);
389
390 /**
391  * This function appends a new Keynode included boolean value to the keylist.
392  * \n If same keyname exist, the keynode will change.
393  * @param[in] keylist Key List
394  * @param[in] keyname Key
395  * @param[in] value The boolean value
396  * @return Number of keynode included in the keylist, -1 on error
397  * @pre None
398  * @post None
399  * @remarks None
400  * @see vconf_set(), vconf_get(), vconf_keylist_add_int(), vconf_keylist_add_str(), vconf_keylist_add_dbl(), vconf_keylist_add_bool(), vconf_keylist_del(), vconf_keylist_add_null()
401  */
402     int             vconf_keylist_add_bool(keylist_t * keylist,
403                                            const char *keyname,
404                                            const int value);
405
406 /**
407  * This function appends a new Keynode included double value to the keylist.
408  * \n If same keyname exist, the keynode will change.
409  * @param[in] keylist Key List
410  * @param[in] keyname Key
411  * @param[in] value The double value
412  * @return Number of keynode included in the keylist, -1 on error
413  * @pre None
414  * @post None
415  * @remarks None
416  * @see vconf_set(), vconf_get(), vconf_keylist_add_int(), vconf_keylist_add_str(), vconf_keylist_add_dbl(), vconf_keylist_add_bool(), vconf_keylist_del(), vconf_keylist_add_null()
417  */
418     int             vconf_keylist_add_dbl(keylist_t * keylist,
419                                           const char *keyname,
420                                           const double value);
421
422 /**
423  * This function appends a new Keynode included string value to the keylist.
424  * \n If same keyname exist, the keynode will change.
425  * @param[in] keylist Key List
426  * @param[in] keyname Key
427  * @param[in] value The pointer of string value
428  * @return Number of keynode included in the keylist, -1 on error
429  * @pre None
430  * @post None
431  * @remarks None
432  * @see vconf_set(), vconf_get(), vconf_keylist_add_int(), vconf_keylist_add_str(), vconf_keylist_add_dbl(), vconf_keylist_add_bool(), vconf_keylist_del(), vconf_keylist_add_null()
433  */
434     int             vconf_keylist_add_str(keylist_t * keylist,
435                                           const char *keyname,
436                                           const char *value);
437
438 /**
439  * This function Appends a new Keynode to the keylist without value.
440  * \n Use for vconf_get()
441  * @param[in] keylist Key List
442  * @param[in] keyname Key
443  * @return Number of keynode included in the keylist, -1 on error
444  * @pre None
445  * @post None
446  * @remarks None
447  * @see vconf_set(), vconf_get(), vconf_keylist_add_int(), vconf_keylist_add_str(), vconf_keylist_add_dbl(), vconf_keylist_add_bool(), vconf_keylist_del(), vconf_keylist_add_null()
448  */
449     int             vconf_keylist_add_null(keylist_t * keylist,
450                                            const char *keyname);
451
452 /**
453  * This function removes the keynode that matches keyname.
454  * @param[in] keylist the keylist included the keyname
455  * @param[in] keyname key
456  * @return 0 on success, -1(Invalid parameter), -2(Not exist keyname in keylist) on error
457  * @pre None
458  * @post None
459  * @remarks None
460  * @see vconf_set(), vconf_get(), vconf_keylist_add_int(), vconf_keylist_add_str(), vconf_keylist_add_dbl(), vconf_keylist_add_bool(), vconf_keylist_del(), vconf_keylist_add_null()
461  */
462     int             vconf_keylist_del(keylist_t * keylist,
463                                       const char *keyname);
464
465 /************************************************
466  * setting APIs                                 *
467  ************************************************/
468
469 /**
470  * This function sets the keys included in keylist.
471  * \n If you use db backend, keylist is handled as one transaction.
472  * @param[in] keylist the keylist which should contain changed keys
473  * @return 0 on success, -1 on error
474  * @pre None
475  * @post None
476  * @remarks None
477  * @see vconf_set(), vconf_get(), vconf_keylist_add_int(), vconf_keylist_add_str(), vconf_keylist_add_dbl(), vconf_keylist_add_bool(), vconf_keylist_del(), vconf_keylist_add_null()
478  * @par example
479  * @code
480 #include <stdio.h>
481 #include <vconf.h>
482
483 int main()
484 {
485    keylist_t *kl=NULL;
486    const char *keyname_list[3]={"db/test/key1", "db/test/key2", "db/test/key3"};
487
488    // Transaction Test(all or nothing is written)
489    kl = vconf_keylist_new();
490
491    vconf_keylist_add_int(kl, keyname_list[0], 1);
492    vconf_keylist_add_str(kl, keyname_list[1], "transaction Test");
493    vconf_keylist_add_dbl(kl, keyname_list[2], 0.3);
494    if(vconf_set(kl))
495       fprintf(stderr, "nothing is written\n");
496    else
497       printf("everything is written\n");
498
499    vconf_keylist_free(kl);
500
501    // You can set items which have different backend.
502    kl = vconf_keylist_new();
503
504    vconf_keylist_add_int(kl, "memory/a/xxx1", 4);
505    vconf_keylist_add_str(kl, "file/a/xxx2", "test 3");
506    vconf_keylist_add_dbl(kl, "db/a/xxx3", 0.3);
507    vconf_set(kl)
508
509    vconf_keylist_free(kl);
510    return 0;
511 }
512  * @endcode
513  */
514     int             vconf_set(keylist_t * keylist);
515
516 /**
517  * This function sets the integer value of given key.
518  * @param[in]   keyname key
519  * @param[in]   intval integer value to set (0 is also allowed as a value.)
520  * @return 0 on success, -1 on error
521  * @pre None
522  * @post None
523  * @remarks None
524  * @see vconf_set_bool(), vconf_set_dbl(), vconf_set_str()
525  */
526     int             vconf_set_int(const char *keyname, const int intval);
527
528 /**
529  * This function sets the boolean value of given key.
530  * @param[in]   keyname key
531  * @param[in]   boolval boolean value(1 or 0) to set.  (Integer value 1 is 'True', and 0 is 'False')
532  * @return 0 on success, -1 on error
533  * @pre None
534  * @post None
535  * @remarks None
536  * @see vconf_set_int(), vconf_set_dbl(), vconf_set_str()
537  * @par example
538  * @code
539 #include <stdio.h>
540 #include <vconf.h>
541
542  const char *key1_name="memory/test/key1";
543
544  int main(int argc, char **argv)
545  {
546    int key1_value;
547
548    if(vconf_set_bool(key1_name, 1))
549       fprintf(stderr, "vconf_set_bool FAIL\n");
550    else
551       printf("vconf_set_bool OK\n");
552
553    if(vconf_get_bool(key1_name, &key1_value))
554       fprintf(stderr, "vconf_get_bool FAIL\n");
555    else
556       printf("vconf_get_bool OK(key1 value is %d)\n", key1_value);
557
558    return 0;
559  }
560  * @endcode
561  */
562     int             vconf_set_bool(const char *keyname, const int boolval);
563
564 /**
565  * This function sets the double value of given key.
566  * @param[in]   keyname key
567  * @param[in]   dblval double value to set (0.0 is also allowed as a value.)
568  * @return 0 on success, -1 on error
569  * @pre None
570  * @post None
571  * @remarks None
572  * @see vconf_set_int(), vconf_set_bool(), vconf_set_str()
573  */
574     int             vconf_set_dbl(const char *keyname,
575                                   const double dblval);
576
577 /**
578  * This function sets the string value of given key.
579  * @param[in]   keyname key
580  * @param[in]   strval string value to set
581  * @return 0 on success, -1 on error
582  * @pre None
583  * @post None
584  * @remarks None
585  * @see vconf_set_bool(), vconf_set_dbl(), vconf_set_int()
586  */
587     int             vconf_set_str(const char *keyname, const char *strval);
588
589 /************************************************
590  * setting label APIs                           *
591  ************************************************/
592
593 /**
594  * This function set the smack label of its keys
595  * @param[in] keylist Key List
596  * @param[in] label The label to set
597  * @return 0 if done, -1 on error
598  * @pre None
599  * @post None
600  * @remarks None
601  */
602     int             vconf_set_labels(keylist_t * keylist, const char *label);
603
604 /**
605  * This function set the smack label of its keys
606  * @param[in] keylist Key List
607  * @param[in] label The label to set
608  * @return 0 if done, -1 on error
609  * @pre None
610  * @post None
611  * @remarks None
612  */
613     int             vconf_set_label(const char *keyname, const char *label);
614
615 /************************************************
616  * getting APIs                                 *
617  ************************************************/
618
619 /**
620  * This function reads the database to refresh the values of
621  * the keys in 'keylist'.
622  * @param[in]   keylist the keylist whose values have to be refreshed
623  * @return 0 on success, -1 on error
624  * @see vconf_keylist_lookup, vconf_keylist_nextnode, vconf_keylist_rewind
625  */
626     int             vconf_refresh(keylist_t * keylist);
627
628 /**
629  * This function retrieves the keys or subdirectory in in_parentDIR.<br>
630  * @param[in]   keylist keylist created by vconf_keylist_new(), MUST be empty
631  * @param[in]   in_parentDIR parent DIRECTORY of needed keys
632  * @param[in]   option VCONF_GET_KEY|VCONF_GET_DIR|VCONF_GET_ALL|VCONF_GET_KEY_REC|VCONF_GET_DIR_REC|VCONF_GET_ALL_REC
633  * @return 0 on success, -1 on error
634  * @pre None
635  * @post None
636  * @remkar None
637  * @par example
638  * @code
639 #include <stdio.h>
640 #include <vconf.h>
641
642 int main()
643 {
644    keylist_t *kl=NULL;
645    keynode_t *temp_node;
646    const char *vconfkeys1="db/test/key1";
647    const char *parent_dir="db/test";
648
649    kl = vconf_keylist_new();
650    if(vconf_scan(kl, parent_dir, VCONF_GET_KEY))
651       fprintf(stderr, "vconf_get FAIL(%s)", vconfkeys1);
652    else
653       printf("vconf_get OK(%s)", vconfkeys1);
654
655    while((temp_node = vconf_keylist_nextnode(kl))) {
656       switch(vconf_keynode_get_type(temp_node)) {
657         case VCONF_TYPE_INT:
658                 printf("key = %s, value = %d\n",
659                         vconf_keynode_get_name(temp_node), vconf_keynode_get_int(temp_node));
660                 break;
661         case VCONF_TYPE_BOOL:
662                 printf("key = %s, value = %d\n",
663                         vconf_keynode_get_name(temp_node), vconf_keynode_get_bool(temp_node));
664                 break;
665         case VCONF_TYPE_DOUBLE:
666                 printf("key = %s, value = %f\n",
667                         vconf_keynode_get_name(temp_node), vconf_keynode_get_dbl(temp_node));
668                 break;
669         case VCONF_TYPE_STRING:
670                 printf("key = %s, value = %s\n",
671                         vconf_keynode_get_name(temp_node), vconf_keynode_get_str(temp_node));
672                 break;
673         default:
674                 printf("Unknown Type\n");
675       }
676    }
677    vconf_keylist_free(kl);
678 }
679  * @endcode
680  */
681     int             vconf_scan(keylist_t * keylist,
682                                const char *in_parentDIR,
683                                get_option_t option);
684
685 /**
686  * This function get the keys or subdirectory in in_parentDIR.<br>
687  * If keylist has any key information, vconf only retrieves the keys.<br>
688  * @param[in]   keylist keylist created by vconf_keylist_new()
689  * @param[in]   in_parentDIR parent DIRECTORY of needed keys
690  * @param[in]   option VCONF_GET_KEY|VCONF_GET_DIR|VCONF_GET_ALL|VCONF_REFRESH_ONLY|VCONF_GET_KEY_REC|VCONF_GET_DIR_REC|VCONF_GET_ALL_REC
691  * @return 0 on success, -1 on error
692  * @pre None
693  * @post None
694  * @remkar None
695  * @par example
696  * @code
697 #include <stdio.h>
698 #include <vconf.h>
699
700 int main()
701 {
702    keylist_t *kl=NULL;
703    keynode_t *temp_node;
704    const char *vconfkeys1="db/test/key1";
705    const char *parent_dir="db/test";
706
707    kl = vconf_keylist_new();
708    if(vconf_get(kl, parent_dir, VCONF_GET_KEY))
709       fprintf(stderr, "vconf_get FAIL(%s)", vconfkeys1);
710    else
711       printf("vconf_get OK(%s)", vconfkeys1);
712
713    while((temp_node = vconf_keylist_nextnode(kl))) {
714       switch(vconf_keynode_get_type(temp_node)) {
715         case VCONF_TYPE_INT:
716                 printf("key = %s, value = %d\n",
717                         vconf_keynode_get_name(temp_node), vconf_keynode_get_int(temp_node));
718                 break;
719         case VCONF_TYPE_BOOL:
720                 printf("key = %s, value = %d\n",
721                         vconf_keynode_get_name(temp_node), vconf_keynode_get_bool(temp_node));
722                 break;
723         case VCONF_TYPE_DOUBLE:
724                 printf("key = %s, value = %f\n",
725                         vconf_keynode_get_name(temp_node), vconf_keynode_get_dbl(temp_node));
726                 break;
727         case VCONF_TYPE_STRING:
728                 printf("key = %s, value = %s\n",
729                         vconf_keynode_get_name(temp_node), vconf_keynode_get_str(temp_node));
730                 break;
731         default:
732                 printf("Unknown Type\n");
733       }
734    }
735    vconf_keylist_free(kl);
736 }
737  * @endcode
738  */
739     int             vconf_get(keylist_t * keylist,
740                               const char *in_parentDIR,
741                               get_option_t option);
742
743 /**
744  * This function get the integer value of given key.
745  *
746  * @param[in]   keyname key
747  * @param[out]  intval output buffer
748  * @return 0 on success, -1 on error
749  * @pre None
750  * @post None
751  * @remkar None
752  * @see vconf_get_bool, vconf_get_dbl, vconf_get_str
753  * @par example
754  * @code
755 #include <stdio.h>
756 #include <vconf.h>
757
758 const char *key1_name="db/test/key1";
759
760 int main(int argc, char **argv)
761 {
762    int key1_value;
763
764    if(vconf_set_int(key1_name,1))
765       fprintf(stderr, "vconf_set_int FAIL\n");
766    else
767       printf("vconf_set_int OK\n");
768
769    if(vconf_get_int(key1_name, &key1_value))
770       fprintf(stderr, "vconf_get_int FAIL\n");
771    else
772       printf("vconf_get_int OK(key1 value is %d)\n", key1_value);
773
774    return 0;
775 }
776  * @endcode
777  */
778     int             vconf_get_int(const char *keyname, int *intval);
779
780 /**
781  * This function get the boolean value(1 or 0) of given key.
782  * @param[in]   keyname key
783  * @param[out]  boolval output buffer
784  * @return 0 on success, -1 on error
785  * @pre None
786  * @post None
787  * @remarks None
788  * @see vconf_get_int(), vconf_get_dbl(), vconf_get_str()
789  */
790     int             vconf_get_bool(const char *keyname, int *boolval);
791
792 /**
793  * This function get the double value of given key.
794  * @param[in]   keyname key
795  * @param[out]  dblval output buffer
796  * @return 0 on success, -1 on error
797  * @pre None
798  * @post None
799  * @remarks None
800  * @see vconf_get_int(), vconf_get_bool(), vconf_get_str()
801  */
802     int             vconf_get_dbl(const char *keyname, double *dblval);
803
804 /**
805  * This function gets the string value of given key.
806  * \n You have to free this returned value.
807  * @param[in]   keyname key
808  * @return allocated pointer of key value on success, NULL on error
809  * @pre None
810  * @post None
811  * @remarks None
812  * @see vconf_get_int(), vconf_get_dbl(), vconf_get_bool()
813  * @par example
814  * @code
815    #include <stdio.h>
816    #include <vconf.h>
817
818    char *get_str=vconf_get_str("db/test/test1");
819    if(get_str) {
820       printf("vconf_get_str OK(value = %s)", get_str);
821       free(get_str);
822    }else
823       fprintf(stderr, "vconf_get_str FAIL");
824  * @endcode
825  */
826     char           *vconf_get_str(const char *keyname);
827
828 /**
829  * This function deletes given key from backend system.
830  * @param[in]   keyname key
831  * @return 0 on success, -1 on error
832  */
833     int             vconf_unset(const char *keyname);
834
835 /**
836  * This function checks if the given key exists from backend system.
837  * @param[in]   keyname key
838  * @return 0 on success: exists, -1 on error or not existing
839  */
840     int             vconf_exists(const char *keyname);
841
842 /**
843  * This function synchronizes the given key(only file backend) with storage device.
844  * @param[in]   keyname key
845  * @return 0 on success, -1 on error
846  * @pre Nome
847  * @post None
848  * @remarks None
849  * @par example
850  * @code
851  if(vconf_set_int("file/test/key1",1))
852     fprintf(stderr, "vconf_set_int FAIL\n");
853  else {
854     printf("vconf_set_int OK\n");
855     vconf_sync_key("file/test/key1");
856  }
857  * @endcode
858  */
859     int             vconf_sync_key(const char *keyname);
860
861 /**
862  * This function deletes all keys and directories below given Directory from backend system.
863  * @param[in]   in_dir  Directory name for removing
864  * @return 0 on success, -1 on error
865  * @pre Nome
866  * @post None
867  * @remarks None
868  * @par example
869  * @code
870    vconf_set_int("db/test/key1",1);
871    vconf_set_int("db/test/test1/key1",1);
872    vconf_set_int("db/test/test2/key1",1);
873    vconf_set_int("db/test/key2",1);
874
875    if(vconf_unset_recursive("db/test"))
876       fprintf(stderr, "vconf_unset_recursive FAIL\n");
877    else
878       printf("vconf_unset_recursive OK(deleted db/test\n");
879
880  * @endcode
881  */
882     int             vconf_unset_recursive(const char *in_dir);
883
884 /**
885  * This function adds a change callback for given key,
886  * which is called when the key is set or unset.
887  * \n Information(#keynode_t) of the key that changed is delivered to #vconf_callback_fn,
888  * or if the key is deleted, the @link #keynode_t keynode @endlink has #VCONF_TYPE_NONE as type.
889  * \n Multiple vconf_callback_fn functions may exist for one key.
890  * \n The callback is issued in the context of the glib main loop.
891  * \n WARNING: This callback mechanism DOES NOT GUARANTEE consistency of data chage. For example,
892  * When you have a callback for a certain key, assume that two or more processes are trying to
893  * change the value of the key competitively. In this case, your callback function will always
894  * get 'CURRENT' value, not the value raised the notify that caused run of the callback.  So,
895  * do not use vconf callback when competitive write for a key is happening. In such case, use
896  * socket-based IPC(dbus or something else) instead.
897  *
898  * @param[in]   keyname  key
899  * @param[in]   cb      callback function
900  * @param[in]   user_data    callback data
901  * @return 0 on success, -1 on error
902  * @pre Nome
903  * @post None
904  * @remarks None
905  * @see vconf_ignore_key_changed
906  * @par example
907  * @code
908  void test_cb(keynode_t *key, void* data)
909  {
910     switch(vconf_keynode_get_type(key))
911     {
912        case VCONF_TYPE_INT:
913         printf("key = %s, value = %d(int)\n",
914                 vconf_keynode_get_name(key), vconf_keynode_get_int(key));
915         break;
916        case VCONF_TYPE_BOOL:
917         printf("key = %s, value = %d(bool)\n",
918                 vconf_keynode_get_name(key), vconf_keynode_get_bool(key));
919         break;
920        case VCONF_TYPE_DOUBLE:
921         printf("key = %s, value = %f(double)\n",
922                 vconf_keynode_get_name(key), vconf_keynode_get_dbl(key));
923         break;
924        case VCONF_TYPE_STRING:
925         printf("key = %s, value = %s(string)\n",
926                 vconf_keynode_get_name(key), vconf_keynode_get_str(key));
927         break;
928        default:
929         fprintf(stderr, "Unknown Type(%d)\n", vconf_keynode_get_type(key));
930         break;
931     }
932     return;
933  }
934
935  int main()
936  {
937     int i;
938     GMainLoop *event_loop;
939
940     g_type_init();
941
942     vconf_notify_key_changed("db/test/test1", test_cb, NULL);
943
944     event_loop = g_main_loop_new(NULL, FALSE);
945     g_main_loop_run(event_loop);
946
947     vconf_ignore_key_changed("db/test/test1", test_cb);
948     return 0;
949  }
950  * @endcode
951  */
952     int             vconf_notify_key_changed(const char *keyname,
953                                              vconf_callback_fn cb,
954                                              void *user_data);
955
956 /**
957  * This function removes a change callback for given key,
958  * which was added by vconf_notify_key_changed().
959  * @param[in]   keyname  key
960  * @param[in]   cb      callback function
961  * @return 0 on success, -1 on error
962  * @pre Nome
963  * @post None
964  * @remarks None
965  * @see vconf_notify_key_changed()
966  */
967     int             vconf_ignore_key_changed(const char *keyname,
968                                              vconf_callback_fn cb);
969
970 #ifdef __cplusplus
971 }
972 #endif
973 /**
974  * @} @}
975  */
976 #endif                          /* __VCONF_BUXTON_H__ */