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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 #ifndef DBUS_MARSHAL_RECURSIVE_H
25 #define DBUS_MARSHAL_RECURSIVE_H
27 #include <dbus/dbus-protocol.h>
28 #include <dbus/dbus-list.h>
30 typedef struct DBusTypeReader DBusTypeReader;
31 typedef struct DBusTypeWriter DBusTypeWriter;
32 typedef struct DBusTypeReaderClass DBusTypeReaderClass;
33 typedef struct DBusArrayLenFixup DBusArrayLenFixup;
36 * The type reader is an iterator for reading values from a block of
41 dbus_uint32_t byte_order : 8; /**< byte order of the block */
43 dbus_uint32_t finished : 1; /**< marks we're at end iterator for cases
44 * where we don't have another way to tell
46 dbus_uint32_t array_len_offset : 3; /**< bytes back from start_pos that len ends */
47 const DBusString *type_str; /**< string containing signature of block */
48 int type_pos; /**< current position in signature */
49 const DBusString *value_str; /**< string containing values of block */
50 int value_pos; /**< current position in values */
52 const DBusTypeReaderClass *klass; /**< the vtable for the reader */
56 int start_pos; /**< for array readers, the start of the array values */
58 } u; /**< class-specific data */
62 * The type writer is an iterator for writing to a block of values.
66 dbus_uint32_t byte_order : 8; /**< byte order to write values with */
68 dbus_uint32_t container_type : 8; /**< what are we inside? (e.g. struct, variant, array) */
70 dbus_uint32_t type_pos_is_expectation : 1; /**< type_pos can be either an insertion point for or an expected next type */
72 dbus_uint32_t enabled : 1; /**< whether to write values */
74 DBusString *type_str; /**< where to write typecodes (or read type expectations) */
75 int type_pos; /**< current pos in type_str */
76 DBusString *value_str; /**< where to write values */
77 int value_pos; /**< next position to write */
82 int start_pos; /**< position of first element in the array */
83 int len_pos; /**< position of length of the array */
84 int element_type_pos; /**< position of array element type in type_str */
86 } u; /**< class-specific data */
90 * When modifying an existing block of values, array lengths may need
91 * to be adjusted; those adjustments are described by this struct.
93 struct DBusArrayLenFixup
95 int len_pos_in_reader; /**< where the length was in the original block */
96 int new_len; /**< the new value of the length in the written-out block */
99 void _dbus_type_reader_init (DBusTypeReader *reader,
101 const DBusString *type_str,
103 const DBusString *value_str,
105 void _dbus_type_reader_init_types_only (DBusTypeReader *reader,
106 const DBusString *type_str,
108 int _dbus_type_reader_get_current_type (const DBusTypeReader *reader);
109 int _dbus_type_reader_get_element_type (const DBusTypeReader *reader);
110 int _dbus_type_reader_get_value_pos (const DBusTypeReader *reader);
111 void _dbus_type_reader_read_basic (const DBusTypeReader *reader,
113 int _dbus_type_reader_get_array_length (const DBusTypeReader *reader);
114 void _dbus_type_reader_read_fixed_multi (const DBusTypeReader *reader,
117 void _dbus_type_reader_read_raw (const DBusTypeReader *reader,
118 const unsigned char **value_location);
119 void _dbus_type_reader_recurse (DBusTypeReader *reader,
120 DBusTypeReader *subreader);
121 dbus_bool_t _dbus_type_reader_next (DBusTypeReader *reader);
122 dbus_bool_t _dbus_type_reader_has_next (const DBusTypeReader *reader);
123 void _dbus_type_reader_get_signature (const DBusTypeReader *reader,
124 const DBusString **str_p,
127 dbus_bool_t _dbus_type_reader_set_basic (DBusTypeReader *reader,
129 const DBusTypeReader *realign_root);
130 dbus_bool_t _dbus_type_reader_delete (DBusTypeReader *reader,
131 const DBusTypeReader *realign_root);
133 dbus_bool_t _dbus_type_reader_equal_values (const DBusTypeReader *lhs,
134 const DBusTypeReader *rhs);
136 void _dbus_type_signature_next (const char *signature,
139 void _dbus_type_writer_init (DBusTypeWriter *writer,
141 DBusString *type_str,
143 DBusString *value_str,
145 void _dbus_type_writer_init_types_delayed (DBusTypeWriter *writer,
147 DBusString *value_str,
149 void _dbus_type_writer_add_types (DBusTypeWriter *writer,
150 DBusString *type_str,
152 void _dbus_type_writer_remove_types (DBusTypeWriter *writer);
153 void _dbus_type_writer_init_values_only (DBusTypeWriter *writer,
155 const DBusString *type_str,
157 DBusString *value_str,
159 dbus_bool_t _dbus_type_writer_write_basic (DBusTypeWriter *writer,
162 dbus_bool_t _dbus_type_writer_write_fixed_multi (DBusTypeWriter *writer,
166 dbus_bool_t _dbus_type_writer_recurse (DBusTypeWriter *writer,
168 const DBusString *contained_type,
169 int contained_type_start,
170 DBusTypeWriter *sub);
171 dbus_bool_t _dbus_type_writer_unrecurse (DBusTypeWriter *writer,
172 DBusTypeWriter *sub);
173 dbus_bool_t _dbus_type_writer_append_array (DBusTypeWriter *writer,
174 const DBusString *contained_type,
175 int contained_type_start,
176 DBusTypeWriter *sub);
177 dbus_bool_t _dbus_type_writer_write_reader (DBusTypeWriter *writer,
178 DBusTypeReader *reader);
181 #endif /* DBUS_MARSHAL_RECURSIVE_H */