-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
IM: Create ReadHandler after Session Establishment for Subscription R…
…esumption
- Loading branch information
Showing
7 changed files
with
205 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/* | ||
* | ||
* Copyright (c) 2023 Project CHIP Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include <app/SubscriptionResumptionHelper.h> | ||
#include <app/InteractionModelEngine.h> | ||
|
||
namespace chip { | ||
namespace app { | ||
SubscriptionResumptionHelper::SubscriptionResumptionHelper() : | ||
mOnConnectedCallback(HandleDeviceConnected, this), mOnConnectionFailureCallback(HandleDeviceConnectionFailure, this) | ||
{} | ||
|
||
CHIP_ERROR SubscriptionResumptionHelper::ResumeSubscription(CASESessionManager & caseSessionManager, | ||
SubscriptionResumptionStorage::SubscriptionInfo & subscriptionInfo) | ||
{ | ||
mNodeId = subscriptionInfo.mNodeId; | ||
mFabricIndex = subscriptionInfo.mFabricIndex; | ||
mSubscriptionId = subscriptionInfo.mSubscriptionId; | ||
mMinIntervalFloorSeconds = subscriptionInfo.mMinInterval; | ||
mMaxInterval = subscriptionInfo.mMaxInterval; | ||
mFabricFiltered = subscriptionInfo.mFabricFiltered; | ||
|
||
if (subscriptionInfo.mAttributePaths.AllocatedSize() > 0) | ||
{ | ||
mAttributePaths.Alloc(subscriptionInfo.mAttributePaths.AllocatedSize()); | ||
ReturnErrorCodeIf(mAttributePaths.Get() == nullptr, CHIP_ERROR_NO_MEMORY); | ||
for (size_t i = 0; i < subscriptionInfo.mAttributePaths.AllocatedSize(); i++) | ||
{ | ||
mAttributePaths[i] = subscriptionInfo.mAttributePaths[i].GetParams(); | ||
} | ||
} | ||
|
||
if (subscriptionInfo.mEventPaths.AllocatedSize() > 0) | ||
{ | ||
mEventPaths.Alloc(subscriptionInfo.mEventPaths.AllocatedSize()); | ||
ReturnErrorCodeIf(mEventPaths.Get() == nullptr, CHIP_ERROR_NO_MEMORY); | ||
for (size_t i = 0; i < subscriptionInfo.mEventPaths.AllocatedSize(); i++) | ||
{ | ||
mEventPaths[i] = subscriptionInfo.mEventPaths[i].GetParams(); | ||
} | ||
} | ||
ScopedNodeId peerNode = ScopedNodeId(mNodeId, mFabricIndex); | ||
caseSessionManager.FindOrEstablishSession(peerNode, &mOnConnectedCallback, &mOnConnectionFailureCallback); | ||
return CHIP_NO_ERROR; | ||
} | ||
|
||
void SubscriptionResumptionHelper::HandleDeviceConnected(void * context, Messaging::ExchangeManager & exchangeMgr, | ||
const SessionHandle & sessionHandle) | ||
{ | ||
Platform::UniquePtr<SubscriptionResumptionHelper> _this(static_cast<SubscriptionResumptionHelper *>(context)); | ||
InteractionModelEngine *imEngine = InteractionModelEngine::GetInstance(); | ||
if (!imEngine->EnsureResourceForSubscription(_this->mFabricIndex, _this->mAttributePaths.AllocatedSize(), | ||
_this->mEventPaths.AllocatedSize())) | ||
{ | ||
ChipLogProgress(InteractionModel, "no resource for subscription resumption"); | ||
return; | ||
} | ||
ReadHandler *readHandler = imEngine->mReadHandlers.CreateObject(*imEngine, imEngine->GetReportScheduler()); | ||
if (readHandler == nullptr) { | ||
ChipLogProgress(InteractionModel, "no resource for ReadHandler creation"); | ||
return; | ||
} | ||
readHandler->OnSubscriptionResumed(sessionHandle, *_this); | ||
} | ||
|
||
void SubscriptionResumptionHelper::HandleDeviceConnectionFailure(void * context, const ScopedNodeId & peerId, CHIP_ERROR error) | ||
{ | ||
Platform::UniquePtr<SubscriptionResumptionHelper> _this(static_cast<SubscriptionResumptionHelper *>(context)); | ||
ChipLogError(DataManagement, "Failed to establish CASE for subscription-resumption with error '%" CHIP_ERROR_FORMAT "'", | ||
error.Format()); | ||
// Delete the persistent subscription information | ||
auto * subscriptionResumptionStorage = InteractionModelEngine::GetInstance()->GetSubscriptionResumptionStorage(); | ||
if (subscriptionResumptionStorage) | ||
{ | ||
subscriptionResumptionStorage->Delete(_this->mNodeId, _this->mFabricIndex, _this->mSubscriptionId); | ||
} | ||
} | ||
|
||
} // namespace app | ||
} // namespace chip |
Oops, something went wrong.