Skip to content

Commit

Permalink
new: teardown fnc on clusters that use Matter Timers
Browse files Browse the repository at this point in the history
  • Loading branch information
rochaferraz committed Feb 11, 2023
1 parent ba1ef67 commit 2d53fb8
Show file tree
Hide file tree
Showing 14 changed files with 726 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1591,9 +1591,11 @@
}; \
const EmberAfGenericClusterFunction chipFuncArrayOnOffServer[] = { \
(EmberAfGenericClusterFunction) emberAfOnOffClusterServerInitCallback, \
(EmberAfGenericClusterFunction) MatterOnOffClusterServerShutdownCallback, \
}; \
const EmberAfGenericClusterFunction chipFuncArrayLevelControlServer[] = { \
(EmberAfGenericClusterFunction) emberAfLevelControlClusterServerInitCallback, \
(EmberAfGenericClusterFunction) MatterLevelControlClusterServerShutdownCallback, \
}; \
const EmberAfGenericClusterFunction chipFuncArrayModeSelectServer[] = { \
(EmberAfGenericClusterFunction) emberAfModeSelectClusterServerInitCallback, \
Expand All @@ -1602,10 +1604,14 @@
const EmberAfGenericClusterFunction chipFuncArrayDoorLockServer[] = { \
(EmberAfGenericClusterFunction) MatterDoorLockClusterServerAttributeChangedCallback, \
(EmberAfGenericClusterFunction) MatterDoorLockClusterServerPreAttributeChangedCallback, \
(EmberAfGenericClusterFunction) MatterDoorLockClusterServerShutdownCallback, \
}; \
const EmberAfGenericClusterFunction chipFuncArrayWindowCoveringServer[] = { \
(EmberAfGenericClusterFunction) MatterWindowCoveringClusterServerAttributeChangedCallback, \
}; \
const EmberAfGenericClusterFunction chipFuncArrayBarrierControlServer[] = { \
(EmberAfGenericClusterFunction) MatterBarrierControlClusterServerShutdownCallback, \
}; \
const EmberAfGenericClusterFunction chipFuncArrayPumpConfigurationAndControlServer[] = { \
(EmberAfGenericClusterFunction) emberAfPumpConfigurationAndControlClusterServerInitCallback, \
(EmberAfGenericClusterFunction) MatterPumpConfigurationAndControlClusterServerAttributeChangedCallback, \
Expand All @@ -1624,6 +1630,7 @@
}; \
const EmberAfGenericClusterFunction chipFuncArrayColorControlServer[] = { \
(EmberAfGenericClusterFunction) emberAfColorControlClusterServerInitCallback, \
(EmberAfGenericClusterFunction) MatterColorControlClusterServerShutdownCallback, \
}; \
const EmberAfGenericClusterFunction chipFuncArrayOccupancySensingServer[] = { \
(EmberAfGenericClusterFunction) emberAfOccupancySensingClusterServerInitCallback, \
Expand Down Expand Up @@ -2383,7 +2390,7 @@
.attributes = ZAP_ATTRIBUTE_INDEX(247), \
.attributeCount = 7, \
.clusterSize = 13, \
.mask = ZAP_CLUSTER_MASK(SERVER) | ZAP_CLUSTER_MASK(INIT_FUNCTION), \
.mask = ZAP_CLUSTER_MASK(SERVER) | ZAP_CLUSTER_MASK(INIT_FUNCTION) | ZAP_CLUSTER_MASK(SHUTDOWN_FUNCTION), \
.functions = chipFuncArrayOnOffServer, \
.acceptedCommandList = ZAP_GENERATED_COMMANDS_INDEX( 109 ) ,\
.generatedCommandList = nullptr ,\
Expand All @@ -2409,7 +2416,7 @@
.attributes = ZAP_ATTRIBUTE_INDEX(258), \
.attributeCount = 16, \
.clusterSize = 27, \
.mask = ZAP_CLUSTER_MASK(SERVER) | ZAP_CLUSTER_MASK(INIT_FUNCTION), \
.mask = ZAP_CLUSTER_MASK(SERVER) | ZAP_CLUSTER_MASK(INIT_FUNCTION) | ZAP_CLUSTER_MASK(SHUTDOWN_FUNCTION), \
.functions = chipFuncArrayLevelControlServer, \
.acceptedCommandList = ZAP_GENERATED_COMMANDS_INDEX( 116 ) ,\
.generatedCommandList = nullptr ,\
Expand Down Expand Up @@ -2552,7 +2559,7 @@
.attributes = ZAP_ATTRIBUTE_INDEX(324), \
.attributeCount = 33, \
.clusterSize = 55, \
.mask = ZAP_CLUSTER_MASK(SERVER) | ZAP_CLUSTER_MASK(ATTRIBUTE_CHANGED_FUNCTION) | ZAP_CLUSTER_MASK(PRE_ATTRIBUTE_CHANGED_FUNCTION), \
.mask = ZAP_CLUSTER_MASK(SERVER) | ZAP_CLUSTER_MASK(ATTRIBUTE_CHANGED_FUNCTION) | ZAP_CLUSTER_MASK(PRE_ATTRIBUTE_CHANGED_FUNCTION) | ZAP_CLUSTER_MASK(SHUTDOWN_FUNCTION), \
.functions = chipFuncArrayDoorLockServer, \
.acceptedCommandList = ZAP_GENERATED_COMMANDS_INDEX( 127 ) ,\
.generatedCommandList = ZAP_GENERATED_COMMANDS_INDEX( 142 ) ,\
Expand All @@ -2578,8 +2585,8 @@
.attributes = ZAP_ATTRIBUTE_INDEX(381), \
.attributeCount = 6, \
.clusterSize = 11, \
.mask = ZAP_CLUSTER_MASK(SERVER), \
.functions = NULL, \
.mask = ZAP_CLUSTER_MASK(SERVER) | ZAP_CLUSTER_MASK(SHUTDOWN_FUNCTION), \
.functions = chipFuncArrayBarrierControlServer, \
.acceptedCommandList = ZAP_GENERATED_COMMANDS_INDEX( 156 ) ,\
.generatedCommandList = nullptr ,\
.eventList = nullptr, \
Expand Down Expand Up @@ -2643,7 +2650,7 @@
.attributes = ZAP_ATTRIBUTE_INDEX(446), \
.attributeCount = 54, \
.clusterSize = 345, \
.mask = ZAP_CLUSTER_MASK(SERVER) | ZAP_CLUSTER_MASK(INIT_FUNCTION), \
.mask = ZAP_CLUSTER_MASK(SERVER) | ZAP_CLUSTER_MASK(INIT_FUNCTION) | ZAP_CLUSTER_MASK(SHUTDOWN_FUNCTION), \
.functions = chipFuncArrayColorControlServer, \
.acceptedCommandList = ZAP_GENERATED_COMMANDS_INDEX( 161 ) ,\
.generatedCommandList = nullptr ,\
Expand Down Expand Up @@ -2929,7 +2936,7 @@
.attributes = ZAP_ATTRIBUTE_INDEX(682), \
.attributeCount = 7, \
.clusterSize = 13, \
.mask = ZAP_CLUSTER_MASK(SERVER) | ZAP_CLUSTER_MASK(INIT_FUNCTION), \
.mask = ZAP_CLUSTER_MASK(SERVER) | ZAP_CLUSTER_MASK(INIT_FUNCTION) | ZAP_CLUSTER_MASK(SHUTDOWN_FUNCTION), \
.functions = chipFuncArrayOnOffServer, \
.acceptedCommandList = ZAP_GENERATED_COMMANDS_INDEX( 237 ) ,\
.generatedCommandList = nullptr ,\
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -608,12 +608,15 @@
}; \
const EmberAfGenericClusterFunction chipFuncArrayOnOffServer[] = { \
(EmberAfGenericClusterFunction) emberAfOnOffClusterServerInitCallback, \
(EmberAfGenericClusterFunction) MatterOnOffClusterServerShutdownCallback, \
}; \
const EmberAfGenericClusterFunction chipFuncArrayLevelControlServer[] = { \
(EmberAfGenericClusterFunction) emberAfLevelControlClusterServerInitCallback, \
(EmberAfGenericClusterFunction) MatterLevelControlClusterServerShutdownCallback, \
}; \
const EmberAfGenericClusterFunction chipFuncArrayColorControlServer[] = { \
(EmberAfGenericClusterFunction) emberAfColorControlClusterServerInitCallback, \
(EmberAfGenericClusterFunction) MatterColorControlClusterServerShutdownCallback, \
}; \
const EmberAfGenericClusterFunction chipFuncArrayOccupancySensingServer[] = { \
(EmberAfGenericClusterFunction) emberAfOccupancySensingClusterServerInitCallback, \
Expand Down Expand Up @@ -1115,7 +1118,7 @@
.attributes = ZAP_ATTRIBUTE_INDEX(214), \
.attributeCount = 7, \
.clusterSize = 13, \
.mask = ZAP_CLUSTER_MASK(SERVER) | ZAP_CLUSTER_MASK(INIT_FUNCTION), \
.mask = ZAP_CLUSTER_MASK(SERVER) | ZAP_CLUSTER_MASK(INIT_FUNCTION) | ZAP_CLUSTER_MASK(SHUTDOWN_FUNCTION), \
.functions = chipFuncArrayOnOffServer, \
.acceptedCommandList = ZAP_GENERATED_COMMANDS_INDEX( 88 ) ,\
.generatedCommandList = nullptr ,\
Expand All @@ -1128,7 +1131,7 @@
.attributes = ZAP_ATTRIBUTE_INDEX(221), \
.attributeCount = 16, \
.clusterSize = 27, \
.mask = ZAP_CLUSTER_MASK(SERVER) | ZAP_CLUSTER_MASK(INIT_FUNCTION), \
.mask = ZAP_CLUSTER_MASK(SERVER) | ZAP_CLUSTER_MASK(INIT_FUNCTION) | ZAP_CLUSTER_MASK(SHUTDOWN_FUNCTION), \
.functions = chipFuncArrayLevelControlServer, \
.acceptedCommandList = ZAP_GENERATED_COMMANDS_INDEX( 95 ) ,\
.generatedCommandList = nullptr ,\
Expand All @@ -1154,7 +1157,7 @@
.attributes = ZAP_ATTRIBUTE_INDEX(243), \
.attributeCount = 23, \
.clusterSize = 40, \
.mask = ZAP_CLUSTER_MASK(SERVER) | ZAP_CLUSTER_MASK(INIT_FUNCTION), \
.mask = ZAP_CLUSTER_MASK(SERVER) | ZAP_CLUSTER_MASK(INIT_FUNCTION) | ZAP_CLUSTER_MASK(SHUTDOWN_FUNCTION), \
.functions = chipFuncArrayColorControlServer, \
.acceptedCommandList = ZAP_GENERATED_COMMANDS_INDEX( 104 ) ,\
.generatedCommandList = nullptr ,\
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ static void scheduleTimerCallbackMs(EndpointId endpoint, uint32_t delayMs)
reinterpret_cast<void *>(static_cast<uintptr_t>(endpoint)));
}

