1 /* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
2 /* vim: set ts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_dom_bluetooth_bluetoothdevice_h__
8 #define mozilla_dom_bluetooth_bluetoothdevice_h__
10 #include "mozilla/Attributes.h"
11 #include "mozilla/DOMEventTargetHelper.h"
12 #include "mozilla/dom/BluetoothDevice2Binding.h"
13 #include "BluetoothCommon.h"
23 BEGIN_BLUETOOTH_NAMESPACE
25 class BluetoothClassOfDevice
;
26 class BluetoothNamedValue
;
28 class BluetoothSignal
;
29 class BluetoothSocket
;
31 class BluetoothDevice MOZ_FINAL
: public DOMEventTargetHelper
32 , public BluetoothSignalObserver
35 NS_DECL_ISUPPORTS_INHERITED
36 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(BluetoothDevice
,
39 /****************************************************************************
41 ***************************************************************************/
42 void GetAddress(nsString
& aAddress
) const
47 BluetoothClassOfDevice
* Cod() const
52 void GetName(nsString
& aName
) const
62 void GetUuids(nsTArray
<nsString
>& aUuids
) const
67 BluetoothDeviceType
Type() const
72 /****************************************************************************
74 ***************************************************************************/
75 IMPL_EVENT_HANDLER(attributechanged
);
77 /****************************************************************************
78 * Methods (Web API Implementation)
79 ***************************************************************************/
80 already_AddRefed
<Promise
> FetchUuids(ErrorResult
& aRv
);
82 /****************************************************************************
84 ***************************************************************************/
85 static already_AddRefed
<BluetoothDevice
>
86 Create(nsPIDOMWindow
* aOwner
, const BluetoothValue
& aValue
);
88 void Notify(const BluetoothSignal
& aParam
); // BluetoothSignalObserver
89 nsPIDOMWindow
* GetParentObject() const
94 virtual JSObject
* WrapObject(JSContext
* aCx
) MOZ_OVERRIDE
;
95 virtual void DisconnectFromOwner() MOZ_OVERRIDE
;
98 * Override operator== for device comparison
100 bool operator==(BluetoothDevice
& aDevice
) const
103 aDevice
.GetAddress(address
);
104 return mAddress
.Equals(address
);
108 BluetoothDevice(nsPIDOMWindow
* aOwner
, const BluetoothValue
& aValue
);
112 * Set device properties according to properties array
114 * @param aValue [in] Properties array to set with
116 void SetPropertyByValue(const BluetoothNamedValue
& aValue
);
119 * Handle "PropertyChanged" bluetooth signal.
121 * @param aValue [in] Array of changed properties
123 void HandlePropertyChanged(const BluetoothValue
& aValue
);
126 * Fire BluetoothAttributeEvent to trigger onattributechanged event handler.
128 void DispatchAttributeEvent(const nsTArray
<nsString
>& aTypes
);
131 * Convert uint32_t to BluetoothDeviceType.
133 * @param aValue [in] uint32_t to convert
135 BluetoothDeviceType
ConvertUint32ToDeviceType(const uint32_t aValue
);
138 * Convert string to BluetoothDeviceAttribute.
140 * @param aString [in] String to convert
142 BluetoothDeviceAttribute
143 ConvertStringToDeviceAttribute(const nsAString
& aString
);
146 * Check whether value of given device property has changed.
148 * @param aType [in] Device property to check
149 * @param aValue [in] New value of the device property
151 bool IsDeviceAttributeChanged(BluetoothDeviceAttribute aType
,
152 const BluetoothValue
& aValue
);
154 /****************************************************************************
156 ***************************************************************************/
158 * BD address of this device.
163 * Class of device (CoD) that describes this device's capabilities.
165 nsRefPtr
<BluetoothClassOfDevice
> mCod
;
168 * Human-readable name of this device.
173 * Whether this device is paired or not.
178 * Cached UUID list of services which this device provides.
180 nsTArray
<nsString
> mUuids
;
183 * Type of this device. Can be unknown/classic/le/dual.
185 BluetoothDeviceType mType
;
188 END_BLUETOOTH_NAMESPACE