Bumping manifests a=b2g-bump
[gecko.git] / dom / bluetooth2 / BluetoothAdapter.h
blob57458aa3f69901edace307855107a3c6367c58c3
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_bluetoothadapter_h__
8 #define mozilla_dom_bluetooth_bluetoothadapter_h__
10 #include "mozilla/Attributes.h"
11 #include "mozilla/DOMEventTargetHelper.h"
12 #include "mozilla/dom/BluetoothAdapter2Binding.h"
13 #include "mozilla/dom/BluetoothDeviceEvent.h"
14 #include "mozilla/dom/Promise.h"
15 #include "BluetoothCommon.h"
16 #include "nsCOMPtr.h"
18 namespace mozilla {
19 namespace dom {
20 class DOMRequest;
21 struct MediaMetaData;
22 struct MediaPlayStatus;
26 BEGIN_BLUETOOTH_NAMESPACE
28 class BluetoothDevice;
29 class BluetoothDiscoveryHandle;
30 class BluetoothSignal;
31 class BluetoothNamedValue;
32 class BluetoothPairingListener;
33 class BluetoothValue;
35 class BluetoothAdapter : public DOMEventTargetHelper
36 , public BluetoothSignalObserver
38 public:
39 NS_DECL_ISUPPORTS_INHERITED
41 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(BluetoothAdapter,
42 DOMEventTargetHelper)
44 static already_AddRefed<BluetoothAdapter>
45 Create(nsPIDOMWindow* aOwner, const BluetoothValue& aValue);
47 void Notify(const BluetoothSignal& aParam);
49 void SetPropertyByValue(const BluetoothNamedValue& aValue);
51 virtual void DisconnectFromOwner() MOZ_OVERRIDE;
53 BluetoothAdapterState State() const
55 return mState;
58 void GetAddress(nsString& aAddress) const
60 aAddress = mAddress;
63 void
64 GetName(nsString& aName) const
66 aName = mName;
69 bool
70 Discovering() const
72 return mDiscovering;
75 bool
76 Discoverable() const
78 return mDiscoverable;
81 BluetoothPairingListener* PairingReqs() const
83 return mPairingReqs;
86 /**
87 * Update this adapter's discovery handle in use (mDiscoveryHandleInUse).
89 * |mDiscoveryHandleInUse| is set to the latest discovery handle when adapter
90 * just starts discovery, and is reset to nullptr when discovery is stopped
91 * by some adapter.
93 * @param aDiscoveryHandle [in] the discovery handle to set.
95 void SetDiscoveryHandleInUse(BluetoothDiscoveryHandle* aDiscoveryHandle);
97 already_AddRefed<Promise> SetName(const nsAString& aName, ErrorResult& aRv);
98 already_AddRefed<Promise>
99 SetDiscoverable(bool aDiscoverable, ErrorResult& aRv);
100 already_AddRefed<Promise> StartDiscovery(ErrorResult& aRv);
101 already_AddRefed<Promise> StopDiscovery(ErrorResult& aRv);
103 already_AddRefed<Promise>
104 Pair(const nsAString& aDeviceAddress, ErrorResult& aRv);
105 already_AddRefed<Promise>
106 Unpair(const nsAString& aDeviceAddress, ErrorResult& aRv);
109 * Get a list of paired bluetooth devices.
111 * @param aDevices [out] Devices array to return
113 void GetPairedDevices(nsTArray<nsRefPtr<BluetoothDevice> >& aDevices);
115 already_AddRefed<Promise> EnableDisable(bool aEnable, ErrorResult& aRv);
116 already_AddRefed<Promise> Enable(ErrorResult& aRv);
117 already_AddRefed<Promise> Disable(ErrorResult& aRv);
119 already_AddRefed<DOMRequest>
120 Connect(BluetoothDevice& aDevice,
121 const Optional<short unsigned int>& aServiceUuid, ErrorResult& aRv);
122 already_AddRefed<DOMRequest>
123 Disconnect(BluetoothDevice& aDevice,
124 const Optional<short unsigned int>& aServiceUuid,
125 ErrorResult& aRv);
126 already_AddRefed<DOMRequest>
127 GetConnectedDevices(uint16_t aServiceUuid, ErrorResult& aRv);
129 already_AddRefed<DOMRequest>
130 SendFile(const nsAString& aDeviceAddress, nsIDOMBlob* aBlob,
131 ErrorResult& aRv);
132 already_AddRefed<DOMRequest>
133 StopSendingFile(const nsAString& aDeviceAddress, ErrorResult& aRv);
134 already_AddRefed<DOMRequest>
135 ConfirmReceivingFile(const nsAString& aDeviceAddress, bool aConfirmation,
136 ErrorResult& aRv);
138 already_AddRefed<DOMRequest> ConnectSco(ErrorResult& aRv);
139 already_AddRefed<DOMRequest> DisconnectSco(ErrorResult& aRv);
140 already_AddRefed<DOMRequest> IsScoConnected(ErrorResult& aRv);
142 already_AddRefed<DOMRequest> AnswerWaitingCall(ErrorResult& aRv);
143 already_AddRefed<DOMRequest> IgnoreWaitingCall(ErrorResult& aRv);
144 already_AddRefed<DOMRequest> ToggleCalls(ErrorResult& aRv);
146 already_AddRefed<DOMRequest>
147 SendMediaMetaData(const MediaMetaData& aMediaMetaData, ErrorResult& aRv);
148 already_AddRefed<DOMRequest>
149 SendMediaPlayStatus(const MediaPlayStatus& aMediaPlayStatus, ErrorResult& aRv);
151 IMPL_EVENT_HANDLER(a2dpstatuschanged);
152 IMPL_EVENT_HANDLER(hfpstatuschanged);
153 IMPL_EVENT_HANDLER(requestmediaplaystatus);
154 IMPL_EVENT_HANDLER(scostatuschanged);
155 IMPL_EVENT_HANDLER(attributechanged);
156 IMPL_EVENT_HANDLER(devicepaired);
157 IMPL_EVENT_HANDLER(deviceunpaired);
159 nsPIDOMWindow* GetParentObject() const
161 return GetOwner();
164 virtual JSObject*
165 WrapObject(JSContext* aCx) MOZ_OVERRIDE;
167 private:
168 BluetoothAdapter(nsPIDOMWindow* aOwner, const BluetoothValue& aValue);
169 ~BluetoothAdapter();
171 already_AddRefed<Promise>
172 PairUnpair(bool aPair, const nsAString& aDeviceAddress, ErrorResult& aRv);
174 bool IsAdapterAttributeChanged(BluetoothAdapterAttribute aType,
175 const BluetoothValue& aValue);
176 void HandleAdapterStateChanged();
177 void HandlePropertyChanged(const BluetoothValue& aValue);
178 void DispatchAttributeEvent(const nsTArray<nsString>& aTypes);
179 BluetoothAdapterAttribute
180 ConvertStringToAdapterAttribute(const nsAString& aString);
182 void GetPairedDeviceProperties(const nsTArray<nsString>& aDeviceAddresses);
184 void HandleDeviceFound(const BluetoothValue& aValue);
185 void HandlePairingRequest(const BluetoothValue& aValue);
188 * Handle DEVICE_PAIRED_ID bluetooth signal.
190 * @param aValue [in] Properties array of the paired device.
191 * The array should contain two properties:
192 * - nsString 'Address'
193 * - bool 'Paired'
195 void HandleDevicePaired(const BluetoothValue& aValue);
198 * Handle DEVICE_UNPAIRED_ID bluetooth signal.
200 * @param aValue [in] Properties array of the unpaired device.
201 * The array should contain two properties:
202 * - nsString 'Address'
203 * - bool 'Paired'
205 void HandleDeviceUnpaired(const BluetoothValue& aValue);
208 * Fire BluetoothDeviceEvent to trigger
209 * ondeviceparied/ondeviceunpaired event handler.
211 * @param aType [in] Event type to fire
212 * @param aInit [in] Event initialization value
214 void DispatchDeviceEvent(const nsAString& aType,
215 const BluetoothDeviceEventInit& aInit);
218 * mDevices holds references of all created device objects.
219 * It is an empty array when the adapter state is disabled.
221 * Devices will be appended when
222 * 1) Enabling BT: Paired devices reported by stack.
223 * 2) Discovering: Discovered devices during discovery operation.
224 * A device won't be appended if a device object with the same
225 * address already exists.
227 * Devices will be removed when
228 * 1) Starting discovery: All unpaired devices will be removed before this
229 * adapter starts a new discovery.
230 * 2) Disabling BT: All devices will be removed.
232 nsTArray<nsRefPtr<BluetoothDevice> > mDevices;
233 nsRefPtr<BluetoothDiscoveryHandle> mDiscoveryHandleInUse;
234 nsRefPtr<BluetoothPairingListener> mPairingReqs;
235 BluetoothAdapterState mState;
236 nsString mAddress;
237 nsString mName;
238 bool mDiscoverable;
239 bool mDiscovering;
242 END_BLUETOOTH_NAMESPACE
244 #endif