From: Pawel Wasowski Date: Fri, 3 Apr 2020 09:49:12 +0000 (+0200) Subject: [Bluetooth] Add uuid_in_source_format field to UUID class X-Git-Tag: submit/tizen/20200508.122743~1^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=37106817e3c42057d6668a77b174549c3c24b2d7;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git [Bluetooth] Add uuid_in_source_format field to UUID class 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 --- diff --git a/src/bluetooth/ut/uuid.cc b/src/bluetooth/ut/uuid.cc index 05588461..a7081f68 100644 --- a/src/bluetooth/ut/uuid.cc +++ b/src/bluetooth/ut/uuid.cc @@ -268,6 +268,10 @@ TEST_F(UUIDTest, ToXXXBits) { << "Failed for UUID: " << std::get(uuid) << " expected: (" << std::get(uuid) << ")" << " got: (" << uuid_obj->uuid_128_bit; + EXPECT_EQ(uuid_obj->uuid_in_source_format, std::get(uuid)) + << "Failed for UUID: " << std::get(uuid) << " expected: (" + << std::get(uuid) << ")" + << " got: (" << uuid_obj->uuid_in_source_format; } } diff --git a/src/bluetooth/uuid.cc b/src/bluetooth/uuid.cc index b692b883..9945c24e 100644 --- a/src/bluetooth/uuid.cc +++ b/src/bluetooth/uuid.cc @@ -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::create(const std::string& uuid) { @@ -60,7 +62,7 @@ optional 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::createFromGatt(const bt_gatt_h gatt_handle) { diff --git a/src/bluetooth/uuid.h b/src/bluetooth/uuid.h index ddfeb479..ac08c153 100644 --- a/src/bluetooth/uuid.h +++ b/src/bluetooth/uuid.h @@ -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 };