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
|
|
|
/* 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 02:50:18 -08:00
|
|
|
bool RawDBusConnection::sDBusIsInit(false);
|
|
|
|
|
2012-05-07 14:50:25 -07:00
|
|
|
RawDBusConnection::RawDBusConnection() {
|
|
|
|
}
|
|
|
|
|
|
|
|
RawDBusConnection::~RawDBusConnection() {
|
|
|
|
}
|
|
|
|
|
2013-01-14 02:50:18 -08: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 14:50:25 -07: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 11:23:16 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
2012-05-07 14:50:25 -07:00
|
|
|
}
|
|
|
|
dbus_connection_set_exit_on_disconnect(mConnection, FALSE);
|
2012-06-02 11:23:16 -07:00
|
|
|
return NS_OK;
|
2012-05-07 14:50:25 -07:00
|
|
|
}
|
|
|
|
|
2012-06-02 11:23:16 -07:00
|
|
|
void RawDBusConnection::ScopedDBusConnectionPtrTraits::release(DBusConnection* ptr)
|
|
|
|
{
|
2013-01-14 02:50:18 -08:00
|
|
|
if (ptr) {
|
|
|
|
dbus_connection_unref(ptr);
|
|
|
|
}
|
2012-06-02 11:23:16 -07:00
|
|
|
}
|