Skip to content

Commit

Permalink
Revisions to System::Layer (project-chip#8267)
Browse files Browse the repository at this point in the history
* Revisions to System::Layer

#### 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.

* restyle

* zap regen
  • Loading branch information
kpschoedel authored and Nikita committed Sep 23, 2021
1 parent 1cc84fa commit 0fec8e4
Show file tree
Hide file tree
Showing 13 changed files with 96 additions and 153 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 @@ -35,8 +35,7 @@ struct ChipDeviceEvent;

// ==================== Platform Adaptations ====================
#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/ESP32/SystemPlatformConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ struct ChipDeviceEvent;

// ==================== Platform Adaptations ====================
#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 *

// ==================== General Configuration Overrides ====================

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 @@ -36,8 +36,7 @@ struct ChipDeviceEvent;

// ==================== Platform Adaptations ====================
#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
4 changes: 2 additions & 2 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 Down Expand Up @@ -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 @@ -35,8 +35,7 @@ struct ChipDeviceEvent;

// ==================== Platform Adaptations ====================
#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 @@ -40,8 +40,7 @@ struct ChipDeviceEvent;
#define CHIP_SYSTEM_CONFIG_MBED_LOCKING 1
#define CHIP_SYSTEM_CONFIG_NO_LOCKING 0
#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/qpg/SystemPlatformConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ struct ChipDeviceEvent;

// ==================== Platform Adaptations ====================
#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
77 changes: 44 additions & 33 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,20 +403,41 @@ 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_XTOR_FUNCTIONS
*
* @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 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 0fec8e4

Please sign in to comment.