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>
32 #error "config.h not included here"
35 typedef struct DBusTypeMark DBusTypeMark;
36 typedef struct DBusTypeReader DBusTypeReader;
37 typedef struct DBusTypeWriter DBusTypeWriter;
38 typedef struct DBusTypeReaderClass DBusTypeReaderClass;
39 typedef struct DBusArrayLenFixup DBusArrayLenFixup;
41 /** The mark is a way to compress a #DBusTypeReader; it isn't all that
42 * successful though. The idea was to use this for caching header
43 * fields in dbus-message.c. However now I'm thinking why not cache
44 * the actual values (e.g. char*) and if the field needs to be set or
45 * deleted, just linear search for it. Those operations are uncommon,
46 * and getting the values should be fast and not involve all this type
49 * @todo DBusTypeMark isn't used right now and probably won't be, we should delete it
53 dbus_uint32_t type_pos_in_value_str : 1; /**< true if the type_pos is in value_str and not type_str */
54 dbus_uint32_t container_type : 3; /**< the "id" of the container type */
55 dbus_uint32_t array_len_offset : 3; /**< bytes back from start_pos that len ends */
56 dbus_uint32_t type_pos : DBUS_MAXIMUM_MESSAGE_LENGTH_BITS; /**< position in type_str */
57 dbus_uint32_t value_pos : DBUS_MAXIMUM_MESSAGE_LENGTH_BITS; /**< position in value_str */
58 dbus_uint32_t array_start_pos : DBUS_MAXIMUM_MESSAGE_LENGTH_BITS; /**< start of the array the reader was iterating over */
62 * The type reader is an iterator for reading values from a block of
67 dbus_uint32_t byte_order : 8; /**< byte order of the block */
69 dbus_uint32_t finished : 1; /**< marks we're at end iterator for cases
70 * where we don't have another way to tell
72 dbus_uint32_t array_len_offset : 3; /**< bytes back from start_pos that len ends */
73 const DBusString *type_str; /**< string containing signature of block */
74 int type_pos; /**< current position in signature */
75 const DBusString *value_str; /**< string containing values of block */
76 int value_pos; /**< current position in values */
78 const DBusTypeReaderClass *klass; /**< the vtable for the reader */
82 int start_pos; /**< for array readers, the start of the array values */
84 } u; /**< class-specific data */
88 * The type writer is an iterator for writing to a block of values.
92 dbus_uint32_t byte_order : 8; /**< byte order to write values with */
94 dbus_uint32_t container_type : 8; /**< what are we inside? (e.g. struct, variant, array) */
96 dbus_uint32_t type_pos_is_expectation : 1; /**< type_pos can be either an insertion point for or an expected next type */
98 dbus_uint32_t enabled : 1; /**< whether to write values */
100 DBusString *type_str; /**< where to write typecodes (or read type expectations) */
101 int type_pos; /**< current pos in type_str */
102 DBusString *value_str; /**< where to write values */
103 int value_pos; /**< next position to write */
108 int start_pos; /**< position of first element in the array */
109 int len_pos; /**< position of length of the array */
110 int element_type_pos; /**< position of array element type in type_str */
112 } u; /**< class-specific data */
116 * When modifying an existing block of values, array lengths may need
117 * to be adjusted; those adjustments are described by this struct.
119 struct DBusArrayLenFixup
121 int len_pos_in_reader; /**< where the length was in the original block */
122 int new_len; /**< the new value of the length in the written-out block */
125 void _dbus_type_reader_init (DBusTypeReader *reader,
127 const DBusString *type_str,
129 const DBusString *value_str,
131 void _dbus_type_reader_init_from_mark (DBusTypeReader *reader,
133 const DBusString *type_str,
134 const DBusString *value_str,
135 const DBusTypeMark *mark);
136 void _dbus_type_reader_init_types_only (DBusTypeReader *reader,
137 const DBusString *type_str,
139 void _dbus_type_reader_init_types_only_from_mark (DBusTypeReader *reader,
140 const DBusString *type_str,
141 const DBusTypeMark *mark);
142 void _dbus_type_reader_save_mark (const DBusTypeReader *reader,
144 int _dbus_type_reader_get_current_type (const DBusTypeReader *reader);
145 int _dbus_type_reader_get_element_type (const DBusTypeReader *reader);
146 int _dbus_type_reader_get_value_pos (const DBusTypeReader *reader);
147 void _dbus_type_reader_read_basic (const DBusTypeReader *reader,
149 void _dbus_type_reader_read_fixed_multi (const DBusTypeReader *reader,
152 void _dbus_type_reader_read_raw (const DBusTypeReader *reader,
153 const unsigned char **value_location);
154 void _dbus_type_reader_recurse (DBusTypeReader *reader,
155 DBusTypeReader *subreader);
156 dbus_bool_t _dbus_type_reader_next (DBusTypeReader *reader);
157 dbus_bool_t _dbus_type_reader_has_next (const DBusTypeReader *reader);
158 void _dbus_type_reader_get_signature (const DBusTypeReader *reader,
159 const DBusString **str_p,
162 dbus_bool_t _dbus_type_reader_set_basic (DBusTypeReader *reader,
164 const DBusTypeReader *realign_root);
165 dbus_bool_t _dbus_type_reader_delete (DBusTypeReader *reader,
166 const DBusTypeReader *realign_root);
167 dbus_bool_t _dbus_type_reader_greater_than (const DBusTypeReader *lhs,
168 const DBusTypeReader *rhs);
170 dbus_bool_t _dbus_type_reader_equal_values (const DBusTypeReader *lhs,
171 const DBusTypeReader *rhs);
173 void _dbus_type_writer_init (DBusTypeWriter *writer,
175 DBusString *type_str,
177 DBusString *value_str,
179 void _dbus_type_writer_init_types_delayed (DBusTypeWriter *writer,
181 DBusString *value_str,
183 void _dbus_type_writer_add_types (DBusTypeWriter *writer,
184 DBusString *type_str,
186 void _dbus_type_writer_remove_types (DBusTypeWriter *writer);
187 void _dbus_type_writer_init_values_only (DBusTypeWriter *writer,
189 const DBusString *type_str,
191 DBusString *value_str,
193 dbus_bool_t _dbus_type_writer_write_basic (DBusTypeWriter *writer,
196 dbus_bool_t _dbus_type_writer_write_fixed_multi (DBusTypeWriter *writer,
200 dbus_bool_t _dbus_type_writer_recurse (DBusTypeWriter *writer,
202 const DBusString *contained_type,
203 int contained_type_start,
204 DBusTypeWriter *sub);
205 dbus_bool_t _dbus_type_writer_unrecurse (DBusTypeWriter *writer,
206 DBusTypeWriter *sub);
207 dbus_bool_t _dbus_type_writer_append_array (DBusTypeWriter *writer,
208 const DBusString *contained_type,
209 int contained_type_start,
210 DBusTypeWriter *sub);
211 dbus_bool_t _dbus_type_writer_write_reader (DBusTypeWriter *writer,
212 DBusTypeReader *reader);
213 dbus_bool_t _dbus_type_writer_write_reader_partial (DBusTypeWriter *writer,
214 DBusTypeReader *reader,
215 const DBusTypeReader *start_after,
216 int start_after_new_pos,
217 int start_after_new_len,
219 void _dbus_type_writer_set_enabled (DBusTypeWriter *writer,
220 dbus_bool_t enabled);
223 #endif /* DBUS_MARSHAL_RECURSIVE_H */