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

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: Fix global interface test 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)
23 , m_stopped(false)
22 { 24 {
25 // See example in Source/platform/heap/ThreadState.h
26 ThreadState::current()->registerPreFinalizer(this);
23 } 27 }
24 28
25 BluetoothGATTCharacteristic* BluetoothGATTCharacteristic::take(ScriptPromiseReso lver*, PassOwnPtr<WebBluetoothGATTCharacteristicInit> webCharacteristic) 29 BluetoothGATTCharacteristic* BluetoothGATTCharacteristic::take(ScriptPromiseReso lver* resolver, PassOwnPtr<WebBluetoothGATTCharacteristicInit> webCharacteristic )
26 { 30 {
27 if (!webCharacteristic) { 31 if (!webCharacteristic) {
28 return nullptr; 32 return nullptr;
29 } 33 }
30 return new BluetoothGATTCharacteristic(webCharacteristic); 34 BluetoothGATTCharacteristic* characteristic = new BluetoothGATTCharacteristi c(resolver->executionContext(), webCharacteristic);
35 // See note in ActiveDOMObject about suspendIfNeeded.
36 characteristic->suspendIfNeeded();
37 return characteristic;
38 }
39
40 void BluetoothGATTCharacteristic::stop()
41 {
42 notifyCharacteristicObjectRemoved();
43 }
44
45 void BluetoothGATTCharacteristic::dispose()
46 {
47 notifyCharacteristicObjectRemoved();
48 }
49
50 void BluetoothGATTCharacteristic::notifyCharacteristicObjectRemoved()
51 {
52 if (!m_stopped) {
53 m_stopped = true;
54 WebBluetooth* webbluetooth = BluetoothSupplement::fromExecutionContext(A ctiveDOMObject::executionContext());
55 webbluetooth->characteristicObjectRemoved(m_webCharacteristic->character isticInstanceID, this);
56 }
31 } 57 }
32 58
33 ScriptPromise BluetoothGATTCharacteristic::readValue(ScriptState* scriptState) 59 ScriptPromise BluetoothGATTCharacteristic::readValue(ScriptState* scriptState)
34 { 60 {
35 WebBluetooth* webbluetooth = BluetoothSupplement::fromScriptState(scriptStat e); 61 WebBluetooth* webbluetooth = BluetoothSupplement::fromScriptState(scriptStat e);
36 62
37 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ; 63 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ;
38 ScriptPromise promise = resolver->promise(); 64 ScriptPromise promise = resolver->promise();
39 webbluetooth->readValue(m_webCharacteristic->characteristicInstanceID, new C allbackPromiseAdapter<ConvertWebVectorToArrayBuffer, BluetoothError>(resolver)); 65 webbluetooth->readValue(m_webCharacteristic->characteristicInstanceID, new C allbackPromiseAdapter<ConvertWebVectorToArrayBuffer, BluetoothError>(resolver));
40 66
(...skipping 15 matching lines...) Expand all
56 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(InvalidModificationError, "Value can't exceed 512 bytes.")); 82 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(InvalidModificationError, "Value can't exceed 512 bytes."));
57 83
58 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ; 84 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ;
59 85
60 ScriptPromise promise = resolver->promise(); 86 ScriptPromise promise = resolver->promise();
61 webbluetooth->writeValue(m_webCharacteristic->characteristicInstanceID, valu eVector, new CallbackPromiseAdapter<void, BluetoothError>(resolver)); 87 webbluetooth->writeValue(m_webCharacteristic->characteristicInstanceID, valu eVector, new CallbackPromiseAdapter<void, BluetoothError>(resolver));
62 88
63 return promise; 89 return promise;
64 } 90 }
65 91
92 ScriptPromise BluetoothGATTCharacteristic::startNotifications(ScriptState* scrip tState)
93 {
94 WebBluetooth* webbluetooth = BluetoothSupplement::fromScriptState(scriptStat e);
95 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ;
96 ScriptPromise promise = resolver->promise();
97 webbluetooth->startNotifications(m_webCharacteristic->characteristicInstance ID, this, new CallbackPromiseAdapter<void, BluetoothError>(resolver));
98 return promise;
99 }
100
101 ScriptPromise BluetoothGATTCharacteristic::stopNotifications(ScriptState* script State)
102 {
103 WebBluetooth* webbluetooth = BluetoothSupplement::fromScriptState(scriptStat e);
104 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ;
105 ScriptPromise promise = resolver->promise();
106 webbluetooth->stopNotifications(m_webCharacteristic->characteristicInstanceI D, this, new CallbackPromiseAdapter<void, BluetoothError>(resolver));
107 return promise;
108 }
109
110 DEFINE_TRACE(BluetoothGATTCharacteristic)
111 {
112 ActiveDOMObject::trace(visitor);
113 }
114
66 } // namespace blink 115 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698