2003-09-15 Havoc Pennington <hp@pobox.com>
[platform/upstream/dbus.git] / dbus / dbus-connection-internal.h
1 /* -*- mode: C; c-file-style: "gnu" -*- */
2 /* dbus-connection-internal.h DBusConnection internal interfaces
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 #ifndef DBUS_CONNECTION_INTERNAL_H
24 #define DBUS_CONNECTION_INTERNAL_H
25
26 #include <dbus/dbus-internals.h>
27 #include <dbus/dbus-connection.h>
28 #include <dbus/dbus-message.h>
29 #include <dbus/dbus-transport.h>
30 #include <dbus/dbus-resources.h>
31 #include <dbus/dbus-list.h>
32 #include <dbus/dbus-timeout.h>
33 #include <dbus/dbus-dataslot.h>
34
35 DBUS_BEGIN_DECLS;
36
37 typedef enum
38 {
39   DBUS_ITERATION_DO_WRITING = 1 << 0, /**< Write messages out. */
40   DBUS_ITERATION_DO_READING = 1 << 1, /**< Read messages in. */
41   DBUS_ITERATION_BLOCK      = 1 << 2  /**< Block if nothing to do. */
42 } DBusIterationFlags;
43
44 /** default timeout value when waiting for a message reply */
45 #define _DBUS_DEFAULT_TIMEOUT_VALUE (15 * 1000)
46
47 void              _dbus_connection_lock                        (DBusConnection     *connection);
48 void              _dbus_connection_unlock                      (DBusConnection     *connection);
49 void              _dbus_connection_ref_unlocked                (DBusConnection     *connection);
50 void              _dbus_connection_unref_unlocked              (DBusConnection     *connection);
51 dbus_bool_t       _dbus_connection_queue_received_message      (DBusConnection     *connection,
52                                                                 DBusMessage        *message);
53 void              _dbus_connection_queue_received_message_link (DBusConnection     *connection,
54                                                                 DBusList           *link);
55 dbus_bool_t       _dbus_connection_have_messages_to_send       (DBusConnection     *connection);
56 DBusMessage*      _dbus_connection_get_message_to_send         (DBusConnection     *connection);
57 void              _dbus_connection_message_sent                (DBusConnection     *connection,
58                                                                 DBusMessage        *message);
59 dbus_bool_t       _dbus_connection_add_watch                   (DBusConnection     *connection,
60                                                                 DBusWatch          *watch);
61 void              _dbus_connection_remove_watch                (DBusConnection     *connection,
62                                                                 DBusWatch          *watch);
63 void              _dbus_connection_toggle_watch                (DBusConnection     *connection,
64                                                                 DBusWatch          *watch,
65                                                                 dbus_bool_t         enabled);
66 dbus_bool_t       _dbus_connection_handle_watch                (DBusWatch          *watch,
67                                                                 unsigned int        condition,
68                                                                 void               *data);
69 dbus_bool_t       _dbus_connection_add_timeout                 (DBusConnection     *connection,
70                                                                 DBusTimeout        *timeout);
71 void              _dbus_connection_remove_timeout              (DBusConnection     *connection,
72                                                                 DBusTimeout        *timeout);
73 void              _dbus_connection_toggle_timeout              (DBusConnection     *connection,
74                                                                 DBusTimeout        *timeout,
75                                                                 dbus_bool_t         enabled);
76 DBusConnection*   _dbus_connection_new_for_transport           (DBusTransport      *transport);
77 void              _dbus_connection_do_iteration                (DBusConnection     *connection,
78                                                                 unsigned int        flags,
79                                                                 int                 timeout_milliseconds);
80 void              _dbus_connection_notify_disconnected         (DBusConnection     *connection);
81
82 DBusPendingCall*  _dbus_pending_call_new                       (DBusConnection     *connection,
83                                                                 int                 timeout_milliseconds,
84                                                                 DBusTimeoutHandler  timeout_handler);
85 void              _dbus_pending_call_notify                    (DBusPendingCall    *pending);
86 void              _dbus_connection_remove_pending_call         (DBusConnection     *connection,
87                                                                 DBusPendingCall    *pending);
88 DBusMessage*      _dbus_connection_block_for_reply             (DBusConnection     *connection,
89                                                                 dbus_uint32_t       client_serial,
90                                                                 int                 timeout_milliseconds);
91 void              _dbus_pending_call_complete_and_unlock       (DBusPendingCall    *pending,
92                                                                 DBusMessage        *message);
93
94
95 /**
96  * @addtogroup DBusPendingCallInternals DBusPendingCall implementation details
97  * @{
98  */
99 /**
100  * @brief Internals of DBusPendingCall
101  *
102  * Object representing a reply message that we're waiting for.
103  */
104 struct DBusPendingCall
105 {
106   DBusAtomic refcount;                            /**< reference count */
107
108   DBusDataSlotList slot_list;                     /**< Data stored by allocated integer ID */
109   
110   DBusPendingCallNotifyFunction function;         /**< Notifier when reply arrives. */
111
112   DBusConnection *connection;                     /**< Connections we're associated with */
113   DBusMessage *reply;                             /**< Reply (after we've received it) */
114   DBusTimeout *timeout;                           /**< Timeout */
115
116   DBusList *timeout_link;                         /**< Preallocated timeout response */
117   
118   dbus_uint32_t reply_serial;                     /**< Expected serial of reply */
119
120   unsigned int completed : 1;                     /**< TRUE if completed */
121   unsigned int timeout_added : 1;                 /**< Have added the timeout */
122 };
123
124 /** @} End of DBusPendingCallInternals */
125
126
127 DBUS_END_DECLS;
128
129 #endif /* DBUS_CONNECTION_INTERNAL_H */