bus: Assign a serial number for messages from the driver
[platform/upstream/dbus.git] / dbus / 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  * Copyright (C) 2015  Samsung Electronics
6  *
7  * Licensed under the Academic Free License version 2.1
8  *
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.
13  *
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.
18  *
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
22  *
23  */
24
25 #ifndef DBUS_MARSHAL_RECURSIVE_H
26 #define DBUS_MARSHAL_RECURSIVE_H
27
28 #include <dbus/dbus-protocol.h>
29 #include <dbus/dbus-list.h>
30
31 typedef struct DBusTypeReader      DBusTypeReader;
32 typedef struct DBusTypeWriter      DBusTypeWriter;
33 typedef struct DBusTypeReaderClass DBusTypeReaderClass;
34 typedef struct DBusArrayLenFixup   DBusArrayLenFixup;
35
36 /**
37  * The type reader is an iterator for reading values from a block of
38  * values.
39  */
40 struct DBusTypeReader
41 {
42   dbus_uint32_t byte_order : 8; /**< byte order of the block */
43
44   dbus_uint32_t finished : 1;   /**< marks we're at end iterator for cases
45                                  * where we don't have another way to tell
46                                  */
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 */
59
60   const DBusTypeReaderClass *klass; /**< the vtable for the reader */
61   union
62   {
63     struct {
64       int start_pos;                /**< for array readers, the start of the array values */
65     } array;
66   } u; /**< class-specific data */
67 };
68
69 /**
70  * The type writer is an iterator for writing to a block of values.
71  */
72 struct DBusTypeWriter
73 {
74   dbus_uint32_t byte_order : 8;            /**< byte order to write values with */
75
76   dbus_uint32_t container_type : 8;        /**< what are we inside? (e.g. struct, variant, array) */
77
78   dbus_uint32_t type_pos_is_expectation : 1; /**< type_pos can be either an insertion point for or an expected next type */
79
80   dbus_uint32_t enabled : 1; /**< whether to write values */
81
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 */
85
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 */
94
95   union
96   {
97     struct {
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 */
101     } array;
102     struct {
103       size_t last_offset; /**< for GVariant marshalling: position of end of last field */
104     } struct_or_dict;
105     struct {
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 */
108     } root;
109   } u; /**< class-specific data */
110 };
111
112 /**
113  * When modifying an existing block of values, array lengths may need
114  * to be adjusted; those adjustments are described by this struct.
115  */
116 struct DBusArrayLenFixup
117 {
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 */
120 };
121
122 DBUS_PRIVATE_EXPORT
123 void        _dbus_type_reader_init                      (DBusTypeReader        *reader,
124                                                          int                    byte_order,
125                                                          const DBusString      *type_str,
126                                                          int                    type_pos,
127                                                          const DBusString      *value_str,
128                                                          int                    value_pos);
129 DBUS_PRIVATE_EXPORT
130 void        _dbus_type_reader_init_types_only           (DBusTypeReader        *reader,
131                                                          const DBusString      *type_str,
132                                                          int                    type_pos);
133 DBUS_PRIVATE_EXPORT
134 int         _dbus_type_reader_get_current_type          (const DBusTypeReader  *reader);
135 DBUS_PRIVATE_EXPORT
136 int         _dbus_type_reader_get_element_type          (const DBusTypeReader  *reader);
137 int         _dbus_type_reader_get_value_pos             (const DBusTypeReader  *reader);
138 DBUS_PRIVATE_EXPORT
139 void        _dbus_type_reader_read_basic                (const DBusTypeReader  *reader,
140                                                          void                  *value);
141 int         _dbus_type_reader_get_array_length          (const DBusTypeReader  *reader);
142 DBUS_PRIVATE_EXPORT
143 void        _dbus_type_reader_read_fixed_multi          (const DBusTypeReader  *reader,
144                                                          void                  *value,
145                                                          int                   *n_elements);
146 void        _dbus_type_reader_read_raw                  (const DBusTypeReader  *reader,
147                                                          const unsigned char  **value_location);
148 DBUS_PRIVATE_EXPORT
149 void        _dbus_type_reader_recurse                   (DBusTypeReader        *reader,
150                                                          DBusTypeReader        *subreader);
151 DBUS_PRIVATE_EXPORT
152 dbus_bool_t _dbus_type_reader_next                      (DBusTypeReader        *reader);
153 dbus_bool_t _dbus_type_reader_has_next                  (const DBusTypeReader  *reader);
154 DBUS_PRIVATE_EXPORT
155 void        _dbus_type_reader_get_signature             (const DBusTypeReader  *reader,
156                                                          const DBusString     **str_p,
157                                                          int                   *start_p,
158                                                          int                   *len_p);
159 DBUS_PRIVATE_EXPORT
160 dbus_bool_t _dbus_type_reader_set_basic                 (DBusTypeReader        *reader,
161                                                          const void            *value,
162                                                          const DBusTypeReader  *realign_root);
163 DBUS_PRIVATE_EXPORT
164 dbus_bool_t _dbus_type_reader_delete                    (DBusTypeReader        *reader,
165                                                          const DBusTypeReader  *realign_root);
166
167 dbus_bool_t _dbus_type_reader_equal_values              (const DBusTypeReader *lhs,
168                                                          const DBusTypeReader *rhs);
169
170 void        _dbus_type_signature_next                   (const char            *signature,
171                                                          int                   *type_pos);
172
173 DBUS_PRIVATE_EXPORT
174 void        _dbus_type_writer_init                 (DBusTypeWriter        *writer,
175                                                     int                    byte_order,
176                                                     DBusString            *type_str,
177                                                     int                    type_pos,
178                                                     DBusString            *value_str,
179                                                     int                    value_pos);
180 void        _dbus_type_writer_init_types_delayed   (DBusTypeWriter        *writer,
181                                                     int                    byte_order,
182                                                     DBusString            *value_str,
183                                                     int                    value_pos);
184 void        _dbus_type_writer_gvariant_init_types_delayed   (DBusTypeWriter        *writer,
185                                                              int                    byte_order,
186                                                              DBusString            *value_str,
187                                                              int                    value_pos,
188                                                              dbus_bool_t            gvariant,
189                                                              size_t                *last_offset,
190                                                              size_t                *last_pos);
191 void        _dbus_type_writer_add_types            (DBusTypeWriter        *writer,
192                                                     DBusString            *type_str,
193                                                     int                    type_pos);
194 void        _dbus_type_writer_remove_types         (DBusTypeWriter        *writer);
195 DBUS_PRIVATE_EXPORT
196 void        _dbus_type_writer_init_values_only     (DBusTypeWriter        *writer,
197                                                     int                    byte_order,
198                                                     const DBusString      *type_str,
199                                                     int                    type_pos,
200                                                     DBusString            *value_str,
201                                                     int                    value_pos);
202 DBUS_PRIVATE_EXPORT
203 dbus_bool_t _dbus_type_writer_write_basic          (DBusTypeWriter        *writer,
204                                                     int                    type,
205                                                     const void            *value);
206 DBUS_PRIVATE_EXPORT
207 dbus_bool_t _dbus_type_writer_write_basic_with_gvariant
208                                                    (DBusTypeWriter        *writer,
209                                                     int                    type,
210                                                     const void            *value,
211                                                     dbus_bool_t            gvariant);
212 DBUS_PRIVATE_EXPORT
213 dbus_bool_t _dbus_type_writer_write_fixed_multi    (DBusTypeWriter        *writer,
214                                                     int                    element_type,
215                                                     const void            *value,
216                                                     int                    n_elements);
217 DBUS_PRIVATE_EXPORT
218 dbus_bool_t _dbus_type_writer_recurse              (DBusTypeWriter        *writer,
219                                                     int                    container_type,
220                                                     const DBusString      *contained_type,
221                                                     int                    contained_type_start,
222                                                     DBusTypeWriter        *sub);
223 DBUS_PRIVATE_EXPORT
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);
230 DBUS_PRIVATE_EXPORT
231 dbus_bool_t _dbus_type_writer_write_reader         (DBusTypeWriter        *writer,
232                                                     DBusTypeReader        *reader);
233
234
235 #endif /* DBUS_MARSHAL_RECURSIVE_H */