dbus-marshal-basic.h

00001 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
00002 /* dbus-marshal-basic.h  Marshalling routines for basic (primitive) types
00003  *
00004  * Copyright (C) 2002  CodeFactory AB
00005  * Copyright (C) 2004, 2005  Red Hat, Inc.
00006  *
00007  * Licensed under the Academic Free License version 2.1
00008  *
00009  * This program is free software; you can redistribute it and/or modify
00010  * it under the terms of the GNU General Public License as published by
00011  * the Free Software Foundation; either version 2 of the License, or
00012  * (at your option) any later version.
00013  *
00014  * This program is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  * GNU General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU General Public License
00020  * along with this program; if not, write to the Free Software
00021  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00022  *
00023  */
00024 
00025 #ifndef DBUS_MARSHAL_BASIC_H
00026 #define DBUS_MARSHAL_BASIC_H
00027 
00028 #include <config.h>
00029 #include <dbus/dbus-protocol.h>
00030 #include <dbus/dbus-types.h>
00031 #include <dbus/dbus-arch-deps.h>
00032 #include <dbus/dbus-string.h>
00033 
00034 #ifndef PACKAGE
00035 #error "config.h not included here"
00036 #endif
00037 
00038 #ifdef WORDS_BIGENDIAN
00039 #define DBUS_COMPILER_BYTE_ORDER DBUS_BIG_ENDIAN
00040 #else
00041 #define DBUS_COMPILER_BYTE_ORDER DBUS_LITTLE_ENDIAN
00042 #endif
00043 
00044 #define DBUS_UINT16_SWAP_LE_BE_CONSTANT(val)    ((dbus_uint16_t) (      \
00045     (dbus_uint16_t) ((dbus_uint16_t) (val) >> 8) |                      \
00046     (dbus_uint16_t) ((dbus_uint16_t) (val) << 8)))
00047 
00048 #define DBUS_UINT32_SWAP_LE_BE_CONSTANT(val)    ((dbus_uint32_t) (      \
00049     (((dbus_uint32_t) (val) & (dbus_uint32_t) 0x000000ffU) << 24) |     \
00050     (((dbus_uint32_t) (val) & (dbus_uint32_t) 0x0000ff00U) <<  8) |     \
00051     (((dbus_uint32_t) (val) & (dbus_uint32_t) 0x00ff0000U) >>  8) |     \
00052     (((dbus_uint32_t) (val) & (dbus_uint32_t) 0xff000000U) >> 24)))
00053 
00054 #ifdef DBUS_HAVE_INT64
00055 
00056 #define DBUS_UINT64_SWAP_LE_BE_CONSTANT(val)    ((dbus_uint64_t) (              \
00057       (((dbus_uint64_t) (val) &                                                 \
00058         (dbus_uint64_t) DBUS_UINT64_CONSTANT (0x00000000000000ff)) << 56) |    \
00059       (((dbus_uint64_t) (val) &                                                 \
00060         (dbus_uint64_t) DBUS_UINT64_CONSTANT (0x000000000000ff00)) << 40) |    \
00061       (((dbus_uint64_t) (val) &                                                 \
00062         (dbus_uint64_t) DBUS_UINT64_CONSTANT (0x0000000000ff0000)) << 24) |    \
00063       (((dbus_uint64_t) (val) &                                                 \
00064         (dbus_uint64_t) DBUS_UINT64_CONSTANT (0x00000000ff000000)) <<  8) |    \
00065       (((dbus_uint64_t) (val) &                                                 \
00066         (dbus_uint64_t) DBUS_UINT64_CONSTANT (0x000000ff00000000)) >>  8) |    \
00067       (((dbus_uint64_t) (val) &                                                 \
00068         (dbus_uint64_t) DBUS_UINT64_CONSTANT (0x0000ff0000000000)) >> 24) |    \
00069       (((dbus_uint64_t) (val) &                                                 \
00070         (dbus_uint64_t) DBUS_UINT64_CONSTANT (0x00ff000000000000)) >> 40) |    \
00071       (((dbus_uint64_t) (val) &                                                 \
00072         (dbus_uint64_t) DBUS_UINT64_CONSTANT (0xff00000000000000)) >> 56)))
00073 #endif /* DBUS_HAVE_INT64 */
00074 
00075 #define DBUS_UINT16_SWAP_LE_BE(val) (DBUS_UINT16_SWAP_LE_BE_CONSTANT (val))
00076 #define DBUS_INT16_SWAP_LE_BE(val)  ((dbus_int16_t)DBUS_UINT16_SWAP_LE_BE_CONSTANT (val))
00077 
00078 #define DBUS_UINT32_SWAP_LE_BE(val) (DBUS_UINT32_SWAP_LE_BE_CONSTANT (val))
00079 #define DBUS_INT32_SWAP_LE_BE(val)  ((dbus_int32_t)DBUS_UINT32_SWAP_LE_BE_CONSTANT (val))
00080 
00081 #ifdef DBUS_HAVE_INT64
00082 #  define DBUS_UINT64_SWAP_LE_BE(val) (DBUS_UINT64_SWAP_LE_BE_CONSTANT (val))
00083 #  define DBUS_INT64_SWAP_LE_BE(val)  ((dbus_int64_t)DBUS_UINT64_SWAP_LE_BE_CONSTANT (val))
00084 #endif /* DBUS_HAVE_INT64 */
00085 
00086 #ifdef WORDS_BIGENDIAN
00087 
00088 #  define DBUS_INT16_TO_BE(val) ((dbus_int16_t) (val))
00089 #  define DBUS_UINT16_TO_BE(val)        ((dbus_uint16_t) (val))
00090 #  define DBUS_INT16_TO_LE(val) (DBUS_INT16_SWAP_LE_BE (val))
00091 #  define DBUS_UINT16_TO_LE(val)        (DBUS_UINT16_SWAP_LE_BE (val))
00092 #  define DBUS_INT32_TO_BE(val) ((dbus_int32_t) (val))
00093 #  define DBUS_UINT32_TO_BE(val)        ((dbus_uint32_t) (val))
00094 #  define DBUS_INT32_TO_LE(val) (DBUS_INT32_SWAP_LE_BE (val))
00095 #  define DBUS_UINT32_TO_LE(val)        (DBUS_UINT32_SWAP_LE_BE (val))
00096 #  ifdef DBUS_HAVE_INT64
00097 #    define DBUS_INT64_TO_BE(val)       ((dbus_int64_t) (val))
00098 #    define DBUS_UINT64_TO_BE(val)      ((dbus_uint64_t) (val))
00099 #    define DBUS_INT64_TO_LE(val)       (DBUS_INT64_SWAP_LE_BE (val))
00100 #    define DBUS_UINT64_TO_LE(val)      (DBUS_UINT64_SWAP_LE_BE (val))
00101 #  endif /* DBUS_HAVE_INT64 */
00102 
00103 #else /* WORDS_BIGENDIAN */
00104 
00105 #  define DBUS_INT16_TO_LE(val) ((dbus_int16_t) (val))
00106 #  define DBUS_UINT16_TO_LE(val)        ((dbus_uint16_t) (val))
00107 #  define DBUS_INT16_TO_BE(val) ((dbus_int16_t) DBUS_UINT16_SWAP_LE_BE (val))
00108 #  define DBUS_UINT16_TO_BE(val)        (DBUS_UINT16_SWAP_LE_BE (val))
00109 #  define DBUS_INT32_TO_LE(val) ((dbus_int32_t) (val))
00110 #  define DBUS_UINT32_TO_LE(val)        ((dbus_uint32_t) (val))
00111 #  define DBUS_INT32_TO_BE(val) ((dbus_int32_t) DBUS_UINT32_SWAP_LE_BE (val))
00112 #  define DBUS_UINT32_TO_BE(val)        (DBUS_UINT32_SWAP_LE_BE (val))
00113 #  ifdef DBUS_HAVE_INT64
00114 #    define DBUS_INT64_TO_LE(val)       ((dbus_int64_t) (val))
00115 #    define DBUS_UINT64_TO_LE(val)      ((dbus_uint64_t) (val))
00116 #    define DBUS_INT64_TO_BE(val)       ((dbus_int64_t) DBUS_UINT64_SWAP_LE_BE (val))
00117 #    define DBUS_UINT64_TO_BE(val)      (DBUS_UINT64_SWAP_LE_BE (val))
00118 #  endif /* DBUS_HAVE_INT64 */
00119 #endif
00120 
00121 /* The transformation is symmetric, so the FROM just maps to the TO. */
00122 #define DBUS_INT16_FROM_LE(val)  (DBUS_INT16_TO_LE (val))
00123 #define DBUS_UINT16_FROM_LE(val) (DBUS_UINT16_TO_LE (val))
00124 #define DBUS_INT16_FROM_BE(val)  (DBUS_INT16_TO_BE (val))
00125 #define DBUS_UINT16_FROM_BE(val) (DBUS_UINT16_TO_BE (val))
00126 #define DBUS_INT32_FROM_LE(val)  (DBUS_INT32_TO_LE (val))
00127 #define DBUS_UINT32_FROM_LE(val) (DBUS_UINT32_TO_LE (val))
00128 #define DBUS_INT32_FROM_BE(val)  (DBUS_INT32_TO_BE (val))
00129 #define DBUS_UINT32_FROM_BE(val) (DBUS_UINT32_TO_BE (val))
00130 #ifdef DBUS_HAVE_INT64
00131 #  define DBUS_INT64_FROM_LE(val)        (DBUS_INT64_TO_LE (val))
00132 #  define DBUS_UINT64_FROM_LE(val) (DBUS_UINT64_TO_LE (val))
00133 #  define DBUS_INT64_FROM_BE(val)        (DBUS_INT64_TO_BE (val))
00134 #  define DBUS_UINT64_FROM_BE(val) (DBUS_UINT64_TO_BE (val))
00135 #endif /* DBUS_HAVE_INT64 */
00136 
00137 #ifndef DBUS_HAVE_INT64
00138 
00142 typedef struct
00143 {
00144   dbus_uint32_t first32;  
00145   dbus_uint32_t second32; 
00146 } DBus8ByteStruct;
00147 #endif /* DBUS_HAVE_INT64 */
00148 
00154 typedef union
00155 {
00156   dbus_int16_t  i16;   
00157   dbus_uint16_t u16;   
00158   dbus_int32_t  i32;   
00159   dbus_uint32_t u32;   
00160 #ifdef DBUS_HAVE_INT64
00161   dbus_int64_t  i64;   
00162   dbus_uint64_t u64;   
00163 #else
00164   DBus8ByteStruct u64; 
00165 #endif
00166   double dbl;          
00167   unsigned char byt;   
00168   char *str;           
00169 } DBusBasicValue;
00170 
00171 #ifdef DBUS_DISABLE_ASSERT
00172 #define _dbus_unpack_uint16(byte_order, data)           \
00173    (((byte_order) == DBUS_LITTLE_ENDIAN) ?              \
00174      DBUS_UINT16_FROM_LE (*(dbus_uint16_t*)(data)) :    \
00175      DBUS_UINT16_FROM_BE (*(dbus_uint16_t*)(data)))
00176 
00177 #define _dbus_unpack_uint32(byte_order, data)           \
00178    (((byte_order) == DBUS_LITTLE_ENDIAN) ?              \
00179      DBUS_UINT32_FROM_LE (*(dbus_uint32_t*)(data)) :    \
00180      DBUS_UINT32_FROM_BE (*(dbus_uint32_t*)(data)))
00181 #endif
00182 
00183 #ifndef _dbus_unpack_uint16
00184 dbus_uint16_t _dbus_unpack_uint16 (int                  byte_order,
00185                                    const unsigned char *data);
00186 #endif
00187 
00188 void          _dbus_pack_uint32   (dbus_uint32_t        value,
00189                                    int                  byte_order,
00190                                    unsigned char       *data);
00191 #ifndef _dbus_unpack_uint32
00192 dbus_uint32_t _dbus_unpack_uint32 (int                  byte_order,
00193                                    const unsigned char *data);
00194 #endif
00195 
00196 dbus_bool_t   _dbus_marshal_set_basic         (DBusString       *str,
00197                                                int               pos,
00198                                                int               type,
00199                                                const void       *value,
00200                                                int               byte_order,
00201                                                int              *old_end_pos,
00202                                                int              *new_end_pos);
00203 dbus_bool_t   _dbus_marshal_write_basic       (DBusString       *str,
00204                                                int               insert_at,
00205                                                int               type,
00206                                                const void       *value,
00207                                                int               byte_order,
00208                                                int              *pos_after);
00209 dbus_bool_t   _dbus_marshal_write_fixed_multi (DBusString       *str,
00210                                                int               insert_at,
00211                                                int               element_type,
00212                                                const void       *value,
00213                                                int               n_elements,
00214                                                int               byte_order,
00215                                                int              *pos_after);
00216 void          _dbus_marshal_read_basic        (const DBusString *str,
00217                                                int               pos,
00218                                                int               type,
00219                                                void             *value,
00220                                                int               byte_order,
00221                                                int              *new_pos);
00222 void          _dbus_marshal_read_fixed_multi  (const DBusString *str,
00223                                                int               pos,
00224                                                int               element_type,
00225                                                void             *value,
00226                                                int               n_elements,
00227                                                int               byte_order,
00228                                                int              *new_pos);
00229 void          _dbus_marshal_skip_basic        (const DBusString *str,
00230                                                int               type,
00231                                                int               byte_order,
00232                                                int              *pos);
00233 void          _dbus_marshal_skip_array        (const DBusString *str,
00234                                                int               element_type,
00235                                                int               byte_order,
00236                                                int              *pos);
00237 void          _dbus_marshal_set_uint32        (DBusString       *str,
00238                                                int               pos,
00239                                                dbus_uint32_t     value,
00240                                                int               byte_order);
00241 dbus_uint32_t _dbus_marshal_read_uint32       (const DBusString *str,
00242                                                int               pos,
00243                                                int               byte_order,
00244                                                int              *new_pos);
00245 dbus_bool_t   _dbus_type_is_valid             (int               typecode);
00246 int           _dbus_type_get_alignment        (int               typecode);
00247 dbus_bool_t   _dbus_type_is_fixed             (int               typecode);
00248 int           _dbus_type_get_alignment        (int               typecode);
00249 const char*   _dbus_type_to_string            (int               typecode);
00250 
00251 int           _dbus_first_type_in_signature   (const DBusString *str,
00252                                                int               pos);
00253 
00254 int           _dbus_first_type_in_signature_c_str   (const char       *str,
00255                                                      int               pos);
00256 
00257 void _dbus_swap_array (unsigned char *data,
00258                        int            n_elements,
00259                        int            alignment);
00260 
00261 #endif /* DBUS_MARSHAL_BASIC_H */

Generated on Tue Feb 24 16:40:39 2009 for D-Bus by  doxygen 1.5.1