| 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 BluetoothGATTCharacteristic_h |   5 #ifndef BluetoothGATTCharacteristic_h | 
|   6 #define BluetoothGATTCharacteristic_h |   6 #define BluetoothGATTCharacteristic_h | 
|   7  |   7  | 
|   8 #include "bindings/core/v8/ScriptWrappable.h" |   8 #include "bindings/core/v8/ScriptWrappable.h" | 
|   9 #include "core/dom/ActiveDOMObject.h" |   9 #include "core/dom/ActiveDOMObject.h" | 
|  10 #include "core/dom/DOMArrayPiece.h" |  10 #include "core/dom/DOMArrayPiece.h" | 
 |  11 #include "modules/EventTargetModules.h" | 
|  11 #include "platform/heap/Handle.h" |  12 #include "platform/heap/Handle.h" | 
|  12 #include "public/platform/modules/bluetooth/WebBluetoothGATTCharacteristic.h" |  13 #include "public/platform/modules/bluetooth/WebBluetoothGATTCharacteristic.h" | 
|  13 #include "public/platform/modules/bluetooth/WebBluetoothGATTCharacteristicInit.h
    " |  14 #include "public/platform/modules/bluetooth/WebBluetoothGATTCharacteristicInit.h
    " | 
|  14 #include "wtf/OwnPtr.h" |  15 #include "wtf/OwnPtr.h" | 
|  15 #include "wtf/PassOwnPtr.h" |  16 #include "wtf/PassOwnPtr.h" | 
|  16 #include "wtf/text/WTFString.h" |  17 #include "wtf/text/WTFString.h" | 
|  17  |  18  | 
|  18 namespace blink { |  19 namespace blink { | 
|  19  |  20  | 
|  20 class ExecutionContext; |  21 class ExecutionContext; | 
|  21 class ScriptPromise; |  22 class ScriptPromise; | 
|  22 class ScriptPromiseResolver; |  23 class ScriptPromiseResolver; | 
|  23 class ScriptState; |  24 class ScriptState; | 
|  24  |  25  | 
|  25 // BluetoothGATTCharacteristic represents a GATT Characteristic, which is a |  26 // BluetoothGATTCharacteristic represents a GATT Characteristic, which is a | 
|  26 // basic data element that provides further information about a peripheral's |  27 // basic data element that provides further information about a peripheral's | 
|  27 // service. |  28 // service. | 
|  28 // |  29 // | 
|  29 // Callbacks providing WebBluetoothGATTCharacteristicInit objects are handled by |  30 // Callbacks providing WebBluetoothGATTCharacteristicInit objects are handled by | 
|  30 // CallbackPromiseAdapter templatized with this class. See this class's |  31 // CallbackPromiseAdapter templatized with this class. See this class's | 
|  31 // "Interface required by CallbackPromiseAdapter" section and the |  32 // "Interface required by CallbackPromiseAdapter" section and the | 
|  32 // CallbackPromiseAdapter class comments. |  33 // CallbackPromiseAdapter class comments. | 
|  33 class BluetoothGATTCharacteristic final |  34 class BluetoothGATTCharacteristic final | 
|  34     : public GarbageCollectedFinalized<BluetoothGATTCharacteristic> |  35     : public RefCountedGarbageCollectedEventTargetWithInlineData<BluetoothGATTCh
    aracteristic> | 
|  35     , public ScriptWrappable |  | 
|  36     , public ActiveDOMObject |  36     , public ActiveDOMObject | 
|  37     , public WebBluetoothGATTCharacteristic { |  37     , public WebBluetoothGATTCharacteristic { | 
|  38     USING_PRE_FINALIZER(BluetoothGATTCharacteristic, dispose); |  38     USING_PRE_FINALIZER(BluetoothGATTCharacteristic, dispose); | 
 |  39     DEFINE_WRAPPERTYPEINFO(); | 
 |  40     REFCOUNTED_GARBAGE_COLLECTED_EVENT_TARGET(BluetoothGATTCharacteristic); | 
|  39     WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(BluetoothGATTCharacteristic); |  41     WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(BluetoothGATTCharacteristic); | 
|  40     DEFINE_WRAPPERTYPEINFO(); |  | 
|  41 public: |  42 public: | 
|  42     explicit BluetoothGATTCharacteristic(ExecutionContext*, PassOwnPtr<WebBlueto
    othGATTCharacteristicInit>); |  43     explicit BluetoothGATTCharacteristic(ExecutionContext*, PassOwnPtr<WebBlueto
    othGATTCharacteristicInit>); | 
|  43  |  44  | 
|  44     // Interface required by CallbackPromiseAdapter. |  45     // Interface required by CallbackPromiseAdapter. | 
|  45     using WebType = OwnPtr<WebBluetoothGATTCharacteristicInit>; |  46     using WebType = OwnPtr<WebBluetoothGATTCharacteristicInit>; | 
|  46     static BluetoothGATTCharacteristic* take(ScriptPromiseResolver*, PassOwnPtr<
    WebBluetoothGATTCharacteristicInit>); |  47     static BluetoothGATTCharacteristic* take(ScriptPromiseResolver*, PassOwnPtr<
    WebBluetoothGATTCharacteristicInit>); | 
|  47  |  48  | 
 |  49     // WebBluetoothGATTCharacteristic interface: | 
 |  50     void dispatchCharacteristicValueChanged(const WebVector<uint8_t>& value); | 
 |  51  | 
|  48     // ActiveDOMObject interface. |  52     // ActiveDOMObject interface. | 
|  49     void stop() override; |  53     void stop() override; | 
|  50  |  54  | 
|  51     // USING_PRE_FINALIZER interface. |  55     // USING_PRE_FINALIZER interface. | 
|  52     // Called before the object gets garbage collected. |  56     // Called before the object gets garbage collected. | 
|  53     void dispose(); |  57     void dispose(); | 
|  54  |  58  | 
|  55     // Notify our embedder that we should stop any notifications. |  59     // Notify our embedder that we should stop any notifications. | 
|  56     // The function only notifies the embedder once. |  60     // The function only notifies the embedder once. | 
|  57     void notifyCharacteristicObjectRemoved(); |  61     void notifyCharacteristicObjectRemoved(); | 
|  58  |  62  | 
 |  63     // EventTarget methods: | 
 |  64     const WTF::AtomicString& interfaceName() const override; | 
 |  65     ExecutionContext* executionContext() const; | 
 |  66     bool addEventListener(const AtomicString& eventType, PassRefPtrWillBeRawPtr<
    EventListener>, bool useCapture) override; | 
 |  67  | 
|  59     // Interface required by garbage collection. |  68     // Interface required by garbage collection. | 
|  60     DECLARE_VIRTUAL_TRACE(); |  69     DECLARE_VIRTUAL_TRACE(); | 
|  61  |  70  | 
|  62     // IDL exposed interface: |  71     // IDL exposed interface: | 
|  63     String uuid() { return m_webCharacteristic->uuid; } |  72     String uuid() { return m_webCharacteristic->uuid; } | 
 |  73     PassRefPtr<DOMArrayBuffer> value() const { return m_value; } | 
|  64     ScriptPromise readValue(ScriptState*); |  74     ScriptPromise readValue(ScriptState*); | 
|  65     ScriptPromise writeValue(ScriptState*, const DOMArrayPiece&); |  75     ScriptPromise writeValue(ScriptState*, const DOMArrayPiece&); | 
|  66     ScriptPromise startNotifications(ScriptState*); |  76     ScriptPromise startNotifications(ScriptState*); | 
|  67     ScriptPromise stopNotifications(ScriptState*); |  77     ScriptPromise stopNotifications(ScriptState*); | 
|  68  |  78  | 
 |  79     DEFINE_ATTRIBUTE_EVENT_LISTENER(characteristicvaluechanged); | 
 |  80  | 
|  69 private: |  81 private: | 
|  70     OwnPtr<WebBluetoothGATTCharacteristicInit> m_webCharacteristic; |  82     OwnPtr<WebBluetoothGATTCharacteristicInit> m_webCharacteristic; | 
|  71     bool m_stopped; |  83     bool m_stopped; | 
 |  84     RefPtr<DOMArrayBuffer> m_value; | 
|  72 }; |  85 }; | 
|  73  |  86  | 
|  74 } // namespace blink |  87 } // namespace blink | 
|  75  |  88  | 
|  76 #endif // BluetoothGATTCharacteristic_h |  89 #endif // BluetoothGATTCharacteristic_h | 
| OLD | NEW |