Xenomai  3.1
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_EXPORT_SCHEDULED ((struct xnvfile *)1L)
59 #define XNOBJECT_EXPORT_INPROGRESS ((struct xnvfile *)2L)
60 #define XNOBJECT_EXPORT_ABORTED ((struct xnvfile *)3L)
61 
62 struct xnptree {
63  const char *dirname;
64  /* hidden */
65  int entries;
66  struct xnvfile_directory vdir;
67 };
68 
69 #define DEFINE_XNPTREE(__var, __name) \
70  struct xnptree __var = { \
71  .dirname = __name, \
72  .entries = 0, \
73  .vdir = xnvfile_nodir, \
74  }
75 
76 struct xnpnode_ops {
77  int (*export)(struct xnobject *object, struct xnpnode *pnode);
78  void (*unexport)(struct xnobject *object, struct xnpnode *pnode);
79  void (*touch)(struct xnobject *object);
80 };
81 
82 struct xnpnode {
83  const char *dirname;
84  struct xnptree *root;
85  struct xnpnode_ops *ops;
86  /* hidden */
87  int entries;
88  struct xnvfile_directory vdir;
89 };
90 
91 struct xnpnode_snapshot {
92  struct xnpnode node;
93  struct xnvfile_snapshot_template vfile;
94 };
95 
96 struct xnpnode_regular {
97  struct xnpnode node;
98  struct xnvfile_regular_template vfile;
99 };
100 
101 struct xnpnode_link {
102  struct xnpnode node;
103  char *(*target)(void *obj);
104 };
105 
106 #else /* !CONFIG_XENO_OPT_VFILE */
107 
108 #define DEFINE_XNPTREE(__var, __name);
109 
110 /* Placeholders. */
111 
112 struct xnpnode {
113  const char *dirname;
114 };
115 
116 struct xnpnode_snapshot {
117  struct xnpnode node;
118 };
119 
120 struct xnpnode_regular {
121  struct xnpnode node;
122 };
123 
124 struct xnpnode_link {
125  struct xnpnode node;
126 };
127 
128 #endif /* !CONFIG_XENO_OPT_VFILE */
129 
130 /* Public interface. */
131 
132 extern struct xnobject *registry_obj_slots;
133 
134 static inline struct xnobject *xnregistry_validate(xnhandle_t handle)
135 {
136  struct xnobject *object;
137  /*
138  * Careful: a removed object which is still in flight to be
139  * unexported carries a NULL objaddr, so we have to check this
140  * as well.
141  */
142  handle = xnhandle_get_index(handle);
143  if (likely(handle && handle < CONFIG_XENO_OPT_REGISTRY_NRSLOTS)) {
144  object = &registry_obj_slots[handle];
145  return object->objaddr ? object : NULL;
146  }
147 
148  return NULL;
149 }
150 
151 static inline const char *xnregistry_key(xnhandle_t handle)
152 {
153  struct xnobject *object = xnregistry_validate(handle);
154  return object ? object->key : NULL;
155 }
156 
157 int xnregistry_enter(const char *key,
158  void *objaddr,
159  xnhandle_t *phandle,
160  struct xnpnode *pnode);
161 
162 static inline int
163 xnregistry_enter_anon(void *objaddr, xnhandle_t *phandle)
164 {
165  return xnregistry_enter(NULL, objaddr, phandle, NULL);
166 }
167 
168 int xnregistry_bind(const char *key,
169  xnticks_t timeout,
170  int timeout_mode,
171  xnhandle_t *phandle);
172 
173 int xnregistry_remove(xnhandle_t handle);
174 
175 static inline
176 void *xnregistry_lookup(xnhandle_t handle,
177  unsigned long *cstamp_r)
178 {
179  struct xnobject *object = xnregistry_validate(handle);
180 
181  if (object == NULL)
182  return NULL;
183 
184  if (cstamp_r)
185  *cstamp_r = object->cstamp;
186 
187  return object->objaddr;
188 }
189 
190 int xnregistry_unlink(const char *key);
191 
192 unsigned xnregistry_hash_size(void);
193 
194 extern struct xnpnode_ops xnregistry_vfsnap_ops;
195 
196 extern struct xnpnode_ops xnregistry_vlink_ops;
197 
200 #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:751
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:632
int xnregistry_remove(xnhandle_t handle)
Forcibly unregister a real-time object.
Definition: registry.c:822
int xnregistry_unlink(const char *key)
Turn a named object into an anonymous object
Definition: registry.c:887
static void * xnregistry_lookup(xnhandle_t handle, unsigned long *cstamp_r)
Find a real-time object into the registry.
Definition: registry.h:176
Snapshot vfile descriptor.
Definition: vfile.h:506