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
3 // found in the LICENSE file.
5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_UUID_H_
6 #define DEVICE_BLUETOOTH_BLUETOOTH_UUID_H_
12 // Opaque wrapper around a Bluetooth UUID. Instances of UUID represent the
13 // 128-bit universally unique identifiers (UUIDs) of profiles and attributes
14 // used in Bluetooth based communication, such as a peripheral's services,
15 // characteristics, and characteristic descriptors. An instance are
16 // constructed using a string representing 16, 32, or 128 bit UUID formats.
19 // Possible representation formats used during construction.
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
34 // xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
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
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
40 // after construction.
41 explicit BluetoothUUID(const std::string
& uuid
);
43 // Default constructor does nothing. Since BluetoothUUID is copyable, this
44 // constructor is useful for initializing member variables and assigning a
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.
48 virtual ~BluetoothUUID();
50 // Returns true, if the UUID is in a valid canonical format.
53 // Returns the representation format of the UUID. This reflects the format
54 // that was provided during construction.
55 Format
format() const { return format_
; }
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,
59 // this representation can have the following formats:
62 // - 128 bit: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
63 // where x is a lowercase hex digit.
64 const std::string
& value() const { return value_
; }
66 // Returns the underlying 128-bit value as a string in the following format:
67 // xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
68 // where x is a lowercase hex digit.
69 const std::string
& canonical_value() const { return canonical_value_
; }
71 // Permit sufficient comparison to allow a UUID to be used as a key in a
73 bool operator<(const BluetoothUUID
& uuid
) const;
75 // Equality operators.
76 bool operator==(const BluetoothUUID
& uuid
) const;
77 bool operator!=(const BluetoothUUID
& uuid
) const;
80 // String representation of the UUID that was used during construction. For
81 // the supported sizes, this representation can have the following formats:
84 // - 128 bit: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
88 // The 128-bit string representation of the UUID.
89 std::string canonical_value_
;
92 // This is required by gtest to print a readable output on test failures.
93 void PrintTo(const BluetoothUUID
& uuid
, std::ostream
* out
);
97 #endif // DEVICE_BLUETOOTH_BLUETOOTH_UUID_H_