finish off my TODO list for stuff needed to port dbus-message.c. Next
[platform/upstream/dbus.git] / dbus / dbus-marshal-recursive.h
1 /* -*- mode: C; c-file-style: "gnu" -*- */
2 /* dbus-marshal-recursive.h  Marshalling routines for recursive types
3  *
4  * Copyright (C) 2004 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  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 #include <dbus/dbus-marshal-basic.h> /* this can vanish when we merge */
31
32 #ifndef PACKAGE
33 #error "config.h not included here"
34 #endif
35
36 /* Features we need to port dbus-message:
37  *  - memoize a position of a reader for small/fast access later
38  *  - delete an array element and re-align the remainder of the array
39  *    (not necessary yet to re-align remainder of entire string,
40  *     though that's probably just as hard/easy)
41  *    (really this one is to set a complex-type array element to
42  *    a new value, but for dbus-message.c delete-and-reappend would
43  *    be good enough)
44  *  - set string, int, etc. values at a memoized position
45  *    (implement generic set of any value? changes only
46  *     value_str not type_str)
47  *  - implement has_next()
48  *  - the all-in-one-block array accessors
49  *  - validation
50  *
51  * - remember to try a HAVE_INT64=0 build at the end
52  */
53
54 typedef struct DBusTypeMark        DBusTypeMark;
55 typedef struct DBusTypeReader      DBusTypeReader;
56 typedef struct DBusTypeWriter      DBusTypeWriter;
57 typedef struct DBusTypeReaderClass DBusTypeReaderClass;
58 typedef struct DBusArrayLenFixup   DBusArrayLenFixup;
59
60 /* The mark is a way to compress a TypeReader; it isn't all that
61  * successful though. The idea was to use this for caching header
62  * fields in dbus-message.c. However now I'm thinking why not cache
63  * the actual values (e.g. char*) and if the field needs to be set or
64  * deleted, just linear search for it. Those operations are uncommon,
65  * and getting the values should be fast and not involve all this type
66  * reader nonsense.
67  */
68 struct DBusTypeMark
69 {
70   dbus_uint32_t type_pos_in_value_str : 1;
71   dbus_uint32_t container_type : 3;
72   dbus_uint32_t array_len_offset : 3; /* bytes back from start_pos that len ends */
73   dbus_uint32_t type_pos : DBUS_MAXIMUM_MESSAGE_LENGTH_BITS;
74   dbus_uint32_t value_pos : DBUS_MAXIMUM_MESSAGE_LENGTH_BITS;
75   dbus_uint32_t array_start_pos : DBUS_MAXIMUM_MESSAGE_LENGTH_BITS;
76 };
77
78 struct DBusTypeReader
79 {
80   dbus_uint32_t byte_order : 8;
81
82   dbus_uint32_t finished : 1;   /* marks we're at end iterator for cases
83                                  * where we don't have another way to tell
84                                  */
85   dbus_uint32_t array_len_offset : 3; /* bytes back from start_pos that len ends */
86   const DBusString *type_str;
87   int type_pos;
88   const DBusString *value_str;
89   int value_pos;
90
91   const DBusTypeReaderClass *klass;
92   union
93   {
94     struct {
95       int start_pos;
96     } array;
97   } u;
98 };
99
100 struct DBusTypeWriter
101 {
102   dbus_uint32_t byte_order : 8;
103
104   dbus_uint32_t container_type : 8;
105
106   dbus_uint32_t type_pos_is_expectation : 1; /* type_pos is an insertion point or an expected next type */
107
108   dbus_uint32_t enabled : 1; /* whether to write values */
109
110   DBusString *type_str;
111   int type_pos;
112   DBusString *value_str;
113   int value_pos;
114
115   union
116   {
117     struct {
118       int start_pos; /* first element */
119       int len_pos;
120       int element_type_pos; /* position of array element type in type_str */
121     } array;
122   } u;
123 };
124
125 struct DBusArrayLenFixup
126 {
127   int len_pos_in_reader;
128   int new_len;
129 };
130
131 void        _dbus_type_reader_init                      (DBusTypeReader        *reader,
132                                                          int                    byte_order,
133                                                          const DBusString      *type_str,
134                                                          int                    type_pos,
135                                                          const DBusString      *value_str,
136                                                          int                    value_pos);
137 void        _dbus_type_reader_init_from_mark            (DBusTypeReader        *reader,
138                                                          int                    byte_order,
139                                                          const DBusString      *type_str,
140                                                          const DBusString      *value_str,
141                                                          const DBusTypeMark    *mark);
142 void        _dbus_type_reader_init_types_only           (DBusTypeReader        *reader,
143                                                          const DBusString      *type_str,
144                                                          int                    type_pos);
145 void        _dbus_type_reader_init_types_only_from_mark (DBusTypeReader        *reader,
146                                                          const DBusString      *type_str,
147                                                          const DBusTypeMark    *mark);
148 void        _dbus_type_reader_save_mark                 (const DBusTypeReader  *reader,
149                                                          DBusTypeMark          *mark);
150 int         _dbus_type_reader_get_current_type          (const DBusTypeReader  *reader);
151 dbus_bool_t _dbus_type_reader_array_is_empty            (const DBusTypeReader  *reader);
152 void        _dbus_type_reader_read_basic                (const DBusTypeReader  *reader,
153                                                          void                  *value);
154 void        _dbus_type_reader_read_fixed_array          (const DBusTypeReader  *reader,
155                                                          void                  *value,
156                                                          int                   *n_elements);
157 void        _dbus_type_reader_recurse                   (DBusTypeReader        *reader,
158                                                          DBusTypeReader        *subreader);
159 dbus_bool_t _dbus_type_reader_next                      (DBusTypeReader        *reader);
160 dbus_bool_t _dbus_type_reader_has_next                  (const DBusTypeReader  *reader);
161 void        _dbus_type_reader_get_signature             (const DBusTypeReader  *reader,
162                                                          const DBusString     **str_p,
163                                                          int                   *start_p,
164                                                          int                   *len_p);
165 dbus_bool_t _dbus_type_reader_set_basic                 (DBusTypeReader        *reader,
166                                                          const void            *value,
167                                                          const DBusTypeReader  *realign_root);
168 dbus_bool_t _dbus_type_reader_delete                    (DBusTypeReader        *reader,
169                                                          const DBusTypeReader  *realign_root);
170 dbus_bool_t _dbus_type_reader_greater_than              (const DBusTypeReader  *lhs,
171                                                          const DBusTypeReader  *rhs);
172
173 void        _dbus_type_writer_init                 (DBusTypeWriter        *writer,
174                                                     int                    byte_order,
175                                                     DBusString            *type_str,
176                                                     int                    type_pos,
177                                                     DBusString            *value_str,
178                                                     int                    value_pos);
179 void        _dbus_type_writer_init_values_only     (DBusTypeWriter        *writer,
180                                                     int                    byte_order,
181                                                     const DBusString      *type_str,
182                                                     int                    type_pos,
183                                                     DBusString            *value_str,
184                                                     int                    value_pos);
185 dbus_bool_t _dbus_type_writer_write_basic          (DBusTypeWriter        *writer,
186                                                     int                    type,
187                                                     const void            *value);
188 dbus_bool_t _dbus_type_writer_write_fixed_array    (DBusTypeWriter        *writer,
189                                                     int                    element_type,
190                                                     const void            *value,
191                                                     int                    n_elements);
192 dbus_bool_t _dbus_type_writer_recurse              (DBusTypeWriter        *writer,
193                                                     int                    container_type,
194                                                     const DBusString      *contained_type,
195                                                     int                    contained_type_start,
196                                                     DBusTypeWriter        *sub);
197 dbus_bool_t _dbus_type_writer_unrecurse            (DBusTypeWriter        *writer,
198                                                     DBusTypeWriter        *sub);
199 dbus_bool_t _dbus_type_writer_write_reader         (DBusTypeWriter        *writer,
200                                                     DBusTypeReader        *reader);
201 dbus_bool_t _dbus_type_writer_write_reader_partial (DBusTypeWriter        *writer,
202                                                     DBusTypeReader        *reader,
203                                                     const DBusTypeReader  *start_after,
204                                                     int                    start_after_new_pos,
205                                                     int                    start_after_new_len,
206                                                     DBusList             **fixups);
207 void        _dbus_type_writer_set_enabled          (DBusTypeWriter        *writer,
208                                                     dbus_bool_t            enabled);
209
210
211
212 #endif /* DBUS_MARSHAL_RECURSIVE_H */