From cb6f5724b85e51295498a39144ed4ccce114ad53 Mon Sep 17 00:00:00 2001 From: Mauro Sardara Date: Fri, 2 Sep 2022 14:34:36 +0000 Subject: fix(sonar): make sonarqube happy Ref: HICN-766 HICN-767 HICN-764 HICN-762 HICN-743 HICN-759 HICN-760 HICN-758 HICN-761 HICN-756 Change-Id: Ic2accf6b6771c7a78d2b22d9bdb8e5a5be9ead8a Signed-off-by: Mauro Sardara --- .../includes/hicn/transport/core/connector.h | 33 +++++++++--------- .../includes/hicn/transport/core/endpoint.h | 4 +-- .../includes/hicn/transport/core/interest.h | 2 +- .../transport/interfaces/publication_options.h | 2 +- .../includes/hicn/transport/utils/CMakeLists.txt | 1 - .../includes/hicn/transport/utils/move_wrapper.h | 39 ---------------------- libtransport/src/core/interest.cc | 16 ++++----- libtransport/src/core/local_connector.h | 1 - libtransport/src/core/portal.h | 2 +- 9 files changed, 27 insertions(+), 73 deletions(-) delete mode 100644 libtransport/includes/hicn/transport/utils/move_wrapper.h (limited to 'libtransport') diff --git a/libtransport/includes/hicn/transport/core/connector.h b/libtransport/includes/hicn/transport/core/connector.h index eaf95b2ec..be191fb4a 100644 --- a/libtransport/includes/hicn/transport/core/connector.h +++ b/libtransport/includes/hicn/transport/core/connector.h @@ -73,29 +73,26 @@ class Connector : public std::enable_shared_from_this { typename OnReconnect> Connector(ReceiveCallback &&receive_callback, SentCallback &&packet_sent, OnClose &&close_callback, OnReconnect &&on_reconnect) - : receive_callback_(std::forward(receive_callback)), - sent_callback_(std::forward(packet_sent)), - on_close_callback_(std::forward(close_callback)), - on_reconnect_callback_(std::forward(on_reconnect)), - state_(State::CLOSED), - connector_id_(invalid_connector), - connection_reattempts_(0) {} + : receive_callback_(std::forward(receive_callback)), + sent_callback_(std::forward(packet_sent)), + on_close_callback_(std::forward(close_callback)), + on_reconnect_callback_(std::forward(on_reconnect)) {} virtual ~Connector(){}; template void setReceiveCallback(ReceiveCallback &&callback) { - receive_callback_ = std::forward(callback); + receive_callback_ = std::forward(callback); } template void setSentCallback(SentCallback &&callback) { - sent_callback_ = std::forward(callback); + sent_callback_ = std::forward(callback); } template void setOnCloseCallback(OnClose &&callback) { - on_close_callback_ = std::forward(callback); + on_close_callback_ = std::forward(callback); } template @@ -137,24 +134,24 @@ class Connector : public std::enable_shared_from_this { Id getConnectorId() { return connector_id_; } - void setConnectorName(std::string connector_name) { + void setConnectorName(const std::string &connector_name) { connector_name_ = connector_name; } - std::string getConnectorName() { return connector_name_; } + std::string getConnectorName() const { return connector_name_; } template void setLocalEndpoint(EP &&endpoint) { local_endpoint_ = std::forward(endpoint); } - Endpoint getLocalEndpoint() { return local_endpoint_; } + Endpoint getLocalEndpoint() const { return local_endpoint_; } - Endpoint getRemoteEndpoint() { return remote_endpoint_; } + Endpoint getRemoteEndpoint() const { return remote_endpoint_; } void setRole(Role r) { role_ = r; } - Role getRole() { return role_; } + Role getRole() const { return role_; } static utils::MemBuf::Ptr getPacketFromBuffer(uint8_t *buffer, std::size_t size) { @@ -213,8 +210,8 @@ class Connector : public std::enable_shared_from_this { OnReconnectCallback on_reconnect_callback_; // Connector state - std::atomic state_; - Id connector_id_; + std::atomic state_ = State::CLOSED; + Id connector_id_ = invalid_connector; // Endpoints Endpoint local_endpoint_; @@ -230,7 +227,7 @@ class Connector : public std::enable_shared_from_this { AtomicConnectorStats stats_; // Connection attempts - std::uint32_t connection_reattempts_; + std::uint32_t connection_reattempts_ = 0; }; } // namespace core diff --git a/libtransport/includes/hicn/transport/core/endpoint.h b/libtransport/includes/hicn/transport/core/endpoint.h index e1fa193d7..2278a1759 100644 --- a/libtransport/includes/hicn/transport/core/endpoint.h +++ b/libtransport/includes/hicn/transport/core/endpoint.h @@ -62,8 +62,8 @@ class Endpoint { #if 0 template Endpoint(Ip &&ip_address, Port &&port) - : address_(std::forward(ip_address)), - port_(std::forward(port)) {} + : address_(std::forward(ip_address)), + port_(std::forward(port)) {} #endif asio::ip::address getAddress() { return address_; } diff --git a/libtransport/includes/hicn/transport/core/interest.h b/libtransport/includes/hicn/transport/core/interest.h index 428829697..59da5b91f 100644 --- a/libtransport/includes/hicn/transport/core/interest.h +++ b/libtransport/includes/hicn/transport/core/interest.h @@ -88,7 +88,7 @@ class Interest uint32_t getLifetime() const override; - bool hasManifest(); + bool hasManifest() const; void appendSuffix(std::uint32_t suffix); diff --git a/libtransport/includes/hicn/transport/interfaces/publication_options.h b/libtransport/includes/hicn/transport/interfaces/publication_options.h index 03a0763f5..f4f409d00 100644 --- a/libtransport/includes/hicn/transport/interfaces/publication_options.h +++ b/libtransport/includes/hicn/transport/interfaces/publication_options.h @@ -25,7 +25,7 @@ class PublicationOptions { public: template PublicationOptions(T&& name, uint32_t lifetime) - : name_(std::forward(name)), + : name_(std::forward(name)), content_lifetime_milliseconds_(lifetime) {} TRANSPORT_ALWAYS_INLINE const core::Name& getName() const { return name_; } diff --git a/libtransport/includes/hicn/transport/utils/CMakeLists.txt b/libtransport/includes/hicn/transport/utils/CMakeLists.txt index bbd149e09..1dba94451 100644 --- a/libtransport/includes/hicn/transport/utils/CMakeLists.txt +++ b/libtransport/includes/hicn/transport/utils/CMakeLists.txt @@ -32,7 +32,6 @@ list(APPEND HEADER_FILES ${CMAKE_CURRENT_SOURCE_DIR}/string_utils.h ${CMAKE_CURRENT_SOURCE_DIR}/file.h ${CMAKE_CURRENT_SOURCE_DIR}/shared_ptr_utils.h - ${CMAKE_CURRENT_SOURCE_DIR}/move_wrapper.h ${CMAKE_CURRENT_SOURCE_DIR}/noncopyable.h ${CMAKE_CURRENT_SOURCE_DIR}/singleton.h ) diff --git a/libtransport/includes/hicn/transport/utils/move_wrapper.h b/libtransport/includes/hicn/transport/utils/move_wrapper.h deleted file mode 100644 index 73389948d..000000000 --- a/libtransport/includes/hicn/transport/utils/move_wrapper.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2021 Cisco and/or its affiliates. - * - * 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 - -namespace utils { - -template -struct MoveWrapper : F { - MoveWrapper(F&& f) : F(std::move(f)) {} - ~MoveWrapper() = default; - - MoveWrapper(MoveWrapper&&) = default; - MoveWrapper& operator=(MoveWrapper&&) = default; - - MoveWrapper(const MoveWrapper&); - MoveWrapper& operator=(const MoveWrapper&); -}; - -template -auto moveHandler(T&& t) -> MoveWrapper::type> { - return std::move(t); -} -} // namespace utils \ No newline at end of file diff --git a/libtransport/src/core/interest.cc b/libtransport/src/core/interest.cc index 10e1a6dfa..6348a8d3e 100644 --- a/libtransport/src/core/interest.cc +++ b/libtransport/src/core/interest.cc @@ -76,14 +76,13 @@ Interest &Interest::operator=(const Interest &other) { return (Interest &)Packet::operator=(other); } -Interest::~Interest() {} +Interest::~Interest() = default; const Name &Interest::getName() const { - if (!name_) { - if (hicn_interest_get_name( - &pkbuf_, (hicn_name_t *)&name_.getConstStructReference()) < 0) { - throw errors::MalformedPacketException(); - } + if (!name_ && + hicn_interest_get_name( + &pkbuf_, (hicn_name_t *)&name_.getConstStructReference()) < 0) { + throw errors::MalformedPacketException(); } return name_; @@ -149,7 +148,7 @@ void Interest::resetForHash() { } } -bool Interest::hasManifest() { +bool Interest::hasManifest() const { return (getPayloadType() == PayloadType::MANIFEST); } @@ -174,8 +173,7 @@ void Interest::encodeSuffixes() { memset(int_manifest_header->request_bitmap, 0xFFFFFFFF, BITMAP_SIZE * sizeof(hicn_uword)); - uint32_t *suffix = (uint32_t *)(int_manifest_header + 1); - for (auto it = suffix_set_.begin(); it != suffix_set_.end(); it++, suffix++) { + for (auto it = suffix_set_.begin(); it != suffix_set_.end(); it++) { interest_manifest_add_suffix(int_manifest_header, *it); } diff --git a/libtransport/src/core/local_connector.h b/libtransport/src/core/local_connector.h index 963f455e6..bf64b71d6 100644 --- a/libtransport/src/core/local_connector.h +++ b/libtransport/src/core/local_connector.h @@ -20,7 +20,6 @@ #include #include #include -#include #include #include diff --git a/libtransport/src/core/portal.h b/libtransport/src/core/portal.h index 7a6ab9d0e..c4ba096b9 100644 --- a/libtransport/src/core/portal.h +++ b/libtransport/src/core/portal.h @@ -56,7 +56,7 @@ class HandlerMemory { HandlerMemory(const HandlerMemory &) = delete; HandlerMemory &operator=(const HandlerMemory &) = delete; - void *allocate(std::size_t size) { + void *allocate(std::size_t /* size */) { return utils::FixedBlockAllocator<128, 8192>::getInstance().allocateBlock(); } -- cgit 1.2.3-korg