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 DBusTypeReader DBusTypeReader;
36 typedef struct DBusTypeWriter DBusTypeWriter;
37 typedef struct DBusTypeReaderClass DBusTypeReaderClass;
38 typedef struct DBusArrayLenFixup DBusArrayLenFixup;
41 * The type reader is an iterator for reading values from a block of
46 dbus_uint32_t byte_order : 8; /**< byte order of the block */
48 dbus_uint32_t finished : 1; /**< marks we're at end iterator for cases
49 * where we don't have another way to tell
51 dbus_uint32_t array_len_offset : 3; /**< bytes back from start_pos that len ends */
52 const DBusString *type_str; /**< string containing signature of block */
53 int type_pos; /**< current position in signature */
54 const DBusString *value_str; /**< string containing values of block */
55 int value_pos; /**< current position in values */
57 const DBusTypeReaderClass *klass; /**< the vtable for the reader */
61 int start_pos; /**< for array readers, the start of the array values */
63 } u; /**< class-specific data */
67 * The type writer is an iterator for writing to a block of values.
71 dbus_uint32_t byte_order : 8; /**< byte order to write values with */
73 dbus_uint32_t container_type : 8; /**< what are we inside? (e.g. struct, variant, array) */
75 dbus_uint32_t type_pos_is_expectation : 1; /**< type_pos can be either an insertion point for or an expected next type */
77 dbus_uint32_t enabled : 1; /**< whether to write values */
79 DBusString *type_str; /**< where to write typecodes (or read type expectations) */
80 int type_pos; /**< current pos in type_str */
81 DBusString *value_str; /**< where to write values */
82 int value_pos; /**< next position to write */
87 int start_pos; /**< position of first element in the array */
88 int len_pos; /**< position of length of the array */
89 int element_type_pos; /**< position of array element type in type_str */
91 } u; /**< class-specific data */
95 * When modifying an existing block of values, array lengths may need
96 * to be adjusted; those adjustments are described by this struct.
98 struct DBusArrayLenFixup
100 int len_pos_in_reader; /**< where the length was in the original block */
101 int new_len; /**< the new value of the length in the written-out block */
104 void _dbus_type_reader_init (DBusTypeReader *reader,
106 const DBusString *type_str,
108 const DBusString *value_str,
110 void _dbus_type_reader_init_types_only (DBusTypeReader *reader,
111 const DBusString *type_str,
113 int _dbus_type_reader_get_current_type (const DBusTypeReader *reader);
114 int _dbus_type_reader_get_element_type (const DBusTypeReader *reader);
115 int _dbus_type_reader_get_value_pos (const DBusTypeReader *reader);
116 void _dbus_type_reader_read_basic (const DBusTypeReader *reader,
118 int _dbus_type_reader_get_array_length (const DBusTypeReader *reader);
119 void _dbus_type_reader_read_fixed_multi (const DBusTypeReader *reader,
122 void _dbus_type_reader_read_raw (const DBusTypeReader *reader,
123 const unsigned char **value_location);
124 void _dbus_type_reader_recurse (DBusTypeReader *reader,
125 DBusTypeReader *subreader);
126 dbus_bool_t _dbus_type_reader_next (DBusTypeReader *reader);
127 dbus_bool_t _dbus_type_reader_has_next (const DBusTypeReader *reader);
128 void _dbus_type_reader_get_signature (const DBusTypeReader *reader,
129 const DBusString **str_p,
132 dbus_bool_t _dbus_type_reader_set_basic (DBusTypeReader *reader,
134 const DBusTypeReader *realign_root);
135 dbus_bool_t _dbus_type_reader_delete (DBusTypeReader *reader,
136 const DBusTypeReader *realign_root);
137 dbus_bool_t _dbus_type_reader_greater_than (const DBusTypeReader *lhs,
138 const DBusTypeReader *rhs);
140 dbus_bool_t _dbus_type_reader_equal_values (const DBusTypeReader *lhs,
141 const DBusTypeReader *rhs);
143 void _dbus_type_signature_next (const char *signature,
146 void _dbus_type_writer_init (DBusTypeWriter *writer,
148 DBusString *type_str,
150 DBusString *value_str,
152 void _dbus_type_writer_init_types_delayed (DBusTypeWriter *writer,
154 DBusString *value_str,
156 void _dbus_type_writer_add_types (DBusTypeWriter *writer,
157 DBusString *type_str,
159 void _dbus_type_writer_remove_types (DBusTypeWriter *writer);
160 void _dbus_type_writer_init_values_only (DBusTypeWriter *writer,
162 const DBusString *type_str,
164 DBusString *value_str,
166 dbus_bool_t _dbus_type_writer_write_basic (DBusTypeWriter *writer,
169 dbus_bool_t _dbus_type_writer_write_fixed_multi (DBusTypeWriter *writer,
173 dbus_bool_t _dbus_type_writer_recurse (DBusTypeWriter *writer,
175 const DBusString *contained_type,
176 int contained_type_start,
177 DBusTypeWriter *sub);
178 dbus_bool_t _dbus_type_writer_unrecurse (DBusTypeWriter *writer,
179 DBusTypeWriter *sub);
180 dbus_bool_t _dbus_type_writer_append_array (DBusTypeWriter *writer,
181 const DBusString *contained_type,
182 int contained_type_start,
183 DBusTypeWriter *sub);
184 dbus_bool_t _dbus_type_writer_write_reader (DBusTypeWriter *writer,
185 DBusTypeReader *reader);
186 dbus_bool_t _dbus_type_writer_write_reader_partial (DBusTypeWriter *writer,
187 DBusTypeReader *reader,
188 const DBusTypeReader *start_after,
189 int start_after_new_pos,
190 int start_after_new_len,
192 void _dbus_type_writer_set_enabled (DBusTypeWriter *writer,
193 dbus_bool_t enabled);
196 #endif /* DBUS_MARSHAL_RECURSIVE_H */