blob: 247ef3779ffd7a7af57c4560d67a093330065041 [file] [log] [blame]
/*
*
* Copyright (c) 2023 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 <app-common/zap-generated/cluster-objects.h>
#include <app/AttributeAccessInterface.h>
#include <app/CommandHandlerInterface.h>
#include <app/util/af.h>
namespace chip {
namespace app {
namespace Clusters {
namespace OperationalState {
class Uncopyable
{
protected:
Uncopyable() {}
~Uncopyable() {}
private:
Uncopyable(const Uncopyable &) = delete;
Uncopyable & operator=(const Uncopyable &) = delete;
};
/**
* OperationalStateServer is a class that represents an instance of a derivation of the operational state cluster.
* It implements CommandHandlerInterface so it can generically handle commands for any derivation cluster id.
*/
class OperationalStateServer : public CommandHandlerInterface, public AttributeAccessInterface, public Uncopyable
{
public:
/**
* Init the operational state server.
* This function must be called after defining a OperationalStateServer class object.
* @param void
* @return CHIP_ERROR CHIP_NO_ERROR on success, or corresponding error code.
*/
CHIP_ERROR Init();
/**
* Shut down the operational state server.
* This function must be called before destroying a OperationalStateServer class object.
* @param void
*/
void Shutdown();
/**
* Creates an operational state cluster instance. The Init() function needs to be called for this instance to be registered and
* called by the interaction model at the appropriate times.
* @param aEndpointId The endpoint on which this cluster exists. This must match the zap configuration.
* @param aClusterId The ID of the ModeSelect aliased cluster to be instantiated.
*/
OperationalStateServer(EndpointId aEndpointId, ClusterId aClusterId) :
CommandHandlerInterface(MakeOptional(aEndpointId), aClusterId),
AttributeAccessInterface(MakeOptional(aEndpointId), aClusterId)
{
mEndpointId = aEndpointId;
mClusterId = aClusterId;
}
~OperationalStateServer() override {}
private:
// Inherited from CommandHandlerInterface
template <typename RequestT, typename FuncT>
void HandleCommand(HandlerContext & handlerContext, FuncT func);
// Inherited from CommandHandlerInterface
void InvokeCommand(HandlerContext & ctx) override;
/// IM-level implementation of read
///
/// Returns appropriately mapped CHIP_ERROR if applicable (may return CHIP_IM_GLOBAL_STATUS errors)
CHIP_ERROR Read(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder) override;
/**
* Handle Command: Pause.
*/
void HandlePauseState(HandlerContext & ctx, const Commands::Pause::DecodableType & req);
/**
* Handle Command: Resume.
*/
void HandleResumeState(HandlerContext & ctx, const Commands::Resume::DecodableType & req);
/**
* Handle Command: Start.
*/
void HandleStartState(HandlerContext & ctx, const Commands::Start::DecodableType & req);
/**
* Handle Command: Stop.
*/
void HandleStopState(HandlerContext & ctx, const Commands::Stop::DecodableType & req);
EndpointId mEndpointId;
ClusterId mClusterId;
};
} // namespace OperationalState
} // namespace Clusters
} // namespace app
} // namespace chip