Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(28)

Side by Side Diff: third_party/WebKit/Source/modules/bluetooth/BluetoothGATTCharacteristic.cpp

Issue 1334763002: bluetooth: Subscribe to notifications (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bluetooth-origin
Patch Set: Address jyasskin's comments Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #include "config.h" 5 #include "config.h"
6 #include "modules/bluetooth/BluetoothGATTCharacteristic.h" 6 #include "modules/bluetooth/BluetoothGATTCharacteristic.h"
7 7
8 #include "bindings/core/v8/CallbackPromiseAdapter.h" 8 #include "bindings/core/v8/CallbackPromiseAdapter.h"
9 #include "bindings/core/v8/ScriptPromise.h" 9 #include "bindings/core/v8/ScriptPromise.h"
10 #include "bindings/core/v8/ScriptPromiseResolver.h" 10 #include "bindings/core/v8/ScriptPromiseResolver.h"
11 #include "core/dom/DOMException.h" 11 #include "core/dom/DOMException.h"
12 #include "core/dom/ExceptionCode.h" 12 #include "core/dom/ExceptionCode.h"
13 #include "modules/bluetooth/BluetoothError.h" 13 #include "modules/bluetooth/BluetoothError.h"
14 #include "modules/bluetooth/BluetoothSupplement.h" 14 #include "modules/bluetooth/BluetoothSupplement.h"
15 #include "modules/bluetooth/ConvertWebVectorToArrayBuffer.h" 15 #include "modules/bluetooth/ConvertWebVectorToArrayBuffer.h"
16 #include "public/platform/modules/bluetooth/WebBluetooth.h" 16 #include "public/platform/modules/bluetooth/WebBluetooth.h"
17 17
18 namespace blink { 18 namespace blink {
19 19
20 BluetoothGATTCharacteristic::BluetoothGATTCharacteristic(PassOwnPtr<WebBluetooth GATTCharacteristicInit> webCharacteristic) 20 BluetoothGATTCharacteristic::BluetoothGATTCharacteristic(ExecutionContext* conte xt, PassOwnPtr<WebBluetoothGATTCharacteristicInit> webCharacteristic)
21 : m_webCharacteristic(webCharacteristic) 21 : ActiveDOMObject(context)
22 , m_webCharacteristic(webCharacteristic)
22 { 23 {
24 // See note in ActiveDOMObject about suspendIfNeeded.
25 suspendIfNeeded();
23 } 26 }
24 27
25 BluetoothGATTCharacteristic* BluetoothGATTCharacteristic::take(ScriptPromiseReso lver*, PassOwnPtr<WebBluetoothGATTCharacteristicInit> webCharacteristic) 28 BluetoothGATTCharacteristic* BluetoothGATTCharacteristic::take(ScriptPromiseReso lver* resolver, PassOwnPtr<WebBluetoothGATTCharacteristicInit> webCharacteristic )
26 { 29 {
27 if (!webCharacteristic) { 30 if (!webCharacteristic) {
28 return nullptr; 31 return nullptr;
29 } 32 }
30 return new BluetoothGATTCharacteristic(webCharacteristic); 33 return new BluetoothGATTCharacteristic(resolver->executionContext(), webChar acteristic);
34 }
35
36 void BluetoothGATTCharacteristic::stop()
37 {
38 WebBluetooth* webbluetooth = BluetoothSupplement::from(ActiveDOMObject::exec utionContext());
39 webbluetooth->characteristicObjectRemoved(m_webCharacteristic->characteristi cInstanceID, this);
31 } 40 }
32 41
33 ScriptPromise BluetoothGATTCharacteristic::readValue(ScriptState* scriptState) 42 ScriptPromise BluetoothGATTCharacteristic::readValue(ScriptState* scriptState)
34 { 43 {
35 WebBluetooth* webbluetooth = BluetoothSupplement::from(scriptState); 44 WebBluetooth* webbluetooth = BluetoothSupplement::from(scriptState);
36 45
37 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ; 46 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ;
38 ScriptPromise promise = resolver->promise(); 47 ScriptPromise promise = resolver->promise();
39 webbluetooth->readValue(m_webCharacteristic->characteristicInstanceID, new C allbackPromiseAdapter<ConvertWebVectorToArrayBuffer, BluetoothError>(resolver)); 48 webbluetooth->readValue(m_webCharacteristic->characteristicInstanceID, new C allbackPromiseAdapter<ConvertWebVectorToArrayBuffer, BluetoothError>(resolver));
40 49
(...skipping 15 matching lines...) Expand all
56 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(InvalidModificationError, "Value can't exceed 512 bytes.")); 65 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(InvalidModificationError, "Value can't exceed 512 bytes."));
57 66
58 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ; 67 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ;
59 68
60 ScriptPromise promise = resolver->promise(); 69 ScriptPromise promise = resolver->promise();
61 webbluetooth->writeValue(m_webCharacteristic->characteristicInstanceID, valu eVector, new CallbackPromiseAdapter<void, BluetoothError>(resolver)); 70 webbluetooth->writeValue(m_webCharacteristic->characteristicInstanceID, valu eVector, new CallbackPromiseAdapter<void, BluetoothError>(resolver));
62 71
63 return promise; 72 return promise;
64 } 73 }
65 74
75 ScriptPromise BluetoothGATTCharacteristic::startNotifications(ScriptState* scrip tState)
76 {
77 WebBluetooth* webbluetooth = BluetoothSupplement::from(scriptState);
78 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ;
79 ScriptPromise promise = resolver->promise();
80 webbluetooth->startNotifications(m_webCharacteristic->characteristicInstance ID, this, new CallbackPromiseAdapter<void, BluetoothError>(resolver));
81 return promise;
82 }
83
84 ScriptPromise BluetoothGATTCharacteristic::stopNotifications(ScriptState* script State)
85 {
86 WebBluetooth* webbluetooth = BluetoothSupplement::from(scriptState);
87 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ;
88 ScriptPromise promise = resolver->promise();
89 webbluetooth->stopNotifications(m_webCharacteristic->characteristicInstanceI D, this, new CallbackPromiseAdapter<void, BluetoothError>(resolver));
90 return promise;
91 }
92
93 DEFINE_TRACE(BluetoothGATTCharacteristic)
94 {
95 ActiveDOMObject::trace(visitor);
96 }
97
66 } // namespace blink 98 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698