Main Page | Modules | Data Structures | File List | Data Fields | Related Pages

dbus-marshal.h

00001 /* -*- mode: C; c-file-style: "gnu" -*- */
00002 /* dbus-marshal.h  Marshalling routines
00003  *
00004  * Copyright (C) 2002  CodeFactory AB
00005  *
00006  * Licensed under the Academic Free License version 2.0
00007  * 
00008  * This program is free software; you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License as published by
00010  * the Free Software Foundation; either version 2 of the License, or
00011  * (at your option) any later version.
00012  *
00013  * This program is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  * GNU General Public License for more details.
00017  * 
00018  * You should have received a copy of the GNU General Public License
00019  * along with this program; if not, write to the Free Software
00020  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00021  *
00022  */
00023 
00024 #ifndef DBUS_MARSHAL_H
00025 #define DBUS_MARSHAL_H
00026 
00027 #include <config.h>
00028 #include <dbus/dbus-protocol.h>
00029 #include <dbus/dbus-types.h>
00030 #include <dbus/dbus-arch-deps.h>
00031 #include <dbus/dbus-string.h>
00032 
00033 #ifndef PACKAGE
00034 #error "config.h not included here"
00035 #endif
00036 
00037 #ifdef WORDS_BIGENDIAN
00038 #define DBUS_COMPILER_BYTE_ORDER DBUS_BIG_ENDIAN
00039 #else
00040 #define DBUS_COMPILER_BYTE_ORDER DBUS_LITTLE_ENDIAN
00041 #endif
00042 
00043 #define DBUS_UINT32_SWAP_LE_BE_CONSTANT(val)    ((dbus_uint32_t) (      \
00044     (((dbus_uint32_t) (val) & (dbus_uint32_t) 0x000000ffU) << 24) |     \
00045     (((dbus_uint32_t) (val) & (dbus_uint32_t) 0x0000ff00U) <<  8) |     \
00046     (((dbus_uint32_t) (val) & (dbus_uint32_t) 0x00ff0000U) >>  8) |     \
00047     (((dbus_uint32_t) (val) & (dbus_uint32_t) 0xff000000U) >> 24)))
00048 
00049 #ifdef DBUS_HAVE_INT64
00050 
00051 #define DBUS_UINT64_SWAP_LE_BE_CONSTANT(val)    ((dbus_uint64_t) (              \
00052       (((dbus_uint64_t) (val) &                                                 \
00053         (dbus_uint64_t) DBUS_UINT64_CONSTANT (0x00000000000000ff)) << 56) |    \
00054       (((dbus_uint64_t) (val) &                                                 \
00055         (dbus_uint64_t) DBUS_UINT64_CONSTANT (0x000000000000ff00)) << 40) |    \
00056       (((dbus_uint64_t) (val) &                                                 \
00057         (dbus_uint64_t) DBUS_UINT64_CONSTANT (0x0000000000ff0000)) << 24) |    \
00058       (((dbus_uint64_t) (val) &                                                 \
00059         (dbus_uint64_t) DBUS_UINT64_CONSTANT (0x00000000ff000000)) <<  8) |    \
00060       (((dbus_uint64_t) (val) &                                                 \
00061         (dbus_uint64_t) DBUS_UINT64_CONSTANT (0x000000ff00000000)) >>  8) |    \
00062       (((dbus_uint64_t) (val) &                                                 \
00063         (dbus_uint64_t) DBUS_UINT64_CONSTANT (0x0000ff0000000000)) >> 24) |    \
00064       (((dbus_uint64_t) (val) &                                                 \
00065         (dbus_uint64_t) DBUS_UINT64_CONSTANT (0x00ff000000000000)) >> 40) |    \
00066       (((dbus_uint64_t) (val) &                                                 \
00067         (dbus_uint64_t) DBUS_UINT64_CONSTANT (0xff00000000000000)) >> 56)))
00068 #endif /* DBUS_HAVE_INT64 */
00069 
00070 #define DBUS_UINT32_SWAP_LE_BE(val) (DBUS_UINT32_SWAP_LE_BE_CONSTANT (val))
00071 #define DBUS_INT32_SWAP_LE_BE(val)  ((dbus_int32_t)DBUS_UINT32_SWAP_LE_BE_CONSTANT (val))
00072 
00073 #ifdef DBUS_HAVE_INT64
00074 #define DBUS_UINT64_SWAP_LE_BE(val) (DBUS_UINT64_SWAP_LE_BE_CONSTANT (val))
00075 #define DBUS_INT64_SWAP_LE_BE(val)  ((dbus_int64_t)DBUS_UINT64_SWAP_LE_BE_CONSTANT (val))
00076 #endif /* DBUS_HAVE_INT64 */
00077 
00078 #ifdef WORDS_BIGENDIAN
00079 #define DBUS_INT32_TO_BE(val)   ((dbus_int32_t) (val))
00080 #define DBUS_UINT32_TO_BE(val)  ((dbus_uint32_t) (val))
00081 #define DBUS_INT32_TO_LE(val)   (DBUS_INT32_SWAP_LE_BE (val))
00082 #define DBUS_UINT32_TO_LE(val)  (DBUS_UINT32_SWAP_LE_BE (val))
00083 #  ifdef DBUS_HAVE_INT64
00084 #define DBUS_INT64_TO_BE(val)   ((dbus_int64_t) (val))
00085 #define DBUS_UINT64_TO_BE(val)  ((dbus_uint64_t) (val))
00086 #define DBUS_INT64_TO_LE(val)   (DBUS_INT64_SWAP_LE_BE (val))
00087 #define DBUS_UINT64_TO_LE(val)  (DBUS_UINT64_SWAP_LE_BE (val))
00088 #  endif /* DBUS_HAVE_INT64 */
00089 #else
00090 #define DBUS_INT32_TO_LE(val)   ((dbus_int32_t) (val))
00091 #define DBUS_UINT32_TO_LE(val)  ((dbus_uint32_t) (val))
00092 #define DBUS_INT32_TO_BE(val)   ((dbus_int32_t) DBUS_UINT32_SWAP_LE_BE (val))
00093 #define DBUS_UINT32_TO_BE(val)  (DBUS_UINT32_SWAP_LE_BE (val))
00094 #  ifdef DBUS_HAVE_INT64
00095 #define DBUS_INT64_TO_LE(val)   ((dbus_int64_t) (val))
00096 #define DBUS_UINT64_TO_LE(val)  ((dbus_uint64_t) (val))
00097 #define DBUS_INT64_TO_BE(val)   ((dbus_int64_t) DBUS_UINT64_SWAP_LE_BE (val))
00098 #define DBUS_UINT64_TO_BE(val)  (DBUS_UINT64_SWAP_LE_BE (val))
00099 #  endif /* DBUS_HAVE_INT64 */
00100 #endif
00101 
00102 /* The transformation is symmetric, so the FROM just maps to the TO. */
00103 #define DBUS_INT32_FROM_LE(val)  (DBUS_INT32_TO_LE (val))
00104 #define DBUS_UINT32_FROM_LE(val) (DBUS_UINT32_TO_LE (val))
00105 #define DBUS_INT32_FROM_BE(val)  (DBUS_INT32_TO_BE (val))
00106 #define DBUS_UINT32_FROM_BE(val) (DBUS_UINT32_TO_BE (val))
00107 #ifdef DBUS_HAVE_INT64
00108 #define DBUS_INT64_FROM_LE(val)  (DBUS_INT64_TO_LE (val))
00109 #define DBUS_UINT64_FROM_LE(val) (DBUS_UINT64_TO_LE (val))
00110 #define DBUS_INT64_FROM_BE(val)  (DBUS_INT64_TO_BE (val))
00111 #define DBUS_UINT64_FROM_BE(val) (DBUS_UINT64_TO_BE (val))
00112 #endif /* DBUS_HAVE_INT64 */
00113 
00114 void          _dbus_pack_int32    (dbus_int32_t         value,
00115                                    int                  byte_order,
00116                                    unsigned char       *data);
00117 dbus_int32_t  _dbus_unpack_int32  (int                  byte_order,
00118                                    const unsigned char *data);
00119 void          _dbus_pack_uint32   (dbus_uint32_t        value,
00120                                    int                  byte_order,
00121                                    unsigned char       *data);
00122 dbus_uint32_t _dbus_unpack_uint32 (int                  byte_order,
00123                                    const unsigned char *data);
00124 #ifdef DBUS_HAVE_INT64
00125 void          _dbus_pack_int64    (dbus_int64_t         value,
00126                                    int                  byte_order,
00127                                    unsigned char       *data);
00128 dbus_int64_t  _dbus_unpack_int64  (int                  byte_order,
00129                                    const unsigned char *data);
00130 void          _dbus_pack_uint64   (dbus_uint64_t        value,
00131                                    int                  byte_order,
00132                                    unsigned char       *data);
00133 dbus_uint64_t _dbus_unpack_uint64 (int                  byte_order,
00134                                    const unsigned char *data);
00135 #endif /* DBUS_HAVE_INT64 */
00136 
00137 void        _dbus_marshal_set_int32  (DBusString       *str,
00138                                       int               byte_order,
00139                                       int               offset,
00140                                       dbus_int32_t      value);
00141 void        _dbus_marshal_set_uint32 (DBusString       *str,
00142                                       int               byte_order,
00143                                       int               offset,
00144                                       dbus_uint32_t     value);
00145 #ifdef DBUS_HAVE_INT64
00146 void        _dbus_marshal_set_int64  (DBusString       *str,
00147                                       int               byte_order,
00148                                       int               offset,
00149                                       dbus_int64_t      value);
00150 void        _dbus_marshal_set_uint64 (DBusString       *str,
00151                                       int               byte_order,
00152                                       int               offset,
00153                                       dbus_uint64_t     value);
00154 #endif /* DBUS_HAVE_INT64 */
00155 
00156 dbus_bool_t _dbus_marshal_set_string      (DBusString         *str,
00157                                            int                 byte_order,
00158                                            int                 offset,
00159                                            const DBusString   *value,
00160                                            int                 len);
00161 void        _dbus_marshal_set_object_path (DBusString         *str,
00162                                            int                 byte_order,
00163                                            int                 offset,
00164                                            const char        **path,
00165                                            int                 path_len);
00166 
00167 dbus_bool_t   _dbus_marshal_int32          (DBusString            *str,
00168                                             int                    byte_order,
00169                                             dbus_int32_t           value);
00170 dbus_bool_t   _dbus_marshal_uint32         (DBusString            *str,
00171                                             int                    byte_order,
00172                                             dbus_uint32_t          value);
00173 #ifdef DBUS_HAVE_INT64
00174 dbus_bool_t   _dbus_marshal_int64          (DBusString            *str,
00175                                             int                    byte_order,
00176                                             dbus_int64_t           value);
00177 dbus_bool_t   _dbus_marshal_uint64         (DBusString            *str,
00178                                             int                    byte_order,
00179                                             dbus_uint64_t          value);
00180 #endif /* DBUS_HAVE_INT64 */
00181 dbus_bool_t   _dbus_marshal_double         (DBusString            *str,
00182                                             int                    byte_order,
00183                                             double                 value);
00184 dbus_bool_t   _dbus_marshal_string         (DBusString            *str,
00185                                             int                    byte_order,
00186                                             const char            *value);
00187 dbus_bool_t   _dbus_marshal_byte_array     (DBusString            *str,
00188                                             int                    byte_order,
00189                                             const unsigned char   *value,
00190                                             int                    len);
00191 dbus_bool_t   _dbus_marshal_int32_array    (DBusString            *str,
00192                                             int                    byte_order,
00193                                             const dbus_int32_t    *value,
00194                                             int                    len);
00195 dbus_bool_t   _dbus_marshal_uint32_array   (DBusString            *str,
00196                                             int                    byte_order,
00197                                             const dbus_uint32_t   *value,
00198                                             int                    len);
00199 #ifdef DBUS_HAVE_INT64
00200 dbus_bool_t   _dbus_marshal_int64_array    (DBusString            *str,
00201                                             int                    byte_order,
00202                                             const dbus_int64_t    *value,
00203                                             int                    len);
00204 dbus_bool_t   _dbus_marshal_uint64_array   (DBusString            *str,
00205                                             int                    byte_order,
00206                                             const dbus_uint64_t   *value,
00207                                             int                    len);
00208 #endif /* DBUS_HAVE_INT64 */
00209 dbus_bool_t   _dbus_marshal_double_array   (DBusString            *str,
00210                                             int                    byte_order,
00211                                             const double          *value,
00212                                             int                    len);
00213 dbus_bool_t   _dbus_marshal_string_array   (DBusString            *str,
00214                                             int                    byte_order,
00215                                             const char           **value,
00216                                             int                    len);
00217 dbus_bool_t   _dbus_marshal_object_path    (DBusString            *str,
00218                                             int                    byte_order,
00219                                             const char           **path,
00220                                             int                    path_len);
00221 
00222 double        _dbus_demarshal_double       (const DBusString      *str,
00223                                             int                    byte_order,
00224                                             int                    pos,
00225                                             int                   *new_pos);
00226 dbus_int32_t  _dbus_demarshal_int32        (const DBusString      *str,
00227                                             int                    byte_order,
00228                                             int                    pos,
00229                                             int                   *new_pos);
00230 dbus_uint32_t _dbus_demarshal_uint32       (const DBusString      *str,
00231                                             int                    byte_order,
00232                                             int                    pos,
00233                                             int                   *new_pos);
00234 #ifdef DBUS_HAVE_INT64
00235 dbus_int64_t  _dbus_demarshal_int64        (const DBusString      *str,
00236                                             int                    byte_order,
00237                                             int                    pos,
00238                                             int                   *new_pos);
00239 dbus_uint64_t _dbus_demarshal_uint64       (const DBusString      *str,
00240                                             int                    byte_order,
00241                                             int                    pos,
00242                                             int                   *new_pos);
00243 #endif /* DBUS_HAVE_INT64 */
00244 char *        _dbus_demarshal_string       (const DBusString      *str,
00245                                             int                    byte_order,
00246                                             int                    pos,
00247                                             int                   *new_pos);
00248 dbus_bool_t   _dbus_demarshal_byte_array   (const DBusString      *str,
00249                                             int                    byte_order,
00250                                             int                    pos,
00251                                             int                   *new_pos,
00252                                             unsigned char        **array,
00253                                             int                   *array_len);
00254 dbus_bool_t   _dbus_demarshal_int32_array  (const DBusString      *str,
00255                                             int                    byte_order,
00256                                             int                    pos,
00257                                             int                   *new_pos,
00258                                             dbus_int32_t         **array,
00259                                             int                   *array_len);
00260 dbus_bool_t   _dbus_demarshal_uint32_array (const DBusString      *str,
00261                                             int                    byte_order,
00262                                             int                    pos,
00263                                             int                   *new_pos,
00264                                             dbus_uint32_t        **array,
00265                                             int                   *array_len);
00266 #ifdef DBUS_HAVE_INT64
00267 dbus_bool_t   _dbus_demarshal_int64_array  (const DBusString      *str,
00268                                             int                    byte_order,
00269                                             int                    pos,
00270                                             int                   *new_pos,
00271                                             dbus_int64_t         **array,
00272                                             int                   *array_len);
00273 dbus_bool_t   _dbus_demarshal_uint64_array (const DBusString      *str,
00274                                             int                    byte_order,
00275                                             int                    pos,
00276                                             int                   *new_pos,
00277                                             dbus_uint64_t        **array,
00278                                             int                   *array_len);
00279 #endif /* DBUS_HAVE_INT64 */
00280 dbus_bool_t   _dbus_demarshal_double_array (const DBusString      *str,
00281                                             int                    byte_order,
00282                                             int                    pos,
00283                                             int                   *new_pos,
00284                                             double               **array,
00285                                             int                   *array_len);
00286 dbus_bool_t   _dbus_demarshal_string_array (const DBusString      *str,
00287                                             int                    byte_order,
00288                                             int                    pos,
00289                                             int                   *new_pos,
00290                                             char                ***array,
00291                                             int                   *array_len);
00292 dbus_bool_t   _dbus_demarshal_object_path  (const DBusString      *str,
00293                                             int                    byte_order,
00294                                             int                    pos,
00295                                             int                   *new_pos,
00296                                             char                ***path,
00297                                             int                   *path_len);
00298 
00299 dbus_bool_t _dbus_marshal_get_arg_end_pos (const DBusString *str,
00300                                            int               byte_order,
00301                                            int               type,
00302                                            int               pos,
00303                                            int              *end_pos);
00304 dbus_bool_t _dbus_marshal_validate_type   (const DBusString *str,
00305                                            int               pos,
00306                                            int              *type,
00307                                            int              *end_pos);
00308 dbus_bool_t _dbus_marshal_validate_arg    (const DBusString *str,
00309                                            int               depth,
00310                                            int               byte_order,
00311                                            int               type,
00312                                            int               array_type_pos,
00313                                            int               pos,
00314                                            int              *end_pos);
00315 
00316 dbus_bool_t _dbus_type_is_valid           (int               typecode);
00317 
00318 #endif /* DBUS_PROTOCOL_H */

Generated on Sun Mar 21 03:52:04 2004 for D-BUS by doxygen 1.3.6-20040222