2003-03-31 Havoc Pennington <hp@pobox.com>
[platform/upstream/dbus.git] / dbus / dbus-server-protected.h
1 /* -*- mode: C; c-file-style: "gnu" -*- */
2 /* dbus-server-protected.h Used by subclasses of DBusServer object (internal to D-BUS implementation)
3  *
4  * Copyright (C) 2002  Red Hat Inc.
5  *
6  * Licensed under the Academic Free License version 1.2
7  * 
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  * 
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  *
22  */
23 #ifndef DBUS_SERVER_PROTECTED_H
24 #define DBUS_SERVER_PROTECTED_H
25
26 #include <dbus/dbus-internals.h>
27 #include <dbus/dbus-server.h>
28 #include <dbus/dbus-timeout.h>
29 #include <dbus/dbus-watch.h>
30 #include <dbus/dbus-resources.h>
31 #include <dbus/dbus-dataslot.h>
32
33 DBUS_BEGIN_DECLS;
34
35 typedef struct DBusServerVTable DBusServerVTable;
36
37 struct DBusServerVTable
38 {
39   void        (* finalize)      (DBusServer *server);
40   /**< The finalize method must free the server. */
41
42   dbus_bool_t (* handle_watch)  (DBusServer  *server,
43                                  DBusWatch   *watch,
44                                  unsigned int flags);
45   /**< The handle_watch method handles reading/writing
46    * data as indicated by the flags.
47    */
48   
49   void        (* disconnect)    (DBusServer *server);
50   /**< Disconnect this server. */
51 };
52
53 struct DBusServer
54 {
55   int refcount;                               /**< Reference count. */
56   const DBusServerVTable *vtable;             /**< Virtual methods for this instance. */
57   DBusWatchList *watches;                     /**< Our watches */
58   DBusTimeoutList *timeouts;                  /**< Our timeouts */
59   
60   DBusCounter *connection_counter;            /**< Number of non-finalized DBusConnection
61                                                *   to this server
62                                                */
63
64   char *address;                              /**< Address this server is listening on. */
65   
66   int max_connections;                        /**< Max number of connections allowed at once. */
67
68   DBusDataSlotList slot_list;   /**< Data stored by allocated integer ID */
69   
70   DBusNewConnectionFunction  new_connection_function;
71   /**< Callback to invoke when a new connection is created. */
72   void *new_connection_data;
73   /**< Data for new connection callback */
74   DBusFreeFunction new_connection_free_data_function;
75   /**< Callback to invoke to free new_connection_data
76    * when server is finalized or data is replaced.
77    */
78   
79   unsigned int disconnected : 1;              /**< TRUE if we are disconnected. */
80 };
81
82 dbus_bool_t _dbus_server_init_base      (DBusServer             *server,
83                                          const DBusServerVTable *vtable,
84                                          const DBusString       *address);
85 void        _dbus_server_finalize_base  (DBusServer             *server);
86 dbus_bool_t _dbus_server_add_watch      (DBusServer             *server,
87                                          DBusWatch              *watch);
88 void        _dbus_server_remove_watch   (DBusServer             *server,
89                                          DBusWatch              *watch);
90 void        _dbus_server_toggle_watch   (DBusServer             *server,
91                                          DBusWatch              *watch,
92                                          dbus_bool_t             enabled);
93 dbus_bool_t _dbus_server_add_timeout    (DBusServer             *server,
94                                          DBusTimeout            *timeout);
95 void        _dbus_server_remove_timeout (DBusServer             *server,
96                                          DBusTimeout            *timeout);
97 void        _dbus_server_toggle_timeout (DBusServer             *server,
98                                          DBusTimeout            *timeout,
99                                          dbus_bool_t             enabled);
100
101
102
103 DBUS_END_DECLS;
104
105 #endif /* DBUS_SERVER_PROTECTED_H */