5c9bdd76005c89b7bca756741573bcd3ef884d6e
[platform/upstream/connectedhomeip.git] / examples / lock-app / lock-common / gen / call-command-handler.cpp
1 /*
2  *
3  *    Copyright (c) 2021 Project CHIP Authors
4  *
5  *    Licensed under the Apache License, Version 2.0 (the "License");
6  *    you may not use this file except in compliance with the License.
7  *    You may obtain a copy of the License at
8  *
9  *        http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *    Unless required by applicable law or agreed to in writing, software
12  *    distributed under the License is distributed on an "AS IS" BASIS,
13  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *    See the License for the specific language governing permissions and
15  *    limitations under the License.
16  */
17
18 // THIS FILE IS GENERATED BY ZAP
19
20 #include <stdint.h>
21
22 #include "af-structs.h"
23 #include "call-command-handler.h"
24 #include "callback.h"
25 #include "cluster-id.h"
26 #include "command-id.h"
27 #include "util.h"
28
29 using namespace chip;
30
31 EmberAfStatus emberAfOnOffClusterServerCommandParse(EmberAfClusterCommand * cmd);
32
33 static EmberAfStatus status(bool wasHandled, bool clusterExists, bool mfgSpecific)
34 {
35     if (wasHandled)
36     {
37         return EMBER_ZCL_STATUS_SUCCESS;
38     }
39     else if (mfgSpecific)
40     {
41         return EMBER_ZCL_STATUS_UNSUP_MANUF_CLUSTER_COMMAND;
42     }
43     else if (clusterExists)
44     {
45         return EMBER_ZCL_STATUS_UNSUP_COMMAND;
46     }
47     else
48     {
49         return EMBER_ZCL_STATUS_UNSUPPORTED_CLUSTER;
50     }
51 }
52
53 // Main command parsing controller.
54 EmberAfStatus emberAfClusterSpecificCommandParse(EmberAfClusterCommand * cmd)
55 {
56     EmberAfStatus result = status(false, false, cmd->mfgSpecific);
57     if (cmd->direction == (uint8_t) ZCL_DIRECTION_SERVER_TO_CLIENT &&
58         emberAfContainsClientWithMfgCode(cmd->apsFrame->destinationEndpoint, cmd->apsFrame->clusterId, cmd->mfgCode))
59     {
60         switch (cmd->apsFrame->clusterId)
61         {
62         default:
63             // Unrecognized cluster ID, error status will apply.
64             break;
65         }
66     }
67     else if (cmd->direction == (uint8_t) ZCL_DIRECTION_CLIENT_TO_SERVER &&
68              emberAfContainsServerWithMfgCode(cmd->apsFrame->destinationEndpoint, cmd->apsFrame->clusterId, cmd->mfgCode))
69     {
70         switch (cmd->apsFrame->clusterId)
71         {
72         case ZCL_ON_OFF_CLUSTER_ID:
73             result = emberAfOnOffClusterServerCommandParse(cmd);
74             break;
75         default:
76             // Unrecognized cluster ID, error status will apply.
77             break;
78         }
79     }
80     return result;
81 }
82
83 // Cluster specific command parsing
84
85 EmberAfStatus emberAfOnOffClusterServerCommandParse(EmberAfClusterCommand * cmd)
86 {
87     bool wasHandled = false;
88
89     if (!cmd->mfgSpecific)
90     {
91         switch (cmd->commandId)
92         {
93         case ZCL_OFF_COMMAND_ID: {
94             wasHandled = emberAfOnOffClusterOffCallback();
95             break;
96         }
97         case ZCL_ON_COMMAND_ID: {
98             wasHandled = emberAfOnOffClusterOnCallback();
99             break;
100         }
101         case ZCL_TOGGLE_COMMAND_ID: {
102             wasHandled = emberAfOnOffClusterToggleCallback();
103             break;
104         }
105         default: {
106             // Unrecognized command ID, error status will apply.
107             break;
108         }
109         }
110     }
111     return status(wasHandled, true, cmd->mfgSpecific);
112 }