arrays are working, woot
[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 /* Notes on my plan to implement this:
35  * - also have DBusTypeWriter (heh)
36  * - TypeReader has accessors for:
37  *    . basic type
38  *    . array of basic type (efficiency hack)
39  *    . another type reader
40  * - a dict will appear to be a list of string, whatever, string, whatever
41  * - a variant will contain another TypeReader
42  * - a struct will be a list of whatever, whatever, whatever
43  *
44  * So the basic API usage is to go next, next, next; if the
45  * item is a basic type or basic array then read the item;
46  * if it's another type reader then process it; if it's
47  * a container type (struct, array, variant, dict) then
48  * recurse.
49  * 
50  */
51
52 struct DBusTypeReader
53 {
54   int byte_order;
55   const DBusString *type_str;
56   int type_pos;
57   const DBusString *value_str;
58   int value_pos;
59
60   /* Hmm - it might be cleaner to do TypeReaderClass *vtable for container type */
61   int container_type;
62   union
63   {
64     struct {
65       int start_pos;
66       dbus_uint32_t len;
67       int element_type;
68     } array;
69
70     struct {
71       int len_pos;
72
73     } dict;
74
75     struct {
76       dbus_uint32_t finished : 1;
77     } strct;
78   } u;
79 };
80
81 typedef struct DBusTypeReader DBusTypeReader;
82
83 struct DBusTypeWriter
84 {
85   int byte_order;
86   DBusString *type_str;
87   int type_pos;
88   DBusString *value_str;
89   int value_pos;
90
91   dbus_uint32_t inside_array : 1;
92
93   int container_type;
94   union
95   {
96     struct {
97       int start_pos; /* first element */
98       int len_pos;
99       char *element_type;
100     } array;
101
102     struct {
103       int len_pos;
104
105     } dict;
106   } u;
107 };
108
109 typedef struct DBusTypeWriter DBusTypeWriter;
110
111 void        _dbus_type_reader_init                (DBusTypeReader    *reader,
112                                                    int                byte_order,
113                                                    const DBusString  *type_str,
114                                                    int                type_pos,
115                                                    const DBusString  *value_str,
116                                                    int                value_pos);
117 int         _dbus_type_reader_get_current_type    (DBusTypeReader    *reader);
118 dbus_bool_t _dbus_type_reader_array_is_empty      (DBusTypeReader    *reader);
119 void        _dbus_type_reader_read_basic          (DBusTypeReader    *reader,
120                                                    void              *value);
121 dbus_bool_t _dbus_type_reader_read_array_of_basic (DBusTypeReader    *reader,
122                                                    int                type,
123                                                    void             **array,
124                                                    int               *array_len);
125 void        _dbus_type_reader_recurse             (DBusTypeReader    *reader,
126                                                    DBusTypeReader    *subreader);
127 dbus_bool_t _dbus_type_reader_next                (DBusTypeReader    *reader);
128
129 void        _dbus_type_writer_init          (DBusTypeWriter *writer,
130                                              int             byte_order,
131                                              DBusString     *type_str,
132                                              int             type_pos,
133                                              DBusString     *value_str,
134                                              int             value_pos);
135 dbus_bool_t _dbus_type_writer_write_basic   (DBusTypeWriter *writer,
136                                              int             type,
137                                              const void     *value);
138 dbus_bool_t _dbus_type_writer_write_array   (DBusTypeWriter *writer,
139                                              int             type,
140                                              const void     *array,
141                                              int             array_len);
142 dbus_bool_t _dbus_type_writer_recurse       (DBusTypeWriter *writer,
143                                              int             container_type,
144                                              DBusTypeWriter *sub);
145 dbus_bool_t _dbus_type_writer_recurse_array (DBusTypeWriter *writer,
146                                              const char     *element_type,
147                                              DBusTypeWriter *sub);
148 dbus_bool_t _dbus_type_writer_unrecurse     (DBusTypeWriter *writer,
149                                              DBusTypeWriter *sub);
150
151
152 #endif /* DBUS_MARSHAL_RECURSIVE_H */