Skip to content

Commit

Permalink
Addressed comments by sharadb-amazon
Browse files Browse the repository at this point in the history
  • Loading branch information
pgregorr-amazon committed Jun 21, 2024
1 parent a04cbde commit fbd68cc
Show file tree
Hide file tree
Showing 15 changed files with 128 additions and 212 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ - (NSError *)verifyOrEstablishConnectionWithCallbacks:(MCConnectionCallbacks * _
if (identificationDeclarationOptions != nil) {
cppIdOptions = [identificationDeclarationOptions getCppIdentificationDeclarationOptions];
} else {
ChipLogProgress(AppServer, "MCCastingPlayer.verifyOrEstablishConnectionWithCallbacks()->setupCppIdOptions() helper. Client did not set the optional MCIdentificationDeclarationOptions using default options");
ChipLogProgress(AppServer, "MCCastingPlayer.setupCppIdOptions() Client did not set the optional MCIdentificationDeclarationOptions using default options");
}
return cppIdOptions;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,42 @@ typedef NS_ENUM(NSInteger, CdError) {
kUnexpectedCommissionerPasscodeReady = 18
};

/** Feature: All - Indicates errors incurred during commissioning. */
@property (nonatomic, readonly) CdError errorCode;
/**
* Feature: Coordinate PIN Dialogs - When NoPasscode field set to true, and the Commissioner
* determines that a Passcode code will be needed for commissioning.
*/
@property (nonatomic, readonly) BOOL needsPasscode;
/**
* Feature: Target Content Application - No apps with AccountLogin cluster implementation were
* found for the last IdentificationDeclaration request. Only apps which provide access to the
* vendor id of the Commissionee will be considered.
*/
@property (nonatomic, readonly) BOOL noAppsFound;
/**
* Feature: Coordinate PIN Dialogs - A Passcode input dialog is now displayed for the user on the
* Commissioner.
*/
@property (nonatomic, readonly) BOOL passcodeDialogDisplayed;
/**
* Feature: Commissioner-Generated Passcode - A Passcode is now displayed for the user by the
* CastingPlayer/Commissioner.
*/
@property (nonatomic, readonly) BOOL commissionerPasscode;
/**
* Feature: Commissioner-Generated Passcode - The user experience conveying a Passcode to the user
* also displays a QR code.
*/
@property (nonatomic, readonly) BOOL qRCodeDisplayed;

- (instancetype)initWithOptions:(NSInteger)errorCode
needsPasscode:(BOOL)needsPasscode
noAppsFound:(BOOL)noAppsFound
passcodeDialogDisplayed:(BOOL)passcodeDialogDisplayed
commissionerPasscode:(BOOL)commissionerPasscode
qRCodeDisplayed:(BOOL)qRCodeDisplayed;

- (CdError)getErrorCode;
- (BOOL)getNeedsPasscode;
- (BOOL)getNoAppsFound;
- (BOOL)getPasscodeDialogDisplayed;
- (BOOL)getCommissionerPasscode;
- (BOOL)getQRCodeDisplayed;

- (NSString *)description;
- (void)logDetail;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,35 +20,6 @@

@interface MCCommissionerDeclaration ()

/** Feature: All - Indicates errors incurred during commissioning. */
@property (nonatomic) CdError errorCode;
/**
* Feature: Coordinate PIN Dialogs - When NoPasscode field set to true, and the Commissioner
* determines that a Passcode code will be needed for commissioning.
*/
@property (nonatomic) BOOL needsPasscode;
/**
* Feature: Target Content Application - No apps with AccountLogin cluster implementation were
* found for the last IdentificationDeclaration request. Only apps which provide access to the
* vendor id of the Commissionee will be considered.
*/
@property (nonatomic) BOOL noAppsFound;
/**
* Feature: Coordinate PIN Dialogs - A Passcode input dialog is now displayed for the user on the
* Commissioner.
*/
@property (nonatomic) BOOL passcodeDialogDisplayed;
/**
* Feature: Commissioner-Generated Passcode - A Passcode is now displayed for the user by the
* CastingPlayer/Commissioner.
*/
@property (nonatomic) BOOL commissionerPasscode;
/**
* Feature: Commissioner-Generated Passcode - The user experience conveying a Passcode to the user
* also displays a QR code.
*/
@property (nonatomic) BOOL qRCodeDisplayed;

@property (nonatomic, readwrite) matter::casting::memory::Strong<chip::Protocols::UserDirectedCommissioning::CommissionerDeclaration> cppCommissionerDeclaration;

@end
Expand Down Expand Up @@ -88,36 +59,6 @@ - (instancetype)initWithOptions:(NSInteger)errorCode
return self;
}

