D-Bus
1.10.12
|
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00022 * 00023 */ 00024 00025 #ifndef DBUS_MARSHAL_BASIC_H 00026 #define DBUS_MARSHAL_BASIC_H 00027 00028 #ifdef HAVE_BYTESWAP_H 00029 #include <byteswap.h> 00030 #endif 00031 00032 #include <dbus/dbus-protocol.h> 00033 #include <dbus/dbus-types.h> 00034 #include <dbus/dbus-arch-deps.h> 00035 #include <dbus/dbus-string.h> 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 #ifdef HAVE_BYTESWAP_H 00044 #define DBUS_UINT16_SWAP_LE_BE_CONSTANT(val) bswap_16(val) 00045 #define DBUS_UINT32_SWAP_LE_BE_CONSTANT(val) bswap_32(val) 00046 #else /* HAVE_BYTESWAP_H */ 00047 00048 #define DBUS_UINT16_SWAP_LE_BE_CONSTANT(val) ((dbus_uint16_t) ( \ 00049 (dbus_uint16_t) ((dbus_uint16_t) (val) >> 8) | \ 00050 (dbus_uint16_t) ((dbus_uint16_t) (val) << 8))) 00051 00052 #define DBUS_UINT32_SWAP_LE_BE_CONSTANT(val) ((dbus_uint32_t) ( \ 00053 (((dbus_uint32_t) (val) & (dbus_uint32_t) 0x000000ffU) << 24) | \ 00054 (((dbus_uint32_t) (val) & (dbus_uint32_t) 0x0000ff00U) << 8) | \ 00055 (((dbus_uint32_t) (val) & (dbus_uint32_t) 0x00ff0000U) >> 8) | \ 00056 (((dbus_uint32_t) (val) & (dbus_uint32_t) 0xff000000U) >> 24))) 00057 00058 #endif /* HAVE_BYTESWAP_H */ 00059 00060 #ifdef HAVE_BYTESWAP_H 00061 #define DBUS_UINT64_SWAP_LE_BE_CONSTANT(val) bswap_64(val) 00062 #else /* HAVE_BYTESWAP_H */ 00063 00064 #define DBUS_UINT64_SWAP_LE_BE_CONSTANT(val) ((dbus_uint64_t) ( \ 00065 (((dbus_uint64_t) (val) & \ 00066 (dbus_uint64_t) DBUS_UINT64_CONSTANT (0x00000000000000ff)) << 56) | \ 00067 (((dbus_uint64_t) (val) & \ 00068 (dbus_uint64_t) DBUS_UINT64_CONSTANT (0x000000000000ff00)) << 40) | \ 00069 (((dbus_uint64_t) (val) & \ 00070 (dbus_uint64_t) DBUS_UINT64_CONSTANT (0x0000000000ff0000)) << 24) | \ 00071 (((dbus_uint64_t) (val) & \ 00072 (dbus_uint64_t) DBUS_UINT64_CONSTANT (0x00000000ff000000)) << 8) | \ 00073 (((dbus_uint64_t) (val) & \ 00074 (dbus_uint64_t) DBUS_UINT64_CONSTANT (0x000000ff00000000)) >> 8) | \ 00075 (((dbus_uint64_t) (val) & \ 00076 (dbus_uint64_t) DBUS_UINT64_CONSTANT (0x0000ff0000000000)) >> 24) | \ 00077 (((dbus_uint64_t) (val) & \ 00078 (dbus_uint64_t) DBUS_UINT64_CONSTANT (0x00ff000000000000)) >> 40) | \ 00079 (((dbus_uint64_t) (val) & \ 00080 (dbus_uint64_t) DBUS_UINT64_CONSTANT (0xff00000000000000)) >> 56))) 00081 00082 #endif /* HAVE_BYTESWAP_H */ 00083 00084 #define DBUS_UINT16_SWAP_LE_BE(val) (DBUS_UINT16_SWAP_LE_BE_CONSTANT (val)) 00085 #define DBUS_INT16_SWAP_LE_BE(val) ((dbus_int16_t)DBUS_UINT16_SWAP_LE_BE_CONSTANT (val)) 00086 00087 #define DBUS_UINT32_SWAP_LE_BE(val) (DBUS_UINT32_SWAP_LE_BE_CONSTANT (val)) 00088 #define DBUS_INT32_SWAP_LE_BE(val) ((dbus_int32_t)DBUS_UINT32_SWAP_LE_BE_CONSTANT (val)) 00089 00090 #define DBUS_UINT64_SWAP_LE_BE(val) (DBUS_UINT64_SWAP_LE_BE_CONSTANT (val)) 00091 #define DBUS_INT64_SWAP_LE_BE(val) ((dbus_int64_t)DBUS_UINT64_SWAP_LE_BE_CONSTANT (val)) 00092 00093 #ifdef WORDS_BIGENDIAN 00094 00095 # define DBUS_INT16_TO_BE(val) ((dbus_int16_t) (val)) 00096 # define DBUS_UINT16_TO_BE(val) ((dbus_uint16_t) (val)) 00097 # define DBUS_INT16_TO_LE(val) (DBUS_INT16_SWAP_LE_BE (val)) 00098 # define DBUS_UINT16_TO_LE(val) (DBUS_UINT16_SWAP_LE_BE (val)) 00099 # define DBUS_INT32_TO_BE(val) ((dbus_int32_t) (val)) 00100 # define DBUS_UINT32_TO_BE(val) ((dbus_uint32_t) (val)) 00101 # define DBUS_INT32_TO_LE(val) (DBUS_INT32_SWAP_LE_BE (val)) 00102 # define DBUS_UINT32_TO_LE(val) (DBUS_UINT32_SWAP_LE_BE (val)) 00103 # define DBUS_INT64_TO_BE(val) ((dbus_int64_t) (val)) 00104 # define DBUS_UINT64_TO_BE(val) ((dbus_uint64_t) (val)) 00105 # define DBUS_INT64_TO_LE(val) (DBUS_INT64_SWAP_LE_BE (val)) 00106 # define DBUS_UINT64_TO_LE(val) (DBUS_UINT64_SWAP_LE_BE (val)) 00107 00108 #else /* WORDS_BIGENDIAN */ 00109 00110 # define DBUS_INT16_TO_LE(val) ((dbus_int16_t) (val)) 00111 # define DBUS_UINT16_TO_LE(val) ((dbus_uint16_t) (val)) 00112 # define DBUS_INT16_TO_BE(val) ((dbus_int16_t) DBUS_UINT16_SWAP_LE_BE (val)) 00113 # define DBUS_UINT16_TO_BE(val) (DBUS_UINT16_SWAP_LE_BE (val)) 00114 # define DBUS_INT32_TO_LE(val) ((dbus_int32_t) (val)) 00115 # define DBUS_UINT32_TO_LE(val) ((dbus_uint32_t) (val)) 00116 # define DBUS_INT32_TO_BE(val) ((dbus_int32_t) DBUS_UINT32_SWAP_LE_BE (val)) 00117 # define DBUS_UINT32_TO_BE(val) (DBUS_UINT32_SWAP_LE_BE (val)) 00118 # define DBUS_INT64_TO_LE(val) ((dbus_int64_t) (val)) 00119 # define DBUS_UINT64_TO_LE(val) ((dbus_uint64_t) (val)) 00120 # define DBUS_INT64_TO_BE(val) ((dbus_int64_t) DBUS_UINT64_SWAP_LE_BE (val)) 00121 # define DBUS_UINT64_TO_BE(val) (DBUS_UINT64_SWAP_LE_BE (val)) 00122 #endif 00123 00124 /* The transformation is symmetric, so the FROM just maps to the TO. */ 00125 #define DBUS_INT16_FROM_LE(val) (DBUS_INT16_TO_LE (val)) 00126 #define DBUS_UINT16_FROM_LE(val) (DBUS_UINT16_TO_LE (val)) 00127 #define DBUS_INT16_FROM_BE(val) (DBUS_INT16_TO_BE (val)) 00128 #define DBUS_UINT16_FROM_BE(val) (DBUS_UINT16_TO_BE (val)) 00129 #define DBUS_INT32_FROM_LE(val) (DBUS_INT32_TO_LE (val)) 00130 #define DBUS_UINT32_FROM_LE(val) (DBUS_UINT32_TO_LE (val)) 00131 #define DBUS_INT32_FROM_BE(val) (DBUS_INT32_TO_BE (val)) 00132 #define DBUS_UINT32_FROM_BE(val) (DBUS_UINT32_TO_BE (val)) 00133 #define DBUS_INT64_FROM_LE(val) (DBUS_INT64_TO_LE (val)) 00134 #define DBUS_UINT64_FROM_LE(val) (DBUS_UINT64_TO_LE (val)) 00135 #define DBUS_INT64_FROM_BE(val) (DBUS_INT64_TO_BE (val)) 00136 #define DBUS_UINT64_FROM_BE(val) (DBUS_UINT64_TO_BE (val)) 00137 00138 #ifdef DBUS_DISABLE_ASSERT 00139 #define _dbus_unpack_uint16(byte_order, data) \ 00140 (((byte_order) == DBUS_LITTLE_ENDIAN) ? \ 00141 DBUS_UINT16_FROM_LE (*(dbus_uint16_t*)(data)) : \ 00142 DBUS_UINT16_FROM_BE (*(dbus_uint16_t*)(data))) 00143 00144 #define _dbus_unpack_uint32(byte_order, data) \ 00145 (((byte_order) == DBUS_LITTLE_ENDIAN) ? \ 00146 DBUS_UINT32_FROM_LE (*(dbus_uint32_t*)(data)) : \ 00147 DBUS_UINT32_FROM_BE (*(dbus_uint32_t*)(data))) 00148 #endif 00149 00150 #ifndef _dbus_unpack_uint16 00151 DBUS_PRIVATE_EXPORT 00152 dbus_uint16_t _dbus_unpack_uint16 (int byte_order, 00153 const unsigned char *data); 00154 #endif 00155 00156 void _dbus_pack_uint32 (dbus_uint32_t value, 00157 int byte_order, 00158 unsigned char *data); 00159 #ifndef _dbus_unpack_uint32 00160 DBUS_PRIVATE_EXPORT 00161 dbus_uint32_t _dbus_unpack_uint32 (int byte_order, 00162 const unsigned char *data); 00163 #endif 00164 00165 dbus_bool_t _dbus_marshal_set_basic (DBusString *str, 00166 int pos, 00167 int type, 00168 const void *value, 00169 int byte_order, 00170 int *old_end_pos, 00171 int *new_end_pos); 00172 dbus_bool_t _dbus_marshal_write_basic (DBusString *str, 00173 int insert_at, 00174 int type, 00175 const void *value, 00176 int byte_order, 00177 int *pos_after); 00178 dbus_bool_t _dbus_marshal_write_fixed_multi (DBusString *str, 00179 int insert_at, 00180 int element_type, 00181 const void *value, 00182 int n_elements, 00183 int byte_order, 00184 int *pos_after); 00185 void _dbus_marshal_read_basic (const DBusString *str, 00186 int pos, 00187 int type, 00188 void *value, 00189 int byte_order, 00190 int *new_pos); 00191 void _dbus_marshal_read_fixed_multi (const DBusString *str, 00192 int pos, 00193 int element_type, 00194 void *value, 00195 int n_elements, 00196 int byte_order, 00197 int *new_pos); 00198 void _dbus_marshal_skip_basic (const DBusString *str, 00199 int type, 00200 int byte_order, 00201 int *pos); 00202 void _dbus_marshal_skip_array (const DBusString *str, 00203 int element_type, 00204 int byte_order, 00205 int *pos); 00206 DBUS_PRIVATE_EXPORT 00207 void _dbus_marshal_set_uint32 (DBusString *str, 00208 int pos, 00209 dbus_uint32_t value, 00210 int byte_order); 00211 DBUS_PRIVATE_EXPORT 00212 dbus_uint32_t _dbus_marshal_read_uint32 (const DBusString *str, 00213 int pos, 00214 int byte_order, 00215 int *new_pos); 00216 int _dbus_type_get_alignment (int typecode); 00217 int _dbus_type_get_alignment (int typecode); 00218 DBUS_PRIVATE_EXPORT 00219 const char* _dbus_type_to_string (int typecode); 00220 00221 DBUS_PRIVATE_EXPORT 00222 int _dbus_first_type_in_signature (const DBusString *str, 00223 int pos); 00224 00225 int _dbus_first_type_in_signature_c_str (const char *str, 00226 int pos); 00227 00228 void _dbus_swap_array (unsigned char *data, 00229 int n_elements, 00230 int alignment); 00231 00232 #endif /* DBUS_MARSHAL_BASIC_H */