Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restyle Inet/(TCP/UDP)Endpoints: Migrate from SystemPool to BitMapObjectPool #11429

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/app/tests/integration/chip_im_initiator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,7 @@ int main(int argc, char * argv[])
chip::DeviceLayer::PlatformMgr().RunEventLoop();

chip::app::InteractionModelEngine::GetInstance()->Shutdown();
gTransportManager.Close();
ShutdownChip();
exit:
if (err != CHIP_NO_ERROR || (gCommandRespCount != kMaxCommandMessageCount + kTotalFailureCommandMessageCount))
Expand Down
2 changes: 1 addition & 1 deletion src/app/tests/integration/chip_im_responder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ int main(int argc, char * argv[])
}

chip::app::InteractionModelEngine::GetInstance()->Shutdown();

gTransportManager.Close();
ShutdownChip();

return EXIT_SUCCESS;
Expand Down
10 changes: 2 additions & 8 deletions src/include/platform/CHIPDeviceEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -307,9 +307,9 @@ typedef void (*AsyncWorkFunct)(intptr_t arg);

#include <ble/BleConfig.h>
#include <inet/InetLayer.h>
#include <lib/support/LambdaBridge.h>
#include <system/SystemEvent.h>
#include <system/SystemLayer.h>
#include <system/SystemObject.h>
#include <system/SystemPacketBuffer.h>

