Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / src / app / zap-templates / templates / app / call-command-handler-src.zapt
1 {{> header}}
2
3 #include <stdint.h>
4
5 #include "af-structs.h"
6 #include "call-command-handler.h"
7 #include "callback.h"
8 #include "cluster-id.h"
9 #include "command-id.h"
10 #include "app/util/util.h"
11
12 using namespace chip;
13
14 {{#all_user_clusters}}
15 {{#if (isEnabled enabled)}}
16 EmberAfStatus emberAf{{asCamelCased name false}}Cluster{{asCamelCased side false}}CommandParse(EmberAfClusterCommand * cmd);
17 {{/if}}
18 {{/all_user_clusters}}
19
20
21 static EmberAfStatus status(bool wasHandled, bool clusterExists, bool mfgSpecific)
22 {
23     if (wasHandled)
24     {
25         return EMBER_ZCL_STATUS_SUCCESS;
26     }
27     else if (mfgSpecific)
28     {
29         return EMBER_ZCL_STATUS_UNSUP_MANUF_CLUSTER_COMMAND;
30     }
31     else if (clusterExists)
32     {
33         return EMBER_ZCL_STATUS_UNSUP_COMMAND;
34     }
35     else
36     {
37         return EMBER_ZCL_STATUS_UNSUPPORTED_CLUSTER;
38     }
39 }
40
41
42 // Main command parsing controller.
43 EmberAfStatus emberAfClusterSpecificCommandParse(EmberAfClusterCommand * cmd)
44 {
45     EmberAfStatus result = status(false, false, cmd->mfgSpecific);
46     if (cmd->direction == (uint8_t) ZCL_DIRECTION_SERVER_TO_CLIENT &&
47         emberAfContainsClientWithMfgCode(cmd->apsFrame->destinationEndpoint, cmd->apsFrame->clusterId, cmd->mfgCode))
48     {
49         switch (cmd->apsFrame->clusterId)
50         {
51         {{#all_user_clusters}}
52         {{#if (isClient side) }}
53         case ZCL_{{asDelimitedMacro define}}_ID :
54             {{#if (user_cluster_has_enabled_command name side)}}
55             result = emberAf{{asCamelCased name false}}Cluster{{asCamelCased side false}}CommandParse(cmd);
56             {{else}}
57             // No commands are enabled for cluster {{name}}
58             result = status(false, true, cmd->mfgSpecific);
59             {{/if}}
60             break;
61         {{/if}}
62         {{/all_user_clusters}}
63         default:
64             // Unrecognized cluster ID, error status will apply.
65             break;
66         }
67     }
68     else if (cmd->direction == (uint8_t) ZCL_DIRECTION_CLIENT_TO_SERVER &&
69              emberAfContainsServerWithMfgCode(cmd->apsFrame->destinationEndpoint, cmd->apsFrame->clusterId, cmd->mfgCode))
70     {
71         switch (cmd->apsFrame->clusterId)
72         {
73         {{#all_user_clusters}}
74         {{#unless (isClient side) }}
75         case ZCL_{{asDelimitedMacro define}}_ID :
76             {{#if (user_cluster_has_enabled_command name side)}}
77             result = emberAf{{asCamelCased name false}}Cluster{{asCamelCased side false}}CommandParse(cmd);
78             {{else}}
79             // No commands are enabled for cluster {{name}}
80             result = status(false, true, cmd->mfgSpecific);
81             {{/if}}
82             break;
83         {{/unless}}
84         {{/all_user_clusters}}
85         default:
86             // Unrecognized cluster ID, error status will apply.
87             break;
88         }
89     }
90     return result;
91 }
92
93 // Cluster specific command parsing
94
95 {{#all_user_clusters}}
96 {{#if (user_cluster_has_enabled_command name side)}}
97 EmberAfStatus emberAf{{asCamelCased name false}}Cluster{{asCamelCased side false}}CommandParse(EmberAfClusterCommand * cmd)
98 {
99     bool wasHandled = false;
100
101     {{#if (user_cluster_has_enabled_manufacturer_command name side)}}
102     if (cmd->mfgSpecific)
103     {
104         {{#all_user_cluster_commands}}
105         {{#if mfgCode}}
106         {{#if (isStrEqual clusterName parent.name)}}
107         {{#if (isCommandAvailable parent.side incoming outgoing commandSource name)}}
108         if (cmd->mfgCode == {{mfgCode}} && cmd->commandId == ZCL_{{asDelimitedMacro name}}_COMMAND_ID)
109         {
110         {{> command_handler_cluster_commands}}
111         }
112         {{/if}}
113         {{/if}}
114         {{/if}}
115         {{/all_user_cluster_commands}}
116     }
117     else
118     {{else}}
119     if (!cmd->mfgSpecific)
120     {{/if}}
121     {
122         switch (cmd->commandId)
123         {
124         {{#all_user_cluster_commands}}
125         {{#unless mfgCode}}
126         {{#if (isStrEqual clusterName parent.name)}}
127         {{#if (isCommandAvailable parent.side incoming outgoing commandSource name)}}
128         case ZCL_{{asDelimitedMacro name}}_COMMAND_ID: {
129         {{> command_handler_cluster_commands}}
130             break;
131         }
132         {{/if}}
133         {{/if}}
134         {{/unless}}
135         {{/all_user_cluster_commands}}
136         default: {
137             // Unrecognized command ID, error status will apply.
138             break;
139         }
140         }
141     }
142     return status(wasHandled, true, cmd->mfgSpecific);
143 }
144 {{/if}}
145 {{/all_user_clusters}}