1 /*
2 * Copyright (c) 2017-2021, Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included
12 * in all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
21 */
22
23 //!
24 //! \file linux_media_skuwa.h
25 //! \brief
26 //!
27
28 #ifndef __LINUX_MEDIA_SKUWA_H__
29 #define __LINUX_MEDIA_SKUWA_H__
30
31 #include <stdint.h>
32 #include <stdbool.h>
33 #include <string>
34 #include <map>
35 #include "media_class_trace.h"
36
37 class MediaFeatureTable
38 {
39 public:
40 typedef std::string SkuKey;
41 typedef std::map<SkuKey, uint8_t> MediaMap;
42 typedef MediaMap::iterator MapIterator;
43 public:
44 //!
45 //! \brief Constructor/Deconstructor
46 //!
MediaFeatureTable()47 MediaFeatureTable() { mediaMap = nullptr; }
~MediaFeatureTable()48 ~MediaFeatureTable()
49 {
50 if (mediaMap) {
51 mediaMap->clear();
52 delete mediaMap;
53 }
54 mediaMap = nullptr;
55 }
56
57 //!
58 //! \brief Copy Constructor
59 //!
MediaFeatureTable(MediaFeatureTable & mediaTable)60 MediaFeatureTable(MediaFeatureTable &mediaTable)
61 {
62 if (mediaMap)
63 mediaMap->clear();
64 else
65 mediaMap = new MediaMap;
66
67 if (mediaTable.mediaMap && mediaMap)
68 {
69 *mediaMap = *(mediaTable.mediaMap);
70 }
71 }
72
73 //!
74 //! \brief read the attribute for the given sku field.
75 //!
76 //! \param [in] ftrKey
77 //! the required FtrKey of MediaFeatureTable
78 //!
79 //! \return bool. true indicates that the attribute is enabled
80 //! false indicates that the attribute is disabled
81
MediaReadSku(SkuKey ftrKey)82 bool MediaReadSku(SkuKey ftrKey)
83 {
84 if (mediaMap == nullptr)
85 {
86 mediaMap = new MediaMap;
87 if (mediaMap == nullptr)
88 return false;
89 }
90
91 MapIterator item = mediaMap->find(ftrKey);
92 if (item == mediaMap->end())
93 {
94 // false is returned if it is not found
95 return false;
96 }
97 return item->second;
98 }
99
100 //!
101 //! \brief write/update the attribute for the given sku field.
102 //!
103 //! \param [in] ftrKey
104 //! the required FtrKey of MediaFeatureTable
105 //! \param [in] ftrValue
106 //! the attribute for the given sku field
107
MediaWriteSku(SkuKey ftrKey,uint8_t ftrValue)108 void MediaWriteSku(SkuKey ftrKey, uint8_t ftrValue)
109 {
110 if (mediaMap == nullptr)
111 {
112 mediaMap = new MediaMap;
113 if (mediaMap == nullptr)
114 return;
115 }
116
117 (*mediaMap)[ftrKey] = ftrValue;
118 return;
119 }
120
121 //!
122 //! \brief clear all the elements
123 //!
reset()124 void reset()
125 {
126 if (mediaMap)
127 {
128 mediaMap->clear();
129 delete mediaMap;
130 }
131 mediaMap = nullptr;
132 }
133
134 //!
135 //! \brief Copy= operator
136 //!
137 inline MediaFeatureTable& operator=(MediaFeatureTable &mediaTable)
138 {
139 if (mediaMap)
140 mediaMap->clear();
141 else
142 mediaMap = new MediaMap;
143
144 if (mediaTable.mediaMap && mediaMap)
145 {
146 *mediaMap = *(mediaTable.mediaMap);
147 }
148
149 return *this;
150 }
151
GetMediaSku()152 MediaMap *GetMediaSku()
153 {
154 return mediaMap;
155 }
156
157 protected:
158 MediaMap *mediaMap = nullptr;
159
160 MEDIA_CLASS_DEFINE_END(MediaFeatureTable)
161 };
162
163 class MediaWaTable
164 {
165 public:
166 typedef std::string WaKey;
167 typedef std::map<WaKey, uint8_t> MediaMap;
168 typedef MediaMap::iterator MapIterator;
169 public:
170 //!
171 //! \brief Constructor
172 //!
MediaWaTable()173 MediaWaTable() { mediaMap = nullptr; }
~MediaWaTable()174 ~MediaWaTable()
175 {
176 if (mediaMap) {
177 mediaMap->clear();
178 delete mediaMap;
179 }
180 mediaMap = nullptr;
181 }
182
183 //!
184 //! \brief Copy Constructor
185 //!
MediaWaTable(MediaWaTable & mediaTable)186 MediaWaTable(MediaWaTable &mediaTable)
187 {
188 if (mediaMap)
189 mediaMap->clear();
190 else
191 mediaMap = new MediaMap;
192
193 if (mediaTable.mediaMap && mediaMap)
194 *mediaMap = *(mediaTable.mediaMap);
195 }
196
197 //!
198 //! \brief read the attribute for the given sku field.
199 //!
200 //! \param [in] waKey
201 //! the required FtrKey of MediaWaTable
202 //!
203 //! \return bool. true indicates that the attribute is enabled
204 //! false indicates that the attribute is disabled
205
MediaReadWa(WaKey waKey)206 bool MediaReadWa(WaKey waKey)
207 {
208 if (mediaMap == nullptr)
209 {
210 mediaMap = new MediaMap;
211 if (mediaMap == nullptr)
212 return false;
213 }
214
215 MapIterator item = mediaMap->find(waKey);
216 if (item == mediaMap->end())
217 {
218 // false is returned if it is not found
219 return false;
220 }
221 return item->second;
222 }
223
224 //!
225 //! \brief write/update the attribute for the given wa field.
226 //!
227 //! \param [in] waKey
228 //! the required FtrKey of MediaWaTable
229 //! \param [in] waValue
230 //! the attribute for the given wa field
231
MediaWriteWa(WaKey waKey,uint8_t waValue)232 void MediaWriteWa(WaKey waKey, uint8_t waValue)
233 {
234 if (mediaMap == nullptr)
235 {
236 mediaMap = new MediaMap;
237 if (mediaMap == nullptr)
238 return;
239 }
240
241 (*mediaMap)[waKey] = waValue;
242 return;
243 }
244
245 //!
246 //! \brief clear all the elements
247 //!
reset()248 void reset()
249 {
250 if (mediaMap)
251 {
252 mediaMap->clear();
253 delete mediaMap;
254 }
255 mediaMap = nullptr;
256 }
257
258 //!
259 //! \brief Copy= operator
260 //!
261 inline MediaWaTable& operator=(MediaWaTable &other)
262 {
263 if (mediaMap)
264 mediaMap->clear();
265 else
266 mediaMap = new MediaMap;
267
268 if (other.mediaMap && mediaMap)
269 {
270 *mediaMap = *(other.mediaMap);
271 }
272
273 return *this;
274 }
275
GetMediaWa()276 MediaMap *GetMediaWa()
277 {
278 return mediaMap;
279 }
280
281 protected:
282 MediaMap *mediaMap = nullptr;
283 MEDIA_CLASS_DEFINE_END(MediaWaTable)
284 };
285
MediaWriteSku(MediaFeatureTable * skuTable,const char * ftrKey,uint8_t value)286 inline void MediaWriteSku(MediaFeatureTable *skuTable, const char *ftrKey, uint8_t value)
287 {
288 skuTable->MediaWriteSku(ftrKey, value);
289 }
290
MediaWriteWa(MediaWaTable * waTable,const char * waKey,uint8_t value)291 inline void MediaWriteWa(MediaWaTable *waTable, const char *waKey, uint8_t value)
292 {
293 waTable->MediaWriteWa(waKey, value);
294 }
295
MediaReadSku(MediaFeatureTable * skuTable,const char * ftrKey)296 inline bool MediaReadSku(MediaFeatureTable *skuTable, const char *ftrKey)
297 {
298 return skuTable->MediaReadSku(ftrKey);
299 }
300
MediaReadWa(MediaWaTable * waTable,const char * waKey)301 inline bool MediaReadWa(MediaWaTable *waTable, const char *waKey)
302 {
303 return waTable->MediaReadWa(waKey);
304 }
305
306 #define MEDIA_IS_SKU(s, f) MediaReadSku(s, #f)
307 #define MEDIA_WR_SKU(s, f, v) MediaWriteSku(s, #f, v)
308 #define MEDIA_IS_WA(s, w) MediaReadWa(s, #w)
309 #define MEDIA_WR_WA(s, w, v) MediaWriteWa(s, #w, v)
310
311 #endif //__LINUX_MEDIA_SKUWA_H__
312