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.
5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_UTILS_H_
6 #define DEVICE_BLUETOOTH_BLUETOOTH_UTILS_H_
10 #include "base/basictypes.h"
13 namespace bluetooth_utils
{
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.
22 // Possible representation formats used during construction.
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
37 // XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
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
);
47 // Returns true, if the UUID is in a valid canonical format.
50 // Returns the representation format of the UUID. This reflects the format
51 // that was provided during construction.
52 Format
format() const { return format_
; }
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:
59 // - 128 bit: XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
60 // where X is a lowercase hex digit.
61 const std::string
& value() const { return value_
; }
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_
; }
68 // Permit sufficient comparison to allow a UUID to be used as a key in a
70 bool operator<(const UUID
& uuid
) const;
72 // Equality operators.
73 bool operator==(const UUID
& uuid
) const;
74 bool operator!=(const UUID
& uuid
) const;
77 // String representation of the UUID that was used during construction. For
78 // the supported sizes, this representation can have the following formats:
81 // - 128 bit: XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
85 // The 128-bit string representation of the UUID.
86 std::string canonical_value_
;
89 // DEPRECATED. Use bluetooth_utils::UUID instead.
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.
100 // XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
101 std::string
CanonicalUuid(std::string uuid
);
103 } // namespace bluetooth_utils
104 } // namespace device
106 #endif // DEVICE_BLUETOOTH_BLUETOOTH_UTILS_H_