1 /* -*- mode: C; c-file-style: "gnu" -*- */
2 /* dbus-marshal-recursive.h Marshalling routines for recursive types
4 * Copyright (C) 2004, 2005 Red Hat, Inc.
6 * Licensed under the Academic Free License version 2.1
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #ifndef DBUS_MARSHAL_RECURSIVE_H
25 #define DBUS_MARSHAL_RECURSIVE_H
28 #include <dbus/dbus-protocol.h>
29 #include <dbus/dbus-list.h>
30 #include <dbus/dbus-marshal-basic.h> /* this can vanish when we merge */
33 #error "config.h not included here"
36 /* Features we need to port dbus-message:
37 * - memoize a position of a reader for small/fast access later
38 * - delete an array element and re-align the remainder of the array
39 * (not necessary yet to re-align remainder of entire string,
40 * though that's probably just as hard/easy)
41 * (really this one is to set a complex-type array element to
42 * a new value, but for dbus-message.c delete-and-reappend would
44 * - set string, int, etc. values at a memoized position
45 * (implement generic set of any value? changes only
46 * value_str not type_str)
47 * - implement has_next()
48 * - the all-in-one-block array accessors
51 * - remember to try a HAVE_INT64=0 build at the end
54 typedef struct DBusTypeMark DBusTypeMark;
55 typedef struct DBusTypeReader DBusTypeReader;
56 typedef struct DBusTypeWriter DBusTypeWriter;
57 typedef struct DBusTypeReaderClass DBusTypeReaderClass;
58 typedef struct DBusArrayLenFixup DBusArrayLenFixup;
60 /** The mark is a way to compress a #DBusTypeReader; it isn't all that
61 * successful though. The idea was to use this for caching header
62 * fields in dbus-message.c. However now I'm thinking why not cache
63 * the actual values (e.g. char*) and if the field needs to be set or
64 * deleted, just linear search for it. Those operations are uncommon,
65 * and getting the values should be fast and not involve all this type
68 * @todo DBusTypeMark isn't used right now and probably won't be, we should delete it
72 dbus_uint32_t type_pos_in_value_str : 1; /**< true if the type_pos is in value_str and not type_str */
73 dbus_uint32_t container_type : 3; /**< the "id" of the container type */
74 dbus_uint32_t array_len_offset : 3; /**< bytes back from start_pos that len ends */
75 dbus_uint32_t type_pos : DBUS_MAXIMUM_MESSAGE_LENGTH_BITS; /**< position in type_str */
76 dbus_uint32_t value_pos : DBUS_MAXIMUM_MESSAGE_LENGTH_BITS; /**< position in value_str */
77 dbus_uint32_t array_start_pos : DBUS_MAXIMUM_MESSAGE_LENGTH_BITS; /**< start of the array the reader was iterating over */
81 * The type reader is an iterator for reading values from a block of
86 dbus_uint32_t byte_order : 8; /**< byte order of the block */
88 dbus_uint32_t finished : 1; /**< marks we're at end iterator for cases
89 * where we don't have another way to tell
91 dbus_uint32_t array_len_offset : 3; /**< bytes back from start_pos that len ends */
92 const DBusString *type_str; /**< string containing signature of block */
93 int type_pos; /**< current position in signature */
94 const DBusString *value_str; /**< string containing values of block */
95 int value_pos; /**< current position in values */
97 const DBusTypeReaderClass *klass; /**< the vtable for the reader */
101 int start_pos; /**< for array readers, the start of the array values */
103 } u; /**< class-specific data */
107 * The type writer is an iterator for writing to a block of values.
109 struct DBusTypeWriter
111 dbus_uint32_t byte_order : 8; /**< byte order to write values with */
113 dbus_uint32_t container_type : 8; /**< what are we inside? (e.g. struct, variant, array) */
115 dbus_uint32_t type_pos_is_expectation : 1; /**< type_pos can be either an insertion point for or an expected next type */
117 dbus_uint32_t enabled : 1; /**< whether to write values */
119 DBusString *type_str; /**< where to write typecodes (or read type expectations) */
120 int type_pos; /**< current pos in type_str */
121 DBusString *value_str; /**< where to write values */
122 int value_pos; /**< next position to write */
127 int start_pos; /**< position of first element in the array */
128 int len_pos; /**< position of length of the array */
129 int element_type_pos; /**< position of array element type in type_str */
131 } u; /**< class-specific data */
135 * When modifying an existing block of values, array lengths may need
136 * to be adjusted; those adjustments are described by this struct.
138 struct DBusArrayLenFixup
140 int len_pos_in_reader; /**< where the length was in the original block */
141 int new_len; /**< the new value of the length in the written-out block */
144 void _dbus_type_reader_init (DBusTypeReader *reader,
146 const DBusString *type_str,
148 const DBusString *value_str,
150 void _dbus_type_reader_init_from_mark (DBusTypeReader *reader,
152 const DBusString *type_str,
153 const DBusString *value_str,
154 const DBusTypeMark *mark);
155 void _dbus_type_reader_init_types_only (DBusTypeReader *reader,
156 const DBusString *type_str,
158 void _dbus_type_reader_init_types_only_from_mark (DBusTypeReader *reader,
159 const DBusString *type_str,
160 const DBusTypeMark *mark);
161 void _dbus_type_reader_save_mark (const DBusTypeReader *reader,
163 int _dbus_type_reader_get_current_type (const DBusTypeReader *reader);
164 int _dbus_type_reader_get_element_type (const DBusTypeReader *reader);
165 int _dbus_type_reader_get_value_pos (const DBusTypeReader *reader);
166 void _dbus_type_reader_read_basic (const DBusTypeReader *reader,
168 void _dbus_type_reader_read_fixed_multi (const DBusTypeReader *reader,
171 void _dbus_type_reader_read_raw (const DBusTypeReader *reader,
172 const unsigned char **value_location);
173 void _dbus_type_reader_recurse (DBusTypeReader *reader,
174 DBusTypeReader *subreader);
175 dbus_bool_t _dbus_type_reader_next (DBusTypeReader *reader);
176 dbus_bool_t _dbus_type_reader_has_next (const DBusTypeReader *reader);
177 void _dbus_type_reader_get_signature (const DBusTypeReader *reader,
178 const DBusString **str_p,
181 dbus_bool_t _dbus_type_reader_set_basic (DBusTypeReader *reader,
183 const DBusTypeReader *realign_root);
184 dbus_bool_t _dbus_type_reader_delete (DBusTypeReader *reader,
185 const DBusTypeReader *realign_root);
186 dbus_bool_t _dbus_type_reader_greater_than (const DBusTypeReader *lhs,
187 const DBusTypeReader *rhs);
189 void _dbus_type_writer_init (DBusTypeWriter *writer,
191 DBusString *type_str,
193 DBusString *value_str,
195 void _dbus_type_writer_init_types_delayed (DBusTypeWriter *writer,
197 DBusString *value_str,
199 void _dbus_type_writer_add_types (DBusTypeWriter *writer,
200 DBusString *type_str,
202 void _dbus_type_writer_remove_types (DBusTypeWriter *writer);
203 void _dbus_type_writer_init_values_only (DBusTypeWriter *writer,
205 const DBusString *type_str,
207 DBusString *value_str,
209 dbus_bool_t _dbus_type_writer_write_basic (DBusTypeWriter *writer,
212 dbus_bool_t _dbus_type_writer_write_fixed_multi (DBusTypeWriter *writer,
216 dbus_bool_t _dbus_type_writer_recurse (DBusTypeWriter *writer,
218 const DBusString *contained_type,
219 int contained_type_start,
220 DBusTypeWriter *sub);
221 dbus_bool_t _dbus_type_writer_unrecurse (DBusTypeWriter *writer,
222 DBusTypeWriter *sub);
223 dbus_bool_t _dbus_type_writer_append_array (DBusTypeWriter *writer,
224 const DBusString *contained_type,
225 int contained_type_start,
226 DBusTypeWriter *sub);
227 dbus_bool_t _dbus_type_writer_write_reader (DBusTypeWriter *writer,
228 DBusTypeReader *reader);
229 dbus_bool_t _dbus_type_writer_write_reader_partial (DBusTypeWriter *writer,
230 DBusTypeReader *reader,
231 const DBusTypeReader *start_after,
232 int start_after_new_pos,
233 int start_after_new_len,
235 void _dbus_type_writer_set_enabled (DBusTypeWriter *writer,
236 dbus_bool_t enabled);
239 #endif /* DBUS_MARSHAL_RECURSIVE_H */