blob: 79fcf3c9ac117027bf6542770e2191a96d567309 [file] [log] [blame]
/*
*
* Copyright (c) 2025 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 "CodegenIntegration.h"
#include <app/clusters/boolean-state-server/boolean-state-cluster.h>
#include <app/static-cluster-config/BooleanState.h>
#include <app/util/attribute-storage.h>
#include <data-model-providers/codegen/ClusterIntegration.h>
#include <data-model-providers/codegen/CodegenDataModelProvider.h>
using namespace chip;
using namespace chip::app;
using namespace chip::app::Clusters;
using namespace chip::app::Clusters::BooleanState;
using namespace chip::app::Clusters::BooleanState::Attributes;
namespace {
constexpr size_t kBooleanStateFixedClusterCount = BooleanState::StaticApplicationConfig::kFixedClusterConfig.size();
constexpr size_t kBooleanStateMaxClusterCount = kBooleanStateFixedClusterCount + CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT;
LazyRegisteredServerCluster<BooleanStateCluster> gServers[kBooleanStateMaxClusterCount];
class IntegrationDelegate : public CodegenClusterIntegration::Delegate
{
public:
ServerClusterRegistration & CreateRegistration(EndpointId endpointId, unsigned emberEndpointIndex,
uint32_t optionalAttributeBits, uint32_t featureMap) override
{
gServers[emberEndpointIndex].Create(endpointId);
return gServers[emberEndpointIndex].Registration();
}
ServerClusterInterface & FindRegistration(unsigned emberEndpointIndex) override
{
return gServers[emberEndpointIndex].Cluster();
}
void ReleaseRegistration(unsigned emberEndpointIndex) override { gServers[emberEndpointIndex].Destroy(); }
};
} // namespace
void emberAfBooleanStateClusterServerInitCallback(EndpointId endpointId)
{
IntegrationDelegate integrationDelegate;
// register a singleton server (root endpoint only)
CodegenClusterIntegration::RegisterServer(
{
.endpointId = endpointId,
.clusterId = BooleanState::Id,
.fixedClusterServerEndpointCount = kBooleanStateFixedClusterCount,
.maxEndpointCount = kBooleanStateMaxClusterCount,
.fetchFeatureMap = false,
.fetchOptionalAttributes = false,
},
integrationDelegate);
}
void MatterBooleanStateClusterServerShutdownCallback(EndpointId endpointId)
{
IntegrationDelegate integrationDelegate;
// register a singleton server (root endpoint only)
CodegenClusterIntegration::UnregisterServer(
{
.endpointId = endpointId,
.clusterId = BooleanState::Id,
.fixedClusterServerEndpointCount = kBooleanStateFixedClusterCount,
.maxEndpointCount = kBooleanStateMaxClusterCount,
},
integrationDelegate);
}
namespace chip::app::Clusters::BooleanState {
BooleanStateCluster * GetClusterForEndpointIndex(EndpointId endpointId)
{
IntegrationDelegate integrationDelegate;
ServerClusterInterface * booleanState = CodegenClusterIntegration::GetClusterForEndpointIndex(
{
.endpointId = endpointId,
.clusterId = BooleanState::Id,
.fixedClusterServerEndpointCount = kBooleanStateFixedClusterCount,
.maxEndpointCount = kBooleanStateMaxClusterCount,
},
integrationDelegate);
return static_cast<BooleanStateCluster *>(booleanState);
}
} // namespace chip::app::Clusters::BooleanState