00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifdef DBUS_INSIDE_DBUS_H
00024 #error "You can't include dbus-internals.h in the public header dbus.h"
00025 #endif
00026
00027 #ifndef DBUS_INTERNALS_H
00028 #define DBUS_INTERNALS_H
00029
00030 #include <config.h>
00031
00032 #include <dbus/dbus-memory.h>
00033 #include <dbus/dbus-types.h>
00034 #include <dbus/dbus-errors.h>
00035 #include <dbus/dbus-sysdeps.h>
00036 #include <dbus/dbus-threads-internal.h>
00037
00038 DBUS_BEGIN_DECLS
00039
00040 #define DBUS_SESSION_BUS_DEFAULT_ADDRESS "autolaunch:"
00041
00042 void _dbus_warn (const char *format,
00043 ...) _DBUS_GNUC_PRINTF (1, 2);
00044
00045 void _dbus_warn_check_failed (const char *format,
00046 ...) _DBUS_GNUC_PRINTF (1, 2);
00047
00048
00049 #if defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
00050 #define _DBUS_FUNCTION_NAME __func__
00051 #elif defined(__GNUC__)
00052 #define _DBUS_FUNCTION_NAME __FUNCTION__
00053 #else
00054 #define _DBUS_FUNCTION_NAME "unknown function"
00055 #endif
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067 #if defined(__GNUC__) && (__GNUC__ > 2) && defined(__OPTIMIZE__)
00068 #define _DBUS_BOOLEAN_EXPR(expr) \
00069 __extension__ ({ \
00070 int _dbus_boolean_var_; \
00071 if (expr) \
00072 _dbus_boolean_var_ = 1; \
00073 else \
00074 _dbus_boolean_var_ = 0; \
00075 _dbus_boolean_var_; \
00076 })
00077 #define _DBUS_LIKELY(expr) (__builtin_expect (_DBUS_BOOLEAN_EXPR(expr), 1))
00078 #define _DBUS_UNLIKELY(expr) (__builtin_expect (_DBUS_BOOLEAN_EXPR(expr), 0))
00079 #else
00080 #define _DBUS_LIKELY(expr) (expr)
00081 #define _DBUS_UNLIKELY(expr) (expr)
00082 #endif
00083
00084 #ifdef DBUS_ENABLE_VERBOSE_MODE
00085
00086 void _dbus_verbose_real (const char *format,
00087 ...) _DBUS_GNUC_PRINTF (1, 2);
00088 void _dbus_verbose_reset_real (void);
00089 dbus_bool_t _dbus_is_verbose_real (void);
00090
00091 # define _dbus_verbose _dbus_verbose_real
00092 # define _dbus_verbose_reset _dbus_verbose_reset_real
00093 # define _dbus_is_verbose _dbus_is_verbose_real
00094 #else
00095 # ifdef HAVE_ISO_VARARGS
00096 # define _dbus_verbose(...)
00097 # elif defined (HAVE_GNUC_VARARGS)
00098 # define _dbus_verbose(format...)
00099 # else
00100 # error "This compiler does not support varargs macros and thus verbose mode can't be disabled meaningfully"
00101 # endif
00102 # define _dbus_verbose_reset()
00103 # define _dbus_is_verbose() FALSE
00104 #endif
00105
00106 const char* _dbus_strerror (int error_number);
00107
00108 #ifdef DBUS_DISABLE_ASSERT
00109 #define _dbus_assert(condition)
00110 #else
00111 void _dbus_real_assert (dbus_bool_t condition,
00112 const char *condition_text,
00113 const char *file,
00114 int line,
00115 const char *func);
00116 #define _dbus_assert(condition) \
00117 _dbus_real_assert ((condition) != 0, #condition, __FILE__, __LINE__, _DBUS_FUNCTION_NAME)
00118 #endif
00119
00120 #ifdef DBUS_DISABLE_ASSERT
00121 #define _dbus_assert_not_reached(explanation)
00122 #else
00123 void _dbus_real_assert_not_reached (const char *explanation,
00124 const char *file,
00125 int line) _DBUS_GNUC_NORETURN;
00126 #define _dbus_assert_not_reached(explanation) \
00127 _dbus_real_assert_not_reached (explanation, __FILE__, __LINE__)
00128 #endif
00129
00130 #ifdef DBUS_DISABLE_CHECKS
00131 #define _dbus_return_if_fail(condition)
00132 #define _dbus_return_val_if_fail(condition, val)
00133 #else
00134 extern const char _dbus_return_if_fail_warning_format[];
00135
00136 #define _dbus_return_if_fail(condition) do { \
00137 _dbus_assert ((*(const char*)_DBUS_FUNCTION_NAME) != '_'); \
00138 if (!(condition)) { \
00139 _dbus_warn_check_failed (_dbus_return_if_fail_warning_format, \
00140 _DBUS_FUNCTION_NAME, #condition, __FILE__, __LINE__); \
00141 return; \
00142 } } while (0)
00143
00144 #define _dbus_return_val_if_fail(condition, val) do { \
00145 _dbus_assert ((*(const char*)_DBUS_FUNCTION_NAME) != '_'); \
00146 if (!(condition)) { \
00147 _dbus_warn_check_failed (_dbus_return_if_fail_warning_format, \
00148 _DBUS_FUNCTION_NAME, #condition, __FILE__, __LINE__); \
00149 return (val); \
00150 } } while (0)
00151
00152 #endif
00153
00154 #define _DBUS_N_ELEMENTS(array) ((int) (sizeof ((array)) / sizeof ((array)[0])))
00155
00156 #define _DBUS_POINTER_TO_INT(pointer) ((long)(pointer))
00157 #define _DBUS_INT_TO_POINTER(integer) ((void*)((long)(integer)))
00158
00159 #define _DBUS_ZERO(object) (memset (&(object), '\0', sizeof ((object))))
00160
00161 #define _DBUS_STRUCT_OFFSET(struct_type, member) \
00162 ((long) ((unsigned char*) &((struct_type*) 0)->member))
00163
00164 #ifdef DBUS_DISABLE_CHECKS
00165
00166
00167
00168 #define _DBUS_ASSERT_ERROR_IS_SET(error)
00169 #define _DBUS_ASSERT_ERROR_IS_CLEAR(error)
00170 #else
00171 #define _DBUS_ASSERT_ERROR_IS_SET(error) _dbus_assert ((error) == NULL || dbus_error_is_set ((error)))
00172 #define _DBUS_ASSERT_ERROR_IS_CLEAR(error) _dbus_assert ((error) == NULL || !dbus_error_is_set ((error)))
00173 #endif
00174
00175 #define _dbus_return_if_error_is_set(error) _dbus_return_if_fail ((error) == NULL || !dbus_error_is_set ((error)))
00176 #define _dbus_return_val_if_error_is_set(error, val) _dbus_return_val_if_fail ((error) == NULL || !dbus_error_is_set ((error)), (val))
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189 #define _DBUS_ALIGN_VALUE(this, boundary) \
00190 (( ((unsigned long)(this)) + (((unsigned long)(boundary)) -1)) & (~(((unsigned long)(boundary))-1)))
00191
00192 #define _DBUS_ALIGN_ADDRESS(this, boundary) \
00193 ((void*)_DBUS_ALIGN_VALUE(this, boundary))
00194
00195
00196 char* _dbus_strdup (const char *str);
00197 void* _dbus_memdup (const void *mem,
00198 size_t n_bytes);
00199 dbus_bool_t _dbus_string_array_contains (const char **array,
00200 const char *str);
00201 char** _dbus_dup_string_array (const char **array);
00202
00203 #define _DBUS_INT16_MIN ((dbus_int16_t) 0x8000)
00204 #define _DBUS_INT16_MAX ((dbus_int16_t) 0x7fff)
00205 #define _DBUS_UINT16_MAX ((dbus_uint16_t)0xffff)
00206 #define _DBUS_INT32_MIN ((dbus_int32_t) 0x80000000)
00207 #define _DBUS_INT32_MAX ((dbus_int32_t) 0x7fffffff)
00208 #define _DBUS_UINT32_MAX ((dbus_uint32_t)0xffffffff)
00209
00210 #define _DBUS_INT_MIN _DBUS_INT32_MIN
00211 #define _DBUS_INT_MAX _DBUS_INT32_MAX
00212 #define _DBUS_UINT_MAX _DBUS_UINT32_MAX
00213 #ifdef DBUS_HAVE_INT64
00214 #define _DBUS_INT64_MAX DBUS_INT64_CONSTANT (0x7fffffffffffffff)
00215 #define _DBUS_UINT64_MAX DBUS_UINT64_CONSTANT (0xffffffffffffffff)
00216 #endif
00217 #define _DBUS_ONE_KILOBYTE 1024
00218 #define _DBUS_ONE_MEGABYTE 1024 * _DBUS_ONE_KILOBYTE
00219 #define _DBUS_ONE_HOUR_IN_MILLISECONDS (1000 * 60 * 60)
00220 #define _DBUS_USEC_PER_SECOND (1000000)
00221
00222 #undef MAX
00223 #define MAX(a, b) (((a) > (b)) ? (a) : (b))
00224
00225 #undef MIN
00226 #define MIN(a, b) (((a) < (b)) ? (a) : (b))
00227
00228 #undef ABS
00229 #define ABS(a) (((a) < 0) ? -(a) : (a))
00230
00231 #define _DBUS_ISASCII(c) ((c) != '\0' && (((c) & ~0x7f) == 0))
00232
00233 typedef void (* DBusForeachFunction) (void *element,
00234 void *data);
00235
00236 dbus_bool_t _dbus_set_fd_nonblocking (int fd,
00237 DBusError *error);
00238
00239 void _dbus_verbose_bytes (const unsigned char *data,
00240 int len,
00241 int offset);
00242 void _dbus_verbose_bytes_of_string (const DBusString *str,
00243 int start,
00244 int len);
00245
00246 const char* _dbus_header_field_to_string (int header_field);
00247
00248 extern const char _dbus_no_memory_message[];
00249 #define _DBUS_SET_OOM(error) dbus_set_error_const ((error), DBUS_ERROR_NO_MEMORY, _dbus_no_memory_message)
00250
00251 #ifdef DBUS_BUILD_TESTS
00252
00253 void _dbus_set_fail_alloc_counter (int until_next_fail);
00254 int _dbus_get_fail_alloc_counter (void);
00255 void _dbus_set_fail_alloc_failures (int failures_per_failure);
00256 int _dbus_get_fail_alloc_failures (void);
00257 dbus_bool_t _dbus_decrement_fail_alloc_counter (void);
00258 dbus_bool_t _dbus_disable_mem_pools (void);
00259 int _dbus_get_malloc_blocks_outstanding (void);
00260
00261 typedef dbus_bool_t (* DBusTestMemoryFunction) (void *data);
00262 dbus_bool_t _dbus_test_oom_handling (const char *description,
00263 DBusTestMemoryFunction func,
00264 void *data);
00265 #else
00266 #define _dbus_set_fail_alloc_counter(n)
00267 #define _dbus_get_fail_alloc_counter _DBUS_INT_MAX
00268
00269
00270
00271
00272 #define _dbus_decrement_fail_alloc_counter() (FALSE)
00273 #define _dbus_disable_mem_pools() (FALSE)
00274 #define _dbus_get_malloc_blocks_outstanding (0)
00275 #endif
00276
00277 typedef void (* DBusShutdownFunction) (void *data);
00278 dbus_bool_t _dbus_register_shutdown_func (DBusShutdownFunction function,
00279 void *data);
00280
00281 extern int _dbus_current_generation;
00282
00283
00284 #define _DBUS_LOCK_NAME(name) _dbus_lock_##name
00285 #define _DBUS_DECLARE_GLOBAL_LOCK(name) extern DBusMutex *_dbus_lock_##name
00286 #define _DBUS_DEFINE_GLOBAL_LOCK(name) DBusMutex *_dbus_lock_##name
00287 #define _DBUS_LOCK(name) _dbus_mutex_lock (_dbus_lock_##name)
00288 #define _DBUS_UNLOCK(name) _dbus_mutex_unlock (_dbus_lock_##name)
00289
00290
00291 _DBUS_DECLARE_GLOBAL_LOCK (list);
00292 _DBUS_DECLARE_GLOBAL_LOCK (connection_slots);
00293 _DBUS_DECLARE_GLOBAL_LOCK (pending_call_slots);
00294 _DBUS_DECLARE_GLOBAL_LOCK (server_slots);
00295 _DBUS_DECLARE_GLOBAL_LOCK (message_slots);
00296
00297 _DBUS_DECLARE_GLOBAL_LOCK (atomic);
00298 _DBUS_DECLARE_GLOBAL_LOCK (bus);
00299 _DBUS_DECLARE_GLOBAL_LOCK (bus_datas);
00300 _DBUS_DECLARE_GLOBAL_LOCK (shutdown_funcs);
00301 _DBUS_DECLARE_GLOBAL_LOCK (system_users);
00302
00303 _DBUS_DECLARE_GLOBAL_LOCK (message_cache);
00304 _DBUS_DECLARE_GLOBAL_LOCK (shared_connections);
00305 _DBUS_DECLARE_GLOBAL_LOCK (win_fds);
00306 _DBUS_DECLARE_GLOBAL_LOCK (sid_atom_cache);
00307 _DBUS_DECLARE_GLOBAL_LOCK (machine_uuid);
00308 #define _DBUS_N_GLOBAL_LOCKS (15)
00309
00310 dbus_bool_t _dbus_threads_init_debug (void);
00311
00312 dbus_bool_t _dbus_address_append_escaped (DBusString *escaped,
00313 const DBusString *unescaped);
00314
00315 void _dbus_set_bad_address (DBusError *error,
00316 const char *address_problem_type,
00317 const char *address_problem_field,
00318 const char *address_problem_other);
00319
00320 #define DBUS_UUID_LENGTH_BYTES 16
00321 #define DBUS_UUID_LENGTH_WORDS (DBUS_UUID_LENGTH_BYTES / 4)
00322 #define DBUS_UUID_LENGTH_HEX (DBUS_UUID_LENGTH_BYTES * 2)
00323
00328 union DBusGUID
00329 {
00330 dbus_uint32_t as_uint32s[DBUS_UUID_LENGTH_WORDS];
00331 char as_bytes[DBUS_UUID_LENGTH_BYTES];
00332 };
00333
00334 void _dbus_generate_uuid (DBusGUID *uuid);
00335 dbus_bool_t _dbus_uuid_encode (const DBusGUID *uuid,
00336 DBusString *encoded);
00337 dbus_bool_t _dbus_read_uuid_file (const DBusString *filename,
00338 DBusGUID *uuid,
00339 dbus_bool_t create_if_not_found,
00340 DBusError *error);
00341
00342 dbus_bool_t _dbus_get_local_machine_uuid_encoded (DBusString *uuid_str);
00343
00344 DBUS_END_DECLS
00345
00346 #endif