Skip to content

Commit

Permalink
Restyled by clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
restyled-commits authored and erwinpan1 committed May 1, 2024
1 parent 02da45b commit 422015f
Show file tree
Hide file tree
Showing 11 changed files with 185 additions and 165 deletions.
8 changes: 4 additions & 4 deletions examples/chef/common/chef-descriptor-namespace.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ constexpr const uint8_t kTagPositionRight = 1;
// Common Position Namespace: 8, tag: 2 (Top)
constexpr const uint8_t kTagPositionTop = 2;
// Common Position Namespace: 8, tag: 3 (Bottom)
constexpr const uint8_t kTagPositionBottom = 3;
constexpr const uint8_t kTagPositionBottom = 3;
// Common Position Namespace: 8, tag: 4 (Middle)
constexpr const uint8_t kTagPositionMiddle = 4;
constexpr const uint8_t kTagPositionMiddle = 4;
// Common Position Namespace: 8, tag: 5 (Row)
constexpr const uint8_t kTagPositionRow = 5;
constexpr const uint8_t kTagPositionRow = 5;
// Common Position Namespace: 8, tag: 6 (Column)
constexpr const uint8_t kTagPositionColumn = 6;
constexpr const uint8_t kTagPositionColumn = 6;
63 changes: 40 additions & 23 deletions examples/chef/common/chef-rpc-actions-worker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
#include <app/data-model/Nullable.h>
#include <app/util/config.h>
#include <lib/core/DataModelTypes.h>
#include <platform/CHIPDeviceLayer.h>
#include <map>
#include <platform/CHIPDeviceLayer.h>

using chip::app::DataModel::Nullable;

Expand All @@ -32,11 +32,12 @@ using namespace chip::app;
using namespace chip::app::Clusters;
using namespace chip::rpc;

static std::map<ClusterId, ActionsDelegate *> gActionsDelegateMap {};
static std::map<ClusterId, ActionsDelegate *> gActionsDelegateMap{};

