2006-10-21 Havoc Pennington <hp@redhat.com>
[platform/upstream/dbus.git] / dbus / dbus-connection.h
1 /* -*- mode: C; c-file-style: "gnu" -*- */
2 /* dbus-connection.h DBusConnection object
3  *
4  * Copyright (C) 2002, 2003  Red Hat Inc.
5  *
6  * Licensed under the Academic Free License version 2.1
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 #if !defined (DBUS_INSIDE_DBUS_H) && !defined (DBUS_COMPILATION)
24 #error "Only <dbus/dbus.h> can be included directly, this file may disappear or change contents."
25 #endif
26
27 #ifndef DBUS_CONNECTION_H
28 #define DBUS_CONNECTION_H
29
30 #include <dbus/dbus-errors.h>
31 #include <dbus/dbus-memory.h>
32 #include <dbus/dbus-message.h>
33 #include <dbus/dbus-shared.h>
34
35 DBUS_BEGIN_DECLS
36
37 /**
38  * @addtogroup DBusConnection
39  * @{
40  */
41
42 typedef struct DBusWatch DBusWatch;
43 typedef struct DBusTimeout DBusTimeout;
44 typedef struct DBusPreallocatedSend DBusPreallocatedSend;
45 typedef struct DBusPendingCall DBusPendingCall;
46 typedef struct DBusConnection DBusConnection;
47 typedef struct DBusObjectPathVTable DBusObjectPathVTable;
48
49 typedef enum
50 {
51   DBUS_WATCH_READABLE = 1 << 0, /**< As in POLLIN */
52   DBUS_WATCH_WRITABLE = 1 << 1, /**< As in POLLOUT */
53   DBUS_WATCH_ERROR    = 1 << 2, /**< As in POLLERR (can't watch for this, but
54                                  *   the flag can be passed to dbus_watch_handle()).
55                                  */
56   DBUS_WATCH_HANGUP   = 1 << 3  /**< As in POLLHUP (can't watch for it, but
57                                  *   can be present in current state). */
58 } DBusWatchFlags;
59
60 typedef enum
61 {
62   DBUS_DISPATCH_DATA_REMAINS,  /**< There is more data to potentially convert to messages. */
63   DBUS_DISPATCH_COMPLETE,      /**< All currently available data has been processed. */
64   DBUS_DISPATCH_NEED_MEMORY    /**< More memory is needed to continue. */
65 } DBusDispatchStatus;
66
67 typedef dbus_bool_t (* DBusAddWatchFunction)       (DBusWatch      *watch,
68                                                     void           *data);
69 typedef void        (* DBusWatchToggledFunction)   (DBusWatch      *watch,
70                                                     void           *data);
71 typedef void        (* DBusRemoveWatchFunction)    (DBusWatch      *watch,
72                                                     void           *data);
73 typedef dbus_bool_t (* DBusAddTimeoutFunction)     (DBusTimeout    *timeout,
74                                                     void           *data);
75 typedef void        (* DBusTimeoutToggledFunction) (DBusTimeout    *timeout,
76                                                     void           *data);
77 typedef void        (* DBusRemoveTimeoutFunction)  (DBusTimeout    *timeout,
78                                                     void           *data);
79 typedef void        (* DBusDispatchStatusFunction) (DBusConnection *connection,
80                                                     DBusDispatchStatus new_status,
81                                                     void           *data);
82 typedef void        (* DBusWakeupMainFunction)     (void           *data);
83 typedef dbus_bool_t (* DBusAllowUnixUserFunction)  (DBusConnection *connection,
84                                                     unsigned long   uid,
85                                                     void           *data);
86
87 typedef void (* DBusPendingCallNotifyFunction) (DBusPendingCall *pending,
88                                                 void            *user_data);
89
90
91 typedef DBusHandlerResult (* DBusHandleMessageFunction) (DBusConnection     *connection,
92                                                          DBusMessage        *message,
93                                                          void               *user_data);
94
95 DBusConnection*    dbus_connection_open                         (const char                 *address,
96                                                                  DBusError                  *error);
97 DBusConnection*    dbus_connection_open_private                 (const char                 *address,
98                                                                  DBusError                  *error);
99 DBusConnection*    dbus_connection_ref                          (DBusConnection             *connection);
100 void               dbus_connection_unref                        (DBusConnection             *connection);
101 void               dbus_connection_close                        (DBusConnection             *connection);
102 dbus_bool_t        dbus_connection_get_is_connected             (DBusConnection             *connection);
103 dbus_bool_t        dbus_connection_get_is_authenticated         (DBusConnection             *connection);
104 void               dbus_connection_set_exit_on_disconnect       (DBusConnection             *connection,
105                                                                  dbus_bool_t                 exit_on_disconnect);
106 void               dbus_connection_flush                        (DBusConnection             *connection);
107 dbus_bool_t        dbus_connection_read_write_dispatch          (DBusConnection             *connection,
108                                                                  int                         timeout_milliseconds);
109 dbus_bool_t        dbus_connection_read_write                   (DBusConnection             *connection,
110                                                                  int                         timeout_milliseconds);
111 DBusMessage*       dbus_connection_borrow_message               (DBusConnection             *connection);
112 void               dbus_connection_return_message               (DBusConnection             *connection,
113                                                                  DBusMessage                *message);
114 void               dbus_connection_steal_borrowed_message       (DBusConnection             *connection,
115                                                                  DBusMessage                *message);
116 DBusMessage*       dbus_connection_pop_message                  (DBusConnection             *connection);
117 DBusDispatchStatus dbus_connection_get_dispatch_status          (DBusConnection             *connection);
118 DBusDispatchStatus dbus_connection_dispatch                     (DBusConnection             *connection);
119 dbus_bool_t        dbus_connection_has_messages_to_send         (DBusConnection *connection);
120 dbus_bool_t        dbus_connection_send                         (DBusConnection             *connection,
121                                                                  DBusMessage                *message,
122                                                                  dbus_uint32_t              *client_serial);
123 dbus_bool_t        dbus_connection_send_with_reply              (DBusConnection             *connection,
124                                                                  DBusMessage                *message,
125                                                                  DBusPendingCall           **pending_return,
126                                                                  int                         timeout_milliseconds);
127 DBusMessage *      dbus_connection_send_with_reply_and_block    (DBusConnection             *connection,
128                                                                  DBusMessage                *message,
129                                                                  int                         timeout_milliseconds,
130                                                                  DBusError                  *error);
131 dbus_bool_t        dbus_connection_set_watch_functions          (DBusConnection             *connection,
132                                                                  DBusAddWatchFunction        add_function,
133                                                                  DBusRemoveWatchFunction     remove_function,
134                                                                  DBusWatchToggledFunction    toggled_function,
135                                                                  void                       *data,
136                                                                  DBusFreeFunction            free_data_function);
137 dbus_bool_t        dbus_connection_set_timeout_functions        (DBusConnection             *connection,
138                                                                  DBusAddTimeoutFunction      add_function,
139                                                                  DBusRemoveTimeoutFunction   remove_function,
140                                                                  DBusTimeoutToggledFunction  toggled_function,
141                                                                  void                       *data,
142                                                                  DBusFreeFunction            free_data_function);
143 void               dbus_connection_set_wakeup_main_function     (DBusConnection             *connection,
144                                                                  DBusWakeupMainFunction      wakeup_main_function,
145                                                                  void                       *data,
146                                                                  DBusFreeFunction            free_data_function);
147 void               dbus_connection_set_dispatch_status_function (DBusConnection             *connection,
148                                                                  DBusDispatchStatusFunction  function,
149                                                                  void                       *data,
150                                                                  DBusFreeFunction            free_data_function);
151 dbus_bool_t        dbus_connection_get_unix_user                (DBusConnection             *connection,
152                                                                  unsigned long              *uid);
153 dbus_bool_t        dbus_connection_get_unix_process_id          (DBusConnection             *connection,
154                                                                  unsigned long              *pid);
155 void               dbus_connection_set_unix_user_function       (DBusConnection             *connection,
156                                                                  DBusAllowUnixUserFunction   function,
157                                                                  void                       *data,
158                                                                  DBusFreeFunction            free_data_function);
159 void               dbus_connection_set_route_peer_messages      (DBusConnection             *connection,
160                                                                  dbus_bool_t                 value);
161
162
163 int          dbus_watch_get_fd      (DBusWatch        *watch);
164 unsigned int dbus_watch_get_flags   (DBusWatch        *watch);
165 void*        dbus_watch_get_data    (DBusWatch        *watch);
166 void         dbus_watch_set_data    (DBusWatch        *watch,
167                                      void             *data,
168                                      DBusFreeFunction  free_data_function);
169 dbus_bool_t  dbus_watch_handle      (DBusWatch        *watch,
170                                      unsigned int      flags);
171 dbus_bool_t  dbus_watch_get_enabled (DBusWatch        *watch);
172
173 int         dbus_timeout_get_interval (DBusTimeout      *timeout);
174 void*       dbus_timeout_get_data     (DBusTimeout      *timeout);
175 void        dbus_timeout_set_data     (DBusTimeout      *timeout,
176                                        void             *data,
177                                        DBusFreeFunction  free_data_function);
178 dbus_bool_t dbus_timeout_handle       (DBusTimeout      *timeout);
179 dbus_bool_t dbus_timeout_get_enabled  (DBusTimeout      *timeout);
180
181 /* Filters */
182
183 dbus_bool_t dbus_connection_add_filter    (DBusConnection            *connection,
184                                            DBusHandleMessageFunction  function,
185                                            void                      *user_data,
186                                            DBusFreeFunction           free_data_function);
187 void        dbus_connection_remove_filter (DBusConnection            *connection,
188                                            DBusHandleMessageFunction  function,
189                                            void                      *user_data);
190
191
192 /* Other */
193 dbus_bool_t dbus_connection_allocate_data_slot (dbus_int32_t     *slot_p);
194 void        dbus_connection_free_data_slot     (dbus_int32_t     *slot_p);
195 dbus_bool_t dbus_connection_set_data           (DBusConnection   *connection,
196                                                 dbus_int32_t      slot,
197                                                 void             *data,
198                                                 DBusFreeFunction  free_data_func);
199 void*       dbus_connection_get_data           (DBusConnection   *connection,
200                                                 dbus_int32_t      slot);
201
202 void        dbus_connection_set_change_sigpipe (dbus_bool_t       will_modify_sigpipe); 
203
204 void dbus_connection_set_max_message_size  (DBusConnection *connection,
205                                             long            size);
206 long dbus_connection_get_max_message_size  (DBusConnection *connection);
207 void dbus_connection_set_max_received_size (DBusConnection *connection,
208                                             long            size);
209 long dbus_connection_get_max_received_size (DBusConnection *connection);
210 long dbus_connection_get_outgoing_size     (DBusConnection *connection);
211
212 DBusPreallocatedSend* dbus_connection_preallocate_send       (DBusConnection       *connection);
213 void                  dbus_connection_free_preallocated_send (DBusConnection       *connection,
214                                                               DBusPreallocatedSend *preallocated);
215 void                  dbus_connection_send_preallocated      (DBusConnection       *connection,
216                                                               DBusPreallocatedSend *preallocated,
217                                                               DBusMessage          *message,
218                                                               dbus_uint32_t        *client_serial);
219
220
221 /* Object tree functionality */
222
223 typedef void              (* DBusObjectPathUnregisterFunction) (DBusConnection  *connection,
224                                                                 void            *user_data);
225 typedef DBusHandlerResult (* DBusObjectPathMessageFunction)    (DBusConnection  *connection,
226                                                                 DBusMessage     *message,
227                                                                 void            *user_data);
228
229 /**
230  * Virtual table that must be implemented to handle a portion of the
231  * object path hierarchy.
232  */
233 struct DBusObjectPathVTable
234 {
235   DBusObjectPathUnregisterFunction   unregister_function; /**< Function to unregister this handler */
236   DBusObjectPathMessageFunction      message_function; /**< Function to handle messages */
237   
238   void (* dbus_internal_pad1) (void *); /**< Reserved for future expansion */
239   void (* dbus_internal_pad2) (void *); /**< Reserved for future expansion */
240   void (* dbus_internal_pad3) (void *); /**< Reserved for future expansion */
241   void (* dbus_internal_pad4) (void *); /**< Reserved for future expansion */
242 };
243
244 dbus_bool_t dbus_connection_register_object_path   (DBusConnection              *connection,
245                                                     const char                  *path,
246                                                     const DBusObjectPathVTable  *vtable,
247                                                     void                        *user_data);
248 dbus_bool_t dbus_connection_register_fallback      (DBusConnection              *connection,
249                                                     const char                  *path,
250                                                     const DBusObjectPathVTable  *vtable,
251                                                     void                        *user_data);
252 dbus_bool_t dbus_connection_unregister_object_path (DBusConnection              *connection,
253                                                     const char                  *path);
254
255 dbus_bool_t dbus_connection_get_object_path_data   (DBusConnection              *connection,
256                                                     const char                  *path,
257                                                     void                       **data_p);
258
259 dbus_bool_t dbus_connection_list_registered        (DBusConnection              *connection,
260                                                     const char                  *parent_path,
261                                                     char                      ***child_entries);
262
263 dbus_bool_t dbus_connection_get_unix_fd            (DBusConnection              *connection,
264                                                     int                         *fd);
265 dbus_bool_t dbus_connection_get_socket             (DBusConnection              *connection,
266                                                     int                         *fd);
267
268 char*       dbus_get_local_machine_id              (void);
269
270 /** @} */
271
272 DBUS_END_DECLS
273
274 #endif /* DBUS_CONNECTION_H */