summaryrefslogtreecommitdiffstats
path: root/device/bluetooth/bluetooth_remote_gatt_descriptor_win.cc
blob: 3610af03f6125e5c202e832d15e2bd8241965e97 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "device/bluetooth/bluetooth_remote_gatt_descriptor_win.h"

#include "base/bind.h"
#include "device/bluetooth/bluetooth_adapter_win.h"
#include "device/bluetooth/bluetooth_remote_gatt_characteristic_win.h"
#include "device/bluetooth/bluetooth_remote_gatt_service_win.h"

namespace device {

BluetoothRemoteGattDescriptorWin::BluetoothRemoteGattDescriptorWin(
    BluetoothRemoteGattCharacteristicWin* parent_characteristic,
    BTH_LE_GATT_DESCRIPTOR* descriptor_info,
    scoped_refptr<base::SequencedTaskRunner>& ui_task_runner)
    : parent_characteristic_(parent_characteristic),
      descriptor_info_(descriptor_info),
      ui_task_runner_(ui_task_runner),
      weak_ptr_factory_(this) {
  DCHECK(ui_task_runner_->RunsTasksOnCurrentThread());
  DCHECK(parent_characteristic_);
  DCHECK(descriptor_info_.get());

  task_manager_ = parent_characteristic_->GetWinService()
                      ->GetWinAdapter()
                      ->GetWinBluetoothTaskManager();
  DCHECK(task_manager_);
  service_path_ = parent_characteristic_->GetWinService()->GetServicePath();
  DCHECK(!service_path_.empty());
  descriptor_uuid_ =
      BluetoothTaskManagerWin::BluetoothLowEnergyUuidToBluetoothUuid(
          descriptor_info_.get()->DescriptorUuid);
  DCHECK(descriptor_uuid_.IsValid());
  descriptor_identifier_ = parent_characteristic_->GetIdentifier() + "_" +
                           std::to_string(descriptor_info_->AttributeHandle);
}

BluetoothRemoteGattDescriptorWin::~BluetoothRemoteGattDescriptorWin() {
  DCHECK(ui_task_runner_->RunsTasksOnCurrentThread());

  parent_characteristic_->GetWinService()
      ->GetWinAdapter()
      ->NotifyGattDescriptorRemoved(this);
}

std::string BluetoothRemoteGattDescriptorWin::GetIdentifier() const {
  return descriptor_identifier_;
}

BluetoothUUID BluetoothRemoteGattDescriptorWin::GetUUID() const {
  return descriptor_uuid_;
}

bool BluetoothRemoteGattDescriptorWin::IsLocal() const {
  return false;
}

std::vector<uint8_t>& BluetoothRemoteGattDescriptorWin::GetValue() const {
  NOTIMPLEMENTED();
  return const_cast<std::vector<uint8_t>&>(descriptor_value_);
}

BluetoothGattCharacteristic*
BluetoothRemoteGattDescriptorWin::GetCharacteristic() const {
  return parent_characteristic_;
}

BluetoothGattCharacteristic::Permissions
BluetoothRemoteGattDescriptorWin::GetPermissions() const {
  NOTIMPLEMENTED();
  return descriptor_permissions_;
}

void BluetoothRemoteGattDescriptorWin::ReadRemoteDescriptor(
    const ValueCallback& callback,
    const ErrorCallback& error_callback) {
  DCHECK(ui_task_runner_->RunsTasksOnCurrentThread());

  NOTIMPLEMENTED();
  error_callback.Run(BluetoothGattService::GATT_ERROR_NOT_SUPPORTED);
}

void BluetoothRemoteGattDescriptorWin::WriteRemoteDescriptor(
    const std::vector<uint8_t>& new_value,
    const base::Closure& callback,
    const ErrorCallback& error_callback) {
  DCHECK(ui_task_runner_->RunsTasksOnCurrentThread());

  NOTIMPLEMENTED();
  error_callback.Run(BluetoothGattService::GATT_ERROR_NOT_SUPPORTED);
}

uint16_t BluetoothRemoteGattDescriptorWin::GetAttributeHandle() const {
  return descriptor_info_->AttributeHandle;
}

}  // namespace device.