Skip to content

Commit

Permalink
Establish CASE on re-subscription (#20080) (#21310)
Browse files Browse the repository at this point in the history
* Establish CASE on re-subscription

This adds support for re-establishing CASE on re-subscription as a
default policy implementation, with the application having the ability
to over-ride that if needed.

* Review feedback WIP

* Further fixes

* Added a Python test to validate re-subscription

* Updated comment style

* More minor cleanup

* More build fixes

* Update to master

* Review feedback

* Review

Co-authored-by: Jerry Johns <johnsj@google.com>
  • Loading branch information
woody-apple and mrjerryjohns authored Jul 28, 2022
1 parent 052e242 commit c803dab
Show file tree
Hide file tree
Showing 28 changed files with 593 additions and 245 deletions.
1 change: 1 addition & 0 deletions examples/bridge-app/esp32/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include <lib/support/ErrorStr.h>
#include <lib/support/ZclString.h>

#include <app/InteractionModelEngine.h>
#include <app/server/Server.h>

#if CONFIG_ENABLE_ESP32_FACTORY_DATA_PROVIDER
Expand Down
4 changes: 2 additions & 2 deletions src/app/BufferedReadCallback.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ class BufferedReadCallback : public ReadClient::Callback
mCallback.OnSubscriptionEstablished(aSubscriptionId);
}

void OnResubscriptionAttempt(CHIP_ERROR aTerminationCause, uint32_t aNextResubscribeIntervalMsec) override
CHIP_ERROR OnResubscriptionNeeded(ReadClient * apReadClient, CHIP_ERROR aTerminationCause) override
{
mCallback.OnResubscriptionAttempt(aTerminationCause, aNextResubscribeIntervalMsec);
return mCallback.OnResubscriptionNeeded(apReadClient, aTerminationCause);
}

void OnDeallocatePaths(chip::app::ReadPrepareParams && aReadPrepareParams) override
Expand Down
4 changes: 2 additions & 2 deletions src/app/ClusterStateCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -576,9 +576,9 @@ class ClusterStateCache : protected ReadClient::Callback
mCallback.OnSubscriptionEstablished(aSubscriptionId);
}

void OnResubscriptionAttempt(CHIP_ERROR aTerminationCause, uint32_t aNextResubscribeIntervalMsec) override
CHIP_ERROR OnResubscriptionNeeded(ReadClient * apReadClient, CHIP_ERROR aTerminationCause) override
{
mCallback.OnResubscriptionAttempt(aTerminationCause, aNextResubscribeIntervalMsec);
return mCallback.OnResubscriptionNeeded(apReadClient, aTerminationCause);
}

void OnDeallocatePaths(chip::app::ReadPrepareParams && aReadPrepareParams) override
Expand Down
1 change: 0 additions & 1 deletion src/app/DeviceProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
#pragma once

#include <app/CommandSender.h>
#include <app/InteractionModelEngine.h>
#include <lib/core/CHIPCallback.h>
#include <lib/core/CHIPCore.h>
#include <lib/support/DLLUtil.h>
Expand Down
22 changes: 18 additions & 4 deletions src/app/InteractionModelEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,17 @@ InteractionModelEngine * InteractionModelEngine::GetInstance()
return &sInteractionModelEngine;
}

