Bug 884840: Added DBusReplyHandler, r=qdot

Handler functions for DBus replies sometimes need several data fields
or need to keep state over replies for multiple messages. The DBus API
itself only allows for a single pointer to user data.

The class DBusReplyHandler is a base class for implementing DBus reply-
message handlers. Users of DBus can inherit from this class to implement
message-specific handlers.

--HG--
extra : rebase_source : 91c5f6e8d365922fd3b52fbaf502052f86274f16
This commit is contained in:
Thomas Zimmermann 2013-07-09 09:55:08 +02:00
Родитель f2a832c8ec
Коммит 4de46e8113
2 изменённых файлов: 49 добавлений и 1 удалений

Просмотреть файл

@ -647,5 +647,15 @@ int dbus_returns_uint32(DBusMessage *reply)
return ret;
}
void DBusReplyHandler::Callback(DBusMessage* aReply, void* aData)
{
MOZ_ASSERT(aData);
nsRefPtr<DBusReplyHandler> handler =
already_AddRefed<DBusReplyHandler>(static_cast<DBusReplyHandler*>(aData));
handler->Handle(aReply);
}
}
}

Просмотреть файл

@ -20,6 +20,7 @@
#define mozilla_ipc_dbus_dbusutils_h__
#include <dbus/dbus.h>
#include "mozilla/RefPtr.h"
#include "mozilla/Scoped.h"
// LOGE and free a D-Bus error
@ -50,8 +51,45 @@ private:
DBusMessage* mMsg;
};
typedef void (*DBusCallback)(DBusMessage *, void *);
/**
* DBusReplyHandler represents a handler for DBus reply messages. Inherit
* from this class and implement the Handle method. The method Callback
* should be passed to the DBus send function, with the class instance as
* user-data argument.
*/
class DBusReplyHandler : public mozilla::RefCounted<DBusReplyHandler>
{
public:
virtual ~DBusReplyHandler() {
}
/**
* Implements a call-back function for DBus. The supplied value for
* aData must be a pointer to an instance of DBusReplyHandler.
*/
static void Callback(DBusMessage* aReply, void* aData);
/**
* Call-back method for handling the reply message from DBus.
*/
virtual void Handle(DBusMessage* aReply) = 0;
protected:
DBusReplyHandler()
{
}
DBusReplyHandler(const DBusReplyHandler& aHandler)
{
}
DBusReplyHandler& operator = (const DBusReplyHandler& aRhs)
{
return *this;
}
};
typedef void (*DBusCallback)(DBusMessage *, void *);
void log_and_free_dbus_error(DBusError* err,
const char* function,