/[dynamips]/upstream/dynamips-0.2.6-RC2/registry.h
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /upstream/dynamips-0.2.6-RC2/registry.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3 - (hide annotations)
Sat Oct 6 16:05:34 2007 UTC (16 years, 5 months ago) by dpavlin
File MIME type: text/plain
File size: 2963 byte(s)
dynamips-0.2.6-RC2

1 dpavlin 1 /*
2     * IPFlow Collector
3     * Copyright (c) 2003 Christophe Fillot.
4     * E-mail: cf@utc.fr
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_ETHSW, /* Ethernet switch */
31     };
32    
33     /* Registry entry */
34     typedef struct registry_entry registry_entry_t;
35     struct registry_entry {
36     char *name;
37     void *data;
38     int object_type;
39     int ref_count;
40     registry_entry_t *hname_next,*hname_prev;
41     registry_entry_t *htype_next,*htype_prev;
42     };
43    
44     /* Registry info */
45     typedef struct registry registry_t;
46     struct registry {
47     pthread_mutex_t lock;
48     mempool_t mp;
49     int ht_name_entries,ht_type_entries;
50     registry_entry_t *ht_names; /* Hash table for names */
51     registry_entry_t *ht_types; /* Hash table for types */
52     };
53    
54     /* Registry "foreach" callback */
55     typedef void (*registry_foreach)(registry_entry_t *entry,void *opt_arg,
56     int *err);
57    
58     /* Registry "exec" callback */
59     typedef int (*registry_exec)(void *data,void *opt_arg);
60    
61     /* Initialize registry */
62     int registry_init(void);
63    
64     /* Remove a registry entry */
65     void registry_remove_entry(registry_entry_t *entry);
66    
67     /* Add a new entry to the registry */
68     int registry_add(char *name,int object_type,void *data);
69    
70     /* Delete an entry from the registry */
71     int registry_delete(char *name,int object_type);
72    
73     /* Find an entry (increment reference count) */
74     void *registry_find(char *name,int object_type);
75    
76     /* Check if entry exists (does not change reference count) */
77     void *registry_exists(char *name,int object_type);
78    
79     /* Release a reference of an entry (decrement the reference count) */
80     int registry_unref(char *name,int object_type);
81    
82     /*
83     * Execute action on an object if its reference count is less or equal to
84     * the specified count.
85     */
86     int registry_exec_refcount(char *name,int object_type,int max_ref,int reg_del,
87     registry_exec obj_action,void *opt_arg);
88    
89     /* Delete object if unused */
90     int registry_delete_if_unused(char *name,int object_type,
91     registry_exec obj_destructor,
92     void *opt_arg);
93    
94     /* Execute a callback function for all objects of specified type */
95     int registry_foreach_type(int object_type,registry_foreach cb,
96     void *opt,int *err);
97    
98     /* Delete all objects of the specified type */
99     int registry_delete_type(int object_type,registry_exec cb,void *opt);
100    
101     /* Dump the registry */
102     void registry_dump(void);
103    
104     #endif

  ViewVC Help
Powered by ViewVC 1.1.26