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

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

Issue 285633003: Bluetooth UUIDs should be case-insensitive. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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
« no previous file with comments | « no previous file | device/bluetooth/bluetooth_uuid.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 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_UUID_H_ 5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_UUID_H_
6 #define DEVICE_BLUETOOTH_BLUETOOTH_UUID_H_ 6 #define DEVICE_BLUETOOTH_BLUETOOTH_UUID_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 namespace device { 10 namespace device {
11 11
12 // Opaque wrapper around a Bluetooth UUID. Instances of UUID represent the 12 // Opaque wrapper around a Bluetooth UUID. Instances of UUID represent the
13 // 128-bit universally unique identifiers (UUIDs) of profiles and attributes 13 // 128-bit universally unique identifiers (UUIDs) of profiles and attributes
14 // used in Bluetooth based communication, such as a peripheral's services, 14 // used in Bluetooth based communication, such as a peripheral's services,
15 // characteristics, and characteristic descriptors. An instance are 15 // characteristics, and characteristic descriptors. An instance are
16 // 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.
17 class BluetoothUUID { 17 class BluetoothUUID {
18 public: 18 public:
19 // Possible representation formats used during construction. 19 // Possible representation formats used during construction.
20 enum Format { 20 enum Format {
21 kFormatInvalid, 21 kFormatInvalid,
22 kFormat16Bit, 22 kFormat16Bit,
23 kFormat32Bit, 23 kFormat32Bit,
24 kFormat128Bit 24 kFormat128Bit
25 }; 25 };
26 26
27 // 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
28 // 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
29 // formats: 29 // formats:
30 // XXXX 30 // xxxx
31 // 0xXXXX 31 // 0xxxxx
32 // XXXXXXXX 32 // xxxxxxxx
33 // 0xXXXXXXXX 33 // 0xxxxxxxxx
34 // XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX 34 // xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
35 // 35 //
36 // 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
37 // the base UUID defined in the Bluetooth specification, hence custom UUIDs 37 // the base UUID defined in the Bluetooth specification, hence custom UUIDs
38 // 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
39 // 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
40 // after construction. 40 // after construction.
41 explicit BluetoothUUID(const std::string& uuid); 41 explicit BluetoothUUID(const std::string& uuid);
42 42
43 // Default constructor does nothing. Since BluetoothUUID is copyable, this 43 // Default constructor does nothing. Since BluetoothUUID is copyable, this
44 // constructor is useful for initializing member variables and assigning a 44 // constructor is useful for initializing member variables and assigning a
45 // value to them later. The default constructor will initialize an invalid 45 // value to them later. The default constructor will initialize an invalid
46 // UUID by definition and the string accessors will return an empty string. 46 // UUID by definition and the string accessors will return an empty string.
47 BluetoothUUID(); 47 BluetoothUUID();
48 virtual ~BluetoothUUID(); 48 virtual ~BluetoothUUID();
49 49
50 // Returns true, if the UUID is in a valid canonical format. 50 // Returns true, if the UUID is in a valid canonical format.
51 bool IsValid() const; 51 bool IsValid() const;
52 52
53 // Returns the representation format of the UUID. This reflects the format 53 // Returns the representation format of the UUID. This reflects the format
54 // that was provided during construction. 54 // that was provided during construction.
55 Format format() const { return format_; } 55 Format format() const { return format_; }
56 56
57 // Returns the value of the UUID as a string. The representation format is 57 // Returns the value of the UUID as a string. The representation format is
58 // based on what was passed in during construction. For the supported sizes, 58 // based on what was passed in during construction. For the supported sizes,
59 // this representation can have the following formats: 59 // this representation can have the following formats:
60 // - 16 bit: XXXX 60 // - 16 bit: xxxx
61 // - 32 bit: XXXXXXXX 61 // - 32 bit: xxxxxxxx
62 // - 128 bit: XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX 62 // - 128 bit: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
63 // where X is a lowercase hex digit. 63 // where x is a lowercase hex digit.
64 const std::string& value() const { return value_; } 64 const std::string& value() const { return value_; }
65 65
66 // Returns the underlying 128-bit value as a string in the following format: 66 // Returns the underlying 128-bit value as a string in the following format:
67 // XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX 67 // xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
68 // where X is a lowercase hex digit. 68 // where x is a lowercase hex digit.
69 const std::string& canonical_value() const { return canonical_value_; } 69 const std::string& canonical_value() const { return canonical_value_; }
70 70
71 // Permit sufficient comparison to allow a UUID to be used as a key in a 71 // Permit sufficient comparison to allow a UUID to be used as a key in a
72 // std::map. 72 // std::map.
73 bool operator<(const BluetoothUUID& uuid) const; 73 bool operator<(const BluetoothUUID& uuid) const;
74 74
75 // Equality operators. 75 // Equality operators.
76 bool operator==(const BluetoothUUID& uuid) const; 76 bool operator==(const BluetoothUUID& uuid) const;
77 bool operator!=(const BluetoothUUID& uuid) const; 77 bool operator!=(const BluetoothUUID& uuid) const;
78 78
79 private: 79 private:
80 // String representation of the UUID that was used during construction. For 80 // String representation of the UUID that was used during construction. For
81 // the supported sizes, this representation can have the following formats: 81 // the supported sizes, this representation can have the following formats:
82 // - 16 bit: XXXX 82 // - 16 bit: xxxx
83 // - 32 bit: XXXXXXXX 83 // - 32 bit: xxxxxxxx
84 // - 128 bit: XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX 84 // - 128 bit: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
85 Format format_; 85 Format format_;
86 std::string value_; 86 std::string value_;
87 87
88 // The 128-bit string representation of the UUID. 88 // The 128-bit string representation of the UUID.
89 std::string canonical_value_; 89 std::string canonical_value_;
90 }; 90 };
91 91
92 // This is required by gtest to print a readable output on test failures. 92 // This is required by gtest to print a readable output on test failures.
93 void PrintTo(const BluetoothUUID& uuid, std::ostream* out); 93 void PrintTo(const BluetoothUUID& uuid, std::ostream* out);
94 94
95 } // namespace device 95 } // namespace device
96 96
97 #endif // DEVICE_BLUETOOTH_BLUETOOTH_UUID_H_ 97 #endif // DEVICE_BLUETOOTH_BLUETOOTH_UUID_H_
OLDNEW
« no previous file with comments | « no previous file | device/bluetooth/bluetooth_uuid.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698