Xenomai  3.0.5
registry.h
1 /*
2  * Copyright (C) 2004 Philippe Gerum <rpm@xenomai.org>
3  *
4  * Xenomai is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation; either version 2 of the
7  * License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17  */
18 #ifndef _COBALT_KERNEL_REGISTRY_H
19 #define _COBALT_KERNEL_REGISTRY_H
20 
21 #include <cobalt/kernel/list.h>
22 #include <cobalt/kernel/synch.h>
23 #include <cobalt/kernel/vfile.h>
24 
30 struct xnpnode;
31 
32 struct xnobject {
33  void *objaddr;
34  const char *key; /* !< Hash key. May be NULL if anonynous. */
35  unsigned long cstamp; /* !< Creation stamp. */
36 #ifdef CONFIG_XENO_OPT_VFILE
37  struct xnpnode *pnode; /* !< v-file information class. */
38  union {
39  struct {
40  struct xnvfile_rev_tag tag;
41  struct xnvfile_snapshot file;
42  } vfsnap; /* !< virtual snapshot file. */
43  struct xnvfile_regular vfreg; /* !< virtual regular file */
44  struct xnvfile_link link; /* !< virtual link. */
45  } vfile_u;
46  struct xnvfile *vfilp;
47 #endif /* CONFIG_XENO_OPT_VFILE */
48  struct hlist_node hlink; /* !< Link in h-table */
49  struct list_head link;
50 };
51 
52 int xnregistry_init(void);
53 
54 void xnregistry_cleanup(void);
55 
56 #ifdef CONFIG_XENO_OPT_VFILE
57 
58 #define XNOBJECT_PNODE_RESERVED1 ((struct xnvfile *)1)
59 #define XNOBJECT_PNODE_RESERVED2 ((struct xnvfile *)2)
60 
61 struct xnptree {
62  const char *dirname;
63  /* hidden */
64  int entries;
65  struct xnvfile_directory vdir;
66 };
67 
68 #define DEFINE_XNPTREE(__var, __name) \
69  struct xnptree __var = { \
70  .dirname = __name, \
71  .entries = 0, \
72  .vdir = xnvfile_nodir, \
73  }
74 
75 struct xnpnode_ops {
76  int (*export)(struct xnobject *object, struct xnpnode *pnode);
77  void (*unexport)(struct xnobject *object, struct xnpnode *pnode);
78  void (*touch)(struct xnobject *object);
79 };
80 
81 struct xnpnode {
82  const char *dirname;
83  struct xnptree *root;
84  struct xnpnode_ops *ops;
85  /* hidden */
86  int entries;
87  struct xnvfile_directory vdir;
88 };
89 
90 struct xnpnode_snapshot {
91  struct xnpnode node;
92  struct xnvfile_snapshot_template vfile;
93 };
94 
95 struct xnpnode_regular {
96  struct xnpnode node;
97  struct xnvfile_regular_template vfile;
98 };
99 
100 struct xnpnode_link {
101  struct xnpnode node;
102  char *(*target)(void *obj);
103 };
104 
105 #else /* !CONFIG_XENO_OPT_VFILE */
106 
107 #define DEFINE_XNPTREE(__var, __name);
108 
109 /* Placeholders. */
110 
111 struct xnpnode {
112  const char *dirname;
113 };
114 
115 struct xnpnode_snapshot {
116  struct xnpnode node;
117 };
118 
119 struct xnpnode_regular {
120  struct xnpnode node;
121 };
122 
123 struct xnpnode_link {
124  struct xnpnode node;
125 };
126 
127 #endif /* !CONFIG_XENO_OPT_VFILE */
128 
129 /* Public interface. */
130 
131 extern struct xnobject *registry_obj_slots;
132 
133 static inline struct xnobject *xnregistry_validate(xnhandle_t handle)
134 {
135  struct xnobject *object;
136  /*
137  * Careful: a removed object which is still in flight to be
138  * unexported carries a NULL objaddr, so we have to check this
139  * as well.
140  */
141  handle = xnhandle_get_index(handle);
142  if (likely(handle && handle < CONFIG_XENO_OPT_REGISTRY_NRSLOTS)) {
143  object = &registry_obj_slots[handle];
144  return object->objaddr ? object : NULL;
145  }
146 
147  return NULL;
148 }
149 
150 static inline const char *xnregistry_key(xnhandle_t handle)
151 {
152  struct xnobject *object = xnregistry_validate(handle);
153  return object ? object->key : NULL;
154 }
155 
156 int xnregistry_enter(const char *key,
157  void *objaddr,
158  xnhandle_t *phandle,
159  struct xnpnode *pnode);
160 
161 static inline int
162 xnregistry_enter_anon(void *objaddr, xnhandle_t *phandle)
163 {
164  return xnregistry_enter(NULL, objaddr, phandle, NULL);
165 }
166 
167 int xnregistry_bind(const char *key,
168  xnticks_t timeout,
169  int timeout_mode,
170  xnhandle_t *phandle);
171 
172 int xnregistry_remove(xnhandle_t handle);
173 
174 static inline
175 void *xnregistry_lookup(xnhandle_t handle,
176  unsigned long *cstamp_r)
177 {
178  struct xnobject *object = xnregistry_validate(handle);
179 
180  if (object == NULL)
181  return NULL;
182 
183  if (cstamp_r)
184  *cstamp_r = object->cstamp;
185 
186  return object->objaddr;
187 }
188 
189 int xnregistry_unlink(const char *key);
190 
191 unsigned xnregistry_hash_size(void);
192 
193 extern struct xnpnode_ops xnregistry_vfsnap_ops;
194 
195 extern struct xnpnode_ops xnregistry_vlink_ops;
196 
199 #endif /* !_COBALT_KERNEL_REGISTRY_H */
int xnregistry_bind(const char *key, xnticks_t timeout, int timeout_mode, xnhandle_t *phandle)
Bind to a real-time object.
Definition: registry.c:748
Snapshot revision tag.
Definition: vfile.h:482
int xnregistry_enter(const char *key, void *objaddr, xnhandle_t *phandle, struct xnpnode *pnode)
Register a real-time object.
Definition: registry.c:630
int xnregistry_remove(xnhandle_t handle)
Forcibly unregister a real-time object.
Definition: registry.c:818
int xnregistry_unlink(const char *key)
Turn a named object into an anonymous object.
Definition: registry.c:869
static void * xnregistry_lookup(xnhandle_t handle, unsigned long *cstamp_r)
Find a real-time object into the registry.
Definition: registry.h:175
Snapshot vfile descriptor.
Definition: vfile.h:506