Remove unused files (#32413)
diff --git a/src/controller/CHIPDeviceController.h b/src/controller/CHIPDeviceController.h
index 024421d..ee4ac09 100644
--- a/src/controller/CHIPDeviceController.h
+++ b/src/controller/CHIPDeviceController.h
@@ -55,7 +55,6 @@
#include <lib/support/DLLUtil.h>
#include <lib/support/Pool.h>
#include <lib/support/SafeInt.h>
-#include <lib/support/SerializableIntegerSet.h>
#include <lib/support/Span.h>
#include <lib/support/ThreadOperationalDataset.h>
#include <messaging/ExchangeMgr.h>
diff --git a/src/lib/support/BUILD.gn b/src/lib/support/BUILD.gn
index 02ca1ee..a5bf63a 100644
--- a/src/lib/support/BUILD.gn
+++ b/src/lib/support/BUILD.gn
@@ -214,7 +214,6 @@
"LifetimePersistedCounter.h",
"LinkedList.h",
"ObjectLifeCycle.h",
- "OwnerOf.h",
"PersistedCounter.h",
"PersistentData.h",
"PersistentStorageAudit.cpp",
@@ -230,8 +229,6 @@
"SafeString.h",
"Scoped.h",
"ScopedBuffer.h",
- "SerializableIntegerSet.cpp",
- "SerializableIntegerSet.h",
"SetupDiscriminator.h",
"SortUtils.h",
"StateMachine.h",
diff --git a/src/lib/support/OwnerOf.h b/src/lib/support/OwnerOf.h
deleted file mode 100644
index eac9ac6..0000000
--- a/src/lib/support/OwnerOf.h
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- *
- * Copyright (c) 2021 Project CHIP Authors
- * All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#pragma once
-
-#include <cstddef>
-#include <cstdint>
-
-namespace chip {
-
-template <class ClassType, class MemberType>
-constexpr ClassType * OwnerOf(MemberType * ptr, const MemberType ClassType::*member)
-{
- return reinterpret_cast<ClassType *>(reinterpret_cast<uintptr_t>(ptr) - offsetof(ClassType, member));
-}
-
-} // namespace chip
diff --git a/src/lib/support/SerializableIntegerSet.cpp b/src/lib/support/SerializableIntegerSet.cpp
deleted file mode 100644
index 7a16aea..0000000
--- a/src/lib/support/SerializableIntegerSet.cpp
+++ /dev/null
@@ -1,123 +0,0 @@
-/*
- *
- * Copyright (c) 2020 Project CHIP Authors
- * All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "SerializableIntegerSet.h"
-
-#include <lib/core/CHIPEncoding.h>
-#include <lib/support/CodeUtils.h>
-
-namespace chip {
-
-CHIP_ERROR SerializableU64SetBase::Deserialize(ByteSpan serialized)
-{
- VerifyOrReturnError(serialized.size() <= MaxSerializedSize(), CHIP_ERROR_INVALID_ARGUMENT);
- memcpy(mData, serialized.data(), serialized.size());
- mNextAvailable = static_cast<uint16_t>(serialized.size() / sizeof(uint64_t));
-
- // Our serialized data is always little-endian; swap to native.
- SwapByteOrderIfNeeded();
- return CHIP_NO_ERROR;
-}
-
-void SerializableU64SetBase::SwapByteOrderIfNeeded()
-{
- /**
- * The data is serialized in LittleEndian byte order in the set. This will enable
- * different machine architectures to interpret a given set in a consistent manner,
- * for serialize and deserialize operations.
- */
- if (nl::ByteOrder::GetCurrent() != nl::ByteOrder::LittleEndian)
- {
- for (uint16_t i = 0; i < mNextAvailable; i++)
- {
- mData[i] = Encoding::LittleEndian::HostSwap64(mData[i]);
- }
- }
-}
-
-uint16_t SerializableU64SetBase::FindIndex(uint64_t value)
-{
- for (uint16_t i = 0; i < mNextAvailable; i++)
- {
- if (mData[i] == value)
- {
- return i;
- }
- }
-
- return mCapacity;
-}
-
-CHIP_ERROR SerializableU64SetBase::Insert(uint64_t value)
-{
- VerifyOrReturnError(value != mEmptyValue, CHIP_ERROR_INVALID_ARGUMENT);
-
- const uint16_t index = FirstAvailableForUniqueId(value);
- if (index < mCapacity)
- {
- mData[index] = value;
- if (index == mNextAvailable)
- {
- mNextAvailable = static_cast<uint16_t>(index + 1);
- }
- return CHIP_NO_ERROR;
- }
-
- return CHIP_ERROR_NO_MEMORY;
-}
-
-void SerializableU64SetBase::Remove(uint64_t value)
-{
- if (value != mEmptyValue)
- {
- const uint16_t index = FindIndex(value);
- if (index < mCapacity)
- {
- mData[index] = mEmptyValue;
- if ((index + 1) == mNextAvailable)
- {
- mNextAvailable = index;
- while (mNextAvailable > 0 && mData[mNextAvailable - 1] == mEmptyValue)
- mNextAvailable--;
- }
- }
- }
-}
-
-uint16_t SerializableU64SetBase::FirstAvailableForUniqueId(uint64_t value)
-{
- uint16_t available = mNextAvailable;
- for (uint16_t i = 0; i < mNextAvailable; i++)
- {
- if (mData[i] == value)
- {
- return i;
- }
-
- if (mData[i] == mEmptyValue && i < available)
- {
- // Don't return here, as we want to make sure there are no duplicate
- // entries in the set.
- available = i;
- }
- }
-
- return available;
-}
-
-} // namespace chip
diff --git a/src/lib/support/SerializableIntegerSet.h b/src/lib/support/SerializableIntegerSet.h
deleted file mode 100644
index 45d7604..0000000
--- a/src/lib/support/SerializableIntegerSet.h
+++ /dev/null
@@ -1,162 +0,0 @@
-/*
- *
- * Copyright (c) 2020 Project CHIP Authors
- * All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/**
- * @file
- * Defines a data structure that can store a set of uint64_t values
- * in not contiguous indexes. The set is initialized with a constant
- * capacity. The data structure supports serialize/deserialize operations,
- * where, serialize converts the set to a base64 string, and deserializing
- * the base64 string reconstructs the original set.
- *
- * The data is stored such that serialized data can be deserialized correctly
- * on different machine architectures.
- *
- */
-
-#pragma once
-
-#include <lib/support/CodeUtils.h>
-#include <lib/support/Span.h>
-
-namespace chip {
-
-class SerializableU64SetBase
-{
-
-public:
- SerializableU64SetBase(uint64_t * data, uint16_t capacity, uint64_t emptyValue) :
- mData(data), mCapacity(capacity), mEmptyValue(emptyValue), mNextAvailable(0)
- {
- for (uint16_t i = 0; i < capacity; i++)
- {
- data[i] = emptyValue;
- }
- }
-
- /**
- * @brief
- * Serialize the sparse array by calling a callback with a ByteSpan to
- * serialize. We ensure that this ByteSpan is architecture-agnostic, so
- * it can be deserialized anywhere later.
- *
- * Only the values till mNextAvailable index are encoded.
- * The empty indexes between 0, and mNextAvailable, are also
- * encoded.
- *
- * @param[in] callback the serialization callback to call.
- */
- template <typename F>
- CHIP_ERROR Serialize(F callback)
- {
- // Ensure that we are holding little-endian data while the serialization
- // callback runs.
- SwapByteOrderIfNeeded();
-
- CHIP_ERROR err = callback(ByteSpan(reinterpret_cast<uint8_t *>(mData), SerializedSize()));
-
- SwapByteOrderIfNeeded();
- return err;
- }
-
- /**
- * @brief
- * Deserialize a previously serialized byte buffer into the sparse array.
- * The mNextAvailable index is calculated based on how many
- * values are in the deserialized array.
- *
- * @param[in] serialized Serialized buffer
- */
- CHIP_ERROR Deserialize(ByteSpan serialized);
-
- /**
- * @brief
- * Get the length of the byte data if the array is serialized.
- */
- size_t SerializedSize() const { return sizeof(uint64_t) * mNextAvailable; }
-
- /**
- * @brief
- * Get the maximum length of the byte data if the array were full and serialized.
- */
- size_t MaxSerializedSize() const { return sizeof(uint64_t) * mCapacity; }
-
- /**
- * @brief
- * Check if the value is in the array.
- *
- * @param[in] value Value to find
- * @return True, if it's prsent in the array.
- */
- bool Contains(uint64_t value) { return FindIndex(value) != mCapacity; }
-
- /**
- * @brief
- * Insert the value in the array. If the value is duplicate, it
- * won't be inserted.
- *
- * @return CHIP_NO_ERROR in case of success, or the error code
- */
- CHIP_ERROR Insert(uint64_t value);
-
- /**
- * @brief
- * Delete the value from the array.
- */
- void Remove(uint64_t value);
-
-private:
- uint64_t * const mData;
- const uint16_t mCapacity;
- const uint64_t mEmptyValue;
- uint16_t mNextAvailable;
-
- uint16_t FirstAvailableForUniqueId(uint64_t value);
-
- /**
- * @brief
- * Find index of the value in the array.
- *
- * @param[in] value Value to find
- * @return index of the value if found, or max length (mCapacity) of the array
- */
- uint16_t FindIndex(uint64_t value);
-
- void SwapByteOrderIfNeeded();
-};
-
-template <uint16_t kCapacity, uint64_t kEmptyValue = 0>
-class SerializableU64Set : public SerializableU64SetBase
-{
-public:
- SerializableU64Set() : SerializableU64SetBase(mBuffer, kCapacity, kEmptyValue)
- {
- /**
- * Check that requested capacity (kCapacity) will not exceed maximum number of uint64_t
- * values that can fit in a meory of size UINT16_MAX. This is required, since APIs in
- * this class are using uint16_t type for buffer sizes.
- */
- nlSTATIC_ASSERT_PRINT(kCapacity < UINT16_MAX / sizeof(uint64_t),
- "Serializable u64 set capacity cannot be more than UINT16_MAX / sizeof(uint64_t)");
- }
-
-private:
- uint64_t mBuffer[kCapacity];
-};
-
-} // namespace chip
diff --git a/src/lib/support/tests/BUILD.gn b/src/lib/support/tests/BUILD.gn
index deac3e2..8dc9bdb 100644
--- a/src/lib/support/tests/BUILD.gn
+++ b/src/lib/support/tests/BUILD.gn
@@ -38,7 +38,6 @@
"TestIntrusiveList.cpp",
"TestJsonToTlv.cpp",
"TestJsonToTlvToJson.cpp",
- "TestOwnerOf.cpp",
"TestPersistedCounter.cpp",
"TestPool.cpp",
"TestPrivateHeap.cpp",
@@ -46,7 +45,6 @@
"TestSafeString.cpp",
"TestScoped.cpp",
"TestScopedBuffer.cpp",
- "TestSerializableIntegerSet.cpp",
"TestSpan.cpp",
"TestStateMachine.cpp",
"TestStaticSupportSmartPtr.cpp",
diff --git a/src/lib/support/tests/TestOwnerOf.cpp b/src/lib/support/tests/TestOwnerOf.cpp
deleted file mode 100644
index e1c3761..0000000
--- a/src/lib/support/tests/TestOwnerOf.cpp
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- *
- * Copyright (c) 2021 Project CHIP Authors
- * All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <lib/support/OwnerOf.h>
-#include <lib/support/UnitTestRegistration.h>
-
-#include <nlunit-test.h>
-
-using namespace chip;
-
-class Member
-{
-};
-
-class Base
-{
-public:
- uint32_t Offset0;
- uint32_t Offset4;
- Member member;
-};
-
-static void TestMemberOwner(nlTestSuite * inSuite, void * inContext)
-{
- Base base;
- Member * member = &base.member;
- NL_TEST_ASSERT(inSuite, OwnerOf(member, &Base::member) == &base);
- NL_TEST_ASSERT(inSuite, &OwnerOf(member, &Base::member)->member == member);
-}
-
-#define NL_TEST_DEF_FN(fn) NL_TEST_DEF("Test " #fn, fn)
-/**
- * Test Suite. It lists all the test functions.
- */
-static const nlTest sTests[] = { NL_TEST_DEF_FN(TestMemberOwner), NL_TEST_SENTINEL() };
-
-int TestOwnerOf()
-{
- nlTestSuite theSuite = { "CHIP OwnerOf tests", &sTests[0], nullptr, nullptr };
-
- // Run test suite against one context.
- nlTestRunner(&theSuite, nullptr);
- return nlTestRunnerStats(&theSuite);
-}
-
-CHIP_REGISTER_TEST_SUITE(TestOwnerOf)
diff --git a/src/lib/support/tests/TestSerializableIntegerSet.cpp b/src/lib/support/tests/TestSerializableIntegerSet.cpp
deleted file mode 100644
index 4d1fcd9..0000000
--- a/src/lib/support/tests/TestSerializableIntegerSet.cpp
+++ /dev/null
@@ -1,184 +0,0 @@
-/*
- *
- * Copyright (c) 2020 Project CHIP Authors
- * All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <lib/support/CHIPMem.h>
-#include <lib/support/CHIPMemString.h>
-#include <lib/support/SerializableIntegerSet.h>
-#include <lib/support/UnitTestRegistration.h>
-
-#include <nlunit-test.h>
-
-namespace {
-
-void TestSerializableIntegerSet(nlTestSuite * inSuite, void * inContext)
-{
- chip::SerializableU64Set<8> set;
- NL_TEST_ASSERT(inSuite, !set.Contains(123));
-
- NL_TEST_ASSERT(inSuite, set.Insert(123) == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, set.Contains(123));
-
- NL_TEST_ASSERT(inSuite, set.Insert(123) == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, set.Contains(123));
-
- set.Remove(123);
- NL_TEST_ASSERT(inSuite, !set.Contains(123));
-
- for (uint64_t i = 1; i <= 8; i++)
- {
- NL_TEST_ASSERT(inSuite, set.Insert(i) == CHIP_NO_ERROR);
- }
-
- NL_TEST_ASSERT(inSuite, set.Insert(9) != CHIP_NO_ERROR);
-
- for (uint64_t i = 1; i <= 8; i++)
- {
- NL_TEST_ASSERT(inSuite, set.Contains(i));
- }
-
- size_t size = set.SerializedSize();
- NL_TEST_ASSERT(inSuite, set.MaxSerializedSize() == size);
-
- for (uint64_t i = 1; i <= 7; i++)
- {
- set.Remove(i);
- NL_TEST_ASSERT(inSuite, set.SerializedSize() == size);
- }
-
- set.Remove(8);
- NL_TEST_ASSERT(inSuite, set.SerializedSize() == 0);
-}
-
-void TestSerializableIntegerSetNonZero(nlTestSuite * inSuite, void * inContext)
-{
- chip::SerializableU64Set<8, 2> set;
- NL_TEST_ASSERT(inSuite, !set.Contains(123));
-
- NL_TEST_ASSERT(inSuite, set.Insert(123) == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, set.Contains(123));
-
- NL_TEST_ASSERT(inSuite, set.Insert(123) == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, set.Contains(123));
-
- set.Remove(123);
- NL_TEST_ASSERT(inSuite, !set.Contains(123));
-
- for (uint64_t i = 0; i <= 1; i++)
- {
- NL_TEST_ASSERT(inSuite, set.Insert(i) == CHIP_NO_ERROR);
- }
-
- // Try inserting empty value
- NL_TEST_ASSERT(inSuite, set.Insert(2) != CHIP_NO_ERROR);
-
- for (uint64_t i = 3; i <= 7; i++)
- {
- NL_TEST_ASSERT(inSuite, set.Insert(i) == CHIP_NO_ERROR);
- }
-
- for (uint64_t i = 0; i <= 1; i++)
- {
- NL_TEST_ASSERT(inSuite, set.Contains(i));
- }
-
- for (uint64_t i = 3; i <= 7; i++)
- {
- NL_TEST_ASSERT(inSuite, set.Contains(i));
- }
-
- for (uint64_t i = 0; i <= 6; i++)
- {
- set.Remove(i);
- }
-
- set.Remove(7);
- NL_TEST_ASSERT(inSuite, set.SerializedSize() == 0);
-}
-
-void TestSerializableIntegerSetSerialize(nlTestSuite * inSuite, void * inContext)
-{
- chip::SerializableU64Set<8> set;
-
- for (uint64_t i = 1; i <= 6; i++)
- {
- NL_TEST_ASSERT(inSuite, set.Insert(i) == CHIP_NO_ERROR);
- }
-
- NL_TEST_ASSERT(inSuite, !set.Contains(0));
- for (uint64_t i = 1; i <= 6; i++)
- {
- NL_TEST_ASSERT(inSuite, set.Contains(i));
- }
- NL_TEST_ASSERT(inSuite, !set.Contains(7));
-
- NL_TEST_ASSERT(inSuite, set.Serialize([&](chip::ByteSpan serialized) -> CHIP_ERROR {
- NL_TEST_ASSERT(inSuite, serialized.size() == 48);
- return CHIP_NO_ERROR;
- }) == CHIP_NO_ERROR);
-
- NL_TEST_ASSERT(inSuite, set.Serialize([&](chip::ByteSpan serialized) -> CHIP_ERROR {
- chip::SerializableU64Set<8> set2;
- NL_TEST_ASSERT(inSuite, set2.Deserialize(serialized) == CHIP_NO_ERROR);
-
- NL_TEST_ASSERT(inSuite, !set2.Contains(0));
- for (uint64_t i = 1; i <= 6; i++)
- {
- NL_TEST_ASSERT(inSuite, set2.Contains(i));
- }
- NL_TEST_ASSERT(inSuite, !set2.Contains(7));
- return CHIP_NO_ERROR;
- }) == CHIP_NO_ERROR);
-}
-
-int Setup(void * inContext)
-{
- CHIP_ERROR error = chip::Platform::MemoryInit();
- if (error != CHIP_NO_ERROR)
- return FAILURE;
- return SUCCESS;
-}
-
-int Teardown(void * inContext)
-{
- chip::Platform::MemoryShutdown();
- return SUCCESS;
-}
-
-} // namespace
-
-#define NL_TEST_DEF_FN(fn) NL_TEST_DEF("Test " #fn, fn)
-/**
- * Test Suite. It lists all the test functions.
- */
-static const nlTest sTests[] = {
- NL_TEST_DEF_FN(TestSerializableIntegerSet), //
- NL_TEST_DEF_FN(TestSerializableIntegerSetNonZero), //
- NL_TEST_DEF_FN(TestSerializableIntegerSetSerialize), //
- NL_TEST_SENTINEL() //
-};
-
-int TestSerializableIntegerSet()
-{
- nlTestSuite theSuite = { "CHIP SerializableIntegerSet tests", &sTests[0], Setup, Teardown };
-
- // Run test suite against one context.
- nlTestRunner(&theSuite, nullptr);
- return nlTestRunnerStats(&theSuite);
-}
-
-CHIP_REGISTER_TEST_SUITE(TestSerializableIntegerSet)