index.html
Main Page
|
modules.html
Modules
|
namespaces.html
Namespace List
|
hierarchy.html
Class Hierarchy
|
annotated.html
Data Structures
|
dirs.html
Directories
|
files.html
File List
|
namespacemembers.html
Namespace Members
|
functions.html
Data Fields
|
pages.html
Related Pages
dir_000004.html
dbus
dbus-pending-call.c
00001
/* -*- mode: C; c-file-style: "gnu" -*- */
00002
/* dbus-pending-call.c Object representing a call in progress.
00003
*
00004
* Copyright (C) 2002, 2003 Red Hat Inc.
00005
*
00006
* Licensed under the Academic Free License version 2.1
00007
*
00008
* This program is free software; you can redistribute it and/or modify
00009
* it under the terms of the GNU General Public License as published by
00010
* the Free Software Foundation; either version 2 of the License, or
00011
* (at your option) any later version.
00012
*
00013
* This program is distributed in the hope that it will be useful,
00014
* but WITHOUT ANY WARRANTY; without even the implied warranty of
00015
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016
* GNU General Public License for more details.
00017
*
00018
* You should have received a copy of the GNU General Public License
00019
* along with this program; if not, write to the Free Software
00020
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00021
*
00022
*/
00023
00024
#include "dbus-internals.h"
00025
#include "dbus-connection-internal.h"
00026
#include "dbus-pending-call.h"
00027
#include "dbus-list.h"
00028
#include "dbus-threads.h"
00029
#include "dbus-test.h"
00030
00041
static
group__DBusTypes.html#ga4
dbus_int32_t
notify_user_data_slot = -1;
00042
00051
structDBusPendingCall.html
DBusPendingCall
*
group__DBusPendingCallInternals.html#ga1
00052
group__DBusPendingCallInternals.html#ga1
_dbus_pending_call_new
(
structDBusConnection.html
DBusConnection
*
structDBusObjectTree.html#o1
connection
,
00053
int
timeout_milliseconds,
00054                         DBusTimeoutHandler timeout_handler)
00055 {
00056
structDBusPendingCall.html
DBusPendingCall
*pending;
00057
structDBusTimeout.html
DBusTimeout
*timeout;
00058
00059
group__DBusInternalsUtils.html#ga130
_dbus_assert
(timeout_milliseconds >= 0 || timeout_milliseconds == -1);
00060
00061
if
(timeout_milliseconds == -1)
00062     timeout_milliseconds = _DBUS_DEFAULT_TIMEOUT_VALUE;
00063
00064
/* it would probably seem logical to pass in _DBUS_INT_MAX for
00065
* infinite timeout, but then math in
00066
* _dbus_connection_block_for_reply would get all overflow-prone, so
00067
* smack that down.
00068
*/
00069
if
(timeout_milliseconds > _DBUS_ONE_HOUR_IN_MILLISECONDS * 6)
00070     timeout_milliseconds = _DBUS_ONE_HOUR_IN_MILLISECONDS * 6;
00071
00072
if
(!
group__DBusPendingCall.html#ga8
dbus_pending_call_allocate_data_slot
(&notify_user_data_slot))
00073
return
group__DBusMacros.html#ga4
NULL
;
00074
00075   pending =
group__DBusMemory.html#ga7
dbus_new0
(
structDBusPendingCall.html
DBusPendingCall
, 1);
00076
00077
if
(pending ==
group__DBusMacros.html#ga4
NULL
)
00078     {
00079
group__DBusPendingCall.html#ga9
dbus_pending_call_free_data_slot
(&notify_user_data_slot);
00080
return
group__DBusMacros.html#ga4
NULL
;
00081     }
00082
00083   timeout =
group__DBusTimeoutInternals.html#ga0
_dbus_timeout_new
(timeout_milliseconds,
00084                                timeout_handler,
00085                                pending,
group__DBusMacros.html#ga4
NULL
);
00086
00087
if
(timeout ==
group__DBusMacros.html#ga4
NULL
)
00088     {
00089
group__DBusPendingCall.html#ga9
dbus_pending_call_free_data_slot
(&notify_user_data_slot);
00090
group__DBusMemory.html#ga3
dbus_free
(pending);
00091
return
group__DBusMacros.html#ga4
NULL
;
00092     }
00093
00094   pending->
structDBusPendingCall.html#o0
refcount
.
structDBusAtomic.html#o0
value
= 1;
00095   pending->
structDBusPendingCall.html#o3
connection
= connection;
00096   pending->
structDBusPendingCall.html#o5
timeout
= timeout;
00097
00098
group__DBusDataSlot.html#ga3
_dbus_data_slot_list_init
(&pending->
structDBusPendingCall.html#o1
slot_list
);
00099
00100
return
pending;
00101 }
00102
00110
void
group__DBusPendingCallInternals.html#ga2
00111
group__DBusPendingCallInternals.html#ga2
_dbus_pending_call_notify
(
structDBusPendingCall.html
DBusPendingCall
*pending)
00112 {
00113
group__DBusInternalsUtils.html#ga130
_dbus_assert
(!pending->
structDBusPendingCall.html#o8
completed
);
00114
00115   pending->
structDBusPendingCall.html#o8
completed
=
group__DBusMacros.html#ga2
TRUE
;
00116
00117
if
(pending->
structDBusPendingCall.html#o2
function
)
00118     {
00119
void
*user_data;
00120       user_data =
group__DBusPendingCall.html#ga11
dbus_pending_call_get_data
(pending,
00121                                               notify_user_data_slot);
00122
00123       (* pending->
structDBusPendingCall.html#o2
function
) (pending, user_data);
00124     }
00125 }
00126
00153
structDBusPendingCall.html
DBusPendingCall
*
group__DBusPendingCall.html#ga1
00154
group__DBusPendingCall.html#ga1
dbus_pending_call_ref
(
structDBusPendingCall.html
DBusPendingCall
*pending)
00155 {
00156   _dbus_return_val_if_fail (pending !=
group__DBusMacros.html#ga4
NULL
,
group__DBusMacros.html#ga4
NULL
);
00157
00158
group__DBusInternalsUtils.html#ga80
_dbus_atomic_inc
(&pending->
structDBusPendingCall.html#o0
refcount
);
00159
00160
return
pending;
00161 }
00162
00169
void
group__DBusPendingCall.html#ga2
00170
group__DBusPendingCall.html#ga2
dbus_pending_call_unref
(
structDBusPendingCall.html
DBusPendingCall
*pending)
00171 {
00172
group__DBusTypes.html#ga2
dbus_bool_t
last_unref;
00173
00174   _dbus_return_if_fail (pending !=
group__DBusMacros.html#ga4
NULL
);
00175
00176   last_unref = (
group__DBusInternalsUtils.html#ga81
_dbus_atomic_dec
(&pending->
structDBusPendingCall.html#o0
refcount
) == 1);
00177
00178
if
(last_unref)
00179     {
00180
/* If we get here, we should be already detached
00181
* from the connection, or never attached.
00182
*/
00183
group__DBusInternalsUtils.html#ga130
_dbus_assert
(pending->
structDBusPendingCall.html#o3
connection
==
group__DBusMacros.html#ga4
NULL
);
00184
group__DBusInternalsUtils.html#ga130
_dbus_assert
(!pending->
structDBusPendingCall.html#o9
timeout_added
);
00185
00186
/* this assumes we aren't holding connection lock... */
00187
group__DBusDataSlot.html#ga7
_dbus_data_slot_list_free
(&pending->
structDBusPendingCall.html#o1
slot_list
);
00188
00189
if
(pending->
structDBusPendingCall.html#o5
timeout
!=
group__DBusMacros.html#ga4
NULL
)
00190
group__DBusTimeoutInternals.html#ga2
_dbus_timeout_unref
(pending->
structDBusPendingCall.html#o5
timeout
);
00191
00192
if
(pending->
structDBusPendingCall.html#o6
timeout_link
)
00193         {
00194
group__DBusMessage.html#ga20
dbus_message_unref
((
structDBusMessage.html
DBusMessage
*)pending->
structDBusPendingCall.html#o6
timeout_link
->
structDBusList.html#o2
data
);
00195
group__DBusList.html#ga1
_dbus_list_free_link
(pending->
structDBusPendingCall.html#o6
timeout_link
);
00196           pending->
structDBusPendingCall.html#o6
timeout_link
=
group__DBusMacros.html#ga4
NULL
;
00197         }
00198
00199
if
(pending->
structDBusPendingCall.html#o4
reply
)
00200         {
00201
group__DBusMessage.html#ga20
dbus_message_unref
(pending->
structDBusPendingCall.html#o4
reply
);
00202           pending->
structDBusPendingCall.html#o4
reply
=
group__DBusMacros.html#ga4
NULL
;
00203         }
00204
00205
group__DBusMemory.html#ga3
dbus_free
(pending);
00206
00207
group__DBusPendingCall.html#ga9
dbus_pending_call_free_data_slot
(&notify_user_data_slot);
00208     }
00209 }
00210
00221
group__DBusTypes.html#ga2
dbus_bool_t
group__DBusPendingCall.html#ga3
00222
group__DBusPendingCall.html#ga3
dbus_pending_call_set_notify
(
structDBusPendingCall.html
DBusPendingCall
*pending,
00223                               DBusPendingCallNotifyFunction function,
00224
void
*user_data,
00225
group__DBusMemory.html#ga8
DBusFreeFunction
free_user_data)
00226 {
00227   _dbus_return_val_if_fail (pending !=
group__DBusMacros.html#ga4
NULL
,
group__DBusMacros.html#ga3
FALSE
);
00228
00229
/* could invoke application code! */
00230
if
(!
group__DBusPendingCall.html#ga10
dbus_pending_call_set_data
(pending, notify_user_data_slot,
00231                                    user_data, free_user_data))
00232
return
group__DBusMacros.html#ga3
FALSE
;
00233
00234   pending->function = function;
00235
00236
return
group__DBusMacros.html#ga2
TRUE
;
00237 }
00238
00248
void
group__DBusPendingCall.html#ga4
00249
group__DBusPendingCall.html#ga4
dbus_pending_call_cancel
(
structDBusPendingCall.html
DBusPendingCall
*pending)
00250 {
00251
if
(pending->
structDBusPendingCall.html#o3
connection
)
00252
group__DBusConnectionInternals.html#ga37
_dbus_connection_remove_pending_call
(pending->
structDBusPendingCall.html#o3
connection
,
00253                                           pending);
00254 }
00255
00264
group__DBusTypes.html#ga2
dbus_bool_t
group__DBusPendingCall.html#ga5
00265
group__DBusPendingCall.html#ga5
dbus_pending_call_get_completed
(
structDBusPendingCall.html
DBusPendingCall
*pending)
00266 {
00267
return
pending->
structDBusPendingCall.html#o8
completed
;
00268 }
00269
00279
structDBusMessage.html
DBusMessage
*
group__DBusPendingCall.html#ga6
00280
group__DBusPendingCall.html#ga6
dbus_pending_call_steal_reply
(
structDBusPendingCall.html
DBusPendingCall
*pending)
00281 {
00282
structDBusMessage.html
DBusMessage
*message;
00283
00284   _dbus_return_val_if_fail (pending->
structDBusPendingCall.html#o8
completed
,
group__DBusMacros.html#ga4
NULL
);
00285   _dbus_return_val_if_fail (pending->
structDBusPendingCall.html#o4
reply
!=
group__DBusMacros.html#ga4
NULL
,
group__DBusMacros.html#ga4
NULL
);
00286
00287   message = pending->
structDBusPendingCall.html#o4
reply
;
00288   pending->
structDBusPendingCall.html#o4
reply
=
group__DBusMacros.html#ga4
NULL
;
00289
00290
return
message;
00291 }
00292
00307
void
group__DBusPendingCall.html#ga7
00308
group__DBusPendingCall.html#ga7
dbus_pending_call_block
(
structDBusPendingCall.html
DBusPendingCall
*pending)
00309 {
00310
group__DBusConnection.html#ga25
_dbus_connection_block_pending_call
(pending);
00311 }
00312
00313
static
structDBusDataSlotAllocator.html
DBusDataSlotAllocator
slot_allocator;
00314
group__DBusInternalsUtils.html#ga146
_DBUS_DEFINE_GLOBAL_LOCK
(pending_call_slots);
00315
00330
group__DBusTypes.html#ga2
dbus_bool_t
group__DBusPendingCall.html#ga8
00331
group__DBusPendingCall.html#ga8
dbus_pending_call_allocate_data_slot
(
group__DBusTypes.html#ga4
dbus_int32_t
*slot_p)
00332 {
00333
return
group__DBusDataSlot.html#ga1
_dbus_data_slot_allocator_alloc
(&slot_allocator,
00334
group__DBusInternalsUtils.html#ga145
_DBUS_LOCK_NAME
(pending_call_slots),
00335                                           slot_p);
00336 }
00337
00349
void
group__DBusPendingCall.html#ga9
00350
group__DBusPendingCall.html#ga9
dbus_pending_call_free_data_slot
(
group__DBusTypes.html#ga4
dbus_int32_t
*slot_p)
00351 {
00352   _dbus_return_if_fail (*slot_p >= 0);
00353
00354
group__DBusDataSlot.html#ga2
_dbus_data_slot_allocator_free
(&slot_allocator, slot_p);
00355 }
00356
00370
group__DBusTypes.html#ga2
dbus_bool_t
group__DBusPendingCall.html#ga10
00371
group__DBusPendingCall.html#ga10
dbus_pending_call_set_data
(
structDBusPendingCall.html
DBusPendingCall
*pending,
00372
group__DBusTypes.html#ga4
dbus_int32_t
slot,
00373
void
*data,
00374
group__DBusMemory.html#ga8
DBusFreeFunction
free_data_func)
00375 {
00376
group__DBusMemory.html#ga8
DBusFreeFunction
old_free_func;
00377
void
*old_data;
00378
group__DBusTypes.html#ga2
dbus_bool_t
retval;
00379
00380   _dbus_return_val_if_fail (pending !=
group__DBusMacros.html#ga4
NULL
,
group__DBusMacros.html#ga3
FALSE
);
00381   _dbus_return_val_if_fail (slot >= 0,
group__DBusMacros.html#ga3
FALSE
);
00382
00383   retval =
group__DBusDataSlot.html#ga4
_dbus_data_slot_list_set
(&slot_allocator,
00384                                      &pending->
structDBusPendingCall.html#o1
slot_list
,
00385                                      slot, data, free_data_func,
00386                                      &old_free_func, &old_data);
00387
00388
if
(retval)
00389     {
00390
if
(old_free_func)
00391         (* old_free_func) (old_data);
00392     }
00393
00394
return
retval;
00395 }
00396
00405
void
*
group__DBusPendingCall.html#ga11
00406
group__DBusPendingCall.html#ga11
dbus_pending_call_get_data
(
structDBusPendingCall.html
DBusPendingCall
*pending,
00407
group__DBusTypes.html#ga4
dbus_int32_t
slot)
00408 {
00409
void
*res;
00410
00411   _dbus_return_val_if_fail (pending !=
group__DBusMacros.html#ga4
NULL
,
group__DBusMacros.html#ga4
NULL
);
00412
00413   res =
group__DBusDataSlot.html#ga5
_dbus_data_slot_list_get
(&slot_allocator,
00414                                   &pending->
structDBusPendingCall.html#o1
slot_list
,
00415                                   slot);
00416
00417
return
res;
00418 }
00419
00422
#ifdef DBUS_BUILD_TESTS
00423
00430
group__DBusTypes.html#ga2
dbus_bool_t
00431 _dbus_pending_call_test (
const
char
*test_data_dir)
00432 {
00433
00434
return
group__DBusMacros.html#ga2
TRUE
;
00435 }
00436
#endif
/* DBUS_BUILD_TESTS */
Generated on Tue Sep 13 01:28:07 2005 for D-BUS by
http://www.doxygen.org/index.html
doxygen
1.4.4
