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