Bumping gaia.json for 4 gaia revision(s) a=gaia-bump
[gecko.git] / dom / bluetooth2 / BluetoothDevice.h
blob7c290e300e5cfbc181c9c2a66c65108716b1cc93
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"
14 #include "nsString.h"
15 #include "nsCOMPtr.h"
17 namespace mozilla {
18 namespace dom {
19 class Promise;
23 BEGIN_BLUETOOTH_NAMESPACE
25 class BluetoothClassOfDevice;
26 class BluetoothNamedValue;
27 class BluetoothValue;
28 class BluetoothSignal;
29 class BluetoothSocket;
31 class BluetoothDevice MOZ_FINAL : public DOMEventTargetHelper
32 , public BluetoothSignalObserver
34 public:
35 NS_DECL_ISUPPORTS_INHERITED
36 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(BluetoothDevice,
37 DOMEventTargetHelper)
39 /****************************************************************************
40 * Attribute Getters
41 ***************************************************************************/
42 void GetAddress(nsString& aAddress) const
44 aAddress = mAddress;
47 BluetoothClassOfDevice* Cod() const
49 return mCod;
52 void GetName(nsString& aName) const
54 aName = mName;
57 bool Paired() const
59 return mPaired;
62 void GetUuids(nsTArray<nsString>& aUuids) const
64 aUuids = mUuids;
67 BluetoothDeviceType Type() const
69 return mType;
72 /****************************************************************************
73 * Event Handlers
74 ***************************************************************************/
75 IMPL_EVENT_HANDLER(attributechanged);
77 /****************************************************************************
78 * Methods (Web API Implementation)
79 ***************************************************************************/
80 already_AddRefed<Promise> FetchUuids(ErrorResult& aRv);
82 /****************************************************************************
83 * Others
84 ***************************************************************************/
85 static already_AddRefed<BluetoothDevice>
86 Create(nsPIDOMWindow* aOwner, const BluetoothValue& aValue);
88 void Notify(const BluetoothSignal& aParam); // BluetoothSignalObserver
89 nsPIDOMWindow* GetParentObject() const
91 return GetOwner();
94 virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE;
95 virtual void DisconnectFromOwner() MOZ_OVERRIDE;
97 /**
98 * Override operator== for device comparison
100 bool operator==(BluetoothDevice& aDevice) const
102 nsString address;
103 aDevice.GetAddress(address);
104 return mAddress.Equals(address);
107 private:
108 BluetoothDevice(nsPIDOMWindow* aOwner, const BluetoothValue& aValue);
109 ~BluetoothDevice();
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 /****************************************************************************
155 * Variables
156 ***************************************************************************/
158 * BD address of this device.
160 nsString mAddress;
163 * Class of device (CoD) that describes this device's capabilities.
165 nsRefPtr<BluetoothClassOfDevice> mCod;
168 * Human-readable name of this device.
170 nsString mName;
173 * Whether this device is paired or not.
175 bool mPaired;
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
190 #endif