Skip to content

Commit

Permalink
Created Terms and Conditions Provider opposed to ConfigurationManager
Browse files Browse the repository at this point in the history
  • Loading branch information
swan-amazon committed May 17, 2024
1 parent d9aa750 commit 210c14f
Show file tree
Hide file tree
Showing 15 changed files with 211 additions and 129 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,16 +97,24 @@ CHIP_ERROR GeneralCommissioningAttrAccess::Read(const ConcreteReadAttributePath
return ReadSupportsConcurrentConnection(aEncoder);
}
case TCAcceptedVersion::Id: {
return ReadIfSupported(&ConfigurationManager::GetTCAcceptedVersion, aEncoder);
uint16_t tcAcceptedVersion;
CHIP_ERROR err = TermsAndConditionsManager::GetInstance().GetTCAcceptedVersion(tcAcceptedVersion);
return (CHIP_NO_ERROR != err) ? err : aEncoder.Encode(tcAcceptedVersion);
}
case TCMinRequiredVersion::Id: {
return ReadIfSupported(&ConfigurationManager::GetTCMinRequiredVersion, aEncoder);
uint16_t tcMinRequiredVersion;
CHIP_ERROR err = TermsAndConditionsManager::GetInstance().GetTCMinRequiredVersion(tcMinRequiredVersion);
return (CHIP_NO_ERROR != err) ? err : aEncoder.Encode(tcMinRequiredVersion);
}
case TCAcknowledgements::Id: {
return ReadIfSupported(&ConfigurationManager::GetTCAcknowledgements, aEncoder);
uint16_t tcAcknowledgements;
CHIP_ERROR err = TermsAndConditionsManager::GetInstance().GetTCAcknowledgements(tcAcknowledgements);
return (CHIP_NO_ERROR != err) ? err : aEncoder.Encode(tcAcknowledgements);
}
case TCAcknowledgementsRequired::Id: {
return ReadIfSupported(&ConfigurationManager::GetTCAcknowledgementsRequired, aEncoder);
uint16_t tcAcknowledgementsRequired;
CHIP_ERROR err = TermsAndConditionsManager::GetInstance().GetTCAcknowledgementsRequired(tcAcknowledgementsRequired);
return (CHIP_NO_ERROR != err) ? err : aEncoder.Encode(tcAcknowledgementsRequired);
}
default:
break;
Expand Down
4 changes: 4 additions & 0 deletions src/app/server/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,16 @@ static_library("server") {
"Dnssd.h",
"EchoHandler.cpp",
"EchoHandler.h",
"EnhancedSetupFlowProvider.cpp",
"EnhancedSetupFlowProvider.h",
"OnboardingCodesUtil.cpp",
"OnboardingCodesUtil.h",
"Server.cpp",
"Server.h",
"TermsAndConditionsManager.cpp",
"TermsAndConditionsManager.h",
"TermsAndConditionsProvider.cpp",
"TermsAndConditionsProvider.h",
]

public_configs = [ ":server_config" ]
Expand Down
19 changes: 19 additions & 0 deletions src/app/server/EnhancedSetupFlowProvider.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
*
* 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 "EnhancedSetupFlowProvider.h"
39 changes: 39 additions & 0 deletions src/app/server/EnhancedSetupFlowProvider.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
*
* 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 <stdint.h>

#include <lib/core/CHIPError.h>

namespace chip {
namespace app {

class EnhancedSetupFlowProvider
{
public:
CHIP_ERROR GetTCAcceptedVersion(uint16_t & value);
CHIP_ERROR GetTCMinRequiredVersion(uint16_t & value);
CHIP_ERROR GetTCAcknowledgements(uint16_t & value);
CHIP_ERROR GetTCAcknowledgementsRequired(uint16_t & value);
CHIP_ERROR StoreTCAcknowledgements(uint16_t tcVersion, uint16_t tcUserResponse);
};

}; // namespace app
}; // namespace chip
12 changes: 7 additions & 5 deletions src/app/server/TermsAndConditionsManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@

#include <platform/ConfigurationManager.h>

chip::app::TermsAndConditionsManager chip::app::TermsAndConditionsManager::sTermsAndConditionsManagerInstance;

