2003-07-12 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
41 typedef enum
42 {
43   DBUS_WATCH_READABLE = 1 << 0, /**< As in POLLIN */
44   DBUS_WATCH_WRITABLE = 1 << 1, /**< As in POLLOUT */
45   DBUS_WATCH_ERROR    = 1 << 2, /**< As in POLLERR (can't watch for this, but
46                                  *   the flag can be passed to dbus_watch_handle()).
47                                  */
48   DBUS_WATCH_HANGUP   = 1 << 3  /**< As in POLLHUP (can't watch for it, but
49                                  *   can be present in current state). */
50 } DBusWatchFlags;
51
52 typedef enum
53 {
54   DBUS_DISPATCH_DATA_REMAINS,  /**< There is more data to potentially convert to messages. */
55   DBUS_DISPATCH_COMPLETE,      /**< All currently available data has been processed. */
56   DBUS_DISPATCH_NEED_MEMORY    /**< More memory is needed to continue. */
57 } DBusDispatchStatus;
58
59 typedef dbus_bool_t (* DBusAddWatchFunction)       (DBusWatch      *watch,
60                                                     void           *data);
61 typedef void        (* DBusWatchToggledFunction)   (DBusWatch      *watch,
62                                                     void           *data);
63 typedef void        (* DBusRemoveWatchFunction)    (DBusWatch      *watch,
64                                                     void           *data);
65 typedef dbus_bool_t (* DBusAddTimeoutFunction)     (DBusTimeout    *timeout,
66                                                     void           *data);
67 typedef void        (* DBusTimeoutToggledFunction) (DBusTimeout    *timeout,
68                                                     void           *data);
69 typedef void        (* DBusRemoveTimeoutFunction)  (DBusTimeout    *timeout,
70                                                     void           *data);
71 typedef void        (* DBusDispatchStatusFunction) (DBusConnection *connection,
72                                                     DBusDispatchStatus new_status,
73                                                     void           *data);
74 typedef void        (* DBusWakeupMainFunction)     (void           *data);
75 typedef dbus_bool_t (* DBusAllowUnixUserFunction)  (DBusConnection *connection,
76                                                     unsigned long   uid,
77                                                     void           *data);
78
79 DBusConnection*    dbus_connection_open                         (const char                 *address,
80                                                                  DBusError                  *error);
81 void               dbus_connection_ref                          (DBusConnection             *connection);
82 void               dbus_connection_unref                        (DBusConnection             *connection);
83 void               dbus_connection_disconnect                   (DBusConnection             *connection);
84 dbus_bool_t        dbus_connection_get_is_connected             (DBusConnection             *connection);
85 dbus_bool_t        dbus_connection_get_is_authenticated         (DBusConnection             *connection);
86 void               dbus_connection_flush                        (DBusConnection             *connection);
87 DBusMessage*       dbus_connection_borrow_message               (DBusConnection             *connection);
88 void               dbus_connection_return_message               (DBusConnection             *connection,
89                                                                  DBusMessage                *message);
90 void               dbus_connection_steal_borrowed_message       (DBusConnection             *connection,
91                                                                  DBusMessage                *message);
92 DBusMessage*       dbus_connection_pop_message                  (DBusConnection             *connection);
93 DBusDispatchStatus dbus_connection_get_dispatch_status          (DBusConnection             *connection);
94 DBusDispatchStatus dbus_connection_dispatch                     (DBusConnection             *connection);
95 dbus_bool_t        dbus_connection_send                         (DBusConnection             *connection,
96                                                                  DBusMessage                *message,
97                                                                  dbus_uint32_t              *client_serial);
98 dbus_bool_t        dbus_connection_send_with_reply              (DBusConnection             *connection,
99                                                                  DBusMessage                *message,
100                                                                  DBusMessageHandler         *reply_handler,
101                                                                  int                         timeout_milliseconds);
102 DBusMessage *      dbus_connection_send_with_reply_and_block    (DBusConnection             *connection,
103                                                                  DBusMessage                *message,
104                                                                  int                         timeout_milliseconds,
105                                                                  DBusError                  *error);
106 dbus_bool_t        dbus_connection_set_watch_functions          (DBusConnection             *connection,
107                                                                  DBusAddWatchFunction        add_function,
108                                                                  DBusRemoveWatchFunction     remove_function,
109                                                                  DBusWatchToggledFunction    toggled_function,
110                                                                  void                       *data,
111                                                                  DBusFreeFunction            free_data_function);
112 dbus_bool_t        dbus_connection_set_timeout_functions        (DBusConnection             *connection,
113                                                                  DBusAddTimeoutFunction      add_function,
114                                                                  DBusRemoveTimeoutFunction   remove_function,
115                                                                  DBusTimeoutToggledFunction  toggled_function,
116                                                                  void                       *data,
117                                                                  DBusFreeFunction            free_data_function);
118 void               dbus_connection_set_wakeup_main_function     (DBusConnection             *connection,
119                                                                  DBusWakeupMainFunction      wakeup_main_function,
120                                                                  void                       *data,
121                                                                  DBusFreeFunction            free_data_function);
122 void               dbus_connection_set_dispatch_status_function (DBusConnection             *connection,
123                                                                  DBusDispatchStatusFunction  function,
124                                                                  void                       *data,
125                                                                  DBusFreeFunction            free_data_function);
126 dbus_bool_t        dbus_connection_get_unix_user                (DBusConnection             *connection,
127                                                                  unsigned long              *uid);
128 void               dbus_connection_set_unix_user_function       (DBusConnection             *connection,
129                                                                  DBusAllowUnixUserFunction   function,
130                                                                  void                       *data,
131                                                                  DBusFreeFunction            free_data_function);
132
133
134 int          dbus_watch_get_fd      (DBusWatch        *watch);
135 unsigned int dbus_watch_get_flags   (DBusWatch        *watch);
136 void*        dbus_watch_get_data    (DBusWatch        *watch);
137 void         dbus_watch_set_data    (DBusWatch        *watch,
138                                      void             *data,
139                                      DBusFreeFunction  free_data_function);
140 dbus_bool_t  dbus_watch_handle      (DBusWatch        *watch,
141                                      unsigned int      flags);
142 dbus_bool_t  dbus_watch_get_enabled (DBusWatch        *watch);
143
144 int         dbus_timeout_get_interval (DBusTimeout      *timeout);
145 void*       dbus_timeout_get_data     (DBusTimeout      *timeout);
146 void        dbus_timeout_set_data     (DBusTimeout      *timeout,
147                                        void             *data,
148                                        DBusFreeFunction  free_data_function);
149 dbus_bool_t dbus_timeout_handle       (DBusTimeout      *timeout);
150 dbus_bool_t dbus_timeout_get_enabled  (DBusTimeout      *timeout);
151
152 /* Handlers */
153 dbus_bool_t dbus_connection_add_filter         (DBusConnection      *connection,
154                                                 DBusMessageHandler  *handler);
155 void        dbus_connection_remove_filter      (DBusConnection      *connection,
156                                                 DBusMessageHandler  *handler);
157
158 /* Objects */
159 dbus_bool_t dbus_connection_register_object   (DBusConnection          *connection,
160                                                const char             **interfaces,
161                                                const DBusObjectVTable  *vtable,
162                                                void                    *object_impl,
163                                                DBusObjectID            *object_id);
164 void        dbus_connection_unregister_object (DBusConnection          *connection,
165                                                const DBusObjectID      *object_id);
166
167
168 /* Other */
169 dbus_bool_t dbus_connection_allocate_data_slot (dbus_int32_t     *slot_p);
170 void        dbus_connection_free_data_slot     (dbus_int32_t     *slot_p);
171 dbus_bool_t dbus_connection_set_data           (DBusConnection   *connection,
172                                                 dbus_int32_t      slot,
173                                                 void             *data,
174                                                 DBusFreeFunction  free_data_func);
175 void*       dbus_connection_get_data           (DBusConnection   *connection,
176                                                 dbus_int32_t      slot);
177
178 void        dbus_connection_set_change_sigpipe (dbus_bool_t       will_modify_sigpipe); 
179
180 void dbus_connection_set_max_message_size  (DBusConnection *connection,
181                                             long            size);
182 long dbus_connection_get_max_message_size  (DBusConnection *connection);
183 void dbus_connection_set_max_received_size (DBusConnection *connection,
184                                             long            size);
185 long dbus_connection_get_max_received_size (DBusConnection *connection);
186 long dbus_connection_get_outgoing_size     (DBusConnection *connection);
187
188 DBusPreallocatedSend* dbus_connection_preallocate_send       (DBusConnection       *connection);
189 void                  dbus_connection_free_preallocated_send (DBusConnection       *connection,
190                                                               DBusPreallocatedSend *preallocated);
191 void                  dbus_connection_send_preallocated      (DBusConnection       *connection,
192                                                               DBusPreallocatedSend *preallocated,
193                                                               DBusMessage          *message,
194                                                               dbus_uint32_t        *client_serial);
195
196
197 DBUS_END_DECLS;
198
199 #endif /* DBUS_CONNECTION_H */