X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dbus%2Fdbus-marshal-recursive.h;h=acbfd73103db33ed2f3b3ee68a68a7ba22132729;hb=5146f3be6bf4734c8fd4d41ab85dec2a07f9d13d;hp=57b55fcfcb7737212cb136732073ee8efc523c3e;hpb=7debfd9ff56c5c2208372142e494c3e4a2defb23;p=platform%2Fupstream%2Fdbus.git diff --git a/dbus/dbus-marshal-recursive.h b/dbus/dbus-marshal-recursive.h index 57b55fc..acbfd73 100644 --- a/dbus/dbus-marshal-recursive.h +++ b/dbus/dbus-marshal-recursive.h @@ -1,10 +1,10 @@ -/* -*- mode: C; c-file-style: "gnu" -*- */ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ /* dbus-marshal-recursive.h Marshalling routines for recursive types * - * Copyright (C) 2004 Red Hat, Inc. + * Copyright (C) 2004, 2005 Red Hat, Inc. * * Licensed under the Academic Free License version 2.1 - * + * * 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 @@ -14,139 +14,168 @@ * 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. - * + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * */ #ifndef DBUS_MARSHAL_RECURSIVE_H #define DBUS_MARSHAL_RECURSIVE_H -#include -#include - -#ifndef PACKAGE -#error "config.h not included here" -#endif - -/* Notes on my plan to implement this: - * - also have DBusTypeWriter (heh) - * - TypeReader has accessors for: - * . basic type - * . array of basic type (efficiency hack) - * . another type reader - * - a dict will appear to be a list of string, whatever, string, whatever - * - a variant will contain another TypeReader - * - a struct will be a list of whatever, whatever, whatever - * - * So the basic API usage is to go next, next, next; if the - * item is a basic type or basic array then read the item; - * if it's another type reader then process it; if it's - * a container type (struct, array, variant, dict) then - * recurse. - * - */ +#include +#include + +typedef struct DBusTypeReader DBusTypeReader; +typedef struct DBusTypeWriter DBusTypeWriter; +typedef struct DBusTypeReaderClass DBusTypeReaderClass; +typedef struct DBusArrayLenFixup DBusArrayLenFixup; +/** + * The type reader is an iterator for reading values from a block of + * values. + */ struct DBusTypeReader { - int byte_order; - const DBusString *type_str; - int type_pos; - const DBusString *value_str; - int value_pos; - - /* Hmm - it might be cleaner to do TypeReaderClass *vtable for container type */ - int container_type; + dbus_uint32_t byte_order : 8; /**< byte order of the block */ + + dbus_uint32_t finished : 1; /**< marks we're at end iterator for cases + * where we don't have another way to tell + */ + 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 */ + + const DBusTypeReaderClass *klass; /**< the vtable for the reader */ union { struct { - int start_pos; - dbus_uint32_t len; - int element_type; + int start_pos; /**< for array readers, the start of the array values */ } array; - - struct { - int len_pos; - - } dict; - - struct { - dbus_uint32_t finished : 1; - } strct; - } u; + } u; /**< class-specific data */ }; -typedef struct DBusTypeReader DBusTypeReader; - +/** + * The type writer is an iterator for writing to a block of values. + */ struct DBusTypeWriter { - int byte_order; - DBusString *type_str; - int type_pos; - DBusString *value_str; - int value_pos; + dbus_uint32_t byte_order : 8; /**< byte order to write values with */ + + dbus_uint32_t container_type : 8; /**< what are we inside? (e.g. struct, variant, array) */ + + dbus_uint32_t type_pos_is_expectation : 1; /**< type_pos can be either an insertion point for or an expected next type */ + + dbus_uint32_t enabled : 1; /**< whether to write values */ - dbus_uint32_t inside_array : 1; + 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 */ - int container_type; union { struct { - int start_pos; /* first element */ - int len_pos; - char *element_type; + 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 */ } array; + } u; /**< class-specific data */ +}; - struct { - int len_pos; - - } dict; - } u; +/** + * When modifying an existing block of values, array lengths may need + * to be adjusted; those adjustments are described by this struct. + */ +struct DBusArrayLenFixup +{ + 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 */ }; -typedef struct DBusTypeWriter DBusTypeWriter; - -void _dbus_type_reader_init (DBusTypeReader *reader, - int byte_order, - const DBusString *type_str, - int type_pos, - const DBusString *value_str, - int value_pos); -int _dbus_type_reader_get_current_type (DBusTypeReader *reader); -int _dbus_type_reader_get_array_length (DBusTypeReader *reader); -void _dbus_type_reader_read_basic (DBusTypeReader *reader, - void *value); -dbus_bool_t _dbus_type_reader_read_array_of_basic (DBusTypeReader *reader, - int type, - void **array, - int *array_len); -void _dbus_type_reader_recurse (DBusTypeReader *reader, - DBusTypeReader *subreader); -dbus_bool_t _dbus_type_reader_next (DBusTypeReader *reader); - -void _dbus_type_writer_init (DBusTypeWriter *writer, - int byte_order, - 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); -dbus_bool_t _dbus_type_writer_write_array (DBusTypeWriter *writer, - int type, - const void *array, - int array_len); -dbus_bool_t _dbus_type_writer_recurse (DBusTypeWriter *writer, - int container_type, - DBusTypeWriter *sub); -dbus_bool_t _dbus_type_writer_recurse_array (DBusTypeWriter *writer, - const char *element_type, - DBusTypeWriter *sub); -dbus_bool_t _dbus_type_writer_unrecurse (DBusTypeWriter *writer, - DBusTypeWriter *sub); +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); +int _dbus_type_reader_get_element_type (const DBusTypeReader *reader); +int _dbus_type_reader_get_value_pos (const DBusTypeReader *reader); +void _dbus_type_reader_read_basic (const DBusTypeReader *reader, + void *value); +int _dbus_type_reader_get_array_length (const DBusTypeReader *reader); +void _dbus_type_reader_read_fixed_multi (const DBusTypeReader *reader, + void *value, + int *n_elements); +void _dbus_type_reader_read_raw (const DBusTypeReader *reader, + const unsigned char **value_location); +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); +void _dbus_type_reader_get_signature (const DBusTypeReader *reader, + const DBusString **str_p, + int *start_p, + int *len_p); +dbus_bool_t _dbus_type_reader_set_basic (DBusTypeReader *reader, + const void *value, + const DBusTypeReader *realign_root); +dbus_bool_t _dbus_type_reader_delete (DBusTypeReader *reader, + const DBusTypeReader *realign_root); + +dbus_bool_t _dbus_type_reader_equal_values (const DBusTypeReader *lhs, + const DBusTypeReader *rhs); + +void _dbus_type_signature_next (const char *signature, + int *type_pos); + +void _dbus_type_writer_init (DBusTypeWriter *writer, + int byte_order, + DBusString *type_str, + int type_pos, + DBusString *value_str, + int value_pos); +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); +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); +dbus_bool_t _dbus_type_writer_write_fixed_multi (DBusTypeWriter *writer, + int element_type, + const void *value, + int n_elements); +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); +dbus_bool_t _dbus_type_writer_append_array (DBusTypeWriter *writer, + const DBusString *contained_type, + int contained_type_start, + DBusTypeWriter *sub); +dbus_bool_t _dbus_type_writer_write_reader (DBusTypeWriter *writer, + DBusTypeReader *reader); #endif /* DBUS_MARSHAL_RECURSIVE_H */