| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 "modules/bluetooth/BluetoothRemoteGATTUtils.h" | 5 #include "modules/bluetooth/BluetoothRemoteGATTUtils.h" |
| 6 | 6 |
| 7 namespace blink { | 7 namespace blink { |
| 8 | 8 |
| 9 // static | 9 // static |
| 10 DOMDataView* BluetoothRemoteGATTUtils::ConvertWTFVectorToDataView( | 10 DOMDataView* BluetoothRemoteGATTUtils::ConvertWTFVectorToDataView( |
| 11 const WTF::Vector<uint8_t>& wtfVector) { | 11 const WTF::Vector<uint8_t>& wtfVector) { |
| 12 static_assert(sizeof(*wtfVector.data()) == 1, | 12 static_assert(sizeof(*wtfVector.data()) == 1, |
| 13 "uint8_t should be a single byte"); | 13 "uint8_t should be a single byte"); |
| 14 DOMArrayBuffer* domBuffer = | 14 DOMArrayBuffer* domBuffer = |
| 15 DOMArrayBuffer::create(wtfVector.data(), wtfVector.size()); | 15 DOMArrayBuffer::create(wtfVector.data(), wtfVector.size()); |
| 16 return DOMDataView::create(domBuffer, 0, wtfVector.size()); | 16 return DOMDataView::create(domBuffer, 0, wtfVector.size()); |
| 17 } | 17 } |
| 18 | 18 |
| 19 // static | |
| 20 DOMException* BluetoothRemoteGATTUtils::CreateDOMException(ExceptionType type) { | |
| 21 switch (type) { | |
| 22 case ExceptionType::kGATTServerDisconnected: | |
| 23 return DOMException::create( | |
| 24 NetworkError, | |
| 25 "GATT Server disconnected while performing a GATT operation."); | |
| 26 | |
| 27 case ExceptionType::kGATTServerNotConnected: | |
| 28 return DOMException::create( | |
| 29 NetworkError, | |
| 30 "GATT Server is disconnected. Cannot perform GATT operations."); | |
| 31 | |
| 32 case ExceptionType::kInvalidCharacteristic: | |
| 33 return DOMException::create( | |
| 34 InvalidStateError, | |
| 35 "Characteristic is no longer valid. Remember to retrieve the " | |
| 36 "characteristic again after reconnecting."); | |
| 37 | |
| 38 case ExceptionType::kInvalidDescriptor: | |
| 39 return DOMException::create( | |
| 40 InvalidStateError, | |
| 41 "Descriptor is no longer valid. Remember to retrieve the " | |
| 42 "Descriptor again after reconnecting."); | |
| 43 | |
| 44 default: | |
| 45 NOTREACHED(); | |
| 46 return nullptr; | |
| 47 } | |
| 48 } | |
| 49 | |
| 50 } // namespace blink | 19 } // namespace blink |
| OLD | NEW |