]>
Commit | Line | Data |
---|---|---|
878ddf1f | 1 | /** @file\r |
2 | Token class.\r | |
3 | \r | |
4 | This module contains all classes releted to PCD token.\r | |
5 | \r | |
6 | Copyright (c) 2006, Intel Corporation\r | |
7 | All rights reserved. This program and the accompanying materials\r | |
8 | are licensed and made available under the terms and conditions of the BSD License\r | |
9 | which accompanies this distribution. The full text of the license may be found at\r | |
10 | http://opensource.org/licenses/bsd-license.php\r | |
11 | \r | |
12 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
13 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
14 | \r | |
15 | **/ \r | |
d14ebb43 | 16 | package org.tianocore.pcd.entity;\r |
878ddf1f | 17 | \r |
6f7e61a0 | 18 | import java.math.BigInteger;\r |
878ddf1f | 19 | import java.util.ArrayList;\r |
6f7e61a0 | 20 | import java.util.HashMap;\r |
878ddf1f | 21 | import java.util.List;\r |
8840ad58 | 22 | import java.util.Map;\r |
6f7e61a0 | 23 | import java.util.UUID;\r |
878ddf1f | 24 | \r |
d14ebb43 | 25 | import org.tianocore.pcd.entity.UsageIdentification;\r |
26 | import org.tianocore.pcd.exception.EntityException;\r | |
878ddf1f | 27 | \r |
28 | /** This class is to descript a PCD token object. The information of a token mainly \r | |
29 | comes from MSA, SPD and setting produced by platform developer. \r | |
30 | **/\r | |
31 | public class Token {\r | |
32 | ///\r | |
33 | /// Enumeration macro defintion for PCD type.\r | |
34 | /// BUGBUG: Not use upcase charater is to facility for reading. It may be changed\r | |
35 | /// in coding review.\r | |
36 | public enum PCD_TYPE {FEATURE_FLAG, FIXED_AT_BUILD, PATCHABLE_IN_MODULE, DYNAMIC, \r | |
37 | DYNAMIC_EX, UNKNOWN}\r | |
38 | \r | |
39 | ///\r | |
40 | /// Enumeration macro definition for datum type. All type mainly comes from ProcessBind.h.\r | |
41 | /// Wizard maybe expand this type as "int, unsigned int, short, unsigned short etc" in \r | |
42 | /// prompt dialog.\r | |
43 | ///\r | |
44 | public enum DATUM_TYPE {UINT8, UINT16, UINT32, UINT64, BOOLEAN, POINTER, UNKNOWN}\r | |
45 | \r | |
46 | ///\r | |
47 | /// Enumeration macor defintion for usage of PCD\r | |
48 | ///\r | |
49 | public enum PCD_USAGE {ALWAYS_PRODUCED, ALWAYS_CONSUMED, SOMETIMES_PRODUCED,\r | |
50 | SOMETIMES_CONSUMED, UNKNOWN}\r | |
51 | \r | |
52 | ///\r | |
53 | /// cName is to identify a PCD entry and will be used for generating autogen.h/autogen.c.\r | |
54 | /// cName will be defined in MSA, SPD and FPD, can be regarded as primary key with token space guid.\r | |
55 | ///\r | |
56 | public String cName;\r | |
57 | \r | |
58 | ///\r | |
59 | /// Token space name is the guid defined by token itself in package or module level. This\r | |
60 | /// name mainly for DynamicEx type. For other PCD type token, his token space name is the \r | |
61 | /// assignedtokenSpaceName as follows.\r | |
62 | /// tokenSpaceName is defined in MSA, SPD, FPD, can be regarded as primary key with cName.\r | |
63 | ///\r | |
eece174a | 64 | public String tokenSpaceName;\r |
878ddf1f | 65 | \r |
66 | ///\r | |
67 | /// tokenNumber is allocated by platform. tokenNumber indicate an index for this token in\r | |
38ee8d9e | 68 | /// platform token space. For Dynamic, dynamicEx type, this number will be re-adjust by\r |
69 | /// PCD run-time database autogen tools.\r | |
878ddf1f | 70 | ///\r |
eece174a | 71 | public long tokenNumber;\r |
878ddf1f | 72 | \r |
38ee8d9e | 73 | ///\r |
74 | /// This token number is retrieved from FPD file for DynamicEx type. \r | |
75 | /// \r | |
eece174a | 76 | public long dynamicExTokenNumber;\r |
38ee8d9e | 77 | \r |
878ddf1f | 78 | ///\r |
6ff7a41c | 79 | /// All supported PCD type, this value can be retrieved from SPD\r |
80 | /// Currently, only record all PCD type for this token in FPD file.\r | |
81 | /// \r | |
82 | public List<PCD_TYPE> supportedPcdType;\r | |
83 | \r | |
878ddf1f | 84 | ///\r |
6ff7a41c | 85 | /// If the token's item type is Dynamic or DynamicEx type, isDynamicPCD\r |
86 | /// is true.\r | |
87 | /// \r | |
88 | public boolean isDynamicPCD;\r | |
878ddf1f | 89 | \r |
878ddf1f | 90 | ///\r |
91 | /// datumSize is to descript the fix size or max size for this token. \r | |
92 | /// datumSize is defined in SPD.\r | |
93 | ///\r | |
94 | public int datumSize;\r | |
95 | \r | |
96 | ///\r | |
97 | /// datum type is to descript what type can be expressed by a PCD token.\r | |
6ff7a41c | 98 | /// For same PCD used in different module, the datum type should be unique.\r |
99 | /// So it belong memeber to Token class.\r | |
878ddf1f | 100 | ///\r |
101 | public DATUM_TYPE datumType;\r | |
102 | \r | |
878ddf1f | 103 | ///\r |
104 | /// skuData contains all value for SkuNumber of token.\r | |
6ff7a41c | 105 | /// This field is for Dynamic or DynamicEx type PCD, \r |
878ddf1f | 106 | ///\r |
107 | public List<SkuInstance> skuData;\r | |
108 | \r | |
878ddf1f | 109 | ///\r |
110 | /// consumers array record all module private information who consume this PCD token.\r | |
111 | ///\r | |
8840ad58 | 112 | public Map<String, UsageInstance> consumers;\r |
878ddf1f | 113 | \r |
eece174a | 114 | /**\r |
115 | Constructure function for Token class\r | |
116 | \r | |
117 | @param cName The name of token\r | |
118 | @param tokenSpaceName The name of token space, it is a guid string\r | |
119 | **/\r | |
120 | public Token(String cName, String tokenSpaceName) {\r | |
878ddf1f | 121 | this.cName = cName;\r |
eece174a | 122 | this.tokenSpaceName = tokenSpaceName;\r |
878ddf1f | 123 | this.tokenNumber = 0;\r |
878ddf1f | 124 | this.datumType = DATUM_TYPE.UNKNOWN;\r |
125 | this.datumSize = -1;\r | |
878ddf1f | 126 | this.skuData = new ArrayList<SkuInstance>();\r |
878ddf1f | 127 | \r |
8840ad58 | 128 | this.consumers = new HashMap<String, UsageInstance>();\r |
6ff7a41c | 129 | this.supportedPcdType = new ArrayList<PCD_TYPE>();\r |
130 | }\r | |
131 | \r | |
132 | /**\r | |
133 | updateSupportPcdType\r | |
134 | \r | |
135 | SupportPcdType should be gotten from SPD file actually, but now it just\r | |
136 | record all PCD type for this token in FPD file.\r | |
137 | \r | |
138 | @param pcdType new PCD type found in FPD file for this token.\r | |
139 | **/\r | |
140 | public void updateSupportPcdType(PCD_TYPE pcdType) {\r | |
eece174a | 141 | for (int index = 0; index < this.supportedPcdType.size(); index ++) {\r |
142 | if (supportedPcdType.get(index) == pcdType) {\r | |
143 | return;\r | |
6ff7a41c | 144 | }\r |
145 | }\r | |
eece174a | 146 | \r |
147 | //\r | |
148 | // If not found, add the pcd type to member variable supportedPcdType\r | |
149 | // \r | |
150 | supportedPcdType.add(pcdType);\r | |
6ff7a41c | 151 | }\r |
152 | \r | |
153 | /**\r | |
154 | Judge whether pcdType is belong to dynamic type. Dynamic type includes\r | |
155 | DYNAMIC and DYNAMIC_EX.\r | |
156 | \r | |
eece174a | 157 | @param pcdType the judged pcd type\r |
6ff7a41c | 158 | \r |
159 | @return boolean\r | |
160 | */\r | |
161 | public static boolean isDynamic(PCD_TYPE pcdType) {\r | |
162 | if ((pcdType == PCD_TYPE.DYNAMIC ) ||\r | |
163 | (pcdType == PCD_TYPE.DYNAMIC_EX)) {\r | |
164 | return true;\r | |
165 | }\r | |
166 | \r | |
167 | return false;\r | |
878ddf1f | 168 | }\r |
169 | \r | |
58f1099f | 170 | public boolean isDynamicEx() {\r |
58f1099f | 171 | for (int i = 0; i < supportedPcdType.size(); i++) {\r |
172 | if (supportedPcdType.get(i) == PCD_TYPE.DYNAMIC_EX) {\r | |
173 | return true;\r | |
174 | }\r | |
175 | }\r | |
176 | \r | |
177 | return false;\r | |
178 | }\r | |
179 | \r | |
878ddf1f | 180 | /**\r |
181 | Use "TokencName + "-" + SpaceTokenName" as primary key when adding token into database\r | |
182 | \r | |
183 | @param cName Token name.\r | |
eece174a | 184 | @param tokenSpaceName The token space guid string defined in MSA or SPD\r |
878ddf1f | 185 | \r |
eece174a | 186 | @retval primary key for this token in token database.\r |
878ddf1f | 187 | **/\r |
eece174a | 188 | public static String getPrimaryKeyString(String cName, String tokenSpaceName) {\r |
8840ad58 | 189 | if (tokenSpaceName == null) {\r |
eece174a | 190 | return cName + "_nullTokenSpaceGuid";\r |
878ddf1f | 191 | } else {\r |
8840ad58 | 192 | return cName + "_" + tokenSpaceName.toString().replace('-', '_');\r |
878ddf1f | 193 | }\r |
194 | }\r | |
195 | \r | |
6ff7a41c | 196 | /**\r |
197 | If skudata list contains more than one data, then Sku mechanism is enable.\r | |
198 | \r | |
eece174a | 199 | @retval boolean if the number of sku data exceed to 1\r |
6ff7a41c | 200 | */\r |
201 | public boolean isSkuEnable() {\r | |
202 | if (this.skuData.size() > 1) {\r | |
203 | return true;\r | |
204 | }\r | |
205 | return false;\r | |
206 | }\r | |
eece174a | 207 | \r |
208 | /**\r | |
209 | If Hii type for value of token\r | |
210 | \r | |
211 | @return boolean\r | |
212 | **/\r | |
58f1099f | 213 | public boolean isHiiEnable() {\r |
214 | if (getDefaultSku().type == DynamicTokenValue.VALUE_TYPE.HII_TYPE) {\r | |
215 | return true;\r | |
216 | }\r | |
217 | return false;\r | |
218 | }\r | |
219 | \r | |
eece174a | 220 | /**\r |
221 | If Vpd type for value of token\r | |
222 | \r | |
223 | @return boolean\r | |
224 | **/\r | |
58f1099f | 225 | public boolean isVpdEnable() {\r |
226 | if (getDefaultSku().type == DynamicTokenValue.VALUE_TYPE.VPD_TYPE) {\r | |
227 | return true;\r | |
228 | }\r | |
229 | return false;\r | |
230 | }\r | |
6ff7a41c | 231 | \r |
8840ad58 | 232 | /**\r |
233 | Get the token primary key in token database.\r | |
234 | \r | |
235 | @return String\r | |
236 | */\r | |
32648c62 | 237 | public String getPrimaryKeyString () {\r |
8840ad58 | 238 | return Token.getPrimaryKeyString(cName, tokenSpaceName);\r |
32648c62 | 239 | }\r |
99d2c3c4 | 240 | \r |
878ddf1f | 241 | /**\r |
242 | Judge datumType is valid\r | |
243 | \r | |
244 | @param type The datumType want to be judged.\r | |
245 | \r | |
246 | @retval TRUE - The type is valid.\r | |
247 | @retval FALSE - The type is invalid.\r | |
248 | **/\r | |
249 | public static boolean isValiddatumType(DATUM_TYPE type) {\r | |
250 | if ((type.ordinal() < DATUM_TYPE.UINT8.ordinal() ) || \r | |
251 | (type.ordinal() > DATUM_TYPE.POINTER.ordinal())) {\r | |
252 | return false;\r | |
253 | }\r | |
254 | return true;\r | |
255 | }\r | |
256 | \r | |
257 | /**\r | |
258 | Judge pcdType is valid\r | |
259 | \r | |
260 | @param type The PCdType want to be judged.\r | |
261 | \r | |
262 | @retval TRUE - The type is valid.\r | |
263 | @retval FALSE - The type is invalid.\r | |
264 | **/\r | |
265 | public static boolean isValidpcdType(PCD_TYPE type) {\r | |
266 | if ((type.ordinal() < PCD_TYPE.FEATURE_FLAG.ordinal() ) || \r | |
267 | (type.ordinal() > PCD_TYPE.DYNAMIC_EX.ordinal())) {\r | |
268 | return false;\r | |
269 | }\r | |
270 | return true;\r | |
271 | }\r | |
272 | \r | |
273 | /**\r | |
274 | Add an usage instance for token\r | |
275 | \r | |
276 | @param usageInstance The usage instance\r | |
277 | \r | |
278 | @retval TRUE - Success to add usage instance.\r | |
279 | @retval FALSE - Fail to add usage instance\r | |
280 | **/\r | |
eece174a | 281 | public boolean addUsageInstance(UsageInstance usageInstance) throws EntityException {\r |
8840ad58 | 282 | String exceptionStr;\r |
283 | \r | |
d14ebb43 | 284 | if (isUsageInstanceExist(usageInstance.usageId)) {\r |
eece174a | 285 | exceptionStr = String.format("[PCD Collection Tool Exception] PCD %s for module %s has already exist in database, Please check all PCD build entries "+\r |
286 | "in modules %s in <ModuleSA> to make sure no duplicated definitions in FPD file!",\r | |
8840ad58 | 287 | usageInstance.parentToken.cName,\r |
d14ebb43 | 288 | usageInstance.usageId.moduleName,\r |
289 | usageInstance.usageId.moduleName);\r | |
8840ad58 | 290 | throw new EntityException(exceptionStr);\r |
878ddf1f | 291 | }\r |
292 | \r | |
eece174a | 293 | //\r |
294 | // Put usage instance into usage instance database of this PCD token.\r | |
295 | // \r | |
8840ad58 | 296 | consumers.put(usageInstance.getPrimaryKey(), usageInstance);\r |
eece174a | 297 | \r |
878ddf1f | 298 | return true;\r |
299 | }\r | |
300 | \r | |
301 | /**\r | |
8840ad58 | 302 | Judge whether exist an usage instance for this token\r |
303 | \r | |
d14ebb43 | 304 | @param usageId The UsageInstance identification for usage instance\r |
8840ad58 | 305 | \r |
306 | @return boolean whether exist an usage instance for this token.\r | |
307 | */\r | |
d14ebb43 | 308 | public boolean isUsageInstanceExist(UsageIdentification usageId) {\r |
309 | String keyStr = UsageInstance.getPrimaryKey(usageId);\r | |
eece174a | 310 | \r |
8840ad58 | 311 | return (consumers.get(keyStr) != null);\r |
878ddf1f | 312 | }\r |
313 | \r | |
314 | /**\r | |
315 | Get the PCD_TYPE according to the string of PCD_TYPE\r | |
316 | \r | |
317 | @param pcdTypeStr The string of PCD_TYPE\r | |
318 | \r | |
319 | @return PCD_TYPE\r | |
320 | **/\r | |
321 | public static PCD_TYPE getpcdTypeFromString(String pcdTypeStr) {\r | |
322 | if (pcdTypeStr == null) {\r | |
323 | return PCD_TYPE.UNKNOWN;\r | |
324 | }\r | |
325 | \r | |
326 | if (pcdTypeStr.equalsIgnoreCase("FEATURE_FLAG")) {\r | |
327 | return PCD_TYPE.FEATURE_FLAG;\r | |
328 | } else if (pcdTypeStr.equalsIgnoreCase("FIXED_AT_BUILD")) {\r | |
329 | return PCD_TYPE.FIXED_AT_BUILD;\r | |
330 | } else if (pcdTypeStr.equalsIgnoreCase("PATCHABLE_IN_MODULE")) {\r | |
331 | return PCD_TYPE.PATCHABLE_IN_MODULE;\r | |
332 | } else if (pcdTypeStr.equalsIgnoreCase("DYNAMIC")) {\r | |
333 | return PCD_TYPE.DYNAMIC;\r | |
334 | } else if (pcdTypeStr.equalsIgnoreCase("DYNAMIC_EX")) {\r | |
335 | return PCD_TYPE.DYNAMIC_EX;\r | |
336 | } else {\r | |
337 | return PCD_TYPE.UNKNOWN;\r | |
338 | }\r | |
339 | }\r | |
340 | \r | |
341 | /**\r | |
342 | Get the string of given datumType. This string will be used for generating autogen files\r | |
343 | \r | |
344 | @param datumType Given datumType\r | |
345 | \r | |
346 | @return The string of datum type.\r | |
347 | **/\r | |
348 | public static String getStringOfdatumType(DATUM_TYPE datumType) {\r | |
349 | switch (datumType) {\r | |
350 | case UINT8:\r | |
351 | return "UINT8";\r | |
352 | case UINT16:\r | |
353 | return "UINT16";\r | |
354 | case UINT32:\r | |
355 | return "UINT32";\r | |
356 | case UINT64:\r | |
357 | return "UINT64";\r | |
358 | case POINTER:\r | |
359 | return "POINTER";\r | |
360 | case BOOLEAN:\r | |
361 | return "BOOLEAN";\r | |
362 | }\r | |
363 | return "UNKNOWN";\r | |
364 | }\r | |
365 | \r | |
366 | /**\r | |
367 | Get the datumType according to a string.\r | |
368 | \r | |
369 | @param datumTypeStr The string of datumType\r | |
370 | \r | |
371 | @return DATUM_TYPE\r | |
372 | **/\r | |
373 | public static DATUM_TYPE getdatumTypeFromString(String datumTypeStr) {\r | |
374 | if (datumTypeStr.equalsIgnoreCase("UINT8")) {\r | |
375 | return DATUM_TYPE.UINT8;\r | |
376 | } else if (datumTypeStr.equalsIgnoreCase("UINT16")) {\r | |
377 | return DATUM_TYPE.UINT16;\r | |
378 | } else if (datumTypeStr.equalsIgnoreCase("UINT32")) {\r | |
379 | return DATUM_TYPE.UINT32;\r | |
380 | } else if (datumTypeStr.equalsIgnoreCase("UINT64")) {\r | |
381 | return DATUM_TYPE.UINT64;\r | |
382 | } else if (datumTypeStr.equalsIgnoreCase("VOID*")) {\r | |
383 | return DATUM_TYPE.POINTER;\r | |
384 | } else if (datumTypeStr.equalsIgnoreCase("BOOLEAN")) {\r | |
385 | return DATUM_TYPE.BOOLEAN;\r | |
386 | }\r | |
387 | return DATUM_TYPE.UNKNOWN;\r | |
388 | }\r | |
389 | \r | |
390 | /**\r | |
391 | Get string of given pcdType\r | |
392 | \r | |
393 | @param pcdType The given PcdType\r | |
394 | \r | |
395 | @return The string of PCD_TYPE.\r | |
396 | **/\r | |
397 | public static String getStringOfpcdType(PCD_TYPE pcdType) {\r | |
398 | switch (pcdType) {\r | |
399 | case FEATURE_FLAG:\r | |
400 | return "FEATURE_FLAG";\r | |
401 | case FIXED_AT_BUILD:\r | |
402 | return "FIXED_AT_BUILD";\r | |
403 | case PATCHABLE_IN_MODULE:\r | |
404 | return "PATCHABLE_IN_MODULE";\r | |
405 | case DYNAMIC:\r | |
406 | return "DYNAMIC";\r | |
407 | case DYNAMIC_EX:\r | |
408 | return "DYNAMIC_EX";\r | |
409 | }\r | |
410 | return "UNKNOWN";\r | |
411 | }\r | |
412 | \r | |
413 | /**\r | |
414 | Get the PCD_USAGE according to a string\r | |
415 | \r | |
416 | @param usageStr The string of PCD_USAGE\r | |
417 | \r | |
418 | @return The PCD_USAGE\r | |
419 | **/\r | |
420 | public static PCD_USAGE getUsageFromString(String usageStr) {\r | |
421 | if (usageStr == null) {\r | |
422 | return PCD_USAGE.UNKNOWN;\r | |
423 | }\r | |
424 | \r | |
425 | if (usageStr.equalsIgnoreCase("ALWAYS_PRODUCED")) {\r | |
426 | return PCD_USAGE.ALWAYS_PRODUCED;\r | |
427 | } else if (usageStr.equalsIgnoreCase("SOMETIMES_PRODUCED")) {\r | |
428 | return PCD_USAGE.SOMETIMES_PRODUCED;\r | |
429 | } else if (usageStr.equalsIgnoreCase("ALWAYS_CONSUMED")) {\r | |
430 | return PCD_USAGE.ALWAYS_CONSUMED;\r | |
431 | } else if (usageStr.equalsIgnoreCase("SOMETIMES_CONSUMED")) {\r | |
432 | return PCD_USAGE.SOMETIMES_CONSUMED;\r | |
433 | }\r | |
434 | \r | |
435 | return PCD_USAGE.UNKNOWN;\r | |
436 | }\r | |
437 | \r | |
438 | /**\r | |
439 | Get the string of given PCD_USAGE\r | |
440 | \r | |
441 | @param usage The given PCD_USAGE\r | |
442 | \r | |
443 | @return The string of PDC_USAGE.\r | |
444 | **/\r | |
445 | public static String getStringOfUsage(PCD_USAGE usage) {\r | |
446 | switch (usage) {\r | |
447 | case ALWAYS_PRODUCED:\r | |
448 | return "ALWAYS_PRODUCED";\r | |
449 | case ALWAYS_CONSUMED:\r | |
450 | return "ALWAYS_CONSUMED";\r | |
451 | case SOMETIMES_PRODUCED:\r | |
452 | return "SOMETIMES_PRODUCED";\r | |
453 | case SOMETIMES_CONSUMED:\r | |
454 | return "SOMETIMES_CONSUMED";\r | |
455 | }\r | |
456 | return "UNKNOWN";\r | |
457 | }\r | |
458 | \r | |
459 | /**\r | |
460 | Get the Defined datumType string for autogen. The string is for generating some MACROs in Autogen.h\r | |
461 | \r | |
462 | @param datumType The given datumType\r | |
463 | \r | |
464 | @return string of datum type for autogen.\r | |
465 | **/\r | |
466 | public static String GetAutogenDefinedatumTypeString(DATUM_TYPE datumType) {\r | |
467 | switch (datumType) {\r | |
468 | \r | |
469 | case UINT8:\r | |
470 | return "8";\r | |
471 | case UINT16:\r | |
472 | return "16";\r | |
473 | case BOOLEAN:\r | |
474 | return "BOOL";\r | |
475 | case POINTER:\r | |
476 | return "PTR";\r | |
477 | case UINT32:\r | |
478 | return "32";\r | |
479 | case UINT64:\r | |
480 | return "64";\r | |
481 | default:\r | |
482 | return null;\r | |
483 | }\r | |
484 | }\r | |
485 | \r | |
486 | /**\r | |
487 | Get the datumType String for Autogen. This string will be used for generating defintions of PCD token in autogen\r | |
488 | \r | |
489 | @param datumType The given datumType\r | |
490 | \r | |
491 | @return string of datum type.\r | |
492 | **/\r | |
58f1099f | 493 | \r |
878ddf1f | 494 | public static String getAutogendatumTypeString(DATUM_TYPE datumType) {\r |
495 | switch (datumType) {\r | |
496 | case UINT8:\r | |
497 | return "UINT8";\r | |
498 | case UINT16:\r | |
499 | return "UINT16";\r | |
500 | case UINT32:\r | |
501 | return "UINT32";\r | |
502 | case UINT64:\r | |
503 | return "UINT64";\r | |
504 | case POINTER:\r | |
505 | return "VOID*";\r | |
506 | case BOOLEAN:\r | |
507 | return "BOOLEAN";\r | |
508 | }\r | |
509 | return null;\r | |
510 | }\r | |
511 | \r | |
512 | /**\r | |
513 | Get the datumType string for generating some MACROs in autogen file of Library\r | |
514 | \r | |
515 | @param datumType The given datumType\r | |
516 | \r | |
517 | @return String of datum for genrating bit charater.\r | |
518 | **/\r | |
519 | public static String getAutogenLibrarydatumTypeString(DATUM_TYPE datumType) {\r | |
520 | switch (datumType) {\r | |
521 | case UINT8:\r | |
522 | return "8";\r | |
523 | case UINT16:\r | |
524 | return "16";\r | |
525 | case BOOLEAN:\r | |
526 | return "Bool";\r | |
527 | case POINTER:\r | |
528 | return "Ptr";\r | |
529 | case UINT32:\r | |
530 | return "32";\r | |
531 | case UINT64:\r | |
532 | return "64";\r | |
533 | default:\r | |
534 | return null;\r | |
535 | }\r | |
536 | }\r | |
537 | \r | |
538 | /**\r | |
eece174a | 539 | Get the sku data who id is 0.\r |
540 | \r | |
541 | @retval DynamicTokenValue the value of this dyanmic token.\r | |
878ddf1f | 542 | **/\r |
6ff7a41c | 543 | public DynamicTokenValue getDefaultSku() {\r |
544 | DynamicTokenValue dynamicData;\r | |
545 | int index;\r | |
eece174a | 546 | \r |
6ff7a41c | 547 | for (index = 0; index < this.skuData.size(); index ++) {\r |
548 | if (skuData.get(index).id == 0) {\r | |
549 | return skuData.get(index).value;\r | |
550 | }\r | |
551 | }\r | |
552 | \r | |
553 | return null;\r | |
554 | }\r | |
eece174a | 555 | \r |
556 | /**\r | |
557 | Get the number of Sku data for this token\r | |
558 | \r | |
559 | @retval int the number of sku data\r | |
560 | **/\r | |
58f1099f | 561 | public int getSkuIdCount () {\r |
562 | return this.skuData.size();\r | |
563 | }\r | |
1de04b4f | 564 | \r |
eece174a | 565 | /**\r |
566 | Get the size of PCD value, this PCD is POINTER type.\r | |
567 | \r | |
568 | @param str the string of the value\r | |
569 | @param al \r | |
570 | **/\r | |
1de04b4f | 571 | private void getCurrentSizeFromDefaultValue (String str, ArrayList<Integer> al) {\r |
572 | if (isValidNullValue(str)) {\r | |
573 | al.add(new Integer(0));\r | |
574 | } else {\r | |
575 | //\r | |
576 | // isValidNullValue has already make sure that str here\r | |
577 | // always contain a valid default value of the following 3\r | |
578 | // cases:\r | |
579 | // 1) "Hello world" //Assci string\r | |
580 | // 2) L"Hello" //Unicode string\r | |
581 | // 3) {0x01, 0x02, 0x03} //Byte stream\r | |
582 | //\r | |
583 | if (str.startsWith("\"")) {\r | |
584 | al.add(new Integer(str.length() - 2));\r | |
585 | } else if (str.startsWith("L\"")){\r | |
586 | //\r | |
587 | // Unicode is 2 bytes each.\r | |
588 | //\r | |
589 | al.add(new Integer((str.length() - 3) * 2));\r | |
590 | } else if (str.startsWith("{")) {\r | |
591 | //\r | |
592 | // We count the number of "," in the string.\r | |
593 | // The number of byte is one plus the number of \r | |
594 | // comma.\r | |
595 | //\r | |
596 | String str2 = str;\r | |
597 | \r | |
598 | int cnt = 0;\r | |
599 | int pos = 0;\r | |
600 | pos = str2.indexOf(",", 0);\r | |
601 | while (pos != -1) {\r | |
602 | cnt++;\r | |
603 | pos++;\r | |
604 | pos = str2.indexOf(",", pos);\r | |
605 | }\r | |
606 | cnt++;\r | |
607 | al.add(new Integer(cnt));\r | |
608 | }\r | |
609 | }\r | |
610 | }\r | |
eece174a | 611 | \r |
612 | /**\r | |
613 | This method can be used to get the MAX and current size\r | |
614 | for pointer type dynamic(ex) PCD entry\r | |
615 | **/ \r | |
1de04b4f | 616 | public ArrayList<Integer> getPointerTypeSize () {\r |
617 | ArrayList<Integer> al = new ArrayList<Integer>();\r | |
618 | \r | |
619 | //\r | |
620 | // For VPD_enabled and HII_enabled, we can only return the MAX size.\r | |
621 | // For the default DATA type dynamic PCD entry, we will return\r | |
622 | // the MAX size and current size for each SKU_ID.\r | |
623 | //\r | |
624 | al.add(new Integer(this.datumSize));\r | |
625 | \r | |
626 | if (!this.isVpdEnable()) {\r | |
627 | int idx;\r | |
628 | if (this.isHiiEnable()){\r | |
629 | for (idx = 0; idx < this.skuData.size(); idx++) {\r | |
630 | String str = this.skuData.get(idx).value.hiiDefaultValue;\r | |
631 | getCurrentSizeFromDefaultValue(str, al);\r | |
632 | }\r | |
633 | } else {\r | |
634 | for (idx = 0; idx < this.skuData.size(); idx++) {\r | |
635 | String str = this.skuData.get(idx).value.value;\r | |
636 | getCurrentSizeFromDefaultValue(str, al);\r | |
637 | }\r | |
638 | }\r | |
639 | }\r | |
640 | \r | |
641 | return al;\r | |
642 | }\r | |
f63ef4b2 | 643 | \r |
644 | /**\r | |
645 | Get default value for a token, For HII type, HiiDefaultValue of default\r | |
646 | SKU 0 will be returned; For Default type, the defaultvalue of default SKU\r | |
647 | 0 will be returned.\r | |
648 | \r | |
649 | @return String\r | |
650 | */\r | |
651 | public String getDynamicDefaultValue() {\r | |
652 | DynamicTokenValue dynamicData = getDefaultSku();\r | |
653 | if (hasDefaultValue()) {\r | |
654 | switch (dynamicData.type) {\r | |
f63ef4b2 | 655 | case DEFAULT_TYPE:\r |
656 | return dynamicData.value;\r | |
657 | }\r | |
658 | }\r | |
659 | \r | |
660 | return null;\r | |
661 | }\r | |
662 | \r | |
99d2c3c4 | 663 | //\r |
664 | // BugBug: We need change this algorithm accordingly when schema is updated\r | |
665 | // to support no default value.\r | |
666 | //\r | |
667 | public boolean hasDefaultValue () {\r | |
6ff7a41c | 668 | int value = 0;\r |
669 | boolean isInteger = true;\r | |
670 | DynamicTokenValue dynamicValue = null;\r | |
671 | \r | |
58f1099f | 672 | if (isSkuEnable()) {\r |
673 | return true;\r | |
674 | }\r | |
675 | \r | |
6ff7a41c | 676 | if (this.isDynamicPCD) {\r |
677 | dynamicValue = getDefaultSku();\r | |
678 | switch (dynamicValue.type) {\r | |
679 | case HII_TYPE:\r | |
58f1099f | 680 | return true;\r |
6ff7a41c | 681 | case VPD_TYPE:\r |
58f1099f | 682 | return true;\r |
6ff7a41c | 683 | case DEFAULT_TYPE:\r |
6f7e61a0 | 684 | return !isValidNullValue(dynamicValue.value);\r |
685 | }\r | |
686 | }\r | |
687 | \r | |
688 | return false;\r | |
689 | }\r | |
6ff7a41c | 690 | \r |
eece174a | 691 | /**\r |
692 | Judge the value is NULL value. NULL value means the value is uninitialized value\r | |
693 | \r | |
694 | @param judgedValue\r | |
695 | \r | |
696 | @return boolean\r | |
697 | */\r | |
6f7e61a0 | 698 | public boolean isValidNullValue(String judgedValue) {\r |
e59cdca8 | 699 | String subStr;\r |
6f7e61a0 | 700 | BigInteger bigIntValue;\r |
701 | \r | |
702 | switch (datumType) {\r | |
703 | case UINT8:\r | |
704 | case UINT16:\r | |
705 | case UINT32:\r | |
e59cdca8 | 706 | if (judgedValue.length() > 2) {\r |
707 | if ((judgedValue.charAt(0) == '0') && \r | |
708 | ((judgedValue.charAt(1) == 'x') || (judgedValue.charAt(1) == 'X'))){\r | |
709 | subStr = judgedValue.substring(2, judgedValue.length());\r | |
710 | bigIntValue = new BigInteger(subStr, 16);\r | |
711 | } else {\r | |
712 | bigIntValue = new BigInteger(judgedValue);\r | |
713 | }\r | |
714 | } else {\r | |
715 | bigIntValue = new BigInteger(judgedValue);\r | |
716 | }\r | |
717 | if (bigIntValue.bitCount() == 0) {\r | |
6f7e61a0 | 718 | return true;\r |
719 | }\r | |
720 | break;\r | |
721 | case UINT64:\r | |
722 | if (judgedValue.length() > 2){\r | |
723 | if ((judgedValue.charAt(0) == '0') && \r | |
724 | ((judgedValue.charAt(1) == 'x') ||\r | |
725 | (judgedValue.charAt(1) == 'X'))) {\r | |
726 | bigIntValue = new BigInteger(judgedValue.substring(2, judgedValue.length()), 16);\r | |
727 | if (bigIntValue.bitCount() == 0) {\r | |
728 | return true;\r | |
729 | }\r | |
6ff7a41c | 730 | } else {\r |
6f7e61a0 | 731 | bigIntValue = new BigInteger(judgedValue);\r |
732 | if (bigIntValue.bitCount() == 0) {\r | |
733 | return true;\r | |
734 | }\r | |
735 | }\r | |
736 | } else {\r | |
737 | bigIntValue = new BigInteger(judgedValue);\r | |
738 | if (bigIntValue.bitCount() == 0) {\r | |
6ff7a41c | 739 | return true;\r |
740 | }\r | |
6f7e61a0 | 741 | }\r |
742 | break;\r | |
743 | case BOOLEAN:\r | |
744 | if (judgedValue.equalsIgnoreCase("false")) {\r | |
745 | return true;\r | |
746 | }\r | |
747 | break;\r | |
748 | case POINTER:\r | |
749 | if (judgedValue.equalsIgnoreCase("") ||\r | |
750 | judgedValue.equalsIgnoreCase("\"\"") ||\r | |
751 | judgedValue.equalsIgnoreCase("L\"\"") ||\r | |
752 | (judgedValue.length() == 0) ||\r | |
ddb87685 | 753 | judgedValue.equalsIgnoreCase("{0}")) {\r |
6f7e61a0 | 754 | return true;\r |
6ff7a41c | 755 | }\r |
32648c62 | 756 | }\r |
6ff7a41c | 757 | return false;\r |
99d2c3c4 | 758 | }\r |
eece174a | 759 | \r |
760 | /**\r | |
761 | Is the string value in Unicode\r | |
762 | \r | |
763 | @return boolean\r | |
764 | **/\r | |
bb5545b6 | 765 | public boolean isHiiDefaultValueUnicodeStringType() {\r |
766 | DynamicTokenValue dynamicData = getDefaultSku();\r | |
767 | \r | |
768 | if (dynamicData == null)\r | |
769 | return false;\r | |
770 | \r | |
771 | return dynamicData.hiiDefaultValue.startsWith("L\"")\r | |
772 | && dynamicData.hiiDefaultValue.endsWith("\"");\r | |
773 | }\r | |
eece174a | 774 | \r |
775 | /**\r | |
776 | Is the string value in ANSCI\r | |
777 | \r | |
778 | @return boolean\r | |
779 | **/\r | |
bb5545b6 | 780 | public boolean isHiiDefaultValueASCIIStringType() {\r |
781 | DynamicTokenValue dynamicData = getDefaultSku();\r | |
782 | \r | |
783 | if (dynamicData == null)\r | |
784 | return false;\r | |
785 | \r | |
786 | return dynamicData.hiiDefaultValue.startsWith("\"")\r | |
787 | && dynamicData.hiiDefaultValue.endsWith("\"");\r | |
788 | }\r | |
789 | \r | |
f63ef4b2 | 790 | /**\r |
791 | Judege whether current value is UNICODE string type.\r | |
792 | @return boolean\r | |
793 | */\r | |
794 | public boolean isUnicodeStringType () {\r | |
795 | String str = getDynamicDefaultValue();\r | |
796 | \r | |
797 | if (str == null) {\r | |
798 | return false;\r | |
799 | }\r | |
99d2c3c4 | 800 | \r |
f63ef4b2 | 801 | if (datumType == Token.DATUM_TYPE.POINTER &&\r |
802 | str.startsWith("L\"") && \r | |
803 | str.endsWith("\"")) {\r | |
32648c62 | 804 | return true;\r |
805 | }\r | |
99d2c3c4 | 806 | \r |
32648c62 | 807 | return false;\r |
808 | }\r | |
4276d5da | 809 | \r |
3534cbb7 | 810 | public boolean isASCIIStringType () {\r |
811 | String str = getDynamicDefaultValue();\r | |
812 | \r | |
813 | if (str == null) {\r | |
814 | return false;\r | |
815 | }\r | |
816 | \r | |
817 | if (datumType == Token.DATUM_TYPE.POINTER &&\r | |
818 | str.startsWith("\"") && \r | |
819 | str.endsWith("\"")) {\r | |
820 | return true;\r | |
821 | }\r | |
822 | \r | |
823 | return false;\r | |
824 | }\r | |
825 | \r | |
4276d5da | 826 | public boolean isByteStreamType () {\r |
827 | String str = getDynamicDefaultValue();\r | |
828 | \r | |
829 | if (str == null) {\r | |
830 | return false;\r | |
831 | }\r | |
832 | \r | |
833 | if (datumType == Token.DATUM_TYPE.POINTER &&\r | |
834 | str.startsWith("{") && \r | |
835 | str.endsWith("}")) {\r | |
836 | return true;\r | |
837 | }\r | |
838 | \r | |
839 | return false;\r | |
840 | \r | |
841 | }\r | |
99d2c3c4 | 842 | \r |
32648c62 | 843 | public String getStringTypeString () { \r |
6ff7a41c | 844 | return getDefaultSku().value.substring(2, getDefaultSku().value.length() - 1);\r |
32648c62 | 845 | }\r |
878ddf1f | 846 | }\r |
847 | \r | |
848 | \r | |
849 | \r | |
850 | \r |