Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / device / bluetooth / bluetooth_uuid.h
blob5c2fc8a3b9c0f05053baab9d0a773f0954c65ea7
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_
8 #include <string>
10 namespace device {
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.
17 class BluetoothUUID {
18 public:
19 // Possible representation formats used during construction.
20 enum Format {
21 kFormatInvalid,
22 kFormat16Bit,
23 kFormat32Bit,
24 kFormat128Bit
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
29 // formats:
30 // xxxx
31 // 0xxxxx
32 // xxxxxxxx
33 // 0xxxxxxxxx
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.
47 BluetoothUUID();
48 virtual ~BluetoothUUID();
50 // Returns true, if the UUID is in a valid canonical format.
51 bool IsValid() const;
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:
60 // - 16 bit: xxxx
61 // - 32 bit: xxxxxxxx
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
72 // std::map.
73 bool operator<(const BluetoothUUID& uuid) const;
75 // Equality operators.
76 bool operator==(const BluetoothUUID& uuid) const;
77 bool operator!=(const BluetoothUUID& uuid) const;
79 private:
80 // String representation of the UUID that was used during construction. For
81 // the supported sizes, this representation can have the following formats:
82 // - 16 bit: xxxx
83 // - 32 bit: xxxxxxxx
84 // - 128 bit: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
85 Format format_;
86 std::string value_;
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);
95 } // namespace device
97 #endif // DEVICE_BLUETOOTH_BLUETOOTH_UUID_H_