1 /* -*- mode: C; c-file-style: "gnu" -*- */
2 /* dbus-marshal-recursive.h Marshalling routines for recursive types
4 * Copyright (C) 2004 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 TypeReader; 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
70 dbus_uint32_t type_pos_in_value_str : 1;
71 dbus_uint32_t container_type : 3;
72 dbus_uint32_t array_len_offset : 3; /* bytes back from start_pos that len ends */
73 dbus_uint32_t type_pos : DBUS_MAXIMUM_MESSAGE_LENGTH_BITS;
74 dbus_uint32_t value_pos : DBUS_MAXIMUM_MESSAGE_LENGTH_BITS;
75 dbus_uint32_t array_start_pos : DBUS_MAXIMUM_MESSAGE_LENGTH_BITS;
80 dbus_uint32_t byte_order : 8;
82 dbus_uint32_t finished : 1; /* marks we're at end iterator for cases
83 * where we don't have another way to tell
85 dbus_uint32_t array_len_offset : 3; /* bytes back from start_pos that len ends */
86 const DBusString *type_str;
88 const DBusString *value_str;
91 const DBusTypeReaderClass *klass;
100 struct DBusTypeWriter
102 dbus_uint32_t byte_order : 8;
104 dbus_uint32_t container_type : 8;
106 dbus_uint32_t type_pos_is_expectation : 1; /* type_pos is an insertion point or an expected next type */
108 dbus_uint32_t enabled : 1; /* whether to write values */
110 DBusString *type_str;
112 DBusString *value_str;
118 int start_pos; /* first element */
120 int element_type_pos; /* position of array element type in type_str */
125 struct DBusArrayLenFixup
127 int len_pos_in_reader;
131 void _dbus_type_reader_init (DBusTypeReader *reader,
133 const DBusString *type_str,
135 const DBusString *value_str,
137 void _dbus_type_reader_init_from_mark (DBusTypeReader *reader,
139 const DBusString *type_str,
140 const DBusString *value_str,
141 const DBusTypeMark *mark);
142 void _dbus_type_reader_init_types_only (DBusTypeReader *reader,
143 const DBusString *type_str,
145 void _dbus_type_reader_init_types_only_from_mark (DBusTypeReader *reader,
146 const DBusString *type_str,
147 const DBusTypeMark *mark);
148 void _dbus_type_reader_save_mark (const DBusTypeReader *reader,
150 int _dbus_type_reader_get_current_type (const DBusTypeReader *reader);
151 dbus_bool_t _dbus_type_reader_array_is_empty (const DBusTypeReader *reader);
152 void _dbus_type_reader_read_basic (const DBusTypeReader *reader,
154 void _dbus_type_reader_read_fixed_array (const DBusTypeReader *reader,
157 void _dbus_type_reader_recurse (DBusTypeReader *reader,
158 DBusTypeReader *subreader);
159 dbus_bool_t _dbus_type_reader_next (DBusTypeReader *reader);
160 dbus_bool_t _dbus_type_reader_has_next (const DBusTypeReader *reader);
161 void _dbus_type_reader_get_signature (const DBusTypeReader *reader,
162 const DBusString **str_p,
165 dbus_bool_t _dbus_type_reader_set_basic (DBusTypeReader *reader,
167 const DBusTypeReader *realign_root);
168 dbus_bool_t _dbus_type_reader_delete (DBusTypeReader *reader,
169 const DBusTypeReader *realign_root);
170 dbus_bool_t _dbus_type_reader_greater_than (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_values_only (DBusTypeWriter *writer,
181 const DBusString *type_str,
183 DBusString *value_str,
185 dbus_bool_t _dbus_type_writer_write_basic (DBusTypeWriter *writer,
188 dbus_bool_t _dbus_type_writer_write_fixed_array (DBusTypeWriter *writer,
192 dbus_bool_t _dbus_type_writer_recurse (DBusTypeWriter *writer,
194 const DBusString *contained_type,
195 int contained_type_start,
196 DBusTypeWriter *sub);
197 dbus_bool_t _dbus_type_writer_unrecurse (DBusTypeWriter *writer,
198 DBusTypeWriter *sub);
199 dbus_bool_t _dbus_type_writer_write_reader (DBusTypeWriter *writer,
200 DBusTypeReader *reader);
201 dbus_bool_t _dbus_type_writer_write_reader_partial (DBusTypeWriter *writer,
202 DBusTypeReader *reader,
203 const DBusTypeReader *start_after,
204 int start_after_new_pos,
205 int start_after_new_len,
207 void _dbus_type_writer_set_enabled (DBusTypeWriter *writer,
208 dbus_bool_t enabled);
212 #endif /* DBUS_MARSHAL_RECURSIVE_H */