EVE 1.0
flags.h
Go to the documentation of this file.
1 #ifndef TOC_TABLE_FLAGS_H_INCLUDED
2 #define TOC_TABLE_FLAGS_H_INCLUDED
3 /**********************************************************************/
4 /*
5  * Copyright (c) 2014-2015, Jetro AS
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without modification,
9  * are permitted provided that the following conditions are met:
10  *
11  * 1. Redistributions of source code must retain the above copyright notice,
12  * this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright notice,
14  * this list of conditions and the following disclaimer in the documentation
15  * and/or other materials provided with the distribution.
16  * 3. The name of the author may not be used to endorse or promote products
17  * derived from this software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONRIBUTORS ``AS IS'' AND ANY EXPRESS
20  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
22  * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
24  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
27  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
28  * OF SUCH DAMAGE.
29  *
30  * This file is part of the EVE platform.
31  */
32 
33 /**
34  * \file
35  * @brief A part of TOC table compile-time generator
36  *
37  * @author DT, Jetro AS
38  */ /******************************************************************/
39 
40 #include <stdint.h>
41 #include <toc/toc-app.h>
42 
43 /***********************************************************************
44  * Interface
45 ***********************************************************************/
46 
47 /** Common base for the flags */
49 {
50  static constexpr bool ble = false;
51  static constexpr uint16_t set = 0;
52  static constexpr uint16_t reset = 0;
53 };
54 
55 /** READ ONLY flag */
56 struct RO
57  : public CTocFlagsBase
58 {
59  static constexpr uint16_t set = TOC_FLAG_READ;
60  static constexpr uint16_t reset = TOC_FLAG_WRITE | TOC_FLAG_WRITE_POLICY_MASK;
61 };
62 
63 /** READ/WRITE flag */
64 struct RW
65  : public CTocFlagsBase
66 {
67  static constexpr uint16_t set = TOC_FLAG_READ | TOC_FLAG_WRITE;
68 };
69 
70 /** WRITE ONLY flag */
71 struct WO
72  : public CTocFlagsBase
73 {
74  static constexpr uint16_t set = TOC_FLAG_WRITE;
75  static constexpr uint16_t reset = TOC_FLAG_READ | TOC_FLAG_READ_POLICY_MASK;
76 };
77 
78 /** VIRTUALL ARRAY flag */
79 struct VIRT
80  : public CTocFlagsBase
81 {
82  static constexpr uint16_t set = TOC_FLAG_VIRTUAL;
83  static constexpr uint16_t reset = TOC_FLAG_WRITE | TOC_FLAG_WRITE_POLICY_MASK;
84 };
85 
86 /** VARIABLE SIZE flag */
87 struct VLEN
88  : public CTocFlagsBase
89 {
90  static constexpr uint16_t set = TOC_FLAG_V_SIZE;
91 };
92 
93 /** BLE BROADCAST flag */
94 struct BCAST
95  : public CTocFlagsBase
96 {
97  static constexpr bool ble = true;
98  static constexpr uint16_t set = TOC_FLAG_BLE_BROADCAST;
99 };
100 
101 /** BLE NOTIFICATION flag */
102 struct NOTIF
103  : public CTocFlagsBase
104 {
105  static constexpr bool ble = true;
106  static constexpr uint16_t set = TOC_FLAG_BLE_NOTIFICATION;
107 };
108 
109 /** BLE INDICATION flag */
110 struct IND
111  : public CTocFlagsBase
112 {
113  static constexpr bool ble = true;
114  static constexpr uint16_t set = TOC_FLAG_BLE_INDICATION;
115 };
116 
117 /** PRE-READ CALLBACK flag */
118 struct cbR
119  : public CTocFlagsBase
120 {
121  static constexpr uint16_t set = TOC_FLAG_READ_POLICY(TOC_POLICY_PRE_CB);
122  static constexpr uint16_t reset = TOC_FLAG_READ_POLICY_MASK ^ TOC_FLAG_READ_POLICY(TOC_POLICY_PRE_CB);
123 };
124 
125 /** PRE/POST-READ CALLBACK flag */
126 struct cbRcb
127  : public CTocFlagsBase
128 {
129  static constexpr uint16_t set = TOC_FLAG_READ_POLICY(TOC_POLICY_PRE_CB | TOC_POLICY_POST_CB);
130 };
131 
132 /** POST-READ CALLBACK flag */
133 struct Rcb
134  : public CTocFlagsBase
135 {
136  static constexpr uint16_t set = TOC_FLAG_READ_POLICY(TOC_POLICY_POST_CB);
137  static constexpr uint16_t reset = TOC_FLAG_READ_POLICY_MASK ^ TOC_FLAG_READ_POLICY(TOC_POLICY_POST_CB);
138 };
139 
140 /** PRE-WRITE CALLBACK flag */
141 struct cbW
142  : public CTocFlagsBase
143 {
144  static constexpr uint16_t set = TOC_FLAG_WRITE_POLICY(TOC_POLICY_PRE_CB);
145  static constexpr uint16_t reset = TOC_FLAG_WRITE_POLICY_MASK ^ TOC_FLAG_WRITE_POLICY(TOC_POLICY_PRE_CB);
146 };
147 
148 /** PRE/POST-WRITE CALLBACK flag */
149 struct cbWcb
150  : public CTocFlagsBase
151 {
152  static constexpr uint16_t set = TOC_FLAG_WRITE_POLICY(TOC_POLICY_PRE_CB | TOC_POLICY_POST_CB);
153 };
154 
155 /** POST-WRITE CALLBACK FLAG */
156 struct Wcb
157  : public CTocFlagsBase
158 {
159  static constexpr uint16_t set = TOC_FLAG_WRITE_POLICY(TOC_POLICY_POST_CB);
160  static constexpr uint16_t reset = TOC_FLAG_WRITE_POLICY_MASK ^ TOC_FLAG_WRITE_POLICY(TOC_POLICY_POST_CB);
161 };
162 
163 /** SUPERUSER flag */
164 struct SU
165  : public CTocFlagsBase
166 {
167  static constexpr uint16_t set = TOC_FLAG_ACL(TOC_ACL_PROTECTED);
168  static constexpr uint16_t reset = TOC_FLAG_ACL_MASK ^ TOC_FLAG_ACL(TOC_ACL_PROTECTED);
169 };
170 
171 /** DBG flag */
172 struct DBG
173  : public CTocFlagsBase
174 {
175  static constexpr uint16_t set = TOC_FLAG_ACL(TOC_ACL_PRIVATE);
176  static constexpr uint16_t reset = TOC_FLAG_ACL_MASK ^ TOC_FLAG_ACL(TOC_ACL_PRIVATE);
177 };
178 
179 /** HIDDEN flag */
180 struct HIDDEN
181  : public CTocFlagsBase
182 {
183  static constexpr uint16_t set = TOC_FLAG_ACL(TOC_ACL_DENIED);
184  static constexpr uint16_t reset = TOC_FLAG_ACL_MASK ^ TOC_FLAG_ACL(TOC_ACL_DENIED);
185 };
186 
187 /** DUMMY flag */
188 struct __
189  : public CTocFlagsBase
190 {
191  static constexpr uint16_t reset = 0xFFFF;
192 };
193 
194 /**
195  * The class can be used to specify non-standard traits set for the specific property.
196  *
197  * Usage:
198  \code
199  template<class U>
200  struct CExtraTraits<CVar_RAM_SomeVar>
201  : public U
202  {
203  // Redefine flags:
204  static const uint16_t m_flags = U::m_flags | SOME_FLAG;
205  // Redefine location:
206  static constexpr uint8_t m_segment = 4;
207  static constexpr size_t m_offset = 16;
208  static constexpr size_t m_size = U::m_size + 2;
209  static constexpr size_t m_count = U::m_count * 99;
210  // Please note that BINARY flag can not be changed by traits.
211 };
212  \endcode
213  */
214 template<class T, class U>
216  : public U
217 {};
218 
219 /***********************************************************************
220  * Implementation
221 ***********************************************************************/
222 
223 /** Location flags (internal) */
224 template <int count>
225 struct CLocFlags
226  : public CTocFlagsBase
227 {
228  /* Virtual arrays can not have an array som en underlaying type */
229  static constexpr uint16_t reset = (count == 1) ? 0 : TOC_FLAG_VIRTUAL;
230 };
231 
232 /** Roll out the flags pack */
233 template<class Flag, class... Flags>
235 {
236  static constexpr bool ble = Flag::ble || CRollFlagsTraits<Flags...>::ble;
237  static constexpr uint16_t set = Flag::set | CRollFlagsTraits<Flags...>::set;
238  static constexpr uint16_t reset = Flag::reset | CRollFlagsTraits<Flags...>::reset;
239 };
240 
241 /** Stop recursion */
242 template<class Flag>
243 struct CRollFlagsTraits<Flag>
244 {
245  static constexpr bool ble = Flag::ble;
246  static constexpr uint16_t set = Flag::set;
247  static constexpr uint16_t reset = Flag::reset;
248 };
249 
250 /** Build a flag bit set from the flag literal pack */
251 template<class Loc, class... Flags>
253  : public Loc
254 {
255 private:
257  static constexpr uint16_t set = traits::set;
258  static constexpr uint16_t reset = traits::reset | TOC_FLAG_EXTERN_LIMITS;
259  static_assert((set & reset) == 0, "TOC: Invalid combination of flags");
260 
261 public:
262  static const uint16_t m_flags = set;
263  static const uint16_t m_ble = traits::ble;
264 };
265 
266 #endif /* TOC_TABLE_FLAGS_H_INCLUDED */
#define TOC_FLAG_BLE_BROADCAST
Definition: toc-app.h:131
Definition: flags.h:87
#define TOC_FLAG_ACL(x)
Definition: toc-app.h:120
Definition: flags.h:71
Definition: flags.h:110
Definition: flags.h:94
Definition: flags.h:56
#define TOC_FLAG_BLE_INDICATION
Definition: toc-app.h:133
#define TOC_POLICY_PRE_CB
Definition: toc-app.h:117
#define TOC_FLAG_V_SIZE
Definition: toc-app.h:129
Definition: flags.h:164
#define TOC_ACL_PRIVATE
Definition: toc-app.h:114
Definition: flags.h:102
Definition: flags.h:180
#define TOC_FLAG_VIRTUAL
Definition: toc-app.h:127
Definition: flags.h:188
Definition: flags.h:79
#define TOC_FLAG_EXTERN_LIMITS
Definition: toc-app.h:128
#define TOC_POLICY_POST_CB
Definition: toc-app.h:118
#define TOC_FLAG_BLE_NOTIFICATION
Definition: toc-app.h:132
#define TOC_FLAG_READ_POLICY(x)
Definition: toc-app.h:121
Definition: flags.h:126
Definition: flags.h:149
TOC application API.
#define TOC_FLAG_ACL_MASK
Definition: toc-app.h:136
Definition: flags.h:133
Definition: flags.h:156
#define TOC_FLAG_WRITE_POLICY_MASK
Definition: toc-app.h:138
#define TOC_FLAG_WRITE
Definition: toc-app.h:124
Definition: flags.h:118
#define TOC_ACL_DENIED
Definition: toc-app.h:115
#define TOC_ACL_PROTECTED
Definition: toc-app.h:113
#define TOC_FLAG_READ_POLICY_MASK
Definition: toc-app.h:137
Definition: flags.h:141
#define TOC_FLAG_READ
Definition: toc-app.h:123
Definition: flags.h:64
#define TOC_FLAG_WRITE_POLICY(x)
Definition: toc-app.h:122
Definition: flags.h:172