/** * * Copyright (c) 2024 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 "PresetStructWithOwnedMembers.h" using namespace chip; using namespace chip::app; using namespace DataModel; using namespace chip::app::Clusters::Thermostat::Structs; namespace chip { namespace app { namespace Clusters { namespace Thermostat { PresetStructWithOwnedMembers::PresetStructWithOwnedMembers(const PresetStruct::Type & other) { *this = other; } PresetStructWithOwnedMembers & PresetStructWithOwnedMembers::operator=(const PresetStruct::Type & other) { SetPresetScenario(other.presetScenario); CHIP_ERROR err = SetPresetHandle(other.presetHandle); if (err != CHIP_NO_ERROR) { ChipLogError(Zcl, "Failed to set Preset handle with err %" CHIP_ERROR_FORMAT, err.Format()); } err = SetName(other.name); if (err != CHIP_NO_ERROR) { ChipLogError(Zcl, "Failed to set Preset name with err %" CHIP_ERROR_FORMAT, err.Format()); } SetCoolingSetpoint(other.coolingSetpoint); SetHeatingSetpoint(other.heatingSetpoint); SetBuiltIn(other.builtIn); return *this; } PresetStructWithOwnedMembers & PresetStructWithOwnedMembers::operator=(const PresetStructWithOwnedMembers & other) { if (this == &other) { return *this; } *this = static_cast(other); return *this; } void PresetStructWithOwnedMembers::SetPresetScenario(PresetScenarioEnum enumValue) { presetScenario = enumValue; } CHIP_ERROR PresetStructWithOwnedMembers::SetPresetHandle(const Nullable & newPresetHandle) { if (!newPresetHandle.IsNull()) { size_t newPresetHandleSize = newPresetHandle.Value().size(); if (newPresetHandleSize > kPresetHandleSize) { ChipLogError(Zcl, "Failed to set Preset handle. New preset handle size (%u) > allowed preset handle size (%u)", static_cast(newPresetHandleSize), static_cast(kPresetNameSize)); return CHIP_ERROR_NO_MEMORY; } MutableByteSpan targetSpan(presetHandleData); ReturnErrorOnFailure(CopySpanToMutableSpan(newPresetHandle.Value(), targetSpan)); presetHandle.SetNonNull(targetSpan); } else { presetHandle.SetNull(); } return CHIP_NO_ERROR; } CHIP_ERROR PresetStructWithOwnedMembers::SetName(const Optional> & newName) { if (newName.HasValue() && !newName.Value().IsNull()) { size_t newNameSize = newName.Value().Value().size(); if (newNameSize > kPresetNameSize) { ChipLogError(Zcl, "Failed to set Preset name. New name size (%u) > allowed preset name size (%u)", static_cast(newNameSize), static_cast(kPresetNameSize)); return CHIP_ERROR_NO_MEMORY; } MutableCharSpan targetSpan(presetNameData); CharSpan newNameSpan = newName.Value().Value(); ReturnErrorOnFailure(CopyCharSpanToMutableCharSpan(newNameSpan, targetSpan)); DataModel::Nullable nullableCharSpan; nullableCharSpan.SetNonNull(targetSpan); name.SetValue(nullableCharSpan); } else { name.ClearValue(); } return CHIP_NO_ERROR; } void PresetStructWithOwnedMembers::SetCoolingSetpoint(const Optional & newCoolingSetpoint) { coolingSetpoint = newCoolingSetpoint; } void PresetStructWithOwnedMembers::SetHeatingSetpoint(const Optional & newHeatingSetpoint) { heatingSetpoint = newHeatingSetpoint; } void PresetStructWithOwnedMembers::SetBuiltIn(DataModel::Nullable newBuiltIn) { builtIn = newBuiltIn; } PresetScenarioEnum PresetStructWithOwnedMembers::GetPresetScenario() const { return presetScenario; } DataModel::Nullable PresetStructWithOwnedMembers::GetPresetHandle() const { return presetHandle; } Optional> PresetStructWithOwnedMembers::GetName() const { return name; } Optional PresetStructWithOwnedMembers::GetCoolingSetpoint() const { return coolingSetpoint; } Optional PresetStructWithOwnedMembers::GetHeatingSetpoint() const { return heatingSetpoint; } DataModel::Nullable PresetStructWithOwnedMembers::GetBuiltIn() const { return builtIn; } } // namespace Thermostat } // namespace Clusters } // namespace app } // namespace chip