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

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: Wait for stop request to finish 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();
haraken 2015/10/07 01:22:33 Nit: Can we move suspendIfNeeded() into the take m
ortuno 2015/10/07 17:03:55 Done. Is there any reason for that? I see a couple
26 // See example in Source/platform/heap/ThreadState.h
27 ThreadState::current()->registerPreFinalizer(this);
23 } 28 }
24 29
25 BluetoothGATTCharacteristic* BluetoothGATTCharacteristic::take(ScriptPromiseReso lver*, PassOwnPtr<WebBluetoothGATTCharacteristicInit> webCharacteristic) 30 BluetoothGATTCharacteristic* BluetoothGATTCharacteristic::take(ScriptPromiseReso lver* resolver, PassOwnPtr<WebBluetoothGATTCharacteristicInit> webCharacteristic )
26 { 31 {
27 if (!webCharacteristic) { 32 if (!webCharacteristic) {
28 return nullptr; 33 return nullptr;
29 } 34 }
30 return new BluetoothGATTCharacteristic(webCharacteristic); 35 return new BluetoothGATTCharacteristic(resolver->executionContext(), webChar acteristic);
36 }
37
38 void BluetoothGATTCharacteristic::stop()
39 {
40 m_stopped = true;
41 WebBluetooth* webbluetooth = BluetoothSupplement::from(ActiveDOMObject::exec utionContext());
42 webbluetooth->characteristicObjectRemoved(m_webCharacteristic->characteristi cInstanceID, this);
43 }
44
45 void BluetoothGATTCharacteristic::dispose()
46 {
47 // stop gets called when the parent document is detached so no need to call
48 // again.
haraken 2015/10/07 01:22:33 Is this comment correct? If the parent document is
ortuno 2015/10/07 17:03:55 Moved things around a bit to make our intention cl
49 if (!m_stopped) {
50 stop();
51 }
31 } 52 }
32 53
33 ScriptPromise BluetoothGATTCharacteristic::readValue(ScriptState* scriptState) 54 ScriptPromise BluetoothGATTCharacteristic::readValue(ScriptState* scriptState)
34 { 55 {
35 WebBluetooth* webbluetooth = BluetoothSupplement::from(scriptState); 56 WebBluetooth* webbluetooth = BluetoothSupplement::from(scriptState);
36 57
37 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ; 58 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ;
38 ScriptPromise promise = resolver->promise(); 59 ScriptPromise promise = resolver->promise();
39 webbluetooth->readValue(m_webCharacteristic->characteristicInstanceID, new C allbackPromiseAdapter<ConvertWebVectorToArrayBuffer, BluetoothError>(resolver)); 60 webbluetooth->readValue(m_webCharacteristic->characteristicInstanceID, new C allbackPromiseAdapter<ConvertWebVectorToArrayBuffer, BluetoothError>(resolver));
40 61
(...skipping 15 matching lines...) Expand all
56 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(InvalidModificationError, "Value can't exceed 512 bytes.")); 77 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(InvalidModificationError, "Value can't exceed 512 bytes."));
57 78
58 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ; 79 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ;
59 80
60 ScriptPromise promise = resolver->promise(); 81 ScriptPromise promise = resolver->promise();
61 webbluetooth->writeValue(m_webCharacteristic->characteristicInstanceID, valu eVector, new CallbackPromiseAdapter<void, BluetoothError>(resolver)); 82 webbluetooth->writeValue(m_webCharacteristic->characteristicInstanceID, valu eVector, new CallbackPromiseAdapter<void, BluetoothError>(resolver));
62 83
63 return promise; 84 return promise;
64 } 85 }
65 86
87 ScriptPromise BluetoothGATTCharacteristic::startNotifications(ScriptState* scrip tState)
88 {
89 WebBluetooth* webbluetooth = BluetoothSupplement::from(scriptState);
90 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ;
91 ScriptPromise promise = resolver->promise();
92 webbluetooth->startNotifications(m_webCharacteristic->characteristicInstance ID, this, new CallbackPromiseAdapter<void, BluetoothError>(resolver));
93 return promise;
94 }
95
96 ScriptPromise BluetoothGATTCharacteristic::stopNotifications(ScriptState* script State)
97 {
98 WebBluetooth* webbluetooth = BluetoothSupplement::from(scriptState);
99 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ;
100 ScriptPromise promise = resolver->promise();
101 webbluetooth->stopNotifications(m_webCharacteristic->characteristicInstanceI D, this, new CallbackPromiseAdapter<void, BluetoothError>(resolver));
102 return promise;
103 }
104
105 DEFINE_TRACE(BluetoothGATTCharacteristic)
106 {
107 ActiveDOMObject::trace(visitor);
108 }
109
66 } // namespace blink 110 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698