Home | History | Annotate | Download | only in dbus
      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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
     21  *
     22  */
     23 
     24 #ifndef DBUS_MARSHAL_RECURSIVE_H
     25 #define DBUS_MARSHAL_RECURSIVE_H
     26 
     27 #include <dbus/dbus-protocol.h>
     28 #include <dbus/dbus-list.h>
     29 
     30 typedef struct DBusTypeReader      DBusTypeReader;
     31 typedef struct DBusTypeWriter      DBusTypeWriter;
     32 typedef struct DBusTypeReaderClass DBusTypeReaderClass;
     33 typedef struct DBusArrayLenFixup   DBusArrayLenFixup;
     34 
     35 /**
     36  * The type reader is an iterator for reading values from a block of
     37  * values.
     38  */
     39 struct DBusTypeReader
     40 {
     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                                  * where we don't have another way to tell
     45                                  */
     46   dbus_uint32_t array_len_offset : 3; /**< bytes back from start_pos that len ends */
     47   const DBusString *type_str;   /**< string containing signature of block */
     48   int type_pos;                 /**< current position in signature */
     49   const DBusString *value_str;  /**< string containing values of block */
     50   int value_pos;                /**< current position in values */
     51 
     52   const DBusTypeReaderClass *klass; /**< the vtable for the reader */
     53   union
     54   {
     55     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  * The type writer is an iterator for writing to a block of values.
     63  */
     64 struct DBusTypeWriter
     65 {
     66   dbus_uint32_t byte_order : 8;            /**< byte order to write values with */
     67 
     68   dbus_uint32_t container_type : 8;        /**< what are we inside? (e.g. struct, variant, array) */
     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   DBusString *type_str; /**< where to write typecodes (or read type expectations) */
     75   int type_pos;         /**< current pos in type_str */
     76   DBusString *value_str; /**< where to write values */
     77   int value_pos;         /**< next position to write */
     78 
     79   union
     80   {
     81     struct {
     82       int start_pos; /**< position of first element in the array */
     83       int len_pos;   /**< position of length of the array */
     84       int element_type_pos; /**< position of array element type in type_str */
     85     } array;
     86   } u; /**< class-specific data */
     87 };
     88 
     89 /**
     90  * When modifying an existing block of values, array lengths may need
     91  * to be adjusted; those adjustments are described by this struct.
     92  */
     93 struct DBusArrayLenFixup
     94 {
     95   int len_pos_in_reader; /**< where the length was in the original block */
     96   int new_len;           /**< the new value of the length in the written-out block */
     97 };
     98 
     99 void        _dbus_type_reader_init                      (DBusTypeReader        *reader,
    100                                                          int                    byte_order,
    101                                                          const DBusString      *type_str,
    102                                                          int                    type_pos,
    103                                                          const DBusString      *value_str,
    104                                                          int                    value_pos);
    105 void        _dbus_type_reader_init_types_only           (DBusTypeReader        *reader,
    106                                                          const DBusString      *type_str,
    107                                                          int                    type_pos);
    108 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 void        _dbus_type_reader_read_basic                (const DBusTypeReader  *reader,
    112                                                          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                                                          void                  *value,
    116                                                          int                   *n_elements);
    117 void        _dbus_type_reader_read_raw                  (const DBusTypeReader  *reader,
    118                                                          const unsigned char  **value_location);
    119 void        _dbus_type_reader_recurse                   (DBusTypeReader        *reader,
    120                                                          DBusTypeReader        *subreader);
    121 dbus_bool_t _dbus_type_reader_next                      (DBusTypeReader        *reader);
    122 dbus_bool_t _dbus_type_reader_has_next                  (const DBusTypeReader  *reader);
    123 void        _dbus_type_reader_get_signature             (const DBusTypeReader  *reader,
    124                                                          const DBusString     **str_p,
    125                                                          int                   *start_p,
    126                                                          int                   *len_p);
    127 dbus_bool_t _dbus_type_reader_set_basic                 (DBusTypeReader        *reader,
    128                                                          const void            *value,
    129                                                          const DBusTypeReader  *realign_root);
    130 dbus_bool_t _dbus_type_reader_delete                    (DBusTypeReader        *reader,
    131                                                          const DBusTypeReader  *realign_root);
    132 dbus_bool_t _dbus_type_reader_greater_than              (const DBusTypeReader  *lhs,
    133                                                          const DBusTypeReader  *rhs);
    134 
    135 dbus_bool_t _dbus_type_reader_equal_values              (const DBusTypeReader *lhs,
    136                                                          const DBusTypeReader *rhs);
    137 
    138 void        _dbus_type_signature_next                   (const char            *signature,
    139 							 int                   *type_pos);
    140 
    141 void        _dbus_type_writer_init                 (DBusTypeWriter        *writer,
    142                                                     int                    byte_order,
    143                                                     DBusString            *type_str,
    144                                                     int                    type_pos,
    145                                                     DBusString            *value_str,
    146                                                     int                    value_pos);
    147 void        _dbus_type_writer_init_types_delayed   (DBusTypeWriter        *writer,
    148                                                     int                    byte_order,
    149                                                     DBusString            *value_str,
    150                                                     int                    value_pos);
    151 void        _dbus_type_writer_add_types            (DBusTypeWriter        *writer,
    152                                                     DBusString            *type_str,
    153                                                     int                    type_pos);
    154 void        _dbus_type_writer_remove_types         (DBusTypeWriter        *writer);
    155 void        _dbus_type_writer_init_values_only     (DBusTypeWriter        *writer,
    156                                                     int                    byte_order,
    157                                                     const DBusString      *type_str,
    158                                                     int                    type_pos,
    159                                                     DBusString            *value_str,
    160                                                     int                    value_pos);
    161 dbus_bool_t _dbus_type_writer_write_basic          (DBusTypeWriter        *writer,
    162                                                     int                    type,
    163                                                     const void            *value);
    164 dbus_bool_t _dbus_type_writer_write_fixed_multi    (DBusTypeWriter        *writer,
    165                                                     int                    element_type,
    166                                                     const void            *value,
    167                                                     int                    n_elements);
    168 dbus_bool_t _dbus_type_writer_recurse              (DBusTypeWriter        *writer,
    169                                                     int                    container_type,
    170                                                     const DBusString      *contained_type,
    171                                                     int                    contained_type_start,
    172                                                     DBusTypeWriter        *sub);
    173 dbus_bool_t _dbus_type_writer_unrecurse            (DBusTypeWriter        *writer,
    174                                                     DBusTypeWriter        *sub);
    175 dbus_bool_t _dbus_type_writer_append_array         (DBusTypeWriter        *writer,
    176                                                     const DBusString      *contained_type,
    177                                                     int                    contained_type_start,
    178                                                     DBusTypeWriter        *sub);
    179 dbus_bool_t _dbus_type_writer_write_reader         (DBusTypeWriter        *writer,
    180                                                     DBusTypeReader        *reader);
    181 dbus_bool_t _dbus_type_writer_write_reader_partial (DBusTypeWriter        *writer,
    182                                                     DBusTypeReader        *reader,
    183                                                     const DBusTypeReader  *start_after,
    184                                                     int                    start_after_new_pos,
    185                                                     int                    start_after_new_len,
    186                                                     DBusList             **fixups);
    187 void        _dbus_type_writer_set_enabled          (DBusTypeWriter        *writer,
    188                                                     dbus_bool_t            enabled);
    189 
    190 
    191 #endif /* DBUS_MARSHAL_RECURSIVE_H */
    192