[Bluetooth] Add uuid_in_source_format field to UUID class 92/229792/3
authorPawel Wasowski <p.wasowski2@samsung.com>
Fri, 3 Apr 2020 09:49:12 +0000 (11:49 +0200)
committerPawel Wasowski <p.wasowski2@samsung.com>
Fri, 3 Apr 2020 10:39:04 +0000 (12:39 +0200)
Some legacy functions have returned UUID in the very same format,
they get it from the user. In order to preserve backward compatibility,
we cannot return this UUID in another form and we have to keep
the UUID in source format in UUID object.

Change-Id: Ia2668aaa331ddfd3331ffe7c42133e8a97cb06bc
Signed-off-by: Pawel Wasowski <p.wasowski2@samsung.com>
src/bluetooth/ut/uuid.cc
src/bluetooth/uuid.cc
src/bluetooth/uuid.h

index 055884617cce07dc30e4a0ed69d293230d3c5aeb..a7081f6891b022085b896684941ab5bf672998c3 100644 (file)
@@ -268,6 +268,10 @@ TEST_F(UUIDTest, ToXXXBits) {
         << "Failed for UUID: " << std::get<Format128>(uuid) << " expected: ("
         << std::get<Format128>(uuid) << ")"
         << " got: (" << uuid_obj->uuid_128_bit;
+    EXPECT_EQ(uuid_obj->uuid_in_source_format, std::get<StringInit>(uuid))
+        << "Failed for UUID: " << std::get<Format128>(uuid) << " expected: ("
+        << std::get<StringInit>(uuid) << ")"
+        << " got: (" << uuid_obj->uuid_in_source_format;
   }
 }
 
index b692b883f5fff0f56aa1823666f1c3543eb45780..9945c24e49fa3bb11571017c1b544490ea8dad8c 100644 (file)
@@ -48,8 +48,10 @@ namespace extension {
 
 namespace bluetooth {
 
-UUID::UUID(std::string&& uuid_128_bit) : uuid_128_bit{uuid_128_bit} {
-  ScopeLogger("Input: %s", uuid_128_bit.c_str());
+UUID::UUID(const std::string& uuid_in_source_format, std::string&& uuid_128_bit)
+    : uuid_in_source_format{uuid_in_source_format}, uuid_128_bit{std::move(uuid_128_bit)} {
+  ScopeLogger("UUID in source format: %s; 128 bit UUID: %s", uuid_in_source_format.c_str(),
+              uuid_128_bit.c_str());
 }
 
 optional<UUID> UUID::create(const std::string& uuid) {
@@ -60,7 +62,7 @@ optional<UUID> UUID::create(const std::string& uuid) {
     return NO_UUID;
   }
 
-  return UUID{std::move(uuid_128_bit)};
+  return UUID{uuid, std::move(uuid_128_bit)};
 }
 
 optional<UUID> UUID::createFromGatt(const bt_gatt_h gatt_handle) {
index ddfeb4798a8276497246646b98710882a02171b2..ac08c153899f0a119b6ad6168bb7c1ca5d2fae12 100644 (file)
@@ -84,6 +84,19 @@ struct UUID {
   std::string ShortestPossibleFormat() const;
 
   bool operator==(const UUID&) const;
+
+  /*
+   * Some legacy functions, i.e. implementation of BluetoothLEDevice::getService(),
+   * work in the following manner:
+   * 1. the user passes them a UUID, in any acceptable format, e.g.: "aBcD"
+   * 2. the function performs requested operations using the passed UUID
+   * 3. the function creates an object, e.g. BlueoothGATTService, with the UUID
+   *    passed by the user.
+   *
+   * As user may expect an identical UUID in the created object, identical to
+   * the one he passed to the function, we need to store the original format.
+   */
+  const std::string uuid_in_source_format;
   /*
    * Hexadecimal letter digits are always stored in lower case.
    */
@@ -93,7 +106,7 @@ struct UUID {
   /*
    * These functions don't validate passed arguments.
    */
-  UUID(std::string&& uuid_128_bit);
+  UUID(const std::string& uuid_in_source_format, std::string&& uuid_128_bit);
   static std::string To128Bit(const std::string& uuid);
 
   enum class Format : int { UUID_16_BIT, UUID_32_BIT, UUID_128_BIT, UUID_INVALID };