PageRenderTime 380ms CodeModel.GetById 207ms app.highlight 11ms RepoModel.GetById 160ms app.codeStats 0ms

/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/*
 26 * History:
 27 * ================================================================
 28 * 2010-08-01 Li XianJing <xianjimli@hotmail.com> created
 29 *
 30 */
 31
 32#ifndef FCONF_H
 33#define FCONF_H
 34
 35#include "fbus_typedef.h"
 36
 37FTK_BEGIN_DECLS
 38
 39struct _FConf;
 40typedef struct _FConf FConf;
 41
 42typedef enum _FConfChangeType
 43{
 44	FCONF_CHANGED_BY_SET = 0x74657300,
 45	FCONF_CHANGED_BY_ADD,
 46	FCONF_CHANGED_BY_REMOVE
 47}FConfChangeType;
 48
 49typedef Ret(*FConfOnChanged)(void* ctx, int changed_by_self, FConfChangeType type, const char* xpath, const char* value);
 50
 51/**
 52 * xpath: root path is the filename(remove the dir and ext name), the sub path are the nodes name in xml.
 53 * for example:
 54 * globals.xml contains:
 55 * <service_manager><port value=\"1978\" /></service_manager>
 56 * The value of xpath /globals/service_manager/port are 1978.
 57 *
 58 */
 59typedef Ret  (*FConfLock)(FConf* thiz);
 60typedef Ret  (*FConfUnlock)(FConf* thiz);
 61typedef Ret  (*FConfRemove)(FConf* thiz, const char* xpath);
 62typedef Ret  (*FConfSet)(FConf* thiz, const char* xpath, const char* value);
 63typedef Ret  (*FConfGet)(FConf* thiz, const char* xpath, char** value);
 64typedef Ret  (*FConfGetChildCount)(FConf* thiz, const char* xpath, int* count);
 65typedef Ret  (*FConfGetChild)(FConf* thiz, const char* xpath, int index, char** child);
 66typedef Ret  (*FConfRegChangedNotify)(FConf* thiz, FConfOnChanged on_changed, void* ctx);
 67typedef void (*FConfDestroy)(FConf* thiz);
 68
 69struct _FConf
 70{
 71	FConfLock lock;
 72	FConfUnlock unlock;
 73	FConfSet set;
 74	FConfGet get;
 75	FConfRemove remove;
 76	FConfGetChild get_child;
 77	FConfGetChildCount get_child_count;
 78	FConfRegChangedNotify reg_changed_notify;
 79	FConfDestroy destroy;
 80
 81	char priv[1];
 82};
 83
 84static inline Ret fconf_lock(FConf* thiz)
 85{
 86	return_val_if_fail(thiz != NULL && thiz->lock != NULL, RET_FAIL);
 87
 88	return thiz->lock(thiz);
 89}
 90
 91static inline Ret fconf_unlock(FConf* thiz)
 92{
 93	return_val_if_fail(thiz != NULL && thiz->unlock != NULL, RET_FAIL);
 94
 95	return thiz->unlock(thiz);
 96}
 97
 98static inline Ret fconf_remove(FConf* thiz, const char* xpath)
 99{
100	return_val_if_fail(thiz != NULL && thiz->remove != NULL, RET_FAIL);
101
102	return thiz->remove(thiz, xpath);
103}
104
105static inline Ret fconf_set(FConf* thiz, const char* xpath, const char* value)
106{
107	return_val_if_fail(thiz != NULL && thiz->set != NULL, RET_FAIL);
108
109	return thiz->set(thiz, xpath, value);
110}
111
112static inline Ret fconf_get(FConf* thiz, const char* xpath, char** value)
113{
114	return_val_if_fail(thiz != NULL && thiz->get != NULL, RET_FAIL);
115
116	return thiz->get(thiz, xpath, value);
117}
118
119static inline Ret fconf_get_child_count(FConf* thiz, const char* xpath, int* count)
120{
121	return_val_if_fail(thiz != NULL && thiz->get_child_count != NULL, RET_FAIL);
122
123	return thiz->get_child_count(thiz, xpath, count);
124}
125
126static inline Ret fconf_get_child(FConf* thiz, const char* xpath, int index, char** child)
127{
128	return_val_if_fail(thiz != NULL && thiz->get_child != NULL, RET_FAIL);
129
130	return thiz->get_child(thiz, xpath, index, child);
131}
132
133static inline Ret fconf_reg_changed_notify(FConf* thiz, FConfOnChanged on_changed, void* ctx)
134{
135	return_val_if_fail(thiz != NULL && thiz->reg_changed_notify != NULL, RET_FAIL);
136
137	return thiz->reg_changed_notify(thiz, on_changed, ctx);
138}
139
140static inline void fconf_destroy(FConf* thiz)
141{
142	if(thiz != NULL && thiz->destroy != NULL)
143	{
144		thiz->destroy(thiz);
145	}
146
147	return;
148}
149
150FTK_END_DECLS
151
152#endif/*FCONF_H*/