dbus-marshal-recursive.h 10.1 KB
Newer Older
1
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
2 3
/* dbus-marshal-recursive.h  Marshalling routines for recursive types
 *
4
 * Copyright (C) 2004, 2005 Red Hat, Inc.
5 6
 *
 * Licensed under the Academic Free License version 2.1
7
 *
8 9 10 11 12 13 14 15 16
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
17
 *
18 19
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
20
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
21 22 23 24 25 26
 *
 */

#ifndef DBUS_MARSHAL_RECURSIVE_H
#define DBUS_MARSHAL_RECURSIVE_H

Havoc Pennington's avatar
Havoc Pennington committed
27
#include <dbus/dbus-protocol.h>
28
#include <dbus/dbus-list.h>
29

30 31 32
typedef struct DBusTypeReader      DBusTypeReader;
typedef struct DBusTypeWriter      DBusTypeWriter;
typedef struct DBusTypeReaderClass DBusTypeReaderClass;
33
typedef struct DBusArrayLenFixup   DBusArrayLenFixup;
34

35 36 37 38
/**
 * The type reader is an iterator for reading values from a block of
 * values.
 */
39 40
struct DBusTypeReader
{
41
  dbus_uint32_t byte_order : 8; /**< byte order of the block */
42

43
  dbus_uint32_t finished : 1;   /**< marks we're at end iterator for cases
44 45
                                 * where we don't have another way to tell
                                 */
46 47 48 49 50
  dbus_uint32_t array_len_offset : 3; /**< bytes back from start_pos that len ends */
  const DBusString *type_str;   /**< string containing signature of block */
  int type_pos;                 /**< current position in signature */
  const DBusString *value_str;  /**< string containing values of block */
  int value_pos;                /**< current position in values */
51

52
  const DBusTypeReaderClass *klass; /**< the vtable for the reader */
53 54 55
  union
  {
    struct {
56
      int start_pos;                /**< for array readers, the start of the array values */
57
    } array;
58
  } u; /**< class-specific data */
59 60
};

61 62 63
/**
 * The type writer is an iterator for writing to a block of values.
 */
64 65
struct DBusTypeWriter
{
66
  dbus_uint32_t byte_order : 8;            /**< byte order to write values with */
Havoc Pennington's avatar
Havoc Pennington committed
67

68
  dbus_uint32_t container_type : 8;        /**< what are we inside? (e.g. struct, variant, array) */
Havoc Pennington's avatar
Havoc Pennington committed
69

70
  dbus_uint32_t type_pos_is_expectation : 1; /**< type_pos can be either an insertion point for or an expected next type */
71

72
  dbus_uint32_t enabled : 1; /**< whether to write values */
73

74 75 76 77
  DBusString *type_str; /**< where to write typecodes (or read type expectations) */
  int type_pos;         /**< current pos in type_str */
  DBusString *value_str; /**< where to write values */
  int value_pos;         /**< next position to write */
78 79 80 81

  union
  {
    struct {
82 83 84
      int start_pos; /**< position of first element in the array */
      int len_pos;   /**< position of length of the array */
      int element_type_pos; /**< position of array element type in type_str */
85
    } array;
86
  } u; /**< class-specific data */
87 88
};

89 90 91 92
/**
 * When modifying an existing block of values, array lengths may need
 * to be adjusted; those adjustments are described by this struct.
 */
93 94
struct DBusArrayLenFixup
{
95 96
  int len_pos_in_reader; /**< where the length was in the original block */
  int new_len;           /**< the new value of the length in the written-out block */
97 98
};

99 100 101 102 103 104 105 106 107 108
void        _dbus_type_reader_init                      (DBusTypeReader        *reader,
                                                         int                    byte_order,
                                                         const DBusString      *type_str,
                                                         int                    type_pos,
                                                         const DBusString      *value_str,
                                                         int                    value_pos);
void        _dbus_type_reader_init_types_only           (DBusTypeReader        *reader,
                                                         const DBusString      *type_str,
                                                         int                    type_pos);
