mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-11 20:35:50 +00:00
Bug 811569 - Patch 1: Remove unused files in bluetooth, r=echou
This commit is contained in:
parent
426c47cdf0
commit
c65148f7ec
@ -481,7 +481,6 @@ using mozilla::dom::workers::ResolveWorkerClasses;
|
||||
#include "BluetoothManager.h"
|
||||
#include "BluetoothAdapter.h"
|
||||
#include "BluetoothDevice.h"
|
||||
#include "BluetoothPropertyEvent.h"
|
||||
#endif
|
||||
|
||||
#include "nsIDOMNavigatorSystemMessages.h"
|
||||
@ -1518,11 +1517,9 @@ static nsDOMClassInfoData sClassInfoData[] = {
|
||||
NS_DEFINE_CLASSINFO_DATA(BluetoothManager, nsEventTargetSH,
|
||||
EVENTTARGET_SCRIPTABLE_FLAGS)
|
||||
NS_DEFINE_CLASSINFO_DATA(BluetoothAdapter, nsEventTargetSH,
|
||||
EVENTTARGET_SCRIPTABLE_FLAGS)
|
||||
EVENTTARGET_SCRIPTABLE_FLAGS)
|
||||
NS_DEFINE_CLASSINFO_DATA(BluetoothDevice, nsEventTargetSH,
|
||||
EVENTTARGET_SCRIPTABLE_FLAGS)
|
||||
NS_DEFINE_CLASSINFO_DATA(BluetoothPropertyEvent, nsDOMGenericSH,
|
||||
DOM_DEFAULT_SCRIPTABLE_FLAGS)
|
||||
#endif
|
||||
|
||||
NS_DEFINE_CLASSINFO_DATA(CameraManager, nsDOMGenericSH,
|
||||
@ -3945,15 +3942,10 @@ nsDOMClassInfo::Init()
|
||||
DOM_CLASSINFO_MAP_BEGIN(BluetoothAdapter, nsIDOMBluetoothAdapter)
|
||||
DOM_CLASSINFO_MAP_ENTRY(nsIDOMBluetoothAdapter)
|
||||
DOM_CLASSINFO_MAP_END
|
||||
|
||||
|
||||
DOM_CLASSINFO_MAP_BEGIN(BluetoothDevice, nsIDOMBluetoothDevice)
|
||||
DOM_CLASSINFO_MAP_ENTRY(nsIDOMBluetoothDevice)
|
||||
DOM_CLASSINFO_MAP_END
|
||||
|
||||
DOM_CLASSINFO_MAP_BEGIN(BluetoothPropertyEvent, nsIDOMBluetoothPropertyEvent)
|
||||
DOM_CLASSINFO_MAP_ENTRY(nsIDOMBluetoothPropertyEvent)
|
||||
DOM_CLASSINFO_MAP_ENTRY(nsIDOMEvent)
|
||||
DOM_CLASSINFO_MAP_END
|
||||
#endif
|
||||
|
||||
DOM_CLASSINFO_MAP_BEGIN(CameraManager, nsIDOMCameraManager)
|
||||
|
@ -445,7 +445,6 @@ DOMCI_CLASS(FMRadio)
|
||||
DOMCI_CLASS(BluetoothManager)
|
||||
DOMCI_CLASS(BluetoothAdapter)
|
||||
DOMCI_CLASS(BluetoothDevice)
|
||||
DOMCI_CLASS(BluetoothPropertyEvent)
|
||||
#endif
|
||||
|
||||
DOMCI_CLASS(CameraManager)
|
||||
|
@ -7,7 +7,6 @@
|
||||
#include "base/basictypes.h"
|
||||
#include "BluetoothAdapter.h"
|
||||
#include "BluetoothDevice.h"
|
||||
#include "BluetoothPropertyEvent.h"
|
||||
#include "BluetoothReplyRunnable.h"
|
||||
#include "BluetoothService.h"
|
||||
#include "BluetoothUtils.h"
|
||||
@ -267,6 +266,7 @@ BluetoothAdapter::Notify(const BluetoothSignal& aData)
|
||||
{
|
||||
InfallibleTArray<BluetoothNamedValue> arr;
|
||||
|
||||
BluetoothValue v = aData.value();
|
||||
if (aData.name().EqualsLiteral("DeviceFound")) {
|
||||
nsRefPtr<BluetoothDevice> device = BluetoothDevice::Create(GetOwner(), mPath, aData.value());
|
||||
nsCOMPtr<nsIDOMEvent> event;
|
||||
@ -301,16 +301,14 @@ BluetoothAdapter::Notify(const BluetoothSignal& aData)
|
||||
false, false, device);
|
||||
DispatchTrustedEvent(e);
|
||||
} else if (aData.name().EqualsLiteral("PropertyChanged")) {
|
||||
NS_ASSERTION(aData.value().type() == BluetoothValue::TArrayOfBluetoothNamedValue,
|
||||
NS_ASSERTION(v.type() == BluetoothValue::TArrayOfBluetoothNamedValue,
|
||||
"PropertyChanged: Invalid value type");
|
||||
arr = aData.value().get_ArrayOfBluetoothNamedValue();
|
||||
const InfallibleTArray<BluetoothNamedValue>& arr =
|
||||
v.get_ArrayOfBluetoothNamedValue();
|
||||
|
||||
NS_ASSERTION(arr.Length() == 1, "Got more than one property in a change message!");
|
||||
BluetoothNamedValue v = arr[0];
|
||||
|
||||
SetPropertyByValue(v);
|
||||
nsRefPtr<BluetoothPropertyEvent> e = BluetoothPropertyEvent::Create(v.name());
|
||||
e->Dispatch(ToIDOMEventTarget(), NS_LITERAL_STRING("propertychanged"));
|
||||
NS_ASSERTION(arr.Length() == 1,
|
||||
"Got more than one property in a change message!");
|
||||
SetPropertyByValue(arr[0]);
|
||||
} else {
|
||||
#ifdef DEBUG
|
||||
nsCString warningMsg;
|
||||
|
@ -6,7 +6,6 @@
|
||||
|
||||
#include "base/basictypes.h"
|
||||
#include "BluetoothDevice.h"
|
||||
#include "BluetoothPropertyEvent.h"
|
||||
#include "BluetoothReplyRunnable.h"
|
||||
#include "BluetoothService.h"
|
||||
#include "BluetoothUtils.h"
|
||||
@ -27,12 +26,12 @@ NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN_INHERITED(BluetoothDevice,
|
||||
NS_IMPL_CYCLE_COLLECTION_TRACE_JS_MEMBER_CALLBACK(mJsServices)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRACE_END
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(BluetoothDevice,
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(BluetoothDevice,
|
||||
nsDOMEventTargetHelper)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(BluetoothDevice,
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(BluetoothDevice,
|
||||
nsDOMEventTargetHelper)
|
||||
tmp->Unroot();
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
||||
@ -176,23 +175,16 @@ BluetoothDevice::Create(nsPIDOMWindow* aOwner,
|
||||
void
|
||||
BluetoothDevice::Notify(const BluetoothSignal& aData)
|
||||
{
|
||||
BluetoothValue v = aData.value();
|
||||
if (aData.name().EqualsLiteral("PropertyChanged")) {
|
||||
NS_ASSERTION(aData.value().type() == BluetoothValue::TArrayOfBluetoothNamedValue,
|
||||
NS_ASSERTION(v.type() == BluetoothValue::TArrayOfBluetoothNamedValue,
|
||||
"PropertyChanged: Invalid value type");
|
||||
InfallibleTArray<BluetoothNamedValue> arr(aData.value().get_ArrayOfBluetoothNamedValue());
|
||||
const InfallibleTArray<BluetoothNamedValue>& arr =
|
||||
v.get_ArrayOfBluetoothNamedValue();
|
||||
|
||||
NS_ASSERTION(arr.Length() == 1, "Got more than one property in a change message!");
|
||||
BluetoothNamedValue v = arr[0];
|
||||
nsString name = v.name();
|
||||
|
||||
SetPropertyByValue(v);
|
||||
if (name.EqualsLiteral("Connected")) {
|
||||
DispatchTrustedEvent(mConnected ? NS_LITERAL_STRING("connected")
|
||||
: NS_LITERAL_STRING("disconnected"));
|
||||
} else {
|
||||
nsRefPtr<BluetoothPropertyEvent> e = BluetoothPropertyEvent::Create(name);
|
||||
e->Dispatch(ToIDOMEventTarget(), NS_LITERAL_STRING("propertychanged"));
|
||||
}
|
||||
NS_ASSERTION(arr.Length() == 1,
|
||||
"Got more than one property in a change message!");
|
||||
SetPropertyByValue(arr[0]);
|
||||
} else {
|
||||
#ifdef DEBUG
|
||||
nsCString warningMsg;
|
||||
|
@ -1,51 +0,0 @@
|
||||
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
|
||||
/* vim: set ts=2 et sw=2 tw=80: */
|
||||
/* 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 "base/basictypes.h"
|
||||
#include "BluetoothPropertyEvent.h"
|
||||
|
||||
#include "nsDOMClassInfo.h"
|
||||
#include "mozilla/dom/bluetooth/BluetoothTypes.h"
|
||||
|
||||
USING_BLUETOOTH_NAMESPACE
|
||||
|
||||
// static
|
||||
already_AddRefed<BluetoothPropertyEvent>
|
||||
BluetoothPropertyEvent::Create(const nsAString& aPropertyName)
|
||||
{
|
||||
NS_ASSERTION(!aPropertyName.IsEmpty(), "Empty Property String!");
|
||||
|
||||
nsRefPtr<BluetoothPropertyEvent> event = new BluetoothPropertyEvent();
|
||||
|
||||
event->mPropertyName = aPropertyName;
|
||||
|
||||
return event.forget();
|
||||
}
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(BluetoothPropertyEvent,
|
||||
nsDOMEvent)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(BluetoothPropertyEvent,
|
||||
nsDOMEvent)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
||||
|
||||
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(BluetoothPropertyEvent)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIDOMBluetoothPropertyEvent)
|
||||
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(BluetoothPropertyEvent)
|
||||
NS_INTERFACE_MAP_END_INHERITING(nsDOMEvent)
|
||||
|
||||
NS_IMPL_ADDREF_INHERITED(BluetoothPropertyEvent, nsDOMEvent)
|
||||
NS_IMPL_RELEASE_INHERITED(BluetoothPropertyEvent, nsDOMEvent)
|
||||
|
||||
DOMCI_DATA(BluetoothPropertyEvent, BluetoothPropertyEvent)
|
||||
|
||||
NS_IMETHODIMP
|
||||
BluetoothPropertyEvent::GetProperty(nsAString& aPropertyName)
|
||||
{
|
||||
aPropertyName = mPropertyName;
|
||||
return NS_OK;
|
||||
}
|
@ -1,64 +0,0 @@
|
||||
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
|
||||
/* vim: set ts=2 et sw=2 tw=80: */
|
||||
/* 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/. */
|
||||
|
||||
#ifndef mozilla_dom_bluetooth_propertyevent_h__
|
||||
#define mozilla_dom_bluetooth_propertyevent_h__
|
||||
|
||||
#include "BluetoothCommon.h"
|
||||
|
||||
#include "nsIDOMBluetoothPropertyEvent.h"
|
||||
#include "nsIDOMEventTarget.h"
|
||||
|
||||
#include "nsDOMEvent.h"
|
||||
|
||||
BEGIN_BLUETOOTH_NAMESPACE
|
||||
|
||||
class BluetoothPropertyEvent : public nsDOMEvent
|
||||
, public nsIDOMBluetoothPropertyEvent
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
NS_FORWARD_TO_NSDOMEVENT
|
||||
NS_DECL_NSIDOMBLUETOOTHPROPERTYEVENT
|
||||
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(BluetoothPropertyEvent, nsDOMEvent)
|
||||
|
||||
static already_AddRefed<BluetoothPropertyEvent>
|
||||
Create(const nsAString& aPropertyName);
|
||||
|
||||
nsresult
|
||||
Dispatch(nsIDOMEventTarget* aTarget, const nsAString& aEventType)
|
||||
{
|
||||
NS_ASSERTION(aTarget, "Null pointer!");
|
||||
NS_ASSERTION(!aEventType.IsEmpty(), "Empty event type!");
|
||||
|
||||
nsresult rv = InitEvent(aEventType, false, false);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
SetTrusted(true);
|
||||
|
||||
nsDOMEvent* thisEvent = this;
|
||||
|
||||
bool dummy;
|
||||
rv = aTarget->DispatchEvent(thisEvent, &dummy);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
private:
|
||||
BluetoothPropertyEvent()
|
||||
: nsDOMEvent(nullptr, nullptr)
|
||||
{ }
|
||||
|
||||
~BluetoothPropertyEvent()
|
||||
{ }
|
||||
|
||||
nsString mPropertyName;
|
||||
};
|
||||
|
||||
END_BLUETOOTH_NAMESPACE
|
||||
|
||||
#endif
|
@ -44,7 +44,6 @@ CPPSRCS += \
|
||||
BluetoothManager.cpp \
|
||||
BluetoothAdapter.cpp \
|
||||
BluetoothDevice.cpp \
|
||||
BluetoothPropertyEvent.cpp \
|
||||
BluetoothReplyRunnable.cpp \
|
||||
BluetoothPropertyContainer.cpp \
|
||||
BluetoothUtils.cpp \
|
||||
@ -70,7 +69,6 @@ XPIDLSRCS = \
|
||||
nsIDOMBluetoothDevice.idl \
|
||||
nsIDOMBluetoothDeviceEvent.idl \
|
||||
nsIDOMBluetoothDeviceAddressEvent.idl \
|
||||
nsIDOMBluetoothPropertyEvent.idl \
|
||||
$(NULL)
|
||||
|
||||
ifeq (gonk,$(MOZ_WIDGET_TOOLKIT))
|
||||
|
@ -1,274 +0,0 @@
|
||||
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
|
||||
/* vim: set ts=2 et sw=2 tw=80: */
|
||||
/*
|
||||
** 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.
|
||||
*/
|
||||
|
||||
#include "BluetoothUtils.h"
|
||||
|
||||
#include <cstdio>
|
||||
#include <dbus/dbus.h>
|
||||
|
||||
#include "nsAutoPtr.h"
|
||||
#include "nsThreadUtils.h"
|
||||
#include "nsDebug.h"
|
||||
#include "nsClassHashtable.h"
|
||||
#include "mozilla/ipc/DBusUtils.h"
|
||||
#include "mozilla/ipc/RawDBusConnection.h"
|
||||
|
||||
|
||||
using namespace mozilla::ipc;
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
namespace bluetooth {
|
||||
|
||||
static nsAutoPtr<RawDBusConnection> sDBusConnection;
|
||||
|
||||
#undef LOG
|
||||
#if defined(MOZ_WIDGET_GONK)
|
||||
#include <android/log.h>
|
||||
#define LOG(args...) __android_log_print(ANDROID_LOG_INFO, "GonkDBus", args);
|
||||
#else
|
||||
#define BTDEBUG true
|
||||
#define LOG(args...) if (BTDEBUG) printf(args);
|
||||
#endif
|
||||
|
||||
#define DBUS_ADAPTER_IFACE BLUEZ_DBUS_BASE_IFC ".Adapter"
|
||||
#define DBUS_DEVICE_IFACE BLUEZ_DBUS_BASE_IFC ".Device"
|
||||
#define BLUEZ_DBUS_BASE_PATH "/org/bluez"
|
||||
#define BLUEZ_DBUS_BASE_IFC "org.bluez"
|
||||
#define BLUEZ_ERROR_IFC "org.bluez.Error"
|
||||
|
||||
static const char* BLUETOOTH_DBUS_SIGNALS[] =
|
||||
{
|
||||
"type='signal',interface='org.freedesktop.DBus'",
|
||||
"type='signal',interface='org.bluez.Adapter'",
|
||||
"type='signal',interface='org.bluez.Manager'",
|
||||
"type='signal',interface='org.bluez.Device'",
|
||||
"type='signal',interface='org.bluez.Input'",
|
||||
"type='signal',interface='org.bluez.Network'",
|
||||
"type='signal',interface='org.bluez.NetworkServer'",
|
||||
"type='signal',interface='org.bluez.HealthDevice'",
|
||||
"type='signal',interface='org.bluez.AudioSink'"
|
||||
};
|
||||
|
||||
typedef nsClassHashtable<nsCStringHashKey, BluetoothEventObserverList >
|
||||
BluetoothEventObserverTable;
|
||||
static nsAutoPtr<BluetoothEventObserverTable> sBluetoothEventObserverTable;
|
||||
|
||||
nsresult
|
||||
RegisterBluetoothEventHandler(const nsCString& aNodeName,
|
||||
BluetoothEventObserver* aHandler)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
BluetoothEventObserverList *ol;
|
||||
|
||||
NS_ENSURE_TRUE(sBluetoothEventObserverTable, NS_ERROR_FAILURE);
|
||||
if (!sBluetoothEventObserverTable->Get(aNodeName, &ol)) {
|
||||
sBluetoothEventObserverTable->Put(aNodeName,
|
||||
new BluetoothEventObserverList());
|
||||
}
|
||||
sBluetoothEventObserverTable->Get(aNodeName, &ol);
|
||||
ol->AddObserver(aHandler);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
UnregisterBluetoothEventHandler(const nsCString& aNodeName,
|
||||
BluetoothEventObserver* aHandler)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
BluetoothEventObserverList *ol;
|
||||
|
||||
NS_ENSURE_TRUE(sBluetoothEventObserverTable, NS_ERROR_FAILURE);
|
||||
if (!sBluetoothEventObserverTable->Get(aNodeName, &ol)) {
|
||||
NS_WARNING("Node does not exist to remove BluetoothEventListener from!");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
sBluetoothEventObserverTable->Get(aNodeName, &ol);
|
||||
ol->RemoveObserver(aHandler);
|
||||
if (ol->Length() == 0) {
|
||||
sBluetoothEventObserverTable->Remove(aNodeName);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
struct DistributeDBusMessageTask : public nsRunnable {
|
||||
|
||||
DistributeDBusMessageTask(DBusMessage* aMsg) : mMsg(aMsg)
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMETHOD Run()
|
||||
{
|
||||
if (dbus_message_get_path(mMsg.get()) == NULL) {
|
||||
return NS_OK;
|
||||
}
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
// Notify observers that a message has been sent
|
||||
nsDependentCString path(dbus_message_get_path(mMsg.get()));
|
||||
nsDependentCString member(dbus_message_get_member(mMsg.get()));
|
||||
BluetoothEventObserverList *ol;
|
||||
if (!sBluetoothEventObserverTable->Get(path, &ol)) {
|
||||
LOG("No objects registered for %s, returning\n",
|
||||
dbus_message_get_path(mMsg.get()));
|
||||
return NS_OK;
|
||||
}
|
||||
BluetoothEvent e;
|
||||
e.mEventName = member;
|
||||
ol->Broadcast(e);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
DBusMessageRefPtr mMsg;
|
||||
};
|
||||
|
||||
// Called by dbus during WaitForAndDispatchEventNative()
|
||||
// This function is called on the IOThread
|
||||
static DBusHandlerResult
|
||||
EventFilter(DBusConnection *aConn, DBusMessage *aMsg,
|
||||
void *aData)
|
||||
{
|
||||
DBusError err;
|
||||
|
||||
dbus_error_init(&err);
|
||||
|
||||
if (dbus_message_get_type(aMsg) != DBUS_MESSAGE_TYPE_SIGNAL) {
|
||||
LOG("%s: not interested (not a signal).\n", __FUNCTION__);
|
||||
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
|
||||
}
|
||||
|
||||
LOG("%s: Received signal %s:%s from %s\n", __FUNCTION__,
|
||||
dbus_message_get_interface(aMsg), dbus_message_get_member(aMsg),
|
||||
dbus_message_get_path(aMsg));
|
||||
|
||||
// TODO: Parse DBusMessage* on the IOThread and return as a BluetoothEvent so
|
||||
// we aren't passing the pointer at all, as well as offloading parsing (not
|
||||
// that it's that heavy.)
|
||||
nsCOMPtr<DistributeDBusMessageTask> t(new DistributeDBusMessageTask(aMsg));
|
||||
if (NS_FAILED(NS_DispatchToMainThread(t))) {
|
||||
NS_WARNING("Failed to dispatch to main thread!");
|
||||
}
|
||||
|
||||
return DBUS_HANDLER_RESULT_HANDLED;
|
||||
}
|
||||
|
||||
nsresult
|
||||
StartBluetoothConnection()
|
||||
{
|
||||
if (sDBusConnection) {
|
||||
NS_WARNING("DBusConnection already established, skipping");
|
||||
return NS_OK;
|
||||
}
|
||||
sBluetoothEventObserverTable = new BluetoothEventObserverTable();
|
||||
sBluetoothEventObserverTable->Init(100);
|
||||
|
||||
sDBusConnection = new RawDBusConnection();
|
||||
sDBusConnection->EstablishDBusConnection();
|
||||
|
||||
// Add a filter for all incoming messages_base
|
||||
if (!dbus_connection_add_filter(sDBusConnection->mConnection, EventFilter,
|
||||
NULL, NULL)) {
|
||||
NS_WARNING("Cannot create DBus Event Filter for DBus Thread!");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
StopBluetoothConnection()
|
||||
{
|
||||
if (!sDBusConnection) {
|
||||
NS_WARNING("DBusConnection does not exist, nothing to stop, skipping.");
|
||||
return NS_OK;
|
||||
}
|
||||
dbus_connection_remove_filter(sDBusConnection->mConnection, EventFilter, NULL);
|
||||
sDBusConnection = NULL;
|
||||
sBluetoothEventObserverTable->Clear();
|
||||
sBluetoothEventObserverTable = NULL;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
GetDefaultAdapterPathInternal(nsCString& aAdapterPath)
|
||||
{
|
||||
DBusMessage *msg = NULL, *reply = NULL;
|
||||
DBusError err;
|
||||
const char *device_path = NULL;
|
||||
int attempt = 0;
|
||||
|
||||
for (attempt = 0; attempt < 1000 && reply == NULL; attempt ++) {
|
||||
msg = dbus_message_new_method_call("org.bluez", "/",
|
||||
"org.bluez.Manager", "DefaultAdapter");
|
||||
if (!msg) {
|
||||
LOG("%s: Can't allocate new method call for get_adapter_path!",
|
||||
__FUNCTION__);
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
dbus_message_append_args(msg, DBUS_TYPE_INVALID);
|
||||
dbus_error_init(&err);
|
||||
reply = dbus_connection_send_with_reply_and_block(
|
||||
sDBusConnection->mConnection, msg, -1, &err);
|
||||
|
||||
if (!reply) {
|
||||
if (dbus_error_is_set(&err)) {
|
||||
if (dbus_error_has_name(&err,
|
||||
"org.freedesktop.DBus.Error.ServiceUnknown")) {
|
||||
// bluetoothd is still down, retry
|
||||
LOG("Service unknown\n");
|
||||
dbus_error_free(&err);
|
||||
//usleep(10000); // 10 ms
|
||||
continue;
|
||||
} else if (dbus_error_has_name(&err,
|
||||
"org.bluez.Error.NoSuchAdapter")) {
|
||||
LOG("No adapter found\n");
|
||||
dbus_error_free(&err);
|
||||
goto failed;
|
||||
} else {
|
||||
// Some other error we weren't expecting
|
||||
LOG("other error\n");
|
||||
dbus_error_free(&err);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (attempt == 1000) {
|
||||
LOG("timeout\n");
|
||||
//printfE("Time out while trying to get Adapter path, is bluetoothd up ?");
|
||||
goto failed;
|
||||
}
|
||||
|
||||
if (!dbus_message_get_args(reply, &err, DBUS_TYPE_OBJECT_PATH,
|
||||
&device_path, DBUS_TYPE_INVALID)
|
||||
|| !device_path) {
|
||||
if (dbus_error_is_set(&err)) {
|
||||
dbus_error_free(&err);
|
||||
}
|
||||
goto failed;
|
||||
}
|
||||
dbus_message_unref(msg);
|
||||
aAdapterPath = nsDependentCString(device_path);
|
||||
return NS_OK;
|
||||
failed:
|
||||
dbus_message_unref(msg);
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
|
||||
/* vim: set ts=2 et sw=2 tw=80: */
|
||||
/* 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 "nsIDOMEvent.idl"
|
||||
|
||||
[scriptable, builtinclass, uuid(ce268e66-2d1a-491a-833c-fb27dc50dc46)]
|
||||
interface nsIDOMBluetoothPropertyEvent : nsIDOMEvent
|
||||
{
|
||||
readonly attribute DOMString property;
|
||||
};
|
Loading…
Reference in New Issue
Block a user