2014-05-20 23:11:31 -07:00
|
|
|
/* -*- 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_bluetoothdevice_h__
|
|
|
|
#define mozilla_dom_bluetooth_bluetoothdevice_h__
|
|
|
|
|
|
|
|
#include "mozilla/Attributes.h"
|
|
|
|
#include "mozilla/DOMEventTargetHelper.h"
|
2014-07-13 19:47:19 -07:00
|
|
|
#include "mozilla/dom/BluetoothDevice2Binding.h"
|
2014-05-20 23:11:31 -07:00
|
|
|
#include "BluetoothCommon.h"
|
|
|
|
#include "nsString.h"
|
2014-07-13 19:47:19 -07:00
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
class Promise;
|
|
|
|
}
|
|
|
|
}
|
2014-05-20 23:11:31 -07:00
|
|
|
|
|
|
|
BEGIN_BLUETOOTH_NAMESPACE
|
|
|
|
|
2014-07-13 19:47:19 -07:00
|
|
|
class BluetoothClassOfDevice;
|
2014-05-20 23:11:31 -07:00
|
|
|
class BluetoothNamedValue;
|
|
|
|
class BluetoothValue;
|
|
|
|
class BluetoothSignal;
|
|
|
|
class BluetoothSocket;
|
|
|
|
|
2014-07-13 19:47:19 -07:00
|
|
|
class BluetoothDevice MOZ_FINAL : public DOMEventTargetHelper
|
|
|
|
, public BluetoothSignalObserver
|
2014-05-20 23:11:31 -07:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
2014-07-13 19:47:19 -07:00
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(BluetoothDevice,
|
|
|
|
DOMEventTargetHelper)
|
2014-05-20 23:11:31 -07:00
|
|
|
|
2014-09-02 03:31:18 -07:00
|
|
|
/****************************************************************************
|
|
|
|
* Attribute Getters
|
|
|
|
***************************************************************************/
|
2014-05-20 23:11:31 -07:00
|
|
|
void GetAddress(nsString& aAddress) const
|
|
|
|
{
|
|
|
|
aAddress = mAddress;
|
|
|
|
}
|
|
|
|
|
2014-07-13 19:47:19 -07:00
|
|
|
BluetoothClassOfDevice* Cod() const
|
2014-05-20 23:11:31 -07:00
|
|
|
{
|
2014-07-13 19:47:19 -07:00
|
|
|
return mCod;
|
2014-05-20 23:11:31 -07:00
|
|
|
}
|
|
|
|
|
2014-07-13 19:47:19 -07:00
|
|
|
void GetName(nsString& aName) const
|
2014-05-20 23:11:31 -07:00
|
|
|
{
|
2014-07-13 19:47:19 -07:00
|
|
|
aName = mName;
|
2014-05-20 23:11:31 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Paired() const
|
|
|
|
{
|
|
|
|
return mPaired;
|
|
|
|
}
|
|
|
|
|
2014-09-02 03:31:18 -07:00
|
|
|
void GetUuids(nsTArray<nsString>& aUuids) const
|
|
|
|
{
|
2014-07-13 19:47:19 -07:00
|
|
|
aUuids = mUuids;
|
2014-05-20 23:11:31 -07:00
|
|
|
}
|
|
|
|
|
2014-09-10 19:04:18 -07:00
|
|
|
BluetoothDeviceType Type() const
|
|
|
|
{
|
|
|
|
return mType;
|
|
|
|
}
|
|
|
|
|
2014-09-02 03:31:18 -07:00
|
|
|
/****************************************************************************
|
|
|
|
* Event Handlers
|
|
|
|
***************************************************************************/
|
|
|
|
IMPL_EVENT_HANDLER(attributechanged);
|
2014-07-13 19:47:19 -07:00
|
|
|
|
2014-09-02 03:31:18 -07:00
|
|
|
/****************************************************************************
|
|
|
|
* Methods (Web API Implementation)
|
|
|
|
***************************************************************************/
|
|
|
|
already_AddRefed<Promise> FetchUuids(ErrorResult& aRv);
|
2014-07-13 19:47:19 -07:00
|
|
|
|
2014-09-02 03:31:18 -07:00
|
|
|
/****************************************************************************
|
|
|
|
* Others
|
|
|
|
***************************************************************************/
|
|
|
|
static already_AddRefed<BluetoothDevice>
|
|
|
|
Create(nsPIDOMWindow* aOwner, const BluetoothValue& aValue);
|
2014-05-20 23:11:31 -07:00
|
|
|
|
2014-09-02 03:31:18 -07:00
|
|
|
void Notify(const BluetoothSignal& aParam); // BluetoothSignalObserver
|
2014-05-20 23:11:31 -07:00
|
|
|
nsPIDOMWindow* GetParentObject() const
|
|
|
|
{
|
|
|
|
return GetOwner();
|
|
|
|
}
|
|
|
|
|
2014-07-13 19:47:19 -07:00
|
|
|
virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE;
|
2014-05-20 23:11:31 -07:00
|
|
|
virtual void DisconnectFromOwner() MOZ_OVERRIDE;
|
|
|
|
|
2014-09-02 03:31:18 -07:00
|
|
|
/**
|
|
|
|
* Override operator== for device comparison
|
|
|
|
*/
|
|
|
|
bool operator==(BluetoothDevice& aDevice) const
|
|
|
|
{
|
|
|
|
nsString address;
|
|
|
|
aDevice.GetAddress(address);
|
|
|
|
return mAddress.Equals(address);
|
|
|
|
}
|
|
|
|
|
2014-05-20 23:11:31 -07:00
|
|
|
private:
|
2014-06-24 00:31:10 -07:00
|
|
|
BluetoothDevice(nsPIDOMWindow* aOwner, const BluetoothValue& aValue);
|
2014-05-20 23:11:31 -07:00
|
|
|
~BluetoothDevice();
|
|
|
|
|
2014-09-02 03:31:18 -07:00
|
|
|
/**
|
|
|
|
* Set device properties according to properties array
|
|
|
|
*
|
|
|
|
* @param aValue [in] Properties array to set with
|
|
|
|
*/
|
|
|
|
void SetPropertyByValue(const BluetoothNamedValue& aValue);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle "PropertyChanged" bluetooth signal.
|
|
|
|
*
|
|
|
|
* @param aValue [in] Array of changed properties
|
|
|
|
*/
|
|
|
|
void HandlePropertyChanged(const BluetoothValue& aValue);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Fire BluetoothAttributeEvent to trigger onattributechanged event handler.
|
|
|
|
*/
|
|
|
|
void DispatchAttributeEvent(const nsTArray<nsString>& aTypes);
|
|
|
|
|
2014-09-10 19:04:18 -07:00
|
|
|
/**
|
|
|
|
* Convert uint32_t to BluetoothDeviceType.
|
|
|
|
*
|
|
|
|
* @param aValue [in] uint32_t to convert
|
|
|
|
*/
|
|
|
|
BluetoothDeviceType ConvertUint32ToDeviceType(const uint32_t aValue);
|
|
|
|
|
2014-09-02 03:31:18 -07:00
|
|
|
/**
|
|
|
|
* Convert string to BluetoothDeviceAttribute.
|
|
|
|
*
|
|
|
|
* @param aString [in] String to convert
|
|
|
|
*/
|
|
|
|
BluetoothDeviceAttribute
|
|
|
|
ConvertStringToDeviceAttribute(const nsAString& aString);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check whether value of given device property has changed.
|
|
|
|
*
|
|
|
|
* @param aType [in] Device property to check
|
|
|
|
* @param aValue [in] New value of the device property
|
|
|
|
*/
|
|
|
|
bool IsDeviceAttributeChanged(BluetoothDeviceAttribute aType,
|
|
|
|
const BluetoothValue& aValue);
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Variables
|
|
|
|
***************************************************************************/
|
|
|
|
/**
|
|
|
|
* BD address of this device.
|
|
|
|
*/
|
2014-05-20 23:11:31 -07:00
|
|
|
nsString mAddress;
|
2014-09-02 03:31:18 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Class of device (CoD) that describes this device's capabilities.
|
|
|
|
*/
|
2014-07-13 19:47:19 -07:00
|
|
|
nsRefPtr<BluetoothClassOfDevice> mCod;
|
2014-09-02 03:31:18 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Human-readable name of this device.
|
|
|
|
*/
|
2014-05-20 23:11:31 -07:00
|
|
|
nsString mName;
|
2014-09-02 03:31:18 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether this device is paired or not.
|
|
|
|
*/
|
2014-05-20 23:11:31 -07:00
|
|
|
bool mPaired;
|
|
|
|
|
2014-09-02 03:31:18 -07:00
|
|
|
/**
|
|
|
|
* Cached UUID list of services which this device provides.
|
|
|
|
*/
|
|
|
|
nsTArray<nsString> mUuids;
|
2014-09-10 19:04:18 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Type of this device. Can be unknown/classic/le/dual.
|
|
|
|
*/
|
|
|
|
BluetoothDeviceType mType;
|
2014-05-20 23:11:31 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
END_BLUETOOTH_NAMESPACE
|
|
|
|
|
|
|
|
#endif
|