/* * * 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 #include #include #include #include #include #include "Rpc.h" namespace chip { namespace app { class ActionsDelegate { public: ActionsDelegate(ClusterId clusterId) : mClusterId(clusterId){}; virtual ~ActionsDelegate() = default; virtual void AttributeWriteHandler(chip::EndpointId endpointId, chip::AttributeId attributeId, std::vector args) = 0; virtual void CommandHandler(chip::EndpointId endpointId, chip::CommandId commandId, std::vector args) = 0; virtual void EventHandler(chip::EndpointId endpointId, chip::EventId eventId, std::vector args) = 0; protected: ClusterId mClusterId; }; struct ActionTask { chip::EndpointId endpointId; chip::ClusterId clusterId; chip::rpc::ActionType type; // Aligned with Storage buf uint32_t delayMs; uint32_t actionId; std::vector args; ActionTask(chip::EndpointId endpoint, chip::ClusterId cluster, chip::rpc::ActionType actionType, uint32_t delay, uint32_t id, std::vector arg) : endpointId(endpoint), clusterId(cluster), type(actionType), delayMs(delay), actionId(id), args(arg){}; ~ActionTask(){}; }; class ChefRpcActionsWorker { public: static ChefRpcActionsWorker & Instance(); ChefRpcActionsWorker(); bool EnqueueAction(ActionTask task); void ProcessActionQueue(); void RegisterRpcActionsDelegate(ClusterId clusterId, ActionsDelegate * delegate); private: std::queue queue; }; } // namespace app } // namespace chip