2012-05-07 21:50:25 +00:00
|
|
|
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
|
2012-08-21 03:21:24 +00:00
|
|
|
/* vim: set ts=2 et sw=2 tw=80: */
|
2012-05-07 21:50:25 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#include "RawDBusConnection.h"
|
|
|
|
#include <dbus/dbus.h>
|
|
|
|
|
|
|
|
using namespace mozilla::ipc;
|
|
|
|
|
2013-01-14 10:50:18 +00:00
|
|
|
bool RawDBusConnection::sDBusIsInit(false);
|
|
|
|
|
2013-07-22 11:30:22 +00:00
|
|
|
RawDBusConnection::RawDBusConnection()
|
|
|
|
{
|
2012-05-07 21:50:25 +00:00
|
|
|
}
|
|
|
|
|
2013-07-22 11:30:22 +00:00
|
|
|
RawDBusConnection::~RawDBusConnection()
|
|
|
|
{
|
2012-05-07 21:50:25 +00:00
|
|
|
}
|
|
|
|
|
2013-01-14 10:50:18 +00:00
|
|
|
nsresult RawDBusConnection::EstablishDBusConnection()
|
|
|
|
{
|
|
|
|
if (!sDBusIsInit) {
|
|
|
|
dbus_bool_t success = dbus_threads_init_default();
|
|
|
|
NS_ENSURE_TRUE(success == TRUE, NS_ERROR_FAILURE);
|
|
|
|
sDBusIsInit = true;
|
|
|
|
}
|
2012-05-07 21:50:25 +00:00
|
|
|
DBusError err;
|
|
|
|
dbus_error_init(&err);
|
|
|
|
mConnection = dbus_bus_get(DBUS_BUS_SYSTEM, &err);
|
|
|
|
if (dbus_error_is_set(&err)) {
|
|
|
|
dbus_error_free(&err);
|
2012-06-02 18:23:16 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
2012-05-07 21:50:25 +00:00
|
|
|
}
|
|
|
|
dbus_connection_set_exit_on_disconnect(mConnection, FALSE);
|
2012-06-02 18:23:16 +00:00
|
|
|
return NS_OK;
|
2012-05-07 21:50:25 +00:00
|
|
|
}
|
|
|
|
|
2012-06-02 18:23:16 +00:00
|
|
|
void RawDBusConnection::ScopedDBusConnectionPtrTraits::release(DBusConnection* ptr)
|
|
|
|
{
|
2013-01-14 10:50:18 +00:00
|
|
|
if (ptr) {
|
|
|
|
dbus_connection_unref(ptr);
|
|
|
|
}
|
2012-06-02 18:23:16 +00:00
|
|
|
}
|