Skip to content

Commit

Permalink
Merge branch 'master' into thread-br-mgmt/server
Browse files Browse the repository at this point in the history
  • Loading branch information
wqx6 authored Jul 18, 2024
2 parents 3bcd93e + e62582e commit 93b7744
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 53 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@
"random": "cpp",
"thread": "cpp",
"variant": "cpp",
"any": "cpp"
"any": "cpp",
"future": "cpp"
},
// Configure paths or glob patterns to exclude from file watching.
"files.watcherExclude": {
Expand Down
8 changes: 4 additions & 4 deletions src/controller/python/chip/clusters/Attribute.py
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,8 @@ def handleEventData(self, header: EventHeader, path: EventPath, data: bytes, sta
LOGGER.exception(ex)

def handleError(self, chipError: PyChipError):
if self._subscription_handler:
self._subscription_handler.OnErrorCb(chipError.code, self._subscription_handler)
self._resultError = chipError

def _handleSubscriptionEstablished(self, subscriptionId):
Expand All @@ -728,6 +730,7 @@ def _handleSubscriptionEstablished(self, subscriptionId):
self, subscriptionId, self._devCtrl)
self._future.set_result(self._subscription_handler)
else:
self._subscription_handler._subscriptionId = subscriptionId
if self._subscription_handler._onResubscriptionSucceededCb is not None:
if (self._subscription_handler._onResubscriptionSucceededCb_isAsync):
self._event_loop.create_task(
Expand Down Expand Up @@ -779,10 +782,7 @@ def _handleDone(self):
#
if not self._future.done():
if self._resultError is not None:
if self._subscription_handler:
self._subscription_handler.OnErrorCb(self._resultError.code, self._subscription_handler)
else:
self._future.set_exception(self._resultError.to_exception())
self._future.set_exception(self._resultError.to_exception())
else:
self._future.set_result(AsyncReadTransaction.ReadResponse(
attributes=self._cache.attributeCache, events=self._events, tlvAttributes=self._cache.attributeTLVCache))
Expand Down
9 changes: 6 additions & 3 deletions src/controller/python/chip/clusters/attribute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,18 +145,20 @@ class ReadClientCallback : public ReadClient::Callback

void OnSubscriptionEstablished(SubscriptionId aSubscriptionId) override
{
// Only enable auto resubscribe if the subscription is established successfully.
mAutoResubscribeNeeded = mAutoResubscribe;
gOnSubscriptionEstablishedCallback(mAppContext, aSubscriptionId);
}

CHIP_ERROR OnResubscriptionNeeded(ReadClient * apReadClient, CHIP_ERROR aTerminationCause) override
{
if (mAutoResubscribe)
if (mAutoResubscribeNeeded)
{
ReturnErrorOnFailure(ReadClient::Callback::OnResubscriptionNeeded(apReadClient, aTerminationCause));
}
gOnResubscriptionAttemptedCallback(mAppContext, ToPyChipError(aTerminationCause),
apReadClient->ComputeTimeTillNextSubscription());
if (mAutoResubscribe)
if (mAutoResubscribeNeeded)
{
return CHIP_NO_ERROR;
}
Expand Down Expand Up @@ -242,7 +244,8 @@ class ReadClientCallback : public ReadClient::Callback
PyObject * mAppContext;

std::unique_ptr<ReadClient> mReadClient;
bool mAutoResubscribe = true;
bool mAutoResubscribe = true;
bool mAutoResubscribeNeeded = false;
};

extern "C" {
Expand Down
65 changes: 34 additions & 31 deletions src/darwin/Framework/CHIP/MTRBaseDevice.mm
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#import <Matter/MTRClusterConstants.h>
#import <Matter/MTRDefines.h>
#import <Matter/Matter.h>

#import "MTRAttributeTLVValueDecoder_Internal.h"
#import "MTRBaseDevice_Internal.h"
Expand All @@ -31,31 +30,32 @@
#import "MTRLogging_Internal.h"
#import "MTRMetricKeys.h"
#import "MTRSetupPayload_Internal.h"
#import "MTRUtilities.h"
#import "NSDataSpanConversion.h"
#import "NSStringSpanConversion.h"
#import "zap-generated/MTRCommandPayloads_Internal.h"

#include "app/ConcreteAttributePath.h"
#include "app/ConcreteCommandPath.h"
#include "app/ConcreteEventPath.h"
#include "app/StatusResponse.h"
#include "lib/core/CHIPError.h"
#include "lib/core/DataModelTypes.h"

#include <app/AttributePathParams.h>
#include <app/BufferedReadCallback.h>
#include <app/ClusterStateCache.h>
#include <app/InteractionModelEngine.h>
#include <app/ReadClient.h>
#include <app/data-model/List.h>
#include <controller/CommissioningWindowOpener.h>
#include <controller/ReadInteraction.h>
#include <controller/WriteInteraction.h>
#include <crypto/CHIPCryptoPAL.h>
#include <setup_payload/SetupPayload.h>
#include <system/SystemClock.h>

#include <memory>
#import "app/ConcreteAttributePath.h"
#import "app/ConcreteCommandPath.h"
#import "app/ConcreteEventPath.h"
#import "app/StatusResponse.h"
#import "lib/core/CHIPError.h"
#import "lib/core/DataModelTypes.h"

#import <app/AttributePathParams.h>
#import <app/BufferedReadCallback.h>
#import <app/ClusterStateCache.h>
#import <app/InteractionModelEngine.h>
#import <app/ReadClient.h>
#import <app/data-model/List.h>
#import <controller/CommissioningWindowOpener.h>
#import <controller/ReadInteraction.h>
#import <controller/WriteInteraction.h>
#import <crypto/CHIPCryptoPAL.h>
#import <setup_payload/SetupPayload.h>
#import <system/SystemClock.h>

#import <memory>

using namespace chip;
using namespace chip::app;
Expand Down Expand Up @@ -2290,8 +2290,9 @@ + (MTRAttributeRequestPath *)requestPathWithEndpointID:(NSNumber * _Nullable)end

- (BOOL)isEqualToAttributeRequestPath:(MTRAttributeRequestPath *)path
{
return [_endpoint isEqualToNumber:path.endpoint] && [_cluster isEqualToNumber:path.cluster] &&
[_attribute isEqualToNumber:path.attribute];
return MTREqualObjects(_endpoint, path.endpoint)
&& MTREqualObjects(_cluster, path.cluster)
&& MTREqualObjects(_attribute, path.attribute);
}

- (BOOL)isEqual:(id)object
Expand Down Expand Up @@ -2362,8 +2363,9 @@ + (MTREventRequestPath *)requestPathWithEndpointID:(NSNumber * _Nullable)endpoin

- (BOOL)isEqualToEventRequestPath:(MTREventRequestPath *)path
{
return
[_endpoint isEqualToNumber:path.endpoint] && [_cluster isEqualToNumber:path.cluster] && [_event isEqualToNumber:path.event];
return MTREqualObjects(_endpoint, path.endpoint)
&& MTREqualObjects(_cluster, path.cluster)
&& MTREqualObjects(_event, path.event);
}

- (BOOL)isEqual:(id)object
Expand Down Expand Up @@ -2432,7 +2434,8 @@ ConcreteClusterPath path(static_cast<chip::EndpointId>([endpointID unsignedShort

- (BOOL)isEqualToClusterPath:(MTRClusterPath *)clusterPath
{
return [_endpoint isEqualToNumber:clusterPath.endpoint] && [_cluster isEqualToNumber:clusterPath.cluster];
return MTREqualObjects(_endpoint, clusterPath.endpoint)
&& MTREqualObjects(_cluster, clusterPath.cluster);
}

- (BOOL)isEqual:(id)object
Expand Down Expand Up @@ -2520,7 +2523,7 @@ ConcreteDataAttributePath path(static_cast<chip::EndpointId>([endpointID unsigne

- (BOOL)isEqualToAttributePath:(MTRAttributePath *)attributePath
{
return [self isEqualToClusterPath:attributePath] && [_attribute isEqualToNumber:attributePath.attribute];
return [self isEqualToClusterPath:attributePath] && MTREqualObjects(_attribute, attributePath.attribute);
}

- (BOOL)isEqual:(id)object
Expand Down Expand Up @@ -2613,7 +2616,7 @@ ConcreteEventPath path(static_cast<chip::EndpointId>([endpointID unsignedShortVa

- (BOOL)isEqualToEventPath:(MTREventPath *)eventPath
{
return [self isEqualToClusterPath:eventPath] && [_event isEqualToNumber:eventPath.event];
return [self isEqualToClusterPath:eventPath] && MTREqualObjects(_event, eventPath.event);
}

- (BOOL)isEqual:(id)object
Expand Down Expand Up @@ -2703,7 +2706,7 @@ ConcreteCommandPath path(static_cast<chip::EndpointId>([endpointID unsignedShort

- (BOOL)isEqualToCommandPath:(MTRCommandPath *)commandPath
{
return [self isEqualToClusterPath:commandPath] && [_command isEqualToNumber:commandPath.command];
return [self isEqualToClusterPath:commandPath] && MTREqualObjects(_command, commandPath.command);
}

- (BOOL)isEqual:(id)object
Expand Down
26 changes: 14 additions & 12 deletions src/darwin/Framework/CHIP/MTRDevice.mm
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

#import <Matter/MTRDefines.h>
#import <Matter/Matter.h>
#import <os/lock.h>

#import "MTRAsyncWorkQueue.h"
Expand All @@ -39,19 +39,20 @@
#import "MTRMetricsCollector.h"
#import "MTRTimeUtils.h"
#import "MTRUnfairLock.h"
#import "MTRUtilities.h"
#import "zap-generated/MTRCommandPayloads_Internal.h"

#include "lib/core/CHIPError.h"
#include "lib/core/DataModelTypes.h"
#include <app/ConcreteAttributePath.h>
#include <lib/support/FibonacciUtils.h>
#import "lib/core/CHIPError.h"
#import "lib/core/DataModelTypes.h"
#import <app/ConcreteAttributePath.h>
#import <lib/support/FibonacciUtils.h>

#include <app/AttributePathParams.h>
#include <app/BufferedReadCallback.h>
#include <app/ClusterStateCache.h>
#include <app/InteractionModelEngine.h>
#include <platform/LockTracker.h>
#include <platform/PlatformManager.h>
#import <app/AttributePathParams.h>
#import <app/BufferedReadCallback.h>
#import <app/ClusterStateCache.h>
#import <app/InteractionModelEngine.h>
#import <platform/LockTracker.h>
#import <platform/PlatformManager.h>

typedef void (^MTRDeviceAttributeReportHandler)(NSArray * _Nonnull);

Expand Down Expand Up @@ -336,7 +337,8 @@ - (id)copyWithZone:(NSZone *)zone

- (BOOL)isEqualToClusterData:(MTRDeviceClusterData *)otherClusterData
{
return [_dataVersion isEqual:otherClusterData.dataVersion] && [_attributes isEqual:otherClusterData.attributes];
return MTREqualObjects(_dataVersion, otherClusterData.dataVersion)
&& MTREqualObjects(_attributes, otherClusterData.attributes);
}

- (BOOL)isEqual:(id)object
Expand Down
13 changes: 12 additions & 1 deletion src/darwin/Framework/CHIP/MTRUtilities.mm
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,16 @@

BOOL MTREqualObjects(id<NSObject> _Nullable a, id<NSObject> _Nullable b)
{
return (a == nil) ? (b == nil) : [a isEqual:b];
// Check if A is nil, and return based on B being nil (or not)
if (a == nil) {
return b == nil;
}

// If B is nil at this point, we're not equal
if (b == nil) {
return NO;
}

// Otherwise work on equality, given that we're both non nil
return [a isEqual:b];
}
2 changes: 1 addition & 1 deletion src/darwin/Framework/Matter.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1626,6 +1626,7 @@
B2E0D7B2245B0B5C003C5B48 /* MTRManualSetupPayloadParser.h in Headers */,
3CF134A7289D8ADA0017A19E /* MTRCSRInfo.h in Headers */,
88E07D612B9A89A4005FD53E /* MTRMetricKeys.h in Headers */,
3D4733B32BE2D1DA003DC19B /* MTRUtilities.h in Headers */,
B2E0D7B1245B0B5C003C5B48 /* Matter.h in Headers */,
7596A84428762729004DAE0E /* MTRDevice.h in Headers */,
B2E0D7B8245B0B5C003C5B48 /* MTRSetupPayload.h in Headers */,
Expand Down Expand Up @@ -1671,7 +1672,6 @@
514C7A022B64223400DD6D7B /* MTRServerEndpoint_Internal.h in Headers */,
511913FC28C100EF009235E9 /* MTRBaseSubscriptionCallback.h in Headers */,
51565CB12A7AD77600469F18 /* MTRDeviceControllerDataStore.h in Headers */,
3D4733B32BE2D1DA003DC19B /* MTRUtilities.h in Headers */,
3D843713294977000070D20A /* NSDataSpanConversion.h in Headers */,
991DC08B247704DC00C13860 /* MTRLogging_Internal.h in Headers */,
51FE723F2ACDEF3E00437032 /* MTRCommandPayloadExtensions_Internal.h in Headers */,
Expand Down

0 comments on commit 93b7744

Please sign in to comment.