implement _dbus_type_writer_write_reader() (to copy a block of values)
[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
51 typedef struct DBusTypeMark        DBusTypeMark;
52 typedef struct DBusTypeReader      DBusTypeReader;
53 typedef struct DBusTypeWriter      DBusTypeWriter;
54 typedef struct DBusTypeReaderClass DBusTypeReaderClass;
55
56 /* The mark is a way to compress a TypeReader; it isn't all that
57  * successful though.
58  */
59 struct DBusTypeMark
60 {
61   dbus_uint32_t type_pos_in_value_str : 1;
62   dbus_uint32_t container_type : 3;
63   dbus_uint32_t array_len_offset : 3; /* bytes back from start_pos that len ends */
64   dbus_uint32_t type_pos : DBUS_MAXIMUM_MESSAGE_LENGTH_BITS;
65   dbus_uint32_t value_pos : DBUS_MAXIMUM_MESSAGE_LENGTH_BITS;
66   dbus_uint32_t array_start_pos : DBUS_MAXIMUM_MESSAGE_LENGTH_BITS;
67 };
68
69 struct DBusTypeReader
70 {
71   dbus_uint32_t byte_order : 8;
72
73   dbus_uint32_t finished : 1;   /* marks we're at end iterator for cases
74                                  * where we don't have another way to tell
75                                  */
76   dbus_uint32_t array_len_offset : 3; /* bytes back from start_pos that len ends */
77   const DBusString *type_str;
78   int type_pos;
79   const DBusString *value_str;
80   int value_pos;
81
82   const DBusTypeReaderClass *klass;
83   union
84   {
85     struct {
86       int start_pos;
87     } array;
88   } u;
89 };
90
91 struct DBusTypeWriter
92 {
93   dbus_uint32_t byte_order : 8;
94
95   dbus_uint32_t container_type : 8;
96
97   dbus_uint32_t type_pos_is_expectation : 1; /* type_pos is an insertion point or an expected next type */
98   DBusString *type_str;
99   int type_pos;
100   DBusString *value_str;
101   int value_pos;
102
103   union
104   {
105     struct {
106       int start_pos; /* first element */
107       int len_pos;
108       int element_type_pos; /* position of array element type in type_str */
109     } array;
110   } u;
111 };
112
113 void        _dbus_type_reader_init                      (DBusTypeReader        *reader,
114                                                          int                    byte_order,
115                                                          const DBusString      *type_str,
116                                                          int                    type_pos,
117                                                          const DBusString      *value_str,
118                                                          int                    value_pos);
119 void        _dbus_type_reader_init_from_mark            (DBusTypeReader        *reader,
120                                                          int                    byte_order,
121                                                          const DBusString      *type_str,
122                                                          const DBusString      *value_str,
123                                                          const DBusTypeMark    *mark);
124 void        _dbus_type_reader_init_types_only           (DBusTypeReader        *reader,
125                                                          const DBusString      *type_str,
126                                                          int                    type_pos);
127 void        _dbus_type_reader_init_types_only_from_mark (DBusTypeReader        *reader,
128                                                          const DBusString      *type_str,
129                                                          const DBusTypeMark    *mark);
130 void        _dbus_type_reader_save_mark                 (const DBusTypeReader  *reader,
131                                                          DBusTypeMark          *mark);
132 int         _dbus_type_reader_get_current_type          (const DBusTypeReader  *reader);
133 dbus_bool_t _dbus_type_reader_array_is_empty            (const DBusTypeReader  *reader);
134 void        _dbus_type_reader_read_basic                (const DBusTypeReader  *reader,
135                                                          void                  *value);
136 dbus_bool_t _dbus_type_reader_read_array_of_basic       (const DBusTypeReader  *reader,
137                                                          int                    type,
138                                                          void                 **array,
139                                                          int                   *array_len);
140 void        _dbus_type_reader_recurse                   (DBusTypeReader        *reader,
141                                                          DBusTypeReader        *subreader);
142 dbus_bool_t _dbus_type_reader_next                      (DBusTypeReader        *reader);
143 dbus_bool_t _dbus_type_reader_has_next                  (const DBusTypeReader  *reader);
144 void        _dbus_type_reader_get_signature             (const DBusTypeReader  *reader,
145                                                          const DBusString     **str_p,
146                                                          int                   *start_p,
147                                                          int                   *len_p);
148
149 void        _dbus_type_writer_init            (DBusTypeWriter *writer,
150                                                int             byte_order,
151                                                DBusString     *type_str,
152                                                int             type_pos,
153                                                DBusString     *value_str,
154                                                int             value_pos);
155 dbus_bool_t _dbus_type_writer_write_basic     (DBusTypeWriter *writer,
156                                                int             type,
157                                                const void     *value);
158 dbus_bool_t _dbus_type_writer_write_array     (DBusTypeWriter *writer,
159                                                int             type,
160                                                const void     *array,
161                                                int             array_len);
162 dbus_bool_t _dbus_type_writer_recurse_struct  (DBusTypeWriter *writer,
163                                                DBusTypeWriter *sub);
164 dbus_bool_t _dbus_type_writer_recurse_array   (DBusTypeWriter *writer,
165                                                const char     *element_type,
166                                                DBusTypeWriter *sub);
167 dbus_bool_t _dbus_type_writer_recurse_variant (DBusTypeWriter *writer,
168                                                const char     *contained_type,
169                                                DBusTypeWriter *sub);
170 dbus_bool_t _dbus_type_writer_unrecurse       (DBusTypeWriter *writer,
171                                                DBusTypeWriter *sub);
172 dbus_bool_t _dbus_type_writer_write_reader    (DBusTypeWriter *writer,
173                                                DBusTypeReader *reader);
174
175
176 #endif /* DBUS_MARSHAL_RECURSIVE_H */