| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef BluetoothRemoteGATTServer_h | 5 #ifndef BluetoothRemoteGATTServer_h |
| 6 #define BluetoothRemoteGATTServer_h | 6 #define BluetoothRemoteGATTServer_h |
| 7 | 7 |
| 8 #include "bindings/core/v8/ScriptWrappable.h" | 8 #include "bindings/core/v8/ScriptWrappable.h" |
| 9 #include "bindings/modules/v8/StringOrUnsignedLong.h" | 9 #include "bindings/modules/v8/StringOrUnsignedLong.h" |
| 10 #include "modules/bluetooth/BluetoothDevice.h" | 10 #include "modules/bluetooth/BluetoothDevice.h" |
| 11 #include "mojo/public/cpp/bindings/associated_binding.h" |
| 11 #include "platform/heap/Heap.h" | 12 #include "platform/heap/Heap.h" |
| 12 #include "public/platform/modules/bluetooth/web_bluetooth.mojom-blink.h" | 13 #include "public/platform/modules/bluetooth/web_bluetooth.mojom-blink.h" |
| 13 #include "wtf/text/WTFString.h" | 14 #include "wtf/text/WTFString.h" |
| 14 | 15 |
| 15 namespace blink { | 16 namespace blink { |
| 16 | 17 |
| 17 class BluetoothDevice; | 18 class BluetoothDevice; |
| 18 class ScriptPromise; | 19 class ScriptPromise; |
| 19 class ScriptPromiseResolver; | 20 class ScriptPromiseResolver; |
| 20 class ScriptState; | 21 class ScriptState; |
| 21 | 22 |
| 22 // BluetoothRemoteGATTServer provides a way to interact with a connected | 23 // BluetoothRemoteGATTServer provides a way to interact with a connected |
| 23 // bluetooth peripheral. | 24 // bluetooth peripheral. |
| 24 class BluetoothRemoteGATTServer final | 25 class BluetoothRemoteGATTServer |
| 25 : public GarbageCollected<BluetoothRemoteGATTServer>, | 26 : public GarbageCollectedFinalized<BluetoothRemoteGATTServer>, |
| 26 public ScriptWrappable { | 27 public ScriptWrappable, |
| 28 public mojom::blink::WebBluetoothServerClient { |
| 29 USING_PRE_FINALIZER(BluetoothRemoteGATTServer, dispose); |
| 27 DEFINE_WRAPPERTYPEINFO(); | 30 DEFINE_WRAPPERTYPEINFO(); |
| 28 | 31 |
| 29 public: | 32 public: |
| 30 BluetoothRemoteGATTServer(BluetoothDevice*); | 33 BluetoothRemoteGATTServer(BluetoothDevice*); |
| 31 | 34 |
| 32 static BluetoothRemoteGATTServer* create(BluetoothDevice*); | 35 static BluetoothRemoteGATTServer* create(BluetoothDevice*); |
| 33 | 36 |
| 37 // mojom::blink::WebBluetoothServerClient: |
| 38 void GattServerDisconnected() override; |
| 39 |
| 34 void setConnected(bool connected) { m_connected = connected; } | 40 void setConnected(bool connected) { m_connected = connected; } |
| 35 | 41 |
| 36 // The Active Algorithms set is maintained so that disconnection, i.e. | 42 // The Active Algorithms set is maintained so that disconnection, i.e. |
| 37 // disconnect() method or the device disconnecting by itself, can be detected | 43 // disconnect() method or the device disconnecting by itself, can be detected |
| 38 // by algorithms. They check via RemoveFromActiveAlgorithms that their | 44 // by algorithms. They check via RemoveFromActiveAlgorithms that their |
| 39 // resolvers is still in the set of active algorithms. | 45 // resolvers is still in the set of active algorithms. |
| 40 // | 46 // |
| 41 // Adds |resolver| to the set of Active Algorithms. CHECK-fails if | 47 // Adds |resolver| to the set of Active Algorithms. CHECK-fails if |
| 42 // |resolver| was already added. | 48 // |resolver| was already added. |
| 43 void AddToActiveAlgorithms(ScriptPromiseResolver*); | 49 void AddToActiveAlgorithms(ScriptPromiseResolver*); |
| 44 // Removes |resolver| from the set of Active Algorithms if it was in the set | 50 // Removes |resolver| from the set of Active Algorithms if it was in the set |
| 45 // and returns true, false otherwise. | 51 // and returns true, false otherwise. |
| 46 bool RemoveFromActiveAlgorithms(ScriptPromiseResolver*); | 52 bool RemoveFromActiveAlgorithms(ScriptPromiseResolver*); |
| 47 // Removes all ScriptPromiseResolvers from the set of Active Algorithms. | 53 // Removes all ScriptPromiseResolvers from the set of Active Algorithms. |
| 48 void ClearActiveAlgorithms() { m_activeAlgorithms.clear(); } | 54 void ClearActiveAlgorithms() { m_activeAlgorithms.clear(); } |
| 49 | 55 |
| 56 // USING_PRE_FINALIZER interface. |
| 57 // Called before the object gets garbage collected. |
| 58 void dispose(); |
| 59 |
| 50 // Interface required by Garbage Collectoin: | 60 // Interface required by Garbage Collectoin: |
| 51 DECLARE_VIRTUAL_TRACE(); | 61 DECLARE_VIRTUAL_TRACE(); |
| 52 | 62 |
| 53 // IDL exposed interface: | 63 // IDL exposed interface: |
| 54 BluetoothDevice* device() { return m_device; } | 64 BluetoothDevice* device() { return m_device; } |
| 55 bool connected() { return m_connected; } | 65 bool connected() { return m_connected; } |
| 56 ScriptPromise connect(ScriptState*); | 66 ScriptPromise connect(ScriptState*); |
| 57 void disconnect(ScriptState*); | 67 void disconnect(ScriptState*); |
| 58 ScriptPromise getPrimaryService(ScriptState*, | 68 ScriptPromise getPrimaryService(ScriptState*, |
| 59 const StringOrUnsignedLong& service, | 69 const StringOrUnsignedLong& service, |
| 60 ExceptionState&); | 70 ExceptionState&); |
| 61 ScriptPromise getPrimaryServices(ScriptState*, | 71 ScriptPromise getPrimaryServices(ScriptState*, |
| 62 const StringOrUnsignedLong& service, | 72 const StringOrUnsignedLong& service, |
| 63 ExceptionState&); | 73 ExceptionState&); |
| 64 ScriptPromise getPrimaryServices(ScriptState*, ExceptionState&); | 74 ScriptPromise getPrimaryServices(ScriptState*, ExceptionState&); |
| 65 | 75 |
| 66 private: | 76 private: |
| 67 ScriptPromise getPrimaryServicesImpl( | 77 ScriptPromise getPrimaryServicesImpl( |
| 68 ScriptState*, | 78 ScriptState*, |
| 69 mojom::blink::WebBluetoothGATTQueryQuantity, | 79 mojom::blink::WebBluetoothGATTQueryQuantity, |
| 70 String serviceUUID = String()); | 80 String serviceUUID = String()); |
| 71 | 81 |
| 72 void ConnectCallback(ScriptPromiseResolver*, | 82 void ConnectCallback(ScriptPromiseResolver*, |
| 73 mojom::blink::WebBluetoothResult); | 83 mojom::blink::WebBluetoothResult, |
| 84 mojom::blink::WebBluetoothServerClientAssociatedRequest); |
| 74 void GetPrimaryServicesCallback( | 85 void GetPrimaryServicesCallback( |
| 75 mojom::blink::WebBluetoothGATTQueryQuantity, | 86 mojom::blink::WebBluetoothGATTQueryQuantity, |
| 76 ScriptPromiseResolver*, | 87 ScriptPromiseResolver*, |
| 77 mojom::blink::WebBluetoothResult, | 88 mojom::blink::WebBluetoothResult, |
| 78 Optional<Vector<mojom::blink::WebBluetoothRemoteGATTServicePtr>> | 89 Optional<Vector<mojom::blink::WebBluetoothRemoteGATTServicePtr>> |
| 79 services); | 90 services); |
| 80 | 91 |
| 81 // Contains a ScriptPromiseResolver corresponding to each active algorithm | 92 // Contains a ScriptPromiseResolver corresponding to each active algorithm |
| 82 // using this server’s connection. | 93 // using this server’s connection. |
| 83 HeapHashSet<Member<ScriptPromiseResolver>> m_activeAlgorithms; | 94 HeapHashSet<Member<ScriptPromiseResolver>> m_activeAlgorithms; |
| 84 | 95 |
| 96 mojo::AssociatedBinding<mojom::blink::WebBluetoothServerClient> |
| 97 m_clientBinding; |
| 98 |
| 85 Member<BluetoothDevice> m_device; | 99 Member<BluetoothDevice> m_device; |
| 86 bool m_connected; | 100 bool m_connected; |
| 87 }; | 101 }; |
| 88 | 102 |
| 89 } // namespace blink | 103 } // namespace blink |
| 90 | 104 |
| 91 #endif // BluetoothDevice_h | 105 #endif // BluetoothDevice_h |
| OLD | NEW |