Skip to content

Commit d5774d6

Browse files
authored
Add callback on passcode error (project-chip#41802)
* callback on passcode error * comments * comments * restyle
1 parent 66389a9 commit d5774d6

File tree

2 files changed

+61
-1
lines changed

2 files changed

+61
-1
lines changed

examples/tv-casting-app/tv-casting-common/core/CastingPlayer.cpp

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ void CastingPlayer::VerifyOrEstablishConnection(ConnectionCallbacks connectionCa
5858
mIdOptions = idOptions;
5959
castingPlayerDiscovery->ClearDisconnectedCastingPlayersInternal();
6060

61+
// Set CastingPlayer as AppDelegate
62+
chip::Server::GetInstance().GetCommissioningWindowManager().SetAppDelegate(this);
63+
6164
// Register the handler for Commissioner's CommissionerDeclaration messages. The CommissionerDeclaration messages provide
6265
// information indicating the Commissioner's pre-commissioning state.
6366
if (connectionCallbacks.mCommissionerDeclarationCallback != nullptr)
@@ -329,6 +332,10 @@ void CastingPlayer::resetState(CHIP_ERROR err)
329332
support::ChipDeviceEventHandler::SetUdcStatus(false);
330333
mConnectionState = CASTING_PLAYER_NOT_CONNECTED;
331334
mCommissioningWindowTimeoutSec = kCommissioningWindowTimeoutSec;
335+
336+
// Unregister from CommissioningWindowManager when unsetting mTargetCastingPlayer
337+
chip::Server::GetInstance().GetCommissioningWindowManager().SetAppDelegate(nullptr);
338+
332339
mTargetCastingPlayer.reset();
333340
if (mOnCompleted)
334341
{
@@ -342,6 +349,10 @@ void CastingPlayer::Disconnect()
342349
{
343350
ChipLogProgress(AppServer, "CastingPlayer::Disconnect()");
344351
mConnectionState = CASTING_PLAYER_NOT_CONNECTED;
352+
353+
// Unregister from CommissioningWindowManager when unsetting mTargetCastingPlayer
354+
chip::Server::GetInstance().GetCommissioningWindowManager().SetAppDelegate(nullptr);
355+
345356
mTargetCastingPlayer.reset();
346357
CastingPlayerDiscovery::GetInstance()->ClearCastingPlayersInternal();
347358
}
@@ -604,6 +615,46 @@ ConnectionContext::~ConnectionContext()
604615
}
605616
}
606617

618+
// AppDelegate implementation
619+
void CastingPlayer::OnCommissioningSessionEstablishmentStarted()
620+
{
621+
ChipLogProgress(AppServer, "CastingPlayer::OnCommissioningSessionEstablishmentStarted()");
622+
}
623+
624+
void CastingPlayer::OnCommissioningSessionStarted()
625+
{
626+
ChipLogProgress(AppServer, "CastingPlayer::OnCommissioningSessionStarted()");
627+
}
628+
629+
void CastingPlayer::OnCommissioningSessionEstablishmentError(CHIP_ERROR err)
630+
{
631+
ChipLogProgress(AppServer, "CastingPlayer::OnCommissioningSessionEstablishmentError() err: %" CHIP_ERROR_FORMAT, err.Format());
632+
if (mOnCompleted != nullptr)
633+
{
634+
// err = 0x38 = CHIP_ERROR_INVALID_PASE_PARAMETER upon bad passcode
635+
mOnCompleted(err, nullptr);
636+
}
637+
}
638+
639+
void CastingPlayer::OnCommissioningSessionStopped()
640+
{
641+
ChipLogProgress(AppServer, "CastingPlayer::OnCommissioningSessionStopped()");
642+
if (mOnCompleted != nullptr)
643+
{
644+
mOnCompleted(CHIP_ERROR_CANCELLED, nullptr);
645+
}
646+
}
647+
648+
void CastingPlayer::OnCommissioningWindowOpened()
649+
{
650+
ChipLogProgress(AppServer, "CastingPlayer::OnCommissioningWindowOpened()");
651+
}
652+
653+
void CastingPlayer::OnCommissioningWindowClosed()
654+
{
655+
ChipLogProgress(AppServer, "CastingPlayer::OnCommissioningWindowClosed()");
656+
}
657+
607658
}; // namespace core
608659
}; // namespace casting
609660
}; // namespace matter

examples/tv-casting-app/tv-casting-common/core/CastingPlayer.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "support/EndpointListLoader.h"
2828

2929
#include "lib/support/logging/CHIPLogging.h"
30+
#include <app/server/AppDelegate.h>
3031
#include <inet/IPAddress.h>
3132
#include <inet/InetInterface.h>
3233
#include <string.h>
@@ -92,7 +93,7 @@ class CastingPlayer;
9293
* @brief CastingPlayer represents a Matter Commissioner that is able to play media to a physical
9394
* output or to a display screen which is part of the device.
9495
*/
95-
class CastingPlayer : public std::enable_shared_from_this<CastingPlayer>
96+
class CastingPlayer : public std::enable_shared_from_this<CastingPlayer>, public AppDelegate
9697
{
9798
public:
9899
CastingPlayer(CastingPlayerAttributes playerAttributes) { mAttributes = playerAttributes; }
@@ -296,6 +297,14 @@ class CastingPlayer : public std::enable_shared_from_this<CastingPlayer>
296297
return mConnectionState;
297298
}
298299

300+
// AppDelegate implementation
301+
void OnCommissioningSessionEstablishmentStarted() override;
302+
void OnCommissioningSessionStarted() override;
303+
void OnCommissioningSessionEstablishmentError(CHIP_ERROR err) override;
304+
void OnCommissioningSessionStopped() override;
305+
void OnCommissioningWindowOpened() override;
306+
void OnCommissioningWindowClosed() override;
307+
299308
private:
300309
std::vector<memory::Strong<Endpoint>> mEndpoints;
301310
ConnectionState mConnectionState = CASTING_PLAYER_NOT_CONNECTED;

0 commit comments

Comments
 (0)