Xenomai API  2.6.5
registry.h
Go to the documentation of this file.
1 
24 #ifndef _XENO_NUCLEUS_REGISTRY_H
25 #define _XENO_NUCLEUS_REGISTRY_H
26 
27 #include <nucleus/types.h>
28 
29 #define XNOBJECT_SELF XN_NO_HANDLE
30 
31 #if defined(__KERNEL__) || defined(__XENO_SIM__)
32 
33 #include <nucleus/synch.h>
34 #include <nucleus/vfile.h>
35 
36 struct xnpnode;
37 
38 typedef struct xnobject {
39  void *objaddr;
40  const char *key; /* !< Hash key. */
41  struct xnsynch safesynch; /* !< Safe synchronization object. */
42  u_long safelock; /* !< Safe lock count. */
43  u_long cstamp; /* !< Creation stamp. */
44 #ifdef CONFIG_XENO_OPT_VFILE
45  struct xnpnode *pnode; /* !< v-file information class. */
46  union {
47  struct {
48  struct xnvfile_rev_tag tag;
49  struct xnvfile_snapshot file;
50  } vfsnap; /* !< virtual snapshot file. */
51  struct xnvfile_regular vfreg; /* !< virtual regular file */
52  struct xnvfile_link link; /* !< virtual link. */
53  } vfile_u;
54  struct xnvfile *vfilp;
55 #endif /* CONFIG_XENO_OPT_VFILE */
56  struct xnobject *hnext; /* !< Next in h-table */
57  struct xnholder link;
58 } xnobject_t;
59 
60 #define link2xnobj(ln) container_of(ln, struct xnobject, link)
61 
62 #ifdef __cplusplus
63 extern "C" {
64 #endif
65 
66 int xnregistry_init(void);
67 
68 void xnregistry_cleanup(void);
69 
70 #ifdef CONFIG_XENO_OPT_VFILE
71 
72 #define XNOBJECT_PNODE_RESERVED1 ((struct xnvfile *)1)
73 #define XNOBJECT_PNODE_RESERVED2 ((struct xnvfile *)2)
74 
75 struct xnptree {
76  const char *dirname;
77  /* hidden */
78  int entries;
79  struct xnvfile_directory vdir;
80 };
81 
82 #define DEFINE_XNPTREE(__var, __name) \
83  struct xnptree __var = { \
84  .dirname = __name, \
85  .entries = 0, \
86  .vdir = xnvfile_nodir, \
87  }
88 
89 struct xnpnode_ops {
90  int (*export)(struct xnobject *object, struct xnpnode *pnode);
91  void (*unexport)(struct xnobject *object, struct xnpnode *pnode);
92  void (*touch)(struct xnobject *object);
93 };
94 
95 struct xnpnode {
96  const char *dirname;
97  struct xnptree *root;
98  struct xnpnode_ops *ops;
99  /* hidden */
100  int entries;
101  struct xnvfile_directory vdir;
102 };
103 
104 struct xnpnode_snapshot {
105  struct xnpnode node;
106  struct xnvfile_snapshot_template vfile;
107 };
108 
109 struct xnpnode_regular {
110  struct xnpnode node;
111  struct xnvfile_regular_template vfile;
112 };
113 
114 struct xnpnode_link {
115  struct xnpnode node;
116  char *(*target)(void *obj);
117 };
118 
119 #else /* !CONFIG_XENO_OPT_VFILE */
120 
121 #define DEFINE_XNPTREE(__var, __name);
122 
123 /* Placeholders. */
124 
125 struct xnpnode {
126  const char *dirname;
127 };
128 
129 struct xnpnode_snapshot {
130  struct xnpnode node;
131 };
132 
133 struct xnpnode_regular {
134  struct xnpnode node;
135 };
136 
137 struct xnpnode_link {
138  struct xnpnode node;
139 };
140 
141 #endif /* !CONFIG_XENO_OPT_VFILE */
142 
143 extern struct xnobject *registry_obj_slots;
144 
145 /* Public interface. */
146 
147 extern struct xnobject *registry_obj_slots;
148 
149 static inline struct xnobject *xnregistry_validate(xnhandle_t handle)
150 {
151  struct xnobject *object;
152  /*
153  * Careful: a removed object which is still in flight to be
154  * unexported carries a NULL objaddr, so we have to check this
155  * as well.
156  */
157  if (likely(handle && handle < CONFIG_XENO_OPT_REGISTRY_NRSLOTS)) {
158  object = &registry_obj_slots[handle];
159  return object->objaddr ? object : NULL;
160  }
161 
162  return NULL;
163 }
164 
165 static inline void *xnregistry_lookup(xnhandle_t handle)
166 {
167  struct xnobject *object = xnregistry_validate(handle);
168  return object ? object->objaddr : NULL;
169 }
170 
171 int xnregistry_enter(const char *key,
172  void *objaddr,
173  xnhandle_t *phandle,
174  struct xnpnode *pnode);
175 
176 int xnregistry_bind(const char *key,
177  xnticks_t timeout,
178  int timeout_mode,
179  xnhandle_t *phandle);
180 
181 int xnregistry_remove(xnhandle_t handle);
182 
183 int xnregistry_remove_safe(xnhandle_t handle,
184  xnticks_t timeout);
185 
186 void *xnregistry_get(xnhandle_t handle);
187 
188 void *xnregistry_fetch(xnhandle_t handle);
189 
190 u_long xnregistry_put(xnhandle_t handle);
191 
192 #ifdef __cplusplus
193 }
194 #endif
195 
196 extern struct xnpnode_ops xnregistry_vfsnap_ops;
197 
198 extern struct xnpnode_ops xnregistry_vlink_ops;
199 
200 #endif /* __KERNEL__ || __XENO_SIM__ */
201 
202 #endif /* !_XENO_NUCLEUS_REGISTRY_H */
This file is part of the Xenomai project.
int xnregistry_remove_safe(xnhandle_t handle, xnticks_t timeout)
Unregister an idle real-time object.
Definition: registry.c:989
Snapshot revision tag.
Definition: vfile.h:490
void * xnregistry_fetch(xnhandle_t handle)
Find a real-time object into the registry.
Definition: registry.c:1220
void * xnregistry_get(xnhandle_t handle)
Find and lock a real-time object into the registry.
Definition: registry.c:1098
u_long xnregistry_put(xnhandle_t handle)
Unlock a real-time object from the registry.
Definition: registry.c:1157
int xnregistry_enter(const char *key, void *objaddr, xnhandle_t *phandle, struct xnpnode *pnode)
Register a real-time object.
Definition: registry.c:657
int xnregistry_bind(const char *key, xnticks_t timeout, int timeout_mode, xnhandle_t *phandle)
Bind to a real-time object.
Definition: registry.c:798
int xnregistry_remove(xnhandle_t handle)
Forcibly unregister a real-time object.
Definition: registry.c:882
Snapshot vfile descriptor.
Definition: vfile.h:514