diff --git a/src/include/platform/PlatformManager.h b/src/include/platform/PlatformManager.h index 8b98c30da236e4..b19986c4850a25 100644 --- a/src/include/platform/PlatformManager.h +++ b/src/include/platform/PlatformManager.h @@ -25,22 +25,9 @@ #include #include +#include namespace chip { -namespace System { -namespace Platform { -namespace Layer { - -CHIP_ERROR PostEvent(System::Layer & aLayer, void * aContext, System::Object & aTarget, System::EventType aType, - uintptr_t aArgument); -CHIP_ERROR DispatchEvents(System::Layer & aLayer, void * aContext); -CHIP_ERROR DispatchEvent(System::Layer & aLayer, void * aContext, System::Event aEvent); -CHIP_ERROR StartTimer(System::Layer & aLayer, void * aContext, uint32_t aMilliseconds); - -} // namespace Layer -} // namespace Platform -} // namespace System - namespace DeviceLayer { class PlatformManagerImpl; @@ -183,14 +170,14 @@ class PlatformManager template friend class Internal::GenericConfigurationManagerImpl; // Parentheses used to fix clang parsing issue with these declarations - friend ::CHIP_ERROR(::chip::System::Platform::Layer::PostEvent)(::chip::System::Layer & aLayer, void * aContext, - ::chip::System::Object & aTarget, - ::chip::System::EventType aType, uintptr_t aArgument); - friend ::CHIP_ERROR(::chip::System::Platform::Layer::DispatchEvents)(::chip::System::Layer & aLayer, void * aContext); - friend ::CHIP_ERROR(::chip::System::Platform::Layer::DispatchEvent)(::chip::System::Layer & aLayer, void * aContext, - ::chip::System::Event aEvent); - friend ::CHIP_ERROR(::chip::System::Platform::Layer::StartTimer)(::chip::System::Layer & aLayer, void * aContext, - uint32_t aMilliseconds); + friend ::CHIP_ERROR(::chip::System::Platform::EventSupport::PostEvent)(::chip::System::Layer & aLayer, void * aContext, + ::chip::System::Object & aTarget, + ::chip::System::EventType aType, uintptr_t aArgument); + friend ::CHIP_ERROR(::chip::System::Platform::EventSupport::DispatchEvents)(::chip::System::Layer & aLayer, void * aContext); + friend ::CHIP_ERROR(::chip::System::Platform::EventSupport::DispatchEvent)(::chip::System::Layer & aLayer, void * aContext, + ::chip::System::Event aEvent); + friend ::CHIP_ERROR(::chip::System::Platform::EventSupport::StartTimer)(::chip::System::Layer & aLayer, + void * aContext, uint32_t aMilliseconds); void PostEvent(const ChipDeviceEvent * event); void DispatchEvent(const ChipDeviceEvent * event); diff --git a/src/platform/EFR32/SystemPlatformConfig.h b/src/platform/EFR32/SystemPlatformConfig.h index 19958242218282..8c48428f4fc043 100644 --- a/src/platform/EFR32/SystemPlatformConfig.h +++ b/src/platform/EFR32/SystemPlatformConfig.h @@ -36,8 +36,7 @@ struct ChipDeviceEvent; // ==================== Platform Adaptations ==================== #define CHIP_SYSTEM_CONFIG_PLATFORM_PROVIDES_EVENT_FUNCTIONS 1 #define CHIP_SYSTEM_CONFIG_PLATFORM_PROVIDES_TIME 1 -#define CHIP_SYSTEM_CONFIG_LWIP_EVENT_TYPE int -#define CHIP_SYSTEM_CONFIG_LWIP_EVENT_OBJECT_TYPE const struct ::chip::DeviceLayer::ChipDeviceEvent * +#define CHIP_SYSTEM_CONFIG_EVENT_OBJECT_TYPE const struct ::chip::DeviceLayer::ChipDeviceEvent * #define CHIP_SYSTEM_LWIP_ERROR_MIN 3000000 #define CHIP_SYSTEM_LWIP_ERROR_MAX 3000128 diff --git a/src/platform/ESP32/SystemPlatformConfig.h b/src/platform/ESP32/SystemPlatformConfig.h index 93e957ee688413..947d8dae5182fb 100644 --- a/src/platform/ESP32/SystemPlatformConfig.h +++ b/src/platform/ESP32/SystemPlatformConfig.h @@ -39,8 +39,7 @@ struct ChipDeviceEvent; // ==================== Platform Adaptations ==================== #define CHIP_SYSTEM_CONFIG_PLATFORM_PROVIDES_EVENT_FUNCTIONS 1 #define CHIP_SYSTEM_CONFIG_PLATFORM_PROVIDES_TIME 1 -#define CHIP_SYSTEM_CONFIG_LWIP_EVENT_TYPE int -#define CHIP_SYSTEM_CONFIG_LWIP_EVENT_OBJECT_TYPE const struct ::chip::DeviceLayer::ChipDeviceEvent * +#define CHIP_SYSTEM_CONFIG_EVENT_OBJECT_TYPE const struct ::chip::DeviceLayer::ChipDeviceEvent * #define CHIP_SYSTEM_LWIP_ERROR_MIN 3000000 #define CHIP_SYSTEM_LWIP_ERROR_MAX 3000128 diff --git a/src/platform/K32W/SystemPlatformConfig.h b/src/platform/K32W/SystemPlatformConfig.h index 44138dde4fc5ff..ccc1b1467c53b9 100644 --- a/src/platform/K32W/SystemPlatformConfig.h +++ b/src/platform/K32W/SystemPlatformConfig.h @@ -37,8 +37,7 @@ struct ChipDeviceEvent; // ==================== Platform Adaptations ==================== #define CHIP_SYSTEM_CONFIG_PLATFORM_PROVIDES_EVENT_FUNCTIONS 1 #define CHIP_SYSTEM_CONFIG_PLATFORM_PROVIDES_TIME 1 -#define CHIP_SYSTEM_CONFIG_LWIP_EVENT_TYPE int -#define CHIP_SYSTEM_CONFIG_LWIP_EVENT_OBJECT_TYPE const struct ::chip::DeviceLayer::ChipDeviceEvent * +#define CHIP_SYSTEM_CONFIG_EVENT_OBJECT_TYPE const struct ::chip::DeviceLayer::ChipDeviceEvent * #define CHIP_SYSTEM_LWIP_ERROR_MIN 3000000 #define CHIP_SYSTEM_LWIP_ERROR_MAX 3000128 diff --git a/src/platform/SystemEventSupport.cpp b/src/platform/SystemEventSupport.cpp index f29a30d81dc72d..918daf0b0c5a7a 100644 --- a/src/platform/SystemEventSupport.cpp +++ b/src/platform/SystemEventSupport.cpp @@ -30,7 +30,7 @@ namespace chip { namespace System { namespace Platform { -namespace Layer { +namespace EventSupport { using namespace ::chip::DeviceLayer; @@ -48,7 +48,7 @@ CHIP_ERROR PostEvent(System::Layer & aLayer, void * aContext, System::Object & a return CHIP_NO_ERROR; } -CHIP_ERROR DispatchEvents(Layer & aLayer, void * aContext) +CHIP_ERROR DispatchEvents(System::Layer & aLayer, void * aContext) { PlatformMgr().RunEventLoop(); @@ -62,7 +62,7 @@ CHIP_ERROR DispatchEvent(System::Layer & aLayer, void * aContext, const ChipDevi return CHIP_NO_ERROR; } -} // namespace Layer +} // namespace EventSupport } // namespace Platform } // namespace System } // namespace chip diff --git a/src/platform/SystemTimerSupport.cpp b/src/platform/SystemTimerSupport.cpp index 8e90c72b091efd..9cc1c2c42961ab 100644 --- a/src/platform/SystemTimerSupport.cpp +++ b/src/platform/SystemTimerSupport.cpp @@ -30,7 +30,7 @@ namespace chip { namespace System { namespace Platform { -namespace Layer { +namespace EventSupport { using namespace ::chip::DeviceLayer; @@ -39,7 +39,7 @@ CHIP_ERROR StartTimer(System::Layer & aLayer, void * aContext, uint32_t aMillise return PlatformMgr().StartChipTimer(aMilliseconds); } -} // namespace Layer +} // namespace EventSupport } // namespace Platform } // namespace System } // namespace chip diff --git a/src/platform/cc13x2_26x2/SystemPlatformConfig.h b/src/platform/cc13x2_26x2/SystemPlatformConfig.h index 7cd34b8feae10b..8de65534721dcd 100644 --- a/src/platform/cc13x2_26x2/SystemPlatformConfig.h +++ b/src/platform/cc13x2_26x2/SystemPlatformConfig.h @@ -36,8 +36,7 @@ struct ChipDeviceEvent; // ==================== Platform Adaptations ==================== #define CHIP_SYSTEM_CONFIG_PLATFORM_PROVIDES_EVENT_FUNCTIONS 1 #define CHIP_SYSTEM_CONFIG_PLATFORM_PROVIDES_TIME 1 -#define CHIP_SYSTEM_CONFIG_LWIP_EVENT_TYPE int -#define CHIP_SYSTEM_CONFIG_LWIP_EVENT_OBJECT_TYPE const struct ::chip::DeviceLayer::ChipDeviceEvent * +#define CHIP_SYSTEM_CONFIG_EVENT_OBJECT_TYPE const struct ::chip::DeviceLayer::ChipDeviceEvent * // ========== Platform-specific Configuration Overrides ========= diff --git a/src/platform/mbed/SystemPlatformConfig.h b/src/platform/mbed/SystemPlatformConfig.h index 2d273fe4da0d0d..dea97fe1d6c1f0 100644 --- a/src/platform/mbed/SystemPlatformConfig.h +++ b/src/platform/mbed/SystemPlatformConfig.h @@ -41,8 +41,7 @@ struct ChipDeviceEvent; #define CHIP_SYSTEM_CONFIG_NO_LOCKING 0 #define CHIP_SYSTEM_CONFIG_PLATFORM_PROVIDES_EVENT_FUNCTIONS 1 #define CHIP_SYSTEM_CONFIG_PLATFORM_PROVIDES_TIME 1 -#define CHIP_SYSTEM_CONFIG_LWIP_EVENT_TYPE int -#define CHIP_SYSTEM_CONFIG_LWIP_EVENT_OBJECT_TYPE const struct ::chip::DeviceLayer::ChipDeviceEvent * +#define CHIP_SYSTEM_CONFIG_EVENT_OBJECT_TYPE const struct ::chip::DeviceLayer::ChipDeviceEvent * #define CHIP_SYSTEM_CONFIG_ERROR_TYPE int32_t #define CHIP_SYSTEM_CONFIG_NO_ERROR 0 diff --git a/src/platform/qpg/SystemPlatformConfig.h b/src/platform/qpg/SystemPlatformConfig.h index 2b6114ff5fc56a..c7af8115bd205e 100644 --- a/src/platform/qpg/SystemPlatformConfig.h +++ b/src/platform/qpg/SystemPlatformConfig.h @@ -35,8 +35,7 @@ struct ChipDeviceEvent; // ==================== Platform Adaptations ==================== #define CHIP_SYSTEM_CONFIG_PLATFORM_PROVIDES_EVENT_FUNCTIONS 1 #define CHIP_SYSTEM_CONFIG_PLATFORM_PROVIDES_TIME 1 -#define CHIP_SYSTEM_CONFIG_LWIP_EVENT_TYPE int -#define CHIP_SYSTEM_CONFIG_LWIP_EVENT_OBJECT_TYPE const struct ::chip::DeviceLayer::ChipDeviceEvent * +#define CHIP_SYSTEM_CONFIG_EVENT_OBJECT_TYPE const struct ::chip::DeviceLayer::ChipDeviceEvent * #define CHIP_SYSTEM_LWIP_ERROR_MIN 3000000 #define CHIP_SYSTEM_LWIP_ERROR_MAX 3000128 diff --git a/src/system/SystemConfig.h b/src/system/SystemConfig.h index 5487148b14fbab..69572cb2ed13de 100644 --- a/src/system/SystemConfig.h +++ b/src/system/SystemConfig.h @@ -359,30 +359,6 @@ #ifndef CHIP_SYSTEM_CONFIG_PACKETBUFFER_CAPACITY_MAX #define CHIP_SYSTEM_CONFIG_PACKETBUFFER_CAPACITY_MAX 1583 #endif /* CHIP_SYSTEM_CONFIG_PACKETBUFFER_CAPACITY_MAX */ -#endif /* !CHIP_SYSTEM_CONFIG_USE_LWIP */ - -#if CHIP_SYSTEM_CONFIG_USE_LWIP - -/** - * @def CHIP_SYSTEM_CONFIG_LWIP_EVENT_TYPE - * - * @brief - * This defines the type for CHIP System Layer event types, typically an integral type. - */ -#ifndef CHIP_SYSTEM_CONFIG_LWIP_EVENT_TYPE -#define CHIP_SYSTEM_CONFIG_LWIP_EVENT_TYPE int -#endif /* CHIP_SYSTEM_CONFIG_LWIP_EVENT_TYPE */ - -/** - * @def CHIP_SYSTEM_CONFIG_LWIP_EVENT_UNRESERVED_CODE - * - * @brief - * This defines the first number in the default event code space not reserved for use by the CHIP System Layer. - * Event codes used by each layer must not overlap. - */ -#ifndef CHIP_SYSTEM_CONFIG_LWIP_EVENT_UNRESERVED_CODE -#define CHIP_SYSTEM_CONFIG_LWIP_EVENT_UNRESERVED_CODE 32 -#endif /* CHIP_SYSTEM_CONFIG_LWIP_EVENT_UNRESERVED_CODE */ /** * @def _CHIP_SYSTEM_CONFIG_LWIP_EVENT @@ -395,16 +371,30 @@ #define _CHIP_SYSTEM_CONFIG_LWIP_EVENT(e) (e) #endif /* _CHIP_SYSTEM_CONFIG_LWIP_EVENT */ +#endif /* !CHIP_SYSTEM_CONFIG_USE_LWIP */ + +/** + * @def CHIP_SYSTEM_CONFIG_EVENT_TYPE + * + * @brief + * This defines the type for CHIP System Layer event types, typically an integral type. + */ +#ifndef CHIP_SYSTEM_CONFIG_EVENT_TYPE +#define CHIP_SYSTEM_CONFIG_EVENT_TYPE int +#endif /* CHIP_SYSTEM_CONFIG_EVENT_TYPE */ + /** - * @def CHIP_SYSTEM_CONFIG_LWIP_EVENT_OBJECT_TYPE + * @def CHIP_SYSTEM_CONFIG_EVENT_OBJECT_TYPE * * @brief - * This defines the type of CHIP System Layer event objects or "messages" for the LwIP dispatcher. + * This defines the type of CHIP System Layer event objects or "messages". * * Such types are not directly used by the CHIP System Layer but are "passed through". Consequently a forward declaration and * a const pointer or reference are appropriate. */ -#ifndef CHIP_SYSTEM_CONFIG_LWIP_EVENT_OBJECT_TYPE +#ifndef CHIP_SYSTEM_CONFIG_EVENT_OBJECT_TYPE + +#if CHIP_SYSTEM_CONFIG_USE_LWIP namespace chip { namespace System { @@ -413,11 +403,32 @@ struct LwIPEvent; } // namespace System } // namespace chip -#define CHIP_SYSTEM_CONFIG_LWIP_EVENT_OBJECT_TYPE const struct chip::System::LwIPEvent* -#endif /* CHIP_SYSTEM_CONFIG_LWIP_EVENT_OBJECT_TYPE */ +#define CHIP_SYSTEM_CONFIG_EVENT_OBJECT_TYPE const struct chip::System::LwIPEvent* + +#else /* CHIP_SYSTEM_CONFIG_USE_LWIP */ + +#define CHIP_SYSTEM_CONFIG_EVENT_OBJECT_TYPE const struct ::chip::DeviceLayer::ChipDeviceEvent * #endif /* CHIP_SYSTEM_CONFIG_USE_LWIP */ +#endif /* CHIP_SYSTEM_CONFIG_EVENT_OBJECT_TYPE */ + +#if CHIP_SYSTEM_CONFIG_USE_LWIP + +/** + * @def _CHIP_SYSTEM_CONFIG_LWIP_EVENT + * + * @brief + * This defines a mapping function for CHIP System Layer codes for describing the types of events for the LwIP dispatcher, + * which allows mapping such event types into a platform- or system-specific range. + */ +#ifndef _CHIP_SYSTEM_CONFIG_LWIP_EVENT +#define _CHIP_SYSTEM_CONFIG_LWIP_EVENT(e) (e) +#endif /* _CHIP_SYSTEM_CONFIG_LWIP_EVENT */ + +#endif /* CHIP_SYSTEM_CONFIG_USE_LWIP */ + + /** * @def CHIP_SYSTEM_CONFIG_PLATFORM_PROVIDES_POSIX_ERROR_FUNCTIONS * @@ -449,10 +460,10 @@ struct LwIPEvent; * * @brief * This defines whether (1) or not (0) your platform will provide the following platform-specific functions: - * - chip::System::Platform::Layer::WillInit - * - chip::System::Platform::Layer::WillShutdown - * - chip::System::Platform::Layer::DidInit - * - chip::System::Platform::Layer::DidShutdown + * - chip::System::Platform::WillInit + * - chip::System::Platform::WillShutdown + * - chip::System::Platform::DidInit + * - chip::System::Platform::DidShutdown */ #ifndef CHIP_SYSTEM_CONFIG_PLATFORM_PROVIDES_XTOR_FUNCTIONS #define CHIP_SYSTEM_CONFIG_PLATFORM_PROVIDES_XTOR_FUNCTIONS 0 @@ -463,10 +474,10 @@ struct LwIPEvent; * * @brief * This defines whether (1) or not (0) your platform will provide the following platform-specific functions: - * - chip::System::Platform::Layer::PostEvent - * - chip::System::Platform::Layer::DispatchEvents - * - chip::System::Platform::Layer::DispatchEvent - * - chip::System::Platform::Layer::StartTimer + * - chip::System::Platform::EventSupport::PostEvent + * - chip::System::Platform::EventSupport::DispatchEvents + * - chip::System::Platform::EventSupport::DispatchEvent + * - chip::System::Platform::EventSupport::StartTimer */ #ifndef CHIP_SYSTEM_CONFIG_PLATFORM_PROVIDES_EVENT_FUNCTIONS #define CHIP_SYSTEM_CONFIG_PLATFORM_PROVIDES_EVENT_FUNCTIONS 0 diff --git a/src/system/SystemEvent.h b/src/system/SystemEvent.h index 3e50ac009cda75..96d88467a207e1 100644 --- a/src/system/SystemEvent.h +++ b/src/system/SystemEvent.h @@ -36,8 +36,6 @@ struct ChipDeviceEvent; namespace chip { namespace System { -#if CHIP_SYSTEM_CONFIG_USE_LWIP - /** * @typedef EventType * The basic type for all InetLayer events. @@ -45,7 +43,7 @@ namespace System { * This is defined to a platform- or system-specific type. * */ -typedef CHIP_SYSTEM_CONFIG_LWIP_EVENT_TYPE EventType; +typedef CHIP_SYSTEM_CONFIG_EVENT_TYPE EventType; /** * @typedef Event @@ -54,7 +52,9 @@ typedef CHIP_SYSTEM_CONFIG_LWIP_EVENT_TYPE EventType; * This is defined to a platform- or system-specific type. * */ -typedef CHIP_SYSTEM_CONFIG_LWIP_EVENT_OBJECT_TYPE Event; +typedef CHIP_SYSTEM_CONFIG_EVENT_OBJECT_TYPE Event; + +#if CHIP_SYSTEM_CONFIG_USE_LWIP /** * The Inet layer event type definitions. @@ -66,46 +66,6 @@ enum kEvent_ScheduleWork = _CHIP_SYSTEM_CONFIG_LWIP_EVENT(1), /**< The event for scheduling work on the System Layer's thread. */ }; -/** - * Check to verify if an EventType is a valid one. - * - * @param[in] aEventType CHIP System Layer event type. - * - * @return true if it falls within the enumerated range; otherwise, false. - */ -static inline bool IsEventOfType(EventType aEventType) -{ - return (aEventType >= kEvent_ReleaseObj && aEventType <= kEvent_ScheduleWork); -} - -#else - -#ifndef CHIP_SYSTEM_CONFIG_EVENT_TYPE -#define CHIP_SYSTEM_CONFIG_EVENT_TYPE int -#endif - -#ifndef CHIP_SYSTEM_CONFIG_EVENT_OBJECT_TYPE -#define CHIP_SYSTEM_CONFIG_EVENT_OBJECT_TYPE const struct ::chip::DeviceLayer::ChipDeviceEvent * -#endif - -/** - * @typedef EventType - * The basic type for all InetLayer events. - * - * This is defined to a platform- or system-specific type. - * - */ -typedef CHIP_SYSTEM_CONFIG_EVENT_TYPE EventType; - -/** - * @typedef Event - * The basic object for all InetLayer events. - * - * This is defined to a platform- or system-specific type. - * - */ -typedef CHIP_SYSTEM_CONFIG_EVENT_OBJECT_TYPE Event; - #endif // CHIP_SYSTEM_CONFIG_USE_LWIP } // namespace System diff --git a/src/system/SystemLayer.cpp b/src/system/SystemLayer.cpp index 3af4332e732559..4621856bce3e0b 100644 --- a/src/system/SystemLayer.cpp +++ b/src/system/SystemLayer.cpp @@ -68,6 +68,16 @@ namespace chip { namespace System { +namespace Platform { + +extern CHIP_ERROR WillInit(System::Layer & aLayer, void * aContext); +extern CHIP_ERROR WillShutdown(System::Layer & aLayer, void * aContext); + +extern void DidInit(System::Layer & aLayer, void * aContext, CHIP_ERROR aStatus); +extern void DidShutdown(System::Layer & aLayer, void * aContext, CHIP_ERROR aStatus); + +} // namespace Platform + namespace { Timer::Epoch GetTimerEpoch(const Callback::Cancelable * timer) @@ -139,7 +149,7 @@ CHIP_ERROR Layer::Init(void * aContext) if (this->mLayerState != kLayerState_NotInitialized) return CHIP_ERROR_INCORRECT_STATE; - lReturn = Platform::Layer::WillInit(*this, aContext); + lReturn = Platform::WillInit(*this, aContext); SuccessOrExit(lReturn); #if CHIP_SYSTEM_CONFIG_USE_SOCKETS @@ -159,7 +169,7 @@ CHIP_ERROR Layer::Init(void * aContext) this->mContext = aContext; exit: - Platform::Layer::DidInit(*this, aContext, lReturn); + Platform::DidInit(*this, aContext, lReturn); return lReturn; } @@ -172,7 +182,7 @@ CHIP_ERROR Layer::Shutdown() return CHIP_ERROR_INCORRECT_STATE; lContext = this->mContext; - lReturn = Platform::Layer::WillShutdown(*this, lContext); + lReturn = Platform::WillShutdown(*this, lContext); SuccessOrExit(lReturn); #if CHIP_SYSTEM_CONFIG_USE_SOCKETS || CHIP_SYSTEM_CONFIG_USE_NETWORK_FRAMEWORK @@ -198,7 +208,7 @@ CHIP_ERROR Layer::Shutdown() this->mLayerState = kLayerState_NotInitialized; exit: - Platform::Layer::DidShutdown(*this, lContext, lReturn); + Platform::DidShutdown(*this, lContext, lReturn); return lReturn; } @@ -810,7 +820,7 @@ CHIP_ERROR Layer::PostEvent(Object & aTarget, EventType aEventType, uintptr_t aA VerifyOrDieWithMsg(aTarget.IsRetained(*this), chipSystemLayer, "wrong poster! [target %p != this %p]", &(aTarget.SystemLayer()), this); - lReturn = Platform::Layer::PostEvent(*this, this->mContext, aTarget, aEventType, aArgument); + lReturn = Platform::EventSupport::PostEvent(*this, this->mContext, aTarget, aEventType, aArgument); if (lReturn != CHIP_NO_ERROR) { ChipLogError(chipSystemLayer, "Failed to queue CHIP System Layer event (type %d): %s", aEventType, ErrorStr(lReturn)); @@ -832,7 +842,7 @@ CHIP_ERROR Layer::DispatchEvents() CHIP_ERROR lReturn = CHIP_NO_ERROR; VerifyOrExit(this->State() == kLayerState_Initialized, lReturn = CHIP_ERROR_INCORRECT_STATE); - lReturn = Platform::Layer::DispatchEvents(*this, this->mContext); + lReturn = Platform::EventSupport::DispatchEvents(*this, this->mContext); SuccessOrExit(lReturn); exit: @@ -854,7 +864,7 @@ CHIP_ERROR Layer::DispatchEvent(Event aEvent) CHIP_ERROR lReturn = CHIP_NO_ERROR; VerifyOrExit(this->State() == kLayerState_Initialized, lReturn = CHIP_ERROR_INCORRECT_STATE); - lReturn = Platform::Layer::DispatchEvent(*this, this->mContext, aEvent); + lReturn = Platform::EventSupport::DispatchEvent(*this, this->mContext, aEvent); SuccessOrExit(lReturn); exit: @@ -926,7 +936,7 @@ CHIP_ERROR Layer::StartPlatformTimer(uint32_t aDelayMilliseconds) CHIP_ERROR lReturn = CHIP_NO_ERROR; VerifyOrExit(this->State() == kLayerState_Initialized, lReturn = CHIP_ERROR_INCORRECT_STATE); - lReturn = Platform::Layer::StartTimer(*this, this->mContext, aDelayMilliseconds); + lReturn = Platform::EventSupport::StartTimer(*this, this->mContext, aDelayMilliseconds); SuccessOrExit(lReturn); exit: @@ -974,7 +984,6 @@ struct LwIPEvent #endif // CHIP_SYSTEM_CONFIG_USE_LWIP namespace Platform { -namespace Layer { #if !CHIP_SYSTEM_CONFIG_PLATFORM_PROVIDES_XTOR_FUNCTIONS @@ -989,7 +998,7 @@ namespace Layer { * @return #CHIP_NO_ERROR on success; otherwise, a specific error indicating the reason for initialization failure. * Returning non-successful status will abort initialization. */ -DLL_EXPORT CHIP_ERROR WillInit(Layer & aLayer, void * aContext) +DLL_EXPORT CHIP_ERROR WillInit(System::Layer & aLayer, void * aContext) { static_cast(aLayer); static_cast(aContext); @@ -1008,7 +1017,7 @@ DLL_EXPORT CHIP_ERROR WillInit(Layer & aLayer, void * aContext) * @return #CHIP_NO_ERROR on success; otherwise, a specific error indicating the reason for shutdown failure. Returning * non-successful status will abort shutdown. */ -DLL_EXPORT CHIP_ERROR WillShutdown(Layer & aLayer, void * aContext) +DLL_EXPORT CHIP_ERROR WillShutdown(System::Layer & aLayer, void * aContext) { static_cast(aLayer); static_cast(aContext); @@ -1026,7 +1035,7 @@ DLL_EXPORT CHIP_ERROR WillShutdown(Layer & aLayer, void * aContext) * * @param[in] aStatus The overall status being returned via the CHIP System Layer \::Init method. */ -DLL_EXPORT void DidInit(Layer & aLayer, void * aContext, CHIP_ERROR aStatus) +DLL_EXPORT void DidInit(System::Layer & aLayer, void * aContext, CHIP_ERROR aStatus) { static_cast(aLayer); static_cast(aContext); @@ -1046,7 +1055,7 @@ DLL_EXPORT void DidInit(Layer & aLayer, void * aContext, CHIP_ERROR aStatus) * @return #CHIP_NO_ERROR on success; otherwise, a specific error indicating the reason for shutdown failure. Returning * non-successful status will abort shutdown. */ -DLL_EXPORT void DidShutdown(Layer & aLayer, void * aContext, CHIP_ERROR aStatus) +DLL_EXPORT void DidShutdown(System::Layer & aLayer, void * aContext, CHIP_ERROR aStatus) { static_cast(aLayer); static_cast(aContext); @@ -1058,6 +1067,8 @@ DLL_EXPORT void DidShutdown(Layer & aLayer, void * aContext, CHIP_ERROR aStatus) #if CHIP_SYSTEM_CONFIG_USE_LWIP #if !CHIP_SYSTEM_CONFIG_PLATFORM_PROVIDES_EVENT_FUNCTIONS +namespace EventSupport { + using chip::System::LwIPEvent; /** @@ -1219,10 +1230,11 @@ DLL_EXPORT CHIP_ERROR StartTimer(Layer & aLayer, void * aContext, uint32_t aMill return lReturn; } +} // namespace EventSupport + #endif // !CHIP_SYSTEM_CONFIG_PLATFORM_PROVIDES_EVENT_FUNCTIONS #endif // CHIP_SYSTEM_CONFIG_USE_LWIP -} // namespace Layer } // namespace Platform } // namespace System } // namespace chip diff --git a/src/system/SystemLayer.h b/src/system/SystemLayer.h index 8d8f9d465112e0..5aeb9db44d32ab 100644 --- a/src/system/SystemLayer.h +++ b/src/system/SystemLayer.h @@ -54,34 +54,17 @@ namespace System { class Layer; class Timer; - -#if CHIP_SYSTEM_CONFIG_USE_LWIP class Object; -#endif // CHIP_SYSTEM_CONFIG_USE_LWIP namespace Platform { -namespace Layer { +namespace EventSupport { -using ::chip::System::Layer; - -#if CHIP_SYSTEM_CONFIG_USE_LWIP -using ::chip::System::Object; -#endif // CHIP_SYSTEM_CONFIG_USE_LWIP - -extern CHIP_ERROR WillInit(Layer & aLayer, void * aContext); -extern CHIP_ERROR WillShutdown(Layer & aLayer, void * aContext); - -extern void DidInit(Layer & aLayer, void * aContext, CHIP_ERROR aStatus); -extern void DidShutdown(Layer & aLayer, void * aContext, CHIP_ERROR aStatus); - -#if CHIP_SYSTEM_CONFIG_USE_LWIP -extern CHIP_ERROR PostEvent(Layer & aLayer, void * aContext, Object & aTarget, EventType aType, uintptr_t aArgument); -extern CHIP_ERROR DispatchEvents(Layer & aLayer, void * aContext); -extern CHIP_ERROR DispatchEvent(Layer & aLayer, void * aContext, Event aEvent); -extern CHIP_ERROR StartTimer(Layer & aLayer, void * aContext, uint32_t aMilliseconds); -#endif // CHIP_SYSTEM_CONFIG_USE_LWIP +extern CHIP_ERROR PostEvent(System::Layer & aLayer, void * aContext, Object & aTarget, EventType aType, uintptr_t aArgument); +extern CHIP_ERROR DispatchEvents(System::Layer & aLayer, void * aContext); +extern CHIP_ERROR DispatchEvent(System::Layer & aLayer, void * aContext, Event aEvent); +extern CHIP_ERROR StartTimer(System::Layer & aLayer, void * aContext, uint32_t aMilliseconds); -} // namespace Layer +} // namespace EventSupport } // namespace Platform /** @@ -213,11 +196,11 @@ class DLL_EXPORT Layer CHIP_ERROR StartPlatformTimer(uint32_t aDelayMilliseconds); - friend CHIP_ERROR Platform::Layer::PostEvent(Layer & aLayer, void * aContext, Object & aTarget, EventType aType, - uintptr_t aArgument); - friend CHIP_ERROR Platform::Layer::DispatchEvents(Layer & aLayer, void * aContext); - friend CHIP_ERROR Platform::Layer::DispatchEvent(Layer & aLayer, void * aContext, Event aEvent); - friend CHIP_ERROR Platform::Layer::StartTimer(Layer & aLayer, void * aContext, uint32_t aMilliseconds); + friend CHIP_ERROR Platform::EventSupport::PostEvent(Layer & aLayer, void * aContext, Object & aTarget, EventType aType, + uintptr_t aArgument); + friend CHIP_ERROR Platform::EventSupport::DispatchEvents(Layer & aLayer, void * aContext); + friend CHIP_ERROR Platform::EventSupport::DispatchEvent(Layer & aLayer, void * aContext, Event aEvent); + friend CHIP_ERROR Platform::EventSupport::StartTimer(Layer & aLayer, void * aContext, uint32_t aMilliseconds); #endif // CHIP_SYSTEM_CONFIG_USE_LWIP #if CHIP_SYSTEM_CONFIG_USE_DISPATCH