Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose new requested APIs #37162

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/darwin/Framework/CHIP/MTRDeviceController.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ typedef void (^MTRDeviceConnectionCallback)(MTRBaseDevice * _Nullable device, NS
@class MTRCommissioningParameters;
@class MTRCommissionableBrowserResult;
@class MTRSetupPayload;
@class MTRDevice;
@protocol MTRDevicePairingDelegate;
@protocol MTRDeviceControllerDelegate;

Expand Down Expand Up @@ -269,6 +270,11 @@ MTR_AVAILABLE(ios(16.1), macos(13.0), watchos(9.1), tvos(16.1))
*/
- (void)removeServerEndpoint:(MTRServerEndpoint *)endpoint MTR_AVAILABLE(ios(17.6), macos(14.6), watchos(10.6), tvos(17.6));

/**
* Delete a device from a device controller, also purge storage for the device.
*/
- (void)deleteDevice:(MTRDevice *)device MTR_NEWLY_AVAILABLE;

/**
* Compute a PASE verifier for the desired setup passcode.
*
Expand Down
5 changes: 5 additions & 0 deletions src/darwin/Framework/CHIP/MTRDeviceController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,11 @@ - (MTRDevice *)deviceForNodeID:(NSNumber *)nodeID
return [self _deviceForNodeID:nodeID createIfNeeded:YES];
}

- (void)deleteDevice:(MTRDevice *)device
{
[self removeDevice:device];
}

- (void)removeDevice:(MTRDevice *)device
{
std::lock_guard lock(*self.deviceMapLock);
Expand Down
6 changes: 6 additions & 0 deletions src/darwin/Framework/CHIP/MTRDeviceController_Concrete.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1314,6 +1314,12 @@ - (void)removeServerEndpointOnMatterQueue:(MTRServerEndpoint *)endpoint
[_factory removeServerEndpoint:endpoint];
}

- (void)deleteDevice:(MTRDevice *)device
{
// TODO NEED TO CLEAN UP DB HERE
MTR_LOG("%@: Delete device: %@", self, device);
}

- (BOOL)checkForInitError:(BOOL)condition logMsg:(NSString *)logMsg
{
if (condition) {
Expand Down
12 changes: 12 additions & 0 deletions src/darwin/Framework/CHIP/MTRDeviceController_XPC.mm
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ @implementation MTRDeviceController_XPC
MTR_DEVICECONTROLLER_SIMPLE_REMOTE_XPC_COMMAND(updateControllerConfiguration
: (NSDictionary *) controllerState, updateControllerConfiguration
: (NSDictionary *) controllerState)
MTR_DEVICECONTROLLER_SIMPLE_REMOTE_XPC_COMMAND(deleteNodeID
: (NSNumber *) nodeID, deleteNodeID
: (NSNumber *) nodeID)

- (void)_updateRegistrationInfo
{
Expand Down Expand Up @@ -95,6 +98,15 @@ - (void)removeDevice:(MTRDevice *)device
[self _updateRegistrationInfo];
}

- (void)deleteDevice:(MTRDevice *)device
{
MTR_LOG("%@: Delete device: %@", self, device);
if (device.nodeID) {
[self deleteNodeID:device.nodeID];
}
[super deleteDevice:device];
}

#pragma mark - XPC
@synthesize controllerNodeID = _controllerNodeID;
@synthesize compressedFabricID = _compressedFabricID;
Expand Down
2 changes: 2 additions & 0 deletions src/darwin/Framework/CHIP/MTRSetupPayload.h
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@ MTR_AVAILABLE(ios(16.1), macos(13.0), watchos(9.1), tvos(16.1))

MTR_AVAILABLE(ios(17.6), macos(14.6), watchos(10.6), tvos(17.6))
@interface MTRSetupPayload () <NSCopying>

+ (BOOL)isValidSetupPIN:(NSUInteger)setupPIN MTR_NEWLY_AVAILABLE;
@end

@interface MTROptionalQRCodeInfo (Deprecated)
Expand Down
5 changes: 5 additions & 0 deletions src/darwin/Framework/CHIP/MTRSetupPayload.mm
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,11 @@ @implementation MTRSetupPayload {
NSNumber * _Nullable _shadowDiscriminator;
}

+ (BOOL)isValidSetupPIN:(NSUInteger)setupPIN
{
return [[MTRSetupPayload alloc] initWithPayload:[NSString stringWithFormat:@"%lu", static_cast<unsigned long>(setupPIN)]] != nil;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't do the right thing; what's provided is a passcode, not the whole numeric payload.

}

+ (void)initialize
{
// Some aspects of working with chip::SetupPayload use Platform memory primitives.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ MTR_AVAILABLE(ios(18.2), macos(15.2), watchos(11.2), tvos(18.2))

// - (oneway void)deviceController:(NSUUID *)controller addServerEndpoint:(MTRServerEndpoint *)endpoint withReply:(void (^)(BOOL success))reply;
// - (oneway void)deviceController:(NSUUID *)controller removeServerEndpoint:(MTRServerEndpoint *)endpoint;
- (oneway void)deviceController:(NSUUID *)controller deleteNodeID:(NSNumber *)nodeID;

- (oneway void)deviceController:(NSUUID *)controller registerNodeID:(NSNumber *)nodeID;
- (oneway void)deviceController:(NSUUID *)controller unregisterNodeID:(NSNumber *)nodeID;
Expand Down
Loading