@@ -47,39 +47,10 @@ ActionsDelegate * RpcFindActionsDelegate(ClusterId clusterId)
47
47
48
48
static void RpcActionsTaskCallback (System::Layer * systemLayer, void * data)
49
49
{
50
- ActionTask task = ChefRpcActionsWorker::Instance ().PopActionQueue ();
50
+ ChefRpcActionsWorker * worker = (ChefRpcActionsWorker *)data;
51
+ printf (" \033 [44m %s , %d \033 [0m \n " , __func__, __LINE__);
51
52
52
- printf (" \033 [41m %s , %d, endpointId=%d, clusterId=%d \033 [0m \n " , __func__, __LINE__, task.endpointId , task.clusterId );
53
-
54
- ActionsDelegate * delegate = RpcFindActionsDelegate (task.clusterId );
55
- if ( nullptr == delegate ) {
56
- // TBD: Error cluster not registered
57
- return ;
58
- }
59
-
60
- ActionType type = static_cast <ActionType>(task.type );
61
-
62
- switch (type) {
63
- case ActionType::WRITE_ATTRIBUTE:
64
- {
65
- delegate->AttributeWriteHandler (static_cast <chip::AttributeId>(task.actionId ), task.args );
66
- }
67
- break ;
68
- case ActionType::RUN_COMMAND:
69
- {
70
- delegate->CommandHandler (static_cast <chip::CommandId>(task.actionId ), task.args );
71
- }
72
- break ;
73
- case ActionType::EMIT_EVENT:
74
- {
75
- delegate->EventHandler (static_cast <chip::EventId>(task.actionId ), task.args );
76
- }
77
- break ;
78
- default :
79
- break ;
80
- }
81
- // TBD: insert the queue t ActionHandler's queue
82
- // delete queue;
53
+ worker->ProcessActionQueue ();
83
54
}
84
55
85
56
bool ChefRpcActionsCallback (EndpointId endpointId, ClusterId clusterId, uint8_t type, uint32_t delayMs, uint32_t actionId, std::vector<uint32_t > args)
@@ -98,18 +69,57 @@ bool ChefRpcActionsWorker::EnqueueAction(ActionTask task)
98
69
kickTimer = true ; // kick timer when the first task is adding to the queue
99
70
}
100
71
if (kickTimer) {
101
- (void ) DeviceLayer::SystemLayer ().StartTimer (System::Clock::Milliseconds32 (10 ), RpcActionsTaskCallback, this );
72
+ (void ) DeviceLayer::SystemLayer ().StartTimer (System::Clock::Milliseconds32 (task. delayMs ), RpcActionsTaskCallback, this );
102
73
}
103
74
return true ;
104
75
}
105
76
106
- ActionTask ChefRpcActionsWorker::PopActionQueue ()
77
+ void ChefRpcActionsWorker::ProcessActionQueue ()
107
78
{
108
- // assert ! queue.empty()
79
+ // delete queue;
109
80
ActionTask task = queue.front ();
110
81
queue.pop ();
111
82
112
- return task;
83
+ printf (" \033 [41m %s , %d, endpointId=%d, clusterId=%d \033 [0m \n " , __func__, __LINE__, task.endpointId , task.clusterId );
84
+
85
+ ActionsDelegate * delegate = RpcFindActionsDelegate (task.clusterId );
86
+ if ( nullptr == delegate ) {
87
+ printf (" \033 [41m %s , %d, Cannot run action due to not finding delegate: endpointId=%d, clusterId=%d \033 [0m \n " , __func__, __LINE__, task.endpointId , task.clusterId );
88
+ } else {
89
+ ActionType type = static_cast <ActionType>(task.type );
90
+
91
+ switch (type) {
92
+ case ActionType::WRITE_ATTRIBUTE:
93
+ {
94
+ printf (" \033 [41m %s , %d, Writing Attribute: %d, args size=%lu \033 [0m \n " , __func__, __LINE__, task.actionId , task.args .size ());
95
+ delegate->AttributeWriteHandler (task.endpointId , static_cast <chip::AttributeId>(task.actionId ), task.args );
96
+ }
97
+ break ;
98
+ case ActionType::RUN_COMMAND:
99
+ {
100
+ printf (" \033 [41m %s , %d, Running Command: %d, args size=%lu \033 [0m \n " , __func__, __LINE__, task.actionId , task.args .size ());
101
+ delegate->CommandHandler (task.endpointId , static_cast <chip::CommandId>(task.actionId ), task.args );
102
+ }
103
+ break ;
104
+ case ActionType::EMIT_EVENT:
105
+ {
106
+ printf (" \033 [41m %s , %d, Emitting Event: %d, args size=%lu \033 [0m \n " , __func__, __LINE__, task.actionId , task.args .size ());
107
+ delegate->EventHandler (task.endpointId , static_cast <chip::EventId>(task.actionId ), task.args );
108
+ }
109
+ break ;
110
+ default :
111
+ break ;
112
+ }
113
+ }
114
+
115
+ if (queue.empty ()) {
116
+ // Return due to no extra queue item to run.
117
+ return ;
118
+ }
119
+
120
+ // Run next task
121
+ task = queue.front ();
122
+ (void ) DeviceLayer::SystemLayer ().StartTimer (System::Clock::Milliseconds32 (task.delayMs ), RpcActionsTaskCallback, this );
113
123
}
114
124
115
125
void ChefRpcActionsWorker::RegisterRpcActionsDelegate (ClusterId clusterId, ActionsDelegate * delegate)
0 commit comments