switch to a vtable approach for the reader
[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 typedef struct DBusTypeWriterClass DBusTypeWriterClass;
38
39 struct DBusTypeReader
40 {
41   int byte_order;
42   const DBusString *type_str;
43   int type_pos;
44   const DBusString *value_str;
45   int value_pos;
46
47   const DBusTypeReaderClass *klass;
48   union
49   {
50     struct {
51       int start_pos;
52       dbus_uint32_t len;
53       int element_type;
54     } array;
55
56     struct {
57       int len_pos;
58
59     } dict;
60
61     struct {
62       dbus_uint32_t finished : 1;
63     } strct;
64   } u;
65 };
66
67 struct DBusTypeWriter
68 {
69   int byte_order;
70   DBusString *type_str;
71   int type_pos;
72   DBusString *value_str;
73   int value_pos;
74
75   dbus_uint32_t inside_array : 1;
76
77   /* const DBusTypeWriterClass *klass; */
78   int container_type;
79   union
80   {
81     struct {
82       int start_pos; /* first element */
83       int len_pos;
84       int element_type_pos; /* position in type_str of array element type */
85       int element_type_len;
86     } array;
87
88     struct {
89       int len_pos;
90
91     } dict;
92   } u;
93 };
94
95 void        _dbus_type_reader_init                (DBusTypeReader    *reader,
96                                                    int                byte_order,
97                                                    const DBusString  *type_str,
98                                                    int                type_pos,
99                                                    const DBusString  *value_str,
100                                                    int                value_pos);
101 int         _dbus_type_reader_get_current_type    (DBusTypeReader    *reader);
102 dbus_bool_t _dbus_type_reader_array_is_empty      (DBusTypeReader    *reader);
103 void        _dbus_type_reader_read_basic          (DBusTypeReader    *reader,
104                                                    void              *value);
105 dbus_bool_t _dbus_type_reader_read_array_of_basic (DBusTypeReader    *reader,
106                                                    int                type,
107                                                    void             **array,
108                                                    int               *array_len);
109 void        _dbus_type_reader_recurse             (DBusTypeReader    *reader,
110                                                    DBusTypeReader    *subreader);
111 dbus_bool_t _dbus_type_reader_next                (DBusTypeReader    *reader);
112
113 void        _dbus_type_writer_init          (DBusTypeWriter *writer,
114                                              int             byte_order,
115                                              DBusString     *type_str,
116                                              int             type_pos,
117                                              DBusString     *value_str,
118                                              int             value_pos);
119 dbus_bool_t _dbus_type_writer_write_basic   (DBusTypeWriter *writer,
120                                              int             type,
121                                              const void     *value);
122 dbus_bool_t _dbus_type_writer_write_array   (DBusTypeWriter *writer,
123                                              int             type,
124                                              const void     *array,
125                                              int             array_len);
126 dbus_bool_t _dbus_type_writer_recurse       (DBusTypeWriter *writer,
127                                              int             container_type,
128                                              DBusTypeWriter *sub);
129 dbus_bool_t _dbus_type_writer_recurse_array (DBusTypeWriter *writer,
130                                              const char     *element_type,
131                                              DBusTypeWriter *sub);
132 dbus_bool_t _dbus_type_writer_unrecurse     (DBusTypeWriter *writer,
133                                              DBusTypeWriter *sub);
134
135
136 #endif /* DBUS_MARSHAL_RECURSIVE_H */