Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(56)

Side by Side Diff: device/bluetooth/bluetooth_service_record_win.cc

Issue 1542163002: Switch to standard integer types in device/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: win Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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_service_record_win.h" 5 #include "device/bluetooth/bluetooth_service_record_win.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/basictypes.h"
10 #include "base/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
11 #include "base/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
12 #include "device/bluetooth/bluetooth_init_win.h" 11 #include "device/bluetooth/bluetooth_init_win.h"
13 #include "device/bluetooth/bluetooth_uuid.h" 12 #include "device/bluetooth/bluetooth_uuid.h"
14 13
15 namespace { 14 namespace {
16 15
17 const uint16 kProtocolDescriptorListId = 4; 16 const uint16_t kProtocolDescriptorListId = 4;
18 const uint16 kRfcommUuid = 3; 17 const uint16_t kRfcommUuid = 3;
19 const uint16 kUuidId = 1; 18 const uint16_t kUuidId = 1;
20 19
21 bool AdvanceToSdpType(const SDP_ELEMENT_DATA& sequence_data, 20 bool AdvanceToSdpType(const SDP_ELEMENT_DATA& sequence_data,
22 SDP_TYPE type, 21 SDP_TYPE type,
23 HBLUETOOTH_CONTAINER_ELEMENT* element, 22 HBLUETOOTH_CONTAINER_ELEMENT* element,
24 SDP_ELEMENT_DATA* sdp_data) { 23 SDP_ELEMENT_DATA* sdp_data) {
25 while (ERROR_SUCCESS == BluetoothSdpGetContainerElementData( 24 while (ERROR_SUCCESS == BluetoothSdpGetContainerElementData(
26 sequence_data.data.sequence.value, 25 sequence_data.data.sequence.value,
27 sequence_data.data.sequence.length, 26 sequence_data.data.sequence.length,
28 element, 27 element,
29 sdp_data)) { 28 sdp_data)) {
30 if (sdp_data->type == type) { 29 if (sdp_data->type == type) {
31 return true; 30 return true;
32 } 31 }
33 } 32 }
34 return false; 33 return false;
35 } 34 }
36 35
37 void ExtractChannels(const SDP_ELEMENT_DATA& protocol_descriptor_list_data, 36 void ExtractChannels(const SDP_ELEMENT_DATA& protocol_descriptor_list_data,
38 bool* supports_rfcomm, 37 bool* supports_rfcomm,
39 uint8* rfcomm_channel) { 38 uint8_t* rfcomm_channel) {
40 HBLUETOOTH_CONTAINER_ELEMENT sequence_element = NULL; 39 HBLUETOOTH_CONTAINER_ELEMENT sequence_element = NULL;
41 SDP_ELEMENT_DATA sequence_data; 40 SDP_ELEMENT_DATA sequence_data;
42 while (AdvanceToSdpType(protocol_descriptor_list_data, 41 while (AdvanceToSdpType(protocol_descriptor_list_data,
43 SDP_TYPE_SEQUENCE, 42 SDP_TYPE_SEQUENCE,
44 &sequence_element, 43 &sequence_element,
45 &sequence_data)) { 44 &sequence_data)) {
46 HBLUETOOTH_CONTAINER_ELEMENT inner_sequence_element = NULL; 45 HBLUETOOTH_CONTAINER_ELEMENT inner_sequence_element = NULL;
47 SDP_ELEMENT_DATA inner_sequence_data; 46 SDP_ELEMENT_DATA inner_sequence_data;
48 if (AdvanceToSdpType(sequence_data, 47 if (AdvanceToSdpType(sequence_data,
49 SDP_TYPE_UUID, 48 SDP_TYPE_UUID,
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 } 96 }
98 } 97 }
99 98
100 BTH_ADDR ConvertToBthAddr(const std::string& address) { 99 BTH_ADDR ConvertToBthAddr(const std::string& address) {
101 BTH_ADDR bth_addr = 0; 100 BTH_ADDR bth_addr = 0;
102 std::string numbers_only; 101 std::string numbers_only;
103 for (int i = 0; i < 6; ++i) { 102 for (int i = 0; i < 6; ++i) {
104 numbers_only += address.substr(i * 3, 2); 103 numbers_only += address.substr(i * 3, 2);
105 } 104 }
106 105
107 std::vector<uint8> address_bytes; 106 std::vector<uint8_t> address_bytes;
108 base::HexStringToBytes(numbers_only, &address_bytes); 107 base::HexStringToBytes(numbers_only, &address_bytes);
109 int byte_position = 0; 108 int byte_position = 0;
110 for (std::vector<uint8>::reverse_iterator iter = address_bytes.rbegin(); 109 for (std::vector<uint8_t>::reverse_iterator iter = address_bytes.rbegin();
111 iter != address_bytes.rend(); 110 iter != address_bytes.rend(); ++iter) {
112 ++iter) {
113 bth_addr += *iter * pow(256.0, byte_position); 111 bth_addr += *iter * pow(256.0, byte_position);
114 byte_position++; 112 byte_position++;
115 } 113 }
116 return bth_addr; 114 return bth_addr;
117 } 115 }
118 116
119 } // namespace 117 } // namespace
120 118
121 namespace device { 119 namespace device {
122 120
123 BluetoothServiceRecordWin::BluetoothServiceRecordWin( 121 BluetoothServiceRecordWin::BluetoothServiceRecordWin(
124 const std::string& device_address, 122 const std::string& device_address,
125 const std::string& name, 123 const std::string& name,
126 const std::vector<uint8>& sdp_bytes, 124 const std::vector<uint8_t>& sdp_bytes,
127 const BluetoothUUID& gatt_uuid) 125 const BluetoothUUID& gatt_uuid)
128 : device_bth_addr_(ConvertToBthAddr(device_address)), 126 : device_bth_addr_(ConvertToBthAddr(device_address)),
129 device_address_(device_address), 127 device_address_(device_address),
130 name_(name), 128 name_(name),
131 uuid_(gatt_uuid), 129 uuid_(gatt_uuid),
132 supports_rfcomm_(false), 130 supports_rfcomm_(false),
133 rfcomm_channel_(0xFF) { 131 rfcomm_channel_(0xFF) {
134 // Bluetooth 2.0 132 // Bluetooth 2.0
135 if (sdp_bytes.size() > 0) { 133 if (sdp_bytes.size() > 0) {
136 LPBYTE blob_data = const_cast<LPBYTE>(&sdp_bytes[0]); 134 LPBYTE blob_data = const_cast<LPBYTE>(&sdp_bytes[0]);
(...skipping 16 matching lines...) Expand all
153 } 151 }
154 152
155 bool BluetoothServiceRecordWin::IsEqual( 153 bool BluetoothServiceRecordWin::IsEqual(
156 const BluetoothServiceRecordWin& other) { 154 const BluetoothServiceRecordWin& other) {
157 return device_address_ == other.device_address_ && name_ == other.name_ && 155 return device_address_ == other.device_address_ && name_ == other.name_ &&
158 uuid_ == other.uuid_ && supports_rfcomm_ == other.supports_rfcomm_ && 156 uuid_ == other.uuid_ && supports_rfcomm_ == other.supports_rfcomm_ &&
159 rfcomm_channel_ == other.rfcomm_channel_; 157 rfcomm_channel_ == other.rfcomm_channel_;
160 } 158 }
161 159
162 } // namespace device 160 } // namespace device
OLDNEW
« no previous file with comments | « device/bluetooth/bluetooth_service_record_win.h ('k') | device/bluetooth/bluetooth_service_record_win_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698