Xenomai  3.0.5
registry-obstack.h
1 /*
2  * Copyright (C) 2014 Philippe Gerum <rpm@xenomai.org>.
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library 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 GNU
12  * Lesser General Public License for more details.
13 
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
17  */
18 #ifndef _COPPERPLATE_REGISTRY_OBSTACK_H
19 #define _COPPERPLATE_REGISTRY_OBSTACK_H
20 
21 #include <copperplate/registry.h>
22 
23 #ifdef CONFIG_XENO_REGISTRY
24 
25 #include <boilerplate/obstack.h>
26 #include <copperplate/heapobj.h>
27 
28 struct threadobj;
29 struct syncobj;
30 
31 /*
32  * Assume we may want fast allocation of private memory from real-time
33  * mode when growing the obstack.
34  */
35 #define obstack_chunk_alloc pvmalloc
36 #define obstack_chunk_free pvfree
37 
38 struct threadobj;
39 
40 struct fsobstack {
41  struct obstack obstack;
42  void *data;
43  size_t len;
44 };
45 
46 struct fsobstack_syncops {
47  int (*prepare_cache)(struct fsobstack *o,
48  struct obstack *cache, int item_count);
49  size_t (*collect_data)(void *p, struct threadobj *thobj);
50  size_t (*format_data)(struct fsobstack *o, void *p);
51 };
52 
53 struct syncobj;
54 
55 #ifdef __cplusplus
56 extern "C" {
57 #endif
58 
59 void fsobstack_grow_string(struct fsobstack *o,
60  const char *s);
61 
62 void fsobstack_grow_char(struct fsobstack *o,
63  char c);
64 
65 int fsobstack_grow_format(struct fsobstack *o,
66  const char *fmt, ...);
67 
68 int fsobstack_grow_file(struct fsobstack *o,
69  const char *path);
70 
71 int fsobstack_grow_syncobj_grant(struct fsobstack *o,
72  struct syncobj *sobj,
73  struct fsobstack_syncops *ops);
74 
75 int fsobstack_grow_syncobj_drain(struct fsobstack *o,
76  struct syncobj *sobj,
77  struct fsobstack_syncops *ops);
78 
79 ssize_t fsobstack_pull(struct fsobstack *o,
80  char *buf, size_t size);
81 
82 ssize_t fsobj_obstack_read(struct fsobj *fsobj,
83  char *buf, size_t size, off_t offset,
84  void *priv);
85 
86 int fsobj_obstack_release(struct fsobj *fsobj, void *priv);
87 
88 #ifdef __cplusplus
89 }
90 #endif
91 
92 static inline void fsobstack_init(struct fsobstack *o)
93 {
94  obstack_init(&o->obstack);
95  o->data = NULL;
96  o->len = 0;
97 }
98 
99 static inline void fsobstack_destroy(struct fsobstack *o)
100 {
101  obstack_free(&o->obstack, NULL);
102 }
103 
104 static inline void fsobstack_finish(struct fsobstack *o)
105 {
106  o->len = obstack_object_size(&o->obstack);
107  o->data = obstack_finish(&o->obstack);
108 }
109 
110 static inline
111 void registry_init_file_obstack(struct fsobj *fsobj,
112  const struct registry_operations *ops)
113 {
114  registry_init_file(fsobj, ops, sizeof(struct fsobstack));
115 }
116 
117 #else /* !CONFIG_XENO_REGISTRY */
118 
119 static inline
120 void registry_init_file_obstack(struct fsobj *fsobj,
121  const struct registry_operations *ops)
122 { }
123 
124 #endif /* !CONFIG_XENO_REGISTRY */
125 
126 #endif /* !_COPPERPLATE_REGISTRY_OBSTACK_H */