00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef DBUS_SERVER_PROTECTED_H
00024 #define DBUS_SERVER_PROTECTED_H
00025
00026 #include <dbus/dbus-internals.h>
00027 #include <dbus/dbus-threads-internal.h>
00028 #include <dbus/dbus-server.h>
00029 #include <dbus/dbus-address.h>
00030 #include <dbus/dbus-timeout.h>
00031 #include <dbus/dbus-watch.h>
00032 #include <dbus/dbus-resources.h>
00033 #include <dbus/dbus-dataslot.h>
00034 #include <dbus/dbus-string.h>
00035
00036 DBUS_BEGIN_DECLS
00037
00038 typedef struct DBusServerVTable DBusServerVTable;
00039
00043 struct DBusServerVTable
00044 {
00045 void (* finalize) (DBusServer *server);
00048 void (* disconnect) (DBusServer *server);
00050 };
00051
00056 struct DBusServer
00057 {
00058 DBusAtomic refcount;
00059 const DBusServerVTable *vtable;
00060 DBusRMutex *mutex;
00062 DBusGUID guid;
00064 DBusString guid_hex;
00066 DBusWatchList *watches;
00067 DBusTimeoutList *timeouts;
00069 char *address;
00070 dbus_bool_t published_address;
00072 int max_connections;
00074 DBusDataSlotList slot_list;
00076 DBusNewConnectionFunction new_connection_function;
00078 void *new_connection_data;
00080 DBusFreeFunction new_connection_free_data_function;
00085 char **auth_mechanisms;
00087 unsigned int disconnected : 1;
00089 #ifndef DBUS_DISABLE_CHECKS
00090 unsigned int have_server_lock : 1;
00091 #endif
00092 };
00093
00094 dbus_bool_t _dbus_server_init_base (DBusServer *server,
00095 const DBusServerVTable *vtable,
00096 const DBusString *address,
00097 DBusError *error);
00098 void _dbus_server_finalize_base (DBusServer *server);
00099 dbus_bool_t _dbus_server_add_watch (DBusServer *server,
00100 DBusWatch *watch);
00101 void _dbus_server_remove_watch (DBusServer *server,
00102 DBusWatch *watch);
00103 DBUS_PRIVATE_EXPORT
00104 void _dbus_server_toggle_all_watches (DBusServer *server,
00105 dbus_bool_t enabled);
00106 dbus_bool_t _dbus_server_add_timeout (DBusServer *server,
00107 DBusTimeout *timeout);
00108 void _dbus_server_remove_timeout (DBusServer *server,
00109 DBusTimeout *timeout);
00110 void _dbus_server_toggle_timeout (DBusServer *server,
00111 DBusTimeout *timeout,
00112 dbus_bool_t enabled);
00113
00114 DBUS_PRIVATE_EXPORT
00115 void _dbus_server_ref_unlocked (DBusServer *server);
00116 DBUS_PRIVATE_EXPORT
00117 void _dbus_server_unref_unlocked (DBusServer *server);
00118
00119 typedef enum
00120 {
00121 DBUS_SERVER_LISTEN_NOT_HANDLED,
00122 DBUS_SERVER_LISTEN_OK,
00123 DBUS_SERVER_LISTEN_BAD_ADDRESS,
00124 DBUS_SERVER_LISTEN_DID_NOT_CONNECT,
00125 DBUS_SERVER_LISTEN_ADDRESS_ALREADY_USED
00126 } DBusServerListenResult;
00127
00128 DBusServerListenResult _dbus_server_listen_platform_specific (DBusAddressEntry *entry,
00129 DBusServer **server_p,
00130 DBusError *error);
00131
00132 #ifdef DBUS_ENABLE_VERBOSE_MODE
00133 void _dbus_server_trace_ref (DBusServer *server,
00134 int old_refcount,
00135 int new_refcount,
00136 const char *why);
00137 #else
00138 #define _dbus_server_trace_ref(s,o,n,w) \
00139 do \
00140 {\
00141 (void) (o); \
00142 (void) (n); \
00143 } while (0)
00144 #endif
00145
00146 #ifdef DBUS_DISABLE_CHECKS
00147 #define TOOK_LOCK_CHECK(server)
00148 #define RELEASING_LOCK_CHECK(server)
00149 #define HAVE_LOCK_CHECK(server)
00150 #else
00151 #define TOOK_LOCK_CHECK(server) do { \
00152 _dbus_assert (!(server)->have_server_lock); \
00153 (server)->have_server_lock = TRUE; \
00154 } while (0)
00155 #define RELEASING_LOCK_CHECK(server) do { \
00156 _dbus_assert ((server)->have_server_lock); \
00157 (server)->have_server_lock = FALSE; \
00158 } while (0)
00159 #define HAVE_LOCK_CHECK(server) _dbus_assert ((server)->have_server_lock)
00160
00161 #endif
00162
00163 #define TRACE_LOCKS 0
00164
00165 #define SERVER_LOCK(server) do { \
00166 if (TRACE_LOCKS) { _dbus_verbose ("LOCK\n"); } \
00167 _dbus_rmutex_lock ((server)->mutex); \
00168 TOOK_LOCK_CHECK (server); \
00169 } while (0)
00170
00171 #define SERVER_UNLOCK(server) do { \
00172 if (TRACE_LOCKS) { _dbus_verbose ("UNLOCK\n"); } \
00173 RELEASING_LOCK_CHECK (server); \
00174 _dbus_rmutex_unlock ((server)->mutex); \
00175 } while (0)
00176
00177 DBUS_END_DECLS
00178
00179 #endif