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: #include michael@0: #include "nsAutoPtr.h" michael@0: #include "DBusUtils.h" michael@0: michael@0: #undef CHROMIUM_LOG michael@0: #if defined(MOZ_WIDGET_GONK) michael@0: #include michael@0: #define CHROMIUM_LOG(args...) __android_log_print(ANDROID_LOG_INFO, "Gonk", args); michael@0: #else michael@0: #define CHROMIUM_LOG(args...) printf(args); michael@0: #endif michael@0: michael@0: namespace mozilla { michael@0: namespace ipc { michael@0: michael@0: // michael@0: // DBusMessageRefPtr michael@0: // michael@0: michael@0: DBusMessageRefPtr::DBusMessageRefPtr(DBusMessage* aMsg) michael@0: : mMsg(aMsg) michael@0: { michael@0: if (mMsg) { michael@0: dbus_message_ref(mMsg); michael@0: } michael@0: } michael@0: michael@0: DBusMessageRefPtr::~DBusMessageRefPtr() michael@0: { michael@0: if (mMsg) { michael@0: dbus_message_unref(mMsg); michael@0: } michael@0: } michael@0: michael@0: // michael@0: // DBusReplyHandler michael@0: // michael@0: michael@0: void DBusReplyHandler::Callback(DBusMessage* aReply, void* aData) michael@0: { michael@0: MOZ_ASSERT(aData); michael@0: michael@0: nsRefPtr handler = michael@0: already_AddRefed(static_cast(aData)); michael@0: michael@0: handler->Handle(aReply); michael@0: } michael@0: michael@0: // michael@0: // Utility functions michael@0: // michael@0: michael@0: void michael@0: log_and_free_dbus_error(DBusError* err, const char* function, DBusMessage* msg) michael@0: { michael@0: if (msg) { michael@0: CHROMIUM_LOG("%s: D-Bus error in %s: %s (%s)", function, michael@0: dbus_message_get_member((msg)), (err)->name, (err)->message); michael@0: } else { michael@0: CHROMIUM_LOG("%s: D-Bus error: %s (%s)", __FUNCTION__, michael@0: (err)->name, (err)->message); michael@0: } michael@0: dbus_error_free((err)); michael@0: } michael@0: michael@0: int dbus_returns_int32(DBusMessage *reply) michael@0: { michael@0: DBusError err; michael@0: int32_t ret = -1; michael@0: michael@0: dbus_error_init(&err); michael@0: if (!dbus_message_get_args(reply, &err, michael@0: DBUS_TYPE_INT32, &ret, michael@0: DBUS_TYPE_INVALID)) { michael@0: LOG_AND_FREE_DBUS_ERROR_WITH_MSG(&err, reply); michael@0: } michael@0: michael@0: return ret; michael@0: } michael@0: michael@0: } michael@0: }