From 85cd3d3dead597970b362e46bef5b96875979445 Mon Sep 17 00:00:00 2001 From: Eric Chou Date: Fri, 23 Mar 2012 14:58:12 -0700 Subject: [PATCH] Bug 730990 - Device object boilerplate for DOM Bluetooth - r=qDot --- dom/base/nsDOMClassInfo.cpp | 7 ++ dom/base/nsDOMClassInfoClasses.h | 1 + dom/bluetooth/BluetoothDevice.cpp | 154 ++++++++++++++++++++++++ dom/bluetooth/BluetoothDevice.h | 48 ++++++++ dom/bluetooth/Makefile.in | 2 + dom/bluetooth/nsIDOMBluetoothDevice.idl | 30 +++++ 6 files changed, 242 insertions(+) create mode 100644 dom/bluetooth/BluetoothDevice.cpp create mode 100644 dom/bluetooth/BluetoothDevice.h create mode 100644 dom/bluetooth/nsIDOMBluetoothDevice.idl diff --git a/dom/base/nsDOMClassInfo.cpp b/dom/base/nsDOMClassInfo.cpp index de9847d9533..d8787f7532c 100644 --- a/dom/base/nsDOMClassInfo.cpp +++ b/dom/base/nsDOMClassInfo.cpp @@ -526,6 +526,7 @@ using mozilla::dom::indexedDB::IDBWrapperCache; #ifdef MOZ_B2G_BT #include "BluetoothAdapter.h" +#include "BluetoothDevice.h" #endif #include "DOMError.h" @@ -1621,6 +1622,8 @@ static nsDOMClassInfoData sClassInfoData[] = { #ifdef MOZ_B2G_BT NS_DEFINE_CLASSINFO_DATA(BluetoothAdapter, nsEventTargetSH, EVENTTARGET_SCRIPTABLE_FLAGS) + NS_DEFINE_CLASSINFO_DATA(BluetoothDevice, nsEventTargetSH, + EVENTTARGET_SCRIPTABLE_FLAGS) #endif NS_DEFINE_CLASSINFO_DATA(DOMError, nsDOMGenericSH, @@ -4374,6 +4377,10 @@ nsDOMClassInfo::Init() #ifdef MOZ_B2G_BT 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 #endif diff --git a/dom/base/nsDOMClassInfoClasses.h b/dom/base/nsDOMClassInfoClasses.h index da29bb7aca9..e63173b5730 100644 --- a/dom/base/nsDOMClassInfoClasses.h +++ b/dom/base/nsDOMClassInfoClasses.h @@ -541,6 +541,7 @@ DOMCI_CLASS(CallEvent) #ifdef MOZ_B2G_BT DOMCI_CLASS(BluetoothAdapter) +DOMCI_CLASS(BluetoothDevice) #endif DOMCI_CLASS(DOMError) diff --git a/dom/bluetooth/BluetoothDevice.cpp b/dom/bluetooth/BluetoothDevice.cpp new file mode 100644 index 00000000000..8cd741e9408 --- /dev/null +++ b/dom/bluetooth/BluetoothDevice.cpp @@ -0,0 +1,154 @@ +/* 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 "BluetoothDevice.h" +#include "nsDOMClassInfo.h" + +USING_BLUETOOTH_NAMESPACE + +DOMCI_DATA(BluetoothDevice, BluetoothDevice) + +NS_IMPL_CYCLE_COLLECTION_CLASS(BluetoothDevice) + +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(BluetoothDevice, + nsDOMEventTargetHelper) + NS_CYCLE_COLLECTION_TRAVERSE_EVENT_HANDLER(propertychanged) + NS_CYCLE_COLLECTION_TRAVERSE_EVENT_HANDLER(disconnectrequested) +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END + +NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(BluetoothDevice, + nsDOMEventTargetHelper) + NS_CYCLE_COLLECTION_UNLINK_EVENT_HANDLER(propertychanged) + NS_CYCLE_COLLECTION_UNLINK_EVENT_HANDLER(disconnectrequested) +NS_IMPL_CYCLE_COLLECTION_UNLINK_END + +NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(BluetoothDevice) + NS_INTERFACE_MAP_ENTRY(nsIDOMBluetoothDevice) + NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMBluetoothDevice) + NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(BluetoothDevice) +NS_INTERFACE_MAP_END_INHERITING(nsDOMEventTargetHelper) + +NS_IMPL_ADDREF_INHERITED(BluetoothDevice, nsDOMEventTargetHelper) +NS_IMPL_RELEASE_INHERITED(BluetoothDevice, nsDOMEventTargetHelper) + +BluetoothDevice::BluetoothDevice() +{ +} + +nsresult +BluetoothDevice::GetAdapter(nsAString& aAdapter) +{ + aAdapter = mAdapter; + return NS_OK; +} + +nsresult +BluetoothDevice::GetAddress(nsAString& aAddress) +{ + aAddress = mAddress; + return NS_OK; +} + +nsresult +BluetoothDevice::GetName(nsAString& aName) +{ + aName = mName; + return NS_OK; +} + +nsresult +BluetoothDevice::GetClass(PRUint32* aClass) +{ + *aClass = mClass; + return NS_OK; +} + +nsresult +BluetoothDevice::GetConnected(bool* aConnected) +{ + *aConnected = mConnected; + return NS_OK; +} + +nsresult +BluetoothDevice::GetPaired(bool* aPaired) +{ + *aPaired = mPaired; + return NS_OK; +} + +nsresult +BluetoothDevice::GetLegacyPairing(bool* aLegacyPairing) +{ + *aLegacyPairing = mLegacyPairing; + return NS_OK; +} + +nsresult +BluetoothDevice::GetTrusted(bool* aTrusted) +{ + *aTrusted = mTrusted; + return NS_OK; +} + +nsresult +BluetoothDevice::SetTrusted(bool aTrusted) +{ + mTrusted = aTrusted; + return NS_OK; +} + +nsresult +BluetoothDevice::GetAlias(nsAString& aAlias) +{ + aAlias = mAlias; + return NS_OK; +} + +nsresult +BluetoothDevice::SetAlias(const nsAString& aAlias) +{ + mAlias = aAlias; + return NS_OK; +} + +nsresult +BluetoothDevice::GetUuids(jsval* aUuids) +{ + //TODO: convert mUuids to jsval and assign to aUuids; + return NS_OK; +} + +nsresult +BluetoothDevice::Disconnect() +{ + return NS_OK; +} + +nsresult +BluetoothDevice::GetProperties(jsval* aProperties) +{ + return NS_OK; +} + +nsresult +BluetoothDevice::SetProperty(const nsAString& aName, const nsAString& aValue) +{ + return NS_OK; +} + +nsresult +BluetoothDevice::DiscoverServices(const nsAString& aPattern, jsval* aServices) +{ + return NS_OK; +} + +nsresult +BluetoothDevice::CancelDiscovery() +{ + return NS_OK; +} + +NS_IMPL_EVENT_HANDLER(BluetoothDevice, propertychanged) +NS_IMPL_EVENT_HANDLER(BluetoothDevice, disconnectrequested) diff --git a/dom/bluetooth/BluetoothDevice.h b/dom/bluetooth/BluetoothDevice.h new file mode 100644 index 00000000000..d0d45430576 --- /dev/null +++ b/dom/bluetooth/BluetoothDevice.h @@ -0,0 +1,48 @@ +/* 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_bluetoothdevice_h__ +#define mozilla_dom_bluetooth_bluetoothdevice_h__ + +#include "BluetoothCommon.h" +#include "nsDOMEventTargetHelper.h" +#include "nsIDOMBluetoothDevice.h" +#include "nsString.h" + +BEGIN_BLUETOOTH_NAMESPACE + +class BluetoothDevice : public nsIDOMBluetoothDevice + , public nsDOMEventTargetHelper +{ +public: + NS_DECL_ISUPPORTS + NS_DECL_NSIDOMBLUETOOTHDEVICE + + NS_FORWARD_NSIDOMEVENTTARGET(nsDOMEventTargetHelper::) + + NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(BluetoothDevice, + nsDOMEventTargetHelper) + + BluetoothDevice(); + +protected: + nsString mAdapter; + nsString mAddress; + PRUint32 mClass; + bool mConnected; + bool mLegacyPairing; + nsString mName; + bool mPaired; + nsTArray mUuids; + + bool mTrusted; + nsString mAlias; + + NS_DECL_EVENT_HANDLER(propertychanged) + NS_DECL_EVENT_HANDLER(disconnectrequested) +}; + +END_BLUETOOTH_NAMESPACE + +#endif diff --git a/dom/bluetooth/Makefile.in b/dom/bluetooth/Makefile.in index 7d782e5356c..46860f2af56 100644 --- a/dom/bluetooth/Makefile.in +++ b/dom/bluetooth/Makefile.in @@ -19,11 +19,13 @@ include $(topsrcdir)/dom/dom-config.mk CPPSRCS = \ BluetoothAdapter.cpp \ + BluetoothDevice.cpp \ $(NULL) XPIDLSRCS = \ nsIDOMNavigatorBluetooth.idl \ nsIDOMBluetoothAdapter.idl \ + nsIDOMBluetoothDevice.idl \ $(NULL) include $(topsrcdir)/config/rules.mk diff --git a/dom/bluetooth/nsIDOMBluetoothDevice.idl b/dom/bluetooth/nsIDOMBluetoothDevice.idl new file mode 100644 index 00000000000..ae79dded421 --- /dev/null +++ b/dom/bluetooth/nsIDOMBluetoothDevice.idl @@ -0,0 +1,30 @@ +/* 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 "nsIDOMEventTarget.idl" + +[scriptable, builtinclass, uuid(2da61f89-a7d2-4f7d-9f4c-fb8a99d9add2)] +interface nsIDOMBluetoothDevice : nsIDOMEventTarget +{ + readonly attribute DOMString adapter; + readonly attribute DOMString address; + readonly attribute unsigned long class; + readonly attribute boolean connected; + readonly attribute boolean legacyPairing; + readonly attribute DOMString name; + readonly attribute boolean paired; + readonly attribute jsval uuids; + + attribute boolean trusted; + attribute DOMString alias; + + attribute nsIDOMEventListener onpropertychanged; + attribute nsIDOMEventListener ondisconnectrequested; + + void disconnect(); + jsval getProperties(); + void setProperty(in DOMString name, in DOMString value); + jsval discoverServices(in DOMString pattern); + void cancelDiscovery(); +};