23
23
#include < platform/PlatformManager.h>
24
24
#include " SwitchEventHandler.h"
25
25
26
- #include " Rpc .h"
26
+ #include " chef-rpc-actions-worker .h"
27
27
28
28
using namespace chip ;
29
29
using namespace chip ::app;
@@ -32,36 +32,46 @@ using namespace chip::app::Clusters::Switch;
32
32
using namespace chip ::DeviceLayer;
33
33
34
34
using namespace chip ::rpc;
35
+ using namespace chip ::app;
36
+
37
+ class SwitchActionsDelegate : public chip ::app::ActionsDelegate
38
+ {
39
+ public:
40
+ SwitchActionsDelegate (EndpointId endpointId, ClusterId clusterId, SwitchEventHandler *eventHandler): ActionsDelegate(endpointId, clusterId), mEventHandler (eventHandler){};
41
+ ~SwitchActionsDelegate () override {};
42
+
43
+ void AttributeWriteHandler (chip::AttributeId attributeId, std::vector<uint32_t >args) override ;
44
+ void EventHandler (chip::EventId eventId, std::vector<uint32_t >args) override ;
35
45
36
- static std::map<int , SwitchEventHandler *> gSwitchEventHandlers {};
37
46
38
- SwitchEventHandler * GetSwitchEventHandler (EndpointId endpointId)
47
+ private:
48
+ SwitchEventHandler *mEventHandler ;
49
+ };
50
+
51
+ void SwitchActionsDelegate::AttributeWriteHandler (chip::AttributeId attributeId, std::vector<uint32_t >args)
39
52
{
40
- if (gSwitchEventHandlers .find (endpointId) == gSwitchEventHandlers .end ()) {
41
- return nullptr ;
42
- }
43
53
44
- return gSwitchEventHandlers [endpointId];
45
54
}
46
55
47
- void SwitchManagerEventHandler ( intptr_t ctx, struct EventsRequest * data )
56
+ void SwitchActionsDelegate::EventHandler (chip::EventId eventId, std::vector< uint32_t >args )
48
57
{
49
- SwitchEventHandler * handler = GetSwitchEventHandler (data->endpointId );
50
-
51
- if (nullptr == handler) {
52
- // TODO: Error
53
- return ;
58
+ switch (eventId) {
59
+ case Events::SwitchLatched::Id:
60
+ {
61
+ uint8_t newPosition = static_cast <uint8_t >(args[0 ]);
62
+ mEventHandler ->OnSwitchLatched (newPosition);
63
+ }
64
+ break ;
65
+ default :
66
+ break ;
54
67
}
55
- // Parse data->events
56
- // According to data->events, to dispatch events
57
- }
68
+ };
58
69
59
- void emberAfSwitchClusterInitCallback (EndpointId endpoint )
70
+ void emberAfSwitchClusterInitCallback (EndpointId endpointId )
60
71
{
61
72
ChipLogProgress (Zcl, " Chef: emberAfSwitchClusterInitCallback" );
62
- gSwitchEventHandlers [endpoint] = new SwitchEventHandler (endpoint);
63
73
printf (" \033 [44m %s, %d, Switch::ID=%u \033 [0m \n " , __func__, __LINE__, Switch::Id);
64
- RpcRegisterAppEventsHandler ( Switch::Id, SwitchManagerEventHandler, reinterpret_cast < intptr_t >(& gSwitchEventHandlers ));
74
+ ActionsDelegate::RegisterRpcActionsDelegate (Clusters:: Switch::Id, new SwitchActionsDelegate (endpointId, Clusters::Switch::Id, new SwitchEventHandler (endpointId) ));
65
75
}
66
76
67
77
0 commit comments