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 typedef struct DBusTypeMark DBusTypeMark;
37 typedef struct DBusTypeReader DBusTypeReader;
38 typedef struct DBusTypeWriter DBusTypeWriter;
39 typedef struct DBusTypeReaderClass DBusTypeReaderClass;
40 typedef struct DBusArrayLenFixup DBusArrayLenFixup;
42 /** The mark is a way to compress a #DBusTypeReader; it isn't all that
43 * successful though. The idea was to use this for caching header
44 * fields in dbus-message.c. However now I'm thinking why not cache
45 * the actual values (e.g. char*) and if the field needs to be set or
46 * deleted, just linear search for it. Those operations are uncommon,
47 * and getting the values should be fast and not involve all this type
50 * @todo DBusTypeMark isn't used right now and probably won't be, we should delete it
54 dbus_uint32_t type_pos_in_value_str : 1; /**< true if the type_pos is in value_str and not type_str */
55 dbus_uint32_t container_type : 3; /**< the "id" of the container type */
56 dbus_uint32_t array_len_offset : 3; /**< bytes back from start_pos that len ends */
57 dbus_uint32_t type_pos : DBUS_MAXIMUM_MESSAGE_LENGTH_BITS; /**< position in type_str */
58 dbus_uint32_t value_pos : DBUS_MAXIMUM_MESSAGE_LENGTH_BITS; /**< position in value_str */
59 dbus_uint32_t array_start_pos : DBUS_MAXIMUM_MESSAGE_LENGTH_BITS; /**< start of the array the reader was iterating over */
63 * The type reader is an iterator for reading values from a block of
68 dbus_uint32_t byte_order : 8; /**< byte order of the block */
70 dbus_uint32_t finished : 1; /**< marks we're at end iterator for cases
71 * where we don't have another way to tell
73 dbus_uint32_t array_len_offset : 3; /**< bytes back from start_pos that len ends */
74 const DBusString *type_str; /**< string containing signature of block */
75 int type_pos; /**< current position in signature */
76 const DBusString *value_str; /**< string containing values of block */
77 int value_pos; /**< current position in values */
79 const DBusTypeReaderClass *klass; /**< the vtable for the reader */
83 int start_pos; /**< for array readers, the start of the array values */
85 } u; /**< class-specific data */
89 * The type writer is an iterator for writing to a block of values.
93 dbus_uint32_t byte_order : 8; /**< byte order to write values with */
95 dbus_uint32_t container_type : 8; /**< what are we inside? (e.g. struct, variant, array) */
97 dbus_uint32_t type_pos_is_expectation : 1; /**< type_pos can be either an insertion point for or an expected next type */
99 dbus_uint32_t enabled : 1; /**< whether to write values */
101 DBusString *type_str; /**< where to write typecodes (or read type expectations) */
102 int type_pos; /**< current pos in type_str */
103 DBusString *value_str; /**< where to write values */
104 int value_pos; /**< next position to write */
109 int start_pos; /**< position of first element in the array */
110 int len_pos; /**< position of length of the array */
111 int element_type_pos; /**< position of array element type in type_str */
113 } u; /**< class-specific data */
117 * When modifying an existing block of values, array lengths may need
118 * to be adjusted; those adjustments are described by this struct.
120 struct DBusArrayLenFixup
122 int len_pos_in_reader; /**< where the length was in the original block */
123 int new_len; /**< the new value of the length in the written-out block */
126 void _dbus_type_reader_init (DBusTypeReader *reader,
128 const DBusString *type_str,
130 const DBusString *value_str,
132 void _dbus_type_reader_init_from_mark (DBusTypeReader *reader,
134 const DBusString *type_str,
135 const DBusString *value_str,
136 const DBusTypeMark *mark);
137 void _dbus_type_reader_init_types_only (DBusTypeReader *reader,
138 const DBusString *type_str,
140 void _dbus_type_reader_init_types_only_from_mark (DBusTypeReader *reader,
141 const DBusString *type_str,
142 const DBusTypeMark *mark);
143 void _dbus_type_reader_save_mark (const DBusTypeReader *reader,
145 int _dbus_type_reader_get_current_type (const DBusTypeReader *reader);
146 int _dbus_type_reader_get_element_type (const DBusTypeReader *reader);
147 int _dbus_type_reader_get_value_pos (const DBusTypeReader *reader);
148 void _dbus_type_reader_read_basic (const DBusTypeReader *reader,
150 void _dbus_type_reader_read_fixed_multi (const DBusTypeReader *reader,
153 void _dbus_type_reader_read_raw (const DBusTypeReader *reader,
154 const unsigned char **value_location);
155 void _dbus_type_reader_recurse (DBusTypeReader *reader,
156 DBusTypeReader *subreader);
157 dbus_bool_t _dbus_type_reader_next (DBusTypeReader *reader);
158 dbus_bool_t _dbus_type_reader_has_next (const DBusTypeReader *reader);
159 void _dbus_type_reader_get_signature (const DBusTypeReader *reader,
160 const DBusString **str_p,
163 dbus_bool_t _dbus_type_reader_set_basic (DBusTypeReader *reader,
165 const DBusTypeReader *realign_root);
166 dbus_bool_t _dbus_type_reader_delete (DBusTypeReader *reader,
167 const DBusTypeReader *realign_root);
168 dbus_bool_t _dbus_type_reader_greater_than (const DBusTypeReader *lhs,
169 const DBusTypeReader *rhs);
171 void _dbus_type_writer_init (DBusTypeWriter *writer,
173 DBusString *type_str,
175 DBusString *value_str,
177 void _dbus_type_writer_init_types_delayed (DBusTypeWriter *writer,
179 DBusString *value_str,
181 void _dbus_type_writer_add_types (DBusTypeWriter *writer,
182 DBusString *type_str,
184 void _dbus_type_writer_remove_types (DBusTypeWriter *writer);
185 void _dbus_type_writer_init_values_only (DBusTypeWriter *writer,
187 const DBusString *type_str,
189 DBusString *value_str,
191 dbus_bool_t _dbus_type_writer_write_basic (DBusTypeWriter *writer,
194 dbus_bool_t _dbus_type_writer_write_fixed_multi (DBusTypeWriter *writer,
198 dbus_bool_t _dbus_type_writer_recurse (DBusTypeWriter *writer,
200 const DBusString *contained_type,
201 int contained_type_start,
202 DBusTypeWriter *sub);
203 dbus_bool_t _dbus_type_writer_unrecurse (DBusTypeWriter *writer,
204 DBusTypeWriter *sub);
205 dbus_bool_t _dbus_type_writer_append_array (DBusTypeWriter *writer,
206 const DBusString *contained_type,
207 int contained_type_start,
208 DBusTypeWriter *sub);
209 dbus_bool_t _dbus_type_writer_write_reader (DBusTypeWriter *writer,
210 DBusTypeReader *reader);
211 dbus_bool_t _dbus_type_writer_write_reader_partial (DBusTypeWriter *writer,
212 DBusTypeReader *reader,
213 const DBusTypeReader *start_after,
214 int start_after_new_pos,
215 int start_after_new_len,
217 void _dbus_type_writer_set_enabled (DBusTypeWriter *writer,
218 dbus_bool_t enabled);
221 #endif /* DBUS_MARSHAL_RECURSIVE_H */