From 33f27bebcd11052a80ba31a5343377a656d57679 Mon Sep 17 00:00:00 2001 From: Greg Medding Date: Thu, 11 Jul 2024 18:46:57 -0700 Subject: [PATCH] Removing unused utility stubs These utilities were not needed for the 1.0.0 release of up-cpp, so they're being removed from the release branch. See #214 #215 #216 #217 --- include/up-cpp/utils/CyclicQueue.h | 61 ------------ include/up-cpp/utils/IpAddress.h | 124 ------------------------ include/up-cpp/utils/ThreadPool.h | 55 ----------- include/up-cpp/utils/base64.h | 49 ---------- src/utils/IpAddress.cpp | 12 --- src/utils/ThreadPool.cpp | 12 --- src/utils/base64.cpp | 12 --- test/CMakeLists.txt | 4 - test/coverage/utils/CyclicQueueTest.cpp | 38 -------- test/coverage/utils/IpAddressTest.cpp | 38 -------- test/coverage/utils/ThreadPoolTest.cpp | 38 -------- test/coverage/utils/base64Test.cpp | 38 -------- 12 files changed, 481 deletions(-) delete mode 100644 include/up-cpp/utils/CyclicQueue.h delete mode 100644 include/up-cpp/utils/IpAddress.h delete mode 100644 include/up-cpp/utils/ThreadPool.h delete mode 100644 include/up-cpp/utils/base64.h delete mode 100644 src/utils/IpAddress.cpp delete mode 100644 src/utils/ThreadPool.cpp delete mode 100644 src/utils/base64.cpp delete mode 100644 test/coverage/utils/CyclicQueueTest.cpp delete mode 100644 test/coverage/utils/IpAddressTest.cpp delete mode 100644 test/coverage/utils/ThreadPoolTest.cpp delete mode 100644 test/coverage/utils/base64Test.cpp diff --git a/include/up-cpp/utils/CyclicQueue.h b/include/up-cpp/utils/CyclicQueue.h deleted file mode 100644 index 2fc8ee13f..000000000 --- a/include/up-cpp/utils/CyclicQueue.h +++ /dev/null @@ -1,61 +0,0 @@ -// SPDX-FileCopyrightText: 2024 Contributors to the Eclipse Foundation -// -// See the NOTICE file(s) distributed with this work for additional -// information regarding copyright ownership. -// -// This program and the accompanying materials are made available under the -// terms of the Apache License Version 2.0 which is available at -// https://www.apache.org/licenses/LICENSE-2.0 -// -// SPDX-License-Identifier: Apache-2.0 - -#ifndef UP_CPP_UTILS_CYCLICQUEUE_H -#define UP_CPP_UTILS_CYCLICQUEUE_H - -#include -#include -#include - -namespace uprotocol::utils { - -/// @brief Queue that enforces a maximum size by evicting the oldest entry to -/// make room for new ones. -template -class CyclicQueue final { -public: - explicit CyclicQueue(const size_t max_size); - - CyclicQueue(const CyclicQueue&) = delete; - CyclicQueue& operator=(const CyclicQueue&) = delete; - - virtual ~CyclicQueue() = default; - - void push(T&& data) noexcept; - void push(const T& data) noexcept; - - bool isFull() const noexcept; - bool isEmpty() const noexcept; - - // Blocking pop() - bool pop(T& popped_value) noexcept; - // Non-blocking pop() - bool tryPop(T& popped_value) noexcept; - // Time-limited blocking pop()s - bool tryPopFor(T& popped_value, std::chrono::milliseconds limit) noexcept; - bool tryPopUntil(T& popped_value, - std::chrono::system_clock::time_point when) noexcept; - - size_t size() const noexcept; - - void clear() noexcept; - -private: - size_t queueMaxSize_; - mutable std::mutex mutex_; - std::condition_variable conditionVariable_; - std::queue queue_; -}; - -} // namespace uprotocol::utils - -#endif // UP_CPP_UTILS_CYCLICQUEUE_H diff --git a/include/up-cpp/utils/IpAddress.h b/include/up-cpp/utils/IpAddress.h deleted file mode 100644 index b8ed8c735..000000000 --- a/include/up-cpp/utils/IpAddress.h +++ /dev/null @@ -1,124 +0,0 @@ -// SPDX-FileCopyrightText: 2024 Contributors to the Eclipse Foundation -// -// See the NOTICE file(s) distributed with this work for additional -// information regarding copyright ownership. -// -// This program and the accompanying materials are made available under the -// terms of the Apache License Version 2.0 which is available at -// https://www.apache.org/licenses/LICENSE-2.0 -// -// SPDX-License-Identifier: Apache-2.0 - -#ifndef UP_CPP_UTILS_IPADDRESS_H -#define UP_CPP_UTILS_IPADDRESS_H - -#include -#include -#include -#include -#include - -namespace uprotocol::utils { - -/// @brief Utility for converting IP addresses between representations and for -/// normalizing string representations. -/// -/// IP addresses can be represented as either human-readable strings or binary -/// numbers, and may be either IPv4 or IPv6. Additionally, each address family -/// has multiple allowable string representations. For example these IPv6 -/// addresses are all the same: -/// -/// * `2001::C0FF:EE01` -/// * `2001:0000:0000:0000:0000:0000:c0ff:ee01` -/// * `2001:0000:0000:0000::0000:192.255.238.1` -/// -/// This class provides three utilities: -/// -/// 1. Given a string, it will detect if it contains an IP address and which -/// family (IPv4 or IPv6) it contains. -/// 2. Given a string IP address, it will convert the address to its binary -/// representation. -/// 3. Given a binary representation of an IP address, it will convert it -/// to a string. -/// 4. In all cases, it will produce a consistent, normalized string -/// representation of an IP address. -/// -/// Point #4 is particularly important in any scenario where a direct string -/// match is used on an address, such as in the Zenoh URI <-> Topic mapping -/// (https://github.com/eclipse-uprotocol/up-spec/blob/main/up-l1/zenoh.adoc). -struct IpAddress { - /// @brief Describes the type / family of an IP address - enum class Type { - /// @brief For IPv4 family addresses - IpV4, - /// @brief For IPv6 family addresses - IpV6, - /// @brief Used when constructed from a string that is not an IP - Invalid - }; - - /// @brief Constructs an IP address from a string representation of - /// an address. - explicit IpAddress(std::string_view const ip_string); - - /// @brief Constructs an IP address from a binary representation of - /// an address. - IpAddress(std::vector const& ip_bytes, Type type); - - /// @brief Get the type of this IP address. - [[nodiscard]] Type getType() const; - - /// @brief Gets the nomalized string representation of this IP address. - [[nodiscard]] const std::string& getString() const; - - /// @brief Gets the binary representation of this IP address. - [[nodiscard]] const std::vector& getBytes() const; - - /// @brief Gets the binary representation of this IP address, wrapped in a - /// string-like container to better interface with protobuf. - /// - /// Protobuf uses std::string as a generic byte container, so this can be - /// useful for embedding compact, binary representations of IP addresses - /// into a protobuf message. - [[nodiscard]] std::string getBytesString() const; - - /// @brief Number of bytes in IPv4 address. - static constexpr uint8_t ip_v4_address_bytes = 4; - - /// @brief Number of bytes in IPv6 address. - static constexpr uint8_t ip_v6_address_bytes = 16; - -private: - /// @brief Updates the state of this instance from the value of the - /// ipString_ field. - void fromString(); - - /// @brief Updates the state of this instance from the value of the - /// ipBytes_ field. - void fromBytes(); - - /// @brief Type of the IP addess contained in this instance. - Type type_{Type::Invalid}; - - /// @brief IP address in byte format. - std::vector ipBytes_{}; - - /// @brief IP address in string format. - std::string ipString_{}; - - /// @name String container compatibility checks - /// @{ - using Bytes = typename std::decay_t::value_type; - using StrBytes = typename std::string_view::value_type; - using StrBytesPtr = typename std::string_view::const_pointer; - - static_assert( - sizeof(StrBytes) == sizeof(Bytes), - "Mismatch in size between string_view value type and ipBytes_ " - "value type invalidates reinterpret_cast used in constructor."); - /// @} -}; - -} // namespace uprotocol::utils - -#endif // UP_CPP_UTILS_IPADDRESS_H diff --git a/include/up-cpp/utils/ThreadPool.h b/include/up-cpp/utils/ThreadPool.h deleted file mode 100644 index d1d6cde46..000000000 --- a/include/up-cpp/utils/ThreadPool.h +++ /dev/null @@ -1,55 +0,0 @@ -// SPDX-FileCopyrightText: 2024 Contributors to the Eclipse Foundation -// -// See the NOTICE file(s) distributed with this work for additional -// information regarding copyright ownership. -// -// This program and the accompanying materials are made available under the -// terms of the Apache License Version 2.0 which is available at -// https://www.apache.org/licenses/LICENSE-2.0 -// -// SPDX-License-Identifier: Apache-2.0 - -#ifndef UP_CPP_UTILS_THREADPOOL_H -#define UP_CPP_UTILS_THREADPOOL_H - -#include - -#include -#include -#include -#include -#include -#include -#include - -namespace uprotocol::utils { - -class ThreadPool { -public: - ThreadPool(const ThreadPool&) = delete; - ThreadPool(ThreadPool&&) = delete; - - ThreadPool& operator=(const ThreadPool&) = delete; - ThreadPool& operator=(ThreadPool&&) = delete; - - ThreadPool(const size_t max_queue_size, const size_t max_num_of_threads, - std::chrono::milliseconds task_timeout); - - ~ThreadPool(); - - // Submit a function to be executed asynchronously by the pool - template - auto submit(F&& f, Args&&... args) -> std::future; - -private: - CyclicQueue> queue_; - bool terminate_; - size_t maxNumOfThreads_; - std::atomic numOfThreads_; - std::vector> threads_; - std::mutex mutex_; - const std::chrono::milliseconds timeout_; -}; -} // namespace uprotocol::utils - -#endif // UP_CPP_UTILS_THREADPOOL_H diff --git a/include/up-cpp/utils/base64.h b/include/up-cpp/utils/base64.h deleted file mode 100644 index 88453460e..000000000 --- a/include/up-cpp/utils/base64.h +++ /dev/null @@ -1,49 +0,0 @@ -// SPDX-FileCopyrightText: 2024 Contributors to the Eclipse Foundation -// -// See the NOTICE file(s) distributed with this work for additional -// information regarding copyright ownership. -// -// This program and the accompanying materials are made available under the -// terms of the Apache License Version 2.0 which is available at -// https://www.apache.org/licenses/LICENSE-2.0 -// -// SPDX-License-Identifier: Apache-2.0 - -#ifndef UP_CPP_UTILS_BASE64_H -#define UP_CPP_UTILS_BASE64_H - -#include -#include -#include -#include - -/// @brief Utilities for encoding / decoding data in Base 64 format. -namespace uprotocol::utils::Base64 { - -/// @brief Encode a string of bytes to base64. -std::string encode(std::string_view); - -/// @brief Encode a vector of bytes to base64. -std::string encode(const std::vector&); - -/// @brief Decode a base64 string to a string of bytes. -std::string decodeAsString(std::string_view); - -/// @brief Decode a base64 string to a vector of bytes. -std::vector decodeAsBytes(std::string_view); - -/// @brief Given a string of bytes, calculate the length needed for a -/// base64 encoding of that string. -size_t encodedLen(std::string_view); - -/// @brief Given a vector of bytes, calculate the length needed for a -/// base64 encoding of that vector. -size_t encodedLen(std::vector); - -/// @brief Given a base64 encoded string, calculate the length of the -/// decoded data. -size_t decodedLen(std::string_view); - -} // namespace uprotocol::utils::Base64 - -#endif // UP_CPP_UTILS_BASE64_H diff --git a/src/utils/IpAddress.cpp b/src/utils/IpAddress.cpp deleted file mode 100644 index 8c222e49a..000000000 --- a/src/utils/IpAddress.cpp +++ /dev/null @@ -1,12 +0,0 @@ -// SPDX-FileCopyrightText: 2024 Contributors to the Eclipse Foundation -// -// See the NOTICE file(s) distributed with this work for additional -// information regarding copyright ownership. -// -// This program and the accompanying materials are made available under the -// terms of the Apache License Version 2.0 which is available at -// https://www.apache.org/licenses/LICENSE-2.0 -// -// SPDX-License-Identifier: Apache-2.0 - -#include "up-cpp/utils/IpAddress.h" diff --git a/src/utils/ThreadPool.cpp b/src/utils/ThreadPool.cpp deleted file mode 100644 index 8733d7e32..000000000 --- a/src/utils/ThreadPool.cpp +++ /dev/null @@ -1,12 +0,0 @@ -// SPDX-FileCopyrightText: 2024 Contributors to the Eclipse Foundation -// -// See the NOTICE file(s) distributed with this work for additional -// information regarding copyright ownership. -// -// This program and the accompanying materials are made available under the -// terms of the Apache License Version 2.0 which is available at -// https://www.apache.org/licenses/LICENSE-2.0 -// -// SPDX-License-Identifier: Apache-2.0 - -#include "up-cpp/utils/ThreadPool.h" diff --git a/src/utils/base64.cpp b/src/utils/base64.cpp deleted file mode 100644 index 474163955..000000000 --- a/src/utils/base64.cpp +++ /dev/null @@ -1,12 +0,0 @@ -// SPDX-FileCopyrightText: 2024 Contributors to the Eclipse Foundation -// -// See the NOTICE file(s) distributed with this work for additional -// information regarding copyright ownership. -// -// This program and the accompanying materials are made available under the -// terms of the Apache License Version 2.0 which is available at -// https://www.apache.org/licenses/LICENSE-2.0 -// -// SPDX-License-Identifier: Apache-2.0 - -#include "up-cpp/utils/base64.h" diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 3c9a6f573..e689f2ab6 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -50,11 +50,7 @@ endfunction() ########################### COVERAGE ########################################## # Utils add_coverage_test("ExpectedTest" coverage/utils/ExpectedTest.cpp) -add_coverage_test("base64Test" coverage/utils/base64Test.cpp) -add_coverage_test("IpAddressTest" coverage/utils/IpAddressTest.cpp) add_coverage_test("CallbackConnectionTest" coverage/utils/CallbackConnectionTest.cpp) -add_coverage_test("CyclicQueueTest" coverage/utils/CyclicQueueTest.cpp) -add_coverage_test("ThreadPoolTest" coverage/utils/ThreadPoolTest.cpp) # Validators add_coverage_test("UuidValidatorTest" coverage/datamodel/UuidValidatorTest.cpp) diff --git a/test/coverage/utils/CyclicQueueTest.cpp b/test/coverage/utils/CyclicQueueTest.cpp deleted file mode 100644 index 8160e8b33..000000000 --- a/test/coverage/utils/CyclicQueueTest.cpp +++ /dev/null @@ -1,38 +0,0 @@ -// SPDX-FileCopyrightText: 2024 Contributors to the Eclipse Foundation -// -// See the NOTICE file(s) distributed with this work for additional -// information regarding copyright ownership. -// -// This program and the accompanying materials are made available under the -// terms of the Apache License Version 2.0 which is available at -// https://www.apache.org/licenses/LICENSE-2.0 -// -// SPDX-License-Identifier: Apache-2.0 - -#include -#include - -namespace { - -class TestFixture : public testing::Test { -protected: - // Run once per TEST_F. - // Used to set up clean environments per test. - void SetUp() override {} - void TearDown() override {} - - // Run once per execution of the test application. - // Used for setup of all tests. Has access to this instance. - TestFixture() = default; - ~TestFixture() = default; - - // Run once per execution of the test application. - // Used only for global setup outside of tests. - static void SetUpTestSuite() {} - static void TearDownTestSuite() {} -}; - -// TODO replace -TEST_F(TestFixture, SomeTestName) {} - -} // namespace diff --git a/test/coverage/utils/IpAddressTest.cpp b/test/coverage/utils/IpAddressTest.cpp deleted file mode 100644 index b243bd071..000000000 --- a/test/coverage/utils/IpAddressTest.cpp +++ /dev/null @@ -1,38 +0,0 @@ -// SPDX-FileCopyrightText: 2024 Contributors to the Eclipse Foundation -// -// See the NOTICE file(s) distributed with this work for additional -// information regarding copyright ownership. -// -// This program and the accompanying materials are made available under the -// terms of the Apache License Version 2.0 which is available at -// https://www.apache.org/licenses/LICENSE-2.0 -// -// SPDX-License-Identifier: Apache-2.0 - -#include -#include - -namespace { - -class TestFixture : public testing::Test { -protected: - // Run once per TEST_F. - // Used to set up clean environments per test. - void SetUp() override {} - void TearDown() override {} - - // Run once per execution of the test application. - // Used for setup of all tests. Has access to this instance. - TestFixture() = default; - ~TestFixture() = default; - - // Run once per execution of the test application. - // Used only for global setup outside of tests. - static void SetUpTestSuite() {} - static void TearDownTestSuite() {} -}; - -// TODO replace -TEST_F(TestFixture, SomeTestName) {} - -} // namespace diff --git a/test/coverage/utils/ThreadPoolTest.cpp b/test/coverage/utils/ThreadPoolTest.cpp deleted file mode 100644 index 22b1dfd6f..000000000 --- a/test/coverage/utils/ThreadPoolTest.cpp +++ /dev/null @@ -1,38 +0,0 @@ -// SPDX-FileCopyrightText: 2024 Contributors to the Eclipse Foundation -// -// See the NOTICE file(s) distributed with this work for additional -// information regarding copyright ownership. -// -// This program and the accompanying materials are made available under the -// terms of the Apache License Version 2.0 which is available at -// https://www.apache.org/licenses/LICENSE-2.0 -// -// SPDX-License-Identifier: Apache-2.0 - -#include -#include - -namespace { - -class TestFixture : public testing::Test { -protected: - // Run once per TEST_F. - // Used to set up clean environments per test. - void SetUp() override {} - void TearDown() override {} - - // Run once per execution of the test application. - // Used for setup of all tests. Has access to this instance. - TestFixture() = default; - ~TestFixture() = default; - - // Run once per execution of the test application. - // Used only for global setup outside of tests. - static void SetUpTestSuite() {} - static void TearDownTestSuite() {} -}; - -// TODO replace -TEST_F(TestFixture, SomeTestName) {} - -} // namespace diff --git a/test/coverage/utils/base64Test.cpp b/test/coverage/utils/base64Test.cpp deleted file mode 100644 index 34fec4db0..000000000 --- a/test/coverage/utils/base64Test.cpp +++ /dev/null @@ -1,38 +0,0 @@ -// SPDX-FileCopyrightText: 2024 Contributors to the Eclipse Foundation -// -// See the NOTICE file(s) distributed with this work for additional -// information regarding copyright ownership. -// -// This program and the accompanying materials are made available under the -// terms of the Apache License Version 2.0 which is available at -// https://www.apache.org/licenses/LICENSE-2.0 -// -// SPDX-License-Identifier: Apache-2.0 - -#include -#include - -namespace { - -class TestFixture : public testing::Test { -protected: - // Run once per TEST_F. - // Used to set up clean environments per test. - void SetUp() override {} - void TearDown() override {} - - // Run once per execution of the test application. - // Used for setup of all tests. Has access to this instance. - TestFixture() = default; - ~TestFixture() = default; - - // Run once per execution of the test application. - // Used only for global setup outside of tests. - static void SetUpTestSuite() {} - static void TearDownTestSuite() {} -}; - -// TODO replace -TEST_F(TestFixture, SomeTestName) {} - -} // namespace