Skip to content

Commit

Permalink
Revisions to System::Layer
Browse files Browse the repository at this point in the history
#### Problem

`System::Layer` has redundancy in event configuration,
and a confusingly-named grab-bag namespace `System::Platform::Layer`

This is a standalone fragment of work toward event/threading
refactoring, issue project-chip#7725.

#### Change overview

- Merge `CHIP_SYSTEM_CONFIG_LWIP_EVENT_OBJECT_TYPE` with
  `CHIP_SYSTEM_CONFIG_EVENT_OBJECT_TYPE`, and
  `CHIP_SYSTEM_CONFIG_LWIP_EVENT_TYPE` with
  `CHIP_SYSTEM_CONFIG_EVENT_TYPE`, since they serve the same purpose
  in LwIP and non-LwIP implementations respectively.
- Remove some dead configuration code.
- Move event functions from the `System::Platform::Layer` namespace
  (not the same kind of ‘layer’ as `System::Layer`) to a specific
  `System::Platform::EventSupport` namespace.
- Move (Will|Did)(Init|Shutdown) functions from the
  `System::Platform::Layer` namespace up to `System::Platform`.

#### Testing

No functional changes, only renaming and pruning.
  • Loading branch information
kpschoedel committed Jul 9, 2021
1 parent ac9c775 commit 83548c4
Show file tree
Hide file tree
Showing 13 changed files with 109 additions and 162 deletions.
31 changes: 9 additions & 22 deletions src/include/platform/PlatformManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,9 @@

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

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;
Expand Down Expand Up @@ -183,14 +170,14 @@ class PlatformManager
template <class>
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);
Expand Down
3 changes: 1 addition & 2 deletions src/platform/EFR32/SystemPlatformConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions src/platform/ESP32/SystemPlatformConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions src/platform/K32W/SystemPlatformConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/platform/SystemEventSupport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
namespace chip {
namespace System {
namespace Platform {
namespace Layer {
namespace EventSupport {

using namespace ::chip::DeviceLayer;

Expand All @@ -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();

Expand All @@ -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
4 changes: 2 additions & 2 deletions src/platform/SystemTimerSupport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
namespace chip {
namespace System {
namespace Platform {
namespace Layer {
namespace EventSupport {

using namespace ::chip::DeviceLayer;

Expand All @@ -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
3 changes: 1 addition & 2 deletions src/platform/cc13x2_26x2/SystemPlatformConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 =========

Expand Down
3 changes: 1 addition & 2 deletions src/platform/mbed/SystemPlatformConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions src/platform/qpg/SystemPlatformConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
85 changes: 48 additions & 37 deletions src/system/SystemConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {

Expand All @@ -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
*
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
48 changes: 4 additions & 44 deletions src/system/SystemEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,14 @@ struct ChipDeviceEvent;
namespace chip {
namespace System {

#if CHIP_SYSTEM_CONFIG_USE_LWIP

/**
* @typedef EventType
* The basic type for all InetLayer events.
*
* 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
Expand All @@ -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.
Expand All @@ -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
Expand Down
Loading

0 comments on commit 83548c4

Please sign in to comment.