Bug 730990 - Device object boilerplate for DOM Bluetooth - r=qDot
authorEric Chou <echou@mozilla.com>
Fri, 23 Mar 2012 14:58:12 -0700
changeset 90207 4a9ebf972d27ebc93d84529a40b0dd5dfaa36933
parent 90206 c7850c2189c28aab0d5956f02d8bfa038e1fd1d1
child 90208 2b113540e75a445d08ab66122ee47aeaf676c444
push idunknown
push userunknown
push dateunknown
reviewersqDot
bugs730990
milestone14.0a1
Bug 730990 - Device object boilerplate for DOM Bluetooth - r=qDot
dom/base/nsDOMClassInfo.cpp
dom/base/nsDOMClassInfoClasses.h
dom/bluetooth/BluetoothDevice.cpp
dom/bluetooth/BluetoothDevice.h
dom/bluetooth/Makefile.in
dom/bluetooth/nsIDOMBluetoothDevice.idl
--- a/dom/base/nsDOMClassInfo.cpp
+++ b/dom/base/nsDOMClassInfo.cpp
@@ -521,16 +521,17 @@ using mozilla::dom::indexedDB::IDBWrappe
 #ifdef MOZ_B2G_RIL
 #include "Telephony.h"
 #include "TelephonyCall.h"
 #include "CallEvent.h"
 #endif
 
 #ifdef MOZ_B2G_BT
 #include "BluetoothAdapter.h"
+#include "BluetoothDevice.h"
 #endif
 
 #include "DOMError.h"
 #include "DOMRequest.h"
 
 using namespace mozilla;
 using namespace mozilla::dom;
 
@@ -1616,16 +1617,18 @@ static nsDOMClassInfoData sClassInfoData
                            EVENTTARGET_SCRIPTABLE_FLAGS)
   NS_DEFINE_CLASSINFO_DATA(CallEvent, nsDOMGenericSH,
                            DOM_DEFAULT_SCRIPTABLE_FLAGS)
 #endif
 
 #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,
                            DOM_DEFAULT_SCRIPTABLE_FLAGS)
 
   NS_DEFINE_CLASSINFO_DATA(DOMRequest, nsEventTargetSH,
                            EVENTTARGET_SCRIPTABLE_FLAGS)
 };
@@ -4369,16 +4372,20 @@ nsDOMClassInfo::Init()
     DOM_CLASSINFO_MAP_ENTRY(nsIDOMCallEvent)
     DOM_CLASSINFO_MAP_ENTRY(nsIDOMEvent)
   DOM_CLASSINFO_MAP_END
 #endif
 
 #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
 
   DOM_CLASSINFO_MAP_BEGIN(DOMError, nsIDOMDOMError)
     DOM_CLASSINFO_MAP_ENTRY(nsIDOMDOMError)
   DOM_CLASSINFO_MAP_END
 
   DOM_CLASSINFO_MAP_BEGIN(DOMRequest, nsIDOMDOMRequest)
--- a/dom/base/nsDOMClassInfoClasses.h
+++ b/dom/base/nsDOMClassInfoClasses.h
@@ -536,12 +536,13 @@ DOMCI_CLASS(CustomEvent)
 #ifdef MOZ_B2G_RIL
 DOMCI_CLASS(Telephony)
 DOMCI_CLASS(TelephonyCall)
 DOMCI_CLASS(CallEvent)
 #endif
 
 #ifdef MOZ_B2G_BT
 DOMCI_CLASS(BluetoothAdapter)
+DOMCI_CLASS(BluetoothDevice)
 #endif
 
 DOMCI_CLASS(DOMError)
 DOMCI_CLASS(DOMRequest)
new file mode 100644
--- /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)
new file mode 100644
--- /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<nsString> mUuids;
+
+  bool mTrusted;
+  nsString mAlias;
+
+  NS_DECL_EVENT_HANDLER(propertychanged)
+  NS_DECL_EVENT_HANDLER(disconnectrequested)
+};
+
+END_BLUETOOTH_NAMESPACE
+
+#endif
--- a/dom/bluetooth/Makefile.in
+++ b/dom/bluetooth/Makefile.in
@@ -14,17 +14,19 @@ LIBRARY_NAME     = dombluetooth_s
 XPIDL_MODULE     = dom_bluetooth
 LIBXUL_LIBRARY   = 1
 FORCE_STATIC_LIB = 1
 
 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
 
new file mode 100644
--- /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();
+};