namespace chip {
Expand All @@ -325,13 +325,7 @@ struct ChipDeviceEvent final
union
{
ChipDevicePlatformEvent Platform;
System::LambdaBridge LambdaEvent;
struct
{
::chip::System::EventType Type;
::chip::System::Object * Target;
uintptr_t Argument;
} ChipSystemLayerEvent;
LambdaBridge LambdaEvent;
struct
{
AsyncWorkFunct WorkFunct;
Expand Down
13 changes: 7 additions & 6 deletions src/include/platform/PlatformManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,9 @@

#include <platform/CHIPDeviceBuildConfig.h>
#include <platform/CHIPDeviceEvent.h>
#include <system/PlatformEventSupport.h>
#include <system/SystemLayer.h>

#if CHIP_SYSTEM_CONFIG_USE_LWIP
#include <system/LwIPEventSupport.h>
#endif // CHIP_SYSTEM_CONFIG_USE_LWIP

namespace chip {

namespace Dnssd {
Expand Down Expand Up @@ -136,6 +133,7 @@ class PlatformManager
* before calling Shutdown.
*/
void RunEventLoop();
void ProcessDeviceEvents();

/**
* Process work items until StopEventLoopTask is called.
Expand Down Expand Up @@ -225,9 +223,7 @@ class PlatformManager
friend class Internal::GenericThreadStackManagerImpl_OpenThread_LwIP;
template <class>
friend class Internal::GenericConfigurationManagerImpl;
#if CHIP_SYSTEM_CONFIG_USE_LWIP
friend class System::PlatformEventing;
#endif // CHIP_SYSTEM_CONFIG_USE_LWIP

/*
* PostEvent can be called safely on any thread without locking the stack.
Expand Down Expand Up @@ -354,6 +350,11 @@ inline void PlatformManager::RunEventLoop()
static_cast<ImplClass *>(this)->_RunEventLoop();
}

inline void PlatformManager::ProcessDeviceEvents()
{
static_cast<ImplClass *>(this)->_ProcessDeviceEvents();
}

/**
* @brief
* Starts the stack on its own task with an associated event queue
Expand Down
25 changes: 1 addition & 24 deletions src/include/platform/internal/GenericPlatformManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,13 +221,8 @@ void GenericPlatformManagerImpl<ImplClass>::_DispatchEvent(const ChipDeviceEvent
// Do nothing for no-op events.
break;

case DeviceEventType::kChipSystemLayerEvent:
// If the event is a CHIP System or Inet Layer event, deliver it to the System::Layer event handler.
Impl()->DispatchEventToSystemLayer(event);
break;

case DeviceEventType::kChipLambdaEvent:
event->LambdaEvent.LambdaProxy(static_cast<const void *>(event->LambdaEvent.LambdaBody));
event->LambdaEvent();
break;

case DeviceEventType::kCallWorkFunct:
Expand Down Expand Up @@ -259,24 +254,6 @@ void GenericPlatformManagerImpl<ImplClass>::_DispatchEvent(const ChipDeviceEvent
#endif // CHIP_PROGRESS_LOGGING
}

template <class ImplClass>
void GenericPlatformManagerImpl<ImplClass>::DispatchEventToSystemLayer(const ChipDeviceEvent * event)
{
// TODO(#788): remove ifdef LWIP once System::Layer event APIs are generally available
#if CHIP_SYSTEM_CONFIG_USE_LWIP
CHIP_ERROR err = CHIP_NO_ERROR;

// Invoke the System Layer's event handler function.
err = static_cast<System::LayerImplLwIP &>(SystemLayer())
.HandleEvent(*event->ChipSystemLayerEvent.Target, event->ChipSystemLayerEvent.Type,
event->ChipSystemLayerEvent.Argument);
if (err != CHIP_NO_ERROR)
{
ChipLogError(DeviceLayer, "Error handling CHIP System Layer event (type %d): %s", event->Type, ErrorStr(err));
}
#endif
}

template <class ImplClass>
void GenericPlatformManagerImpl<ImplClass>::DispatchEventToDeviceLayer(const ChipDeviceEvent * event)
{
Expand Down
1 change: 0 additions & 1 deletion src/include/platform/internal/GenericPlatformManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ class GenericPlatformManagerImpl

// ===== Support methods that can be overridden by the implementation subclass.

void DispatchEventToSystemLayer(const ChipDeviceEvent * event);
void DispatchEventToDeviceLayer(const ChipDeviceEvent * event);
void DispatchEventToApplication(const ChipDeviceEvent * event);
static void HandleMessageLayerActivityChanged(bool messageLayerIsActive);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,18 @@ void GenericPlatformManagerImpl_FreeRTOS<ImplClass>::_RunEventLoop(void)
}
}

template <class ImplClass>
void GenericPlatformManagerImpl_FreeRTOS<ImplClass>::_ProcessDeviceEvents()
{
ChipDeviceEvent event;
BaseType_t eventReceived = xQueueReceive(mChipEventQueue, &event, 0);
while (eventReceived == pdTRUE)
{
Impl()->DispatchEvent(&event);
eventReceived = xQueueReceive(mChipEventQueue, &event, 0);
}
}

template <class ImplClass>
CHIP_ERROR GenericPlatformManagerImpl_FreeRTOS<ImplClass>::_StartEventLoopTask(void)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class GenericPlatformManagerImpl_FreeRTOS : public GenericPlatformManagerImpl<Im
void _UnlockChipStack(void);
CHIP_ERROR _PostEvent(const ChipDeviceEvent * event);
void _RunEventLoop(void);
void _ProcessDeviceEvents();
CHIP_ERROR _StartEventLoopTask(void);
CHIP_ERROR _StopEventLoopTask();
CHIP_ERROR _StartChipTimer(System::Clock::Timeout duration);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ CHIP_ERROR GenericPlatformManagerImpl_POSIX<ImplClass>::_PostEvent(const ChipDev
}

template <class ImplClass>
void GenericPlatformManagerImpl_POSIX<ImplClass>::ProcessDeviceEvents()
void GenericPlatformManagerImpl_POSIX<ImplClass>::_ProcessDeviceEvents()
{
while (!mChipEventQueue.Empty())
{
Expand Down Expand Up @@ -180,7 +180,7 @@ void GenericPlatformManagerImpl_POSIX<ImplClass>::_RunEventLoop()

SystemLayerSocketsLoop().HandleEvents();

ProcessDeviceEvents();
_ProcessDeviceEvents();
} while (mShouldRunEventLoop.load(std::memory_order_relaxed));
SystemLayerSocketsLoop().EventLoopEnds();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ class GenericPlatformManagerImpl_POSIX : public GenericPlatformManagerImpl<ImplC
void _UnlockChipStack();
CHIP_ERROR _PostEvent(const ChipDeviceEvent * event);
void _RunEventLoop();
void _ProcessDeviceEvents();

CHIP_ERROR _StartEventLoopTask();
CHIP_ERROR _StopEventLoopTask();
CHIP_ERROR _StartChipTimer(System::Clock::Timeout duration);
Expand All @@ -107,8 +109,6 @@ class GenericPlatformManagerImpl_POSIX : public GenericPlatformManagerImpl<ImplC

inline ImplClass * Impl() { return static_cast<ImplClass *>(this); }

void ProcessDeviceEvents();

DeviceSafeQueue mChipEventQueue;
std::atomic<bool> mShouldRunEventLoop;
static void * EventLoopTaskMain(void * arg);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ CHIP_ERROR GenericPlatformManagerImpl_Zephyr<ImplClass>::_PostEvent(const ChipDe
}

template <class ImplClass>
void GenericPlatformManagerImpl_Zephyr<ImplClass>::ProcessDeviceEvents()
void GenericPlatformManagerImpl_Zephyr<ImplClass>::_ProcessDeviceEvents()
{
ChipDeviceEvent event;

Expand All @@ -148,7 +148,7 @@ void GenericPlatformManagerImpl_Zephyr<ImplClass>::_RunEventLoop(void)

SystemLayerSocketsLoop().HandleEvents();

ProcessDeviceEvents();
_ProcessDeviceEvents();
}
SystemLayerSocketsLoop().EventLoopEnds();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class GenericPlatformManagerImpl_Zephyr : public GenericPlatformManagerImpl<Impl
void _UnlockChipStack(void);
CHIP_ERROR _PostEvent(const ChipDeviceEvent * event);
void _RunEventLoop(void);
void _ProcessDeviceEvents();
CHIP_ERROR _StartEventLoopTask(void);
CHIP_ERROR _StopEventLoopTask();
CHIP_ERROR _StartChipTimer(System::Clock::Timeout duration);
Expand All @@ -89,7 +90,6 @@ class GenericPlatformManagerImpl_Zephyr : public GenericPlatformManagerImpl<Impl
ImplClass * Impl() { return static_cast<ImplClass *>(this); }
void SysUpdate();
void SysProcess();
void ProcessDeviceEvents();

static void EventLoopTaskMain(void * thisPtr, void *, void *);
};
Expand Down
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",
"InetLayerEvents.h",
"arpa-inet-compatibility.h",
]

Expand Down
22 changes: 0 additions & 22 deletions src/inet/EndPointBasis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,6 @@ void EndPointBasis::InitEndPointBasis(InetLayer & aInetLayer, void * aAppState)
mLwIPEndPointType = LwIPEndPointType::Unknown;
}

void EndPointBasis::DeferredFree(System::Object::ReleaseDeferralErrorTactic aTactic)
{
if (!CHIP_SYSTEM_CONFIG_USE_SOCKETS || (mVoid != nullptr))
{
DeferredRelease(static_cast<System::LayerLwIP *>(Layer().SystemLayer()), aTactic);
}
else
{
Release();
}
}

#endif // CHIP_SYSTEM_CONFIG_USE_LWIP

#if CHIP_SYSTEM_CONFIG_USE_SOCKETS
Expand All @@ -62,11 +50,6 @@ void EndPointBasis::InitEndPointBasis(InetLayer & aInetLayer, void * aAppState)
mSocket = kInvalidSocketFd;
}

void EndPointBasis::DeferredFree(System::Object::ReleaseDeferralErrorTactic aTactic)
{
Release();
}

#endif // CHIP_SYSTEM_CONFIG_USE_SOCKETS

#if CHIP_SYSTEM_CONFIG_USE_NETWORK_FRAMEWORK
Expand All @@ -77,11 +60,6 @@ void EndPointBasis::InitEndPointBasis(InetLayer & aInetLayer, void * aAppState)
mInetLayer = &aInetLayer;
}

void EndPointBasis::DeferredFree(System::Object::ReleaseDeferralErrorTactic aTactic)
{
Release();
}

#endif // CHIP_SYSTEM_CONFIG_USE_NETWORK_FRAMEWORK

} // namespace Inet
Expand Down
7 changes: 3 additions & 4 deletions src/inet/EndPointBasis.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@

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

#if CHIP_SYSTEM_CONFIG_USE_SOCKETS
#include <system/SocketEvents.h>
Expand All @@ -51,7 +50,7 @@ class InetLayer;
/**
* Basis of internet transport endpoint classes.
*/
class DLL_EXPORT EndPointBasis : public System::Object
class DLL_EXPORT EndPointBasis
{
public:
/**
Expand All @@ -68,12 +67,13 @@ class DLL_EXPORT EndPointBasis : public System::Object
*/
bool IsCreatedByInetLayer(const InetLayer & aInetLayer) const { return mInetLayer == &aInetLayer; }

void * AppState;

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);

#if CHIP_SYSTEM_CONFIG_USE_NETWORK_FRAMEWORK
nw_parameters_t mParameters;
Expand All @@ -91,7 +91,6 @@ class DLL_EXPORT EndPointBasis : public System::Object
/** Encapsulated LwIP protocol control block */
union
{
const void * mVoid; /**< An untyped protocol control buffer reference */
#if INET_CONFIG_ENABLE_UDP_ENDPOINT
udp_pcb * mUDP; /**< User datagram protocol (UDP) control */
#endif // INET_CONFIG_ENABLE_UDP_ENDPOINT
Expand Down
1 change: 0 additions & 1 deletion src/inet/Inet.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
#include <inet/InetError.h>
#include <inet/InetInterface.h>
#include <inet/InetLayer.h>
#include <inet/InetLayerEvents.h>

#if INET_CONFIG_ENABLE_TCP_ENDPOINT
#include <inet/TCPEndPoint.h>
Expand Down
1 change: 0 additions & 1 deletion src/inet/InetInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
#include "InetInterface.h"

#include "InetLayer.h"
#include "InetLayerEvents.h"

#include <lib/support/CHIPMemString.h>
#include <lib/support/CodeUtils.h>
Expand Down
Loading