CHIP_ERROR chip::app::TermsAndConditionsManager::GetTCAcceptedVersion(uint16_t & value)
{
CHIP_ERROR err = CHIP_NO_ERROR;

err = DeviceLayer::ConfigurationMgr().GetTCAcceptedVersion(value);
err = mTermsAndConditionsProvider.GetTCAcceptedVersion(value);
SuccessOrExit(err);

exit:
Expand All @@ -39,7 +41,7 @@ CHIP_ERROR chip::app::TermsAndConditionsManager::GetTCMinRequiredVersion(uint16_
{
CHIP_ERROR err = CHIP_NO_ERROR;

err = DeviceLayer::ConfigurationMgr().GetTCMinRequiredVersion(value);
err = mTermsAndConditionsProvider.GetTCMinRequiredVersion(value);
SuccessOrExit(err);

exit:
Expand All @@ -54,7 +56,7 @@ CHIP_ERROR chip::app::TermsAndConditionsManager::GetTCAcknowledgements(uint16_t
{
CHIP_ERROR err = CHIP_NO_ERROR;

err = DeviceLayer::ConfigurationMgr().GetTCAcknowledgements(value);
err = mTermsAndConditionsProvider.GetTCAcknowledgements(value);
SuccessOrExit(err);

exit:
Expand All @@ -69,7 +71,7 @@ CHIP_ERROR chip::app::TermsAndConditionsManager::GetTCAcknowledgementsRequired(u
{
CHIP_ERROR err = CHIP_NO_ERROR;

err = DeviceLayer::ConfigurationMgr().GetTCAcknowledgementsRequired(value);
err = mTermsAndConditionsProvider.GetTCAcknowledgementsRequired(value);
SuccessOrExit(err);

exit:
Expand All @@ -84,7 +86,7 @@ CHIP_ERROR chip::app::TermsAndConditionsManager::SetTCAcknowledgements(uint16_t
{
CHIP_ERROR err = CHIP_NO_ERROR;

err = DeviceLayer::ConfigurationMgr().StoreTCAcknowledgements(tcVersion, tcUserResponse);
err = mTermsAndConditionsProvider.SetTCAcknowledgements(tcVersion, tcUserResponse);
SuccessOrExit(err);

exit:
Expand Down
19 changes: 14 additions & 5 deletions src/app/server/TermsAndConditionsManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,29 @@

#pragma once

#include "EnhancedSetupFlowProvider.h"
#include "TermsAndConditionsProvider.h"
#include <stdint.h>

#include <lib/core/CHIPError.h>

namespace chip {
namespace app {

class TermsAndConditionsManager {
class TermsAndConditionsManager
{
public:
CHIP_ERROR GetTCAcceptedVersion(uint16_t &value);
CHIP_ERROR GetTCMinRequiredVersion(uint16_t &value);
CHIP_ERROR GetTCAcknowledgements(uint16_t &value);
CHIP_ERROR GetTCAcknowledgementsRequired(uint16_t &value);
static TermsAndConditionsManager& GetInstance() { return sTermsAndConditionsManagerInstance; }

CHIP_ERROR GetTCAcceptedVersion(uint16_t & value);
CHIP_ERROR GetTCMinRequiredVersion(uint16_t & value);
CHIP_ERROR GetTCAcknowledgements(uint16_t & value);
CHIP_ERROR GetTCAcknowledgementsRequired(uint16_t & value);
CHIP_ERROR SetTCAcknowledgements(uint16_t tcVersion, uint16_t tcUserResponse);
private:
static TermsAndConditionsManager sTermsAndConditionsManagerInstance;
TermsAndConditionsProvider mTermsAndConditionsProvider;
EnhancedSetupFlowProvider mEnhancedSetupFlowProvider;
};

}; // namespace app
Expand Down
56 changes: 56 additions & 0 deletions src/app/server/TermsAndConditionsProvider.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
*
* 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 "TermsAndConditionsProvider.h"

#include "core/CHIPBuildConfig.h"

chip::app::TermsAndConditionsProvider::TermsAndConditionsProvider() :
mTermsAndConditionsAcceptedVersion(0), mTermsAndConditionsAcknowledgements(0)
{}

CHIP_ERROR chip::app::TermsAndConditionsProvider::GetTCAcceptedVersion(uint16_t & value)
{
value = mTermsAndConditionsAcceptedVersion;
return CHIP_NO_ERROR;
}

CHIP_ERROR chip::app::TermsAndConditionsProvider::GetTCMinRequiredVersion(uint16_t & value)
{
value = CHIP_CONFIG_TC_REQUIRED_VERSION;
return CHIP_NO_ERROR;
}

CHIP_ERROR chip::app::TermsAndConditionsProvider::GetTCAcknowledgements(uint16_t & value)
{
value = mTermsAndConditionsAcknowledgements;
return CHIP_NO_ERROR;
}

CHIP_ERROR chip::app::TermsAndConditionsProvider::GetTCAcknowledgementsRequired(uint16_t & value)
{
value = CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS;
return CHIP_NO_ERROR;
}

CHIP_ERROR chip::app::TermsAndConditionsProvider::SetTCAcknowledgements(uint16_t tcVersion, uint16_t tcUserResponse)
{
mTermsAndConditionsAcceptedVersion = tcVersion;
mTermsAndConditionsAcknowledgements = tcUserResponse;
return CHIP_NO_ERROR;
}
44 changes: 44 additions & 0 deletions src/app/server/TermsAndConditionsProvider.h
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 <stdint.h>

#include <lib/core/CHIPError.h>

namespace chip {
namespace app {

class TermsAndConditionsProvider
{
public:
TermsAndConditionsProvider();
CHIP_ERROR GetTCAcceptedVersion(uint16_t & value);
CHIP_ERROR GetTCMinRequiredVersion(uint16_t & value);
CHIP_ERROR GetTCAcknowledgements(uint16_t & value);
CHIP_ERROR GetTCAcknowledgementsRequired(uint16_t & value);
CHIP_ERROR SetTCAcknowledgements(uint16_t tcVersion, uint16_t tcUserResponse);

private:
uint16_t mTermsAndConditionsAcceptedVersion;
uint16_t mTermsAndConditionsAcknowledgements;
};

}; // namespace app
}; // namespace chip
11 changes: 1 addition & 10 deletions src/include/platform/ConfigurationManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,7 @@ class ConfigurationManager
virtual CHIP_ERROR GetSoftwareVersionString(char * buf, size_t bufSize) = 0;
virtual CHIP_ERROR GetSoftwareVersion(uint32_t & softwareVer) = 0;
virtual CHIP_ERROR GetFirmwareBuildChipEpochTime(System::Clock::Seconds32 & buildTime) = 0;
virtual CHIP_ERROR SetFirmwareBuildChipEpochTime(System::Clock::Seconds32 buildTime)
{
return CHIP_ERROR_NOT_IMPLEMENTED;
}
virtual CHIP_ERROR SetFirmwareBuildChipEpochTime(System::Clock::Seconds32 buildTime) { return CHIP_ERROR_NOT_IMPLEMENTED; }
#if CHIP_ENABLE_ROTATING_DEVICE_ID && defined(CHIP_DEVICE_CONFIG_ROTATING_DEVICE_ID_UNIQUE_ID)
// Lifetime counter is monotonic counter that is incremented upon each commencement of advertising
virtual CHIP_ERROR GetLifetimeCounter(uint16_t & lifetimeCounter) = 0;
Expand Down Expand Up @@ -135,12 +132,6 @@ class ConfigurationManager
virtual CHIP_ERROR GetFailSafeArmed(bool & val) = 0;
virtual CHIP_ERROR SetFailSafeArmed(bool val) = 0;

virtual CHIP_ERROR GetTCAcceptedVersion(uint16_t & value) = 0;
virtual CHIP_ERROR GetTCMinRequiredVersion(uint16_t & value) = 0;
virtual CHIP_ERROR GetTCAcknowledgements(uint16_t & value) = 0;
virtual CHIP_ERROR GetTCAcknowledgementsRequired(uint16_t & value) = 0;
virtual CHIP_ERROR StoreTCAcknowledgements(uint16_t tcVersion, uint16_t tcUserResponse) = 0;

virtual CHIP_ERROR GetBLEDeviceIdentificationInfo(Ble::ChipBLEDeviceIdentificationInfo & deviceIdInfo) = 0;

#if CHIP_CONFIG_TEST
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ class GenericConfigurationManagerImpl : public ConfigurationManager
#endif
CHIP_ERROR GetFailSafeArmed(bool & val) override;
CHIP_ERROR SetFailSafeArmed(bool val) override;

CHIP_ERROR GetBLEDeviceIdentificationInfo(Ble::ChipBLEDeviceIdentificationInfo & deviceIdInfo) override;
bool IsCommissionableDeviceTypeEnabled() override;
CHIP_ERROR GetDeviceTypeId(uint32_t & deviceType) override;
Expand All @@ -95,11 +94,6 @@ class GenericConfigurationManagerImpl : public ConfigurationManager
CHIP_ERROR StoreRegulatoryLocation(uint8_t location) override;
CHIP_ERROR GetCountryCode(char * buf, size_t bufSize, size_t & codeLen) override;
CHIP_ERROR StoreCountryCode(const char * code, size_t codeLen) override;
CHIP_ERROR GetTCAcceptedVersion(uint16_t &value) override;
CHIP_ERROR GetTCMinRequiredVersion(uint16_t &value) override;
CHIP_ERROR GetTCAcknowledgements(uint16_t &value) override;
CHIP_ERROR GetTCAcknowledgementsRequired(uint16_t &value) override;
CHIP_ERROR StoreTCAcknowledgements(uint16_t tcVersion, uint16_t tcUserResponse) override;
CHIP_ERROR GetRebootCount(uint32_t & rebootCount) override;
CHIP_ERROR StoreRebootCount(uint32_t rebootCount) override;
CHIP_ERROR GetTotalOperationalHours(uint32_t & totalOperationalHours) override;
Expand Down Expand Up @@ -142,8 +136,8 @@ class GenericConfigurationManagerImpl : public ConfigurationManager
// Methods to read and write configuration values, as well as run the configuration unit test.
typedef typename ConfigClass::Key Key;
virtual CHIP_ERROR ReadConfigValue(Key key, bool & val) = 0;
virtual CHIP_ERROR ReadConfigValue(Key key, uint16_t & val) = 0;
virtual CHIP_ERROR ReadConfigValue(Key key, uint32_t & val) = 0;
virtual CHIP_ERROR ReadConfigValue(Key key, uint16_t & val) = 0;
virtual CHIP_ERROR ReadConfigValue(Key key, uint64_t & val) = 0;
virtual CHIP_ERROR ReadConfigValueStr(Key key, char * buf, size_t bufSize, size_t & outLen) = 0;
virtual CHIP_ERROR ReadConfigValueBin(Key key, uint8_t * buf, size_t bufSize, size_t & outLen) = 0;
Expand Down
Loading

0 comments on commit 210c14f

Please sign in to comment.