static void deactivateEndpointTimerCallback(EndpointId endpoint)
static void cancelEndpointTimerCallback(EndpointId endpoint)
{
DeviceLayer::SystemLayer().CancelTimer(timerCallback, reinterpret_cast<void *>(static_cast<uintptr_t>(endpoint)));
}
Expand Down Expand Up @@ -248,7 +248,7 @@ void emberAfBarrierControlClusterServerTickCallback(EndpointId endpoint)
{
emAfPluginBarrierControlServerSetBarrierPosition(endpoint, state.currentPosition);
setMovingState(endpoint, EMBER_ZCL_BARRIER_CONTROL_MOVING_STATE_STOPPED);
deactivateEndpointTimerCallback(endpoint);
cancelEndpointTimerCallback(endpoint);
}
else
{
Expand Down Expand Up @@ -342,10 +342,15 @@ bool emberAfBarrierControlClusterBarrierControlStopCallback(app::CommandHandler
const Commands::BarrierControlStop::DecodableType & commandData)
{
EndpointId endpoint = commandPath.mEndpointId;
deactivateEndpointTimerCallback(endpoint);
cancelEndpointTimerCallback(endpoint);
setMovingState(endpoint, EMBER_ZCL_BARRIER_CONTROL_MOVING_STATE_STOPPED);
sendDefaultResponse(EMBER_ZCL_STATUS_SUCCESS);
return true;
}

void MatterBarrierControlPluginServerInitCallback() {}

void MatterBarrierControlClusterServerShutdownCallback(EndpointId endpoint)
{
cancelEndpointTimerCallback(endpoint);
}
17 changes: 13 additions & 4 deletions src/app/clusters/color-control-server/color-control-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,13 @@ void ColorControlServer::scheduleTimerCallbackMs(EmberEventControl * control, ui
{
ChipLogError(Zcl, "Color Control Server failed to schedule event: %" CHIP_ERROR_FORMAT, err.Format());
}
else
{
control->status = EMBER_EVENT_MS_TIME;
}
}

void ColorControlServer::deactivateEndpointTimerCallback(EmberEventControl * control)
void ColorControlServer::cancelEndpointTimerCallback(EmberEventControl * control)
{
if (control->status != EMBER_EVENT_INACTIVE)
{
Expand All @@ -59,10 +63,10 @@ void ColorControlServer::deactivateEndpointTimerCallback(EmberEventControl * con
DeviceLayer::SystemLayer().CancelTimer(timerCallback, control);
}

void ColorControlServer::deactivateEndpointTimerCallback(EndpointId endpoint)
void ColorControlServer::cancelEndpointTimerCallback(EndpointId endpoint)
{
auto control = ColorControlServer::getEventControl(endpoint);
deactivateEndpointTimerCallback(control);
cancelEndpointTimerCallback(control);
}

/**********************************************************
Expand Down Expand Up @@ -94,7 +98,7 @@ EmberAfStatus ColorControlServer::stopAllColorTransitions(EndpointId endpoint)
EmberEventControl * event = getEventControl(endpoint);
VerifyOrReturnError(event != nullptr, EMBER_ZCL_STATUS_UNSUPPORTED_ENDPOINT);

deactivateEndpointTimerCallback(event);
cancelEndpointTimerCallback(event);
return EMBER_ZCL_STATUS_SUCCESS;
}

Expand Down Expand Up @@ -2674,6 +2678,11 @@ void emberAfColorControlClusterServerInitCallback(EndpointId endpoint)
#endif // EMBER_AF_PLUGIN_COLOR_CONTROL_SERVER_TEMP
}

void MatterColorControlClusterServerShutdownCallback(EndpointId endpoint)
{
ColorControlServer::Instance().cancelEndpointTimerCallback(endpoint);
}

#ifdef EMBER_AF_PLUGIN_COLOR_CONTROL_SERVER_TEMP
/**
* @brief Callback for temperature update when timer is finished
Expand Down
5 changes: 3 additions & 2 deletions src/app/clusters/color-control-server/color-control-server.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ class ColorControlServer
void updateTempCommand(chip::EndpointId endpoint);
#endif // EMBER_AF_PLUGIN_COLOR_CONTROL_SERVER_TEMP

void cancelEndpointTimerCallback(chip::EndpointId endpoint);

private:
/**********************************************************
* Functions Definitions
Expand All @@ -193,8 +195,7 @@ class ColorControlServer
// Matter timer scheduling glue logic
static void timerCallback(chip::System::Layer *, void * callbackContext);
void scheduleTimerCallbackMs(EmberEventControl * control, uint32_t delayMs);
void deactivateEndpointTimerCallback(EmberEventControl * control);
void deactivateEndpointTimerCallback(chip::EndpointId endpoint);
void cancelEndpointTimerCallback(EmberEventControl * control);

#ifdef EMBER_AF_PLUGIN_COLOR_CONTROL_SERVER_HSV
ColorHueTransitionState * getColorHueTransitionState(chip::EndpointId endpoint);
Expand Down
8 changes: 7 additions & 1 deletion src/app/clusters/door-lock-server/door-lock-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3425,7 +3425,7 @@ void DoorLockServer::ScheduleAutoRelock(chip::EndpointId endpointId, uint32_t ti

if (err != CHIP_NO_ERROR)
{
ChipLogError(Zcl, "Color Control Server failed to schedule event: %" CHIP_ERROR_FORMAT, err.Format());
ChipLogError(Zcl, "Failed to schedule autorelock: timeout=%" PRIu32 ", status=0x%x", timeoutSec, err.AsInteger());
}
}

Expand Down Expand Up @@ -3784,6 +3784,12 @@ void MatterDoorLockPluginServerInitCallback()

void MatterDoorLockClusterServerAttributeChangedCallback(const app::ConcreteAttributePath & attributePath) {}

void MatterDoorLockClusterServerShutdownCallback(EndpointId endpoint)
{
DeviceLayer::SystemLayer().CancelTimer(DoorLockOnAutoRelockCallback,
reinterpret_cast<void *>(static_cast<uintptr_t>(endpointId)));
}

// =============================================================================
// Timer callbacks
// =============================================================================
Expand Down
15 changes: 10 additions & 5 deletions src/app/clusters/level-control/level-control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ static void scheduleTimerCallbackMs(EndpointId endpoint, uint32_t delayMs)
}
}

static void deactivateEndpointTimerCallback(EndpointId endpoint)
static void cancelEndpointTimerCallback(EndpointId endpoint)
{
DeviceLayer::SystemLayer().CancelTimer(timerCallback, reinterpret_cast<void *>(static_cast<uintptr_t>(endpoint)));
}
Expand Down Expand Up @@ -651,7 +651,7 @@ static EmberAfStatus moveToLevelHandler(EndpointId endpoint, CommandId commandId
}

// Cancel any currently active command before fiddling with the state.
deactivateEndpointTimerCallback(endpoint);
cancelEndpointTimerCallback(endpoint);

status = Attributes::CurrentLevel::Get(endpoint, currentLevel);
if (status != EMBER_ZCL_STATUS_SUCCESS)
Expand Down Expand Up @@ -800,7 +800,7 @@ static void moveHandler(EndpointId endpoint, CommandId commandId, uint8_t moveMo
}

// Cancel any currently active command before fiddling with the state.
deactivateEndpointTimerCallback(endpoint);
cancelEndpointTimerCallback(endpoint);

status = Attributes::CurrentLevel::Get(endpoint, currentLevel);
if (status != EMBER_ZCL_STATUS_SUCCESS)
Expand Down Expand Up @@ -928,7 +928,7 @@ static void stepHandler(EndpointId endpoint, CommandId commandId, uint8_t stepMo
}

// Cancel any currently active command before fiddling with the state.
deactivateEndpointTimerCallback(endpoint);
cancelEndpointTimerCallback(endpoint);

status = Attributes::CurrentLevel::Get(endpoint, currentLevel);
if (status != EMBER_ZCL_STATUS_SUCCESS)
Expand Down Expand Up @@ -1061,7 +1061,7 @@ static void stopHandler(EndpointId endpoint, CommandId commandId, chip::Optional
}

// Cancel any currently active command.
deactivateEndpointTimerCallback(endpoint);
cancelEndpointTimerCallback(endpoint);
writeRemainingTime(endpoint, 0);
status = EMBER_ZCL_STATUS_SUCCESS;

Expand Down Expand Up @@ -1292,6 +1292,11 @@ void emberAfLevelControlClusterServerInitCallback(EndpointId endpoint)
emberAfPluginLevelControlClusterServerPostInitCallback(endpoint);
}

void MatterLevelControlClusterServerShutdownCallback(EndpointId endpoint)
{
DeviceLayer::SystemLayer().CancelTimer(timerCallback, reinterpret_cast<void *>(static_cast<uintptr_t>(endpoint)));
}

#ifndef IGNORE_LEVEL_CONTROL_CLUSTER_START_UP_CURRENT_LEVEL
static bool areStartUpLevelControlServerAttributesNonVolatile(EndpointId endpoint)
{
Expand Down
Loading

0 comments on commit 2d53fb8

Please sign in to comment.