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