int         _dbus_type_reader_get_current_type          (const DBusTypeReader  *reader);
109
int         _dbus_type_reader_get_element_type          (const DBusTypeReader  *reader);
110
int         _dbus_type_reader_get_value_pos             (const DBusTypeReader  *reader);
111 112
void        _dbus_type_reader_read_basic                (const DBusTypeReader  *reader,
                                                         void                  *value);
113
int         _dbus_type_reader_get_array_length          (const DBusTypeReader  *reader);
114
void        _dbus_type_reader_read_fixed_multi          (const DBusTypeReader  *reader,
115 116
                                                         void                  *value,
                                                         int                   *n_elements);
117 118
void        _dbus_type_reader_read_raw                  (const DBusTypeReader  *reader,
                                                         const unsigned char  **value_location);
119 120 121 122
void        _dbus_type_reader_recurse                   (DBusTypeReader        *reader,
                                                         DBusTypeReader        *subreader);
dbus_bool_t _dbus_type_reader_next                      (DBusTypeReader        *reader);
dbus_bool_t _dbus_type_reader_has_next                  (const DBusTypeReader  *reader);
123 124 125 126
void        _dbus_type_reader_get_signature             (const DBusTypeReader  *reader,
                                                         const DBusString     **str_p,
                                                         int                   *start_p,
                                                         int                   *len_p);
127
dbus_bool_t _dbus_type_reader_set_basic                 (DBusTypeReader        *reader,
Havoc Pennington's avatar
Havoc Pennington committed
128 129
                                                         const void            *value,
                                                         const DBusTypeReader  *realign_root);
130 131
dbus_bool_t _dbus_type_reader_delete                    (DBusTypeReader        *reader,
                                                         const DBusTypeReader  *realign_root);
132

133 134 135
dbus_bool_t _dbus_type_reader_equal_values              (const DBusTypeReader *lhs,
                                                         const DBusTypeReader *rhs);

136 137 138
void        _dbus_type_signature_next                   (const char            *signature,
							 int                   *type_pos);

139 140 141 142 143 144
void        _dbus_type_writer_init                 (DBusTypeWriter        *writer,
                                                    int                    byte_order,
                                                    DBusString            *type_str,
                                                    int                    type_pos,
                                                    DBusString            *value_str,
                                                    int                    value_pos);
145 146 147 148 149 150 151 152
void        _dbus_type_writer_init_types_delayed   (DBusTypeWriter        *writer,
                                                    int                    byte_order,
                                                    DBusString            *value_str,
                                                    int                    value_pos);
void        _dbus_type_writer_add_types            (DBusTypeWriter        *writer,
                                                    DBusString            *type_str,
                                                    int                    type_pos);
void        _dbus_type_writer_remove_types         (DBusTypeWriter        *writer);
153 154 155 156 157 158 159 160 161
void        _dbus_type_writer_init_values_only     (DBusTypeWriter        *writer,
                                                    int                    byte_order,
                                                    const DBusString      *type_str,
                                                    int                    type_pos,
                                                    DBusString            *value_str,
                                                    int                    value_pos);
dbus_bool_t _dbus_type_writer_write_basic          (DBusTypeWriter        *writer,
                                                    int                    type,
                                                    const void            *value);
162
dbus_bool_t _dbus_type_writer_write_fixed_multi    (DBusTypeWriter        *writer,
163 164 165
                                                    int                    element_type,
                                                    const void            *value,
                                                    int                    n_elements);
166 167 168 169 170 171 172
dbus_bool_t _dbus_type_writer_recurse              (DBusTypeWriter        *writer,
                                                    int                    container_type,
                                                    const DBusString      *contained_type,
                                                    int                    contained_type_start,
                                                    DBusTypeWriter        *sub);
dbus_bool_t _dbus_type_writer_unrecurse            (DBusTypeWriter        *writer,
                                                    DBusTypeWriter        *sub);
173 174 175 176
dbus_bool_t _dbus_type_writer_append_array         (DBusTypeWriter        *writer,
                                                    const DBusString      *contained_type,
                                                    int                    contained_type_start,
                                                    DBusTypeWriter        *sub);
177 178 179
dbus_bool_t _dbus_type_writer_write_reader         (DBusTypeWriter        *writer,
                                                    DBusTypeReader        *reader);

180

181
#endif /* DBUS_MARSHAL_RECURSIVE_H */