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.h>
00037
00038 DBUS_BEGIN_DECLS;
00039
00040 void _dbus_warn (const char *format,
00041 ...) _DBUS_GNUC_PRINTF (1, 2);
00042 void _dbus_verbose_real (const char *format,
00043 ...) _DBUS_GNUC_PRINTF (1, 2);
00044 void _dbus_verbose_reset_real (void);
00045
00046 #if defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
00047 #define _DBUS_FUNCTION_NAME __func__
00048 #elif defined(__GNUC__)
00049 #define _DBUS_FUNCTION_NAME __FUNCTION__
00050 #else
00051 #define _DBUS_FUNCTION_NAME "unknown function"
00052 #endif
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064 #if defined(__GNUC__) && (__GNUC__ > 2) && defined(__OPTIMIZE__)
00065 #define _DBUS_BOOLEAN_EXPR(expr) \
00066 __extension__ ({ \
00067 int _dbus_boolean_var_; \
00068 if (expr) \
00069 _dbus_boolean_var_ = 1; \
00070 else \
00071 _dbus_boolean_var_ = 0; \
00072 _dbus_boolean_var_; \
00073 })
00074 #define _DBUS_LIKELY(expr) (__builtin_expect (_DBUS_BOOLEAN_EXPR(expr), 1))
00075 #define _DBUS_UNLIKELY(expr) (__builtin_expect (_DBUS_BOOLEAN_EXPR(expr), 0))
00076 #else
00077 #define _DBUS_LIKELY(expr) (expr)
00078 #define _DBUS_UNLIKELY(expr) (expr)
00079 #endif
00080
00081 #ifdef DBUS_ENABLE_VERBOSE_MODE
00082 # define _dbus_verbose _dbus_verbose_real
00083 # define _dbus_verbose_reset _dbus_verbose_reset_real
00084 #else
00085 # ifdef HAVE_ISO_VARARGS
00086 # define _dbus_verbose(...)
00087 # elif defined (HAVE_GNUC_VARARGS)
00088 # define _dbus_verbose(format...)
00089 # else
00090 # error "This compiler does not support varargs macros and thus verbose mode can't be disabled meaningfully"
00091 # endif
00092 # define _dbus_verbose_reset()
00093 #endif
00094
00095 const char* _dbus_strerror (int error_number);
00096
00097 #ifdef DBUS_DISABLE_ASSERT
00098 #define _dbus_assert(condition)
00099 #else
00100 void _dbus_real_assert (dbus_bool_t condition,
00101 const char *condition_text,
00102 const char *file,
00103 int line);
00104 #define _dbus_assert(condition) \
00105 _dbus_real_assert ((condition) != 0, #condition, __FILE__, __LINE__)
00106 #endif
00107
00108 #ifdef DBUS_DISABLE_ASSERT
00109 #define _dbus_assert_not_reached(explanation)
00110 #else
00111 void _dbus_real_assert_not_reached (const char *explanation,
00112 const char *file,
00113 int line) _DBUS_GNUC_NORETURN;
00114 #define _dbus_assert_not_reached(explanation) \
00115 _dbus_real_assert_not_reached (explanation, __FILE__, __LINE__)
00116 #endif
00117
00118 #ifdef DBUS_DISABLE_CHECKS
00119 #define _dbus_return_if_fail(condition)
00120 #define _dbus_return_val_if_fail(condition, val)
00121 #else
00122 extern const char _dbus_return_if_fail_warning_format[];
00123
00124 #define _dbus_return_if_fail(condition) do { \
00125 if (!(condition)) { \
00126 _dbus_warn (_dbus_return_if_fail_warning_format, \
00127 _dbus_getpid (), _DBUS_FUNCTION_NAME, #condition, __FILE__, __LINE__); \
00128 return; \
00129 } } while (0)
00130
00131 #define _dbus_return_val_if_fail(condition, val) do { \
00132 if (!(condition)) { \
00133 _dbus_warn (_dbus_return_if_fail_warning_format, \
00134 _dbus_getpid (), _DBUS_FUNCTION_NAME, #condition, __FILE__, __LINE__); \
00135 return (val); \
00136 } } while (0)
00137
00138 #endif
00139
00140 #define _DBUS_N_ELEMENTS(array) ((int) (sizeof ((array)) / sizeof ((array)[0])))
00141
00142 #define _DBUS_POINTER_TO_INT(pointer) ((long)(pointer))
00143 #define _DBUS_INT_TO_POINTER(integer) ((void*)((long)(integer)))
00144
00145 #define _DBUS_ZERO(object) (memset (&(object), '\0', sizeof ((object))))
00146
00147 #define _DBUS_STRUCT_OFFSET(struct_type, member) \
00148 ((long) ((unsigned char*) &((struct_type*) 0)->member))
00149
00150 #define _DBUS_ASSERT_ERROR_IS_SET(error) _dbus_assert ((error) == NULL || dbus_error_is_set ((error)))
00151 #define _DBUS_ASSERT_ERROR_IS_CLEAR(error) _dbus_assert ((error) == NULL || !dbus_error_is_set ((error)))
00152
00153 #define _dbus_return_if_error_is_set(error) _dbus_return_if_fail ((error) == NULL || !dbus_error_is_set ((error)))
00154 #define _dbus_return_val_if_error_is_set(error, val) _dbus_return_val_if_fail ((error) == NULL || !dbus_error_is_set ((error)), (val))
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167 #define _DBUS_ALIGN_VALUE(this, boundary) \
00168 (( ((unsigned long)(this)) + (((unsigned long)(boundary)) -1)) & (~(((unsigned long)(boundary))-1)))
00169
00170 #define _DBUS_ALIGN_ADDRESS(this, boundary) \
00171 ((void*)_DBUS_ALIGN_VALUE(this, boundary))
00172
00173 char* _dbus_strdup (const char *str);
00174 void* _dbus_memdup (const void *mem,
00175 size_t n_bytes);
00176 dbus_bool_t _dbus_string_array_contains (const char **array,
00177 const char *str);
00178 char** _dbus_dup_string_array (const char **array);
00179
00180 #define _DBUS_INT_MIN (-_DBUS_INT_MAX - 1)
00181 #define _DBUS_INT_MAX 2147483647
00182 #define _DBUS_UINT_MAX 0xffffffff
00183 #ifdef DBUS_HAVE_INT64
00184 #define _DBUS_INT64_MAX DBUS_INT64_CONSTANT (9223372036854775807)
00185 #define _DBUS_UINT64_MAX DBUS_UINT64_CONSTANT (0xffffffffffffffff)
00186 #endif
00187 #define _DBUS_ONE_KILOBYTE 1024
00188 #define _DBUS_ONE_MEGABYTE 1024 * _DBUS_ONE_KILOBYTE
00189 #define _DBUS_ONE_HOUR_IN_MILLISECONDS (1000 * 60 * 60)
00190 #define _DBUS_USEC_PER_SECOND (1000000)
00191
00192 #undef MAX
00193 #define MAX(a, b) (((a) > (b)) ? (a) : (b))
00194
00195 #undef MIN
00196 #define MIN(a, b) (((a) < (b)) ? (a) : (b))
00197
00198 #undef ABS
00199 #define ABS(a) (((a) < 0) ? -(a) : (a))
00200
00201 typedef void (* DBusForeachFunction) (void *element,
00202 void *data);
00203
00204 dbus_bool_t _dbus_set_fd_nonblocking (int fd,
00205 DBusError *error);
00206
00207 void _dbus_verbose_bytes (const unsigned char *data,
00208 int len);
00209 void _dbus_verbose_bytes_of_string (const DBusString *str,
00210 int start,
00211 int len);
00212
00213
00214 const char* _dbus_type_to_string (int type);
00215 const char* _dbus_header_field_to_string (int header_field);
00216
00217 extern const char _dbus_no_memory_message[];
00218 #define _DBUS_SET_OOM(error) dbus_set_error_const ((error), DBUS_ERROR_NO_MEMORY, _dbus_no_memory_message)
00219
00220 #ifdef DBUS_BUILD_TESTS
00221
00222 void _dbus_set_fail_alloc_counter (int until_next_fail);
00223 int _dbus_get_fail_alloc_counter (void);
00224 void _dbus_set_fail_alloc_failures (int failures_per_failure);
00225 int _dbus_get_fail_alloc_failures (void);
00226 dbus_bool_t _dbus_decrement_fail_alloc_counter (void);
00227 dbus_bool_t _dbus_disable_mem_pools (void);
00228 int _dbus_get_malloc_blocks_outstanding (void);
00229
00230 typedef dbus_bool_t (* DBusTestMemoryFunction) (void *data);
00231 dbus_bool_t _dbus_test_oom_handling (const char *description,
00232 DBusTestMemoryFunction func,
00233 void *data);
00234 #else
00235 #define _dbus_set_fail_alloc_counter(n)
00236 #define _dbus_get_fail_alloc_counter _DBUS_INT_MAX
00237
00238
00239
00240
00241 #define _dbus_decrement_fail_alloc_counter() (FALSE)
00242 #define _dbus_disable_mem_pools() (FALSE)
00243 #define _dbus_get_malloc_blocks_outstanding (0)
00244 #endif
00245
00246 typedef void (* DBusShutdownFunction) (void *data);
00247 dbus_bool_t _dbus_register_shutdown_func (DBusShutdownFunction function,
00248 void *data);
00249
00250 extern int _dbus_current_generation;
00251
00252
00253 #define _DBUS_LOCK_NAME(name) _dbus_lock_##name
00254 #define _DBUS_DECLARE_GLOBAL_LOCK(name) extern DBusMutex *_dbus_lock_##name
00255 #define _DBUS_DEFINE_GLOBAL_LOCK(name) DBusMutex *_dbus_lock_##name
00256 #define _DBUS_LOCK(name) dbus_mutex_lock (_dbus_lock_##name)
00257 #define _DBUS_UNLOCK(name) dbus_mutex_unlock (_dbus_lock_##name)
00258
00259 _DBUS_DECLARE_GLOBAL_LOCK (list);
00260 _DBUS_DECLARE_GLOBAL_LOCK (connection_slots);
00261 _DBUS_DECLARE_GLOBAL_LOCK (pending_call_slots);
00262 _DBUS_DECLARE_GLOBAL_LOCK (server_slots);
00263 _DBUS_DECLARE_GLOBAL_LOCK (message_slots);
00264 _DBUS_DECLARE_GLOBAL_LOCK (atomic);
00265 _DBUS_DECLARE_GLOBAL_LOCK (bus);
00266 _DBUS_DECLARE_GLOBAL_LOCK (shutdown_funcs);
00267 _DBUS_DECLARE_GLOBAL_LOCK (system_users);
00268 #define _DBUS_N_GLOBAL_LOCKS (9)
00269
00270 dbus_bool_t _dbus_threads_init_debug (void);
00271
00272 DBUS_END_DECLS;
00273
00274 #endif