Skip to content

Commit

Permalink
[icd] add OnPeerTypeChange for dynamic ICD
Browse files Browse the repository at this point in the history
  • Loading branch information
erjiaqing committed Jan 15, 2024
1 parent 4676d27 commit 02d522a
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/app/InteractionModelEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -995,6 +995,21 @@ void InteractionModelEngine::OnActiveModeNotification(ScopedNodeId aPeer)
}
}

void InteractionModelEngine::OnPeerTypeChange(ScopedNodeId aPeer, ReadClient::PeerType aType)
{
for (ReadClient * pListItem = mpActiveReadClientList; pListItem != nullptr;)
{
auto pNextItem = pListItem->GetNextClient();
// It is possible that pListItem is destroyed by the app in OnPeerTypeChange.
// Get the next item before invoking `OnPeerTypeChange`.
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.
*
* 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.
*/
void OnPeerTypeChange(ScopedNodeId aPeer, ReadClient::PeerType aType);

/**
* 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.
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.
*
* 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

0 comments on commit 02d522a

Please sign in to comment.