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