D-Bus: dbus-marshal-recursive.h Source File

D-Bus 1.12.16

dbus-marshal-recursive.h
1 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
2 /* dbus-marshal-recursive.h Marshalling routines for recursive types
3 *
4 * Copyright (C) 2004, 2005 Red Hat, Inc.
5 *
6 * Licensed under the Academic Free License version 2.1
7 *
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.
12 *
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.
17 *
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
21 *
22 */
23
24 #ifndef DBUS_MARSHAL_RECURSIVE_H
25 #define DBUS_MARSHAL_RECURSIVE_H
26
27 #include <dbus/dbus-protocol.h>
28 #include <dbus/dbus-list.h>
29
30 typedef struct DBusTypeReader DBusTypeReader;
31 typedef struct DBusTypeWriter DBusTypeWriter;
32 typedef struct DBusTypeReaderClass DBusTypeReaderClass;
33 typedef struct DBusArrayLenFixup DBusArrayLenFixup;
34
39 struct DBusTypeReader
40 {
41 dbus_uint32_t byte_order : 8;
43 dbus_uint32_t finished : 1;
46 dbus_uint32_t array_len_offset : 3;
47 const DBusString *type_str;
48 int type_pos;
49 const DBusString *value_str;
50 int value_pos;
52 const DBusTypeReaderClass *klass;
53 union
54 {
55 struct {
56 int start_pos;
57 } array;
58 } u;
59 };
60
64 struct DBusTypeWriter
65 {
66 dbus_uint32_t byte_order : 8;
68 dbus_uint32_t container_type : 8;
70 dbus_uint32_t type_pos_is_expectation : 1;
72 dbus_uint32_t enabled : 1;
74 DBusString *type_str;
75 int type_pos;
76 DBusString *value_str;
77 int value_pos;
79 union
80 {
81 struct {
82 int start_pos;
83 int len_pos;
84 int element_type_pos;
85 } array;
86 } u;
87 };
88
93 struct DBusArrayLenFixup
94 {
95 int len_pos_in_reader;
96 int new_len;
97 };
98
99 DBUS_PRIVATE_EXPORT
100 void _dbus_type_reader_init (DBusTypeReader *reader,
101 int byte_order,
102 const DBusString *type_str,
103 int type_pos,
104 const DBusString *value_str,
105 int value_pos);
106 DBUS_PRIVATE_EXPORT
107 void _dbus_type_reader_init_types_only (DBusTypeReader *reader,
108 const DBusString *type_str,
109 int type_pos);
110 DBUS_PRIVATE_EXPORT
111 int _dbus_type_reader_get_current_type (const DBusTypeReader *reader);
112 DBUS_PRIVATE_EXPORT
113 int _dbus_type_reader_get_element_type (const DBusTypeReader *reader);
114 int _dbus_type_reader_get_value_pos (const DBusTypeReader *reader);
115 DBUS_PRIVATE_EXPORT
116 void _dbus_type_reader_read_basic (const DBusTypeReader *reader,
117 void *value);
118 int _dbus_type_reader_get_array_length (const DBusTypeReader *reader);
119 DBUS_PRIVATE_EXPORT
120 void _dbus_type_reader_read_fixed_multi (const DBusTypeReader *reader,
121 void *value,
122 int *n_elements);
123 void _dbus_type_reader_read_raw (const DBusTypeReader *reader,
124 const unsigned char **value_location);
125 DBUS_PRIVATE_EXPORT
126 void _dbus_type_reader_recurse (DBusTypeReader *reader,
127 DBusTypeReader *subreader);
128 DBUS_PRIVATE_EXPORT
129 dbus_bool_t _dbus_type_reader_next (DBusTypeReader *reader);
130 dbus_bool_t _dbus_type_reader_has_next (const DBusTypeReader *reader);
131 DBUS_PRIVATE_EXPORT
132 void _dbus_type_reader_get_signature (const DBusTypeReader *reader,
133 const DBusString **str_p,
134 int *start_p,
135 int *len_p);
136 DBUS_PRIVATE_EXPORT
137 dbus_bool_t _dbus_type_reader_set_basic (DBusTypeReader *reader,
138 const void *value,
139 const DBusTypeReader *realign_root);
140 DBUS_PRIVATE_EXPORT
141 dbus_bool_t _dbus_type_reader_delete (DBusTypeReader *reader,
142 const DBusTypeReader *realign_root);
143
144 dbus_bool_t _dbus_type_reader_equal_values (const DBusTypeReader *lhs,
145 const DBusTypeReader *rhs);
146
147 void _dbus_type_signature_next (const char *signature,
148 int *type_pos);
149
150 DBUS_PRIVATE_EXPORT
151 void _dbus_type_writer_init (DBusTypeWriter *writer,
152 int byte_order,
153 DBusString *type_str,
154 int type_pos,
155 DBusString *value_str,
156 int value_pos);
157 void _dbus_type_writer_init_types_delayed (DBusTypeWriter *writer,
158 int byte_order,
159 DBusString *value_str,
160 int value_pos);
161 void _dbus_type_writer_add_types (DBusTypeWriter *writer,
162 DBusString *type_str,
163 int type_pos);
164 void _dbus_type_writer_remove_types (DBusTypeWriter *writer);
165 DBUS_PRIVATE_EXPORT
166 void _dbus_type_writer_init_values_only (DBusTypeWriter *writer,
167 int byte_order,
168 const DBusString *type_str,
169 int type_pos,
170 DBusString *value_str,
171 int value_pos);
172 DBUS_PRIVATE_EXPORT
173 dbus_bool_t _dbus_type_writer_write_basic (DBusTypeWriter *writer,
174 int type,
175 const void *value);
176 DBUS_PRIVATE_EXPORT
177 dbus_bool_t _dbus_type_writer_write_fixed_multi (DBusTypeWriter *writer,
178 int element_type,
179 const void *value,
180 int n_elements);
181 DBUS_PRIVATE_EXPORT
182 dbus_bool_t _dbus_type_writer_recurse (DBusTypeWriter *writer,
183 int container_type,
184 const DBusString *contained_type,
185 int contained_type_start,
186 DBusTypeWriter *sub);
187 DBUS_PRIVATE_EXPORT
188 dbus_bool_t _dbus_type_writer_unrecurse (DBusTypeWriter *writer,
189 DBusTypeWriter *sub);
190 dbus_bool_t _dbus_type_writer_append_array (DBusTypeWriter *writer,
191 const DBusString *contained_type,
192 int contained_type_start,
193 DBusTypeWriter *sub);
194 DBUS_PRIVATE_EXPORT
195 dbus_bool_t _dbus_type_writer_write_reader (DBusTypeWriter *writer,
196 DBusTypeReader *reader);
197
198
199 #endif /* DBUS_MARSHAL_RECURSIVE_H */
DBusTypeReader::type_str
const DBusString * type_str
string containing signature of block
Definition: dbus-marshal-recursive.h:47
_dbus_type_reader_read_fixed_multi
DBUS_PRIVATE_EXPORT void _dbus_type_reader_read_fixed_multi(const DBusTypeReader *reader, void *value, int *n_elements)
Reads a block of fixed-length basic values, from the current point in an array to the end of the arra...
Definition: dbus-marshal-recursive.c:924
dbus_uint32_t
unsigned int dbus_uint32_t
A 32-bit unsigned integer on all platforms.
Definition: dbus-arch-deps.h:43
_dbus_type_writer_remove_types
void _dbus_type_writer_remove_types(DBusTypeWriter *writer)
Removes type string from the writer.
Definition: dbus-marshal-recursive.c:1564
DBusTypeReader::start_pos
int start_pos
for array readers, the start of the array values
Definition: dbus-marshal-recursive.h:56
DBusTypeWriter
The type writer is an iterator for writing to a block of values.
Definition: dbus-marshal-recursive.h:64
_dbus_type_reader_recurse
DBUS_PRIVATE_EXPORT void _dbus_type_reader_recurse(DBusTypeReader *reader, DBusTypeReader *subreader)
Initialize a new reader pointing to the first type and corresponding value that's a child of the curr...
Definition: dbus-marshal-recursive.c:989
DBusTypeReader::finished
dbus_uint32_t finished
marks we're at end iterator for cases where we don't have another way to tell
Definition: dbus-marshal-recursive.h:43
DBusTypeReader::type_pos
int type_pos
current position in signature
Definition: dbus-marshal-recursive.h:48
_dbus_type_signature_next
void _dbus_type_signature_next(const char *signature, int *type_pos)
Skips to the next "complete" type inside a type signature.
Definition: dbus-marshal-recursive.c:341
DBusTypeWriter::type_pos_is_expectation
dbus_uint32_t type_pos_is_expectation
type_pos can be either an insertion point for or an expected next type
Definition: dbus-marshal-recursive.h:70
DBusTypeReaderClass
Virtual table for a type reader.
Definition: dbus-marshal-recursive.c:125
_dbus_type_writer_write_basic
DBUS_PRIVATE_EXPORT dbus_bool_t _dbus_type_writer_write_basic(DBusTypeWriter *writer, int type, const void *value)
Writes out a basic type.
Definition: dbus-marshal-recursive.c:2312
_dbus_type_reader_init_types_only
DBUS_PRIVATE_EXPORT void _dbus_type_reader_init_types_only(DBusTypeReader *reader, const DBusString *type_str, int type_pos)
Like _dbus_type_reader_init() but the iteration is over the signature, not over values.
Definition: dbus-marshal-recursive.c:761
DBusArrayLenFixup::new_len
int new_len
the new value of the length in the written-out block
Definition: dbus-marshal-recursive.h:96
DBusTypeWriter::value_str
DBusString * value_str
where to write values
Definition: dbus-marshal-recursive.h:76
DBusTypeWriter::type_pos
int type_pos
current pos in type_str
Definition: dbus-marshal-recursive.h:75
DBusTypeWriter::type_str
DBusString * type_str
where to write typecodes (or read type expectations)
Definition: dbus-marshal-recursive.h:74
DBusTypeReader::klass
const DBusTypeReaderClass * klass
the vtable for the reader
Definition: dbus-marshal-recursive.h:52
_dbus_type_reader_delete
DBUS_PRIVATE_EXPORT dbus_bool_t _dbus_type_reader_delete(DBusTypeReader *reader, const DBusTypeReader *realign_root)
Recursively deletes any value pointed to by the reader, leaving the reader valid to continue reading.
Definition: dbus-marshal-recursive.c:1421
_dbus_type_writer_init_values_only
DBUS_PRIVATE_EXPORT void _dbus_type_writer_init_values_only(DBusTypeWriter *writer, int byte_order, const DBusString *type_str, int type_pos, DBusString *value_str, int value_pos)
Like _dbus_type_writer_init(), except the type string passed in should correspond to an existing sign...
Definition: dbus-marshal-recursive.c:1585
_dbus_type_reader_set_basic
DBUS_PRIVATE_EXPORT dbus_bool_t _dbus_type_reader_set_basic(DBusTypeReader *reader, const void *value, const DBusTypeReader *realign_root)
Sets a new value for the basic type value pointed to by the reader, leaving the reader valid to conti...
Definition: dbus-marshal-recursive.c:1364
_dbus_type_writer_init_types_delayed
void _dbus_type_writer_init_types_delayed(DBusTypeWriter *writer, int byte_order, DBusString *value_str, int value_pos)
Initialize a write iterator, with the signature to be provided later.
Definition: dbus-marshal-recursive.c:1529
DBusTypeWriter::element_type_pos
int element_type_pos
position of array element type in type_str
Definition: dbus-marshal-recursive.h:84
DBusString
Definition: dbus-string.h:42
_dbus_type_writer_unrecurse
DBUS_PRIVATE_EXPORT dbus_bool_t _dbus_type_writer_unrecurse(DBusTypeWriter *writer, DBusTypeWriter *sub)
Closes a container created by _dbus_type_writer_recurse() and writes any additional information to th...
Definition: dbus-marshal-recursive.c:2180
dbus_bool_t
dbus_uint32_t dbus_bool_t
A boolean, valid values are TRUE and FALSE.
Definition: dbus-types.h:35
_dbus_type_reader_read_basic
DBUS_PRIVATE_EXPORT void _dbus_type_reader_read_basic(const DBusTypeReader *reader, void *value)
Reads a basic-typed value, as with _dbus_marshal_read_basic().
Definition: dbus-marshal-recursive.c:870
DBusTypeWriter::len_pos
int len_pos
position of length of the array
Definition: dbus-marshal-recursive.h:83
_dbus_type_writer_append_array
dbus_bool_t _dbus_type_writer_append_array(DBusTypeWriter *writer, const DBusString *contained_type, int contained_type_start, DBusTypeWriter *sub)
Append to an existing array.
Definition: dbus-marshal-recursive.c:2144
_dbus_type_reader_next
DBUS_PRIVATE_EXPORT dbus_bool_t _dbus_type_reader_next(DBusTypeReader *reader)
Skip to the next value on this "level".
Definition: dbus-marshal-recursive.c:1055
DBusArrayLenFixup
When modifying an existing block of values, array lengths may need to be adjusted; those adjustments ...
Definition: dbus-marshal-recursive.h:93
DBusTypeWriter::enabled
dbus_uint32_t enabled
whether to write values
Definition: dbus-marshal-recursive.h:72
DBusTypeReader::byte_order
dbus_uint32_t byte_order
byte order of the block
Definition: dbus-marshal-recursive.h:41
DBusTypeWriter::byte_order
dbus_uint32_t byte_order
byte order to write values with
Definition: dbus-marshal-recursive.h:66
DBusTypeReader
The type reader is an iterator for reading values from a block of values.
Definition: dbus-marshal-recursive.h:39
_dbus_type_writer_add_types
void _dbus_type_writer_add_types(DBusTypeWriter *writer, DBusString *type_str, int type_pos)
Adds type string to the writer, if it had none.
Definition: dbus-marshal-recursive.c:1547
_dbus_type_writer_write_reader
DBUS_PRIVATE_EXPORT dbus_bool_t _dbus_type_writer_write_reader(DBusTypeWriter *writer, DBusTypeReader *reader)
Iterate through all values in the given reader, writing a copy of each value to the writer.
Definition: dbus-marshal-recursive.c:2732
DBusTypeWriter::value_pos
int value_pos
next position to write
Definition: dbus-marshal-recursive.h:77
_dbus_type_reader_init
DBUS_PRIVATE_EXPORT void _dbus_type_reader_init(DBusTypeReader *reader, int byte_order, const DBusString *type_str, int type_pos, const DBusString *value_str, int value_pos)
Initializes a type reader.
Definition: dbus-marshal-recursive.c:733
DBusTypeReader::u
union DBusTypeReader::@1 u
class-specific data
DBusArrayLenFixup::len_pos_in_reader
int len_pos_in_reader
where the length was in the original block
Definition: dbus-marshal-recursive.h:95
_dbus_type_reader_get_element_type
DBUS_PRIVATE_EXPORT int _dbus_type_reader_get_element_type(const DBusTypeReader *reader)
Gets the type of an element of the array the reader is currently pointing to.
Definition: dbus-marshal-recursive.c:821
_dbus_type_writer_init
DBUS_PRIVATE_EXPORT void _dbus_type_writer_init(DBusTypeWriter *writer, int byte_order, DBusString *type_str, int type_pos, DBusString *value_str, int value_pos)
Initialize a write iterator, which is used to write out values in serialized D-Bus format.
Definition: dbus-marshal-recursive.c:1494
DBusTypeWriter::u
union DBusTypeWriter::@3 u
class-specific data
_dbus_type_reader_has_next
dbus_bool_t _dbus_type_reader_has_next(const DBusTypeReader *reader)
Check whether there's another value on this "level".
Definition: dbus-marshal-recursive.c:1095
DBusTypeWriter::container_type
dbus_uint32_t container_type
what are we inside? (e.g.
Definition: dbus-marshal-recursive.h:68
_dbus_type_reader_get_array_length
int _dbus_type_reader_get_array_length(const DBusTypeReader *reader)
Returns the number of bytes in the array.
Definition: dbus-marshal-recursive.c:900
_dbus_type_reader_get_current_type
DBUS_PRIVATE_EXPORT int _dbus_type_reader_get_current_type(const DBusTypeReader *reader)
Gets the type of the value the reader is currently pointing to; or for a types-only reader gets the t...
Definition: dbus-marshal-recursive.c:786
_dbus_type_reader_get_signature
DBUS_PRIVATE_EXPORT void _dbus_type_reader_get_signature(const DBusTypeReader *reader, const DBusString **str_p, int *start_p, int *len_p)
Gets the string and range of said string containing the signature of the current value.
Definition: dbus-marshal-recursive.c:1126
_dbus_type_writer_write_fixed_multi
DBUS_PRIVATE_EXPORT dbus_bool_t _dbus_type_writer_write_fixed_multi(DBusTypeWriter *writer, int element_type, const void *value, int n_elements)
Writes a block of fixed-length basic values, i.e.
Definition: dbus-marshal-recursive.c:2360
DBusTypeReader::array_len_offset
dbus_uint32_t array_len_offset
bytes back from start_pos that len ends
Definition: dbus-marshal-recursive.h:46
DBusTypeReader::value_pos
int value_pos
current position in values
Definition: dbus-marshal-recursive.h:50
DBusTypeWriter::start_pos
int start_pos
position of first element in the array
Definition: dbus-marshal-recursive.h:82
DBusTypeReader::value_str
const DBusString * value_str
string containing values of block
Definition: dbus-marshal-recursive.h:49
_dbus_type_writer_recurse
DBUS_PRIVATE_EXPORT dbus_bool_t _dbus_type_writer_recurse(DBusTypeWriter *writer, int container_type, const DBusString *contained_type, int contained_type_start, DBusTypeWriter *sub)
Opens a new container and writes out the initial information for that container.
Definition: dbus-marshal-recursive.c:2110
_dbus_type_reader_get_value_pos
int _dbus_type_reader_get_value_pos(const DBusTypeReader *reader)
Gets the current position in the value block.
Definition: dbus-marshal-recursive.c:838
_dbus_type_reader_read_raw
void _dbus_type_reader_read_raw(const DBusTypeReader *reader, const unsigned char **value_location)
Get the address of the marshaled value in the data being read.
Definition: dbus-marshal-recursive.c:853