25 #include "dbus-internals.h" 
   26 #include "dbus-connection-internal.h" 
   27 #include "dbus-message-internal.h" 
   28 #include "dbus-pending-call-internal.h" 
   29 #include "dbus-pending-call.h" 
   30 #include "dbus-list.h" 
   31 #include "dbus-threads.h" 
   32 #include "dbus-test.h" 
   53 #define CONNECTION_LOCK(connection)   _dbus_connection_lock(connection) 
   57 #define CONNECTION_UNLOCK(connection) _dbus_connection_unlock(connection) 
   96 #ifdef DBUS_ENABLE_VERBOSE_MODE 
   97   static int enabled = -1;
 
   99   _dbus_trace_ref (
"DBusPendingCall", pending_call, old_refcount,
 
  100       new_refcount, why, 
"DBUS_PENDING_CALL_TRACE", &enabled);
 
  118                                  int                timeout_milliseconds,
 
  124   _dbus_assert (timeout_milliseconds >= 0 || timeout_milliseconds == -1);
 
  126   if (timeout_milliseconds == -1)
 
  127     timeout_milliseconds = _DBUS_DEFAULT_TIMEOUT_VALUE;
 
  166   _dbus_pending_call_trace_ref (pending, 0, 1, 
"new_unlocked");
 
  191   _dbus_verbose (
"  handing message %p (%s) to pending call serial %u\n",
 
  196                  "error" : 
"other type",
 
  201   pending->
reply = message;
 
  240                                               notify_user_data_slot);
 
  242       (* pending->
function) (pending, user_data);
 
  388                                   "Did not receive a reply. Possible causes include: " 
  389                                   "the remote application did not send a reply, " 
  390                                   "the message bus security policy blocked the reply, " 
  391                                   "the reply timeout expired, or " 
  392                                   "the network connection was broken.");
 
  397   if (reply_link == 
NULL)
 
  425   _dbus_pending_call_trace_ref (pending, old_refcount, old_refcount + 1,
 
  489   _dbus_pending_call_trace_ref (pending, old_refcount,
 
  490       old_refcount - 1, 
"unref_and_unlock");
 
  494   if (old_refcount == 1)
 
  495     _dbus_pending_call_last_unref (pending);
 
  539                                      slot, data, free_data_func,
 
  540                                      &old_free_func, &old_data);
 
  548         (* old_free_func) (old_data);
 
  607   _dbus_return_val_if_fail (pending != 
NULL, 
NULL);
 
  610   _dbus_pending_call_trace_ref (pending, old_refcount, old_refcount + 1,
 
  627   _dbus_return_if_fail (pending != 
NULL);
 
  630   _dbus_pending_call_trace_ref (pending, old_refcount, old_refcount - 1,
 
  633   if (old_refcount == 1)
 
  634     _dbus_pending_call_last_unref(pending);
 
  655   _dbus_return_val_if_fail (pending != 
NULL, 
FALSE);
 
  661                                              user_data, free_user_data))
 
  691   _dbus_return_if_fail (pending != 
NULL);
 
  709   _dbus_return_val_if_fail (pending != 
NULL, 
FALSE);
 
  732   _dbus_return_val_if_fail (pending != 
NULL, 
NULL);
 
  738   message = pending->
