OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "device/bluetooth/bluetooth_remote_gatt_characteristic_win.h" | |
6 | |
7 #include "device/bluetooth/bluetooth_adapter_win.h" | |
8 #include "device/bluetooth/bluetooth_remote_gatt_service_win.h" | |
9 #include "device/bluetooth/bluetooth_task_manager_win.h" | |
10 | |
11 namespace device { | |
12 | |
13 BluetoothRemoteGattCharacteristicWin::BluetoothRemoteGattCharacteristicWin( | |
14 BluetoothRemoteGattServiceWin* parent_service, | |
15 BTH_LE_GATT_CHARACTERISTIC* characteristic_info, | |
16 scoped_refptr<base::SequencedTaskRunner>& ui_task_runner) | |
17 : parent_service_(parent_service), | |
18 characteristic_info_(characteristic_info), | |
19 ui_task_runner_(ui_task_runner), | |
20 weak_ptr_factory_(this) { | |
21 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); | |
22 DCHECK(parent_service_); | |
23 DCHECK(characteristic_info_); | |
24 | |
25 adapter_ = static_cast<BluetoothAdapterWin*>( | |
26 parent_service_->GetDevice()->GetAdapter()); | |
27 DCHECK(adapter_); | |
28 task_manager_ = adapter_->GetWinBluetoothTaskManager(); | |
29 DCHECK(task_manager_); | |
30 | |
31 characteristic_uuid_ = task_manager_->BluetoothLowEnergyUuidToBluetoothUuid( | |
32 characteristic_info_->CharacteristicUuid); | |
33 Update(); | |
34 } | |
35 | |
36 BluetoothRemoteGattCharacteristicWin::~BluetoothRemoteGattCharacteristicWin() { | |
37 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); | |
38 | |
39 adapter_->NotifyGattCharacteristicRemoved(this); | |
40 } | |
41 | |
42 std::string BluetoothRemoteGattCharacteristicWin::GetIdentifier() const { | |
43 return parent_service_->GetIdentifier() + "_" + | |
ortuno
2016/02/19 17:33:06
I don't think you need to construct this every sin
gogerald1
2016/02/19 22:45:02
Done.
| |
44 std::to_string(characteristic_info_->AttributeHandle); | |
45 } | |
46 | |
47 BluetoothUUID BluetoothRemoteGattCharacteristicWin::GetUUID() const { | |
48 return characteristic_uuid_; | |
49 } | |
50 | |
51 bool BluetoothRemoteGattCharacteristicWin::IsLocal() const { | |
52 return false; | |
53 } | |
54 | |
55 std::vector<uint8_t>& BluetoothRemoteGattCharacteristicWin::GetValue() const { | |
56 NOTIMPLEMENTED(); | |
57 return const_cast<std::vector<uint8_t>&>(characteristic_value_); | |
58 } | |
59 | |
60 BluetoothGattService* BluetoothRemoteGattCharacteristicWin::GetService() const { | |
61 return parent_service_; | |
62 } | |
63 | |
64 BluetoothGattCharacteristic::Properties | |
65 BluetoothRemoteGattCharacteristicWin::GetProperties() const { | |
66 BluetoothGattCharacteristic::Properties properties = PROPERTY_NONE; | |
67 | |
68 if (characteristic_info_->IsBroadcastable) | |
69 properties = properties | PROPERTY_BROADCAST; | |
70 if (characteristic_info_->IsReadable) | |
71 properties = properties | PROPERTY_READ; | |
72 if (characteristic_info_->IsWritableWithoutResponse) | |
73 properties = properties | PROPERTY_WRITE_WITHOUT_RESPONSE; | |
74 if (characteristic_info_->IsWritable) | |
75 properties = properties | PROPERTY_WRITE; | |
76 if (characteristic_info_->IsNotifiable) | |
77 properties = properties | PROPERTY_NOTIFY; | |
78 if (characteristic_info_->IsIndicatable) | |
79 properties = properties | PROPERTY_INDICATE; | |
80 if (characteristic_info_->IsSignedWritable) | |
81 properties = properties | PROPERTY_AUTHENTICATED_SIGNED_WRITES; | |
82 if (characteristic_info_->HasExtendedProperties) | |
83 properties = properties | PROPERTY_EXTENDED_PROPERTIES; | |
84 | |
ortuno
2016/02/19 17:33:06
What about the other two properties, ReliableWrite
gogerald1
2016/02/19 22:45:02
Done.
| |
85 return properties; | |
86 } | |
87 | |
88 BluetoothGattCharacteristic::Permissions | |
89 BluetoothRemoteGattCharacteristicWin::GetPermissions() const { | |
90 BluetoothGattCharacteristic::Permissions permissions = PERMISSION_NONE; | |
91 | |
92 if (characteristic_info_->IsReadable) | |
93 permissions = permissions | PERMISSION_READ; | |
94 if (characteristic_info_->IsWritable) | |
95 permissions = permissions | PERMISSION_WRITE; | |
96 | |
97 return permissions; | |
98 } | |
99 | |
100 bool BluetoothRemoteGattCharacteristicWin::IsNotifying() const { | |
101 NOTIMPLEMENTED(); | |
102 return false; | |
103 } | |
104 | |
105 std::vector<BluetoothGattDescriptor*> | |
106 BluetoothRemoteGattCharacteristicWin::GetDescriptors() const { | |
107 NOTIMPLEMENTED(); | |
108 return std::vector<BluetoothGattDescriptor*>(); | |
109 } | |
110 | |
111 BluetoothGattDescriptor* BluetoothRemoteGattCharacteristicWin::GetDescriptor( | |
112 const std::string& identifier) const { | |
113 NOTIMPLEMENTED(); | |
114 return nullptr; | |
115 } | |
116 | |
117 bool BluetoothRemoteGattCharacteristicWin::AddDescriptor( | |
118 BluetoothGattDescriptor* descriptor) { | |
119 NOTIMPLEMENTED(); | |
120 return false; | |
121 } | |
122 | |
123 bool BluetoothRemoteGattCharacteristicWin::UpdateValue( | |
124 const std::vector<uint8_t>& value) { | |
125 NOTIMPLEMENTED(); | |
126 return false; | |
127 } | |
128 | |
129 void BluetoothRemoteGattCharacteristicWin::StartNotifySession( | |
130 const NotifySessionCallback& callback, | |
131 const ErrorCallback& error_callback) { | |
132 NOTIMPLEMENTED(); | |
133 error_callback.Run(BluetoothGattService::GATT_ERROR_NOT_SUPPORTED); | |
134 } | |
135 | |
136 void BluetoothRemoteGattCharacteristicWin::ReadRemoteCharacteristic( | |
137 const ValueCallback& callback, | |
138 const ErrorCallback& error_callback) { | |
139 NOTIMPLEMENTED(); | |
140 error_callback.Run(BluetoothGattService::GATT_ERROR_NOT_SUPPORTED); | |
141 } | |
142 | |
143 void BluetoothRemoteGattCharacteristicWin::WriteRemoteCharacteristic( | |
144 const std::vector<uint8_t>& new_value, | |
145 const base::Closure& callback, | |
146 const ErrorCallback& error_callback) { | |
147 NOTIMPLEMENTED(); | |
148 error_callback.Run(BluetoothGattService::GATT_ERROR_NOT_SUPPORTED); | |
149 } | |
150 | |
151 void BluetoothRemoteGattCharacteristicWin::Update() { | |
152 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); | |
153 } | |
154 | |
155 uint16_t BluetoothRemoteGattCharacteristicWin::GetAttributeHandle() const { | |
156 return characteristic_info_->AttributeHandle; | |
157 } | |
158 | |
159 } // namespace device. | |
OLD | NEW |