Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ICD] Add OnPeerTypeChange for dynamic ICD #31340

Merged
16 changes: 16 additions & 0 deletions src/app/InteractionModelEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -995,6 +995,22 @@ void InteractionModelEngine::OnActiveModeNotification(ScopedNodeId aPeer)
}
}

void InteractionModelEngine::OnPeerTypeChange(ScopedNodeId aPeer, ReadClient::PeerType aType)
{
// TODO: Follow up to use a iterator function to avoid copy/paste here.
for (ReadClient * pListItem = mpActiveReadClientList; pListItem != nullptr;)
{
// It is possible that pListItem is destroyed by the app in OnPeerTypeChange.
// Get the next item before invoking `OnPeerTypeChange`.
yunhanw-google marked this conversation as resolved.
Show resolved Hide resolved
auto pNextItem = pListItem->GetNextClient();
if (ScopedNodeId(pListItem->GetPeerNodeId(), pListItem->GetFabricIndex()) == aPeer)
{
pListItem->OnPeerTypeChange(aType);
}
pListItem = pNextItem;
}
}

void InteractionModelEngine::AddReadClient(ReadClient * apReadClient)
{
apReadClient->SetNextClient(mpActiveReadClientList);
Expand Down
8 changes: 8 additions & 0 deletions src/app/InteractionModelEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,14 @@ class InteractionModelEngine : public Messaging::UnsolicitedMessageHandler,
*/
void OnActiveModeNotification(ScopedNodeId aPeer);

/**
* Used to notify whether a peer becomes LIT ICD or vice versa.
yunhanw-google marked this conversation as resolved.
Show resolved Hide resolved
*
* When the app knows that the peer becoms LIT ICD, it is expected to call this method with PeerType::kLITICD and when
* the peer is nolonger a LIT ICD, it is expected to call this method with PeerType::kNormal.
yunhanw-google marked this conversation as resolved.
Show resolved Hide resolved
*/
void OnPeerTypeChange(ScopedNodeId aPeer, ReadClient::PeerType aType);
yunhanw-google marked this conversation as resolved.
Show resolved Hide resolved

/**
* Add a read client to the internally tracked list of weak references. This list is used to
* correctly dispatch unsolicited reports to the right matching handler by subscription ID.
Expand Down
13 changes: 13 additions & 0 deletions src/app/ReadClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,19 @@ void ReadClient::OnActiveModeNotification()
TriggerResubscriptionForLivenessTimeout(CHIP_ERROR_TIMEOUT);
}

void ReadClient::OnPeerTypeChange(PeerType aType)
{
VerifyOrDie(mpImEngine->InActiveReadClientList(this));

mIsPeerLIT = (aType == PeerType::kLITICD);

// If the peer is nolonger LIT, try to wake up the subscription and do resubsribe when necessary.
yunhanw-google marked this conversation as resolved.
Show resolved Hide resolved
if (!mIsPeerLIT)
{
OnActiveModeNotification();
}
}

CHIP_ERROR ReadClient::OnMessageReceived(Messaging::ExchangeContext * apExchangeContext, const PayloadHeader & aPayloadHeader,
System::PacketBufferHandle && aPayload)
{
Expand Down
15 changes: 15 additions & 0 deletions src/app/ReadClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,11 @@ class ReadClient : public Messaging::ExchangeDelegate
Subscribe,
};

enum class PeerType : uint8_t {
kNormal,
kLITICD,
};

/**
*
* Constructor.
Expand Down Expand Up @@ -350,6 +355,16 @@ class ReadClient : public Messaging::ExchangeDelegate
*/
void OnActiveModeNotification();

/**
* Used to notify whether a peer becomes LIT ICD or vice versa.
*
* When the app knows that the peer becoms LIT ICD, it is expected to call this method with PeerType::kLITICD and when
* the peer is nolonger a LIT ICD, it is expected to call this method with PeerType::kNormal.
yunhanw-google marked this conversation as resolved.
Show resolved Hide resolved
*
* Users should call InteractionModelEngine::OnPeerTypeChange instead of this function.
*/
void OnPeerTypeChange(PeerType aType);

void OnUnsolicitedReportData(Messaging::ExchangeContext * apExchangeContext, System::PacketBufferHandle && aPayload);

void OnUnsolicitedMessageFromPublisher()
Expand Down
Loading