/vconf/include/vconf.h

https://review.tizen.org/git/ · C++ Header · 847 lines · 79 code · 49 blank · 719 comment · 0 complexity · cb2020c1b1b2b9511115cbb360a2bb4c MD5 · raw file

  1. /*
  2. * libslp-setting
  3. *
  4. * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
  5. *
  6. * Contact: 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. #ifndef __VCONF_H__
  22. #define __VCONF_H__
  23. /**
  24. * @addtogroup APPLICATION_FRAMEWORK
  25. * @{
  26. *
  27. * @defgroup VCONF VConf
  28. * @author Sangjung Woo (sangjung.woo@samsung.com)
  29. * @version 0.2
  30. * @brief A library for reading/writing Configuration Data
  31. *
  32. * @section Header To use Them:
  33. * @code
  34. * #include <vconf.h>
  35. * @endcode
  36. *
  37. * @section Properties
  38. * - Convenient API
  39. * - Guarantee Transaction(db backend only)
  40. * - Apply Key-List concept
  41. * - Changeable Backend
  42. * - Simple Notification based on inotify
  43. *
  44. * @section Backend key has below backend.
  45. * - db => use libsqlfs ex) db/a/b
  46. * \n Lowest speed, highest robustness, correctly sync
  47. * - memory => use tmpfs ex) memory/a/b
  48. * \n Highest speed, volitile
  49. * - file => use basic file system(not support atomicity) ex) file/a/b
  50. * \n Higher speed, lower robustness(Not guarantee atomicity)
  51. *
  52. * @section example Simple Example
  53. * @code
  54. #include <stdio.h>
  55. #include <vconf.h>
  56. const char *key1_name="db/test/key1";
  57. int main(int argc, char **argv)
  58. {
  59. int key1_value;
  60. if(vconf_set_int(key1_name,1))
  61. fprintf(stderr, "vconf_set_int FAIL\n");
  62. else
  63. printf("vconf_set_int OK\n");
  64. if(vconf_get_int(key1_name, &key1_value))
  65. fprintf(stderr, "vconf_get_int FAIL\n");
  66. else
  67. printf("vconf_get_int OK(key1 value is %d)\n", key1_value);
  68. return 0;
  69. }
  70. * @endcode
  71. *
  72. */
  73. /**
  74. * @addtogroup VCONF
  75. * @{
  76. */
  77. #include "vconf-keys.h"
  78. #ifdef __cplusplus
  79. extern "C" {
  80. #endif
  81. /**
  82. * VCONF_GET_KEY, VCONF_GET_ALL, VCONF_GET_DIR
  83. * \n Use for vconf_get()
  84. * @see vconf_get()
  85. */
  86. enum get_option_t {
  87. VCONF_GET_KEY = 0,
  88. /**< get only keys */
  89. VCONF_GET_ALL,
  90. /**< get keys and directorys */
  91. VCONF_GET_DIR
  92. /**< get only directorys */
  93. };
  94. typedef enum get_option_t get_option_t;
  95. enum vconf_t {
  96. VCONF_TYPE_NONE = 0,
  97. /**< Vconf none type for Error detection */
  98. VCONF_TYPE_STRING = 40,
  99. /**< Vconf string type */
  100. VCONF_TYPE_INT = 41,
  101. /**< Vconf integer type */
  102. VCONF_TYPE_DOUBLE = 42,
  103. /**< Vconf double type */
  104. VCONF_TYPE_BOOL = 43,
  105. /**< Vconf boolean type */
  106. VCONF_TYPE_DIR
  107. /**< Vconf directory type */
  108. };
  109. /**
  110. * keynode_t is an opaque type, it must be
  111. * used via accessor functions.
  112. * @see vconf_keynode_get_name(), vconf_keynode_get_type()
  113. * @see vconf_keynode_get_bool(), vconf_keynode_get_dbl(), vconf_keynode_get_int(), vconf_keynode_get_str()
  114. */
  115. typedef struct _keynode_t {
  116. char *keyname;
  117. int type;
  118. union {
  119. int i;
  120. int b;
  121. double d;
  122. char *s;
  123. } value;
  124. struct _keynode_t *next;
  125. } keynode_t;
  126. /**
  127. * keylist_t is an opaque type, it must be
  128. * used via accessor functions.
  129. * @see vconf_keylist_new(), vconf_keylist_free()
  130. * @see vconf_keylist_add_bool(),vconf_keylist_add_str(), vconf_keylist_add_dbl(), vconf_keylist_add_int()
  131. * @see vconf_keylist_del(), vconf_keylist_add_null()
  132. * @see vconf_keylist_lookup(), vconf_keylist_nextnode(), vconf_keylist_rewind()
  133. */
  134. typedef struct _keylist_t {
  135. int num;
  136. keynode_t *head;
  137. keynode_t *cursor;
  138. } keylist_t;
  139. /**
  140. * This is the signature of a callback function added with vconf_notify_key_changed().
  141. * \n The callback function is invoked when the key is set.
  142. * @see keynode_t
  143. */
  144. typedef void (*vconf_callback_fn) (keynode_t *node, void *user_data);
  145. /************************************************
  146. * keynode handling APIs *
  147. ************************************************/
  148. /**
  149. * This function gets Key name of the keynode.
  150. * @param[in] keynode The Key
  151. * @return Key Name of the keynode
  152. * @pre Nome
  153. * @post None
  154. * @remarks None
  155. * @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
  156. */
  157. char *vconf_keynode_get_name(keynode_t *keynode);
  158. /**
  159. * This function gets value type of the keynode.
  160. * @param[in] keynode The Key
  161. * @return Type of the keynode
  162. * @pre Nome
  163. * @post None
  164. * @remarks None
  165. * @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
  166. */
  167. int vconf_keynode_get_type(keynode_t *keynode);
  168. /**
  169. * This function gets Integer value of the keynode.
  170. * @param[in] keynode The Key
  171. * @return Integer value, or 0 if no value is obtained
  172. ** @pre Nome
  173. * @post None
  174. * @remarks None
  175. * @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
  176. */
  177. int vconf_keynode_get_int(keynode_t *keynode);
  178. /**
  179. * This function gets Double value of the keynode.
  180. * @param[in] keynode The Key
  181. * @return Double value, or 0.0 if no value is obtained
  182. * @pre Nome
  183. * @post None
  184. * @remarks None
  185. * @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
  186. */
  187. double vconf_keynode_get_dbl(keynode_t *keynode);
  188. /**
  189. * This function gets Boolean value of the keynode.
  190. * @param[in] keynode The Key
  191. * @return Boolean value, -1 on error (Integer value 1 is 'True', and 0 is 'False')
  192. * @pre Nome
  193. * @post None
  194. * @remarks None
  195. * @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
  196. */
  197. int vconf_keynode_get_bool(keynode_t *keynode);
  198. /**
  199. * This function gets String value of the keynode.
  200. * @param[in] keynode The Key
  201. * @return String value, or NULL 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_int, vconf_keynode_get_dbl, keynode_t, vconf_t
  206. */
  207. char *vconf_keynode_get_str(keynode_t *keynode);
  208. /************************************************
  209. * keylist handling APIs
  210. ************************************************/
  211. /**
  212. * Allocate, initialize and return a new Keylist object.
  213. * Return value keylist_t* pointer must be relised by calling vconf_keylist_free()
  214. * @return The pointer of New keylist, NULL on error
  215. * @pre None
  216. * @post None
  217. * @remarks None
  218. * @see vconf_set(), vconf_get(), vconf_keylist_new(), vconf_keylist_free()
  219. */
  220. keylist_t *vconf_keylist_new(void);
  221. /**
  222. * This function moves the current Keynode position to the first items.
  223. * @param[in] keylist Key List
  224. * @return 0 on success, -1 on error
  225. * @pre None
  226. * @post None
  227. * @remarks None
  228. * @see vconf_set(), vconf_get(), vconf_keylist_nextnode(), vconf_keylist_rewind(), vconf_keylist_nextnode()
  229. * @par example
  230. * @code
  231. int r =0;
  232. keylist_t* pKeyList = NULL;
  233. pKeyList = vconf_keylist_new();
  234. r = vconf_get(pKeyList, KEY_PARENT, VCONF_GET_KEY);
  235. if (r) {
  236. tet_infoline("vconf_get() failed in positive test case");
  237. tet_result(TET_FAIL);
  238. return;
  239. }
  240. vconf_keylist_nextnode(pKeyList);
  241. vconf_keylist_nextnode(pKeyList);
  242. // Move first position from KeyList
  243. r = vconf_keylist_rewind(pKeyList);
  244. if (r<0) {
  245. tet_infoline("vconf_keylist_rewind() failed in positive test case");
  246. tet_result(TET_FAIL);
  247. return;
  248. }
  249. while(vconf_keylist_nextnode(pKeyList)) ;
  250. * @endcode
  251. */
  252. int vconf_keylist_rewind(keylist_t *keylist);
  253. /**
  254. * A destructor for Keylist objects.<br>
  255. * After calling vconf_keylist_new(), developer have to call this function for release internal memory.
  256. * @param[in] keylist Key List
  257. * @return 0 on success, -1 on error
  258. * @pre None
  259. * @post None
  260. * @remarks None
  261. * @see vconf_set(), vconf_get(), vconf_keylist_new()
  262. */
  263. int vconf_keylist_free(keylist_t *keylist);
  264. /**
  265. * This function looks for a Keynode contained in keylist that matches keyname.
  266. * @param[in] keylist Key List
  267. * @param[in] keyname Key to find
  268. * @param[out] return_node pointer of keynode to set
  269. * @return Type of the found key that is vconf_t enumeration value
  270. * @pre None
  271. * @post None
  272. * @remarks None
  273. * @see vconf_set(), vconf_get(), keynode_t, vconf_t
  274. * @par example
  275. * @code
  276. #include <stdio.h>
  277. #include <vconf.h>
  278. int main()
  279. {
  280. int r = 0;
  281. int nResult = 0;
  282. keylist_t* pKeyList = NULL;
  283. keynode_t *pKeyNode;
  284. pKeyList = vconf_keylist_new();
  285. r = vconf_get(pKeyList, KEY_PARENT, VCONF_GET_KEY);
  286. if (r<0) {
  287. printf("vconf_get() failed in positive test case");
  288. return -1;
  289. }
  290. r = vconf_keylist_lookup(pKeyList, KEY_02, &pKeyNode);
  291. if (r<0) {
  292. printf("vconf_get() failed in positive test case");
  293. return -1;
  294. }
  295. nResult = vconf_keynode_get_int(pKeyNode);
  296. if(nResult !=KEY_02_INT_VALUE)
  297. {
  298. printf("vconf_get() failed in positive test case");
  299. return -1;
  300. }
  301. vconf_keylist_free(pKeyList);
  302. return 0;
  303. }
  304. * @endcode
  305. */
  306. int vconf_keylist_lookup(keylist_t *keylist, const char *keyname,
  307. keynode_t **return_node);
  308. /**
  309. * This function returns the next Key in a Keylist.
  310. * Next key is known by the keylist internal cursor.
  311. * @param[in] keylist Key List
  312. * @return The next Keynode, NULL on error
  313. * @pre None
  314. * @post None
  315. * @remarks None
  316. * @see vconf_set(), vconf_get(), vconf_keylist_rewind(), vconf_keylist_nextnode(), keynode_t
  317. */
  318. keynode_t *vconf_keylist_nextnode(keylist_t *keylist);
  319. /**
  320. * This function appends a new Keynode included integer value to the keylist.
  321. * \n If same keyname exist, the keynode will change.
  322. * @param[in] keylist Key List
  323. * @param[in] keyname Key
  324. * @param[in] value The integer value
  325. * @return Number of keynode included in the keylist, -1 on error
  326. * @see vconf_set(), vconf_get()
  327. */
  328. int vconf_keylist_add_int(keylist_t *keylist, const char *keyname,
  329. const int value);
  330. /**
  331. * This function appends a new Keynode included boolean value to the keylist.
  332. * \n If same keyname exist, the keynode will change.
  333. * @param[in] keylist Key List
  334. * @param[in] keyname Key
  335. * @param[in] value The boolean value
  336. * @return Number of keynode included in the keylist, -1 on error
  337. * @pre None
  338. * @post None
  339. * @remarks None
  340. * @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()
  341. */
  342. int vconf_keylist_add_bool(keylist_t *keylist, const char *keyname,
  343. const int value);
  344. /**
  345. * This function appends a new Keynode included double value to the keylist.
  346. * \n If same keyname exist, the keynode will change.
  347. * @param[in] keylist Key List
  348. * @param[in] keyname Key
  349. * @param[in] value The double value
  350. * @return Number of keynode included in the keylist, -1 on error
  351. * @pre None
  352. * @post None
  353. * @remarks None
  354. * @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()
  355. */
  356. int vconf_keylist_add_dbl(keylist_t *keylist, const char *keyname,
  357. const double value);
  358. /**
  359. * This function appends a new Keynode included string value to the keylist.
  360. * \n If same keyname exist, the keynode will change.
  361. * @param[in] keylist Key List
  362. * @param[in] keyname Key
  363. * @param[in] value The pointer of string value
  364. * @return Number of keynode included in the keylist, -1 on error
  365. * @pre None
  366. * @post None
  367. * @remarks None
  368. * @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()
  369. */
  370. int vconf_keylist_add_str(keylist_t *keylist, const char *keyname,
  371. const char *value);
  372. /**
  373. * This function Appends a new Keynode to the keylist without value.
  374. * \n Use for vconf_get()
  375. * @param[in] keylist Key List
  376. * @param[in] keyname Key
  377. * @return Number of keynode included in the keylist, -1 on error
  378. * @pre None
  379. * @post None
  380. * @remarks None
  381. * @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()
  382. */
  383. int vconf_keylist_add_null(keylist_t *keylist, const char *keyname);
  384. /**
  385. * This function removes the keynode that matches keyname.
  386. * @param[in] keylist the keylist included the keyname
  387. * @param[in] keyname key
  388. * @return 0 on success, -1(Invalid parameter), -2(Not exist keyname in keylist) on error
  389. * @pre None
  390. * @post None
  391. * @remarks None
  392. * @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()
  393. */
  394. int vconf_keylist_del(keylist_t *keylist, const char *keyname);
  395. /************************************************
  396. * setting APIs *
  397. ************************************************/
  398. /**
  399. * This function sets the keys included in keylist.
  400. * \n If you use db backend, keylist is handled as one transaction.
  401. * @param[in] keylist the keylist which should contain changed keys
  402. * @return 0 on success, -1 on error
  403. * @pre None
  404. * @post None
  405. * @remarks None
  406. * @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()
  407. * @par example
  408. * @code
  409. #include <stdio.h>
  410. #include <vconf.h>
  411. int main()
  412. {
  413. keylist_t *kl=NULL;
  414. const char *keyname_list[3]={"db/test/key1", "db/test/key2", "db/test/key3"};
  415. // Transaction Test(all or nothing is written)
  416. kl = vconf_keylist_new();
  417. vconf_keylist_add_int(kl, keyname_list[0], 1);
  418. vconf_keylist_add_str(kl, keyname_list[1], "transaction Test");
  419. vconf_keylist_add_dbl(kl, keyname_list[2], 0.3);
  420. if(vconf_set(kl))
  421. fprintf(stderr, "nothing is written\n");
  422. else
  423. printf("everything is written\n");
  424. vconf_keylist_free(kl);
  425. // You can set items which have different backend.
  426. kl = vconf_keylist_new();
  427. vconf_keylist_add_int(kl, "memory/a/xxx1", 4);
  428. vconf_keylist_add_str(kl, "file/a/xxx2", "test 3");
  429. vconf_keylist_add_dbl(kl, "db/a/xxx3", 0.3);
  430. vconf_set(kl)
  431. vconf_keylist_free(kl);
  432. return 0;
  433. }
  434. * @endcode
  435. */
  436. int vconf_set(keylist_t *keylist);
  437. /**
  438. * This function sets the integer value of given key.
  439. * @param[in] in_key key
  440. * @param[in] intval integer value to set (0 is also allowed as a value.)
  441. * @return 0 on success, -1 on error
  442. * @pre None
  443. * @post None
  444. * @remarks None
  445. * @see vconf_set_bool(), vconf_set_dbl(), vconf_set_str()
  446. */
  447. int vconf_set_int(const char *in_key, const int intval);
  448. /**
  449. * This function sets the boolean value of given key.
  450. * @param[in] in_key key
  451. * @param[in] boolval boolean value(1 or 0) to set. (Integer value 1 is 'True', and 0 is 'False')
  452. * @return 0 on success, -1 on error
  453. * @pre None
  454. * @post None
  455. * @remarks None
  456. * @see vconf_set_int(), vconf_set_dbl(), vconf_set_str()
  457. * @par example
  458. * @code
  459. #include <stdio.h>
  460. #include <vconf.h>
  461. const char *key1_name="memory/test/key1";
  462. int main(int argc, char **argv)
  463. {
  464. int key1_value;
  465. if(vconf_set_bool(key1_name, 1))
  466. fprintf(stderr, "vconf_set_bool FAIL\n");
  467. else
  468. printf("vconf_set_bool OK\n");
  469. if(vconf_get_bool(key1_name, &key1_value))
  470. fprintf(stderr, "vconf_get_bool FAIL\n");
  471. else
  472. printf("vconf_get_bool OK(key1 value is %d)\n", key1_value);
  473. return 0;
  474. }
  475. * @endcode
  476. */
  477. int vconf_set_bool(const char *in_key, const int boolval);
  478. /**
  479. * This function sets the double value of given key.
  480. * @param[in] in_key key
  481. * @param[in] dblval double value to set (0.0 is also allowed as a value.)
  482. * @return 0 on success, -1 on error
  483. * @pre None
  484. * @post None
  485. * @remarks None
  486. * @see vconf_set_int(), vconf_set_bool(), vconf_set_str()
  487. */
  488. int vconf_set_dbl(const char *in_key, const double dblval);
  489. /**
  490. * This function sets the string value of given key.
  491. * @param[in] in_key key
  492. * @param[in] strval string value to set
  493. * @return 0 on success, -1 on error
  494. * @pre None
  495. * @post None
  496. * @remarks None
  497. * @see vconf_set_bool(), vconf_set_dbl(), vconf_set_int()
  498. */
  499. int vconf_set_str(const char *in_key, const char *strval);
  500. /**
  501. * This function get the keys or subdirectory in in_parentDIR.<br>
  502. * If keylist has any key information, vconf only retrieves the keys.<br>
  503. * This is not recursive.
  504. * @param[in] keylist keylist created by vconf_keylist_new()
  505. * @param[in] in_parentDIR parent DIRECTORY of needed keys
  506. * @param[in] option VCONF_GET_KEY|VCONF_GET_DIR|VCONF_GET_ALL
  507. * @return 0 on success, -1 on error
  508. * @pre None
  509. * @post None
  510. * @remkar None
  511. * @par example
  512. * @code
  513. #include <stdio.h>
  514. #include <vconf.h>
  515. int main()
  516. {
  517. keylist_t *kl=NULL;
  518. keynode_t *temp_node;
  519. const char *vconfkeys1="db/test/key1";
  520. const char *parent_dir="db/test";
  521. kl = vconf_keylist_new();
  522. if(vconf_get(kl, parent_dir, 0))
  523. fprintf(stderr, "vconf_get FAIL(%s)", vconfkeys1);
  524. else
  525. printf("vconf_get OK(%s)", vconfkeys1);
  526. while((temp_node = vconf_keylist_nextnode(kl))) {
  527. switch(vconf_keynode_get_type(temp_node)) {
  528. case VCONF_TYPE_INT:
  529. printf("key = %s, value = %d\n",
  530. vconf_keynode_get_name(temp_node), vconf_keynode_get_int(temp_node));
  531. break;
  532. case VCONF_TYPE_BOOL:
  533. printf("key = %s, value = %d\n",
  534. vconf_keynode_get_name(temp_node), vconf_keynode_get_bool(temp_node));
  535. break;
  536. case VCONF_TYPE_DOUBLE:
  537. printf("key = %s, value = %f\n",
  538. vconf_keynode_get_name(temp_node), vconf_keynode_get_dbl(temp_node));
  539. break;
  540. case VCONF_TYPE_STRING:
  541. printf("key = %s, value = %s\n",
  542. vconf_keynode_get_name(temp_node), vconf_keynode_get_str(temp_node));
  543. break;
  544. default:
  545. printf("Unknown Type\n");
  546. }
  547. }
  548. vconf_keylist_free(kl);
  549. }
  550. * @endcode
  551. */
  552. int vconf_get(keylist_t *keylist, const char *in_parentDIR, get_option_t option);
  553. /**
  554. * This function get the integer value of given key.
  555. *
  556. * @param[in] in_key key
  557. * @param[out] intval output buffer
  558. * @return 0 on success, -1 on error
  559. * @pre None
  560. * @post None
  561. * @remkar None
  562. * @see vconf_get_bool, vconf_get_dbl, vconf_get_str
  563. * @par example
  564. * @code
  565. #include <stdio.h>
  566. #include <vconf.h>
  567. const char *key1_name="db/test/key1";
  568. int main(int argc, char **argv)
  569. {
  570. int key1_value;
  571. if(vconf_set_int(key1_name,1))
  572. fprintf(stderr, "vconf_set_int FAIL\n");
  573. else
  574. printf("vconf_set_int OK\n");
  575. if(vconf_get_int(key1_name, &key1_value))
  576. fprintf(stderr, "vconf_get_int FAIL\n");
  577. else
  578. printf("vconf_get_int OK(key1 value is %d)\n", key1_value);
  579. return 0;
  580. }
  581. * @endcode
  582. */
  583. int vconf_get_int(const char *in_key, int *intval);
  584. /**
  585. * This function get the boolean value(1 or 0) of given key.
  586. * @param[in] in_key key
  587. * @param[out] boolval output buffer
  588. * @return 0 on success, -1 on error
  589. * @pre None
  590. * @post None
  591. * @remarks None
  592. * @see vconf_get_int(), vconf_get_dbl(), vconf_get_str()
  593. */
  594. int vconf_get_bool(const char *in_key, int *boolval);
  595. /**
  596. * This function get the double value of given key.
  597. * @param[in] in_key key
  598. * @param[out] dblval output buffer
  599. * @return 0 on success, -1 on error
  600. * @pre None
  601. * @post None
  602. * @remarks None
  603. * @see vconf_get_int(), vconf_get_bool(), vconf_get_str()
  604. */
  605. int vconf_get_dbl(const char *in_key, double *dblval);
  606. /**
  607. * This function gets the string value of given key.
  608. * \n You have to free this returned value.
  609. * @param[in] in_key key
  610. * @return allocated pointer of key value on success, NULL on error
  611. * @pre None
  612. * @post None
  613. * @remarks None
  614. * @see vconf_get_int(), vconf_get_dbl(), vconf_get_bool()
  615. * @par example
  616. * @code
  617. #include <stdio.h>
  618. #include <vconf.h>
  619. char *get_str=vconf_get_str("db/test/test1");
  620. if(get_str) {
  621. printf("vconf_get_str OK(value = %s)", get_str);
  622. free(get_str);
  623. }else
  624. fprintf(stderr, "vconf_get_str FAIL");
  625. * @endcode
  626. */
  627. char *vconf_get_str(const char *in_key);
  628. /**
  629. * This function deletes given key from backend system.
  630. * @param[in] in_key key
  631. * @return 0 on success, -1 on error
  632. */
  633. int vconf_unset(const char *in_key);
  634. /**
  635. * This function synchronizes the given key(only file backend) with storage device.
  636. * @param[in] in_key key
  637. * @return 0 on success, -1 on error
  638. * @pre Nome
  639. * @post None
  640. * @remarks None
  641. * @par example
  642. * @code
  643. if(vconf_set_int("file/test/key1",1))
  644. fprintf(stderr, "vconf_set_int FAIL\n");
  645. else {
  646. printf("vconf_set_int OK\n");
  647. vconf_sync_key("file/test/key1");
  648. }
  649. * @endcode
  650. */
  651. int vconf_sync_key(const char *in_key);
  652. /**
  653. * This function deletes all keys and directories below given Directory from backend system.
  654. * @param[in] in_dir Directory name for removing
  655. * @return 0 on success, -1 on error
  656. * @pre Nome
  657. * @post None
  658. * @remarks None
  659. * @par example
  660. * @code
  661. vconf_set_int("db/test/key1",1);
  662. vconf_set_int("db/test/test1/key1",1);
  663. vconf_set_int("db/test/test2/key1",1);
  664. vconf_set_int("db/test/key2",1);
  665. if(vconf_unset_recursive("db/test"))
  666. fprintf(stderr, "vconf_unset_recursive FAIL\n");
  667. else
  668. printf("vconf_unset_recursive OK(deleted db/test\n");
  669. * @endcode
  670. */
  671. int vconf_unset_recursive(const char *in_dir);
  672. /**
  673. * This function adds a change callback for given key,
  674. * which is called when the key is set or unset.
  675. * \n Information(#keynode_t) of the key that changed is delivered to #vconf_callback_fn,
  676. * or if the key is deleted, the @link #keynode_t keynode @endlink has #VCONF_TYPE_NONE as type.
  677. * \n Multiple vconf_callback_fn functions may exist for one key.
  678. * \n The callback is issued in the context of the glib main loop.
  679. * \n WARNING: This callback mechanism DOES NOT GUARANTEE consistency of data chage. For example,
  680. * When you have a callback for a certain key, assume that two or more processes are trying to
  681. * change the value of the key competitively. In this case, your callback function will always
  682. * get 'CURRENT' value, not the value raised the notify that caused run of the callback. So,
  683. * do not use vconf callback when competitive write for a key is happening. In such case, use
  684. * socket-based IPC(dbus or something else) instead.
  685. *
  686. * @param[in] in_key key
  687. * @param[in] cb callback function
  688. * @param[in] user_data callback data
  689. * @return 0 on success, -1 on error
  690. * @pre Nome
  691. * @post None
  692. * @remarks None
  693. * @see vconf_ignore_key_changed
  694. * @par example
  695. * @code
  696. void test_cb(keynode_t *key, void* data)
  697. {
  698. switch(vconf_keynode_get_type(key))
  699. {
  700. case VCONF_TYPE_INT:
  701. printf("key = %s, value = %d(int)\n",
  702. vconf_keynode_get_name(key), vconf_keynode_get_int(key));
  703. break;
  704. case VCONF_TYPE_BOOL:
  705. printf("key = %s, value = %d(bool)\n",
  706. vconf_keynode_get_name(key), vconf_keynode_get_bool(key));
  707. break;
  708. case VCONF_TYPE_DOUBLE:
  709. printf("key = %s, value = %f(double)\n",
  710. vconf_keynode_get_name(key), vconf_keynode_get_dbl(key));
  711. break;
  712. case VCONF_TYPE_STRING:
  713. printf("key = %s, value = %s(string)\n",
  714. vconf_keynode_get_name(key), vconf_keynode_get_str(key));
  715. break;
  716. default:
  717. fprintf(stderr, "Unknown Type(%d)\n", vconf_keynode_get_type(key));
  718. break;
  719. }
  720. return;
  721. }
  722. int main()
  723. {
  724. int i;
  725. GMainLoop *event_loop;
  726. g_type_init();
  727. vconf_notify_key_changed("db/test/test1", test_cb, NULL);
  728. event_loop = g_main_loop_new(NULL, FALSE);
  729. g_main_loop_run(event_loop);
  730. vconf_ignore_key_changed("db/test/test1", test_cb);
  731. return 0;
  732. }
  733. * @endcode
  734. */
  735. int vconf_notify_key_changed(const char *in_key, vconf_callback_fn cb,
  736. void *user_data);
  737. /**
  738. * This function removes a change callback for given key,
  739. * which was added by vconf_notify_key_changed().
  740. * @param[in] in_key key
  741. * @param[in] cb callback function
  742. * @return 0 on success, -1 on error
  743. * @pre Nome
  744. * @post None
  745. * @remarks None
  746. * @see vconf_notify_key_changed()
  747. */
  748. int vconf_ignore_key_changed(const char *in_key, vconf_callback_fn cb);
  749. #ifdef __cplusplus
  750. }
  751. #endif
  752. /**
  753. * @} @}
  754. */
  755. #endif /* __VCONF_H__ */