2006-10-19 Havoc Pennington <hp@redhat.com>
[platform/upstream/dbus.git] / dbus / dbus-pending-call.c
1 /* -*- mode: C; c-file-style: "gnu" -*- */
2 /* dbus-pending-call.c Object representing a call in progress.
3  *
4  * Copyright (C) 2002, 2003 Red Hat Inc.
5  *
6  * Licensed under the Academic Free License version 2.1
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
24 #include "dbus-internals.h"
25 #include "dbus-connection-internal.h"
26 #include "dbus-pending-call-internal.h"
27 #include "dbus-pending-call.h"
28 #include "dbus-list.h"
29 #include "dbus-threads.h"
30 #include "dbus-test.h"
31
32 /**
33  * @defgroup DBusPendingCallInternals DBusPendingCall implementation details
34  * @ingroup DBusInternals
35  * @brief DBusPendingCall private implementation details.
36  *
37  * The guts of DBusPendingCall and its methods.
38  *
39  * @{
40  */
41
42 /**
43  * @brief Internals of DBusPendingCall
44  *
45  * Opaque object representing a reply message that we're waiting for.
46  */
47
48 /**
49  * shorter and more visible way to write _dbus_connection_lock()
50  */
51 #define CONNECTION_LOCK(connection)   _dbus_connection_lock(connection)
52 /**
53  * shorter and more visible way to write _dbus_connection_unlock()
54  */
55 #define CONNECTION_UNLOCK(connection) _dbus_connection_unlock(connection)
56
57 /**
58  * Implementation details of #DBusPendingCall - all fields are private.
59  */
60 struct DBusPendingCall
61 {
62   DBusAtomic refcount;                            /**< reference count */
63
64   DBusDataSlotList slot_list;                     /**< Data stored by allocated integer ID */
65   
66   DBusPendingCallNotifyFunction function;         /**< Notifier when reply arrives. */
67
68   DBusConnection *connection;                     /**< Connections we're associated with */
69   DBusMessage *reply;                             /**< Reply (after we've received it) */
70   DBusTimeout *timeout;                           /**< Timeout */
71
72   DBusList *timeout_link;                         /**< Preallocated timeout response */
73   
74   dbus_uint32_t reply_serial;                     /**< Expected serial of reply */
75
76   unsigned int completed : 1;                     /**< TRUE if completed */
77   unsigned int timeout_added : 1;                 /**< Have added the timeout */
78 };
79
80 static dbus_int32_t notify_user_data_slot = -1;
81
82 /**
83  * Creates a new pending reply object.
84  *
85  * @param connection connection where reply will arrive
86  * @param timeout_milliseconds length of timeout, -1 for default
87  * @param timeout_handler timeout handler, takes pending call as data
88  * @returns a new #DBusPendingCall or #NULL if no memory.
89  */
90 DBusPendingCall*
91 _dbus_pending_call_new_unlocked (DBusConnection    *connection,
92                                  int                timeout_milliseconds,
93                                  DBusTimeoutHandler timeout_handler)
94 {
95   DBusPendingCall *pending;
96   DBusTimeout *timeout;
97
98   _dbus_assert (timeout_milliseconds >= 0 || timeout_milliseconds == -1);
99  
100   if (timeout_milliseconds == -1)
101     timeout_milliseconds = _DBUS_DEFAULT_TIMEOUT_VALUE;
102
103   /* it would probably seem logical to pass in _DBUS_INT_MAX for
104    * infinite timeout, but then math in
105    * _dbus_connection_block_for_reply would get all overflow-prone, so
106    * smack that down.
107    */
108   if (timeout_milliseconds > _DBUS_ONE_HOUR_IN_MILLISECONDS * 6)
109     timeout_milliseconds = _DBUS_ONE_HOUR_IN_MILLISECONDS * 6;
110   
111   if (!dbus_pending_call_allocate_data_slot (&notify_user_data_slot))
112     return NULL;
113   
114   pending = dbus_new0 (DBusPendingCall, 1);
115   
116   if (pending == NULL)
117     {
118       dbus_pending_call_free_data_slot (&notify_user_data_slot);
119       return NULL;
120     }
121
122   timeout = _dbus_timeout_new (timeout_milliseconds,
123                                timeout_handler,
124                                pending, NULL);  
125
126   if (timeout == NULL)
127     {
128       dbus_pending_call_free_data_slot (&notify_user_data_slot);
129       dbus_free (pending);
130       return NULL;
131     }
132   
133   pending->refcount.value = 1;
134   pending->connection = connection;
135   _dbus_connection_ref_unlocked (pending->connection);
136
137   pending->timeout = timeout;
138
139
140   _dbus_data_slot_list_init (&pending->slot_list);
141   
142   return pending;
143 }
144
145 /**
146  * Sets the reply of a pending call with the given message,
147  * or if the message is #NULL, by timing out the pending call.
148  * 
149  * @param pending the pending call
150  * @param message the message to complete the call with, or #NULL
151  *  to time out the call
152  */
153 void
154 _dbus_pending_call_set_reply_unlocked (DBusPendingCall *pending,
155                                        DBusMessage     *message)
156 {
157   if (message == NULL)
158     {
159       message = pending->timeout_link->data;
160       _dbus_list_clear (&pending->timeout_link);
161     }
162   else
163     dbus_message_ref (message);
164
165   _dbus_verbose ("  handing message %p (%s) to pending call serial %u\n",
166                  message,
167                  dbus_message_get_type (message) == DBUS_MESSAGE_TYPE_METHOD_RETURN ?
168                  "method return" :
169                  dbus_message_get_type (message) == DBUS_MESSAGE_TYPE_ERROR ?
170                  "error" : "other type",
171                  pending->reply_serial);
172   
173   _dbus_assert (pending->reply == NULL);
174   _dbus_assert (pending->reply_serial == dbus_message_get_reply_serial (message));
175   pending->reply = message;
176 }
177
178 /**
179  * Calls notifier function for the pending call
180  * and sets the call to completed.
181  *
182  * @param pending the pending call
183  * 
184  */
185 void
186 _dbus_pending_call_complete (DBusPendingCall *pending)
187 {
188   _dbus_assert (!pending->completed);
189   
190   pending->completed = TRUE;
191
192   if (pending->function)
193     {
194       void *user_data;
195       user_data = dbus_pending_call_get_data (pending,
196                                               notify_user_data_slot);
197       
198       (* pending->function) (pending, user_data);
199     }
200 }
201
202 /**
203  * If the pending call hasn't been timed out, add its timeout
204  * error reply to the connection's incoming message queue.
205  *
206  * @param pending the pending call
207  * @param connection the connection the call was sent to
208  */
209 void
210 _dbus_pending_call_queue_timeout_error_unlocked (DBusPendingCall *pending, 
211                                                  DBusConnection  *connection)
212 {
213   _dbus_assert (connection == pending->connection);
214   
215   if (pending->timeout_link)
216     {
217       _dbus_connection_queue_synthesized_message_link (connection,
218                                                        pending->timeout_link);
219       pending->timeout_link = NULL;
220     }
221 }
222
223 /**
224  * Checks to see if a timeout has been added
225  *
226  * @param pending the pending_call
227  * @returns #TRUE if there is a timeout or #FALSE if not
228  */
229 dbus_bool_t 
230 _dbus_pending_call_is_timeout_added_unlocked (DBusPendingCall  *pending)
231 {
232   _dbus_assert (pending != NULL);
233
234   return pending->timeout_added;
235 }
236
237
238 /**
239  * Sets wether the timeout has been added
240  *
241  * @param pending the pending_call
242  * @param is_added whether or not a timeout is added
243  */
244 void
245 _dbus_pending_call_set_timeout_added_unlocked (DBusPendingCall  *pending,
246                                                dbus_bool_t       is_added)
247 {
248   _dbus_assert (pending != NULL);
249
250   pending->timeout_added = is_added;
251 }
252
253
254 /**
255  * Retrives the timeout
256  *
257  * @param pending the pending_call
258  * @returns a timeout object 
259  */
260 DBusTimeout *
261 _dbus_pending_call_get_timeout_unlocked (DBusPendingCall  *pending)
262 {
263   _dbus_assert (pending != NULL);
264
265   return pending->timeout;
266 }
267
268 /**
269  * Gets the reply's serial number
270  *
271  * @param pending the pending_call
272  * @returns a serial number for the reply or 0 
273  */
274 dbus_uint32_t 
275 _dbus_pending_call_get_reply_serial_unlocked (DBusPendingCall  *pending)
276 {
277   _dbus_assert (pending != NULL);
278
279   return pending->reply_serial;
280 }
281
282 /**
283  * Sets the reply's serial number
284  *
285  * @param pending the pending_call
286  * @param serial the serial number 
287  */
288 void
289 _dbus_pending_call_set_reply_serial_unlocked  (DBusPendingCall *pending,
290                                                dbus_uint32_t serial)
291 {
292   _dbus_assert (pending != NULL);
293   _dbus_assert (pending->reply_serial == 0);
294
295   pending->reply_serial = serial;
296 }
297
298 /**
299  * Gets the connection associated with this pending call.
300  *
301  * @param pending the pending_call
302  * @returns the connection associated with the pending call
303  */
304 DBusConnection *
305 _dbus_pending_call_get_connection_and_lock (DBusPendingCall *pending)
306 {
307   _dbus_assert (pending != NULL);
308  
309   CONNECTION_LOCK (pending->connection);
310   return pending->connection;
311 }
312
313 /**
314  * Gets the connection associated with this pending call.
315  *
316  * @param pending the pending_call
317  * @returns the connection associated with the pending call
318  */
319 DBusConnection *
320 _dbus_pending_call_get_connection_unlocked (DBusPendingCall *pending)
321 {
322   _dbus_assert (pending != NULL);
323  
324   return pending->connection;
325 }
326
327 /**
328  * Sets the reply message associated with the pending call to a timeout error
329  *
330  * @param pending the pending_call
331  * @param message the message we are sending the error reply to 
332  * @param serial serial number for the reply
333  * @return #FALSE on OOM
334  */
335 dbus_bool_t
336 _dbus_pending_call_set_timeout_error_unlocked (DBusPendingCall *pending,
337                                                DBusMessage     *message,
338                                                dbus_uint32_t    serial)
339
340   DBusList *reply_link;
341   DBusMessage *reply;
342
343   reply = dbus_message_new_error (message, DBUS_ERROR_NO_REPLY,
344                                   "Did not receive a reply. Possible causes include: "
345                                   "the remote application did not send a reply, "
346                                   "the message bus security policy blocked the reply, "
347                                   "the reply timeout expired, or "
348                                   "the network connection was broken.");
349   if (reply == NULL)
350     return FALSE;
351
352   reply_link = _dbus_list_alloc_link (reply);
353   if (reply_link == NULL)
354     {
355       dbus_message_unref (reply);
356       return FALSE;
357     }
358
359   pending->timeout_link = reply_link;
360
361   _dbus_pending_call_set_reply_serial_unlocked (pending, serial);
362   
363   return TRUE;
364 }
365
366 /** @} */
367
368 /**
369  * @defgroup DBusPendingCall DBusPendingCall
370  * @ingroup  DBus
371  * @brief Pending reply to a method call message
372  *
373  * A DBusPendingCall is an object representing an
374  * expected reply. A #DBusPendingCall can be created
375  * when you send a message that should have a reply.
376  *
377  * @{
378  */
379
380 /**
381  * @typedef DBusPendingCall
382  *
383  * Opaque data type representing a message pending.
384  */
385
386 /**
387  * Increments the reference count on a pending call,
388  * while the lock on its connection is already held.
389  *
390  * @param pending the pending call object
391  * @returns the pending call object
392  */
393 DBusPendingCall *
394 _dbus_pending_call_ref_unlocked (DBusPendingCall *pending)
395 {
396   pending->refcount.value += 1;
397   
398   return pending;
399 }
400
401 /**
402  * Increments the reference count on a pending call.
403  *
404  * @param pending the pending call object
405  * @returns the pending call object
406  */
407 DBusPendingCall *
408 dbus_pending_call_ref (DBusPendingCall *pending)
409 {
410   _dbus_return_val_if_fail (pending != NULL, NULL);
411
412   /* The connection lock is better than the global
413    * lock in the atomic increment fallback
414    */
415 #ifdef DBUS_HAVE_ATOMIC_INT
416   _dbus_atomic_inc (&pending->refcount);
417 #else
418   CONNECTION_LOCK (pending->connection);
419   _dbus_assert (pending->refcount.value > 0);
420
421   pending->refcount.value += 1;
422   CONNECTION_UNLOCK (pending->connection);
423 #endif
424   
425   return pending;
426 }
427
428 static void
429 _dbus_pending_call_last_unref (DBusPendingCall *pending)
430 {
431   DBusConnection *connection;
432   
433   /* If we get here, we should be already detached
434    * from the connection, or never attached.
435    */
436   _dbus_assert (!pending->timeout_added);  
437
438   connection = pending->connection;
439
440   /* this assumes we aren't holding connection lock... */
441   _dbus_data_slot_list_free (&pending->slot_list);
442
443   if (pending->timeout != NULL)
444     _dbus_timeout_unref (pending->timeout);
445       
446   if (pending->timeout_link)
447     {
448       dbus_message_unref ((DBusMessage *)pending->timeout_link->data);
449       _dbus_list_free_link (pending->timeout_link);
450       pending->timeout_link = NULL;
451     }
452
453   if (pending->reply)
454     {
455       dbus_message_unref (pending->reply);
456       pending->reply = NULL;
457     }
458       
459   dbus_free (pending);
460
461   dbus_pending_call_free_data_slot (&notify_user_data_slot);
462
463   /* connection lock should not be held. */
464   /* Free the connection last to avoid a weird state while
465    * calling out to application code where the pending exists
466    * but not the connection.
467    */
468   dbus_connection_unref (connection);
469 }
470
471 /**
472  * Decrements the reference count on a pending call,
473  * freeing it if the count reaches 0. Assumes
474  * connection lock is already held.
475  *
476  * @param pending the pending call object
477  */
478 void
479 _dbus_pending_call_unref_and_unlock (DBusPendingCall *pending)
480 {
481   dbus_bool_t last_unref;
482   
483   _dbus_assert (pending->refcount.value > 0);
484
485   pending->refcount.value -= 1;
486   last_unref = pending->refcount.value == 0;
487
488   CONNECTION_UNLOCK (pending->connection);
489   if (last_unref)
490     _dbus_pending_call_last_unref (pending);
491 }
492
493 /**
494  * Decrements the reference count on a pending call,
495  * freeing it if the count reaches 0.
496  *
497  * @param pending the pending call object
498  */
499 void
500 dbus_pending_call_unref (DBusPendingCall *pending)
501 {
502   dbus_bool_t last_unref;
503
504   _dbus_return_if_fail (pending != NULL);
505
506   /* More efficient to use the connection lock instead of atomic
507    * int fallback if we lack atomic int decrement
508    */
509 #ifdef DBUS_HAVE_ATOMIC_INT
510   last_unref = (_dbus_atomic_dec (&pending->refcount) == 1);
511 #else
512   CONNECTION_LOCK (pending->connection);
513   _dbus_assert (pending->refcount.value > 0);
514   pending->refcount.value -= 1;
515   last_unref = pending->refcount.value == 0;
516   CONNECTION_UNLOCK (pending->connection);
517 #endif
518   
519   if (last_unref)
520     _dbus_pending_call_last_unref(pending);
521 }
522
523 /**
524  * Sets a notification function to be called when the reply is
525  * received or the pending call times out.
526  *
527  * @param pending the pending call
528  * @param function notifier function
529  * @param user_data data to pass to notifier function
530  * @param free_user_data function to free the user data
531  * @returns #FALSE if not enough memory
532  */
533 dbus_bool_t
534 dbus_pending_call_set_notify (DBusPendingCall              *pending,
535                               DBusPendingCallNotifyFunction function,
536                               void                         *user_data,
537                               DBusFreeFunction              free_user_data)
538 {
539   _dbus_return_val_if_fail (pending != NULL, FALSE);
540
541   CONNECTION_LOCK (pending->connection);
542   
543   /* could invoke application code! */
544   if (!_dbus_pending_call_set_data_unlocked (pending, notify_user_data_slot,
545                                              user_data, free_user_data))
546     return FALSE;
547   
548   pending->function = function;
549
550   CONNECTION_UNLOCK (pending->connection);
551   
552   return TRUE;
553 }
554
555 /**
556  * Cancels the pending call, such that any reply or error received
557  * will just be ignored.  Drops the dbus library's internal reference
558  * to the #DBusPendingCall so will free the call if nobody else is
559  * holding a reference. However you usually get a reference
560  * from dbus_connection_send() so probably your app owns a ref also.
561  * 
562  * @param pending the pending call
563  */
564 void
565 dbus_pending_call_cancel (DBusPendingCall *pending)
566 {
567   _dbus_return_if_fail (pending != NULL);
568
569   _dbus_connection_remove_pending_call (pending->connection,
570                                         pending);
571 }
572
573 /**
574  * Checks whether the pending call has received a reply
575  * yet, or not. Assumes connection lock is held.
576  *
577  * @param pending the pending call
578  * @returns #TRUE if a reply has been received
579  */
580 dbus_bool_t
581 _dbus_pending_call_get_completed_unlocked (DBusPendingCall    *pending)
582 {
583   return pending->completed;
584 }
585
586 /**
587  * Checks whether the pending call has received a reply
588  * yet, or not.
589  *
590  * @param pending the pending call
591  * @returns #TRUE if a reply has been received
592  */
593 dbus_bool_t
594 dbus_pending_call_get_completed (DBusPendingCall *pending)
595 {
596   dbus_bool_t completed;
597   
598   _dbus_return_val_if_fail (pending != NULL, FALSE);
599
600   CONNECTION_LOCK (pending->connection);
601   completed = pending->completed;
602   CONNECTION_UNLOCK (pending->connection);
603
604   return completed;
605 }
606
607 /**
608  * Gets the reply, or returns #NULL if none has been received
609  * yet. Ownership of the reply message passes to the caller. This
610  * function can only be called once per pending call, since the reply
611  * message is tranferred to the caller.
612  * 
613  * @param pending the pending call
614  * @returns the reply message or #NULL.
615  */
616 DBusMessage*
617 dbus_pending_call_steal_reply (DBusPendingCall *pending)
618 {
619   DBusMessage *message;
620   
621   _dbus_return_val_if_fail (pending != NULL, NULL);
622   _dbus_return_val_if_fail (pending->completed, NULL);
623   _dbus_return_val_if_fail (pending->reply != NULL, NULL);
624
625   CONNECTION_LOCK (pending->connection);
626   
627   message = pending->reply;
628   pending->reply = NULL;
629
630   CONNECTION_UNLOCK (pending->connection);
631   
632   return message;
633 }
634
635 /**
636  * Block until the pending call is completed.  The blocking is as with
637  * dbus_connection_send_with_reply_and_block(); it does not enter the
638  * main loop or process other messages, it simply waits for the reply
639  * in question.
640  *
641  * If the pending call is already completed, this function returns
642  * immediately.
643  *
644  * @todo when you start blocking, the timeout is reset, but it should
645  * really only use time remaining since the pending call was created.
646  * This requires storing timestamps instead of intervals in the timeout
647  *
648  * @param pending the pending call
649  */
650 void
651 dbus_pending_call_block (DBusPendingCall *pending)
652 {
653   _dbus_return_if_fail (pending != NULL);
654
655   _dbus_connection_block_pending_call (pending);
656 }
657
658 static DBusDataSlotAllocator slot_allocator;
659 _DBUS_DEFINE_GLOBAL_LOCK (pending_call_slots);
660
661 /**
662  * Allocates an integer ID to be used for storing application-specific
663  * data on any DBusPendingCall. The allocated ID may then be used
664  * with dbus_pending_call_set_data() and dbus_pending_call_get_data().
665  * The passed-in slot must be initialized to -1, and is filled in
666  * with the slot ID. If the passed-in slot is not -1, it's assumed
667  * to be already allocated, and its refcount is incremented.
668  * 
669  * The allocated slot is global, i.e. all DBusPendingCall objects will
670  * have a slot with the given integer ID reserved.
671  *
672  * @param slot_p address of a global variable storing the slot
673  * @returns #FALSE on failure (no memory)
674  */
675 dbus_bool_t
676 dbus_pending_call_allocate_data_slot (dbus_int32_t *slot_p)
677 {
678   _dbus_return_val_if_fail (slot_p != NULL, FALSE);
679
680   return _dbus_data_slot_allocator_alloc (&slot_allocator,
681                                           &_DBUS_LOCK_NAME (pending_call_slots),
682                                           slot_p);
683 }
684
685 /**
686  * Deallocates a global ID for #DBusPendingCall data slots.
687  * dbus_pending_call_get_data() and dbus_pending_call_set_data() may
688  * no longer be used with this slot.  Existing data stored on existing
689  * DBusPendingCall objects will be freed when the #DBusPendingCall is
690  * finalized, but may not be retrieved (and may only be replaced if
691  * someone else reallocates the slot).  When the refcount on the
692  * passed-in slot reaches 0, it is set to -1.
693  *
694  * @param slot_p address storing the slot to deallocate
695  */
696 void
697 dbus_pending_call_free_data_slot (dbus_int32_t *slot_p)
698 {
699   _dbus_return_if_fail (slot_p != NULL);
700   _dbus_return_if_fail (*slot_p >= 0);
701
702   _dbus_data_slot_allocator_free (&slot_allocator, slot_p);
703 }
704
705 /**
706  * Stores a pointer on a #DBusPendingCall, along
707  * with an optional function to be used for freeing
708  * the data when the data is set again, or when
709  * the pending call is finalized. The slot number
710  * must have been allocated with dbus_pending_call_allocate_data_slot().
711  *
712  * @param pending the pending_call
713  * @param slot the slot number
714  * @param data the data to store
715  * @param free_data_func finalizer function for the data
716  * @returns #TRUE if there was enough memory to store the data
717  */
718 dbus_bool_t
719 _dbus_pending_call_set_data_unlocked (DBusPendingCall  *pending,
720                                      dbus_int32_t      slot,
721                                      void             *data,
722                                      DBusFreeFunction  free_data_func)
723 {
724   DBusFreeFunction old_free_func;
725   void *old_data;
726   dbus_bool_t retval;
727
728   retval = _dbus_data_slot_list_set (&slot_allocator,
729                                      &pending->slot_list,
730                                      slot, data, free_data_func,
731                                      &old_free_func, &old_data);
732
733   /* Drop locks to call out to app code */
734   CONNECTION_UNLOCK (pending->connection);
735   
736   if (retval)
737     {
738       if (old_free_func)
739         (* old_free_func) (old_data);
740     }
741
742   CONNECTION_LOCK (pending->connection);
743   
744   return retval;
745 }
746
747 /**
748  * Stores a pointer on a #DBusPendingCall, along
749  * with an optional function to be used for freeing
750  * the data when the data is set again, or when
751  * the pending call is finalized. The slot number
752  * must have been allocated with dbus_pending_call_allocate_data_slot().
753  *
754  * @param pending the pending_call
755  * @param slot the slot number
756  * @param data the data to store
757  * @param free_data_func finalizer function for the data
758  * @returns #TRUE if there was enough memory to store the data
759  */
760 dbus_bool_t
761 dbus_pending_call_set_data (DBusPendingCall  *pending,
762                             dbus_int32_t      slot,
763                             void             *data,
764                             DBusFreeFunction  free_data_func)
765 {
766   dbus_bool_t retval;
767   
768   _dbus_return_val_if_fail (pending != NULL, FALSE);
769   _dbus_return_val_if_fail (slot >= 0, FALSE);
770
771   
772   CONNECTION_LOCK (pending->connection);
773   retval = _dbus_pending_call_set_data_unlocked (pending, slot, data, free_data_func);
774   CONNECTION_UNLOCK (pending->connection);
775   return retval;
776 }
777
778 /**
779  * Retrieves data previously set with dbus_pending_call_set_data().
780  * The slot must still be allocated (must not have been freed).
781  *
782  * @param pending the pending_call
783  * @param slot the slot to get data from
784  * @returns the data, or #NULL if not found
785  */
786 void*
787 dbus_pending_call_get_data (DBusPendingCall   *pending,
788                             dbus_int32_t       slot)
789 {
790   void *res;
791
792   _dbus_return_val_if_fail (pending != NULL, NULL);
793
794   CONNECTION_LOCK (pending->connection);
795   res = _dbus_data_slot_list_get (&slot_allocator,
796                                   &pending->slot_list,
797                                   slot);
798   CONNECTION_UNLOCK (pending->connection);
799
800   return res;
801 }
802
803 /** @} */
804
805 #ifdef DBUS_BUILD_TESTS
806
807 /**
808  * @ingroup DBusPendingCallInternals
809  * Unit test for DBusPendingCall.
810  *
811  * @returns #TRUE on success.
812  */
813 dbus_bool_t
814 _dbus_pending_call_test (const char *test_data_dir)
815 {  
816
817   return TRUE;
818 }
819 #endif /* DBUS_BUILD_TESTS */