Skip to content

Commit

Permalink
Addressed comments by sharadb-amazon part 2
Browse files Browse the repository at this point in the history
  • Loading branch information
pgregorr-amazon committed Jun 3, 2024
1 parent 008ea31 commit bb1dcd7
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,8 @@ public void onClick(DialogInterface dialog, int which) {
TAG,
"displayPasscodeInputDialog() continueConnecting() failed, calling stopConnecting() due to: "
+ err);
// Attempt to cancel the connection attempt with the CastingPlayer/Commissioner.
// Since continueConnecting() failed, Attempt to cancel the connection attempt with
// the CastingPlayer/Commissioner.
err = targetCastingPlayer.stopConnecting();
if (err.hasError()) {
Log.e(TAG, "displayPasscodeInputDialog() stopConnecting() failed due to: " + err);
Expand Down
24 changes: 18 additions & 6 deletions examples/tv-casting-app/tv-casting-common/core/CastingPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,8 @@ CHIP_ERROR CastingPlayer::ContinueConnecting()

CHIP_ERROR CastingPlayer::StopConnecting()
{
ChipLogProgress(AppServer, "CastingPlayer::StopConnecting()");
ChipLogProgress(AppServer, "CastingPlayer::StopConnecting() called, while ChipDeviceEventHandler.sUdcInProgress: %s",
support::ChipDeviceEventHandler::isUdcInProgress() ? "true" : "false");
VerifyOrReturnValue(mConnectionState == CASTING_PLAYER_CONNECTING, CHIP_ERROR_INCORRECT_STATE,
ChipLogError(AppServer, "CastingPlayer::StopConnecting() called while not in connecting state"););
VerifyOrReturnValue(
Expand All @@ -231,19 +232,30 @@ CHIP_ERROR CastingPlayer::StopConnecting()

CHIP_ERROR err = CHIP_NO_ERROR;
mIdOptions.resetState();
mIdOptions.mCancelPasscode = true;
mIdOptions.mCancelPasscode = true;
mConnectionState = CASTING_PLAYER_NOT_CONNECTED;
mCommissioningWindowTimeoutSec = kCommissioningWindowTimeoutSec;
mTargetCastingPlayer = nullptr;

// If a CastingPlayer::ContinueConnecting() error occurs, StopConnecting() can be called while sUdcInProgress == true.
// sUdcInProgress should be set to false before sending the CancelPasscode IdentificationDeclaration message to the
// CastingPlayer/Commissioner.
if (support::ChipDeviceEventHandler::isUdcInProgress())
{
support::ChipDeviceEventHandler::SetUdcStatus(false);
}

ChipLogProgress(
AppServer,
"CastingPlayer::StopConnecting() calling SendUserDirectedCommissioningRequest() to indicate user canceled passcode entry");
#if CHIP_DEVICE_CONFIG_ENABLE_COMMISSIONER_DISCOVERY_CLIENT
SuccessOrExit(err = SendUserDirectedCommissioningRequest());
#endif // CHIP_DEVICE_CONFIG_ENABLE_COMMISSIONER_DISCOVERY_CLIENT

// SendUserDirectedCommissioningRequest() sets SetUdcStatus(true) when sending a UDC message.
// CastingPlayer::SendUserDirectedCommissioningRequest() calls SetUdcStatus(true) before sending the UDC
// IdentificationDeclaration message. Since StopConnecting() is attempting to cancel the commissioning proces, we need to set
// the UDC status to false after sending the message.
support::ChipDeviceEventHandler::SetUdcStatus(false);
mConnectionState = CASTING_PLAYER_NOT_CONNECTED;
mCommissioningWindowTimeoutSec = kCommissioningWindowTimeoutSec;
mTargetCastingPlayer = nullptr;

exit:
if (err != CHIP_NO_ERROR)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,11 @@ CHIP_ERROR ChipDeviceEventHandler::SetUdcStatus(bool udcInProgress)
return CHIP_NO_ERROR;
}

bool ChipDeviceEventHandler::isUdcInProgress()
{
return sUdcInProgress;
}

}; // namespace support
}; // namespace casting
}; // namespace matter
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ class ChipDeviceEventHandler
*/
static CHIP_ERROR SetUdcStatus(bool udcInProgress);

/**
* @brief Returns true if User Directed Commissioning (UDC) is in progress, false otherwise.
*/
static bool isUdcInProgress();

private:
/**
* @brief if kFailSafeTimerExpired is received and a request to connect to a CastingPlayer is pending, open a basic
Expand Down

0 comments on commit bb1dcd7

Please sign in to comment.