2003-02-15 Alexander Larsson <alexl@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
41 typedef enum
42 {
43   DBUS_HANDLER_RESULT_REMOVE_MESSAGE,     /**< Remove this message, no further processing. */
44   DBUS_HANDLER_RESULT_ALLOW_MORE_HANDLERS /**< Run any additional handlers that are interested in this message. */
45 } DBusHandlerResult;
46
47 typedef enum
48 {
49   DBUS_WATCH_READABLE = 1 << 0, /**< As in POLLIN */
50   DBUS_WATCH_WRITABLE = 1 << 1, /**< As in POLLOUT */
51   DBUS_WATCH_ERROR    = 1 << 2, /**< As in POLLERR (can't watch for this, but
52                                  *   the flag can be passed to dbus_connection_handle_watch()).
53                                  */
54   DBUS_WATCH_HANGUP   = 1 << 3  /**< As in POLLHUP (can't watch for it, but
55                                  *   can be present in current state). */
56 } DBusWatchFlags;
57
58 typedef void (* DBusAddWatchFunction)      (DBusWatch      *watch,
59                                             void           *data);
60
61 typedef void (* DBusRemoveWatchFunction)   (DBusWatch      *watch,
62                                             void           *data);
63
64 typedef void (* DBusAddTimeoutFunction)    (DBusTimeout    *timeout,
65                                             void           *data);
66 typedef void (* DBusRemoveTimeoutFunction) (DBusTimeout    *timeout,
67                                             void           *data);
68
69 DBusConnection* dbus_connection_open                   (const char     *address,
70                                                         DBusResultCode *result);
71 void            dbus_connection_ref                    (DBusConnection *connection);
72 void            dbus_connection_unref                  (DBusConnection *connection);
73 void            dbus_connection_disconnect             (DBusConnection *connection);
74 dbus_bool_t     dbus_connection_get_is_connected       (DBusConnection *connection);
75 dbus_bool_t     dbus_connection_get_is_authenticated   (DBusConnection *connection);
76 void            dbus_connection_flush                  (DBusConnection *connection);
77 int             dbus_connection_get_n_messages         (DBusConnection *connection);
78 DBusMessage*    dbus_connection_borrow_message         (DBusConnection *connection);
79 void            dbus_connection_return_message         (DBusConnection *connection,
80                                                         DBusMessage    *message);
81 void            dbus_connection_steal_borrowed_message (DBusConnection *connection,
82                                                         DBusMessage    *message);
83 DBusMessage*    dbus_connection_pop_message            (DBusConnection *connection);
84 dbus_bool_t     dbus_connection_dispatch_message       (DBusConnection *connection);
85
86
87 dbus_bool_t  dbus_connection_send_message                      (DBusConnection     *connection,
88                                                                 DBusMessage        *message,
89                                                                 dbus_int32_t       *client_serial,
90                                                                 DBusResultCode     *result);
91 dbus_bool_t  dbus_connection_send_message_with_reply           (DBusConnection     *connection,
92                                                                 DBusMessage        *message,
93                                                                 DBusMessageHandler *reply_handler,
94                                                                 int                 timeout_milliseconds,
95                                                                 DBusResultCode     *result);
96 DBusMessage *dbus_connection_send_message_with_reply_and_block (DBusConnection     *connection,
97                                                                 DBusMessage        *message,
98                                                                 int                 timeout_milliseconds,
99                                                                 DBusResultCode     *result);
100
101
102 void dbus_connection_set_watch_functions     (DBusConnection            *connection,
103                                               DBusAddWatchFunction       add_function,
104                                               DBusRemoveWatchFunction    remove_function,
105                                               void                      *data,
106                                               DBusFreeFunction           free_data_function);
107 void dbus_connection_set_timeout_functions   (DBusConnection            *connection,
108                                               DBusAddTimeoutFunction     add_function,
109                                               DBusRemoveTimeoutFunction  remove_function,
110                                               void                      *data,
111                                               DBusFreeFunction           free_data_function);
112 void dbus_connection_handle_watch            (DBusConnection            *connection,
113                                               DBusWatch                 *watch,
114                                               unsigned int               condition);
115
116
117
118 int          dbus_watch_get_fd    (DBusWatch        *watch);
119 unsigned int dbus_watch_get_flags (DBusWatch        *watch);
120 void*        dbus_watch_get_data  (DBusWatch        *watch);
121 void         dbus_watch_set_data  (DBusWatch        *watch,
122                                    void             *data,
123                                    DBusFreeFunction  free_data_function);
124
125 int   dbus_timeout_get_interval (DBusTimeout      *timeout);
126 void* dbus_timeout_get_data     (DBusTimeout      *timeout);
127 void  dbus_timeout_set_data     (DBusTimeout      *timeout,
128                                  void             *data,
129                                  DBusFreeFunction  free_data_function);
130 void  dbus_timeout_handle       (DBusTimeout      *timeout);
131
132
133 /* Handlers */
134 dbus_bool_t dbus_connection_add_filter         (DBusConnection      *connection,
135                                                 DBusMessageHandler  *handler);
136 void        dbus_connection_remove_filter      (DBusConnection      *connection,
137                                                 DBusMessageHandler  *handler);
138
139 dbus_bool_t dbus_connection_register_handler   (DBusConnection      *connection,
140                                                 DBusMessageHandler  *handler,
141                                                 const char         **messages_to_handle,
142                                                 int                  n_messages);
143 void        dbus_connection_unregister_handler (DBusConnection      *connection,
144                                                 DBusMessageHandler  *handler,
145                                                 const char         **messages_to_handle,
146                                                 int                  n_messages);
147
148
149 int         dbus_connection_allocate_data_slot (void);
150 void        dbus_connection_free_data_slot     (int               slot);
151 dbus_bool_t dbus_connection_set_data           (DBusConnection   *connection,
152                                                 int               slot,
153                                                 void             *data,
154                                                 DBusFreeFunction  free_data_func);
155 void*       dbus_connection_get_data           (DBusConnection   *connection,
156                                                 int               slot);
157
158 void dbus_connection_set_max_message_size       (DBusConnection *connection,
159                                                  long            size);
160 long dbus_connection_get_max_message_size       (DBusConnection *connection);
161 void dbus_connection_set_max_live_messages_size (DBusConnection *connection,
162                                                  long            size);
163 long dbus_connection_get_max_live_messages_size (DBusConnection *connection);
164
165
166 DBUS_END_DECLS;
167
168 #endif /* DBUS_CONNECTION_H */