Skip to content

Commit

Permalink
Collapse InetLayerBasis into EndPointBasis
Browse files Browse the repository at this point in the history
#### Problem

For historical reasons, Inet EndPoints had unnecessarily deep
class hierarchy, originally:

    InetLayerBasis
      EndPointBasis
        TCPEndPoint
        IPEndPointBasis
          UDPEndPoint

Previous PRs project-chip#11135 and project-chip#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.
  • Loading branch information
kpschoedel committed Oct 28, 2021
1 parent 26449ef commit a901412
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 75 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,28 @@ 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; }

protected:
void InitEndPointBasis(InetLayer & aInetLayer, void * aAppState = nullptr);
void DeferredFree(System::Object::ReleaseDeferralErrorTactic aTactic);
Expand Down Expand Up @@ -90,6 +106,9 @@ class DLL_EXPORT EndPointBasis : public InetLayerBasis
TCP = 4
} mLwIPEndPointType;
#endif // CHIP_SYSTEM_CONFIG_USE_LWIP

private:
InetLayer * mInetLayer; /**< Pointer to the InetLayer object that owns this object. */
};

} // namespace Inet
Expand Down
2 changes: 1 addition & 1 deletion src/inet/InetLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,7 @@ 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);
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 @@ -54,7 +54,7 @@
#include <inet/IPPrefix.h>
#include <inet/InetError.h>
#include <inet/InetInterface.h>
#include <inet/InetLayerBasis.h>
#include <inet/EndPointBasis.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 a901412

Please sign in to comment.