michael@0: /* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */ michael@0: /* vim: set ts=2 et sw=2 tw=80: */ michael@0: /* michael@0: ** Copyright 2006, The Android Open Source Project michael@0: ** michael@0: ** Licensed under the Apache License, Version 2.0 (the "License"); michael@0: ** you may not use this file except in compliance with the License. michael@0: ** You may obtain a copy of the License at michael@0: ** michael@0: ** http://www.apache.org/licenses/LICENSE-2.0 michael@0: ** michael@0: ** Unless required by applicable law or agreed to in writing, software michael@0: ** distributed under the License is distributed on an "AS IS" BASIS, michael@0: ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. michael@0: ** See the License for the specific language governing permissions and michael@0: ** limitations under the License. michael@0: */ michael@0: michael@0: #ifndef mozilla_ipc_dbus_dbusutils_h__ michael@0: #define mozilla_ipc_dbus_dbusutils_h__ michael@0: michael@0: #include "mozilla/RefPtr.h" michael@0: michael@0: // LOGE and free a D-Bus error michael@0: // Using #define so that __FUNCTION__ resolves usefully michael@0: #define LOG_AND_FREE_DBUS_ERROR_WITH_MSG(err, msg) log_and_free_dbus_error(err, __FUNCTION__, msg); michael@0: #define LOG_AND_FREE_DBUS_ERROR(err) log_and_free_dbus_error(err, __FUNCTION__); michael@0: michael@0: struct DBusError; michael@0: struct DBusMessage; michael@0: michael@0: namespace mozilla { michael@0: namespace ipc { michael@0: michael@0: class DBusMessageRefPtr michael@0: { michael@0: public: michael@0: DBusMessageRefPtr(DBusMessage* aMsg); michael@0: ~DBusMessageRefPtr(); michael@0: michael@0: operator DBusMessage* () michael@0: { michael@0: return mMsg; michael@0: } michael@0: michael@0: DBusMessage* get() michael@0: { michael@0: return mMsg; michael@0: } michael@0: michael@0: private: michael@0: DBusMessage* mMsg; michael@0: }; michael@0: michael@0: /** michael@0: * DBusReplyHandler represents a handler for DBus reply messages. Inherit michael@0: * from this class and implement the Handle method. The method Callback michael@0: * should be passed to the DBus send function, with the class instance as michael@0: * user-data argument. michael@0: */ michael@0: class DBusReplyHandler michael@0: { michael@0: public: michael@0: NS_INLINE_DECL_THREADSAFE_REFCOUNTING(DBusReplyHandler) michael@0: michael@0: /** michael@0: * Implements a call-back function for DBus. The supplied value for michael@0: * aData must be a pointer to an instance of DBusReplyHandler. michael@0: */ michael@0: static void Callback(DBusMessage* aReply, void* aData); michael@0: michael@0: /** michael@0: * Call-back method for handling the reply message from DBus. michael@0: */ michael@0: virtual void Handle(DBusMessage* aReply) = 0; michael@0: michael@0: protected: michael@0: DBusReplyHandler() michael@0: { michael@0: } michael@0: michael@0: DBusReplyHandler(const DBusReplyHandler& aHandler) michael@0: { michael@0: } michael@0: michael@0: DBusReplyHandler& operator = (const DBusReplyHandler& aRhs) michael@0: { michael@0: return *this; michael@0: } michael@0: michael@0: virtual ~DBusReplyHandler() michael@0: { michael@0: } michael@0: }; michael@0: michael@0: void log_and_free_dbus_error(DBusError* err, michael@0: const char* function, michael@0: DBusMessage* msg = nullptr); michael@0: michael@0: int dbus_returns_int32(DBusMessage *reply); michael@0: michael@0: } michael@0: } michael@0: michael@0: #endif michael@0: