From a609994417082370b0bb7e964f9185ea8103a1a9 Mon Sep 17 00:00:00 2001 From: Kevin Schoedel <67607049+kpschoedel@users.noreply.github.com> Date: Tue, 2 Nov 2021 10:52:45 -0400 Subject: [PATCH] Collapse InetLayerBasis into EndPointBasis (#11212) * Collapse InetLayerBasis into EndPointBasis #### Problem For historical reasons, Inet EndPoints had unnecessarily deep class hierarchy, originally: InetLayerBasis EndPointBasis TCPEndPoint IPEndPointBasis UDPEndPoint Previous PRs #11135 and #11145 merged `IPEndPointBasis` with `UDPEndPoint`. #### Change overview This change merges `InetLayerBasis` with `EndPointBasis`, so that the EndPoint class hierarchy is now: EndPointBasis TCPEndPoint UDPEndPoint #### Testing CI; no changes to functionality. * reorder members to avoid structure size increase on some platforms --- src/inet/BUILD.gn | 1 - src/inet/EndPointBasis.cpp | 11 ++++--- src/inet/EndPointBasis.h | 25 +++++++++++++-- src/inet/InetLayer.cpp | 4 +-- src/inet/InetLayer.h | 2 +- src/inet/InetLayerBasis.h | 64 -------------------------------------- src/inet/UDPEndPoint.h | 2 +- 7 files changed, 33 insertions(+), 76 deletions(-) delete mode 100644 src/inet/InetLayerBasis.h diff --git a/src/inet/BUILD.gn b/src/inet/BUILD.gn index 8bbbea0d69526a..77eb03ad819fe2 100644 --- a/src/inet/BUILD.gn +++ b/src/inet/BUILD.gn @@ -84,7 +84,6 @@ static_library("inet") { "InetInterface.h", "InetLayer.cpp", "InetLayer.h", - "InetLayerBasis.h", "InetLayerEvents.h", "arpa-inet-compatibility.h", ] diff --git a/src/inet/EndPointBasis.cpp b/src/inet/EndPointBasis.cpp index a3e5d54486bc7f..0dc43cf79e5ff2 100644 --- a/src/inet/EndPointBasis.cpp +++ b/src/inet/EndPointBasis.cpp @@ -34,7 +34,8 @@ namespace Inet { void EndPointBasis::InitEndPointBasis(InetLayer & aInetLayer, void * aAppState) { - InitInetLayerBasis(aInetLayer, aAppState); + AppState = aAppState; + mInetLayer = &aInetLayer; mLwIPEndPointType = LwIPEndPointType::Unknown; } @@ -56,8 +57,9 @@ void EndPointBasis::DeferredFree(System::Object::ReleaseDeferralErrorTactic aTac void EndPointBasis::InitEndPointBasis(InetLayer & aInetLayer, void * aAppState) { - InitInetLayerBasis(aInetLayer, aAppState); - mSocket = kInvalidSocketFd; + AppState = aAppState; + mInetLayer = &aInetLayer; + mSocket = kInvalidSocketFd; } void EndPointBasis::DeferredFree(System::Object::ReleaseDeferralErrorTactic aTactic) @@ -71,7 +73,8 @@ void EndPointBasis::DeferredFree(System::Object::ReleaseDeferralErrorTactic aTac void EndPointBasis::InitEndPointBasis(InetLayer & aInetLayer, void * aAppState) { - InitInetLayerBasis(aInetLayer, aAppState); + AppState = aAppState; + mInetLayer = &aInetLayer; } void EndPointBasis::DeferredFree(System::Object::ReleaseDeferralErrorTactic aTactic) diff --git a/src/inet/EndPointBasis.h b/src/inet/EndPointBasis.h index 154d32aa132447..a6decde4ae2353 100644 --- a/src/inet/EndPointBasis.h +++ b/src/inet/EndPointBasis.h @@ -27,9 +27,8 @@ #include #include -#include - #include +#include #if CHIP_SYSTEM_CONFIG_USE_SOCKETS #include @@ -47,11 +46,31 @@ struct tcp_pcb; namespace chip { namespace Inet { +class InetLayer; + /** * Basis of internet transport endpoint classes. */ -class DLL_EXPORT EndPointBasis : public InetLayerBasis +class DLL_EXPORT EndPointBasis : public System::Object { +public: + /** + * Returns a reference to the Inet layer object that owns this basis object. + */ + InetLayer & Layer() const { return *mInetLayer; } + + /** + * Returns \c true if the basis object was obtained by the specified Inet layer instance. + * + * @note + * Does not check whether the object is actually obtained by the system layer instance associated with the Inet layer + * instance. It merely tests whether \c aInetLayer is the Inet layer instance that was provided to \c InitInetLayerBasis. + */ + bool IsCreatedByInetLayer(const InetLayer & aInetLayer) const { return mInetLayer == &aInetLayer; } + +private: + InetLayer * mInetLayer; /**< Pointer to the InetLayer object that owns this object. */ + protected: void InitEndPointBasis(InetLayer & aInetLayer, void * aAppState = nullptr); void DeferredFree(System::Object::ReleaseDeferralErrorTactic aTactic); diff --git a/src/inet/InetLayer.cpp b/src/inet/InetLayer.cpp index 9cb196b9123668..6f8f279b53e878 100644 --- a/src/inet/InetLayer.cpp +++ b/src/inet/InetLayer.cpp @@ -656,8 +656,8 @@ CHIP_ERROR InetLayer::HandleInetLayerEvent(chip::System::Object & aTarget, chip: // If the event was droppable, record the fact that it has been dequeued. if (IsDroppableEvent(aEventType)) { - InetLayerBasis & lBasis = static_cast(aTarget); - InetLayer & lInetLayer = lBasis.Layer(); + EndPointBasis & lBasis = static_cast(aTarget); + InetLayer & lInetLayer = lBasis.Layer(); lInetLayer.DroppableEventDequeued(); } diff --git a/src/inet/InetLayer.h b/src/inet/InetLayer.h index d87917bd9efa0a..5f040b9f22c066 100644 --- a/src/inet/InetLayer.h +++ b/src/inet/InetLayer.h @@ -49,12 +49,12 @@ #include +#include #include #include #include #include #include -#include #include #if INET_CONFIG_ENABLE_TCP_ENDPOINT diff --git a/src/inet/InetLayerBasis.h b/src/inet/InetLayerBasis.h deleted file mode 100644 index 4645a8a118e67a..00000000000000 --- a/src/inet/InetLayerBasis.h +++ /dev/null @@ -1,64 +0,0 @@ -/* - * - * Copyright (c) 2020-2021 Project CHIP Authors - * Copyright (c) 2014-2017 Nest Labs, Inc. - * - * 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. - */ - -/** - * This file contains the basis class for reference counting objects by the Inet layer. - */ - -#pragma once - -#include - -namespace chip { -namespace Inet { - -class InetLayer; - -/** - * This is the basis class of reference-counted objects managed by an InetLayer object. - */ -class InetLayerBasis : public chip::System::Object -{ -public: - /** - * Returns a reference to the Inet layer object that owns this basis object. - */ - InetLayer & Layer() const { return *mInetLayer; } - - /** - * Returns \c true if the basis object was obtained by the specified Inet layer instance. - * - * @note - * Does not check whether the object is actually obtained by the system layer instance associated with the Inet layer - * instance. It merely tests whether \c aInetLayer is the Inet layer instance that was provided to \c InitInetLayerBasis. - */ - bool IsCreatedByInetLayer(const InetLayer & aInetLayer) const { return mInetLayer == &aInetLayer; } - -protected: - void InitInetLayerBasis(InetLayer & aInetLayer, void * aAppState = nullptr) - { - AppState = aAppState; - mInetLayer = &aInetLayer; - } - -private: - InetLayer * mInetLayer; /**< Pointer to the InetLayer object that owns this object. */ -}; - -} // namespace Inet -} // namespace chip diff --git a/src/inet/UDPEndPoint.h b/src/inet/UDPEndPoint.h index 50057ad93e6f4a..eadb2d935e3858 100644 --- a/src/inet/UDPEndPoint.h +++ b/src/inet/UDPEndPoint.h @@ -242,7 +242,7 @@ class DLL_EXPORT UDPEndPoint : public EndPointBasis /** * Close the endpoint and recycle its memory. * - * Invokes the \c Close method, then invokes the InetLayerBasis::Release method to return the object to its + * Invokes the \c Close method, then invokes the EndPointBasis::Release method to return the object to its * memory pool. * * On LwIP systems, this method must not be called with the LwIP stack lock already acquired.