Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / src / app / zap-templates / templates / app / gen-tokens.zapt
1 {{> header}}
2
3 // #TODO : This template wasn't tested in any way with CHIP
4 // Might need a zap submodule update and / or other fixes to make it work.
5 // ISSUE : #3637
6
7
8 #pragma once
9
10 {{#endpoint_config}}
11 {{#tokens_context}}
12
13 {{#each singletons}}
14 // Creator for attribute: {{name}}, singleton
15 #define CREATOR_{{define}}_SINGLETON {{asHex ../token_id 4}}
16 #define NVM3KEY_{{define}}_SINGLETON (NVM3KEY_DOMAIN_ZIGBEE | {{asHex ../token_id 4}})
17 {{token_next ..}}
18 {{/each}}
19 {{#each endpoints}}
20 {{#each nonSingletons}}
21 // Creator for attribute: {{name}}, endpoint: {{../id}}
22 #define CREATOR_{{define}}_{{../id}} {{asHex ../../token_id 4}}
23 #define NVM3KEY_{{define}}_{{../id}} (NVM3KEY_DOMAIN_ZIGBEE | {{asHex ../../token_id 4}})
24 {{token_next ../..}}
25 {{/each}}
26 {{/each}}
27
28 // Types for the tokens
29 #ifdef DEFINETYPES
30 {{#each singletons}}
31 {{#if maxLength}}
32 typedef uint8_t tokType_{{tokenType}}[{{maxLength}}];
33 {{else}}
34 typedef {{as_underlying_type type}} tokType_{{tokenType}};
35 {{/if}}
36 {{/each}}
37 {{#each nonSingletons}}
38 {{#if maxLength}}
39 typedef uint8_t tokType_{{tokenType}}[{{maxLength}}];
40 {{else}}
41 typedef {{as_underlying_type type}} tokType_{{tokenType}};
42 {{/if}}
43 {{/each}}
44 #endif // DEFINETYPES
45
46
47 #ifdef DEFINETOKENS
48 {{#each singletons}}
49 {{#if longDefault}}
50 DEFINE_BASIC_TOKEN({{define}}_SINGLETON, tokType_{{tokenType}}, { {{longDefault}} })
51 {{else}}
52 {{#if defaultValue}}
53 DEFINE_BASIC_TOKEN({{define}}_SINGLETON, tokType_{{tokenType}}, {{defaultValue}})
54 {{else}}
55 DEFINE_BASIC_TOKEN({{define}}_SINGLETON, tokType_{{tokenType}}, 0)
56 {{/if}}
57 {{/if}}
58 {{/each}}
59 {{#each endpoints}}
60 {{#each nonSingletons}}
61 {{#if longDefault}}
62 DEFINE_BASIC_TOKEN({{define}}_{{../id}}, tokType_{{tokenType}}, { {{longDefault}} })
63 {{else}}
64 {{#if defaultValue}}
65 DEFINE_BASIC_TOKEN({{define}}_{{../id}}, tokType_{{tokenType}}, {{defaultValue}})
66 {{else}}
67 DEFINE_BASIC_TOKEN({{define}}_{{../id}}, tokType_{{tokenType}}, 0)
68 {{/if}}
69 {{/if}}
70 {{/each}}
71 {{/each}}
72 #endif // DEFINETOKENS
73
74
75 // Macro snippet that loads all the attributes from tokens
76 #define GENERATED_TOKEN_LOADER(endpoint) do {\
77 {{#if hasAttributes}}
78   uint8_t ptr[{{maxSize}}]; \
79 {{/if}}
80 {{#if hasNonSingletons}}
81   uint8_t curNetwork = emberGetCurrentNetwork(); \
82   uint8_t epNetwork; \
83 {{/if}}
84 {{#each singletons}}
85   halCommonGetToken((tokType_{{tokenType}} *)ptr, TOKEN_{{define}}_SINGLETON); \
86 {{#if serverSide}}
87   emberAfWriteServerAttribute(1, ZCL_{{as_delimited_macro cluster.name}}_CLUSTER_ID, ZCL_{{define}}_ATTRIBUTE_ID, (uint8_t*)ptr, ZCL_{{as_delimited_macro type}}_ATTRIBUTE_TYPE); \
88 {{/if}}
89   {{#unless serverSide}}
90   emberAfWriteClientAttribute(1, ZCL_{{as_delimited_macro cluster.name}}_CLUSTER_ID, ZCL_{{define}}_ATTRIBUTE_ID, (uint8_t*)ptr, ZCL_{{as_delimited_macro type}}_ATTRIBUTE_TYPE); \
91 {{/unless}}
92 {{/each}}
93 {{#each endpoints}}
94 {{#if hasNonSingletons}}
95   epNetwork = emberAfNetworkIndexFromEndpoint({{id}}); \
96   if({{id}} == (endpoint) || (EMBER_BROADCAST_ENDPOINT == (endpoint) && epNetwork == curNetwork)) { \
97 {{#each nonSingletons}}
98     halCommonGetToken((tokType_{{tokenType}} *)ptr, TOKEN_{{define}}_{{../id}}); \
99 {{#if serverSide}}
100     emberAfWriteServerAttribute(1, ZCL_{{as_delimited_macro cluster.name}}_CLUSTER_ID, ZCL_{{define}}_ATTRIBUTE_ID, (uint8_t*)ptr, ZCL_{{as_delimited_macro type}}_ATTRIBUTE_TYPE); \
101 {{/if}}
102 {{#unless serverSide}}
103     emberAfWriteClientAttribute(1, ZCL_{{as_delimited_macro cluster.name}}_CLUSTER_ID, ZCL_{{define}}_ATTRIBUTE_ID, (uint8_t*)ptr, ZCL_{{as_delimited_macro type}}_ATTRIBUTE_TYPE); \
104 {{/unless}}
105 {{/each}}
106   } \
107 {{/if}}
108 {{/each}}
109 } while(false)
110
111
112 // Macro snippet that saves the attribute to token
113 #define GENERATED_TOKEN_SAVER do {                                                                                               \
114     uint8_t allZeroData[{{maxSize}}];                                                                                                     \
115     MEMSET(allZeroData, 0, {{maxSize}});                                                                                                  \
116     if ( data == NULL ) { data = allZeroData; }                                                                                  \
117 {{#each clusters}}
118 {{#if hasSingletons}}
119     if ( {{hexCode}} == clusterId ) {                                                                                                 \
120 {{#each singletons}}
121       if ( {{hexCode}} == metadata->attributeId && 0x0000 == emberAfGetMfgCode(metadata) && !emberAfAttributeIsClient(metadata) ) {   \
122         halCommonSetToken(TOKEN_{{define}}_SINGLETON, data); }                                                                 \
123 {{/each}}
124     } \
125 {{/if}}
126 {{/each}}
127 {{#each endpoints}}
128 {{#if hasNonSingletons}}
129     if ( {{id}} == endpoint ) { \
130 {{#each clusters}}
131 {{#if hasNonSingletons}}
132       if ( {{hexCode}} == clusterId ) { \
133 {{#each nonSingletons}}
134         if ( {{hexCode}} == metadata->attributeId && 0x0000 == emberAfGetMfgCode(metadata) && {{#if serverSide}}!{{/if}}emberAfAttributeIsClient(metadata) ) \
135           halCommonSetToken(TOKEN_{{define}}_{{../../id}}, data); \
136 {{/each}}
137       } \
138 {{/if}}
139 {{/each}}
140     } \
141 {{/if}}
142 {{/each}}
143 } while(false)
144
145 {{/tokens_context}}
146 {{/endpoint_config}}