2003-08-28 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, 2003  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-message.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 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 enum
63 {
64   DBUS_HANDLER_RESULT_HANDLED,         /**< Message has had its effect */ 
65   DBUS_HANDLER_RESULT_NOT_YET_HANDLED, /**< Message has not had any effect */
66   DBUS_HANDLER_RESULT_NEED_MEMORY      /**< Need more memory to return another result */
67 } DBusHandlerResult;
68
69 typedef dbus_bool_t (* DBusAddWatchFunction)       (DBusWatch      *watch,
70                                                     void           *data);
71 typedef void        (* DBusWatchToggledFunction)   (DBusWatch      *watch,
72                                                     void           *data);
73 typedef void        (* DBusRemoveWatchFunction)    (DBusWatch      *watch,
74                                                     void           *data);
75 typedef dbus_bool_t (* DBusAddTimeoutFunction)     (DBusTimeout    *timeout,
76                                                     void           *data);
77 typedef void        (* DBusTimeoutToggledFunction) (DBusTimeout    *timeout,
78                                                     void           *data);
79 typedef void        (* DBusRemoveTimeoutFunction)  (DBusTimeout    *timeout,
80                                                     void           *data);
81 typedef void        (* DBusDispatchStatusFunction) (DBusConnection *connection,
82                                                     DBusDispatchStatus new_status,
83                                                     void           *data);
84 typedef void        (* DBusWakeupMainFunction)     (void           *data);
85 typedef dbus_bool_t (* DBusAllowUnixUserFunction)  (DBusConnection *connection,
86                                                     unsigned long   uid,
87                                                     void           *data);
88
89 typedef void (* DBusPendingCallNotifyFunction) (DBusPendingCall *pending,
90                                                 void            *user_data);
91
92 DBusConnection*    dbus_connection_open                         (const char                 *address,
93                                                                  DBusError                  *error);
94 void               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_flush                        (DBusConnection             *connection);
100 DBusMessage*       dbus_connection_borrow_message               (DBusConnection             *connection);
101 void               dbus_connection_return_message               (DBusConnection             *connection,
102                                                                  DBusMessage                *message);
103 void               dbus_connection_steal_borrowed_message       (DBusConnection             *connection,
104                                                                  DBusMessage                *message);
105 DBusMessage*       dbus_connection_pop_message                  (DBusConnection             *connection);
106 DBusDispatchStatus dbus_connection_get_dispatch_status          (DBusConnection             *connection);
107 DBusDispatchStatus dbus_connection_dispatch                     (DBusConnection             *connection);
108 dbus_bool_t        dbus_connection_send                         (DBusConnection             *connection,
109                                                                  DBusMessage                *message,
110                                                                  dbus_uint32_t              *client_serial);
111 dbus_bool_t        dbus_connection_send_with_reply              (DBusConnection             *connection,
112                                                                  DBusMessage                *message,
113                                                                  DBusPendingCall           **pending_return,
114                                                                  int                         timeout_milliseconds);
115 DBusMessage *      dbus_connection_send_with_reply_and_block    (DBusConnection             *connection,
116                                                                  DBusMessage                *message,
117                                                                  int                         timeout_milliseconds,
118                                                                  DBusError                  *error);
119 dbus_bool_t        dbus_connection_set_watch_functions          (DBusConnection             *connection,
120                                                                  DBusAddWatchFunction        add_function,
121                                                                  DBusRemoveWatchFunction     remove_function,
122                                                                  DBusWatchToggledFunction    toggled_function,
123                                                                  void                       *data,
124                                                                  DBusFreeFunction            free_data_function);
125 dbus_bool_t        dbus_connection_set_timeout_functions        (DBusConnection             *connection,
126                                                                  DBusAddTimeoutFunction      add_function,
127                                                                  DBusRemoveTimeoutFunction   remove_function,
128                                                                  DBusTimeoutToggledFunction  toggled_function,
129                                                                  void                       *data,
130                                                                  DBusFreeFunction            free_data_function);
131 void               dbus_connection_set_wakeup_main_function     (DBusConnection             *connection,
132                                                                  DBusWakeupMainFunction      wakeup_main_function,
133                                                                  void                       *data,
134                                                                  DBusFreeFunction            free_data_function);
135 void               dbus_connection_set_dispatch_status_function (DBusConnection             *connection,
136                                                                  DBusDispatchStatusFunction  function,
137                                                                  void                       *data,
138                                                                  DBusFreeFunction            free_data_function);
139 dbus_bool_t        dbus_connection_get_unix_user                (DBusConnection             *connection,
140                                                                  unsigned long              *uid);
141 void               dbus_connection_set_unix_user_function       (DBusConnection             *connection,
142                                                                  DBusAllowUnixUserFunction   function,
143                                                                  void                       *data,
144                                                                  DBusFreeFunction            free_data_function);
145
146
147 int          dbus_watch_get_fd      (DBusWatch        *watch);
148 unsigned int dbus_watch_get_flags   (DBusWatch        *watch);
149 void*        dbus_watch_get_data    (DBusWatch        *watch);
150 void         dbus_watch_set_data    (DBusWatch        *watch,
151                                      void             *data,
152                                      DBusFreeFunction  free_data_function);
153 dbus_bool_t  dbus_watch_handle      (DBusWatch        *watch,
154                                      unsigned int      flags);
155 dbus_bool_t  dbus_watch_get_enabled (DBusWatch        *watch);
156
157 int         dbus_timeout_get_interval (DBusTimeout      *timeout);
158 void*       dbus_timeout_get_data     (DBusTimeout      *timeout);
159 void        dbus_timeout_set_data     (DBusTimeout      *timeout,
160                                        void             *data,
161                                        DBusFreeFunction  free_data_function);
162 dbus_bool_t dbus_timeout_handle       (DBusTimeout      *timeout);
163 dbus_bool_t dbus_timeout_get_enabled  (DBusTimeout      *timeout);
164
165 /* Handlers */
166 dbus_bool_t dbus_connection_add_filter         (DBusConnection      *connection,
167                                                 DBusMessageHandler  *handler);
168 void        dbus_connection_remove_filter      (DBusConnection      *connection,
169                                                 DBusMessageHandler  *handler);
170
171 /* Other */
172 dbus_bool_t dbus_connection_allocate_data_slot (dbus_int32_t     *slot_p);
173 void        dbus_connection_free_data_slot     (dbus_int32_t     *slot_p);
174 dbus_bool_t dbus_connection_set_data           (DBusConnection   *connection,
175                                                 dbus_int32_t      slot,
176                                                 void             *data,
177                                                 DBusFreeFunction  free_data_func);
178 void*       dbus_connection_get_data           (DBusConnection   *connection,
179                                                 dbus_int32_t      slot);
180
181 void        dbus_connection_set_change_sigpipe (dbus_bool_t       will_modify_sigpipe); 
182
183 void dbus_connection_set_max_message_size  (DBusConnection *connection,
184                                             long            size);
185 long dbus_connection_get_max_message_size  (DBusConnection *connection);
186 void dbus_connection_set_max_received_size (DBusConnection *connection,
187                                             long            size);
188 long dbus_connection_get_max_received_size (DBusConnection *connection);
189 long dbus_connection_get_outgoing_size     (DBusConnection *connection);
190
191 DBusPreallocatedSend* dbus_connection_preallocate_send       (DBusConnection       *connection);
192 void                  dbus_connection_free_preallocated_send (DBusConnection       *connection,
193                                                               DBusPreallocatedSend *preallocated);
194 void                  dbus_connection_send_preallocated      (DBusConnection       *connection,
195                                                               DBusPreallocatedSend *preallocated,
196                                                               DBusMessage          *message,
197                                                               dbus_uint32_t        *client_serial);
198
199
200 /* Object tree functionality */
201
202 typedef void              (* DBusObjectPathUnregisterFunction) (DBusConnection  *connection,
203                                                                 const char     **path,
204                                                                 void            *user_data);
205 typedef DBusHandlerResult (* DBusObjectPathMessageFunction)    (DBusConnection  *connection,
206                                                                 DBusMessage     *message,
207                                                                 void            *user_data);
208
209 struct DBusObjectPathVTable
210 {
211   DBusObjectPathUnregisterFunction   unregister_function;
212   DBusObjectPathMessageFunction      message_function;
213   
214   void (* dbus_internal_pad1) (void *);
215   void (* dbus_internal_pad2) (void *);
216   void (* dbus_internal_pad3) (void *);
217   void (* dbus_internal_pad4) (void *);
218 };
219
220 dbus_bool_t dbus_connection_register_object_path   (DBusConnection              *connection,
221                                                     const char                 **path,
222                                                     const DBusObjectPathVTable  *vtable,
223                                                     void                        *user_data);
224 void        dbus_connection_unregister_object_path (DBusConnection              *connection,
225                                                     const char                 **path);
226
227
228 DBUS_END_DECLS;
229
230 #endif /* DBUS_CONNECTION_H */