diff --git a/include/up-cpp/client/usubscription/v3/USubscriptionUUriBuilder.h b/include/up-cpp/client/usubscription/v3/USubscriptionUUriBuilder.h index 40c41715f..8df624a1d 100644 --- a/include/up-cpp/client/usubscription/v3/USubscriptionUUriBuilder.h +++ b/include/up-cpp/client/usubscription/v3/USubscriptionUUriBuilder.h @@ -33,16 +33,40 @@ struct USubscriptionUUriBuilder { /// @brief Constructor for uSubscriptionUUriBuilder. USubscriptionUUriBuilder(); + /// @brief Sets the authority name that will be used to build URIs. + /// + /// @param authority_name The authority to set in the URI. + /// + /// @return Returns a reference to the builder instance USubscriptionUUriBuilder& setAuthorityName( const std::string& authority_name); + /// @brief Sets the uEntity id that will be used to build URIs. + /// + /// @param ue_id The uEntity id to set in the URI. + /// + /// @return Returns a reference to the builder instance USubscriptionUUriBuilder& setUEntityId(uint32_t ue_id); + /// + /// @brief Sets the instance id that will be used to build URIs. + /// @param instance_id The instance id to set in the URI. + /// + /// @return Returns a reference to the builder instance USubscriptionUUriBuilder& setInstanceId(uint16_t instance_id); + /// @brief Sets the service id that will be used to build URIs. + /// @param service_id The service id to set in the URI. + /// + /// @return Returns a reference to the builder instance USubscriptionUUriBuilder& setServiceId(uint16_t service_id); + /// @brief Sets the resource id that will be used to build URIs. + /// @param resource_id The resource id to set in the URI. + /// + /// @return Returns a reference to the builder instance USubscriptionUUriBuilder& setResourceId(uint32_t resource_id); + /// @brief Get the URI with a specific resource ID. /// /// @param resource_id The resource ID to set in the URI. diff --git a/include/up-cpp/communication/RpcClient.h b/include/up-cpp/communication/RpcClient.h index b800ae1c0..c249a352c 100644 --- a/include/up-cpp/communication/RpcClient.h +++ b/include/up-cpp/communication/RpcClient.h @@ -180,10 +180,24 @@ struct RpcClient { /// * A UMessage containing the response from the RPC target. [[nodiscard]] InvokeFuture invokeMethod(const v1::UUri&); + /// @brief Invokes an RPC method by sending a request message directly + /// from a protobuf object. + /// + /// @param The method that will be invoked + /// @param The protobuf object that will be sent as the payload + /// @param A callback that will be called with the result. + /// + /// @post The provided callback will be called with one of: + /// * A UStatus with a DEADLINE_EXCEEDED code if no response was + /// received before the request expired (based on request TTL). + /// * A UStatus with the value returned by UTransport::send(). + /// * A UStatus based on the commstatus received in the response + /// message (if not OK). + /// * A UMessage containing the response from the RPC target. template - InvokeHandle invokeMethodToProto(const v1::UUri& method, - const R& request_message, - Callback&& callback) { + [[nodiscard]] InvokeHandle invokeMethodFromProto(const v1::UUri& method, + const R& request_message, + Callback&& callback) { auto payload_or_status = uprotocol::utils::ProtoConverter::protoToPayload(request_message); @@ -199,13 +213,29 @@ struct RpcClient { return handle; } + /// @brief Invokes an RPC method by sending a request message directly + /// from a protobuf object and converts the returned payload + /// to protobuf. + /// + /// @param The method that will be invoked + /// @param The protobuf object that will be sent as the payload + /// @param A callback that will be called with the result. + /// + /// @returns A promised future that can resolve to one of: + /// * A UStatus with a DEADLINE_EXCEEDED code if no response was + /// received before the request expired (based on request TTL). + /// * A UStatus with the value returned by UTransport::send(). + /// * A UStatus based on the commstatus received in the response + /// message (if not OK). + /// * A protobuf object constructed from the response from the RPC + /// target. template - InvokeProtoFuture invokeMethodToProto(const v1::UUri& method, - const R& request_message) { + [[nodiscard]] InvokeProtoFuture invokeMethodToProto( + const v1::UUri& method, const R& request_message) { auto result_promise = std::make_shared>>(); auto future = result_promise->get_future(); - auto handle = invokeMethodToProto( + auto handle = invokeMethodFromProto( method, request_message, [result_promise](const MessageOrStatus& message_or_status) { if (!message_or_status.has_value()) { @@ -233,14 +263,26 @@ struct RpcClient { return {std::move(future), std::move(handle)}; } + /// @brief Invokes an RPC method by sending a request message. + /// + /// @param The method that will be invoked + /// @param The protobuf object that will be sent as a payload. + /// + /// @returns A promised future that can resolve to one of: + /// * A UStatus with a DEADLINE_EXCEEDED code if no response was + /// received before the request expired (based on request TTL). + /// * A UStatus with the value returned by UTransport::send(). + /// * A UStatus based on the commstatus received in the response + /// message (if not OK). + /// * A UMessage containing the response from the RPC target. template - InvokeFuture invokeMethodToProto(const v1::UUri& method, - const R& request_message) { + [[nodiscard]] InvokeFuture invokeMethodFromProto(const v1::UUri& method, + const R& request_message) { auto result_promise = std::make_shared>>(); auto future = result_promise->get_future(); - auto handle = invokeMethodToProto( + auto handle = invokeMethodFromProto( method, request_message, [result_promise](const MessageOrStatus& message_or_status) { if (!message_or_status.has_value()) { diff --git a/include/up-cpp/utils/ThreadPool.h b/include/up-cpp/utils/ThreadPool.h deleted file mode 100644 index f888509cf..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(size_t max_queue_size, 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 77b2cf7bf..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/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 1adee2504..ed5472a6c 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -59,11 +59,9 @@ 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/ThreadPoolTest.cpp b/test/coverage/utils/ThreadPoolTest.cpp deleted file mode 100644 index 182128f25..000000000 --- a/test/coverage/utils/ThreadPoolTest.cpp +++ /dev/null @@ -1,40 +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; - - // Run once per execution of the test application. - // Used only for global setup outside of tests. - static void SetUpTestSuite() {} - static void TearDownTestSuite() {} - -public: - ~TestFixture() override = default; -}; - -// TODO(unknown) -TEST_F(TestFixture, SomeTestName3) {} // NOLINT - -} // namespace diff --git a/test/coverage/utils/base64Test.cpp b/test/coverage/utils/base64Test.cpp deleted file mode 100644 index cb03562e9..000000000 --- a/test/coverage/utils/base64Test.cpp +++ /dev/null @@ -1,40 +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; - - // Run once per execution of the test application. - // Used only for global setup outside of tests. - static void SetUpTestSuite() {} - static void TearDownTestSuite() {} - -public: - ~TestFixture() override = default; -}; - -// TODO(unknown) -TEST_F(TestFixture, SomeTestName0) {} // NOLINT - -} // namespace