2012-05-07 14:50:25 -07:00
|
|
|
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
|
2012-08-20 20:21:24 -07:00
|
|
|
/* vim: set ts=2 et sw=2 tw=80: */
|
2012-05-07 14:50:25 -07: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 01:20:39 -07:00
|
|
|
#include <dbus/dbus.h>
|
2013-01-28 01:15:31 -08:00
|
|
|
#include "nsAutoPtr.h"
|
2013-10-01 01:20:39 -07:00
|
|
|
#include "DBusUtils.h"
|
2012-05-07 14:50:25 -07:00
|
|
|
|
2013-12-17 10:26:45 -08:00
|
|
|
#undef CHROMIUM_LOG
|
2012-05-07 14:50:25 -07:00
|
|
|
#if defined(MOZ_WIDGET_GONK)
|
|
|
|
#include <android/log.h>
|
2013-12-17 10:26:45 -08:00
|
|
|
#define CHROMIUM_LOG(args...) __android_log_print(ANDROID_LOG_INFO, "Gonk", args);
|
2012-05-07 14:50:25 -07:00
|
|
|
#else
|
2013-12-17 10:26:45 -08:00
|
|
|
#define CHROMIUM_LOG(args...) printf(args);
|
2012-05-07 14:50:25 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace ipc {
|
|
|
|
|
2013-03-01 04:43:45 -08:00
|
|
|
//
|
2013-10-01 01:20:39 -07:00
|
|
|
// DBusMessageRefPtr
|
2013-03-01 04:43:45 -08:00
|
|
|
//
|
|
|
|
|
2013-10-01 01:20:39 -07:00
|
|
|
DBusMessageRefPtr::DBusMessageRefPtr(DBusMessage* aMsg)
|
|
|
|
: mMsg(aMsg)
|
2013-03-01 04:43:45 -08:00
|
|
|
{
|
2013-10-01 01:20:39 -07:00
|
|
|
if (mMsg) {
|
|
|
|
dbus_message_ref(mMsg);
|
2013-03-01 04:43:45 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-01 01:20:39 -07:00
|
|
|
DBusMessageRefPtr::~DBusMessageRefPtr()
|
2013-03-01 04:43:45 -08:00
|
|
|
{
|
2013-10-01 01:20:39 -07:00
|
|
|
if (mMsg) {
|
|
|
|
dbus_message_unref(mMsg);
|
2013-03-01 04:43:45 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-01 03:49:57 -08:00
|
|
|
//
|
2013-10-01 01:20:39 -07:00
|
|
|
// DBusReplyHandler
|
2013-03-01 03:49:57 -08:00
|
|
|
//
|
|
|
|
|
2013-10-01 01:20:39 -07:00
|
|
|
void DBusReplyHandler::Callback(DBusMessage* aReply, void* aData)
|
2013-01-28 01:15:31 -08:00
|
|
|
{
|
2013-10-01 01:20:39 -07:00
|
|
|
MOZ_ASSERT(aData);
|
2012-06-02 11:23:16 -07:00
|
|
|
|
2015-10-17 22:24:48 -07:00
|
|
|
RefPtr<DBusReplyHandler> handler =
|
2013-10-01 01:20:39 -07:00
|
|
|
already_AddRefed<DBusReplyHandler>(static_cast<DBusReplyHandler*>(aData));
|
2012-06-02 11:23:16 -07:00
|
|
|
|
2013-10-01 01:20:39 -07:00
|
|
|
handler->Handle(aReply);
|
2012-06-02 11:23:16 -07:00
|
|
|
}
|
|
|
|
|
2013-03-01 06:05:50 -08:00
|
|
|
//
|
2013-10-01 01:20:39 -07:00
|
|
|
// Utility functions
|
2013-03-01 06:05:50 -08:00
|
|
|
//
|
|
|
|
|
2013-10-01 01:20:39 -07:00
|
|
|
void
|
|
|
|
log_and_free_dbus_error(DBusError* err, const char* function, DBusMessage* msg)
|
2013-03-01 06:05:50 -08:00
|
|
|
{
|
|
|
|
if (msg) {
|
2013-12-17 10:26:45 -08:00
|
|
|
CHROMIUM_LOG("%s: D-Bus error in %s: %s (%s)", function,
|
|
|
|
dbus_message_get_member((msg)), (err)->name, (err)->message);
|
2013-10-01 01:20:39 -07:00
|
|
|
} else {
|
2013-12-17 10:26:45 -08:00
|
|
|
CHROMIUM_LOG("%s: D-Bus error: %s (%s)", __FUNCTION__,
|
|
|
|
(err)->name, (err)->message);
|
2012-06-02 11:23:16 -07:00
|
|
|
}
|
2013-10-01 01:20:39 -07:00
|
|
|
dbus_error_free((err));
|
2012-06-02 11:23:16 -07:00
|
|
|
}
|
|
|
|
|
2013-03-01 06:05:50 -08:00
|
|
|
int dbus_returns_int32(DBusMessage *reply)
|
2012-08-07 21:19:07 -07:00
|
|
|
{
|
|
|
|
DBusError err;
|
2012-10-01 00:04:01 -07:00
|
|
|
int32_t ret = -1;
|
2012-08-07 21:19:07 -07: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-07 14:50:25 -07:00
|
|
|
}
|
|
|
|
}
|