summaryrefslogtreecommitdiffstats
path: root/device/bluetooth/bluetooth_uuid.h
diff options
context:
space:
mode:
authorarmansito@chromium.org <armansito@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-04-04 04:10:38 +0000
committerarmansito@chromium.org <armansito@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-04-04 04:10:38 +0000
commit8148ad4c315725f995e52f91113203f0135add1b (patch)
treec60f826a8201e49537874e8f9ba399af1f3dbcaa /device/bluetooth/bluetooth_uuid.h
parentb250f01e51eae5377a3419048b0fed2a17d4dea9 (diff)
downloadchromium_src-8148ad4c315725f995e52f91113203f0135add1b.zip
chromium_src-8148ad4c315725f995e52f91113203f0135add1b.tar.gz
chromium_src-8148ad4c315725f995e52f91113203f0135add1b.tar.bz2
device/bluetooth: Rename device::bluetooth_utils::UUID to device::BluetoothUUID
Moved bluetooth_utils::UUID into its own file called bluetooth_uuid.h/cc as class BluetoothUUID. This effectively removes the usage of bluetooth_utils::CanonicalUuid. This is a post-revert reupload of https://codereview.chromium.org/220323004/. The CQ didn't run any Mac bots that build and run device_unittests. BUG=358874 TEST=device_unittests, browser_tests Review URL: https://codereview.chromium.org/224893002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@261663 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'device/bluetooth/bluetooth_uuid.h')
-rw-r--r--device/bluetooth/bluetooth_uuid.h94
1 files changed, 94 insertions, 0 deletions
diff --git a/device/bluetooth/bluetooth_uuid.h b/device/bluetooth/bluetooth_uuid.h
new file mode 100644
index 0000000..282c8ba
--- /dev/null
+++ b/device/bluetooth/bluetooth_uuid.h
@@ -0,0 +1,94 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef DEVICE_BLUETOOTH_BLUETOOTH_UUID_H_
+#define DEVICE_BLUETOOTH_BLUETOOTH_UUID_H_
+
+#include <string>
+
+namespace device {
+
+// Opaque wrapper around a Bluetooth UUID. Instances of UUID represent the
+// 128-bit universally unique identifiers (UUIDs) of profiles and attributes
+// used in Bluetooth based communication, such as a peripheral's services,
+// characteristics, and characteristic descriptors. An instance are
+// constructed using a string representing 16, 32, or 128 bit UUID formats.
+class BluetoothUUID {
+ public:
+ // Possible representation formats used during construction.
+ enum Format {
+ kFormatInvalid,
+ kFormat16Bit,
+ kFormat32Bit,
+ kFormat128Bit
+ };
+
+ // Single argument constructor. |uuid| can be a 16, 32, or 128 bit UUID
+ // represented as a 4, 8, or 36 character string with the following
+ // formats:
+ // XXXX
+ // 0xXXXX
+ // XXXXXXXX
+ // 0xXXXXXXXX
+ // XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
+ //
+ // 16 and 32 bit UUIDs will be internally converted to a 128 bit UUID using
+ // the base UUID defined in the Bluetooth specification, hence custom UUIDs
+ // should be provided in the 128-bit format. If |uuid| is in an unsupported
+ // format, the result might be invalid. Use IsValid to check for validity
+ // after construction.
+ explicit BluetoothUUID(const std::string& uuid);
+
+ // Default constructor does nothing. Since BluetoothUUID is copyable, this
+ // constructor is useful for initializing member variables and assigning a
+ // value to them later. The default constructor will initialize an invalid
+ // UUID by definition and the string accessors will return an empty string.
+ BluetoothUUID();
+ virtual ~BluetoothUUID();
+
+ // Returns true, if the UUID is in a valid canonical format.
+ bool IsValid() const;
+
+ // Returns the representation format of the UUID. This reflects the format
+ // that was provided during construction.
+ Format format() const { return format_; }
+
+ // Returns the value of the UUID as a string. The representation format is
+ // based on what was passed in during construction. For the supported sizes,
+ // this representation can have the following formats:
+ // - 16 bit: XXXX
+ // - 32 bit: XXXXXXXX
+ // - 128 bit: XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
+ // where X is a lowercase hex digit.
+ const std::string& value() const { return value_; }
+
+ // Returns the underlying 128-bit value as a string in the following format:
+ // XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
+ // where X is a lowercase hex digit.
+ const std::string& canonical_value() const { return canonical_value_; }
+
+ // Permit sufficient comparison to allow a UUID to be used as a key in a
+ // std::map.
+ bool operator<(const BluetoothUUID& uuid) const;
+
+ // Equality operators.
+ bool operator==(const BluetoothUUID& uuid) const;
+ bool operator!=(const BluetoothUUID& uuid) const;
+
+ private:
+ // String representation of the UUID that was used during construction. For
+ // the supported sizes, this representation can have the following formats:
+ // - 16 bit: XXXX
+ // - 32 bit: XXXXXXXX
+ // - 128 bit: XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
+ Format format_;
+ std::string value_;
+
+ // The 128-bit string representation of the UUID.
+ std::string canonical_value_;
+};
+
+} // namespace device
+
+#endif // DEVICE_BLUETOOTH_BLUETOOTH_UUID_H_