2002-11-24 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-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
39 typedef enum
40 {
41   DBUS_WATCH_READABLE = 1 << 0, /**< As in POLLIN */
42   DBUS_WATCH_WRITABLE = 1 << 1, /**< As in POLLOUT */
43   DBUS_WATCH_ERROR    = 1 << 2, /**< As in POLLERR (can't watch for this, but
44                                  *   the flag can be passed to dbus_connection_handle_watch()).
45                                  */
46   DBUS_WATCH_HANGUP   = 1 << 3  /**< As in POLLHUP (can't watch for it, but
47                                  *   can be present in current state). */
48 } DBusWatchFlags;
49
50 typedef void (* DBusAddWatchFunction)    (DBusWatch      *watch,
51                                           void           *data);
52
53 typedef void (* DBusRemoveWatchFunction) (DBusWatch      *watch,
54                                           void           *data);
55
56 typedef void (* DBusConnectionErrorFunction) (DBusConnection *connection,
57                                               DBusResultCode  error_code,
58                                               void           *data);
59
60 DBusConnection* dbus_connection_open             (const char     *address,
61                                                   DBusResultCode *result);
62 void            dbus_connection_ref              (DBusConnection *connection);
63 void            dbus_connection_unref            (DBusConnection *connection);
64 void            dbus_connection_disconnect       (DBusConnection *connection);
65 dbus_bool_t     dbus_connection_get_is_connected (DBusConnection *connection);
66 dbus_bool_t     dbus_connection_send_message     (DBusConnection *connection,
67                                                   DBusMessage    *message,
68                                                   DBusResultCode *result);
69 void            dbus_connection_flush            (DBusConnection *connection);
70
71 int          dbus_connection_get_n_messages      (DBusConnection *connection);
72 DBusMessage* dbus_connection_peek_message        (DBusConnection *connection);
73 DBusMessage* dbus_connection_pop_message         (DBusConnection *connection);
74
75
76 void dbus_connection_set_error_function  (DBusConnection              *connection,
77                                           DBusConnectionErrorFunction  error_function,
78                                           void                        *data,
79                                           DBusFreeFunction             free_data_function);
80 void dbus_connection_set_watch_functions (DBusConnection              *connection,
81                                           DBusAddWatchFunction         add_function,
82                                           DBusRemoveWatchFunction      remove_function,
83                                           void                        *data,
84                                           DBusFreeFunction             free_data_function);
85 void dbus_connection_handle_watch        (DBusConnection              *connection,
86                                           DBusWatch                   *watch,
87                                           unsigned int                 condition);
88
89
90 int          dbus_watch_get_fd    (DBusWatch        *watch);
91 unsigned int dbus_watch_get_flags (DBusWatch        *watch);
92 void*        dbus_watch_get_data  (DBusWatch        *watch);
93 void         dbus_watch_set_data  (DBusWatch        *watch,
94                                    void             *data,
95                                    DBusFreeFunction  free_data_function);
96
97
98 DBUS_END_DECLS;
99
100 #endif /* DBUS_CONNECTION_H */