OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_UTILS_H_ | |
6 #define DEVICE_BLUETOOTH_BLUETOOTH_UTILS_H_ | |
7 | |
8 #include <string> | |
9 | |
10 #include "base/basictypes.h" | |
11 | |
12 namespace device { | |
13 namespace bluetooth_utils { | |
14 | |
15 // Opaque wrapper around a Bluetooth UUID. Instances of UUID represent the | |
16 // 128-bit universally unique identifiers (UUIDs) of profiles and attributes | |
17 // used in Bluetooth based communication, such as a peripheral's services, | |
18 // characteristics, and characteristic descriptors. An instance are | |
19 // constructed using a string representing 16, 32, or 128 bit UUID formats. | |
20 class UUID { | |
21 public: | |
22 // Possible representation formats used during construction. | |
23 enum Format { | |
24 kFormatInvalid, | |
25 kFormat16Bit, | |
26 kFormat32Bit, | |
27 kFormat128Bit | |
28 }; | |
29 | |
30 // 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 | |
32 // formats: | |
33 // XXXX | |
34 // 0xXXXX | |
35 // XXXXXXXX | |
36 // 0xXXXXXXXX | |
37 // XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX | |
38 // | |
39 // 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 | |
41 // 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 | |
43 // after construction. | |
44 explicit UUID(const std::string& uuid); | |
45 ~UUID(); | |
46 | |
47 // Returns true, if the UUID is in a valid canonical format. | |
48 bool IsValid() const; | |
49 | |
50 // Returns the representation format of the UUID. This reflects the format | |
51 // that was provided during construction. | |
52 Format format() const { return format_; } | |
53 | |
54 // 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, | |
56 // this representation can have the following formats: | |
57 // - 16 bit: XXXX | |
58 // - 32 bit: XXXXXXXX | |
59 // - 128 bit: XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX | |
60 // where X is a lowercase hex digit. | |
61 const std::string& value() const { return value_; } | |
62 | |
63 // Returns the underlying 128-bit value as a string in the following format: | |
64 // XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX | |
65 // where X is a lowercase hex digit. | |
66 const std::string& canonical_value() const { return canonical_value_; } | |
67 | |
68 // Permit sufficient comparison to allow a UUID to be used as a key in a | |
69 // std::map. | |
70 bool operator<(const UUID& uuid) const; | |
71 | |
72 // Equality operators. | |
73 bool operator==(const UUID& uuid) const; | |
74 bool operator!=(const UUID& uuid) const; | |
75 | |
76 private: | |
77 // String representation of the UUID that was used during construction. For | |
78 // the supported sizes, this representation can have the following formats: | |
79 // - 16 bit: XXXX | |
80 // - 32 bit: XXXXXXXX | |
81 // - 128 bit: XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX | |
82 Format format_; | |
83 std::string value_; | |
84 | |
85 // The 128-bit string representation of the UUID. | |
86 std::string canonical_value_; | |
87 }; | |
88 | |
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 | |
105 | |
106 #endif // DEVICE_BLUETOOTH_BLUETOOTH_UTILS_H_ | |
OLD | NEW |