1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/ipc/dbus/DBusUtils.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,106 @@ 1.4 +/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */ 1.5 +/* vim: set ts=2 et sw=2 tw=80: */ 1.6 +/* 1.7 +** Copyright 2006, The Android Open Source Project 1.8 +** 1.9 +** Licensed under the Apache License, Version 2.0 (the "License"); 1.10 +** you may not use this file except in compliance with the License. 1.11 +** You may obtain a copy of the License at 1.12 +** 1.13 +** http://www.apache.org/licenses/LICENSE-2.0 1.14 +** 1.15 +** Unless required by applicable law or agreed to in writing, software 1.16 +** distributed under the License is distributed on an "AS IS" BASIS, 1.17 +** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1.18 +** See the License for the specific language governing permissions and 1.19 +** limitations under the License. 1.20 +*/ 1.21 + 1.22 +#ifndef mozilla_ipc_dbus_dbusutils_h__ 1.23 +#define mozilla_ipc_dbus_dbusutils_h__ 1.24 + 1.25 +#include "mozilla/RefPtr.h" 1.26 + 1.27 +// LOGE and free a D-Bus error 1.28 +// Using #define so that __FUNCTION__ resolves usefully 1.29 +#define LOG_AND_FREE_DBUS_ERROR_WITH_MSG(err, msg) log_and_free_dbus_error(err, __FUNCTION__, msg); 1.30 +#define LOG_AND_FREE_DBUS_ERROR(err) log_and_free_dbus_error(err, __FUNCTION__); 1.31 + 1.32 +struct DBusError; 1.33 +struct DBusMessage; 1.34 + 1.35 +namespace mozilla { 1.36 +namespace ipc { 1.37 + 1.38 +class DBusMessageRefPtr 1.39 +{ 1.40 +public: 1.41 + DBusMessageRefPtr(DBusMessage* aMsg); 1.42 + ~DBusMessageRefPtr(); 1.43 + 1.44 + operator DBusMessage* () 1.45 + { 1.46 + return mMsg; 1.47 + } 1.48 + 1.49 + DBusMessage* get() 1.50 + { 1.51 + return mMsg; 1.52 + } 1.53 + 1.54 +private: 1.55 + DBusMessage* mMsg; 1.56 +}; 1.57 + 1.58 +/** 1.59 + * DBusReplyHandler represents a handler for DBus reply messages. Inherit 1.60 + * from this class and implement the Handle method. The method Callback 1.61 + * should be passed to the DBus send function, with the class instance as 1.62 + * user-data argument. 1.63 + */ 1.64 +class DBusReplyHandler 1.65 +{ 1.66 +public: 1.67 + NS_INLINE_DECL_THREADSAFE_REFCOUNTING(DBusReplyHandler) 1.68 + 1.69 + /** 1.70 + * Implements a call-back function for DBus. The supplied value for 1.71 + * aData must be a pointer to an instance of DBusReplyHandler. 1.72 + */ 1.73 + static void Callback(DBusMessage* aReply, void* aData); 1.74 + 1.75 + /** 1.76 + * Call-back method for handling the reply message from DBus. 1.77 + */ 1.78 + virtual void Handle(DBusMessage* aReply) = 0; 1.79 + 1.80 +protected: 1.81 + DBusReplyHandler() 1.82 + { 1.83 + } 1.84 + 1.85 + DBusReplyHandler(const DBusReplyHandler& aHandler) 1.86 + { 1.87 + } 1.88 + 1.89 + DBusReplyHandler& operator = (const DBusReplyHandler& aRhs) 1.90 + { 1.91 + return *this; 1.92 + } 1.93 + 1.94 + virtual ~DBusReplyHandler() 1.95 + { 1.96 + } 1.97 +}; 1.98 + 1.99 +void log_and_free_dbus_error(DBusError* err, 1.100 + const char* function, 1.101 + DBusMessage* msg = nullptr); 1.102 + 1.103 +int dbus_returns_int32(DBusMessage *reply); 1.104 + 1.105 +} 1.106 +} 1.107 + 1.108 +#endif 1.109 +