D-Bus 1.4.1

dbus-server-protected.h

00001 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
00002 /* dbus-server-protected.h Used by subclasses of DBusServer object (internal to D-Bus implementation)
00003  *
00004  * Copyright (C) 2002  Red Hat Inc.
00005  *
00006  * Licensed under the Academic Free License version 2.1
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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
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   DBusMutex *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 void        _dbus_server_finalize_base  (DBusServer             *server);
00098 dbus_bool_t _dbus_server_add_watch      (DBusServer             *server,
00099                                          DBusWatch              *watch);
00100 void        _dbus_server_remove_watch   (DBusServer             *server,
00101                                          DBusWatch              *watch);
00102 void        _dbus_server_toggle_watch   (DBusServer             *server,
00103                                          DBusWatch              *watch,
00104                                          dbus_bool_t             enabled);
00105 dbus_bool_t _dbus_server_add_timeout    (DBusServer             *server,
00106                                          DBusTimeout            *timeout);
00107 void        _dbus_server_remove_timeout (DBusServer             *server,
00108                                          DBusTimeout            *timeout);
00109 void        _dbus_server_toggle_timeout (DBusServer             *server,
00110                                          DBusTimeout            *timeout,
00111                                          dbus_bool_t             enabled);
00112 
00113 void        _dbus_server_ref_unlocked   (DBusServer             *server);
00114 void        _dbus_server_unref_unlocked (DBusServer             *server);
00115 
00116 typedef enum
00117 {
00118   DBUS_SERVER_LISTEN_NOT_HANDLED, 
00119   DBUS_SERVER_LISTEN_OK,          
00120   DBUS_SERVER_LISTEN_BAD_ADDRESS, 
00121   DBUS_SERVER_LISTEN_DID_NOT_CONNECT, 
00122   DBUS_SERVER_LISTEN_ADDRESS_ALREADY_USED 
00123 } DBusServerListenResult;
00124 
00125 DBusServerListenResult _dbus_server_listen_platform_specific (DBusAddressEntry  *entry,
00126                                                               DBusServer       **server_p,
00127                                                               DBusError         *error);
00128 
00129 #ifdef DBUS_DISABLE_CHECKS
00130 #define TOOK_LOCK_CHECK(server)
00131 #define RELEASING_LOCK_CHECK(server)
00132 #define HAVE_LOCK_CHECK(server)
00133 #else
00134 #define TOOK_LOCK_CHECK(server) do {                \
00135     _dbus_assert (!(server)->have_server_lock); \
00136     (server)->have_server_lock = TRUE;          \
00137   } while (0)
00138 #define RELEASING_LOCK_CHECK(server) do {            \
00139     _dbus_assert ((server)->have_server_lock);   \
00140     (server)->have_server_lock = FALSE;          \
00141   } while (0)
00142 #define HAVE_LOCK_CHECK(server)        _dbus_assert ((server)->have_server_lock)
00143 /* A "DO_NOT_HAVE_LOCK_CHECK" is impossible since we need the lock to check the flag */
00144 #endif
00145 
00146 #define TRACE_LOCKS 0
00147 
00148 #define SERVER_LOCK(server)   do {                                              \
00149     if (TRACE_LOCKS) { _dbus_verbose ("LOCK\n"); }   \
00150     _dbus_mutex_lock ((server)->mutex);                                          \
00151     TOOK_LOCK_CHECK (server);                                                   \
00152   } while (0)
00153 
00154 #define SERVER_UNLOCK(server) do {                                                      \
00155     if (TRACE_LOCKS) { _dbus_verbose ("UNLOCK\n");  }        \
00156     RELEASING_LOCK_CHECK (server);                                                      \
00157     _dbus_mutex_unlock ((server)->mutex);                                                \
00158   } while (0)
00159 
00160 DBUS_END_DECLS
00161 
00162 #endif /* DBUS_SERVER_PROTECTED_H */