1 /* buffers.c:
2 *
3 ****************************************************************
4 * Copyright (C) 2004 Tom Lord
5 *
6 * See the file "COPYING" for further information about
7 * the copyright and warranty status of this work.
8 */
9
10
11 #include "hackerlab/dynid/dynid.h"
12 #include "hackerlab/buffers/buffer-set.h"
13 #include "hackerlab/buffers/buffers.h"
14
15
16 /* typedefs */
17
18 typedef struct buffer_set_entry t_buffer_set_entry;
19
20 struct buffer_set_entry
21 {
22 t_buffer_set set;
23 };
24
25 OBTABLE_STATIC_TABLE (buffer_set, t_buffer_set_entry);
26
27
28 /* __STDC__ prototypes for static functions */
29
30
31 /* declarations */
32
33
34 /* code */
35
36 ssize_t
buffer_session_open(alloc_limits const limits,ssize_t const representation_type_spec)37 buffer_session_open (alloc_limits const limits,
38 ssize_t const representation_type_spec)
39 {
40 ssize_t it_desc;
41 struct buffer_set_entry * it;
42 ssize_t representation_type;
43
44 it_desc = buffer_set_alloc_id ();
45 it = buffer_set_ref_id (it_desc);
46 if (!it)
47 return -1;
48
49
50 if (representation_type > 0)
51 {
52 representation_type = representation_type_spec;
53 }
54 else
55 {
56 representation_type = ensure_global_dynid ((void *)buffer_session_open);
57 if (representation_type <= 0)
58 return -1;
59 }
60
61 if (0 > init_buffer_set (&it->set, limits, representation_type))
62 return -1;
63
64 return it_desc;
65 }
66
67
68 int
buffer_session_close(alloc_limits const limits,ssize_t const id)69 buffer_session_close (alloc_limits const limits,
70 ssize_t const id)
71 {
72 struct buffer_set_entry * it;
73
74 it = buffer_set_ref_id (id);
75 if (!it)
76 return -1;
77
78 if (0 > uninit_buffer_set (&it->set))
79 return -1;
80
81 buffer_set_free_id (id);
82
83 return 0;
84 }
85
86
87
88
89 alloc_limits
buffer_session_limits(ssize_t const session)90 buffer_session_limits (ssize_t const session)
91 {
92 struct buffer_set_entry * it;
93
94 it = buffer_set_ref_id (session);
95 if (!it)
96 return 0;
97
98 return buffer_set_limits (&it->set);
99 }
100
101
102 ssize_t
buffer_session_representation_type(ssize_t const session)103 buffer_session_representation_type (ssize_t const session)
104 {
105 struct buffer_set_entry * it;
106
107 it = buffer_set_ref_id (session);
108 if (!it)
109 return 0;
110
111 return buffer_set_representation_type (&it->set);
112 }
113
114
115
116 ssize_t
buffer_session_n_entries(ssize_t const session)117 buffer_session_n_entries (ssize_t const session)
118 {
119 struct buffer_set_entry * it;
120
121 it = buffer_set_ref_id (session);
122 if (!it)
123 return 0;
124
125 return buffer_set_n_entries (&it->set);
126 }
127
128
129 ssize_t
buffer_session_room(ssize_t const session)130 buffer_session_room (ssize_t const session)
131 {
132 struct buffer_set_entry * it;
133
134 it = buffer_set_ref_id (session);
135 if (!it)
136 return 0;
137
138 return buffer_set_room (&it->set);
139 }
140
141
142 t_buffer *
buffer_session_buffer_n(const t_uchar ** const name_ret,ssize_t const session,ssize_t const n)143 buffer_session_buffer_n (const t_uchar ** const name_ret,
144 ssize_t const session,
145 ssize_t const n)
146 {
147 struct buffer_set_entry * it;
148
149 it = buffer_set_ref_id (session);
150 if (!it)
151 return 0;
152
153 return buffer_set_buffer_n (name_ret, &it->set, n);
154 }
155
156
157 t_buffer *
buffer_session_nth_buffer(const t_uchar ** const name_ret,ssize_t const session,ssize_t const n)158 buffer_session_nth_buffer (const t_uchar ** const name_ret,
159 ssize_t const session,
160 ssize_t const n)
161 {
162 struct buffer_set_entry * it;
163
164 it = buffer_set_ref_id (session);
165 if (!it)
166 return 0;
167
168 return buffer_set_nth_buffer (name_ret, &it->set, n);
169 }
170
171
172 t_buffer *
buffer_session_find(ssize_t const session,t_uchar * const name)173 buffer_session_find (ssize_t const session,
174 t_uchar * const name)
175 {
176 struct buffer_set_entry * it;
177
178 it = buffer_set_ref_id (session);
179 if (!it)
180 return 0;
181
182 return buffer_set_find (&it->set, name);
183 }
184
185
186 t_buffer *
buffer_session_ensure(ssize_t const session,t_uchar * const name)187 buffer_session_ensure (ssize_t const session,
188 t_uchar * const name)
189 {
190 struct buffer_set_entry * it;
191
192 it = buffer_set_ref_id (session);
193 if (!it)
194 return 0;
195
196 return buffer_set_ensure (&it->set, name);
197 }
198
199
200 ssize_t
buffer_session_index(ssize_t const session,t_uchar * const name)201 buffer_session_index (ssize_t const session,
202 t_uchar * const name)
203 {
204 struct buffer_set_entry * it;
205
206 it = buffer_set_ref_id (session);
207 if (!it)
208 return -1;
209
210 return buffer_set_index (&it->set, name);
211 }
212
213
214 ssize_t
buffer_session_index_create(ssize_t const session,t_uchar * const name)215 buffer_session_index_create (ssize_t const session,
216 t_uchar * const name)
217 {
218 ssize_t answer;
219
220 answer = buffer_session_index (session, name);
221 if (answer < 0)
222 {
223 (void)buffer_session_ensure (session, name);
224 answer = buffer_session_index (session, name);
225 }
226
227 return answer;
228 }
229
230
231 int
buffer_session_delete(ssize_t const session,t_uchar * const name)232 buffer_session_delete (ssize_t const session,
233 t_uchar * const name)
234 {
235 struct buffer_set_entry * it;
236
237 it = buffer_set_ref_id (session);
238 if (!it)
239 return 0;
240
241 return buffer_set_delete (&it->set, name);
242 }
243
244
245 int
buffer_session_delete_nth(ssize_t const session,ssize_t const n)246 buffer_session_delete_nth (ssize_t const session,
247 ssize_t const n)
248 {
249 struct buffer_set_entry * it;
250
251 it = buffer_set_ref_id (session);
252 if (!it)
253 return 0;
254
255 return buffer_set_delete_nth (&it->set, n);
256 }
257
258
259
260 void *
buffer_session_property_soft_ref(ssize_t const session,ssize_t const elt_size,ssize_t const buffer,ssize_t const global_property_id)261 buffer_session_property_soft_ref (ssize_t const session,
262 ssize_t const elt_size,
263 ssize_t const buffer,
264 ssize_t const global_property_id)
265 {
266 struct buffer_set_entry * it;
267
268 it = buffer_set_ref_id (session);
269 if (!it)
270 return 0;
271
272 return buffer_set_property_soft_ref (&it->set, elt_size, buffer, global_property_id);
273 }
274
275
276 void *
buffer_session_property_ref(ssize_t const session,ssize_t const elt_size,ssize_t const buffer,ssize_t const global_property_id,t_property_type * const type)277 buffer_session_property_ref (ssize_t const session,
278 ssize_t const elt_size,
279 ssize_t const buffer,
280 ssize_t const global_property_id,
281 t_property_type * const type)
282 {
283 struct buffer_set_entry * it;
284
285 it = buffer_set_ref_id (session);
286 if (!it)
287 return 0;
288
289 return buffer_set_property_ref (&it->set, elt_size, buffer, global_property_id, type);
290 }
291
292
293
294
295 /* tag: Tom Lord Sun Nov 21 08:02:31 2004 (buffers.c)
296 */
297