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

Side by Side Diff: device/bluetooth/bluetooth_uuid.h

Issue 220323004: device/bluetooth: Rename device::bluetooth_utils::UUID to device::BluetoothUUID (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 8 months 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2014 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 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_UTILS_H_ 5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_UUID_H_
6 #define DEVICE_BLUETOOTH_BLUETOOTH_UTILS_H_ 6 #define DEVICE_BLUETOOTH_BLUETOOTH_UUID_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/basictypes.h"
11
12 namespace device { 10 namespace device {
13 namespace bluetooth_utils {
14 11
15 // Opaque wrapper around a Bluetooth UUID. Instances of UUID represent the 12 // Opaque wrapper around a Bluetooth UUID. Instances of UUID represent the
16 // 128-bit universally unique identifiers (UUIDs) of profiles and attributes 13 // 128-bit universally unique identifiers (UUIDs) of profiles and attributes
17 // used in Bluetooth based communication, such as a peripheral's services, 14 // used in Bluetooth based communication, such as a peripheral's services,
18 // characteristics, and characteristic descriptors. An instance are 15 // characteristics, and characteristic descriptors. An instance are
19 // constructed using a string representing 16, 32, or 128 bit UUID formats. 16 // constructed using a string representing 16, 32, or 128 bit UUID formats.
20 class UUID { 17 class BluetoothUUID {
21 public: 18 public:
22 // Possible representation formats used during construction. 19 // Possible representation formats used during construction.
23 enum Format { 20 enum Format {
24 kFormatInvalid, 21 kFormatInvalid,
25 kFormat16Bit, 22 kFormat16Bit,
26 kFormat32Bit, 23 kFormat32Bit,
27 kFormat128Bit 24 kFormat128Bit
28 }; 25 };
29 26
30 // Single argument constructor. |uuid| can be a 16, 32, or 128 bit UUID 27 // Single argument constructor. |uuid| can be a 16, 32, or 128 bit UUID
31 // represented as a 4, 8, or 36 character string with the following 28 // represented as a 4, 8, or 36 character string with the following
32 // formats: 29 // formats:
33 // XXXX 30 // XXXX
34 // 0xXXXX 31 // 0xXXXX
35 // XXXXXXXX 32 // XXXXXXXX
36 // 0xXXXXXXXX 33 // 0xXXXXXXXX
37 // XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX 34 // XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
38 // 35 //
39 // 16 and 32 bit UUIDs will be internally converted to a 128 bit UUID using 36 // 16 and 32 bit UUIDs will be internally converted to a 128 bit UUID using
40 // the base UUID defined in the Bluetooth specification, hence custom UUIDs 37 // the base UUID defined in the Bluetooth specification, hence custom UUIDs
41 // should be provided in the 128-bit format. If |uuid| is in an unsupported 38 // should be provided in the 128-bit format. If |uuid| is in an unsupported
42 // format, the result might be invalid. Use IsValid to check for validity 39 // format, the result might be invalid. Use IsValid to check for validity
43 // after construction. 40 // after construction.
44 explicit UUID(const std::string& uuid); 41 explicit BluetoothUUID(const std::string& uuid);
45 ~UUID(); 42 ~BluetoothUUID();
46 43
47 // Returns true, if the UUID is in a valid canonical format. 44 // Returns true, if the UUID is in a valid canonical format.
48 bool IsValid() const; 45 bool IsValid() const;
49 46
50 // Returns the representation format of the UUID. This reflects the format 47 // Returns the representation format of the UUID. This reflects the format
51 // that was provided during construction. 48 // that was provided during construction.
52 Format format() const { return format_; } 49 Format format() const { return format_; }
53 50
54 // Returns the value of the UUID as a string. The representation format is 51 // Returns the value of the UUID as a string. The representation format is
55 // based on what was passed in during construction. For the supported sizes, 52 // based on what was passed in during construction. For the supported sizes,
56 // this representation can have the following formats: 53 // this representation can have the following formats:
57 // - 16 bit: XXXX 54 // - 16 bit: XXXX
58 // - 32 bit: XXXXXXXX 55 // - 32 bit: XXXXXXXX
59 // - 128 bit: XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX 56 // - 128 bit: XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
60 // where X is a lowercase hex digit. 57 // where X is a lowercase hex digit.
61 const std::string& value() const { return value_; } 58 const std::string& value() const { return value_; }
62 59
63 // Returns the underlying 128-bit value as a string in the following format: 60 // Returns the underlying 128-bit value as a string in the following format:
64 // XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX 61 // XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
65 // where X is a lowercase hex digit. 62 // where X is a lowercase hex digit.
66 const std::string& canonical_value() const { return canonical_value_; } 63 const std::string& canonical_value() const { return canonical_value_; }
67 64
68 // Permit sufficient comparison to allow a UUID to be used as a key in a 65 // Permit sufficient comparison to allow a UUID to be used as a key in a
69 // std::map. 66 // std::map.
70 bool operator<(const UUID& uuid) const; 67 bool operator<(const BluetoothUUID& uuid) const;
71 68
72 // Equality operators. 69 // Equality operators.
73 bool operator==(const UUID& uuid) const; 70 bool operator==(const BluetoothUUID& uuid) const;
74 bool operator!=(const UUID& uuid) const; 71 bool operator!=(const BluetoothUUID& uuid) const;
75 72
76 private: 73 private:
77 // String representation of the UUID that was used during construction. For 74 // String representation of the UUID that was used during construction. For
78 // the supported sizes, this representation can have the following formats: 75 // the supported sizes, this representation can have the following formats:
79 // - 16 bit: XXXX 76 // - 16 bit: XXXX
80 // - 32 bit: XXXXXXXX 77 // - 32 bit: XXXXXXXX
81 // - 128 bit: XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX 78 // - 128 bit: XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
82 Format format_; 79 Format format_;
83 std::string value_; 80 std::string value_;
84 81
85 // The 128-bit string representation of the UUID. 82 // The 128-bit string representation of the UUID.
86 std::string canonical_value_; 83 std::string canonical_value_;
87 }; 84 };
88 85
89 // DEPRECATED. Use bluetooth_utils::UUID instead.
90 //
91 // Takes a 4, 8 or 36 character UUID, validates it and returns it in 36
92 // character format with all hex digits lower case. If |uuid| is invalid, the
93 // empty string is returned.
94 //
95 // Valid inputs are:
96 // XXXX
97 // 0xXXXX
98 // XXXXXXXX
99 // 0xXXXXXXXX
100 // XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
101 std::string CanonicalUuid(std::string uuid);
102
103 } // namespace bluetooth_utils
104 } // namespace device 86 } // namespace device
105 87
106 #endif // DEVICE_BLUETOOTH_BLUETOOTH_UTILS_H_ 88 #endif // DEVICE_BLUETOOTH_BLUETOOTH_UUID_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698