aboutsummaryrefslogtreecommitdiffstats
path: root/dict/pdict.h
blob: bdd8065b81bb21b33b5d875a2356d1004460ed4e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#ifndef _PDICT_H_
#define _PDICT_H_

typedef enum {
	PDR_VALUE_CHANGED = 1,
	PDR_ENTRY_ADDED,
	PDR_ENTRY_REMOVING,
	PDR_CURRENT_VALUE
}  pdict_reason_t;

/* The _t stands for typedef? */
typedef struct pdict pdict_t;

typedef void (*pdl_notify_func_t)(const char *k, 
								  const char *v,
								  pdict_reason_t r, 
								  const char *pde_oldval, 
								  void *arg);

typedef int (*pdict_walk_func_t)(const char *k, 
								 const char *v, 
								 void *arg);

pdict_t *pdict_alloc(void);

int pdict_add(pdict_t *pd, 
			  const char *k, 
			  const char *v, 
			  const char **ovp);

int pdict_add_persistent_change_listener(pdict_t *pd, 
										 const char *kpat,
										 pdl_notify_func_t, 
										 void *);

int pdict_walk(pdict_t *pd, 
			   pdict_walk_func_t, 
			   void *arg);

/*
 * Return whether a given key is in the dictionary.  If v is set, it
 * will be set to point to a copy of the value, which must be freed by
 * the caller.
 */
int pdict_ent_lookup(pdict_t *pd, 
					 const char *k, 
					 const char **v);

int pdict_ent_add_change_listener(pdict_t *pd, 
								  const char *k,
								  pdl_notify_func_t, 
								  void *);

int pdict_ent_remove_change_listener(pdict_t *pd, 
									 const char *k,
									 pdl_notify_func_t, 
									 void *);

int pdict_remove_persistent_change_listener(pdict_t *pd, 
											int id);

int pdict_ent_remove(pdict_t *pd, 
					 const char *k, 
					 char **ovp);

const char *pdict_reason_str(pdict_reason_t);

pdict_reason_t pdict_reason_from_str(const char *);

#endif