forked from project-chip/connectedhomeip
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Terms and Conditions] Introduce TermsAndConditionsManager singleton
Refactor Terms and Conditions handling by introducing a dedicated TermsAndConditionsManager singleton class that manages all T&C operations. - Removes T&C provider from Server class to reduce coupling - Adds new TermsAndConditionsManager class with singleton pattern - Updates all T&C provider references to use the manager - Moves initialization logic from CommonCaseDeviceServerInitParams to manager - Updates Linux example app to use the new manager The change simplifies T&C management and improves code organization by centralizing T&C functionality in a dedicated manager class.
- Loading branch information
1 parent
0c99ddc
commit 485bae5
Showing
8 changed files
with
153 additions
and
36 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
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,79 @@ | ||
/* | ||
* | ||
* Copyright (c) 2024 Project CHIP Authors | ||
* All rights reserved. | ||
* | ||
* 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 "DefaultTermsAndConditionsProvider.h" | ||
#include "TermsAndConditionsManager.h" | ||
|
||
static chip::app::TermsAndConditionsManager sTermsAndConditionsManager; | ||
static chip::app::DefaultTermsAndConditionsProvider sTermsAndConditionsProviderInstance; | ||
static chip::app::DefaultTermsAndConditionsStorageDelegate sTermsAndConditionsStorageDelegateInstance; | ||
|
||
chip::app::TermsAndConditionsManager * chip::app::TermsAndConditionsManager::GetInstance() | ||
{ | ||
return &sTermsAndConditionsManager; | ||
} | ||
|
||
CHIP_ERROR chip::app::TermsAndConditionsManager::Init(chip::PersistentStorageDelegate * const inPersistentStorageDelegate, const Optional<TermsAndConditions> & inRequiredTermsAndConditions) | ||
{ | ||
Optional<app::TermsAndConditions> termsAndConditions = Optional<app::TermsAndConditions>(app::TermsAndConditions(CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS, CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS_VERSION)); | ||
|
||
ReturnErrorOnFailure(sTermsAndConditionsStorageDelegateInstance.Init(inPersistentStorageDelegate)); | ||
ReturnErrorOnFailure(sTermsAndConditionsProviderInstance.Init(&sTermsAndConditionsStorageDelegateInstance, termsAndConditions)); | ||
|
||
return CHIP_NO_ERROR; | ||
} | ||
|
||
CHIP_ERROR chip::app::TermsAndConditionsManager::CheckAcceptance(const Optional<TermsAndConditions> & inTermsAndConditions, TermsAndConditionsState & outState) const | ||
{ | ||
return sTermsAndConditionsProviderInstance.CheckAcceptance(inTermsAndConditions, outState); | ||
} | ||
|
||
CHIP_ERROR chip::app::TermsAndConditionsManager::CommitAcceptance() | ||
{ | ||
return sTermsAndConditionsProviderInstance.CommitAcceptance(); | ||
} | ||
|
||
CHIP_ERROR chip::app::TermsAndConditionsManager::GetAcceptance(Optional<TermsAndConditions> & outTermsAndConditions) const | ||
{ | ||
return sTermsAndConditionsProviderInstance.GetAcceptance(outTermsAndConditions); | ||
} | ||
|
||
CHIP_ERROR chip::app::TermsAndConditionsManager::GetRequirements(Optional<TermsAndConditions> & outTermsAndConditions) const | ||
{ | ||
return sTermsAndConditionsProviderInstance.GetRequirements(outTermsAndConditions); | ||
} | ||
|
||
CHIP_ERROR chip::app::TermsAndConditionsManager::GetUpdateAcceptanceDeadline(Optional<uint32_t> & outUpdateAcceptanceDeadline) const | ||
{ | ||
return sTermsAndConditionsProviderInstance.GetUpdateAcceptanceDeadline(outUpdateAcceptanceDeadline); | ||
} | ||
|
||
CHIP_ERROR chip::app::TermsAndConditionsManager::ResetAcceptance() | ||
{ | ||
return sTermsAndConditionsProviderInstance.ResetAcceptance(); | ||
} | ||
|
||
CHIP_ERROR chip::app::TermsAndConditionsManager::RevertAcceptance() | ||
{ | ||
return sTermsAndConditionsProviderInstance.RevertAcceptance(); | ||
} | ||
|
||
CHIP_ERROR chip::app::TermsAndConditionsManager::SetAcceptance(const Optional<TermsAndConditions> & inTermsAndConditions) | ||
{ | ||
return sTermsAndConditionsProviderInstance.SetAcceptance(inTermsAndConditions); | ||
} |
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,44 @@ | ||
/* | ||
* | ||
* Copyright (c) 2024 Project CHIP Authors | ||
* All rights reserved. | ||
* | ||
* 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. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <lib/core/CHIPPersistentStorageDelegate.h> | ||
|
||
#include "TermsAndConditionsProvider.h" | ||
|
||
namespace chip { | ||
namespace app { | ||
|
||
class TermsAndConditionsManager : public TermsAndConditionsProvider | ||
{ | ||
public: | ||
static TermsAndConditionsManager * GetInstance(); | ||
CHIP_ERROR Init(PersistentStorageDelegate * const inPersistentStorageDelegate, const Optional<TermsAndConditions> & inRequiredTermsAndConditions); | ||
CHIP_ERROR CheckAcceptance(const Optional<TermsAndConditions> & inTermsAndConditions, TermsAndConditionsState & outState) const; | ||
CHIP_ERROR CommitAcceptance(); | ||
CHIP_ERROR GetAcceptance(Optional<TermsAndConditions> & outTermsAndConditions) const; | ||
CHIP_ERROR GetRequirements(Optional<TermsAndConditions> & outTermsAndConditions) const; | ||
CHIP_ERROR GetUpdateAcceptanceDeadline(Optional<uint32_t> & outUpdateAcceptanceDeadline) const; | ||
CHIP_ERROR ResetAcceptance(); | ||
CHIP_ERROR RevertAcceptance(); | ||
CHIP_ERROR SetAcceptance(const Optional<TermsAndConditions> & inTermsAndConditions); | ||
}; | ||
|
||
} // namespace app | ||
} // namespace chip |