1 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
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>
31 typedef struct DBusTypeReader DBusTypeReader;
32 typedef struct DBusTypeWriter DBusTypeWriter;
33 typedef struct DBusTypeReaderClass DBusTypeReaderClass;
34 typedef struct DBusArrayLenFixup DBusArrayLenFixup;
37 * The type reader is an iterator for reading values from a block of
42 dbus_uint32_t byte_order : 8; /**< byte order of the block */
44 dbus_uint32_t finished : 1; /**< marks we're at end iterator for cases
45 * where we don't have another way to tell
47 dbus_uint32_t array_len_offset : 3; /**< bytes back from start_pos that len ends */
48 const DBusString *type_str; /**< string containing signature of block */
49 int type_pos; /**< current position in signature */
50 const DBusString *value_str; /**< string containing values of block */
51 int value_pos; /**< current position in values */
53 const DBusTypeReaderClass *klass; /**< the vtable for the reader */
57 int start_pos; /**< for array readers, the start of the array values */
59 } u; /**< class-specific data */
63 * The type writer is an iterator for writing to a block of values.
67 dbus_uint32_t byte_order : 8; /**< byte order to write values with */
69 dbus_uint32_t container_type : 8; /**< what are we inside? (e.g. struct, variant, array) */
71 dbus_uint32_t type_pos_is_expectation : 1; /**< type_pos can be either an insertion point for or an expected next type */
73 dbus_uint32_t enabled : 1; /**< whether to write values */
75 DBusString *type_str; /**< where to write typecodes (or read type expectations) */
76 int type_pos; /**< current pos in type_str */
77 DBusString *value_str; /**< where to write values */
78 int value_pos; /**< next position to write */
83 int start_pos; /**< position of first element in the array */
84 int len_pos; /**< position of length of the array */
85 int element_type_pos; /**< position of array element type in type_str */
87 } u; /**< class-specific data */
91 * When modifying an existing block of values, array lengths may need
92 * to be adjusted; those adjustments are described by this struct.
94 struct DBusArrayLenFixup
96 int len_pos_in_reader; /**< where the length was in the original block */
97 int new_len; /**< the new value of the length in the written-out block */
100 void _dbus_type_reader_init (DBusTypeReader *reader,
102 const DBusString *type_str,
104 const DBusString *value_str,
106 void _dbus_type_reader_init_types_only (DBusTypeReader *reader,
107 const DBusString *type_str,
109 int _dbus_type_reader_get_current_type (const DBusTypeReader *reader);
110 int _dbus_type_reader_get_element_type (const DBusTypeReader *reader);
111 int _dbus_type_reader_get_value_pos (const DBusTypeReader *reader);
112 void _dbus_type_reader_read_basic (const DBusTypeReader *reader,
114 int _dbus_type_reader_get_array_length (const DBusTypeReader *reader);
115 void _dbus_type_reader_read_fixed_multi (const DBusTypeReader *reader,
118 void _dbus_type_reader_read_raw (const DBusTypeReader *reader,
119 const unsigned char **value_location);
120 void _dbus_type_reader_recurse (DBusTypeReader *reader,
121 DBusTypeReader *subreader);
122 dbus_bool_t _dbus_type_reader_next (DBusTypeReader *reader);
123 dbus_bool_t _dbus_type_reader_has_next (const DBusTypeReader *reader);
124 void _dbus_type_reader_get_signature (const DBusTypeReader *reader,
125 const DBusString **str_p,
128 dbus_bool_t _dbus_type_reader_set_basic (DBusTypeReader *reader,
130 const DBusTypeReader *realign_root);
131 dbus_bool_t _dbus_type_reader_delete (DBusTypeReader *reader,
132 const DBusTypeReader *realign_root);
133 dbus_bool_t _dbus_type_reader_greater_than (const DBusTypeReader *lhs,
134 const DBusTypeReader *rhs);
136 dbus_bool_t _dbus_type_reader_equal_values (const DBusTypeReader *lhs,
137 const DBusTypeReader *rhs);
139 void _dbus_type_signature_next (const char *signature,
142 void _dbus_type_writer_init (DBusTypeWriter *writer,
144 DBusString *type_str,
146 DBusString *value_str,
148 void _dbus_type_writer_init_types_delayed (DBusTypeWriter *writer,
150 DBusString *value_str,
152 void _dbus_type_writer_add_types (DBusTypeWriter *writer,
153 DBusString *type_str,
155 void _dbus_type_writer_remove_types (DBusTypeWriter *writer);
156 void _dbus_type_writer_init_values_only (DBusTypeWriter *writer,
158 const DBusString *type_str,
160 DBusString *value_str,
162 dbus_bool_t _dbus_type_writer_write_basic (DBusTypeWriter *writer,
165 dbus_bool_t _dbus_type_writer_write_fixed_multi (DBusTypeWriter *writer,
169 dbus_bool_t _dbus_type_writer_recurse (DBusTypeWriter *writer,
171 const DBusString *contained_type,
172 int contained_type_start,
173 DBusTypeWriter *sub);
174 dbus_bool_t _dbus_type_writer_unrecurse (DBusTypeWriter *writer,
175 DBusTypeWriter *sub);
176 dbus_bool_t _dbus_type_writer_append_array (DBusTypeWriter *writer,
177 const DBusString *contained_type,
178 int contained_type_start,
179 DBusTypeWriter *sub);
180 dbus_bool_t _dbus_type_writer_write_reader (DBusTypeWriter *writer,
181 DBusTypeReader *reader);
182 dbus_bool_t _dbus_type_writer_write_reader_partial (DBusTypeWriter *writer,
183 DBusTypeReader *reader,
184 const DBusTypeReader *start_after,
185 int start_after_new_pos,
186 int start_after_new_len,
188 void _dbus_type_writer_set_enabled (DBusTypeWriter *writer,
189 dbus_bool_t enabled);
192 #endif /* DBUS_MARSHAL_RECURSIVE_H */