Skip to content

Commit

Permalink
Addressing feedback from tcarmelveilleux@
Browse files Browse the repository at this point in the history
  • Loading branch information
sharadb-amazon committed Jul 25, 2023
1 parent 42f6eae commit 19f6b95
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
9 changes: 7 additions & 2 deletions src/app/server/AppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,16 @@ class AppDelegate
* This is called when there is an error in establishing a commissioning session (such as, when an invalid passcode is provided)
*
* @param err CHIP_ERROR indicating the error that occurred during session establishment
*
* @return true if the commissioning window should be closed, false otherwise
*/
virtual void OnCommissioningSessionEstablishmentError(CHIP_ERROR err) {}
virtual bool OnCommissioningSessionEstablishmentError(CHIP_ERROR err) { return false; }

/**
* This is called when the commissioning session establishment stops
* This is called in addition to OnCommissioningSessionEstablishmentError i.e. when there is an error in establishing a
* commissioning session AND the commissioning window is closed. The window may be closed because
* OnCommissioningSessionEstablishmentError returned 'true', the commissioning attempts limit was reached or listening for PASE
* failed.
*/
virtual void OnCommissioningSessionStopped() {}

Expand Down
14 changes: 7 additions & 7 deletions src/app/server/CommissioningWindowManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,17 +151,17 @@ void CommissioningWindowManager::HandleFailedAttempt(CHIP_ERROR err)
mServer->GetBleLayerObject()->CloseAllBleConnections();
#endif

CHIP_ERROR prevErr = err;
if (mFailedCommissioningAttempts < kMaxFailedCommissioningAttempts)
bool closeWindow = true;
if (mAppDelegate != nullptr)
{
// If the number of commissioning attempts has not exceeded maximum
// retries, let's start listening for commissioning connections again.
err = AdvertiseAndListenForPASE();
closeWindow = mAppDelegate->OnCommissioningSessionEstablishmentError(err);
}

if (mAppDelegate != nullptr)
if (!closeWindow && mFailedCommissioningAttempts < kMaxFailedCommissioningAttempts)
{
mAppDelegate->OnCommissioningSessionEstablishmentError(prevErr);
// If the number of commissioning attempts has not exceeded maximum
// retries, let's start listening for commissioning connections again.
err = AdvertiseAndListenForPASE();
}

if (err != CHIP_NO_ERROR)
Expand Down

0 comments on commit 19f6b95

Please sign in to comment.