ipc/dbus/DBusUtils.h

Wed, 31 Dec 2014 06:55:46 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:55:46 +0100
changeset 1
ca08bd8f51b2
permissions
-rw-r--r--

Added tag TORBROWSER_REPLICA for changeset 6474c204b198

     1 /* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
     2 /* vim: set ts=2 et sw=2 tw=80: */
     3 /*
     4 ** Copyright 2006, The Android Open Source Project
     5 **
     6 ** Licensed under the Apache License, Version 2.0 (the "License");
     7 ** you may not use this file except in compliance with the License.
     8 ** You may obtain a copy of the License at
     9 **
    10 **     http://www.apache.org/licenses/LICENSE-2.0
    11 **
    12 ** Unless required by applicable law or agreed to in writing, software
    13 ** distributed under the License is distributed on an "AS IS" BASIS,
    14 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    15 ** See the License for the specific language governing permissions and
    16 ** limitations under the License.
    17 */
    19 #ifndef mozilla_ipc_dbus_dbusutils_h__
    20 #define mozilla_ipc_dbus_dbusutils_h__
    22 #include "mozilla/RefPtr.h"
    24 // LOGE and free a D-Bus error
    25 // Using #define so that __FUNCTION__ resolves usefully
    26 #define LOG_AND_FREE_DBUS_ERROR_WITH_MSG(err, msg) log_and_free_dbus_error(err, __FUNCTION__, msg);
    27 #define LOG_AND_FREE_DBUS_ERROR(err) log_and_free_dbus_error(err, __FUNCTION__);
    29 struct DBusError;
    30 struct DBusMessage;
    32 namespace mozilla {
    33 namespace ipc {
    35 class DBusMessageRefPtr
    36 {
    37 public:
    38   DBusMessageRefPtr(DBusMessage* aMsg);
    39   ~DBusMessageRefPtr();
    41   operator DBusMessage* ()
    42   {
    43     return mMsg;
    44   }
    46   DBusMessage* get()
    47   {
    48     return mMsg;
    49   }
    51 private:
    52   DBusMessage* mMsg;
    53 };
    55 /**
    56  * DBusReplyHandler represents a handler for DBus reply messages. Inherit
    57  * from this class and implement the Handle method. The method Callback
    58  * should be passed to the DBus send function, with the class instance as
    59  * user-data argument.
    60  */
    61 class DBusReplyHandler
    62 {
    63 public:
    64   NS_INLINE_DECL_THREADSAFE_REFCOUNTING(DBusReplyHandler)
    66   /**
    67    * Implements a call-back function for DBus. The supplied value for
    68    * aData must be a pointer to an instance of DBusReplyHandler.
    69    */
    70   static void Callback(DBusMessage* aReply, void* aData);
    72   /**
    73    * Call-back method for handling the reply message from DBus.
    74    */
    75   virtual void Handle(DBusMessage* aReply) = 0;
    77 protected:
    78   DBusReplyHandler()
    79   {
    80   }
    82   DBusReplyHandler(const DBusReplyHandler& aHandler)
    83   {
    84   }
    86   DBusReplyHandler& operator = (const DBusReplyHandler& aRhs)
    87   {
    88     return *this;
    89   }
    91   virtual ~DBusReplyHandler()
    92   {
    93   }
    94 };
    96 void log_and_free_dbus_error(DBusError* err,
    97                              const char* function,
    98                              DBusMessage* msg = nullptr);
   100 int dbus_returns_int32(DBusMessage *reply);
   102 }
   103 }
   105 #endif

mercurial