CHIP_ERROR InteractionModelEngine::Init(Messaging::ExchangeManager * apExchangeMgr, FabricTable * apFabricTable)
CHIP_ERROR InteractionModelEngine::Init(Messaging::ExchangeManager * apExchangeMgr, FabricTable * apFabricTable,
CASESessionManager * apCASESessionMgr)
{
mpExchangeMgr = apExchangeMgr;
mpFabricTable = apFabricTable;
VerifyOrReturnError(apFabricTable != nullptr, CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrReturnError(apExchangeMgr != nullptr, CHIP_ERROR_INVALID_ARGUMENT);

mpExchangeMgr = apExchangeMgr;
mpFabricTable = apFabricTable;
mpCASESessionMgr = apCASESessionMgr;

ReturnErrorOnFailure(mpExchangeMgr->RegisterUnsolicitedMessageHandlerForProtocol(Protocols::InteractionModel::Id, this));
VerifyOrReturnError(mpFabricTable != nullptr, CHIP_ERROR_INVALID_ARGUMENT);

mReportingEngine.Init();
mMagic++;
Expand Down Expand Up @@ -122,6 +126,16 @@ void InteractionModelEngine::Shutdown()
mEventPathPool.ReleaseAll();
mDataVersionFilterPool.ReleaseAll();
mpExchangeMgr->UnregisterUnsolicitedMessageHandlerForProtocol(Protocols::InteractionModel::Id);

mpCASESessionMgr = nullptr;

//
// We _should_ be clearing these out, but doing so invites a world
// of trouble. #21233 tracks fixing the underlying assumptions to make
// this possible.
//
// mpFabricTable = nullptr;
// mpExchangeMgr = nullptr;
}

uint32_t InteractionModelEngine::GetNumActiveReadHandlers() const
Expand Down
17 changes: 15 additions & 2 deletions src/app/InteractionModelEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@
#include <app/util/attribute-metadata.h>
#include <app/util/basic-types.h>

#include <app/CASESessionManager.h>

namespace chip {
namespace app {

Expand Down Expand Up @@ -102,17 +104,26 @@ class InteractionModelEngine : public Messaging::UnsolicitedMessageHandler,
* Initialize the InteractionModel Engine.
*
* @param[in] apExchangeMgr A pointer to the ExchangeManager object.
* @param[in] apFabricTable A pointer to the FabricTable object.
* @param[in] apCASESessionMgr An optional pointer to a CASESessionManager (used for re-subscriptions).
*
* @retval #CHIP_ERROR_INCORRECT_STATE If the state is not equal to
* kState_NotInitialized.
* @retval #CHIP_NO_ERROR On success.
*
*/
CHIP_ERROR Init(Messaging::ExchangeManager * apExchangeMgr, FabricTable * apFabricTable);
CHIP_ERROR Init(Messaging::ExchangeManager * apExchangeMgr, FabricTable * apFabricTable,
CASESessionManager * apCASESessionMgr = nullptr);

void Shutdown();

Messaging::ExchangeManager * GetExchangeManager(void) const { return mpExchangeMgr; };
Messaging::ExchangeManager * GetExchangeManager(void) const { return mpExchangeMgr; }

/**
* Returns a pointer to the CASESessionManager. This can return nullptr if one wasn't
* provided in the call to Init().
*/
CASESessionManager * GetCASESessionManager() const { return mpCASESessionMgr; }

/**
* Tears down an active subscription.
Expand Down Expand Up @@ -551,6 +562,8 @@ class InteractionModelEngine : public Messaging::UnsolicitedMessageHandler,

FabricTable * mpFabricTable;

CASESessionManager * mpCASESessionMgr = nullptr;

// A magic number for tracking values between stack Shutdown()-s and Init()-s.
// An ObjectHandle is valid iff. its magic equals to this one.
uint32_t mMagic = 0;
Expand Down
9 changes: 4 additions & 5 deletions src/app/OperationalDeviceProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,11 @@
* messages to and from the corresponding CHIP devices.
*/

#include "OperationalDeviceProxy.h"
#include <app/OperationalDeviceProxy.h>

#include "CASEClient.h"
#include "CommandSender.h"
#include "ReadPrepareParams.h"
#include "transport/SecureSession.h"
#include <app/CASEClient.h>
#include <app/InteractionModelEngine.h>
#include <transport/SecureSession.h>

#include <lib/address_resolve/AddressResolve.h>
#include <lib/core/CHIPCore.h>
Expand Down
Loading

0 comments on commit c803dab

Please sign in to comment.