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