Bug 730990 - Device object boilerplate for DOM Bluetooth - r=qDot

This commit is contained in:
Eric Chou 2012-03-23 14:58:12 -07:00
parent 9e86abdcfe
commit 85cd3d3dea
6 changed files with 242 additions and 0 deletions

View File

@ -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

View File

@ -541,6 +541,7 @@ DOMCI_CLASS(CallEvent)
#ifdef MOZ_B2G_BT
DOMCI_CLASS(BluetoothAdapter)
DOMCI_CLASS(BluetoothDevice)
#endif
DOMCI_CLASS(DOMError)

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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();
};