ActionsDelegate * RpcFindActionsDelegate(ClusterId clusterId)
{
if (gActionsDelegateMap.find(clusterId) != gActionsDelegateMap.end()) {
if (gActionsDelegateMap.find(clusterId) != gActionsDelegateMap.end())
{
return gActionsDelegateMap[clusterId];
}

Expand All @@ -45,12 +46,13 @@ ActionsDelegate * RpcFindActionsDelegate(ClusterId clusterId)

static void RpcActionsTaskCallback(System::Layer * systemLayer, void * data)
{
ChefRpcActionsWorker * worker = (ChefRpcActionsWorker *)data;
ChefRpcActionsWorker * worker = (ChefRpcActionsWorker *) data;

worker->ProcessActionQueue();
}

bool ChefRpcActionsCallback(EndpointId endpointId, ClusterId clusterId, uint8_t type, uint32_t delayMs, uint32_t actionId, std::vector<uint32_t> args)
bool ChefRpcActionsCallback(EndpointId endpointId, ClusterId clusterId, uint8_t type, uint32_t delayMs, uint32_t actionId,
std::vector<uint32_t> args)
{
ActionTask task(endpointId, clusterId, static_cast<ActionType>(type), delayMs, actionId, args);

Expand All @@ -61,13 +63,15 @@ bool ChefRpcActionsWorker::EnqueueAction(ActionTask task)
{
bool kickTimer = false;

if (queue.empty()) {
kickTimer = true; // kick timer when the first task is adding to the queue
if (queue.empty())
{
kickTimer = true; // kick timer when the first task is adding to the queue
}

queue.push(task);

if (kickTimer) {
if (kickTimer)
{
(void) DeviceLayer::SystemLayer().StartTimer(System::Clock::Milliseconds32(task.delayMs), RpcActionsTaskCallback, this);
}
return true;
Expand All @@ -80,27 +84,36 @@ void ChefRpcActionsWorker::ProcessActionQueue()
queue.pop();

ActionsDelegate * delegate = RpcFindActionsDelegate(task.clusterId);
if ( nullptr == delegate ) {
ChipLogError(NotSpecified, "Cannot run action due to not finding delegate: endpointId=%d, clusterId=%04lx, attributeId=%04lx \033[0m \n", task.endpointId, static_cast<unsigned long>(task.clusterId), static_cast<unsigned long>(task.actionId));
} else {
if (nullptr == delegate)
{
ChipLogError(NotSpecified,
"Cannot run action due to not finding delegate: endpointId=%d, clusterId=%04lx, attributeId=%04lx \033[0m \n",
task.endpointId, static_cast<unsigned long>(task.clusterId), static_cast<unsigned long>(task.actionId));
}
else
{
ActionType type = static_cast<ActionType>(task.type);

switch (type) {
case ActionType::WRITE_ATTRIBUTE:
switch (type)
{
ChipLogProgress(NotSpecified, "Writing Attribute: endpointId=%d, clusterId=%04lx, attributeId=%04lx, args.size=%lu", task.endpointId, static_cast<unsigned long>(task.clusterId), static_cast<unsigned long>(task.actionId), static_cast<unsigned long>(task.args.size()));
case ActionType::WRITE_ATTRIBUTE: {
ChipLogProgress(NotSpecified, "Writing Attribute: endpointId=%d, clusterId=%04lx, attributeId=%04lx, args.size=%lu",
task.endpointId, static_cast<unsigned long>(task.clusterId), static_cast<unsigned long>(task.actionId),
static_cast<unsigned long>(task.args.size()));
delegate->AttributeWriteHandler(task.endpointId, static_cast<chip::AttributeId>(task.actionId), task.args);
}
break;
case ActionType::RUN_COMMAND:
{
ChipLogProgress(NotSpecified, "Running Command: endpointId=%d, clusterId=%04lx, commandId=%04lx, args.size=%lu",task.endpointId, static_cast<unsigned long>(task.clusterId), static_cast<unsigned long>(task.actionId), static_cast<unsigned long>(task.args.size()));
case ActionType::RUN_COMMAND: {
ChipLogProgress(NotSpecified, "Running Command: endpointId=%d, clusterId=%04lx, commandId=%04lx, args.size=%lu",
task.endpointId, static_cast<unsigned long>(task.clusterId), static_cast<unsigned long>(task.actionId),
static_cast<unsigned long>(task.args.size()));
delegate->CommandHandler(task.endpointId, static_cast<chip::CommandId>(task.actionId), task.args);
}
break;
case ActionType::EMIT_EVENT:
{
ChipLogProgress(NotSpecified, "Emitting Event: endpointId=%d, clusterId=%04lx, eventIdId=%04lx, args.size=%lu",task.endpointId, static_cast<unsigned long>(task.clusterId), static_cast<unsigned long>(task.actionId), static_cast<unsigned long>(task.args.size()));
case ActionType::EMIT_EVENT: {
ChipLogProgress(NotSpecified, "Emitting Event: endpointId=%d, clusterId=%04lx, eventIdId=%04lx, args.size=%lu",
task.endpointId, static_cast<unsigned long>(task.clusterId), static_cast<unsigned long>(task.actionId),
static_cast<unsigned long>(task.args.size()));
delegate->EventHandler(task.endpointId, static_cast<chip::EventId>(task.actionId), task.args);
}
break;
Expand All @@ -109,21 +122,25 @@ void ChefRpcActionsWorker::ProcessActionQueue()
}
}

if (queue.empty()) {
if (queue.empty())
{
// Return due to no more actions in queue
return;
}

// Run next action
task = queue.front();
ChipLogProgress(NotSpecified, "StartTimer: endpointId=%d, clusterId=%04lx, eventIdId=%04lx, task.delyMs=%lu",task.endpointId, static_cast<unsigned long>(task.clusterId), static_cast<unsigned long>(task.actionId), static_cast<unsigned long>(task.delayMs));
ChipLogProgress(NotSpecified, "StartTimer: endpointId=%d, clusterId=%04lx, eventIdId=%04lx, task.delyMs=%lu", task.endpointId,
static_cast<unsigned long>(task.clusterId), static_cast<unsigned long>(task.actionId),
static_cast<unsigned long>(task.delayMs));
(void) DeviceLayer::SystemLayer().StartTimer(System::Clock::Milliseconds32(task.delayMs), RpcActionsTaskCallback, this);
}

void ChefRpcActionsWorker::RegisterRpcActionsDelegate(ClusterId clusterId, ActionsDelegate * delegate)
{
// Register by cluster
if ( nullptr == RpcFindActionsDelegate(clusterId) ) {
if (nullptr == RpcFindActionsDelegate(clusterId))
{
gActionsDelegateMap[clusterId] = delegate;
return;
}
Expand Down
28 changes: 14 additions & 14 deletions examples/chef/common/chef-rpc-actions-worker.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
#include <app/clusters/mode-base-server/mode-base-server.h>
#include <app/util/config.h>
#include <cstring>
#include <vector>
#include <utility>
#include <queue>
#include <utility>
#include <vector>

#include "Rpc.h"

Expand All @@ -33,45 +33,45 @@ namespace app {
class ActionsDelegate
{
public:
ActionsDelegate(ClusterId clusterId): mClusterId(clusterId) { };
ActionsDelegate(ClusterId clusterId) : mClusterId(clusterId){};

virtual ~ActionsDelegate() = default;

virtual void AttributeWriteHandler(chip::EndpointId endpointId, chip::AttributeId attributeId, std::vector<uint32_t>args) {};
virtual void CommandHandler(chip::EndpointId endpointId, chip::CommandId commandId, std::vector<uint32_t>args) {};
virtual void EventHandler(chip::EndpointId endpointId, chip::EventId eventId, std::vector<uint32_t>args) {};
virtual void AttributeWriteHandler(chip::EndpointId endpointId, chip::AttributeId attributeId, std::vector<uint32_t> args){};
virtual void CommandHandler(chip::EndpointId endpointId, chip::CommandId commandId, std::vector<uint32_t> args){};
virtual void EventHandler(chip::EndpointId endpointId, chip::EventId eventId, std::vector<uint32_t> args){};

protected:
ClusterId mClusterId;
};

struct ActionTask {
struct ActionTask
{
chip::EndpointId endpointId;
chip::ClusterId clusterId;
chip::rpc::ActionType type; // Aligned with Storage buf
chip::rpc::ActionType type; // Aligned with Storage buf
uint32_t delayMs;
uint32_t actionId;
std::vector<uint32_t> args;
ActionTask(chip::EndpointId e, chip::ClusterId c,
chip::rpc::ActionType t, uint32_t d, uint32_t i, std::vector<uint32_t> a): endpointId(e), clusterId(c), type(t), delayMs(d), actionId(i), args(a) {};
~ActionTask() {};
ActionTask(chip::EndpointId e, chip::ClusterId c, chip::rpc::ActionType t, uint32_t d, uint32_t i, std::vector<uint32_t> a) :
endpointId(e), clusterId(c), type(t), delayMs(d), actionId(i), args(a){};
~ActionTask(){};
};

class ChefRpcActionsWorker
{
public:
static ChefRpcActionsWorker& Instance();
static ChefRpcActionsWorker & Instance();

ChefRpcActionsWorker();

bool EnqueueAction(ActionTask task);
void ProcessActionQueue();
void RegisterRpcActionsDelegate(ClusterId clusterId, ActionsDelegate * delegate);

private:
private:
std::queue<ActionTask> queue;
};


} // namespace app
} // namespace chip
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ using namespace chip::app::Clusters;
using namespace chip::app::Clusters::Switch;
using namespace chip::DeviceLayer;


void SwitchEventHandler::OnSwitchLatched(EndpointId endpointId, uint8_t newPosition)
{
ChipLogDetail(NotSpecified, "The latching switch is moved to a new position:%d", newPosition);
Expand Down
3 changes: 1 addition & 2 deletions examples/chef/common/clusters/switch/SwitchEventHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace Switch {
class SwitchEventHandler
{
public:
SwitchEventHandler() {};
SwitchEventHandler(){};

/**
* Should be called when the latching switch is moved to a new position.
Expand Down Expand Up @@ -74,7 +74,6 @@ class SwitchEventHandler
private:
};


} // namespace Switch
} // namespace Clusters
} // namespace app
Expand Down
Loading

0 comments on commit 422015f

Please sign in to comment.