chop dbus-marshal-basic in half and move it to be insertion rather than append based
[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-marshal-basic.h> /* this can become protocol.h when we merge */
29
30 #ifndef PACKAGE
31 #error "config.h not included here"
32 #endif
33
34 /* Features we need to port dbus-message:
35  *  - memoize a position of a reader for small/fast access later
36  *  - delete an array element and re-align the remainder of the array
37  *    (not necessary yet to re-align remainder of entire string,
38  *     though that's probably just as hard/easy)
39  *  - set string, int, etc. values at a memoized position
40  *    (implement generic set of any value? changes only
41  *     value_str not type_str)
42  *  - implement has_next()
43  *  - the all-in-one-block array accessors
44  *  - validation
45  */
46
47 typedef struct DBusTypeReader      DBusTypeReader;
48 typedef struct DBusTypeWriter      DBusTypeWriter;
49 typedef struct DBusTypeReaderClass DBusTypeReaderClass;
50
51 struct DBusTypeReader
52 {
53   dbus_uint32_t byte_order : 8;
54
55   dbus_uint32_t finished : 1;   /* marks we're at end iterator for cases
56                                  * where we don't have another way to tell
57                                  */
58   const DBusString *type_str;
59   int type_pos;
60   const DBusString *value_str;
61   int value_pos;
62
63   const DBusTypeReaderClass *klass;
64   union
65   {
66     struct {
67       int start_pos;
68       dbus_uint32_t len;
69       int element_type;
70     } array;
71   } u;
72 };
73
74 struct DBusTypeWriter
75 {
76   dbus_uint32_t byte_order : 8;
77
78   dbus_uint32_t container_type : 8;
79
80   dbus_uint32_t type_pos_is_expectation : 1; /* type_pos is an insertion point or an expected next type */
81   DBusString *type_str;
82   int type_pos;
83   DBusString *value_str;
84   int value_pos;
85
86   union
87   {
88     struct {
89       int start_pos; /* first element */
90       int len_pos;
91       int element_type_pos; /* position of array element type in type_str */
92     } array;
93   } u;
94 };
95
96 void        _dbus_type_reader_init                (DBusTypeReader    *reader,
97                                                    int                byte_order,
98                                                    const DBusString  *type_str,
99                                                    int                type_pos,
100                                                    const DBusString  *value_str,
101                                                    int                value_pos);
102 void        _dbus_type_reader_init_types_only     (DBusTypeReader    *reader,
103                                                    const DBusString  *type_str,
104                                                    int                type_pos);
105 int         _dbus_type_reader_get_current_type    (DBusTypeReader    *reader);
106 dbus_bool_t _dbus_type_reader_array_is_empty      (DBusTypeReader    *reader);
107 void        _dbus_type_reader_read_basic          (DBusTypeReader    *reader,
108                                                    void              *value);
109 dbus_bool_t _dbus_type_reader_read_array_of_basic (DBusTypeReader    *reader,
110                                                    int                type,
111                                                    void             **array,
112                                                    int               *array_len);
113 void        _dbus_type_reader_recurse             (DBusTypeReader    *reader,
114                                                    DBusTypeReader    *subreader);
115 dbus_bool_t _dbus_type_reader_next                (DBusTypeReader    *reader);
116
117 void        _dbus_type_writer_init            (DBusTypeWriter *writer,
118                                                int             byte_order,
119                                                DBusString     *type_str,
120                                                int             type_pos,
121                                                DBusString     *value_str,
122                                                int             value_pos);
123 dbus_bool_t _dbus_type_writer_write_basic     (DBusTypeWriter *writer,
124                                                int             type,
125                                                const void     *value);
126 dbus_bool_t _dbus_type_writer_write_array     (DBusTypeWriter *writer,
127                                                int             type,
128                                                const void     *array,
129                                                int             array_len);
130 dbus_bool_t _dbus_type_writer_recurse_struct  (DBusTypeWriter *writer,
131                                                DBusTypeWriter *sub);
132 dbus_bool_t _dbus_type_writer_recurse_array   (DBusTypeWriter *writer,
133                                                const char     *element_type,
134                                                DBusTypeWriter *sub);
135 dbus_bool_t _dbus_type_writer_recurse_variant (DBusTypeWriter *writer,
136                                                const char     *contained_type,
137                                                DBusTypeWriter *sub);
138 dbus_bool_t _dbus_type_writer_unrecurse       (DBusTypeWriter *writer,
139                                                DBusTypeWriter *sub);
140
141
142
143 #endif /* DBUS_MARSHAL_RECURSIVE_H */