OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/chromeos/bluetooth/bluetooth_service_record.h" | 5 #include "chrome/browser/chromeos/bluetooth/bluetooth_service_record_dbus.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/string_number_conversions.h" | 11 #include "base/string_number_conversions.h" |
12 #include "chrome/browser/chromeos/bluetooth/bluetooth_utils.h" | 12 #include "chrome/browser/chromeos/bluetooth/bluetooth_utils.h" |
13 #include "third_party/libxml/chromium/libxml_utils.h" | 13 #include "third_party/libxml/chromium/libxml_utils.h" |
14 | 14 |
15 namespace { | 15 namespace { |
(...skipping 23 matching lines...) Expand all Loading... |
39 reader->NodeAttribute(kValueAttribute, value_out); | 39 reader->NodeAttribute(kValueAttribute, value_out); |
40 return true; | 40 return true; |
41 } | 41 } |
42 return false; | 42 return false; |
43 } | 43 } |
44 | 44 |
45 } // namespace | 45 } // namespace |
46 | 46 |
47 namespace chromeos { | 47 namespace chromeos { |
48 | 48 |
49 BluetoothServiceRecord::BluetoothServiceRecord( | 49 BluetoothServiceRecordDBus::BluetoothServiceRecordDBus( |
50 const std::string& address, | 50 const std::string& address, |
51 const std::string& xml_data) | 51 const std::string& xml_data) |
52 : address_(address), | 52 : address_(address), |
53 supports_rfcomm_(false) { | 53 supports_rfcomm_(false) { |
54 | 54 |
55 XmlReader reader; | 55 XmlReader reader; |
56 if (!reader.Load(xml_data)) | 56 if (!reader.Load(xml_data)) |
57 return; | 57 return; |
58 | 58 |
59 while (AdvanceToTag(&reader, kAttributeNode)) { | 59 while (AdvanceToTag(&reader, kAttributeNode)) { |
60 std::string id; | 60 std::string id; |
61 if (reader.NodeAttribute(kIdAttribute, &id)) { | 61 if (reader.NodeAttribute(kIdAttribute, &id)) { |
62 if (id == kSdpNameId) { | 62 if (id == kSdpNameId) { |
63 ExtractTextValue(&reader, &name_); | 63 ExtractTextValue(&reader, &name_); |
64 } else if (id == kProtocolDescriptorListId) { | 64 } else if (id == kProtocolDescriptorListId) { |
65 if (AdvanceToTag(&reader, kSequenceNode)) { | 65 if (AdvanceToTag(&reader, kSequenceNode)) { |
66 ExtractChannels(&reader); | 66 ExtractChannels(&reader); |
67 } | 67 } |
68 } else if (id == kUuidId) { | 68 } else if (id == kUuidId) { |
69 if (AdvanceToTag(&reader, kSequenceNode)) { | 69 if (AdvanceToTag(&reader, kSequenceNode)) { |
70 ExtractUuid(&reader); | 70 ExtractUuid(&reader); |
71 } | 71 } |
72 } | 72 } |
73 } | 73 } |
74 // We don't care about anything else here, so find the closing tag | 74 // We don't care about anything else here, so find the closing tag |
75 AdvanceToTag(&reader, kAttributeNode); | 75 AdvanceToTag(&reader, kAttributeNode); |
76 } | 76 } |
77 } | 77 } |
78 | 78 |
79 void BluetoothServiceRecord::ExtractChannels(XmlReader* reader) { | 79 const std::string& BluetoothServiceRecordDBus::name() const { |
| 80 return name_; |
| 81 } |
| 82 |
| 83 const std::string& BluetoothServiceRecordDBus::uuid() const { |
| 84 return uuid_; |
| 85 } |
| 86 |
| 87 void BluetoothServiceRecordDBus::ExtractChannels(XmlReader* reader) { |
80 const int start_depth = reader->Depth(); | 88 const int start_depth = reader->Depth(); |
81 do { | 89 do { |
82 if (reader->NodeName() == kSequenceNode) { | 90 if (reader->NodeName() == kSequenceNode) { |
83 if (AdvanceToTag(reader, kUuidNode)) { | 91 if (AdvanceToTag(reader, kUuidNode)) { |
84 std::string type; | 92 std::string type; |
85 if (reader->NodeAttribute(kValueAttribute, &type) && | 93 if (reader->NodeAttribute(kValueAttribute, &type) && |
86 type == kRfcommUuid) { | 94 type == kRfcommUuid) { |
87 if (AdvanceToTag(reader, kUint8Node)) { | 95 if (AdvanceToTag(reader, kUint8Node)) { |
88 std::string channel_string; | 96 std::string channel_string; |
89 if (reader->NodeAttribute(kValueAttribute, &channel_string)) { | 97 if (reader->NodeAttribute(kValueAttribute, &channel_string)) { |
90 std::vector<uint8> channel_bytes; | 98 std::vector<uint8> channel_bytes; |
91 if (base::HexStringToBytes(channel_string.substr(2), | 99 if (base::HexStringToBytes(channel_string.substr(2), |
92 &channel_bytes)) { | 100 &channel_bytes)) { |
93 if (channel_bytes.size() == 1) { | 101 if (channel_bytes.size() == 1) { |
94 rfcomm_channel_ = channel_bytes[0]; | 102 rfcomm_channel_ = channel_bytes[0]; |
95 supports_rfcomm_ = true; | 103 supports_rfcomm_ = true; |
96 } | 104 } |
97 } | 105 } |
98 } | 106 } |
99 } | 107 } |
100 } | 108 } |
101 } | 109 } |
102 } | 110 } |
103 } while (AdvanceToTag(reader, kSequenceNode) && | 111 } while (AdvanceToTag(reader, kSequenceNode) && |
104 reader->Depth() != start_depth); | 112 reader->Depth() != start_depth); |
105 } | 113 } |
106 | 114 |
107 void BluetoothServiceRecord::ExtractUuid(XmlReader* reader) { | 115 void BluetoothServiceRecordDBus::ExtractUuid(XmlReader* reader) { |
108 const int start_depth = reader->Depth(); | 116 const int start_depth = reader->Depth(); |
109 do { | 117 do { |
110 if (reader->NodeName() == kSequenceNode) { | 118 if (reader->NodeName() == kSequenceNode) { |
111 if (AdvanceToTag(reader, kUuidNode)) { | 119 if (AdvanceToTag(reader, kUuidNode)) { |
112 if (!reader->NodeAttribute(kValueAttribute, &uuid_)) | 120 if (!reader->NodeAttribute(kValueAttribute, &uuid_)) |
113 uuid_.clear(); | 121 uuid_.clear(); |
114 } | 122 } |
115 } | 123 } |
116 } while (AdvanceToTag(reader, kSequenceNode) && | 124 } while (AdvanceToTag(reader, kSequenceNode) && |
117 reader->Depth() != start_depth); | 125 reader->Depth() != start_depth); |
118 | 126 |
119 uuid_ = bluetooth_utils::CanonicalUuid(uuid_); | 127 uuid_ = bluetooth_utils::CanonicalUuid(uuid_); |
120 } | 128 } |
121 | 129 |
122 } // namespace chromeos | 130 } // namespace chromeos |
OLD | NEW |