Skip to content

Commit

Permalink
Merge branch 'master' into telink_image_update
Browse files Browse the repository at this point in the history
  • Loading branch information
s07641069 authored May 3, 2024
2 parents 32f5c03 + 881676d commit 99af5b2
Show file tree
Hide file tree
Showing 11 changed files with 385 additions and 445 deletions.
112 changes: 23 additions & 89 deletions src/darwin/Framework/CHIP/MTRBaseDevice.mm
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,18 @@
NSString * const MTREventIsHistoricalKey = @"eventIsHistorical";

class MTRDataValueDictionaryCallbackBridge;
class MTRDataValueDictionaryDecodableType;
template <typename DecodableValueType>
class BufferedReadClientCallback;

@interface MTRReadClientContainer : NSObject
@property (nonatomic, readwrite) app::ReadClient * readClientPtr;
@property (nonatomic, readwrite) BufferedReadClientCallback<MTRDataValueDictionaryDecodableType> * callback;
@property (nonatomic, readwrite) app::AttributePathParams * pathParams;
@property (nonatomic, readwrite) app::EventPathParams * eventPathParams;
@property (nonatomic, readwrite) uint64_t deviceID;

- (void)cleanup;
- (void)onDone;
@end

Expand Down Expand Up @@ -157,22 +163,7 @@ static void PurgeReadClientContainers(
[controller
asyncDispatchToMatterQueue:^() {
for (MTRReadClientContainer * container in listToDelete) {
if (container.readClientPtr) {
Platform::Delete(container.readClientPtr);
container.readClientPtr = nullptr;
}
if (container.pathParams) {
static_assert(std::is_trivially_destructible<AttributePathParams>::value,
"AttributePathParams destructors won't get run");
Platform::MemoryFree(container.pathParams);
container.pathParams = nullptr;
}
if (container.eventPathParams) {
static_assert(
std::is_trivially_destructible<EventPathParams>::value, "EventPathParams destructors won't get run");
Platform::MemoryFree(container.eventPathParams);
container.eventPathParams = nullptr;
}
[container cleanup];
}
[listToDelete removeAllObjects];
if (completion) {
Expand Down Expand Up @@ -204,47 +195,13 @@ static void PurgeCompletedReadClientContainers(uint64_t deviceId)
[readClientContainersLock unlock];
}

#ifdef DEBUG
// This function is for unit testing only. This function closes all read clients.
static void CauseReadClientFailure(
MTRDeviceController * controller, uint64_t deviceId, dispatch_queue_t queue, void (^_Nullable completion)(void))
{
InitializeReadClientContainers();

NSMutableArray<MTRReadClientContainer *> * listToFail;
NSNumber * key = [NSNumber numberWithUnsignedLongLong:deviceId];
[readClientContainersLock lock];
listToFail = readClientContainers[key];
[readClientContainers removeObjectForKey:key];
[readClientContainersLock unlock];

[controller
asyncDispatchToMatterQueue:^() {
for (MTRReadClientContainer * container in listToFail) {
// Send auto resubscribe request again by read clients, which must fail.
chip::app::ReadPrepareParams readParams;
if (container.readClientPtr) {
container.readClientPtr->SendAutoResubscribeRequest(std::move(readParams));
}
}
if (completion) {
dispatch_async(queue, completion);
}
}
errorHandler:^(NSError * error) {
// Can't fail things. Just put them back.
ReinstateReadClientList(listToFail, key, queue, completion);
}];
}
#endif

static bool CheckMemberOfType(NSDictionary<NSString *, id> * responseValue, NSString * memberName, Class expectedClass,
NSString * errorMessage, NSError * __autoreleasing * error);
static void LogStringAndReturnError(NSString * errorStr, CHIP_ERROR errorCode, NSError * __autoreleasing * error);
static void LogStringAndReturnError(NSString * errorStr, MTRErrorCode errorCode, NSError * __autoreleasing * error);

@implementation MTRReadClientContainer
- (void)onDone
- (void)cleanup
{
if (_readClientPtr) {
Platform::Delete(_readClientPtr);
Expand All @@ -260,26 +217,19 @@ - (void)onDone
Platform::MemoryFree(_eventPathParams);
_eventPathParams = nullptr;
}
PurgeCompletedReadClientContainers(_deviceID);
if (_callback) {
Platform::Delete(_callback);
_callback = nullptr;
}
}

- (void)dealloc
- (void)onDone
{
if (_readClientPtr) {
Platform::Delete(_readClientPtr);
_readClientPtr = nullptr;
}
if (_pathParams) {
static_assert(std::is_trivially_destructible<AttributePathParams>::value, "AttributePathParams destructors won't get run");
Platform::MemoryFree(_pathParams);
_pathParams = nullptr;
}
if (_eventPathParams) {
static_assert(std::is_trivially_destructible<EventPathParams>::value, "EventPathParams destructors won't get run");
Platform::MemoryFree(_eventPathParams);
_eventPathParams = nullptr;
}
[self cleanup];

PurgeCompletedReadClientContainers(_deviceID);
}

@end

@implementation MTRBaseDevice
Expand Down Expand Up @@ -1730,6 +1680,7 @@ - (void)subscribeToAttributePaths:(NSArray<MTRAttributeRequestPath *> * _Nullabl
dispatch_async(queue, ^{
reportHandler(nil, [MTRError errorForCHIPErrorCode:CHIP_ERROR_NO_MEMORY]);
});
[container cleanup];
return;
}
for (MTRAttributeRequestPath * attribute in attributes) {
Expand All @@ -1744,6 +1695,7 @@ - (void)subscribeToAttributePaths:(NSArray<MTRAttributeRequestPath *> * _Nullabl
dispatch_async(queue, ^{
reportHandler(nil, [MTRError errorForCHIPErrorCode:CHIP_ERROR_NO_MEMORY]);
});
[container cleanup];
return;
}
for (MTREventRequestPath * event in events) {
Expand All @@ -1763,9 +1715,6 @@ - (void)subscribeToAttributePaths:(NSArray<MTRAttributeRequestPath *> * _Nullabl

auto onDone = [container](BufferedReadClientCallback<MTRDataValueDictionaryDecodableType> * callback) {
[container onDone];
// Make sure we delete callback last, because doing that actually destroys our
// lambda, so we can't access captured values after that.
chip::Platform::Delete(callback);
};

auto callback = chip::Platform::MakeUnique<BufferedReadClientCallback<MTRDataValueDictionaryDecodableType>>(
Expand All @@ -1775,6 +1724,9 @@ - (void)subscribeToAttributePaths:(NSArray<MTRAttributeRequestPath *> * _Nullabl
auto readClient = Platform::New<app::ReadClient>(
engine, exchangeManager, callback->GetBufferedCallback(), chip::app::ReadClient::InteractionType::Subscribe);

container.readClientPtr = readClient;
container.callback = callback.release();

if (!params.resubscribeAutomatically) {
err = readClient->SendRequest(readParams);
} else {
Expand All @@ -1785,23 +1737,12 @@ - (void)subscribeToAttributePaths:(NSArray<MTRAttributeRequestPath *> * _Nullabl
dispatch_async(queue, ^{
reportHandler(nil, [MTRError errorForCHIPErrorCode:err]);
});
Platform::Delete(readClient);
if (container.pathParams != nullptr) {
Platform::MemoryFree(container.pathParams);
}

if (container.eventPathParams != nullptr) {
Platform::MemoryFree(container.eventPathParams);
}
container.pathParams = nullptr;
container.eventPathParams = nullptr;
[container cleanup];
return;
}

// Read clients will be purged when deregistered.
container.readClientPtr = readClient;
AddReadClientContainer(container.deviceID, container);
callback.release();
}];
}

Expand Down Expand Up @@ -2024,13 +1965,6 @@ - (void)openCommissioningWindowWithDiscriminator:(NSNumber *)discriminator
}

#ifdef DEBUG
// This method is for unit testing only
- (void)failSubscribers:(dispatch_queue_t)queue completion:(void (^)(void))completion
{
MTR_LOG_DEBUG("Causing failure in subscribers on purpose");
CauseReadClientFailure(self.deviceController, self.nodeID, queue, completion);
}

// The following method is for unit testing purpose only
+ (id)CHIPEncodeAndDecodeNSObject:(id)object
{
Expand Down
121 changes: 119 additions & 2 deletions src/darwin/Framework/CHIP/templates/availability.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7458,7 +7458,6 @@
provisional:
clusters:
## Not ready at cutoff
- AirQuality
# Replaceable Monitoring clusters
- HEPAFilterMonitoring
- ActivatedCarbonFilterMonitoring
Expand All @@ -7475,7 +7474,6 @@
- TotalVolatileOrganicCompoundsConcentrationMeasurement
- RefrigeratorAlarm
- TemperatureControl
- SmokeCOAlarm
## Not ready to be public API yet.
- ICDManagement
- LaundryWasherMode
Expand Down Expand Up @@ -8528,35 +8526,154 @@
- release: "Future"
versions: "future"
introduced:
clusters:
- AirQuality
- SmokeCOAlarm
attributes:
AirQuality:
- AirQuality
- GeneratedCommandList
- AcceptedCommandList
- AttributeList
- FeatureMap
- ClusterRevision
FanControl:
- AirflowDirection
SmokeCOAlarm:
- ExpressedState
- SmokeState
- COState
- BatteryAlert
- DeviceMuted
- TestInProgress
- HardwareFaultAlert
- EndOfServiceAlert
- InterconnectSmokeAlarm
- InterconnectCOAlarm
- ContaminationState
- SmokeSensitivityLevel
- ExpiryDate
- GeneratedCommandList
- AcceptedCommandList
- AttributeList
- FeatureMap
- ClusterRevision
commands:
FanControl:
- Step
SmokeCOAlarm:
- SelfTestRequest
command fields:
FanControl:
Step:
- direction
- wrap
- lowestOff
events:
SmokeCOAlarm:
- SmokeAlarm
- COAlarm
- LowBattery
- HardwareFault
- EndOfService
- SelfTestComplete
- AlarmMuted
- MuteEnded
- InterconnectSmokeAlarm
- InterconnectCOAlarm
- AllClear
event fields:
SmokeCOAlarm:
SmokeAlarm:
- alarmSeverityLevel
COAlarm:
- alarmSeverityLevel
LowBattery:
- alarmSeverityLevel
InterconnectSmokeAlarm:
- alarmSeverityLevel
InterconnectCOAlarm:
- alarmSeverityLevel
enums:
AirQuality:
- AirQualityEnum
FanControl:
- StepDirectionEnum
- AirflowDirectionEnum
SmokeCOAlarm:
- AlarmStateEnum
- SensitivityEnum
- ExpressedStateEnum
- MuteStateEnum
- EndOfServiceEnum
- ContaminationStateEnum
enum values:
AirQuality:
AirQualityEnum:
- Unknown
- Good
- Fair
- Moderate
- Poor
- VeryPoor
- ExtremelyPoor
FanControl:
StepDirectionEnum:
- Increase
- Decrease
AirflowDirectionEnum:
- Forward
- Reverse
SmokeCOAlarm:
AlarmStateEnum:
- Normal
- Warning
- Critical
SensitivityEnum:
- High
- Standard
- Low
ExpressedStateEnum:
- Normal
- SmokeAlarm
- COAlarm
- BatteryAlert
- Testing
- HardwareFault
- EndOfService
- InterconnectSmoke
- InterconnectCO
MuteStateEnum:
- NotMuted
- Muted
EndOfServiceEnum:
- Normal
- Expired
ContaminationStateEnum:
- Normal
- Low
- Warning
- Critical
bitmaps:
AirQuality:
- Feature
SmokeCOAlarm:
- Feature
bitmap values:
AirQuality:
Feature:
- Fair
- Moderate
- VeryPoor
- ExtremelyPoor
FanControl:
Feature:
- Step
- AirflowDirection
SmokeCOAlarm:
Feature:
- SmokeAlarm
- COAlarm
provisional:
clusters:
# Targeting Spring 2024 Matter release
Expand Down
Loading

0 comments on commit 99af5b2

Please sign in to comment.