2003-08-15 Havoc Pennington <hp@redhat.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
34 DBUS_BEGIN_DECLS;
35
36 typedef enum
37 {
38   DBUS_ITERATION_DO_WRITING = 1 << 0, /**< Write messages out. */
39   DBUS_ITERATION_DO_READING = 1 << 1, /**< Read messages in. */
40   DBUS_ITERATION_BLOCK      = 1 << 2  /**< Block if nothing to do. */
41 } DBusIterationFlags;
42
43 /** default timeout value when waiting for a message reply */
44 #define _DBUS_DEFAULT_TIMEOUT_VALUE (15 * 1000)
45
46 void              _dbus_connection_lock                        (DBusConnection     *connection);
47 void              _dbus_connection_unlock                      (DBusConnection     *connection);
48 void              _dbus_connection_ref_unlocked                (DBusConnection     *connection);
49 void              _dbus_connection_unref_unlocked              (DBusConnection     *connection);
50 dbus_bool_t       _dbus_connection_queue_received_message      (DBusConnection     *connection,
51                                                                 DBusMessage        *message);
52 void              _dbus_connection_queue_received_message_link (DBusConnection     *connection,
53                                                                 DBusList           *link);
54 dbus_bool_t       _dbus_connection_have_messages_to_send       (DBusConnection     *connection);
55 DBusMessage*      _dbus_connection_get_message_to_send         (DBusConnection     *connection);
56 void              _dbus_connection_message_sent                (DBusConnection     *connection,
57                                                                 DBusMessage        *message);
58 dbus_bool_t       _dbus_connection_add_watch                   (DBusConnection     *connection,
59                                                                 DBusWatch          *watch);
60 void              _dbus_connection_remove_watch                (DBusConnection     *connection,
61                                                                 DBusWatch          *watch);
62 void              _dbus_connection_toggle_watch                (DBusConnection     *connection,
63                                                                 DBusWatch          *watch,
64                                                                 dbus_bool_t         enabled);
65 dbus_bool_t       _dbus_connection_handle_watch                (DBusWatch          *watch,
66                                                                 unsigned int        condition,
67                                                                 void               *data);
68 dbus_bool_t       _dbus_connection_add_timeout                 (DBusConnection     *connection,
69                                                                 DBusTimeout        *timeout);
70 void              _dbus_connection_remove_timeout              (DBusConnection     *connection,
71                                                                 DBusTimeout        *timeout);
72 void              _dbus_connection_toggle_timeout              (DBusConnection     *connection,
73                                                                 DBusTimeout        *timeout,
74                                                                 dbus_bool_t         enabled);
75 DBusConnection*   _dbus_connection_new_for_transport           (DBusTransport      *transport);
76 void              _dbus_connection_do_iteration                (DBusConnection     *connection,
77                                                                 unsigned int        flags,
78                                                                 int                 timeout_milliseconds);
79 void              _dbus_connection_notify_disconnected         (DBusConnection     *connection);
80 void              _dbus_connection_handler_destroyed_locked    (DBusConnection     *connection,
81                                                                 DBusMessageHandler *handler);
82 dbus_bool_t       _dbus_message_handler_add_connection         (DBusMessageHandler *handler,
83                                                                 DBusConnection     *connection);
84 void              _dbus_message_handler_remove_connection      (DBusMessageHandler *handler,
85                                                                 DBusConnection     *connection);
86 DBusHandlerResult _dbus_message_handler_handle_message         (DBusMessageHandler *handler,
87                                                                 DBusConnection     *connection,
88                                                                 DBusMessage        *message);
89 void              _dbus_connection_init_id                     (DBusConnection     *connection,
90                                                                 DBusObjectID       *id);
91 DBusPendingCall*  _dbus_pending_call_new                       (DBusConnection     *connection,
92                                                                 int                 timeout_milliseconds,
93                                                                 DBusTimeoutHandler  timeout_handler);
94 void              _dbus_pending_call_notify                    (DBusPendingCall    *pending);
95 void              _dbus_connection_remove_pending_call         (DBusConnection     *connection,
96                                                                 DBusPendingCall    *pending);
97 DBusMessage*      _dbus_connection_block_for_reply             (DBusConnection     *connection,
98                                                                 dbus_uint32_t       client_serial,
99                                                                 int                 timeout_milliseconds);
100 void              _dbus_pending_call_complete_and_unlock       (DBusPendingCall    *pending,
101                                                                 DBusMessage        *message);
102
103
104 /**
105  * @addtogroup DBusPendingCallInternals DBusPendingCall implementation details
106  * @{
107  */
108 /**
109  * @brief Internals of DBusPendingCall
110  *
111  * Object representing a reply message that we're waiting for.
112  */
113 struct DBusPendingCall
114 {
115   DBusAtomic refcount;                            /**< reference count */
116
117   DBusPendingCallNotifyFunction function;         /**< Notifier when reply arrives. */
118   void                     *user_data;            /**< user data for function */
119   DBusFreeFunction          free_user_data;       /**< free the user data */
120
121   DBusConnection *connection;                     /**< Connections we're associated with */
122   DBusMessage *reply;                             /**< Reply (after we've received it) */
123   DBusTimeout *timeout;                           /**< Timeout */
124
125   DBusList *timeout_link;                         /**< Preallocated timeout response */
126   
127   dbus_uint32_t reply_serial;                     /**< Expected serial of reply */
128
129   unsigned int completed : 1;                     /**< TRUE if completed */
130   unsigned int timeout_added : 1;                 /**< Have added the timeout */
131 };
132
133 /** @} End of DBusPendingCallInternals */
134
135
136 DBUS_END_DECLS;
137
138 #endif /* DBUS_CONNECTION_INTERNAL_H */