2003-08-25 Havoc Pennington <hp@pobox.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  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 #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-object.h>
33
34 DBUS_BEGIN_DECLS;
35
36 typedef struct DBusWatch DBusWatch;
37 typedef struct DBusTimeout DBusTimeout;
38 typedef struct DBusMessageHandler DBusMessageHandler;
39 typedef struct DBusPreallocatedSend DBusPreallocatedSend;
40 typedef struct DBusPendingCall DBusPendingCall;
41
42 typedef enum
43 {
44   DBUS_WATCH_READABLE = 1 << 0, /**< As in POLLIN */
45   DBUS_WATCH_WRITABLE = 1 << 1, /**< As in POLLOUT */
46   DBUS_WATCH_ERROR    = 1 << 2, /**< As in POLLERR (can't watch for this, but
47                                  *   the flag can be passed to dbus_watch_handle()).
48                                  */
49   DBUS_WATCH_HANGUP   = 1 << 3  /**< As in POLLHUP (can't watch for it, but
50                                  *   can be present in current state). */
51 } DBusWatchFlags;
52
53 typedef enum
54 {
55   DBUS_DISPATCH_DATA_REMAINS,  /**< There is more data to potentially convert to messages. */
56   DBUS_DISPATCH_COMPLETE,      /**< All currently available data has been processed. */
57   DBUS_DISPATCH_NEED_MEMORY    /**< More memory is needed to continue. */
58 } DBusDispatchStatus;
59
60 typedef dbus_bool_t (* DBusAddWatchFunction)       (DBusWatch      *watch,
61                                                     void           *data);
62 typedef void        (* DBusWatchToggledFunction)   (DBusWatch      *watch,
63                                                     void           *data);
64 typedef void        (* DBusRemoveWatchFunction)    (DBusWatch      *watch,
65                                                     void           *data);
66 typedef dbus_bool_t (* DBusAddTimeoutFunction)     (DBusTimeout    *timeout,
67                                                     void           *data);
68 typedef void        (* DBusTimeoutToggledFunction) (DBusTimeout    *timeout,
69                                                     void           *data);
70 typedef void        (* DBusRemoveTimeoutFunction)  (DBusTimeout    *timeout,
71                                                     void           *data);
72 typedef void        (* DBusDispatchStatusFunction) (DBusConnection *connection,
73                                                     DBusDispatchStatus new_status,
74                                                     void           *data);
75 typedef void        (* DBusWakeupMainFunction)     (void           *data);
76 typedef dbus_bool_t (* DBusAllowUnixUserFunction)  (DBusConnection *connection,
77                                                     unsigned long   uid,
78                                                     void           *data);
79
80 typedef void (* DBusPendingCallNotifyFunction) (DBusPendingCall *pending,
81                                                 void            *user_data);
82
83 DBusConnection*    dbus_connection_open                         (const char                 *address,
84                                                                  DBusError                  *error);
85 void               dbus_connection_ref                          (DBusConnection             *connection);
86 void               dbus_connection_unref                        (DBusConnection             *connection);
87 void               dbus_connection_disconnect                   (DBusConnection             *connection);
88 dbus_bool_t        dbus_connection_get_is_connected             (DBusConnection             *connection);
89 dbus_bool_t        dbus_connection_get_is_authenticated         (DBusConnection             *connection);
90 void               dbus_connection_flush                        (DBusConnection             *connection);
91 DBusMessage*       dbus_connection_borrow_message               (DBusConnection             *connection);
92 void               dbus_connection_return_message               (DBusConnection             *connection,
93                                                                  DBusMessage                *message);
94 void               dbus_connection_steal_borrowed_message       (DBusConnection             *connection,
95                                                                  DBusMessage                *message);
96 DBusMessage*       dbus_connection_pop_message                  (DBusConnection             *connection);
97 DBusDispatchStatus dbus_connection_get_dispatch_status          (DBusConnection             *connection);
98 DBusDispatchStatus dbus_connection_dispatch                     (DBusConnection             *connection);
99 dbus_bool_t        dbus_connection_send                         (DBusConnection             *connection,
100                                                                  DBusMessage                *message,
101                                                                  dbus_uint32_t              *client_serial);
102 dbus_bool_t        dbus_connection_send_with_reply              (DBusConnection             *connection,
103                                                                  DBusMessage                *message,
104                                                                  DBusPendingCall           **pending_return,
105                                                                  int                         timeout_milliseconds);
106 DBusMessage *      dbus_connection_send_with_reply_and_block    (DBusConnection             *connection,
107                                                                  DBusMessage                *message,
108                                                                  int                         timeout_milliseconds,
109                                                                  DBusError                  *error);
110 dbus_bool_t        dbus_connection_set_watch_functions          (DBusConnection             *connection,
111                                                                  DBusAddWatchFunction        add_function,
112                                                                  DBusRemoveWatchFunction     remove_function,
113                                                                  DBusWatchToggledFunction    toggled_function,
114                                                                  void                       *data,
115                                                                  DBusFreeFunction            free_data_function);
116 dbus_bool_t        dbus_connection_set_timeout_functions        (DBusConnection             *connection,
117                                                                  DBusAddTimeoutFunction      add_function,
118                                                                  DBusRemoveTimeoutFunction   remove_function,
119                                                                  DBusTimeoutToggledFunction  toggled_function,
120                                                                  void                       *data,
121                                                                  DBusFreeFunction            free_data_function);
122 void               dbus_connection_set_wakeup_main_function     (DBusConnection             *connection,
123                                                                  DBusWakeupMainFunction      wakeup_main_function,
124                                                                  void                       *data,
125                                                                  DBusFreeFunction            free_data_function);
126 void               dbus_connection_set_dispatch_status_function (DBusConnection             *connection,
127                                                                  DBusDispatchStatusFunction  function,
128                                                                  void                       *data,
129                                                                  DBusFreeFunction            free_data_function);
130 dbus_bool_t        dbus_connection_get_unix_user                (DBusConnection             *connection,
131                                                                  unsigned long              *uid);
132 void               dbus_connection_set_unix_user_function       (DBusConnection             *connection,
133                                                                  DBusAllowUnixUserFunction   function,
134                                                                  void                       *data,
135                                                                  DBusFreeFunction            free_data_function);
136
137
138 int          dbus_watch_get_fd      (DBusWatch        *watch);
139 unsigned int dbus_watch_get_flags   (DBusWatch        *watch);
140 void*        dbus_watch_get_data    (DBusWatch        *watch);
141 void         dbus_watch_set_data    (DBusWatch        *watch,
142                                      void             *data,
143                                      DBusFreeFunction  free_data_function);
144 dbus_bool_t  dbus_watch_handle      (DBusWatch        *watch,
145                                      unsigned int      flags);
146 dbus_bool_t  dbus_watch_get_enabled (DBusWatch        *watch);
147
148 int         dbus_timeout_get_interval (DBusTimeout      *timeout);
149 void*       dbus_timeout_get_data     (DBusTimeout      *timeout);
150 void        dbus_timeout_set_data     (DBusTimeout      *timeout,
151                                        void             *data,
152                                        DBusFreeFunction  free_data_function);
153 dbus_bool_t dbus_timeout_handle       (DBusTimeout      *timeout);
154 dbus_bool_t dbus_timeout_get_enabled  (DBusTimeout      *timeout);
155
156 /* Handlers */
157 dbus_bool_t dbus_connection_add_filter         (DBusConnection      *connection,
158                                                 DBusMessageHandler  *handler);
159 void        dbus_connection_remove_filter      (DBusConnection      *connection,
160                                                 DBusMessageHandler  *handler);
161
162 /* Objects */
163 dbus_bool_t dbus_connection_register_object   (DBusConnection          *connection,
164                                                const char             **interfaces,
165                                                const DBusObjectVTable  *vtable,
166                                                void                    *object_impl,
167                                                DBusObjectID            *object_id);
168 void        dbus_connection_unregister_object (DBusConnection          *connection,
169                                                const DBusObjectID      *object_id);
170
171
172 /* Other */
173 dbus_bool_t dbus_connection_allocate_data_slot (dbus_int32_t     *slot_p);
174 void        dbus_connection_free_data_slot     (dbus_int32_t     *slot_p);
175 dbus_bool_t dbus_connection_set_data           (DBusConnection   *connection,
176                                                 dbus_int32_t      slot,
177                                                 void             *data,
178                                                 DBusFreeFunction  free_data_func);
179 void*       dbus_connection_get_data           (DBusConnection   *connection,
180                                                 dbus_int32_t      slot);
181
182 void        dbus_connection_set_change_sigpipe (dbus_bool_t       will_modify_sigpipe); 
183
184 void dbus_connection_set_max_message_size  (DBusConnection *connection,
185                                             long            size);
186 long dbus_connection_get_max_message_size  (DBusConnection *connection);
187 void dbus_connection_set_max_received_size (DBusConnection *connection,
188                                             long            size);
189 long dbus_connection_get_max_received_size (DBusConnection *connection);
190 long dbus_connection_get_outgoing_size     (DBusConnection *connection);
191
192 DBusPreallocatedSend* dbus_connection_preallocate_send       (DBusConnection       *connection);
193 void                  dbus_connection_free_preallocated_send (DBusConnection       *connection,
194                                                               DBusPreallocatedSend *preallocated);
195 void                  dbus_connection_send_preallocated      (DBusConnection       *connection,
196                                                               DBusPreallocatedSend *preallocated,
197                                                               DBusMessage          *message,
198                                                               dbus_uint32_t        *client_serial);
199
200
201 /* Object tree functionality */
202
203 typedef struct DBusObjectTreeVTable DBusObjectTreeVTable;
204
205 typedef void              (* DBusObjectTreeUnregisterFunction) (DBusConnection  *connection,
206                                                                 const char     **path,
207                                                                 void            *user_data);
208 typedef DBusHandlerResult (* DBusObjectTreeMessageFunction)    (DBusConnection  *connection,
209                                                                 DBusMessage     *message,
210                                                                 void            *user_data);
211 typedef dbus_bool_t       (* DBusObjectTreeSubdirsFunction)    (DBusConnection  *connection,
212                                                                 const char     **path,
213                                                                 char          ***subdirs,
214                                                                 int             *n_subdirs,
215                                                                 void            *user_data);
216 typedef dbus_bool_t       (* DBusObjectTreeObjectsFunction)    (DBusConnection  *connection,
217                                                                 const char     **path,
218                                                                 DBusObjectID   **object_ids,
219                                                                 int             *n_object_ids,
220                                                                 void            *user_data);
221 typedef dbus_bool_t       (* DBusObjectTreeMethodsFunction)    (DBusConnection  *connection,
222                                                                 const char     **path,
223                                                                 DBusObjectID   **object_ids,
224                                                                 int             *n_object_ids,
225                                                                 void            *user_data);
226
227 struct DBusObjectTreeVTable
228 {
229   DBusObjectTreeUnregisterFunction   unregister_function;
230   DBusObjectTreeMessageFunction      message_function;
231   DBusObjectTreeSubdirsFunction      subdirs_function;
232   DBusObjectTreeObjectsFunction      objects_function;
233   DBusObjectTreeMethodsFunction      methods_function;
234   
235   void (* dbus_internal_pad1) (void *);
236   void (* dbus_internal_pad2) (void *);
237   void (* dbus_internal_pad3) (void *);
238   void (* dbus_internal_pad4) (void *);
239 };
240
241 dbus_bool_t dbus_connection_register_object_tree   (DBusConnection              *connection,
242                                                     const char                 **path,
243                                                     const DBusObjectTreeVTable  *vtable,
244                                                     void                        *user_data);
245 void        dbus_connection_unregister_object_tree (DBusConnection              *connection,
246                                                     const char                 **path);
247
248
249 DBUS_END_DECLS;
250
251 #endif /* DBUS_CONNECTION_H */