add "types only" TypeReader, will move to use a vtable instead of a flag in a minute
[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>
29
30 #ifndef PACKAGE
31 #error "config.h not included here"
32 #endif
33
34 typedef struct DBusTypeReader      DBusTypeReader;
35 typedef struct DBusTypeWriter      DBusTypeWriter;
36 typedef struct DBusTypeReaderClass DBusTypeReaderClass;
37
38 struct DBusTypeReader
39 {
40   dbus_uint32_t byte_order : 8;
41
42   dbus_uint32_t types_only : 1; /* iterate over types not values */
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   const DBusString *type_str;
48   int type_pos;
49   const DBusString *value_str;
50   int value_pos;
51
52   const DBusTypeReaderClass *klass;
53   union
54   {
55     struct {
56       int start_pos;
57       dbus_uint32_t len;
58       int element_type;
59     } array;
60   } u;
61 };
62
63 struct DBusTypeWriter
64 {
65   dbus_uint32_t byte_order : 8;
66
67   dbus_uint32_t container_type : 8;
68
69   dbus_uint32_t type_pos_is_expectation : 1; /* type_pos is an insertion point or an expected next type */
70   DBusString *type_str;
71   int type_pos;
72   DBusString *value_str;
73   int value_pos;
74
75   union
76   {
77     struct {
78       int start_pos; /* first element */
79       int len_pos;
80       int element_type_pos; /* position of array element type in type_str */
81     } array;
82   } u;
83 };
84
85 void        _dbus_type_reader_init                (DBusTypeReader    *reader,
86                                                    int                byte_order,
87                                                    const DBusString  *type_str,
88                                                    int                type_pos,
89                                                    const DBusString  *value_str,
90                                                    int                value_pos);
91 void        _dbus_type_reader_init_types_only     (DBusTypeReader    *reader,
92                                                    const DBusString  *type_str,
93                                                    int                type_pos);
94 int         _dbus_type_reader_get_current_type    (DBusTypeReader    *reader);
95 dbus_bool_t _dbus_type_reader_array_is_empty      (DBusTypeReader    *reader);
96 void        _dbus_type_reader_read_basic          (DBusTypeReader    *reader,
97                                                    void              *value);
98 dbus_bool_t _dbus_type_reader_read_array_of_basic (DBusTypeReader    *reader,
99                                                    int                type,
100                                                    void             **array,
101                                                    int               *array_len);
102 void        _dbus_type_reader_recurse             (DBusTypeReader    *reader,
103                                                    DBusTypeReader    *subreader);
104 dbus_bool_t _dbus_type_reader_next                (DBusTypeReader    *reader);
105
106 void        _dbus_type_writer_init            (DBusTypeWriter *writer,
107                                                int             byte_order,
108                                                DBusString     *type_str,
109                                                int             type_pos,
110                                                DBusString     *value_str,
111                                                int             value_pos);
112 dbus_bool_t _dbus_type_writer_write_basic     (DBusTypeWriter *writer,
113                                                int             type,
114                                                const void     *value);
115 dbus_bool_t _dbus_type_writer_write_array     (DBusTypeWriter *writer,
116                                                int             type,
117                                                const void     *array,
118                                                int             array_len);
119 dbus_bool_t _dbus_type_writer_recurse_struct  (DBusTypeWriter *writer,
120                                                DBusTypeWriter *sub);
121 dbus_bool_t _dbus_type_writer_recurse_array   (DBusTypeWriter *writer,
122                                                const char     *element_type,
123                                                DBusTypeWriter *sub);
124 dbus_bool_t _dbus_type_writer_recurse_variant (DBusTypeWriter *writer,
125                                                const char     *contained_type,
126                                                DBusTypeWriter *sub);
127 dbus_bool_t _dbus_type_writer_unrecurse       (DBusTypeWriter *writer,
128                                                DBusTypeWriter *sub);
129
130
131
132 #endif /* DBUS_MARSHAL_RECURSIVE_H */