2007-07-13 Havoc Pennington <hp@redhat.com>
[platform/upstream/dbus.git] / dbus / dbus-marshal-recursive.h
1 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
2 /* dbus-marshal-recursive.h  Marshalling routines for recursive types
3  *
4  * Copyright (C) 2004, 2005 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-list.h>
30
31 #ifndef PACKAGE
32 #error "config.h not included here"
33 #endif
34
35 typedef struct DBusTypeReader      DBusTypeReader;
36 typedef struct DBusTypeWriter      DBusTypeWriter;
37 typedef struct DBusTypeReaderClass DBusTypeReaderClass;
38 typedef struct DBusArrayLenFixup   DBusArrayLenFixup;
39
40 /**
41  * The type reader is an iterator for reading values from a block of
42  * values.
43  */
44 struct DBusTypeReader
45 {
46   dbus_uint32_t byte_order : 8; /**< byte order of the block */
47
48   dbus_uint32_t finished : 1;   /**< marks we're at end iterator for cases
49                                  * where we don't have another way to tell
50                                  */
51   dbus_uint32_t array_len_offset : 3; /**< bytes back from start_pos that len ends */
52   const DBusString *type_str;   /**< string containing signature of block */
53   int type_pos;                 /**< current position in signature */
54   const DBusString *value_str;  /**< string containing values of block */
55   int value_pos;                /**< current position in values */
56
57   const DBusTypeReaderClass *klass; /**< the vtable for the reader */
58   union
59   {
60     struct {
61       int start_pos;                /**< for array readers, the start of the array values */
62     } array;
63   } u; /**< class-specific data */
64 };
65
66 /**
67  * The type writer is an iterator for writing to a block of values.
68  */
69 struct DBusTypeWriter
70 {
71   dbus_uint32_t byte_order : 8;            /**< byte order to write values with */
72
73   dbus_uint32_t container_type : 8;        /**< what are we inside? (e.g. struct, variant, array) */
74
75   dbus_uint32_t type_pos_is_expectation : 1; /**< type_pos can be either an insertion point for or an expected next type */
76
77   dbus_uint32_t enabled : 1; /**< whether to write values */
78
79   DBusString *type_str; /**< where to write typecodes (or read type expectations) */
80   int type_pos;         /**< current pos in type_str */
81   DBusString *value_str; /**< where to write values */
82   int value_pos;         /**< next position to write */
83
84   union
85   {
86     struct {
87       int start_pos; /**< position of first element in the array */
88       int len_pos;   /**< position of length of the array */
89       int element_type_pos; /**< position of array element type in type_str */
90     } array;
91   } u; /**< class-specific data */
92 };
93
94 /**
95  * When modifying an existing block of values, array lengths may need
96  * to be adjusted; those adjustments are described by this struct.
97  */
98 struct DBusArrayLenFixup
99 {
100   int len_pos_in_reader; /**< where the length was in the original block */
101   int new_len;           /**< the new value of the length in the written-out block */
102 };
103
104 void        _dbus_type_reader_init                      (DBusTypeReader        *reader,
105                                                          int                    byte_order,
106                                                          const DBusString      *type_str,
107                                                          int                    type_pos,
108                                                          const DBusString      *value_str,
109                                                          int                    value_pos);
110 void        _dbus_type_reader_init_types_only           (DBusTypeReader        *reader,
111                                                          const DBusString      *type_str,
112                                                          int                    type_pos);
113 int         _dbus_type_reader_get_current_type          (const DBusTypeReader  *reader);
114 int         _dbus_type_reader_get_element_type          (const DBusTypeReader  *reader);
115 int         _dbus_type_reader_get_value_pos             (const DBusTypeReader  *reader);
116 void        _dbus_type_reader_read_basic                (const DBusTypeReader  *reader,
117                                                          void                  *value);
118 int         _dbus_type_reader_get_array_length          (const DBusTypeReader  *reader);
119 void        _dbus_type_reader_read_fixed_multi          (const DBusTypeReader  *reader,
120                                                          void                  *value,
121                                                          int                   *n_elements);
122 void        _dbus_type_reader_read_raw                  (const DBusTypeReader  *reader,
123                                                          const unsigned char  **value_location);
124 void        _dbus_type_reader_recurse                   (DBusTypeReader        *reader,
125                                                          DBusTypeReader        *subreader);
126 dbus_bool_t _dbus_type_reader_next                      (DBusTypeReader        *reader);
127 dbus_bool_t _dbus_type_reader_has_next                  (const DBusTypeReader  *reader);
128 void        _dbus_type_reader_get_signature             (const DBusTypeReader  *reader,
129                                                          const DBusString     **str_p,
130                                                          int                   *start_p,
131                                                          int                   *len_p);
132 dbus_bool_t _dbus_type_reader_set_basic                 (DBusTypeReader        *reader,
133                                                          const void            *value,
134                                                          const DBusTypeReader  *realign_root);
135 dbus_bool_t _dbus_type_reader_delete                    (DBusTypeReader        *reader,
136                                                          const DBusTypeReader  *realign_root);
137 dbus_bool_t _dbus_type_reader_greater_than              (const DBusTypeReader  *lhs,
138                                                          const DBusTypeReader  *rhs);
139
140 dbus_bool_t _dbus_type_reader_equal_values              (const DBusTypeReader *lhs,
141                                                          const DBusTypeReader *rhs);
142
143 void        _dbus_type_signature_next                   (const char            *signature,
144                                                          int                   *type_pos);
145
146 void        _dbus_type_writer_init                 (DBusTypeWriter        *writer,
147                                                     int                    byte_order,
148                                                     DBusString            *type_str,
149                                                     int                    type_pos,
150                                                     DBusString            *value_str,
151                                                     int                    value_pos);
152 void        _dbus_type_writer_init_types_delayed   (DBusTypeWriter        *writer,
153                                                     int                    byte_order,
154                                                     DBusString            *value_str,
155                                                     int                    value_pos);
156 void        _dbus_type_writer_add_types            (DBusTypeWriter        *writer,
157                                                     DBusString            *type_str,
158                                                     int                    type_pos);
159 void        _dbus_type_writer_remove_types         (DBusTypeWriter        *writer);
160 void        _dbus_type_writer_init_values_only     (DBusTypeWriter        *writer,
161                                                     int                    byte_order,
162                                                     const DBusString      *type_str,
163                                                     int                    type_pos,
164                                                     DBusString            *value_str,
165                                                     int                    value_pos);
166 dbus_bool_t _dbus_type_writer_write_basic          (DBusTypeWriter        *writer,
167                                                     int                    type,
168                                                     const void            *value);
169 dbus_bool_t _dbus_type_writer_write_fixed_multi    (DBusTypeWriter        *writer,
170                                                     int                    element_type,
171                                                     const void            *value,
172                                                     int                    n_elements);
173 dbus_bool_t _dbus_type_writer_recurse              (DBusTypeWriter        *writer,
174                                                     int                    container_type,
175                                                     const DBusString      *contained_type,
176                                                     int                    contained_type_start,
177                                                     DBusTypeWriter        *sub);
178 dbus_bool_t _dbus_type_writer_unrecurse            (DBusTypeWriter        *writer,
179                                                     DBusTypeWriter        *sub);
180 dbus_bool_t _dbus_type_writer_append_array         (DBusTypeWriter        *writer,
181                                                     const DBusString      *contained_type,
182                                                     int                    contained_type_start,
183                                                     DBusTypeWriter        *sub);
184 dbus_bool_t _dbus_type_writer_write_reader         (DBusTypeWriter        *writer,
185                                                     DBusTypeReader        *reader);
186 dbus_bool_t _dbus_type_writer_write_reader_partial (DBusTypeWriter        *writer,
187                                                     DBusTypeReader        *reader,
188                                                     const DBusTypeReader  *start_after,
189                                                     int                    start_after_new_pos,
190                                                     int                    start_after_new_len,
191                                                     DBusList             **fixups);
192 void        _dbus_type_writer_set_enabled          (DBusTypeWriter        *writer,
193                                                     dbus_bool_t            enabled);
194
195
196 #endif /* DBUS_MARSHAL_RECURSIVE_H */