Skip to content

Commit

Permalink
Collapse InetLayerBasis into EndPointBasis (#11212)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
kpschoedel authored and pull[bot] committed Feb 8, 2024
1 parent b0b0837 commit 1036926
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 76 deletions.
1 change: 0 additions & 1 deletion src/inet/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ static_library("inet") {
"InetInterface.h",
"InetLayer.cpp",
"InetLayer.h",
"InetLayerBasis.h",
"InetLayerEvents.h",
"arpa-inet-compatibility.h",
]
Expand Down
11 changes: 7 additions & 4 deletions src/inet/EndPointBasis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ namespace Inet {

void EndPointBasis::InitEndPointBasis(InetLayer & aInetLayer, void * aAppState)
{
InitInetLayerBasis(aInetLayer, aAppState);
AppState = aAppState;
mInetLayer = &aInetLayer;
mLwIPEndPointType = LwIPEndPointType::Unknown;
}

Expand All @@ -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)
Expand All @@ -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)
Expand Down
25 changes: 22 additions & 3 deletions src/inet/EndPointBasis.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@
#include <inet/InetConfig.h>

#include <inet/IPAddress.h>
#include <inet/InetLayerBasis.h>

#include <lib/support/DLLUtil.h>
#include <system/SystemObject.h>

#if CHIP_SYSTEM_CONFIG_USE_SOCKETS
#include <system/SocketEvents.h>
Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/inet/InetLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<InetLayerBasis &>(aTarget);
InetLayer & lInetLayer = lBasis.Layer();
EndPointBasis & lBasis = static_cast<EndPointBasis &>(aTarget);
InetLayer & lInetLayer = lBasis.Layer();

lInetLayer.DroppableEventDequeued();
}
Expand Down
2 changes: 1 addition & 1 deletion src/inet/InetLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@

#include <inet/InetConfig.h>

#include <inet/EndPointBasis.h>
#include <inet/IANAConstants.h>
#include <inet/IPAddress.h>
#include <inet/IPPrefix.h>
#include <inet/InetError.h>
#include <inet/InetInterface.h>
#include <inet/InetLayerBasis.h>
#include <inet/InetLayerEvents.h>

#if INET_CONFIG_ENABLE_TCP_ENDPOINT
Expand Down
64 changes: 0 additions & 64 deletions src/inet/InetLayerBasis.h

This file was deleted.

2 changes: 1 addition & 1 deletion src/inet/UDPEndPoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <tt>InetLayerBasis::Release</tt> method to return the object to its
* Invokes the \c Close method, then invokes the <tt>EndPointBasis::Release</tt> 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.
Expand Down

0 comments on commit 1036926

Please sign in to comment.