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 28, 2024
1 parent 176b733 commit 76c1f5f
Show file tree
Hide file tree
Showing 6 changed files with 277 additions and 266 deletions.
479 changes: 230 additions & 249 deletions examples/tv-casting-app/APIs.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@

public class InitializationExample {
private static final String TAG = InitializationExample.class.getSimpleName();
// Dummy values for commissioning demonstration only. These are hard coded in the example tv-app:
// connectedhomeip/examples/tv-app/tv-common/src/AppTv.cpp
private static final long DUMMY_SETUP_PASSCODE = 20202021;
private static final int DUMMY_DISCRIMINATOR = 3874;

/**
* DataProvider implementation for the Unique ID that is used by the SDK to generate the Rotating
Expand All @@ -53,6 +49,12 @@ public byte[] get() {
* through commissioning
*/
public static class CommissionableDataProvider implements DataProvider<CommissionableData> {
// Dummy values for commissioning demonstration only. These are hard coded in the example
// tv-app:
// connectedhomeip/examples/tv-app/tv-common/src/AppTv.cpp
private static final long DUMMY_SETUP_PASSCODE = 20202021;
private static final int DUMMY_DISCRIMINATOR = 3874;

CommissionableData commissionableData =
new CommissionableData(DUMMY_SETUP_PASSCODE, DUMMY_DISCRIMINATOR);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public String toString() {
sb.append("IdentificationDeclarationOptions::targetAppInfos list: \n");

for (TargetAppInfo targetAppInfo : targetAppInfos) {
sb.append("\t\t").append(targetAppInfo.toString()).append("\n");
sb.append("\t\t").append(targetAppInfo).append("\n");
}

return sb.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ public TargetAppInfo(Integer vendorId, Integer productId) {
*/
public TargetAppInfo(Integer vendorId) {
this.vendorId = vendorId;
this.productId = null; // product ID unspecified
}

/**
Expand All @@ -62,15 +61,6 @@ public Integer getProductId() {
return productId;
}

/**
* Returns both vendorId and productId as an array.
*
* @return an array with vendorId and productId.
*/
public Integer[] getVendorAndProductId() {
return new Integer[] {vendorId, productId};
}

/**
* Returns a string representation of the object.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,18 @@ class MCConnectionExampleViewModel: ObservableObject {
dataSource.update(newCommissionableData)
self.Log.info("MCConnectionExampleViewModel connect() commissionerDeclarationCallback, Updated MCAppParametersDataSource instance with new MCCommissionableData.")
} else {
self.Log.error("MCConnectionExampleViewModel connect() commissionerDeclarationCallback, InitializationExample.getAppParametersDataSource() failed")
self.Log.error("MCConnectionExampleViewModel connect() commissionerDeclarationCallback, InitializationExample.getAppParametersDataSource() failed, calling stopConnecting()")
self.connectionStatus = "Failed to update the MCAppParametersDataSource with the user entered passcode: \n\nRoute back and try again."
self.connectionSuccess = false
// Since we failed to update the passcode, Attempt to cancel the connection attempt with
// the CastingPlayer/Commissioner.
let err = selectedCastingPlayer?.stopConnecting()
if err == nil {
self.Log.info("MCConnectionExampleViewModel connect() commissionerDeclarationCallback, InitializationExample.getAppParametersDataSource() failed, then stopConnecting() succeeded")
} else {
self.Log.error("MCConnectionExampleViewModel connect() commissionerDeclarationCallback, InitializationExample.getAppParametersDataSource() failed, then stopConnecting() failed due to: \(err)")
}
return
}

self.Log.info("MCConnectionExampleViewModel connect() commissionerDeclarationCallback, calling MCCastingPlayer.continueConnecting()")
Expand All @@ -99,6 +109,14 @@ class MCConnectionExampleViewModel: ObservableObject {
} else {
self.connectionStatus = "Continue Connecting to Casting Player failed with: \(String(describing: errContinue)) \n\nRoute back and try again."
self.Log.error("MCConnectionExampleViewModel connect() commissionerDeclarationCallback, MCCastingPlayer.continueConnecting() failed due to: \(errContinue)")
// Since continueConnecting() failed, Attempt to cancel the connection attempt with
// the CastingPlayer/Commissioner.
let err = selectedCastingPlayer?.stopConnecting()
if err == nil {
self.Log.info("MCConnectionExampleViewModel connect() commissionerDeclarationCallback, MCCastingPlayer.continueConnecting() failed, then stopConnecting() succeeded")
} else {
self.Log.error("MCConnectionExampleViewModel connect() commissionerDeclarationCallback, MCCastingPlayer.continueConnecting() failed, then stopConnecting() failed due to: \(err)")
}
}
}, cancelConnecting: {
self.Log.info("MCConnectionExampleViewModel connect() commissionerDeclarationCallback, Connection attempt cancelled by the user, calling MCCastingPlayer.stopConnecting()")
Expand Down
22 changes: 21 additions & 1 deletion examples/tv-casting-app/linux/simple-app-helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,10 @@ CHIP_ERROR CommandHandler(int argc, char ** argv)
targetCastingPlayer = castingPlayers.at(index);

gCommissionerGeneratedPasscodeFlowRunning = false;

// Specify the TargetApp that the client wants to interact with after commissioning. If this value is passed in,
// VerifyOrEstablishConnection() will force UDC, in case the desired TargetApp is not found in the on-device
// CastingStore
matter::casting::core::IdentificationDeclarationOptions idOptions;
chip::Protocols::UserDirectedCommissioning::TargetAppInfo targetAppInfo;
targetAppInfo.vendorId = kDesiredEndpointVendorId;
Expand Down Expand Up @@ -474,6 +478,7 @@ CHIP_ERROR CommandHandler(int argc, char ** argv)
ChipLogError(AppServer,
"CommandHandler() setcommissionerpasscode InitCommissionableDataProvider() err %" CHIP_ERROR_FORMAT,
err.Format());
return err;
}
// Update the CommissionableDataProvider stored in this CastingApp's AppParameters and the CommissionableDataProvider to
// be used for the commissioning session.
Expand All @@ -483,21 +488,35 @@ CHIP_ERROR CommandHandler(int argc, char ** argv)
ChipLogError(AppServer,
"CommandHandler() setcommissionerpasscode InitCommissionableDataProvider() err %" CHIP_ERROR_FORMAT,
err.Format());
return err;
}

// Continue Connecting to the target CastingPlayer with the user entered Commissioner-generated Passcode.
err = targetCastingPlayer->ContinueConnecting();
if (err != CHIP_NO_ERROR)
{
ChipLogError(AppServer, "CommandHandler() setcommissionerpasscode ContinueConnecting() err %" CHIP_ERROR_FORMAT,
ChipLogError(AppServer,
"CommandHandler() setcommissionerpasscode ContinueConnecting() failed due to err %" CHIP_ERROR_FORMAT,
err.Format());
// Since continueConnecting() failed, Attempt to cancel the connection attempt with
// the CastingPlayer/Commissioner by calling StopConnecting().
err = targetCastingPlayer->StopConnecting();
if (err != CHIP_NO_ERROR)
{
ChipLogError(AppServer,
"CommandHandler() setcommissionerpasscode, ContinueConnecting() failed and then StopConnecting "
"failed due to err %" CHIP_ERROR_FORMAT,
err.Format());
}
return err;
}
}
else
{
ChipLogError(
AppServer,
"CommandHandler() setcommissionerpasscode, no Commissioner-Generated passcode input expected at this time.");
return CHIP_ERROR_INVALID_ARGUMENT;
}
}
if (strcmp(argv[0], "stop-connecting") == 0)
Expand All @@ -507,6 +526,7 @@ CHIP_ERROR CommandHandler(int argc, char ** argv)
if (err != CHIP_NO_ERROR)
{
ChipLogError(AppServer, "CommandHandler() stop-connecting, err %" CHIP_ERROR_FORMAT, err.Format());
return err;
}
}
if (strcmp(argv[0], "print-bindings") == 0)
Expand Down

0 comments on commit 76c1f5f

Please sign in to comment.