Xenomai API  2.6.5
registry.h
1 #ifndef PSE51_REGISTRY_H
2 #define PSE51_REGISTRY_H
3 
4 #include <stdarg.h>
5 #include <nucleus/queue.h>
6 #include <nucleus/synch.h>
7 #include <posix/posix.h>
8 
9 #define PSE51_MAXNAME 64
10 
11 /* A pse51_node_t is the holder to be added to each object which needs to be put
12  in the registry. */
13 typedef struct pse51_node {
14  unsigned magic;
15  unsigned flags; /* PSE51_NODE_PARTIAL_INIT. */
16  unsigned refcount;
17  /* pse51_unlink_t *dest_hook; */
18 
19  struct pse51_node *next;
20  struct pse51_node **prev;
21  char name[PSE51_MAXNAME];
22 } pse51_node_t;
23 
24 int pse51_reg_pkg_init(unsigned objects_count, unsigned maxfds);
25 
26 void pse51_reg_pkg_cleanup(void);
27 
28 /* Get an existing node: oflags are POSIX open style flags.
29  If 0 is returned and (*nodep) is NULL, then a new node should be added
30  with node_add. */
31 int pse51_node_get(pse51_node_t **nodep,
32  const char *name,
33  unsigned long magic,
34  long oflags);
35 
36 /* bind a node. */
37 int pse51_node_add(pse51_node_t *node, const char *name, unsigned magic);
38 
39 /* Any successful call to node_get or node_add need to be paired with a call
40  node_put before a node may be unlinked. */
41 int pse51_node_put(pse51_node_t *node);
42 
43 /* Remove the binding of a node to its name, if the node is still referenced,
44  real destruction is deferred until the last call to node_put. */
45 int pse51_node_remove(pse51_node_t **nodep, const char *name, unsigned magic);
46 
47 #define PSE51_NODE_REMOVED 1
48 
49 #define pse51_node_ref_p(node) ((node)->refcount)
50 
51 #define pse51_node_removed_p(node) \
52  ((node)->flags & PSE51_NODE_REMOVED && !pse51_node_ref_p(node))
53 
54 /* A pse51_desc_t is the structure associated with a descriptor. */
55 typedef struct pse51_desc {
56  pse51_node_t *node;
57  long flags;
58  int fd;
59 } pse51_desc_t;
60 
61 int pse51_desc_create(pse51_desc_t **descp, pse51_node_t *node, long flags);
62 
63 int pse51_desc_get(pse51_desc_t **descp, int fd, unsigned magic);
64 
65 int pse51_desc_destroy(pse51_desc_t *desc);
66 
67 #define pse51_desc_setflags(desc, fl) ((desc)->flags = (fl))
68 
69 #define pse51_desc_getflags(desc) ((desc)->flags)
70 
71 #define pse51_desc_node(desc) ((desc)->node)
72 
73 #define pse51_desc_fd(desc) ((desc)->fd)
74 
75 #define PSE51_PERMS_MASK (O_RDONLY | O_WRONLY | O_RDWR)
76 
77 
78 /* Associative lists, used for association of user-space to kernel-space
79  objects. */
80 #ifdef CONFIG_XENO_OPT_PERVASIVE
81 struct mm_struct;
82 
83 DECLARE_EXTERN_XNLOCK(pse51_assoc_lock);
84 
85 typedef xnqueue_t pse51_assocq_t;
86 
87 typedef struct {
88  u_long key;
89  xnholder_t link;
90 
91 #define link2assoc(laddr) \
92  ((pse51_assoc_t *)((unsigned long)(laddr) - offsetof(pse51_assoc_t, link)))
93 
94 } pse51_assoc_t;
95 
96 typedef struct {
97  unsigned long kfd;
98  pse51_assoc_t assoc;
99 
100 #define assoc2ufd(laddr) \
101  ((pse51_ufd_t *)((unsigned long) (laddr) - offsetof(pse51_ufd_t, assoc)))
102 } pse51_ufd_t;
103 
104 #define pse51_assocq_init(q) (initq(q))
105 
106 #define pse51_assoc_key(assoc) ((assoc)->key)
107 
108 void pse51_assocq_destroy(pse51_assocq_t *q, void (*destroy)(pse51_assoc_t *));
109 
110 int pse51_assoc_insert(pse51_assocq_t *q,
111  pse51_assoc_t *assoc,
112  u_long key);
113 
114 pse51_assoc_t *pse51_assoc_lookup(pse51_assocq_t *q,
115  u_long key);
116 
117 pse51_assoc_t *pse51_assoc_remove(pse51_assocq_t *q,
118  u_long key);
119 #endif /* CONFIG_XENO_OPT_PERVASIVE */
120 
121 #endif /* PSE51_REGISTRY_H */