summaryrefslogtreecommitdiff
path: root/metadata/metatree.h
blob: 325e6fe9c5c2a15e495f2d7c5c3ab13a415b6934 (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
71
72
73
74
75
76
77
78
79
80
#include <glib.h>

typedef struct _MetaTree MetaTree;
typedef struct _MetaLookupCache MetaLookupCache;

typedef enum {
  META_KEY_TYPE_NONE,
  META_KEY_TYPE_STRING,
  META_KEY_TYPE_STRINGV
} MetaKeyType;

/* Note: These are called with the read-lock held, so
   don't call any MetaTree operations */
typedef gboolean (*meta_tree_dir_enumerate_callback) (const char *entry,
						      guint64 last_changed,
						      gboolean has_children,
						      gboolean has_data,
						      gpointer user_data);

typedef gboolean (*meta_tree_keys_enumerate_callback) (const char *key,
						       MetaKeyType type,
						       gpointer value,
						       gpointer user_data);

/* MetaLookupCache is not threadsafe */
MetaLookupCache *meta_lookup_cache_new         (void);
void             meta_lookup_cache_free        (MetaLookupCache *cache);
MetaTree        *meta_lookup_cache_lookup_path (MetaLookupCache *cache,
						const char *filename,
						guint64 device,
						gboolean for_write,
						char **tree_path);

/* All public MetaTree calls are threadsafe */
MetaTree *  meta_tree_open           (const char *filename,
				      gboolean    for_write);
MetaTree *  meta_tree_lookup_by_name (const char *name,
				      gboolean    for_write);
MetaTree *  meta_tree_ref            (MetaTree   *tree);
void        meta_tree_unref          (MetaTree   *tree);
void        meta_tree_refresh        (MetaTree   *tree);
const char *meta_tree_get_filename   (MetaTree   *tree);
gboolean    meta_tree_exists         (MetaTree   *tree);

MetaKeyType meta_tree_lookup_key_type  (MetaTree                         *tree,
					const char                       *path,
					const char                       *key);
guint64     meta_tree_get_last_changed (MetaTree                         *tree,
					const char                       *path);
char *      meta_tree_lookup_string    (MetaTree                         *tree,
					const char                       *path,
					const char                       *key);
char **     meta_tree_lookup_stringv   (MetaTree                         *tree,
					const char                       *path,
					const char                       *key);
void        meta_tree_enumerate_dir    (MetaTree                         *tree,
					const char                       *path,
					meta_tree_dir_enumerate_callback  callback,
					gpointer                          user_data);
void        meta_tree_enumerate_keys   (MetaTree                         *tree,
					const char                       *path,
					meta_tree_keys_enumerate_callback callback,
					gpointer                          user_data);
gboolean    meta_tree_flush            (MetaTree                         *tree);
gboolean    meta_tree_unset            (MetaTree                         *tree,
					const char                       *path,
					const char                       *key);
gboolean    meta_tree_set_string       (MetaTree                         *tree,
					const char                       *path,
					const char                       *key,
					const char                       *value);
gboolean    meta_tree_set_stringv      (MetaTree                         *tree,
					const char                       *path,
					const char                       *key,
					char                            **value);
gboolean    meta_tree_remove           (MetaTree                         *tree,
					const char                       *path);
gboolean    meta_tree_copy             (MetaTree                         *tree,
					const char                       *src,
					const char                       *dest);