Wed, 31 Dec 2014 06:55:46 +0100
Added tag TORBROWSER_REPLICA for changeset 6474c204b198
michael@0 | 1 | /* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */ |
michael@0 | 2 | /* vim: set ts=2 et sw=2 tw=80: */ |
michael@0 | 3 | /* |
michael@0 | 4 | ** Copyright 2006, The Android Open Source Project |
michael@0 | 5 | ** |
michael@0 | 6 | ** Licensed under the Apache License, Version 2.0 (the "License"); |
michael@0 | 7 | ** you may not use this file except in compliance with the License. |
michael@0 | 8 | ** You may obtain a copy of the License at |
michael@0 | 9 | ** |
michael@0 | 10 | ** http://www.apache.org/licenses/LICENSE-2.0 |
michael@0 | 11 | ** |
michael@0 | 12 | ** Unless required by applicable law or agreed to in writing, software |
michael@0 | 13 | ** distributed under the License is distributed on an "AS IS" BASIS, |
michael@0 | 14 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
michael@0 | 15 | ** See the License for the specific language governing permissions and |
michael@0 | 16 | ** limitations under the License. |
michael@0 | 17 | */ |
michael@0 | 18 | |
michael@0 | 19 | #include <dbus/dbus.h> |
michael@0 | 20 | #include "nsAutoPtr.h" |
michael@0 | 21 | #include "DBusUtils.h" |
michael@0 | 22 | |
michael@0 | 23 | #undef CHROMIUM_LOG |
michael@0 | 24 | #if defined(MOZ_WIDGET_GONK) |
michael@0 | 25 | #include <android/log.h> |
michael@0 | 26 | #define CHROMIUM_LOG(args...) __android_log_print(ANDROID_LOG_INFO, "Gonk", args); |
michael@0 | 27 | #else |
michael@0 | 28 | #define CHROMIUM_LOG(args...) printf(args); |
michael@0 | 29 | #endif |
michael@0 | 30 | |
michael@0 | 31 | namespace mozilla { |
michael@0 | 32 | namespace ipc { |
michael@0 | 33 | |
michael@0 | 34 | // |
michael@0 | 35 | // DBusMessageRefPtr |
michael@0 | 36 | // |
michael@0 | 37 | |
michael@0 | 38 | DBusMessageRefPtr::DBusMessageRefPtr(DBusMessage* aMsg) |
michael@0 | 39 | : mMsg(aMsg) |
michael@0 | 40 | { |
michael@0 | 41 | if (mMsg) { |
michael@0 | 42 | dbus_message_ref(mMsg); |
michael@0 | 43 | } |
michael@0 | 44 | } |
michael@0 | 45 | |
michael@0 | 46 | DBusMessageRefPtr::~DBusMessageRefPtr() |
michael@0 | 47 | { |
michael@0 | 48 | if (mMsg) { |
michael@0 | 49 | dbus_message_unref(mMsg); |
michael@0 | 50 | } |
michael@0 | 51 | } |
michael@0 | 52 | |
michael@0 | 53 | // |
michael@0 | 54 | // DBusReplyHandler |
michael@0 | 55 | // |
michael@0 | 56 | |
michael@0 | 57 | void DBusReplyHandler::Callback(DBusMessage* aReply, void* aData) |
michael@0 | 58 | { |
michael@0 | 59 | MOZ_ASSERT(aData); |
michael@0 | 60 | |
michael@0 | 61 | nsRefPtr<DBusReplyHandler> handler = |
michael@0 | 62 | already_AddRefed<DBusReplyHandler>(static_cast<DBusReplyHandler*>(aData)); |
michael@0 | 63 | |
michael@0 | 64 | handler->Handle(aReply); |
michael@0 | 65 | } |
michael@0 | 66 | |
michael@0 | 67 | // |
michael@0 | 68 | // Utility functions |
michael@0 | 69 | // |
michael@0 | 70 | |
michael@0 | 71 | void |
michael@0 | 72 | log_and_free_dbus_error(DBusError* err, const char* function, DBusMessage* msg) |
michael@0 | 73 | { |
michael@0 | 74 | if (msg) { |
michael@0 | 75 | CHROMIUM_LOG("%s: D-Bus error in %s: %s (%s)", function, |
michael@0 | 76 | dbus_message_get_member((msg)), (err)->name, (err)->message); |
michael@0 | 77 | } else { |
michael@0 | 78 | CHROMIUM_LOG("%s: D-Bus error: %s (%s)", __FUNCTION__, |
michael@0 | 79 | (err)->name, (err)->message); |
michael@0 | 80 | } |
michael@0 | 81 | dbus_error_free((err)); |
michael@0 | 82 | } |
michael@0 | 83 | |
michael@0 | 84 | int dbus_returns_int32(DBusMessage *reply) |
michael@0 | 85 | { |
michael@0 | 86 | DBusError err; |
michael@0 | 87 | int32_t ret = -1; |
michael@0 | 88 | |
michael@0 | 89 | dbus_error_init(&err); |
michael@0 | 90 | if (!dbus_message_get_args(reply, &err, |
michael@0 | 91 | DBUS_TYPE_INT32, &ret, |
michael@0 | 92 | DBUS_TYPE_INVALID)) { |
michael@0 | 93 | LOG_AND_FREE_DBUS_ERROR_WITH_MSG(&err, reply); |
michael@0 | 94 | } |
michael@0 | 95 | |
michael@0 | 96 | return ret; |
michael@0 | 97 | } |
michael@0 | 98 | |
michael@0 | 99 | } |
michael@0 | 100 | } |