Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 556f039

Browse files
committedJun 28, 2024·
Addressed comments by sharadb-amazon
1 parent ab075f7 commit 556f039

File tree

6 files changed

+277
-266
lines changed

6 files changed

+277
-266
lines changed
 

‎examples/tv-casting-app/APIs.md

+230-249
Large diffs are not rendered by default.

‎examples/tv-casting-app/android/App/app/src/main/java/com/matter/casting/InitializationExample.java

+6-4
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,6 @@
2828

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

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

‎examples/tv-casting-app/android/App/app/src/main/jni/com/matter/casting/support/IdentificationDeclarationOptions.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ public String toString() {
166166
sb.append("IdentificationDeclarationOptions::targetAppInfos list: \n");
167167

168168
for (TargetAppInfo targetAppInfo : targetAppInfos) {
169-
sb.append("\t\t").append(targetAppInfo.toString()).append("\n");
169+
sb.append("\t\t").append(targetAppInfo).append("\n");
170170
}
171171

172172
return sb.toString();

‎examples/tv-casting-app/android/App/app/src/main/jni/com/matter/casting/support/TargetAppInfo.java

-10
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ public TargetAppInfo(Integer vendorId, Integer productId) {
4141
*/
4242
public TargetAppInfo(Integer vendorId) {
4343
this.vendorId = vendorId;
44-
this.productId = null; // product ID unspecified
4544
}
4645

4746
/**
@@ -62,15 +61,6 @@ public Integer getProductId() {
6261
return productId;
6362
}
6463

65-
/**
66-
* Returns both vendorId and productId as an array.
67-
*
68-
* @return an array with vendorId and productId.
69-
*/
70-
public Integer[] getVendorAndProductId() {
71-
return new Integer[] {vendorId, productId};
72-
}
73-
7464
/**
7565
* Returns a string representation of the object.
7666
*

‎examples/tv-casting-app/darwin/TvCasting/TvCasting/MCConnectionExampleViewModel.swift

+19-1
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,18 @@ class MCConnectionExampleViewModel: ObservableObject {
8888
dataSource.update(newCommissionableData)
8989
self.Log.info("MCConnectionExampleViewModel connect() commissionerDeclarationCallback, Updated MCAppParametersDataSource instance with new MCCommissionableData.")
9090
} else {
91-
self.Log.error("MCConnectionExampleViewModel connect() commissionerDeclarationCallback, InitializationExample.getAppParametersDataSource() failed")
91+
self.Log.error("MCConnectionExampleViewModel connect() commissionerDeclarationCallback, InitializationExample.getAppParametersDataSource() failed, calling stopConnecting()")
9292
self.connectionStatus = "Failed to update the MCAppParametersDataSource with the user entered passcode: \n\nRoute back and try again."
93+
self.connectionSuccess = false
94+
// Since we failed to update the passcode, Attempt to cancel the connection attempt with
95+
// the CastingPlayer/Commissioner.
96+
let err = selectedCastingPlayer?.stopConnecting()
97+
if err == nil {
98+
self.Log.info("MCConnectionExampleViewModel connect() commissionerDeclarationCallback, InitializationExample.getAppParametersDataSource() failed, then stopConnecting() succeeded")
99+
} else {
100+
self.Log.error("MCConnectionExampleViewModel connect() commissionerDeclarationCallback, InitializationExample.getAppParametersDataSource() failed, then stopConnecting() failed due to: \(err)")
101+
}
102+
return
93103
}
94104

95105
self.Log.info("MCConnectionExampleViewModel connect() commissionerDeclarationCallback, calling MCCastingPlayer.continueConnecting()")
@@ -99,6 +109,14 @@ class MCConnectionExampleViewModel: ObservableObject {
99109
} else {
100110
self.connectionStatus = "Continue Connecting to Casting Player failed with: \(String(describing: errContinue)) \n\nRoute back and try again."
101111
self.Log.error("MCConnectionExampleViewModel connect() commissionerDeclarationCallback, MCCastingPlayer.continueConnecting() failed due to: \(errContinue)")
112+
// Since continueConnecting() failed, Attempt to cancel the connection attempt with
113+
// the CastingPlayer/Commissioner.
114+
let err = selectedCastingPlayer?.stopConnecting()
115+
if err == nil {
116+
self.Log.info("MCConnectionExampleViewModel connect() commissionerDeclarationCallback, MCCastingPlayer.continueConnecting() failed, then stopConnecting() succeeded")
117+
} else {
118+
self.Log.error("MCConnectionExampleViewModel connect() commissionerDeclarationCallback, MCCastingPlayer.continueConnecting() failed, then stopConnecting() failed due to: \(err)")
119+
}
102120
}
103121
}, cancelConnecting: {
104122
self.Log.info("MCConnectionExampleViewModel connect() commissionerDeclarationCallback, Connection attempt cancelled by the user, calling MCCastingPlayer.stopConnecting()")

‎examples/tv-casting-app/linux/simple-app-helper.cpp

+21-1
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,10 @@ CHIP_ERROR CommandHandler(int argc, char ** argv)
394394
targetCastingPlayer = castingPlayers.at(index);
395395

396396
gCommissionerGeneratedPasscodeFlowRunning = false;
397+
398+
// Specify the TargetApp that the client wants to interact with after commissioning. If this value is passed in,
399+
// VerifyOrEstablishConnection() will force UDC, in case the desired TargetApp is not found in the on-device
400+
// CastingStore
397401
matter::casting::core::IdentificationDeclarationOptions idOptions;
398402
chip::Protocols::UserDirectedCommissioning::TargetAppInfo targetAppInfo;
399403
targetAppInfo.vendorId = kDesiredEndpointVendorId;
@@ -474,6 +478,7 @@ CHIP_ERROR CommandHandler(int argc, char ** argv)
474478
ChipLogError(AppServer,
475479
"CommandHandler() setcommissionerpasscode InitCommissionableDataProvider() err %" CHIP_ERROR_FORMAT,
476480
err.Format());
481+
return err;
477482
}
478483
// Update the CommissionableDataProvider stored in this CastingApp's AppParameters and the CommissionableDataProvider to
479484
// be used for the commissioning session.
@@ -483,21 +488,35 @@ CHIP_ERROR CommandHandler(int argc, char ** argv)
483488
ChipLogError(AppServer,
484489
"CommandHandler() setcommissionerpasscode InitCommissionableDataProvider() err %" CHIP_ERROR_FORMAT,
485490
err.Format());
491+
return err;
486492
}
487493

488494
// Continue Connecting to the target CastingPlayer with the user entered Commissioner-generated Passcode.
489495
err = targetCastingPlayer->ContinueConnecting();
490496
if (err != CHIP_NO_ERROR)
491497
{
492-
ChipLogError(AppServer, "CommandHandler() setcommissionerpasscode ContinueConnecting() err %" CHIP_ERROR_FORMAT,
498+
ChipLogError(AppServer,
499+
"CommandHandler() setcommissionerpasscode ContinueConnecting() failed due to err %" CHIP_ERROR_FORMAT,
493500
err.Format());
501+
// Since continueConnecting() failed, Attempt to cancel the connection attempt with
502+
// the CastingPlayer/Commissioner by calling StopConnecting().
503+
err = targetCastingPlayer->StopConnecting();
504+
if (err != CHIP_NO_ERROR)
505+
{
506+
ChipLogError(AppServer,
507+
"CommandHandler() setcommissionerpasscode, ContinueConnecting() failed and then StopConnecting "
508+
"failed due to err %" CHIP_ERROR_FORMAT,
509+
err.Format());
510+
}
511+
return err;
494512
}
495513
}
496514
else
497515
{
498516
ChipLogError(
499517
AppServer,
500518
"CommandHandler() setcommissionerpasscode, no Commissioner-Generated passcode input expected at this time.");
519+
return CHIP_ERROR_INVALID_ARGUMENT;
501520
}
502521
}
503522
if (strcmp(argv[0], "stop-connecting") == 0)
@@ -507,6 +526,7 @@ CHIP_ERROR CommandHandler(int argc, char ** argv)
507526
if (err != CHIP_NO_ERROR)
508527
{
509528
ChipLogError(AppServer, "CommandHandler() stop-connecting, err %" CHIP_ERROR_FORMAT, err.Format());
529+
return err;
510530
}
511531
}
512532
if (strcmp(argv[0], "print-bindings") == 0)

0 commit comments

Comments
 (0)
Please sign in to comment.