Merge branch 'dbus-1.2'
[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  *
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 <config.h>
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   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 */
52
53   const DBusTypeReaderClass *klass; /**< the vtable for the reader */
54   union
55   {
56     struct {
57       int start_pos;                /**< for array readers, the start of the array values */
58     } array;
59   } u; /**< class-specific data */
60 };
61
62 /**
63  * The type writer is an iterator for writing to a block of values.
64  */
65 struct DBusTypeWriter
66 {
67   dbus_uint32_t byte_order : 8;            /**< byte order to write values with */
68
69   dbus_uint32_t container_type : 8;        /**< what are we inside? (e.g. struct, variant, array) */
70
71   dbus_uint32_t type_pos_is_expectation : 1; /**< type_pos can be either an insertion point for or an expected next type */
72
73   dbus_uint32_t enabled : 1; /**< whether to write values */
74
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 */
79
80   union
81   {
82     struct {
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 */
86     } array;
87   } u; /**< class-specific data */
88 };
89
90 /**
91  * When modifying an existing block of values, array lengths may need
92  * to be adjusted; those adjustments are described by this struct.
93  */
94 struct DBusArrayLenFixup
95 {
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 */
98 };
99
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 void        _dbus_type_reader_init_types_only           (DBusTypeReader        *reader,
107                                                          const DBusString      *type_str,
108                                                          int                    type_pos);
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,
113                                                          void                  *value);
114 int         _dbus_type_reader_get_array_length          (const DBusTypeReader  *reader);
115 void        _dbus_type_reader_read_fixed_multi          (const DBusTypeReader  *reader,
116                                                          void                  *value,
117                                                          int                   *n_elements);
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,
126                                                          int                   *start_p,
127                                                          int                   *len_p);
128 dbus_bool_t _dbus_type_reader_set_basic                 (DBusTypeReader        *reader,
129                                                          const void            *value,
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);
135
136 dbus_bool_t _dbus_type_reader_equal_values              (const DBusTypeReader *lhs,
137                                                          const DBusTypeReader *rhs);
138
139 void        _dbus_type_signature_next                   (const char            *signature,
140                                                          int                   *type_pos);
141
142 void        _dbus_type_writer_init                 (DBusTypeWriter        *writer,
143                                                     int                    byte_order,
144                                                     DBusString            *type_str,
145                                                     int                    type_pos,
146                                                     DBusString            *value_str,
147                                                     int                    value_pos);
148 void        _dbus_type_writer_init_types_delayed   (DBusTypeWriter        *writer,
149                                                     int                    byte_order,
150                                                     DBusString            *value_str,
151                                                     int                    value_pos);
152 void        _dbus_type_writer_add_types            (DBusTypeWriter        *writer,
153                                                     DBusString            *type_str,
154                                                     int                    type_pos);
155 void        _dbus_type_writer_remove_types         (DBusTypeWriter        *writer);
156 void        _dbus_type_writer_init_values_only     (DBusTypeWriter        *writer,
157                                                     int                    byte_order,
158                                                     const DBusString      *type_str,
159                                                     int                    type_pos,
160                                                     DBusString            *value_str,
161                                                     int                    value_pos);
162 dbus_bool_t _dbus_type_writer_write_basic          (DBusTypeWriter        *writer,
163                                                     int                    type,
164                                                     const void            *value);
165 dbus_bool_t _dbus_type_writer_write_fixed_multi    (DBusTypeWriter        *writer,
166                                                     int                    element_type,
167                                                     const void            *value,
168                                                     int                    n_elements);
169 dbus_bool_t _dbus_type_writer_recurse              (DBusTypeWriter        *writer,
170                                                     int                    container_type,
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,
187                                                     DBusList             **fixups);
188 void        _dbus_type_writer_set_enabled          (DBusTypeWriter        *writer,
189                                                     dbus_bool_t            enabled);
190
191
192 #endif /* DBUS_MARSHAL_RECURSIVE_H */