diff --git a/ipc/dbus/DBusUtils.cpp b/ipc/dbus/DBusUtils.cpp index 80701010b3ab..0f119234c14c 100644 --- a/ipc/dbus/DBusUtils.cpp +++ b/ipc/dbus/DBusUtils.cpp @@ -647,5 +647,15 @@ int dbus_returns_uint32(DBusMessage *reply) return ret; } +void DBusReplyHandler::Callback(DBusMessage* aReply, void* aData) +{ + MOZ_ASSERT(aData); + + nsRefPtr handler = + already_AddRefed(static_cast(aData)); + + handler->Handle(aReply); +} + } } diff --git a/ipc/dbus/DBusUtils.h b/ipc/dbus/DBusUtils.h index a1ec0ebadb1a..b3f0f018ce68 100644 --- a/ipc/dbus/DBusUtils.h +++ b/ipc/dbus/DBusUtils.h @@ -20,6 +20,7 @@ #define mozilla_ipc_dbus_dbusutils_h__ #include +#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 +{ +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,