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.
5 * Copyright (C) 2015 Samsung Electronics
7 * Licensed under the Academic Free License version 2.1
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25 #ifndef DBUS_MARSHAL_RECURSIVE_H
26 #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 dbus_uint32_t gvariant : 1; /**< TRUE if gvariant marshaling should be used */
49 dbus_uint32_t offsets_from_back : 1; /**< for GVariant marshalling: direction of offsets */
50 dbus_uint32_t is_variant : 1; /**< for GVariant marshalling: indicator of variant type */
51 const DBusString *type_str; /**< string containing signature of block */
52 int type_pos; /**< current position in signature */
53 const DBusString *value_str; /**< string containing values of block */
54 int value_pos; /**< current position in values */
55 int variable_index; /**< index of value within variable values in the container */
56 size_t value_start; /**< start of container */
57 size_t value_end; /**< end of container */
58 int n_offsets; /**< for GVariant marshalling: number of variable offsets */
60 const DBusTypeReaderClass *klass; /**< the vtable for the reader */
64 int start_pos; /**< for array readers, the start of the array values */
66 } u; /**< class-specific data */
70 * The type writer is an iterator for writing to a block of values.
74 dbus_uint32_t byte_order : 8; /**< byte order to write values with */
76 dbus_uint32_t container_type : 8; /**< what are we inside? (e.g. struct, variant, array) */
78 dbus_uint32_t type_pos_is_expectation : 1; /**< type_pos can be either an insertion point for or an expected next type */
80 dbus_uint32_t enabled : 1; /**< whether to write values */
82 dbus_uint32_t gvariant : 1; /**< TRUE if gvariant marshaling should be used */
83 dbus_uint32_t body_container : 1; /**< TRUE if this writer is top-level */
84 dbus_uint32_t is_fixed : 1; /**< TRUE if this writer wrote only fixed-size values so far */
86 DBusString *type_str; /**< where to write typecodes (or read type expectations) */
87 int type_pos; /**< current pos in type_str */
88 DBusString *value_str; /**< where to write values */
89 int value_pos; /**< next position to write */
90 size_t value_start; /**< start of the container */
91 DBusString *offsets; /**< for GVariant marshalling: actual offsets */
92 int alignment; /**< for GVariant marshalling: for enclosing containers */
93 char offsets_size; /**< for GVariant marshalling: current size of offsets */
98 int start_pos; /**< position of first element in the array */
99 int len_pos; /**< position of length of the array */
100 int element_type_pos; /**< position of array element type in type_str */
103 size_t last_offset; /**< for GVariant marshalling: position of end of last field */
106 size_t *last_offset; /**< for GVariant: pointer to root-level last offset */
107 size_t *last_pos; /**< for GVariant: pointer to root-level last writing position */
109 } u; /**< class-specific data */
113 * When modifying an existing block of values, array lengths may need
114 * to be adjusted; those adjustments are described by this struct.
116 struct DBusArrayLenFixup
118 int len_pos_in_reader; /**< where the length was in the original block */
119 int new_len; /**< the new value of the length in the written-out block */
123 void _dbus_type_reader_init (DBusTypeReader *reader,
125 const DBusString *type_str,
127 const DBusString *value_str,
130 void _dbus_type_reader_init_types_only (DBusTypeReader *reader,
131 const DBusString *type_str,
134 int _dbus_type_reader_get_current_type (const DBusTypeReader *reader);
136 int _dbus_type_reader_get_element_type (const DBusTypeReader *reader);
137 int _dbus_type_reader_get_value_pos (const DBusTypeReader *reader);
139 void _dbus_type_reader_read_basic (const DBusTypeReader *reader,
141 int _dbus_type_reader_get_array_length (const DBusTypeReader *reader);
143 void _dbus_type_reader_read_fixed_multi (const DBusTypeReader *reader,
146 void _dbus_type_reader_read_raw (const DBusTypeReader *reader,
147 const unsigned char **value_location);
149 void _dbus_type_reader_recurse (DBusTypeReader *reader,
150 DBusTypeReader *subreader);
152 dbus_bool_t _dbus_type_reader_next (DBusTypeReader *reader);
153 dbus_bool_t _dbus_type_reader_has_next (const DBusTypeReader *reader);
155 void _dbus_type_reader_get_signature (const DBusTypeReader *reader,
156 const DBusString **str_p,
160 dbus_bool_t _dbus_type_reader_set_basic (DBusTypeReader *reader,
162 const DBusTypeReader *realign_root);
164 dbus_bool_t _dbus_type_reader_delete (DBusTypeReader *reader,
165 const DBusTypeReader *realign_root);
167 dbus_bool_t _dbus_type_reader_equal_values (const DBusTypeReader *lhs,
168 const DBusTypeReader *rhs);
170 void _dbus_type_signature_next (const char *signature,
174 void _dbus_type_writer_init (DBusTypeWriter *writer,
176 DBusString *type_str,
178 DBusString *value_str,
180 void _dbus_type_writer_init_types_delayed (DBusTypeWriter *writer,
182 DBusString *value_str,
184 void _dbus_type_writer_gvariant_init_types_delayed (DBusTypeWriter *writer,
186 DBusString *value_str,
188 dbus_bool_t gvariant,
191 void _dbus_type_writer_add_types (DBusTypeWriter *writer,
192 DBusString *type_str,
194 void _dbus_type_writer_remove_types (DBusTypeWriter *writer);
196 void _dbus_type_writer_init_values_only (DBusTypeWriter *writer,
198 const DBusString *type_str,
200 DBusString *value_str,
203 dbus_bool_t _dbus_type_writer_write_basic (DBusTypeWriter *writer,
207 dbus_bool_t _dbus_type_writer_write_basic_with_gvariant
208 (DBusTypeWriter *writer,
211 dbus_bool_t gvariant);
213 dbus_bool_t _dbus_type_writer_write_fixed_multi (DBusTypeWriter *writer,
218 dbus_bool_t _dbus_type_writer_recurse (DBusTypeWriter *writer,
220 const DBusString *contained_type,
221 int contained_type_start,
222 DBusTypeWriter *sub);
224 dbus_bool_t _dbus_type_writer_unrecurse (DBusTypeWriter *writer,
225 DBusTypeWriter *sub);
226 dbus_bool_t _dbus_type_writer_append_array (DBusTypeWriter *writer,
227 const DBusString *contained_type,
228 int contained_type_start,
229 DBusTypeWriter *sub);
231 dbus_bool_t _dbus_type_writer_write_reader (DBusTypeWriter *writer,
232 DBusTypeReader *reader);
235 #endif /* DBUS_MARSHAL_RECURSIVE_H */