Debian Codegraph @

common/registry.h

raw
1 /*
2 * IPFlow Collector
3 * Copyright (c) 2003 Christophe Fillot.
4 * E-mail: [email protected]
5 *
6 * registry.h: Object Registry.
7 */
8
9 #ifndef __REGISTRY_H__
10 #define __REGISTRY_H__ 1
11
12 static const char rcsid_registry[] = "$Id$";
13
14 #include <sys/types.h>
15 #include <sys/time.h>
16 #include <pthread.h>
17
18 #include "mempool.h"
19
20 #define REGISTRY_HT_NAME_ENTRIES 1024
21 #define REGISTRY_MAX_TYPES 256
22
23 /* Object types for Registry */
24 enum {
25 OBJ_TYPE_VM, /* Virtual machine */
26 OBJ_TYPE_NIO, /* Network IO descriptor */
27 OBJ_TYPE_NIO_BRIDGE, /* Network IO bridge */
28 OBJ_TYPE_FRSW, /* Frame-Relay switch */
29 OBJ_TYPE_ATMSW, /* ATM switch */
30 OBJ_TYPE_ATM_BRIDGE, /* ATM bridge */
31 OBJ_TYPE_ETHSW, /* Ethernet switch */
32 OBJ_TYPE_STORE, /* Hypervisor store */
33 };
34
35 /* Registry entry */
36 typedef struct registry_entry registry_entry_t;
37 struct registry_entry {
38 char *name;
39 void *data;
40 int object_type;
41 int ref_count;
42 registry_entry_t *hname_next,*hname_prev;
43 registry_entry_t *htype_next,*htype_prev;
44 };
45
46 /* Registry info */
47 typedef struct registry registry_t;
48 struct registry {
49 pthread_mutex_t lock;
50 mempool_t mp;
51 int ht_name_entries,ht_type_entries;
52 registry_entry_t *ht_names; /* Hash table for names */
53 registry_entry_t *ht_types; /* Hash table for types */
54 };
55
56 /* Registry "foreach" callback */
57 typedef void (*registry_foreach)(registry_entry_t *entry,void *opt_arg,
58 int *err);
59
60 /* Registry "exec" callback */
61 typedef int (*registry_exec)(void *data,void *opt_arg);
62
63 /* Initialize registry */
64 int registry_init(void);
65
66 /* Add a new entry to the registry */
67 int registry_add(char *name,int object_type,void *data);
68
69 /* Delete an entry from the registry */
70 int registry_delete(char *name,int object_type);
71
72 /* Rename an entry in the registry */
73 int registry_rename(char *name,char *newname,int object_type);
74
75 /* Find an entry (increment reference count) */
76 void *registry_find(char *name,int object_type);
77
78 /* Check if entry exists (does not change reference count) */
79 void *registry_exists(char *name,int object_type);
80
81 /* Release a reference of an entry (decrement the reference count) */
82 int registry_unref(char *name,int object_type);
83
84 /*
85 * Execute action on an object if its reference count is less or equal to
86 * the specified count.
87 */
88 int registry_exec_refcount(char *name,int object_type,int max_ref,int reg_del,
89 registry_exec obj_action,void *opt_arg);
90
91 /* Delete object if unused */
92 int registry_delete_if_unused(char *name,int object_type,
93 registry_exec obj_destructor,
94 void *opt_arg);
95
96 /* Execute a callback function for all objects of specified type */
97 int registry_foreach_type(int object_type,registry_foreach cb,
98 void *opt,int *err);
99
100 /* Delete all objects of the specified type */
101 int registry_delete_type(int object_type,registry_exec cb,void *opt);
102
103 /* Dump the registry */
104 void registry_dump(void);
105
106 #endif