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/bind_helpers.h" |
| 9 #include "base/logging.h" |
| 10 #include "base/threading/thread_task_runner_handle.h" |
| 11 #include "device/bluetooth/bluetooth_remote_gatt_characteristic.h" |
| 12 |
7 namespace device { | 13 namespace device { |
8 | 14 |
9 BluetoothGattNotifySession::BluetoothGattNotifySession() { | 15 BluetoothGattNotifySession::BluetoothGattNotifySession( |
| 16 base::WeakPtr<BluetoothRemoteGattCharacteristic> characteristic) |
| 17 : characteristic_(characteristic), |
| 18 characteristic_id_(characteristic.get() ? characteristic->GetIdentifier() |
| 19 : std::string()), |
| 20 active_(true) {} |
| 21 |
| 22 BluetoothGattNotifySession::~BluetoothGattNotifySession() { |
| 23 if (active_) { |
| 24 Stop(base::Bind(&base::DoNothing)); |
| 25 } |
10 } | 26 } |
11 | 27 |
12 BluetoothGattNotifySession::~BluetoothGattNotifySession() { | 28 std::string BluetoothGattNotifySession::GetCharacteristicIdentifier() const { |
| 29 return characteristic_id_; |
| 30 } |
| 31 |
| 32 BluetoothRemoteGattCharacteristic* |
| 33 BluetoothGattNotifySession::GetCharacteristic() const { |
| 34 return characteristic_.get(); |
| 35 } |
| 36 |
| 37 bool BluetoothGattNotifySession::IsActive() { |
| 38 return active_ && characteristic_ != nullptr && |
| 39 characteristic_->IsNotifying(); |
| 40 } |
| 41 |
| 42 void BluetoothGattNotifySession::Stop(const base::Closure& callback) { |
| 43 active_ = false; |
| 44 if (characteristic_ != nullptr) { |
| 45 characteristic_->StopNotifySession(this, callback); |
| 46 } else { |
| 47 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, callback); |
| 48 } |
13 } | 49 } |
14 | 50 |
15 } // namespace device | 51 } // namespace device |
OLD | NEW |