reply;
 
  743   _dbus_message_trace_ref (message, -1, -1, 
"dbus_pending_call_steal_reply");
 
  765   _dbus_return_if_fail (pending != 
NULL);
 
  787   _dbus_return_val_if_fail (slot_p != 
NULL, 
FALSE);
 
  807   _dbus_return_if_fail (slot_p != 
NULL);
 
  808   _dbus_return_if_fail (*slot_p >= 0);
 
  834   _dbus_return_val_if_fail (pending != 
NULL, 
FALSE);
 
  835   _dbus_return_val_if_fail (slot >= 0, 
FALSE);
 
  858   _dbus_return_val_if_fail (pending != 
NULL, 
NULL);
 
  
DBusTimeout * _dbus_timeout_new(int interval, DBusTimeoutHandler handler, void *data, DBusFreeFunction free_data_function)
Creates a new DBusTimeout, enabled by default.
dbus_int32_t _dbus_atomic_dec(DBusAtomic *atomic)
Atomically decrement an integer.
void * _dbus_data_slot_list_get(DBusDataSlotAllocator *allocator, DBusDataSlotList *list, int slot)
Retrieves data previously set with _dbus_data_slot_list_set_data().
void * dbus_pending_call_get_data(DBusPendingCall *pending, dbus_int32_t slot)
Retrieves data previously set with dbus_pending_call_set_data().
#define CONNECTION_LOCK(connection)
Internals of DBusPendingCall.
void _dbus_connection_queue_synthesized_message_link(DBusConnection *connection, DBusList *link)
Adds a link + message to the incoming message queue.
dbus_uint32_t _dbus_pending_call_get_reply_serial_unlocked(DBusPendingCall *pending)
Gets the reply's serial number.
DBusMessage * dbus_message_ref(DBusMessage *message)
Increments the reference count of a DBusMessage.
dbus_bool_t dbus_pending_call_set_data(DBusPendingCall *pending, dbus_int32_t slot, void *data, DBusFreeFunction free_data_func)
Stores a pointer on a DBusPendingCall, along with an optional function to be used for freeing the dat...
DBusAtomic refcount
reference count
DBusPendingCall * _dbus_pending_call_new_unlocked(DBusConnection *connection, int timeout_milliseconds, DBusTimeoutHandler timeout_handler)
Creates a new pending reply object.
void _dbus_list_clear(DBusList **list)
Frees all links in the list and sets the list head to NULL.
void dbus_message_unref(DBusMessage *message)
Decrements the reference count of a DBusMessage, freeing the message if the count reaches 0.
unsigned int completed
TRUE if some thread has taken responsibility for completing this pending call: either the pending cal...
void(* DBusFreeFunction)(void *memory)
unsigned int timeout_added
TRUE if we have added the timeout.
DBusList * _dbus_list_alloc_link(void *data)
Allocates a linked list node.
void _dbus_pending_call_unref_and_unlock(DBusPendingCall *pending)
Decrements the reference count on a pending call, freeing it if the count reaches 0.
DBusPendingCall * _dbus_pending_call_ref_unlocked(DBusPendingCall *pending)
Increments the reference count on a pending call, while the lock on its connection is already held.
dbus_bool_t _dbus_pending_call_is_timeout_added_unlocked(DBusPendingCall *pending)
Checks to see if a timeout has been added.
void dbus_pending_call_free_data_slot(dbus_int32_t *slot_p)
Deallocates a global ID for DBusPendingCall data slots.
Implementation details of DBusConnection.
dbus_uint32_t reply_serial
Expected serial of reply.
dbus_bool_t dbus_pending_call_set_notify(DBusPendingCall *pending, DBusPendingCallNotifyFunction function, void *user_data, DBusFreeFunction free_user_data)
Sets a notification function to be called when the reply is received or the pending call times out.
void _dbus_connection_block_pending_call(DBusPendingCall *pending)
Blocks until a pending call times out or gets a reply.
DBusPendingCallNotifyFunction function
Notifier when reply arrives.
void dbus_pending_call_unref(DBusPendingCall *pending)
Decrements the reference count on a pending call, freeing it if the count reaches 0.
#define DBUS_TIMEOUT_INFINITE
dbus_bool_t _dbus_data_slot_list_set(DBusDataSlotAllocator *allocator, DBusDataSlotList *list, int slot, void *data, DBusFreeFunction free_data_func, DBusFreeFunction *old_free_func, void **old_data)
Stores a pointer in the data slot list, along with an optional function to be used for freeing the da...
void(* DBusPendingCallNotifyFunction)(DBusPendingCall *pending, void *user_data)
Called when a pending call now has a reply available.
DBusMessage * dbus_pending_call_steal_reply(DBusPendingCall *pending)
Gets the reply, or returns NULL if none has been received yet.
void dbus_pending_call_cancel(DBusPendingCall *pending)
Cancels the pending call, such that any reply or error received will just be ignored.
void dbus_pending_call_block(DBusPendingCall *pending)
Block until the pending call is completed.
dbus_bool_t dbus_pending_call_get_completed(DBusPendingCall *pending)
Checks whether the pending call has received a reply yet, or not.
DBusDataSlotList slot_list
Data stored by allocated integer ID.
void _dbus_pending_call_set_timeout_added_unlocked(DBusPendingCall *pending, dbus_bool_t is_added)
Sets wether the timeout has been added.
void _dbus_pending_call_set_reply_unlocked(DBusPendingCall *pending, DBusMessage *message)
Sets the reply of a pending call with the given message, or if the message is NULL,...
void dbus_free(void *memory)
Frees a block of memory previously allocated by dbus_malloc() or dbus_malloc0().
void _dbus_timeout_unref(DBusTimeout *timeout)
Decrements the reference count of a DBusTimeout object and finalizes the object if the count reaches ...
void _dbus_pending_call_queue_timeout_error_unlocked(DBusPendingCall *pending, DBusConnection *connection)
If the pending call hasn't been timed out, add its timeout error reply to the connection's incoming m...
#define CONNECTION_UNLOCK(connection)
shorter and more visible way to write _dbus_connection_unlock()
#define _DBUS_LOCK_NAME(name)
#define DBUS_ERROR_NO_REPLY
No reply to a message expecting one, usually means a timeout occurred.
DBusMessage * reply
Reply (after we've received it)
dbus_bool_t _dbus_pending_call_set_data_unlocked(DBusPendingCall *pending, dbus_int32_t slot, void *data, DBusFreeFunction free_data_func)
Stores a pointer on a DBusPendingCall, along with an optional function to be used for freeing the dat...
unsigned int dbus_uint32_t
Internals of DBusTimeout.
void _dbus_data_slot_list_init(DBusDataSlotList *list)
Initializes a slot list.
dbus_bool_t _dbus_data_slot_allocator_alloc(DBusDataSlotAllocator *allocator, dbus_int32_t *slot_id_p)
Allocates an integer ID to be used for storing data in a DBusDataSlotList.
DBusConnection * _dbus_pending_call_get_connection_and_lock(DBusPendingCall *pending)
Gets the connection associated with this pending call.
DBusConnection * connection
Connections we're associated with.
void _dbus_data_slot_list_free(DBusDataSlotList *list)
Frees the data slot list and all data slots contained in it, calling application-provided free functi...
dbus_bool_t _dbus_pending_call_set_timeout_error_unlocked(DBusPendingCall *pending, DBusMessage *message, dbus_uint32_t serial)
Sets the reply message associated with the pending call to a timeout error.
Internals of DBusMessage.
void * data
Data stored at this element.
void _dbus_list_free_link(DBusList *link)
Frees a linked list node allocated with _dbus_list_alloc_link.
#define DBUS_MESSAGE_TYPE_ERROR
Message type of an error reply message, see dbus_message_get_type()
#define DBUS_MESSAGE_TYPE_METHOD_RETURN
Message type of a method return message, see dbus_message_get_type()
DBusPendingCall * dbus_pending_call_ref(DBusPendingCall *pending)
Increments the reference count on a pending call.
dbus_uint32_t dbus_message_get_reply_serial(DBusMessage *message)
Returns the serial that the message is a reply to or 0 if none.
An atomic integer safe to increment or decrement from multiple threads.
#define _dbus_assert(condition)
void _dbus_connection_remove_pending_call(DBusConnection *connection, DBusPendingCall *pending)
Removes a pending call from the connection, such that the pending reply will be ignored.
DBusList * timeout_link
Preallocated timeout response.
An allocator that tracks a set of slot IDs.
DBusConnection * _dbus_pending_call_get_connection_unlocked(DBusPendingCall *pending)
Gets the connection associated with this pending call.
void _dbus_pending_call_finish_completion(DBusPendingCall *pending)
Call the notifier function for the pending call.
void _dbus_pending_call_start_completion_unlocked(DBusPendingCall *pending)
Sets the pending call to completed.
void _dbus_data_slot_allocator_free(DBusDataSlotAllocator *allocator, dbus_int32_t *slot_id_p)
Deallocates an ID previously allocated with _dbus_data_slot_allocator_alloc().
void dbus_connection_unref(DBusConnection *connection)
Decrements the reference count of a DBusConnection, and finalizes it if the count reaches zero.
dbus_bool_t(* DBusTimeoutHandler)(void *data)
function to run when the timeout is handled
dbus_bool_t _dbus_pending_call_get_completed_unlocked(DBusPendingCall *pending)
Checks whether the pending call has received a reply yet, or not.
dbus_bool_t dbus_pending_call_allocate_data_slot(dbus_int32_t *slot_p)
Allocates an integer ID to be used for storing application-specific data on any DBusPendingCall.
void _dbus_pending_call_set_reply_serial_unlocked(DBusPendingCall *pending, dbus_uint32_t serial)
Sets the reply's serial number.
dbus_int32_t _dbus_atomic_inc(DBusAtomic *atomic)
Atomically increments an integer.
Data structure that stores the actual user data set at a given slot.
DBusTimeout * _dbus_pending_call_get_timeout_unlocked(DBusPendingCall *pending)
Retrives the timeout.
int dbus_message_get_type(DBusMessage *message)
Gets the type of a message.
Implementation details of DBusPendingCall - all fields are private.
#define dbus_new0(type, count)
DBUS_PRIVATE_EXPORT DBusConnection * _dbus_connection_ref_unlocked(DBusConnection *connection)
Increments the reference count of a DBusConnection.
DBusMessage * dbus_message_new_error(DBusMessage *reply_to, const char *error_name, const char *error_message)
Creates a new message that is an error reply to another message.
DBusTimeout * timeout
Timeout.
dbus_uint32_t dbus_bool_t