2 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
3 * Copyright (C) 2014 Intel Corporation
5 * Author: José Bollo <jose.bollo@open.eurogiciel.org>
6 * Author: Hakjoo Ko <hakjoo.ko@samsung.com>
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 #ifndef __VCONF_BUXTON_H__
23 #define __VCONF_BUXTON_H__
25 #define VCONF_BUXTON "1.0"
28 * @addtogroup APPLICATION_FRAMEWORK
31 * @defgroup VCONF VConf
32 * @author Sangjung Woo (sangjung.woo@samsung.com)
34 * @brief A library for reading/writing Configuration Data
36 * @section Header To use Them:
43 * - Guarantee Transaction(db backend only)
44 * - Apply Key-List concept
45 * - Changeable Backend
46 * - Simple Notification based on inotify
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)
56 * @section example Simple Example
61 const char *key1_name="db/test/key1";
63 int main(int argc, char **argv)
67 if(vconf_set_int(key1_name,1))
68 fprintf(stderr, "vconf_set_int FAIL\n");
70 printf("vconf_set_int OK\n");
72 if(vconf_get_int(key1_name, &key1_value))
73 fprintf(stderr, "vconf_get_int FAIL\n");
75 printf("vconf_get_int OK(key1 value is %d)\n", key1_value);
88 #include "vconf-buxton-keys.h"
95 * VCONF_GET_KEY, VCONF_GET_ALL, VCONF_GET_DIR
96 * \n Use for vconf_get()
101 /**< get only keys */
103 /**< get keys and directorys */
105 /**< get only directorys */
107 /**< get only keys */
109 /**< get only keys recursively */
111 /**< get keys and directorys recursively */
113 /**< get only directorys recursively */
116 typedef enum get_option_t get_option_t;
120 /**< Vconf none type for Error detection */
121 VCONF_TYPE_STRING = 40,
122 /**< Vconf string type */
124 /**< Vconf integer type */
125 VCONF_TYPE_DOUBLE = 42,
126 /**< Vconf double type */
127 VCONF_TYPE_BOOL = 43,
128 /**< Vconf boolean type */
130 /**< Vconf directory type */
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()
140 typedef struct _keynode_t keynode_t;
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()
150 typedef struct _keylist_t keylist_t;
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.
158 typedef void (*vconf_callback_fn) (keynode_t * node,
161 /************************************************
162 * keynode handling APIs *
163 ************************************************/
166 * This function gets Key name of the keynode.
167 * @param[in] keynode The Key
168 * @return Key Name of the keynode
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
174 const char *vconf_keynode_get_name(keynode_t * keynode);
177 * This function gets value type of the keynode.
178 * @param[in] keynode The Key
179 * @return Type of the keynode
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
185 int vconf_keynode_get_type(keynode_t * keynode);
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
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
196 int vconf_keynode_get_int(keynode_t * keynode);
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
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
207 double vconf_keynode_get_dbl(keynode_t * keynode);
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')
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
218 int vconf_keynode_get_bool(keynode_t * keynode);
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
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
229 char *vconf_keynode_get_str(keynode_t * keynode);
232 /************************************************
233 * keylist handling APIs
234 ************************************************/
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()
242 int vconf_set_default_group(const char *groupname);
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
250 * @see vconf_set(), vconf_get(), vconf_keylist_create(), vconf_keylist_free(), vconf_set_default_group()
252 keylist_t *vconf_keylist_new(void);
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
262 * @see vconf_set(), vconf_get(), vconf_keylist_new()
264 int vconf_keylist_free(keylist_t * keylist);
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
273 * @see vconf_set(), vconf_get(), vconf_keylist_nextnode(), vconf_keylist_rewind(), vconf_keylist_nextnode()
277 keylist_t* pKeyList = NULL;
278 pKeyList = vconf_keylist_new();
280 r = vconf_get(pKeyList, KEY_PARENT, VCONF_GET_KEY);
282 tet_infoline("vconf_get() failed in positive test case");
283 tet_result(TET_FAIL);
287 vconf_keylist_nextnode(pKeyList);
288 vconf_keylist_nextnode(pKeyList);
290 // Move first position from KeyList
291 r = vconf_keylist_rewind(pKeyList);
293 tet_infoline("vconf_keylist_rewind() failed in positive test case");
294 tet_result(TET_FAIL);
298 while(vconf_keylist_nextnode(pKeyList)) ;
301 int vconf_keylist_rewind(keylist_t * keylist);
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
312 * @see vconf_set(), vconf_get(), keynode_t, vconf_t
322 keylist_t* pKeyList = NULL;
325 pKeyList = vconf_keylist_new();
326 r = vconf_get(pKeyList, KEY_PARENT, VCONF_GET_KEY);
328 printf("vconf_get() failed in positive test case");
332 r = vconf_keylist_lookup(pKeyList, KEY_02, &pKeyNode);
334 printf("vconf_get() failed in positive test case");
338 nResult = vconf_keynode_get_int(pKeyNode);
339 if(nResult !=KEY_02_INT_VALUE)
341 printf("vconf_get() failed in positive test case");
346 vconf_keylist_free(pKeyList);
351 int vconf_keylist_lookup(keylist_t * keylist,
353 keynode_t ** return_node);
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
363 * @see vconf_set(), vconf_get(), vconf_keylist_rewind(), vconf_keylist_nextnode(), keynode_t
365 keynode_t *vconf_keylist_nextnode(keylist_t * keylist);
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
375 int vconf_keylist_sort(keylist_t * keylist);
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()
386 int vconf_keylist_add_int(keylist_t * keylist,
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
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()
402 int vconf_keylist_add_bool(keylist_t * keylist,
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
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()
418 int vconf_keylist_add_dbl(keylist_t * keylist,
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
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()
434 int vconf_keylist_add_str(keylist_t * keylist,
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
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()
449 int vconf_keylist_add_null(keylist_t * keylist,
450 const char *keyname);
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
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()
462 int vconf_keylist_del(keylist_t * keylist,
463 const char *keyname);
465 /************************************************
467 ************************************************/
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
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()
486 const char *keyname_list[3]={"db/test/key1", "db/test/key2", "db/test/key3"};
488 // Transaction Test(all or nothing is written)
489 kl = vconf_keylist_new();
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);
495 fprintf(stderr, "nothing is written\n");
497 printf("everything is written\n");
499 vconf_keylist_free(kl);
501 // You can set items which have different backend.
502 kl = vconf_keylist_new();
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);
509 vconf_keylist_free(kl);
514 int vconf_set(keylist_t * keylist);
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
524 * @see vconf_set_bool(), vconf_set_dbl(), vconf_set_str()
526 int vconf_set_int(const char *keyname, const int intval);
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
536 * @see vconf_set_int(), vconf_set_dbl(), vconf_set_str()
542 const char *key1_name="memory/test/key1";
544 int main(int argc, char **argv)
548 if(vconf_set_bool(key1_name, 1))
549 fprintf(stderr, "vconf_set_bool FAIL\n");
551 printf("vconf_set_bool OK\n");
553 if(vconf_get_bool(key1_name, &key1_value))
554 fprintf(stderr, "vconf_get_bool FAIL\n");
556 printf("vconf_get_bool OK(key1 value is %d)\n", key1_value);
562 int vconf_set_bool(const char *keyname, const int boolval);
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
572 * @see vconf_set_int(), vconf_set_bool(), vconf_set_str()
574 int vconf_set_dbl(const char *keyname,
575 const double dblval);
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
585 * @see vconf_set_bool(), vconf_set_dbl(), vconf_set_int()
587 int vconf_set_str(const char *keyname, const char *strval);
589 /************************************************
590 * setting label APIs *
591 ************************************************/
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
602 int vconf_set_labels(keylist_t * keylist, const char *label);
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
613 int vconf_set_label(const char *keyname, const char *label);
615 /************************************************
617 ************************************************/
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
626 int vconf_refresh(keylist_t * keylist);
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
645 keynode_t *temp_node;
646 const char *vconfkeys1="db/test/key1";
647 const char *parent_dir="db/test";
649 kl = vconf_keylist_new();
650 if(vconf_scan(kl, parent_dir, VCONF_GET_KEY))
651 fprintf(stderr, "vconf_get FAIL(%s)", vconfkeys1);
653 printf("vconf_get OK(%s)", vconfkeys1);
655 while((temp_node = vconf_keylist_nextnode(kl))) {
656 switch(vconf_keynode_get_type(temp_node)) {
658 printf("key = %s, value = %d\n",
659 vconf_keynode_get_name(temp_node), vconf_keynode_get_int(temp_node));
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));
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));
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));
674 printf("Unknown Type\n");
677 vconf_keylist_free(kl);
681 int vconf_scan(keylist_t * keylist,
682 const char *in_parentDIR,
683 get_option_t option);
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
703 keynode_t *temp_node;
704 const char *vconfkeys1="db/test/key1";
705 const char *parent_dir="db/test";
707 kl = vconf_keylist_new();
708 if(vconf_get(kl, parent_dir, VCONF_GET_KEY))
709 fprintf(stderr, "vconf_get FAIL(%s)", vconfkeys1);
711 printf("vconf_get OK(%s)", vconfkeys1);
713 while((temp_node = vconf_keylist_nextnode(kl))) {
714 switch(vconf_keynode_get_type(temp_node)) {
716 printf("key = %s, value = %d\n",
717 vconf_keynode_get_name(temp_node), vconf_keynode_get_int(temp_node));
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));
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));
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));
732 printf("Unknown Type\n");
735 vconf_keylist_free(kl);
739 int vconf_get(keylist_t * keylist,
740 const char *in_parentDIR,
741 get_option_t option);
744 * This function get the integer value of given key.
746 * @param[in] keyname key
747 * @param[out] intval output buffer
748 * @return 0 on success, -1 on error
752 * @see vconf_get_bool, vconf_get_dbl, vconf_get_str
758 const char *key1_name="db/test/key1";
760 int main(int argc, char **argv)
764 if(vconf_set_int(key1_name,1))
765 fprintf(stderr, "vconf_set_int FAIL\n");
767 printf("vconf_set_int OK\n");
769 if(vconf_get_int(key1_name, &key1_value))
770 fprintf(stderr, "vconf_get_int FAIL\n");
772 printf("vconf_get_int OK(key1 value is %d)\n", key1_value);
778 int vconf_get_int(const char *keyname, int *intval);
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
788 * @see vconf_get_int(), vconf_get_dbl(), vconf_get_str()
790 int vconf_get_bool(const char *keyname, int *boolval);
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
800 * @see vconf_get_int(), vconf_get_bool(), vconf_get_str()
802 int vconf_get_dbl(const char *keyname, double *dblval);
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
812 * @see vconf_get_int(), vconf_get_dbl(), vconf_get_bool()
818 char *get_str=vconf_get_str("db/test/test1");
820 printf("vconf_get_str OK(value = %s)", get_str);
823 fprintf(stderr, "vconf_get_str FAIL");
826 char *vconf_get_str(const char *keyname);
829 * This function deletes given key from backend system.
830 * @param[in] keyname key
831 * @return 0 on success, -1 on error
833 int vconf_unset(const char *keyname);
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
840 int vconf_exists(const char *keyname);
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
851 if(vconf_set_int("file/test/key1",1))
852 fprintf(stderr, "vconf_set_int FAIL\n");
854 printf("vconf_set_int OK\n");
855 vconf_sync_key("file/test/key1");
859 int vconf_sync_key(const char *keyname);
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
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);
875 if(vconf_unset_recursive("db/test"))
876 fprintf(stderr, "vconf_unset_recursive FAIL\n");
878 printf("vconf_unset_recursive OK(deleted db/test\n");
882 int vconf_unset_recursive(const char *in_dir);
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.
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
905 * @see vconf_ignore_key_changed
908 void test_cb(keynode_t *key, void* data)
910 switch(vconf_keynode_get_type(key))
913 printf("key = %s, value = %d(int)\n",
914 vconf_keynode_get_name(key), vconf_keynode_get_int(key));
916 case VCONF_TYPE_BOOL:
917 printf("key = %s, value = %d(bool)\n",
918 vconf_keynode_get_name(key), vconf_keynode_get_bool(key));
920 case VCONF_TYPE_DOUBLE:
921 printf("key = %s, value = %f(double)\n",
922 vconf_keynode_get_name(key), vconf_keynode_get_dbl(key));
924 case VCONF_TYPE_STRING:
925 printf("key = %s, value = %s(string)\n",
926 vconf_keynode_get_name(key), vconf_keynode_get_str(key));
929 fprintf(stderr, "Unknown Type(%d)\n", vconf_keynode_get_type(key));
938 GMainLoop *event_loop;
942 vconf_notify_key_changed("db/test/test1", test_cb, NULL);
944 event_loop = g_main_loop_new(NULL, FALSE);
945 g_main_loop_run(event_loop);
947 vconf_ignore_key_changed("db/test/test1", test_cb);
952 int vconf_notify_key_changed(const char *keyname,
953 vconf_callback_fn cb,
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
965 * @see vconf_notify_key_changed()
967 int vconf_ignore_key_changed(const char *keyname,
968 vconf_callback_fn cb);
976 #endif /* __VCONF_BUXTON_H__ */