Main Page   Modules   Data Structures   File List   Data Fields   Related Pages  

dbus-internals.h

00001 /* -*- mode: C; c-file-style: "gnu" -*- */
00002 /* dbus-internals.h  random utility stuff (internal to D-BUS implementation)
00003  *
00004  * Copyright (C) 2002, 2003  Red Hat, Inc.
00005  *
00006  * Licensed under the Academic Free License version 1.2
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 #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 #ifdef DBUS_ENABLE_VERBOSE_MODE
00055 #  define _dbus_verbose _dbus_verbose_real
00056 #  define _dbus_verbose_reset _dbus_verbose_reset_real
00057 #else
00058 #  ifdef HAVE_ISO_VARARGS
00059 #    define _dbus_verbose(...)
00060 #  elif defined (HAVE_GNUC_VARARGS)
00061 #    define _dbus_verbose(format...)
00062 #  else
00063 #    error "This compiler does not support varargs macros and thus verbose mode can't be disabled meaningfully"
00064 #  endif
00065 #  define _dbus_verbose_reset()
00066 #endif /* !DBUS_ENABLE_VERBOSE_MODE */
00067 
00068 const char* _dbus_strerror (int error_number);
00069 
00070 #ifdef DBUS_DISABLE_ASSERT
00071 #define _dbus_assert(condition)
00072 #else
00073 void _dbus_real_assert (dbus_bool_t  condition,
00074                         const char  *condition_text,
00075                         const char  *file,
00076                         int          line);
00077 #define _dbus_assert(condition)                                         \
00078   _dbus_real_assert ((condition) != 0, #condition, __FILE__, __LINE__)
00079 #endif /* !DBUS_DISABLE_ASSERT */
00080 
00081 #ifdef DBUS_DISABLE_ASSERT
00082 #define _dbus_assert_not_reached(explanation)
00083 #else
00084 void _dbus_real_assert_not_reached (const char *explanation,
00085                                     const char *file,
00086                                     int         line) _DBUS_GNUC_NORETURN;
00087 #define _dbus_assert_not_reached(explanation)                                   \
00088   _dbus_real_assert_not_reached (explanation, __FILE__, __LINE__)
00089 #endif /* !DBUS_DISABLE_ASSERT */
00090 
00091 #ifdef DBUS_DISABLE_CHECKS
00092 #define _dbus_return_if_fail(condition)
00093 #define _dbus_return_val_if_fail(condition, val)
00094 #else
00095 extern const char _dbus_return_if_fail_warning_format[];
00096 
00097 #define _dbus_return_if_fail(condition) do {                            \
00098   if (!(condition)) {                                                   \
00099     _dbus_warn (_dbus_return_if_fail_warning_format,                    \
00100                 _DBUS_FUNCTION_NAME, #condition, __FILE__, __LINE__);   \
00101     return;                                                             \
00102   } } while (0)
00103 
00104 #define _dbus_return_val_if_fail(condition, val) do {                   \
00105   if (!(condition)) {                                                   \
00106     _dbus_warn (_dbus_return_if_fail_warning_format,                    \
00107                 _DBUS_FUNCTION_NAME, #condition, __FILE__, __LINE__);   \
00108     return (val);                                                       \
00109   } } while (0)
00110 
00111 #endif /* !DBUS_DISABLE_ASSERT */
00112 
00113 #define _DBUS_N_ELEMENTS(array) ((int) (sizeof ((array)) / sizeof ((array)[0])))
00114 
00115 #define _DBUS_POINTER_TO_INT(pointer) ((long)(pointer))
00116 #define _DBUS_INT_TO_POINTER(integer) ((void*)((long)(integer)))
00117 
00118 #define _DBUS_ZERO(object) (memset (&(object), '\0', sizeof ((object))))
00119 
00120 #define _DBUS_STRUCT_OFFSET(struct_type, member)        \
00121     ((long) ((unsigned char*) &((struct_type*) 0)->member))
00122 
00123 #define _DBUS_ASSERT_ERROR_IS_SET(error)   _dbus_assert ((error) == NULL || dbus_error_is_set ((error)))
00124 #define _DBUS_ASSERT_ERROR_IS_CLEAR(error) _dbus_assert ((error) == NULL || !dbus_error_is_set ((error)))
00125 
00126 #define _dbus_return_if_error_is_set(error) _dbus_return_if_fail ((error) == NULL || !dbus_error_is_set ((error)))
00127 #define _dbus_return_val_if_error_is_set(error, val) _dbus_return_val_if_fail ((error) == NULL || !dbus_error_is_set ((error)), (val))
00128 
00129 /* This alignment thing is from ORBit2 */
00130 /* Align a value upward to a boundary, expressed as a number of bytes.
00131  * E.g. align to an 8-byte boundary with argument of 8.
00132  */
00133 
00134 /*
00135  *   (this + boundary - 1)
00136  *          &
00137  *    ~(boundary - 1)
00138  */
00139 
00140 #define _DBUS_ALIGN_VALUE(this, boundary) \
00141   (( ((unsigned long)(this)) + (((unsigned long)(boundary)) -1)) & (~(((unsigned long)(boundary))-1)))
00142 
00143 #define _DBUS_ALIGN_ADDRESS(this, boundary) \
00144   ((void*)_DBUS_ALIGN_VALUE(this, boundary))
00145 
00146 char*       _dbus_strdup                (const char  *str);
00147 dbus_bool_t _dbus_string_array_contains (const char **array,
00148                                          const char  *str);
00149 char**      _dbus_dup_string_array      (const char **array);
00150 
00151 #define _DBUS_INT_MIN    (-_DBUS_INT_MAX - 1)
00152 #define _DBUS_INT_MAX    2147483647
00153 #define _DBUS_UINT_MAX   0xffffffff
00154 #ifdef DBUS_HAVE_INT64
00155 #define _DBUS_INT64_MAX  DBUS_INT64_CONSTANT (9223372036854775807)
00156 #define _DBUS_UINT64_MAX DBUS_UINT64_CONSTANT (0xffffffffffffffff)
00157 #endif
00158 #define _DBUS_ONE_KILOBYTE 1024
00159 #define _DBUS_ONE_MEGABYTE 1024 * _DBUS_ONE_KILOBYTE
00160 #define _DBUS_ONE_HOUR_IN_MILLISECONDS (1000 * 60 * 60)
00161 #define _DBUS_USEC_PER_SECOND          (1000000)
00162 
00163 #undef  MAX
00164 #define MAX(a, b)  (((a) > (b)) ? (a) : (b))
00165 
00166 #undef  MIN
00167 #define MIN(a, b)  (((a) < (b)) ? (a) : (b))
00168 
00169 #undef  ABS
00170 #define ABS(a)     (((a) < 0) ? -(a) : (a))
00171 
00172 typedef void (* DBusForeachFunction) (void *element,
00173                                       void *data);
00174 
00175 dbus_bool_t _dbus_set_fd_nonblocking (int             fd,
00176                                       DBusError      *error);
00177 
00178 void _dbus_verbose_bytes           (const unsigned char *data,
00179                                     int                  len);
00180 void _dbus_verbose_bytes_of_string (const DBusString    *str,
00181                                     int                  start,
00182                                     int                  len);
00183 
00184 
00185 const char* _dbus_type_to_string (int type);
00186 
00187 extern const char _dbus_no_memory_message[];
00188 #define _DBUS_SET_OOM(error) dbus_set_error ((error), DBUS_ERROR_NO_MEMORY, _dbus_no_memory_message)
00189 
00190 #ifdef DBUS_BUILD_TESTS
00191 /* Memory debugging */
00192 void        _dbus_set_fail_alloc_counter        (int  until_next_fail);
00193 int         _dbus_get_fail_alloc_counter        (void);
00194 void        _dbus_set_fail_alloc_failures       (int  failures_per_failure);
00195 int         _dbus_get_fail_alloc_failures       (void);
00196 dbus_bool_t _dbus_decrement_fail_alloc_counter  (void);
00197 dbus_bool_t _dbus_disable_mem_pools             (void);
00198 int         _dbus_get_malloc_blocks_outstanding (void);
00199 
00200 typedef dbus_bool_t (* DBusTestMemoryFunction)  (void *data);
00201 dbus_bool_t _dbus_test_oom_handling (const char             *description,
00202                                      DBusTestMemoryFunction  func,
00203                                      void                   *data);
00204 #else
00205 #define _dbus_set_fail_alloc_counter(n)
00206 #define _dbus_get_fail_alloc_counter _DBUS_INT_MAX
00207 
00208 /* These are constant expressions so that blocks
00209  * they protect should be optimized away
00210  */
00211 #define _dbus_decrement_fail_alloc_counter() (FALSE)
00212 #define _dbus_disable_mem_pools()            (FALSE)
00213 #define _dbus_get_malloc_blocks_outstanding  (0)
00214 #endif /* !DBUS_BUILD_TESTS */
00215 
00216 typedef void (* DBusShutdownFunction) (void *data);
00217 dbus_bool_t _dbus_register_shutdown_func (DBusShutdownFunction  function,
00218                                           void                 *data);
00219 
00220 extern int _dbus_current_generation;
00221 
00222 /* Thread initializers */
00223 #define _DBUS_LOCK_NAME(name)           _dbus_lock_##name
00224 #define _DBUS_DECLARE_GLOBAL_LOCK(name) extern DBusMutex  *_dbus_lock_##name
00225 #define _DBUS_DEFINE_GLOBAL_LOCK(name)  DBusMutex         *_dbus_lock_##name  
00226 #define _DBUS_LOCK(name)                dbus_mutex_lock   (_dbus_lock_##name)
00227 #define _DBUS_UNLOCK(name)              dbus_mutex_unlock (_dbus_lock_##name)
00228 
00229 _DBUS_DECLARE_GLOBAL_LOCK (list);
00230 _DBUS_DECLARE_GLOBAL_LOCK (connection_slots);
00231 _DBUS_DECLARE_GLOBAL_LOCK (server_slots);
00232 _DBUS_DECLARE_GLOBAL_LOCK (message_slots);
00233 _DBUS_DECLARE_GLOBAL_LOCK (atomic);
00234 _DBUS_DECLARE_GLOBAL_LOCK (message_handler);
00235 _DBUS_DECLARE_GLOBAL_LOCK (bus);
00236 _DBUS_DECLARE_GLOBAL_LOCK (shutdown_funcs);
00237 _DBUS_DECLARE_GLOBAL_LOCK (system_users);
00238 #define _DBUS_N_GLOBAL_LOCKS (9)
00239 
00240 dbus_bool_t _dbus_threads_init_debug (void);
00241 
00242 DBUS_END_DECLS;
00243 
00244 #endif /* DBUS_INTERNALS_H */

Generated on Wed Oct 22 14:05:01 2003 for D-BUS by doxygen1.3-rc3