- (CdError)getErrorCode
{
return _errorCode;
}

- (BOOL)getNeedsPasscode
{
return _needsPasscode;
}

- (BOOL)getNoAppsFound
{
return _noAppsFound;
}

- (BOOL)getPasscodeDialogDisplayed
{
return _passcodeDialogDisplayed;
}

- (BOOL)getCommissionerPasscode
{
return _commissionerPasscode;
}

- (BOOL)getQRCodeDisplayed
{
return _qRCodeDisplayed;
}

- (NSString *)description
{
return [NSString stringWithFormat:@"MCCommissionerDeclaration::errorCode: %@\nMCCommissionerDeclaration::needsPasscode: %d\nMCCommissionerDeclaration::noAppsFound: %d\nMCCommissionerDeclaration::passcodeDialogDisplayed: %d\nMCCommissionerDeclaration::commissionerPasscode: %d\nMCCommissionerDeclaration::qRCodeDisplayed: %d",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,6 @@
*/
- (dispatch_queue_t _Nonnull)clientQueue;

/**
* @brief Updates the MCCommissionableData object stored inside MCAppParametersDataSource, which was used to
* initialize the MCCastingApp. This function needs to be implemented by the client in use cases where the
* MCCommissionableData needs to be updated post-initialization. For example, when the Commissioner-Generated
* Passcode feature is used.
*
* @param newCommissionableData The new MCCommissionableData object to be used for the next commissioning session.
*/
- (void)update:(MCCommissionableData * _Nonnull)newCommissionableData;

/**
* @brief Provide UniqueId used to generate the RotatingDeviceId advertised during commissioning by the MCCastingApp
* Must be at least 16 bytes (i.e. ConfigurationManager::kMinRotatingDeviceIDUniqueIDLength)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,49 @@
*/
@interface MCIdentificationDeclarationOptions : NSObject

/**
* Feature: Target Content Application - Flag to instruct the Commissioner not to display a
* Passcode input dialog, and instead send a CommissionerDeclaration message if a commissioning
* Passcode is needed.
*/
@property (nonatomic, readonly) BOOL noPasscode;
/**
* Feature: Coordinate Passcode Dialogs - Flag to instruct the Commissioner to send a
* CommissionerDeclaration message when the Passcode input dialog on the Commissioner has been
* shown to the user.
*/
@property (nonatomic, readonly) BOOL cdUponPasscodeDialog;
/**
* Feature: Commissioner-Generated Passcode - Flag to instruct the Commissioner to use the
* Commissioner-generated Passcode for commissioning.
*/
@property (nonatomic, readonly) BOOL commissionerPasscode;
/**
* Feature: Commissioner-Generated Passcode - Flag to indicate whether or not the Commissionee has
* obtained the Commissioner Passcode from the user and is therefore ready for commissioning.
*/
@property (nonatomic, readonly) BOOL commissionerPasscodeReady;
/**
* Feature: Coordinate Passcode Dialogs Flag - to indicate when the Commissionee user has decided
* to exit the commissioning process.
*/
@property (nonatomic, readonly) BOOL cancelPasscode;

- (instancetype)init;

- (instancetype)initWithCommissionerPasscodeOnly:(BOOL)commissionerPasscode;

// Getter methods
- (BOOL)getNoPasscode;
- (BOOL)getCdUponPasscodeDialog;
- (BOOL)getCommissionerPasscode;
- (BOOL)getCommissionerPasscodeReady;
- (BOOL)getCancelPasscode;

/**
* @brief Adds a TargetAppInfo to the IdentificationDeclarationOptions.java TargetAppInfos list,
* up to a maximum of CHIP_DEVICE_CONFIG_UDC_MAX_TARGET_APPS.
*/
- (BOOL)addTargetAppInfo:(MCTargetAppInfo *)targetAppInfo NS_SWIFT_NAME(addTargetAppInfo(_:));
/**
* Feature: Target Content Application - The set of content app Vendor IDs (and optionally,
* Product IDs) that can be used for authentication. Also, if TargetAppInfo is passed in,
* VerifyOrEstablishConnection() will force User Directed Commissioning, in case the desired
* TargetApp is not found in the on-device CastingStore.
*/
- (NSArray<MCTargetAppInfo *> *)getTargetAppInfoList;

- (NSString *)description;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,35 +21,6 @@

@interface MCIdentificationDeclarationOptions ()

// Private properties:

/**
* Feature: Target Content Application - Flag to instruct the Commissioner not to display a
* Passcode input dialog, and instead send a CommissionerDeclaration message if a commissioning
* Passcode is needed.
*/
@property (nonatomic) BOOL noPasscode;
/**
* Feature: Coordinate Passcode Dialogs - Flag to instruct the Commissioner to send a
* CommissionerDeclaration message when the Passcode input dialog on the Commissioner has been
* shown to the user.
*/
@property (nonatomic) BOOL cdUponPasscodeDialog;
/**
* Feature: Commissioner-Generated Passcode - Flag to instruct the Commissioner to use the
* Commissioner-generated Passcode for commissioning.
*/
@property (nonatomic) BOOL commissionerPasscode;
/**
* Feature: Commissioner-Generated Passcode - Flag to indicate whether or not the Commissionee has
* obtained the Commissioner Passcode from the user and is therefore ready for commissioning.
*/
@property (nonatomic) BOOL commissionerPasscodeReady;
/**
* Feature: Coordinate Passcode Dialogs Flag - to indicate when the Commissionee user has decided
* to exit the commissioning process.
*/
@property (nonatomic) BOOL cancelPasscode;
/**
* Feature: Target Content Application - The set of content app Vendor IDs (and optionally,
* Product IDs) that can be used for authentication. Also, if TargetAppInfo is passed in,
Expand Down Expand Up @@ -159,8 +130,8 @@ - (NSString *)description
NSArray<MCTargetAppInfo *> * targetAppInfos = [self getTargetAppInfoList];
for (MCTargetAppInfo * appInfo in targetAppInfos) {
chip::Protocols::UserDirectedCommissioning::TargetAppInfo targetAppInfo;
targetAppInfo.vendorId = appInfo.getVendorId;
targetAppInfo.productId = appInfo.getProductId;
targetAppInfo.vendorId = appInfo.vendorId;
targetAppInfo.productId = appInfo.productId;
CHIP_ERROR err = cppIdOptions.addTargetAppInfo(targetAppInfo);
if (err != CHIP_NO_ERROR) {
ChipLogError(AppServer, "MCIdentificationDeclarationOptions.getCppIdentificationDeclarationOptions() Failed to add TargetAppInfo: %@", appInfo.description);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,13 @@
*/
@interface MCTargetAppInfo : NSObject

/** Initialize with vendorId and productId set to 0 */
/** Target Target Content Application Vendor ID, 0 means unspecified */
@property (nonatomic, readonly) uint16_t vendorId;

/** Target Target Content Application Product ID, 0 means unspecified */
@property (nonatomic, readonly) uint16_t productId;

/** Initialize with vendorId and productId set to 0 */
- (instancetype)init;

/** Initialize with vendorId, productId defaults to 0 */
Expand All @@ -36,18 +41,6 @@
/** Initialize with vendorId and productId */
- (instancetype _Nonnull)initWithVendorId:(uint16_t)vendorId productId:(uint16_t)productId NS_DESIGNATED_INITIALIZER;

/** Vendor ID getter */
- (uint16_t)getVendorId;

/** Vendor ID setter */
- (void)setVendorId:(uint16_t)vendorId;

/** Product ID getter */
- (uint16_t)getProductId;

/** Product ID setter */
- (void)setProductId:(uint16_t)productId;

/** Description method */
- (NSString * _Nonnull)description;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,6 @@

#import "MCTargetAppInfo.h"

@interface MCTargetAppInfo ()

// Private properties:

/** Target Target Content Application Vendor ID, 0 means unspecified */
@property (nonatomic) uint16_t vendorId;

/** Target Target Content Application Product ID, 0 means unspecified */
@property (nonatomic) uint16_t productId;

@end

@implementation MCTargetAppInfo

- (instancetype)init
Expand Down Expand Up @@ -56,26 +44,6 @@ - (instancetype)initWithVendorId:(uint16_t)vendorId productId:(uint16_t)productI
return self;
}

- (uint16_t)getVendorId
{
return _vendorId;
}

- (void)setVendorId:(uint16_t)vendorId
{
_vendorId = vendorId;
}

- (uint16_t)getProductId
{
return _productId;
}

- (void)setProductId:(uint16_t)productId
{
_productId = productId;
}

- (NSString *)description
{
return [NSString stringWithFormat:@"MCTargetAppInfo: vendorId: %d, productId: %d", self.vendorId, self.productId];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
39231BEA2C24F90200ADFB3A /* MCEndpointSelector.swift in Sources */ = {isa = PBXBuildFile; fileRef = 39231BE92C24F90200ADFB3A /* MCEndpointSelector.swift */; };
3C40586E2B632DC500C7C6D6 /* MCMediaPlaybackSubscribeToCurrentStateExampleView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C40586D2B632DC500C7C6D6 /* MCMediaPlaybackSubscribeToCurrentStateExampleView.swift */; };
3C4058702B632DDB00C7C6D6 /* MCMediaPlaybackSubscribeToCurrentStateExampleViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C40586F2B632DDB00C7C6D6 /* MCMediaPlaybackSubscribeToCurrentStateExampleViewModel.swift */; };
3C4F52302B51F32000BB8A10 /* MCContentLauncherLaunchURLExampleViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C4F522F2B51F32000BB8A10 /* MCContentLauncherLaunchURLExampleViewModel.swift */; };
Expand Down Expand Up @@ -54,6 +55,7 @@
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
39231BE92C24F90200ADFB3A /* MCEndpointSelector.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MCEndpointSelector.swift; sourceTree = "<group>"; };
3C40586D2B632DC500C7C6D6 /* MCMediaPlaybackSubscribeToCurrentStateExampleView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MCMediaPlaybackSubscribeToCurrentStateExampleView.swift; sourceTree = "<group>"; };
3C40586F2B632DDB00C7C6D6 /* MCMediaPlaybackSubscribeToCurrentStateExampleViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MCMediaPlaybackSubscribeToCurrentStateExampleViewModel.swift; sourceTree = "<group>"; };
3C4F522F2B51F32000BB8A10 /* MCContentLauncherLaunchURLExampleViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MCContentLauncherLaunchURLExampleViewModel.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -158,6 +160,7 @@
3C94377C2B364D380096E5F4 /* MCDiscoveryExampleViewModel.swift */,
3C94378F2B3B3FF90096E5F4 /* MCConnectionExampleView.swift */,
3C94377E2B364D510096E5F4 /* MCConnectionExampleViewModel.swift */,
39231BE92C24F90200ADFB3A /* MCEndpointSelector.swift */,
3C621CB42B607FFD005CDBA3 /* MCActionSelectorView.swift */,
3C4F52312B5721D000BB8A10 /* MCContentLauncherLaunchURLExampleView.swift */,
3C4F522F2B51F32000BB8A10 /* MCContentLauncherLaunchURLExampleViewModel.swift */,
Expand Down Expand Up @@ -266,6 +269,7 @@
3C94377F2B364D510096E5F4 /* MCConnectionExampleViewModel.swift in Sources */,
3C4058702B632DDB00C7C6D6 /* MCMediaPlaybackSubscribeToCurrentStateExampleViewModel.swift in Sources */,
3CCB8745286A5D0F00771BAD /* CommissionerDiscoveryView.swift in Sources */,
39231BEA2C24F90200ADFB3A /* MCEndpointSelector.swift in Sources */,
3C621CB12B6078A9005CDBA3 /* MCApplicationBasicReadVendorIDExampleView.swift in Sources */,
3CCB8746286A5D0F00771BAD /* CommissionerDiscoveryViewModel.swift in Sources */,
3C4F52302B51F32000BB8A10 /* MCContentLauncherLaunchURLExampleViewModel.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,10 @@ class MCApplicationBasicReadVendorIDExampleViewModel: ObservableObject {
{
self.Log.info("MCApplicationBasicReadVendorIDExampleViewModel.read()")
castingPlayer.logAllEndpoints()
var selectedEndpoint: MCEndpoint?

// select the MCEndpoint on the MCCastingPlayer to invoke the command on
if let endpoint = castingPlayer.endpoints().filter({ $0.vendorId().intValue == sampleEndpointVid }).first {
selectedEndpoint = endpoint
// For the example Commissioner-Generated passcode commissioning flow, run demo interactions with the Endpoint with
// ID 1. For this flow, we commissioned with the Target Content Application with Vendor ID 1111. Since this target
// content application does not report its Endpoint's Vendor IDs, we find the desired endpoint based on the Endpoint
// ID. See connectedhomeip/examples/tv-app/tv-common/include/AppTv.h.
} else if let endpoint = castingPlayer.endpoints().filter({ $0.identifier().intValue == 1 }).first {
self.Log.info("MCApplicationBasicReadVendorIDExampleViewModel.read() No endpoint matching the sampleEndpointVid: \(String(describing: self.sampleEndpointVid)), but found endpoint with identifier: 1")
selectedEndpoint = endpoint
}

guard let endpoint = selectedEndpoint else {
self.Log.error("No endpoint matching the example VID or identifier 1 found")
// Use MCEndpointSelector to select the endpoint
guard let endpoint = MCEndpointSelector.selectEndpoint(from: castingPlayer, sampleEndpointVid: sampleEndpointVid) else {
self.Log.error("MCApplicationBasicReadVendorIDExampleViewModel.read() No endpoint matching the example VID or identifier 1 found")
DispatchQueue.main.async {
self.status = "No endpoint matching the example VID or identifier 1 found"
}
Expand Down
Loading

0 comments on commit fbd68cc

Please sign in to comment.