2012-05-08 01:50:25 +04:00
|
|
|
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
|
2012-08-21 07:21:24 +04:00
|
|
|
/* vim: set ts=2 et sw=2 tw=80: */
|
2012-05-08 01:50:25 +04:00
|
|
|
/*
|
|
|
|
** Copyright 2006, The Android Open Source Project
|
|
|
|
**
|
|
|
|
** Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
** you may not use this file except in compliance with the License.
|
|
|
|
** You may obtain a copy of the License at
|
|
|
|
**
|
|
|
|
** http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
**
|
|
|
|
** Unless required by applicable law or agreed to in writing, software
|
|
|
|
** distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
** See the License for the specific language governing permissions and
|
|
|
|
** limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2013-10-01 12:20:39 +04:00
|
|
|
#include <dbus/dbus.h>
|
2013-01-28 13:15:31 +04:00
|
|
|
#include "nsAutoPtr.h"
|
2013-10-01 12:20:39 +04:00
|
|
|
#include "DBusUtils.h"
|
2012-05-08 01:50:25 +04:00
|
|
|
|
2013-12-17 22:26:45 +04:00
|
|
|
#undef CHROMIUM_LOG
|
2012-05-08 01:50:25 +04:00
|
|
|
#if defined(MOZ_WIDGET_GONK)
|
|
|
|
#include <android/log.h>
|
2013-12-17 22:26:45 +04:00
|
|
|
#define CHROMIUM_LOG(args...) __android_log_print(ANDROID_LOG_INFO, "Gonk", args);
|
2012-05-08 01:50:25 +04:00
|
|
|
#else
|
2013-12-17 22:26:45 +04:00
|
|
|
#define CHROMIUM_LOG(args...) printf(args);
|
2012-05-08 01:50:25 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace ipc {
|
|
|
|
|
2013-03-01 16:43:45 +04:00
|
|
|
//
|
2013-10-01 12:20:39 +04:00
|
|
|
// DBusMessageRefPtr
|
2013-03-01 16:43:45 +04:00
|
|
|
//
|
|
|
|
|
2013-10-01 12:20:39 +04:00
|
|
|
DBusMessageRefPtr::DBusMessageRefPtr(DBusMessage* aMsg)
|
|
|
|
: mMsg(aMsg)
|
2013-03-01 16:43:45 +04:00
|
|
|
{
|
2013-10-01 12:20:39 +04:00
|
|
|
if (mMsg) {
|
|
|
|
dbus_message_ref(mMsg);
|
2013-03-01 16:43:45 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-01 12:20:39 +04:00
|
|
|
DBusMessageRefPtr::~DBusMessageRefPtr()
|
2013-03-01 16:43:45 +04:00
|
|
|
{
|
2013-10-01 12:20:39 +04:00
|
|
|
if (mMsg) {
|
|
|
|
dbus_message_unref(mMsg);
|
2013-03-01 16:43:45 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-01 15:49:57 +04:00
|
|
|
//
|
2013-10-01 12:20:39 +04:00
|
|
|
// DBusReplyHandler
|
2013-03-01 15:49:57 +04:00
|
|
|
//
|
|
|
|
|
2013-10-01 12:20:39 +04:00
|
|
|
void DBusReplyHandler::Callback(DBusMessage* aReply, void* aData)
|
2013-01-28 13:15:31 +04:00
|
|
|
{
|
2013-10-01 12:20:39 +04:00
|
|
|
MOZ_ASSERT(aData);
|
2012-06-02 22:23:16 +04:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<DBusReplyHandler> handler =
|
2013-10-01 12:20:39 +04:00
|
|
|
already_AddRefed<DBusReplyHandler>(static_cast<DBusReplyHandler*>(aData));
|
2012-06-02 22:23:16 +04:00
|
|
|
|
2013-10-01 12:20:39 +04:00
|
|
|
handler->Handle(aReply);
|
2012-06-02 22:23:16 +04:00
|
|
|
}
|
|
|
|
|
2013-03-01 18:05:50 +04:00
|
|
|
//
|
2013-10-01 12:20:39 +04:00
|
|
|
// Utility functions
|
2013-03-01 18:05:50 +04:00
|
|
|
//
|
|
|
|
|
2013-10-01 12:20:39 +04:00
|
|
|
void
|
|
|
|
log_and_free_dbus_error(DBusError* err, const char* function, DBusMessage* msg)
|
2013-03-01 18:05:50 +04:00
|
|
|
{
|
|
|
|
if (msg) {
|
2013-12-17 22:26:45 +04:00
|
|
|
CHROMIUM_LOG("%s: D-Bus error in %s: %s (%s)", function,
|
|
|
|
dbus_message_get_member((msg)), (err)->name, (err)->message);
|
2013-10-01 12:20:39 +04:00
|
|
|
} else {
|
2013-12-17 22:26:45 +04:00
|
|
|
CHROMIUM_LOG("%s: D-Bus error: %s (%s)", __FUNCTION__,
|
|
|
|
(err)->name, (err)->message);
|
2012-06-02 22:23:16 +04:00
|
|
|
}
|
2013-10-01 12:20:39 +04:00
|
|
|
dbus_error_free((err));
|
2012-06-02 22:23:16 +04:00
|
|
|
}
|
|
|
|
|
2013-03-01 18:05:50 +04:00
|
|
|
int dbus_returns_int32(DBusMessage *reply)
|
2012-08-08 08:19:07 +04:00
|
|
|
{
|
|
|
|
DBusError err;
|
2012-10-01 11:04:01 +04:00
|
|
|
int32_t ret = -1;
|
2012-08-08 08:19:07 +04:00
|
|
|
|
|
|
|
dbus_error_init(&err);
|
|
|
|
if (!dbus_message_get_args(reply, &err,
|
|
|
|
DBUS_TYPE_INT32, &ret,
|
|
|
|
DBUS_TYPE_INVALID)) {
|
|
|
|
LOG_AND_FREE_DBUS_ERROR_WITH_MSG(&err, reply);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-05-08 01:50:25 +04:00
|
|
|
}
|
|
|
|
}
|