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