2003-03-24 Havoc Pennington <hp@redhat.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-message.h>
32 #include <dbus/dbus-memory.h>
33
34 DBUS_BEGIN_DECLS;
35
36 typedef struct DBusConnection DBusConnection;
37 typedef struct DBusWatch DBusWatch;
38 typedef struct DBusTimeout DBusTimeout;
39 typedef struct DBusMessageHandler DBusMessageHandler;
40 typedef struct DBusPreallocatedSend DBusPreallocatedSend;
41
42 typedef enum
43 {
44   DBUS_HANDLER_RESULT_REMOVE_MESSAGE,     /**< Remove this message, no further processing. */
45   DBUS_HANDLER_RESULT_ALLOW_MORE_HANDLERS /**< Run any additional handlers that are interested in this message. */
46 } DBusHandlerResult;
47
48 typedef enum
49 {
50   DBUS_WATCH_READABLE = 1 << 0, /**< As in POLLIN */
51   DBUS_WATCH_WRITABLE = 1 << 1, /**< As in POLLOUT */
52   DBUS_WATCH_ERROR    = 1 << 2, /**< As in POLLERR (can't watch for this, but
53                                  *   the flag can be passed to dbus_connection_handle_watch()).
54                                  */
55   DBUS_WATCH_HANGUP   = 1 << 3  /**< As in POLLHUP (can't watch for it, but
56                                  *   can be present in current state). */
57 } DBusWatchFlags;
58
59 typedef enum
60 {
61   DBUS_DISPATCH_DATA_REMAINS,  /**< There is more data to potentially convert to messages. */
62   DBUS_DISPATCH_COMPLETE,      /**< All currently available data has been processed. */
63   DBUS_DISPATCH_NEED_MEMORY    /**< More memory is needed to continue. */
64 } DBusDispatchStatus;
65
66 typedef dbus_bool_t (* DBusAddWatchFunction)       (DBusWatch      *watch,
67                                                     void           *data);
68 typedef void        (* DBusWatchToggledFunction)   (DBusWatch      *watch,
69                                                     void           *data);
70 typedef void        (* DBusRemoveWatchFunction)    (DBusWatch      *watch,
71                                                     void           *data);
72 typedef dbus_bool_t (* DBusAddTimeoutFunction)     (DBusTimeout    *timeout,
73                                                     void           *data);
74 typedef void        (* DBusTimeoutToggledFunction) (DBusTimeout    *timeout,
75                                                     void           *data);
76 typedef void        (* DBusRemoveTimeoutFunction)  (DBusTimeout    *timeout,
77                                                     void           *data);
78 typedef void        (* DBusWakeupMainFunction)     (void           *data);
79 typedef dbus_bool_t (* DBusAllowUnixUserFunction)  (DBusConnection *connection,
80                                                     unsigned long   uid,
81                                                     void           *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_int32_t               *client_serial);
102 dbus_bool_t        dbus_connection_send_with_reply           (DBusConnection             *connection,
103                                                               DBusMessage                *message,
104                                                               DBusMessageHandler         *reply_handler,
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 dbus_bool_t        dbus_connection_handle_watch              (DBusConnection             *connection,
127                                                               DBusWatch                  *watch,
128                                                               unsigned int                condition);
129 dbus_bool_t        dbus_connection_get_unix_user             (DBusConnection             *connection,
130                                                               unsigned long              *uid);
131 void               dbus_connection_set_unix_user_function    (DBusConnection             *connection,
132                                                               DBusAllowUnixUserFunction   function,
133                                                               void                       *data,
134                                                               DBusFreeFunction            free_data_function);
135
136 int          dbus_watch_get_fd      (DBusWatch        *watch);
137 unsigned int dbus_watch_get_flags   (DBusWatch        *watch);
138 void*        dbus_watch_get_data    (DBusWatch        *watch);
139 void         dbus_watch_set_data    (DBusWatch        *watch,
140                                      void             *data,
141                                      DBusFreeFunction  free_data_function);
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 dbus_bool_t dbus_connection_register_handler   (DBusConnection      *connection,
159                                                 DBusMessageHandler  *handler,
160                                                 const char         **messages_to_handle,
161                                                 int                  n_messages);
162 void        dbus_connection_unregister_handler (DBusConnection      *connection,
163                                                 DBusMessageHandler  *handler,
164                                                 const char         **messages_to_handle,
165                                                 int                  n_messages);
166
167
168 int         dbus_connection_allocate_data_slot (void);
169 void        dbus_connection_free_data_slot     (int               slot);
170 dbus_bool_t dbus_connection_set_data           (DBusConnection   *connection,
171                                                 int               slot,
172                                                 void             *data,
173                                                 DBusFreeFunction  free_data_func);
174 void*       dbus_connection_get_data           (DBusConnection   *connection,
175                                                 int               slot);
176
177 void        dbus_connection_set_change_sigpipe (dbus_bool_t       will_modify_sigpipe); 
178
179 void dbus_connection_set_max_message_size       (DBusConnection *connection,
180                                                  long            size);
181 long dbus_connection_get_max_message_size       (DBusConnection *connection);
182 void dbus_connection_set_max_live_messages_size (DBusConnection *connection,
183                                                  long            size);
184 long dbus_connection_get_max_live_messages_size (DBusConnection *connection);
185
186 DBusPreallocatedSend* dbus_connection_preallocate_send       (DBusConnection       *connection);
187 void                  dbus_connection_free_preallocated_send (DBusConnection       *connection,
188                                                               DBusPreallocatedSend *preallocated);
189 void                  dbus_connection_send_preallocated      (DBusConnection       *connection,
190                                                               DBusPreallocatedSend *preallocated,
191                                                               DBusMessage          *message,
192                                                               dbus_int32_t         *client_serial);
193
194
195 DBUS_END_DECLS;
196
197 #endif /* DBUS_CONNECTION_H */