OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "device/bluetooth/bluetooth_gatt_notify_session.h" | 5 #include "device/bluetooth/bluetooth_gatt_notify_session.h" |
6 | 6 |
7 #include "base/bind.h" | |
8 #include "base/logging.h" | |
9 #include "device/bluetooth/bluetooth_remote_gatt_characteristic.h" | |
10 | |
7 namespace device { | 11 namespace device { |
8 | 12 |
9 BluetoothGattNotifySession::BluetoothGattNotifySession() { | 13 BluetoothGattNotifySession::BluetoothGattNotifySession( |
14 base::WeakPtr<BluetoothRemoteGattCharacteristic> characteristic) | |
15 : characteristic_(characteristic), | |
16 characteristic_id_(characteristic.get() ? characteristic->GetIdentifier() | |
17 : std::string()) {} | |
18 | |
19 BluetoothGattNotifySession::~BluetoothGattNotifySession() { | |
20 if (characteristic_.get()) { | |
ortuno
2016/07/28 21:59:29
optional nit: I think the preferred method for che
tommyt
2016/08/01 11:39:21
Done.
| |
21 Stop(base::Bind(&base::DoNothing)); | |
22 } | |
10 } | 23 } |
11 | 24 |
12 BluetoothGattNotifySession::~BluetoothGattNotifySession() { | 25 std::string BluetoothGattNotifySession::GetCharacteristicIdentifier() const { |
26 return characteristic_id_; | |
27 } | |
28 | |
29 BluetoothRemoteGattCharacteristic* | |
30 BluetoothGattNotifySession::GetCharacteristic() const { | |
31 return characteristic_.get(); | |
32 } | |
33 | |
34 bool BluetoothGattNotifySession::IsActive() { | |
35 return characteristic_.get() != nullptr && characteristic_->IsNotifying(); | |
ortuno
2016/07/28 21:59:30
When would characteristic_.get() != nullptr and Is
tommyt
2016/08/01 11:39:21
Currently never. However, if we move towards creat
| |
36 } | |
37 | |
38 void BluetoothGattNotifySession::Stop(const base::Closure& callback) { | |
39 BluetoothRemoteGattCharacteristic* characteristic = characteristic_.get(); | |
40 characteristic_.reset(); | |
41 if (characteristic) { | |
ortuno
2016/07/28 21:59:30
optional nit for clarity: characteristic != nullpt
tommyt
2016/08/01 11:39:21
Done.
| |
42 characteristic->StopNotifySession(this, callback); | |
43 } else { | |
44 callback.Run(); | |
45 } | |
13 } | 46 } |
14 | 47 |
15 } // namespace device | 48 } // namespace device |
OLD | NEW |