/services/fconf/fconf.h

http://ftk.googlecode.com/ · C Header · 152 lines · 85 code · 30 blank · 37 comment · 28 complexity · 4420b3a23f874a5634855e2ce8241433 MD5 · raw file

  1. /*
  2. * File: fconf.h
  3. * Author: Li XianJing <xianjimli@hotmail.com>
  4. * Brief: config interface
  5. *
  6. * Copyright (c) 2009 - 2010 Li XianJing <xianjimli@hotmail.com>
  7. *
  8. * Licensed under the Academic Free License version 2.1
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  23. */
  24. /*
  25. * History:
  26. * ================================================================
  27. * 2010-08-01 Li XianJing <xianjimli@hotmail.com> created
  28. *
  29. */
  30. #ifndef FCONF_H
  31. #define FCONF_H
  32. #include "fbus_typedef.h"
  33. FTK_BEGIN_DECLS
  34. struct _FConf;
  35. typedef struct _FConf FConf;
  36. typedef enum _FConfChangeType
  37. {
  38. FCONF_CHANGED_BY_SET = 0x74657300,
  39. FCONF_CHANGED_BY_ADD,
  40. FCONF_CHANGED_BY_REMOVE
  41. }FConfChangeType;
  42. typedef Ret(*FConfOnChanged)(void* ctx, int changed_by_self, FConfChangeType type, const char* xpath, const char* value);
  43. /**
  44. * xpath: root path is the filename(remove the dir and ext name), the sub path are the nodes name in xml.
  45. * for example:
  46. * globals.xml contains:
  47. * <service_manager><port value=\"1978\" /></service_manager>
  48. * The value of xpath /globals/service_manager/port are 1978.
  49. *
  50. */
  51. typedef Ret (*FConfLock)(FConf* thiz);
  52. typedef Ret (*FConfUnlock)(FConf* thiz);
  53. typedef Ret (*FConfRemove)(FConf* thiz, const char* xpath);
  54. typedef Ret (*FConfSet)(FConf* thiz, const char* xpath, const char* value);
  55. typedef Ret (*FConfGet)(FConf* thiz, const char* xpath, char** value);
  56. typedef Ret (*FConfGetChildCount)(FConf* thiz, const char* xpath, int* count);
  57. typedef Ret (*FConfGetChild)(FConf* thiz, const char* xpath, int index, char** child);
  58. typedef Ret (*FConfRegChangedNotify)(FConf* thiz, FConfOnChanged on_changed, void* ctx);
  59. typedef void (*FConfDestroy)(FConf* thiz);
  60. struct _FConf
  61. {
  62. FConfLock lock;
  63. FConfUnlock unlock;
  64. FConfSet set;
  65. FConfGet get;
  66. FConfRemove remove;
  67. FConfGetChild get_child;
  68. FConfGetChildCount get_child_count;
  69. FConfRegChangedNotify reg_changed_notify;
  70. FConfDestroy destroy;
  71. char priv[1];
  72. };
  73. static inline Ret fconf_lock(FConf* thiz)
  74. {
  75. return_val_if_fail(thiz != NULL && thiz->lock != NULL, RET_FAIL);
  76. return thiz->lock(thiz);
  77. }
  78. static inline Ret fconf_unlock(FConf* thiz)
  79. {
  80. return_val_if_fail(thiz != NULL && thiz->unlock != NULL, RET_FAIL);
  81. return thiz->unlock(thiz);
  82. }
  83. static inline Ret fconf_remove(FConf* thiz, const char* xpath)
  84. {
  85. return_val_if_fail(thiz != NULL && thiz->remove != NULL, RET_FAIL);
  86. return thiz->remove(thiz, xpath);
  87. }
  88. static inline Ret fconf_set(FConf* thiz, const char* xpath, const char* value)
  89. {
  90. return_val_if_fail(thiz != NULL && thiz->set != NULL, RET_FAIL);
  91. return thiz->set(thiz, xpath, value);
  92. }
  93. static inline Ret fconf_get(FConf* thiz, const char* xpath, char** value)
  94. {
  95. return_val_if_fail(thiz != NULL && thiz->get != NULL, RET_FAIL);
  96. return thiz->get(thiz, xpath, value);
  97. }
  98. static inline Ret fconf_get_child_count(FConf* thiz, const char* xpath, int* count)
  99. {
  100. return_val_if_fail(thiz != NULL && thiz->get_child_count != NULL, RET_FAIL);
  101. return thiz->get_child_count(thiz, xpath, count);
  102. }
  103. static inline Ret fconf_get_child(FConf* thiz, const char* xpath, int index, char** child)
  104. {
  105. return_val_if_fail(thiz != NULL && thiz->get_child != NULL, RET_FAIL);
  106. return thiz->get_child(thiz, xpath, index, child);
  107. }
  108. static inline Ret fconf_reg_changed_notify(FConf* thiz, FConfOnChanged on_changed, void* ctx)
  109. {
  110. return_val_if_fail(thiz != NULL && thiz->reg_changed_notify != NULL, RET_FAIL);
  111. return thiz->reg_changed_notify(thiz, on_changed, ctx);
  112. }
  113. static inline void fconf_destroy(FConf* thiz)
  114. {
  115. if(thiz != NULL && thiz->destroy != NULL)
  116. {
  117. thiz->destroy(thiz);
  118. }
  119. return;
  120. }
  121. FTK_END_DECLS
  122. #endif/*FCONF_H*/