Bug 830290: Cleanup DBus EventLoop function r=bent,qdot

We intent to run the DBus thread's EventLoop function as separate
nsRunnable, but the function also contains code for initializing
sockets that are used for internal communication.

With this patch the socket initialization has been moved to the
setup function. This reduces the EventLoop function to plain event
handling.
Bug 830290: Added DBusPollTask r=bent,qdot

This patch adds class DBusPollTask. The DBusPollTask class is an
nsRunnable for receiving DBus messages. It is intended to run in
a separate thread that is dedicated to DBus only.

The Run function of the poll task resembles the DBus EventLoop
function, but allows to intercept execution in favor of other
nsRunnables. Afterwards the DBusPollTask continues.
Bug 830290: Use DBusPollTask r=bent,qdot

This patch replaces the DBus EventLoop function by an instance
of DBusPollTask. It also cleans up the initialization and shutdown
code of the DBusThread.
Bug 830290: Added dispatch function for DBus thread r=bent,qdot

The new function allows to schedule nsRunnables to an existing DBus
thread. This intercepts the running instance of DBusPollTask and
makes the DBus thread process the dispatched runnable. The intercepted
poll task automatically continues polling once all pending runnables
have been processed.
Bug 830290: Setup asyncronous DBus messages in DBus thread r=bent,qdot

This patch finally fixes bug 827888 were a message's reply was
received before the respective handler function could be installed.

The patch adds the class DBusConnectionSendWithReplyTask, which
asyncronously sends a DBus message and installs the reply's handler
function. The DBus utility functions for asyncronous messages create
an instance of this class and dispatch it to the DBus thread. This
intercepts the DBusPollTask, so no DBus replies can be received until
the dispatched DBusConnectionSendWithReplyTask has finished.
Bug 830290: Cleanup DBusConnectionSendWithReplyTask r=bent,qdot

The class DBusConnectionSendWithReplyTask has been renamed to
DBusConnectionSendWithReplyRunnable, which better fits its purpose. The
internal callback function and data has been move into the implementation
of DBusConnectionSendWithReplyRunnable. Additionally, there is now an
abstract base class for DBus send runnables. This class will become useful
for implementing send classes with different policies.
Bug 830290: Execute DBus send operation in DBus thread r=bent,qdot

The DBus send operation simply sends a DBus message without further
processing of replies. If the sender is interested in a reply, the
respective serial number can be returned. In this case, the sending
operation (and only the sending) is serialized with the calling
thread.
Bug 830290: Replace dbus_connection_send by dbus_func_send r=bent,qdot

The Bluetooth system now uses dbus_func_send for sending DBus
messages where dbus_connection_send use used before. The former
function is similar to the latter one, but sends messages from
within the DBus thread; thus avoiding concurrency issues within
DBus.
Bug 830290: Send blocking DBus messages from within DBus thread r=bent,qdot

The this commit moves the sending of blocking DBus messages to the
DBus thread. This allows us to avoid concurrency problems within the
DBus library, which is not explicitly thread-safe.

As a side note, I'd like to mention that blocking in distributed
systems simply doesn't work. The dbus library is especially broken
in this regard as it delays all unrelated messages until the reply
for the blocking request has been received. A future commit should
implement this functionality with an asyncronous call and make the
related thread wait for the reply.
Bug 830290: Replace calls to dbus_connection_send_with_reply_and_block r=bent,qdot

There is one call to dbus_connection_send_with_reply_and_block in
the Bluetooth code. This patch replaces the call by a call to the
helper function dbus_func_send_and_block, which executes the DBus
operation within the DBus thread.
Bug 830290: Don't block DBus while waiting for replies r=bent,qdot