import java.util.ArrayList;\r
import java.util.List;\r
import java.util.UUID;\r
+import java.util.Map;\r
+import java.util.HashMap;\r
\r
import org.tianocore.build.pcd.action.ActionMessage;\r
+import org.tianocore.build.pcd.exception.EntityException;\r
\r
/** This class is to descript a PCD token object. The information of a token mainly \r
comes from MSA, SPD and setting produced by platform developer. \r
///\r
public int tokenNumber;\r
\r
- ///\r
- /// The token space name assigned by platform. For Non-DynamicEx driver this value is same.\r
- /// assignedtokenSpaceName is defined in FPD.\r
- ///\r
- public UUID assignedtokenSpaceName;\r
-\r
- ///\r
- /// The token number assigned by platform. The number indiect the offset of this token in platform\r
- /// token space.\r
- /// AssgiendtokenNumber is defined in FPD.\r
- ///\r
- public int assignedtokenNumber;\r
-\r
///\r
/// pcdType is the PCD item type defined by platform developer.\r
///\r
public PCD_TYPE pcdType;\r
\r
- ///\r
- /// PCDtype is set by platform developer. It is final PCD type of this token.\r
- /// SupportedPcdType is defined in SPD.\r
- ///\r
- public PCD_TYPE[] supportedpcdType;\r
-\r
///\r
/// datumSize is to descript the fix size or max size for this token. \r
/// datumSize is defined in SPD.\r
///\r
public DATUM_TYPE datumType;\r
\r
- ///\r
- /// Isplatform is to descript whether this token is defined in platform level.\r
- /// If token is belong to platform level. The value can be different for every\r
- /// module. All are determined by platform developer.\r
- ///\r
- public boolean isPlatform;\r
-\r
///\r
/// hiiEnabled is to indicate whether the token support Hii functionality.\r
/// hiiEnabled is defined in FPD.\r
///\r
public boolean skuEnabled;\r
\r
- ///\r
- /// skuDataArrayEnabled is to indicate wheter use the skuData array or default value.\r
- ///\r
- public boolean skuDataArrayEnabled;\r
-\r
///\r
/// skuData contains all value for SkuNumber of token.\r
/// skuData is defined in FPD.\r
///\r
public Object datum;\r
\r
- ///\r
- /// Default value of this token.\r
- /// This default value is defined in SPD level.\r
- ///\r
- public Object defaultValue;\r
-\r
///\r
/// BUGBUG: fix comment\r
/// vpdEnabled is defined in FPD.\r
///\r
public long vpdOffset;\r
\r
- ///\r
- /// producers array record all module private information who produce this PCD token.\r
- ///\r
- public List<UsageInstance> producers;\r
-\r
///\r
/// consumers array record all module private information who consume this PCD token.\r
///\r
- public List<UsageInstance> consumers;\r
+ public Map<String, UsageInstance> consumers;\r
\r
- /**\r
- Constructure function.\r
- \r
- Initialize the value of token.\r
- \r
- @param cName The cName of this token\r
- @param tokenSpaceName The tokenSpaceName of this token, it is a GUID.\r
- @param assignedtokenSpaceName The assignedtokenSpaceName of this token, it is a GUID.\r
- \r
- **/ \r
- public Token(String cName, UUID tokenSpaceName, UUID assignedtokenSpaceName) {\r
+ public Token(String cName, UUID tokenSpaceName) {\r
UUID nullUUID = new UUID(0, 0);\r
\r
this.cName = cName;\r
- this.tokenSpaceName =(tokenSpaceName == null) ? nullUUID : tokenSpaceName;\r
- this.assignedtokenSpaceName =(assignedtokenSpaceName == null) ? nullUUID : assignedtokenSpaceName;\r
+ this.tokenSpaceName = (tokenSpaceName == null) ? nullUUID : tokenSpaceName;\r
this.tokenNumber = 0;\r
- this.assignedtokenNumber = 0;\r
this.pcdType = PCD_TYPE.UNKNOWN;\r
- this.supportedpcdType = null;\r
- this.isPlatform = false;\r
this.datumType = DATUM_TYPE.UNKNOWN;\r
this.datumSize = -1;\r
- this.defaultValue = null;\r
this.datum = null;\r
this.hiiEnabled = false;\r
this.variableGuid = null;\r
this.variableName = "";\r
this.variableOffset = -1;\r
this.skuEnabled = false;\r
- this.skuDataArrayEnabled = false;\r
this.skuId = -1;\r
this.maxSkuCount = -1;\r
this.skuData = new ArrayList<SkuInstance>();\r
this.vpdEnabled = false;\r
this.vpdOffset = -1;\r
\r
- this.producers = new ArrayList<UsageInstance>();\r
- this.consumers = new ArrayList<UsageInstance>();\r
+ this.consumers = new HashMap<String, UsageInstance>();\r
}\r
\r
/**\r
\r
@return primary key for this token in token database.\r
**/\r
- public static String getPrimaryKeyString(String cName, UUID tokenSpaceName, \r
- UUID platformtokenSpaceName) {\r
+ public static String getPrimaryKeyString(String cName, UUID tokenSpaceName) {\r
UUID nullUUID = new UUID(0, 0);\r
\r
- if (platformtokenSpaceName == nullUUID) {\r
- return cName + "_" + tokenSpaceName.toString().replace('-', '_');\r
+ if (tokenSpaceName == null) {\r
+ return cName + "_" + nullUUID.toString().replace('-', '_');\r
} else {\r
- return cName + "_" + platformtokenSpaceName.toString().replace('-', '_');\r
+ return cName + "_" + tokenSpaceName.toString().replace('-', '_');\r
}\r
}\r
\r
+ /**\r
+ Get the token primary key in token database.\r
+ \r
+ @return String\r
+ */\r
public String getPrimaryKeyString () {\r
- return cName + "_" + tokenSpaceName.toString().replace('-', '_');\r
+ return Token.getPrimaryKeyString(cName, tokenSpaceName);\r
}\r
\r
/**\r
@retval TRUE - Success to add usage instance.\r
@retval FALSE - Fail to add usage instance\r
**/\r
- public boolean addUsageInstance(UsageInstance usageInstance) {\r
- if (usageInstance.usage == PCD_USAGE.UNKNOWN) {\r
- return false;\r
+ public boolean addUsageInstance(UsageInstance usageInstance) \r
+ throws EntityException {\r
+ String exceptionStr;\r
+\r
+ if (isUsageInstanceExist(usageInstance.moduleName,\r
+ usageInstance.moduleGUID,\r
+ usageInstance.packageName,\r
+ usageInstance.packageGUID,\r
+ usageInstance.arch,\r
+ usageInstance.version)) {\r
+ exceptionStr = String.format("PCD %s for module %s has already exist in database, Please check all PCD build entries "+\r
+ "in modules PcdPeim in <ModuleSA> to make sure no duplicated definitions!",\r
+ usageInstance.parentToken.cName,\r
+ usageInstance.moduleName);\r
+ throw new EntityException(exceptionStr);\r
}\r
\r
- if ((usageInstance.usage == PCD_USAGE.ALWAYS_PRODUCED) ||\r
- (usageInstance.usage == PCD_USAGE.SOMETIMES_PRODUCED)) {\r
- producers.add(usageInstance);\r
- } else {\r
- consumers.add(usageInstance);\r
- }\r
+ consumers.put(usageInstance.getPrimaryKey(), usageInstance);\r
return true;\r
}\r
\r
/**\r
- Judge whether exist an usage instance for this token\r
- \r
- @param moduleName Use xmlFilePath as keyword to search the usage instance\r
- \r
- @retval PCD_USAGE - if UsageInstance exists.\r
- @retval UNKNOWN - if UsageInstance does not exist, return UNKONW.\r
- **/\r
- public PCD_USAGE isUsageInstanceExist(String moduleName) {\r
- int index;\r
- UsageInstance usageInstance;\r
-\r
- if (moduleName == null) {\r
- ActionMessage.warning(this, "Error parameter for isUsageInstanceExist() function!");\r
- return PCD_USAGE.UNKNOWN;\r
- }\r
-\r
- if (moduleName.length() == 0) {\r
- return PCD_USAGE.UNKNOWN;\r
- }\r
-\r
- //\r
- // Searching the usage instance in module's producer and consumer according to \r
- // module's name.\r
- //\r
- for (index = 0; index < producers.size(); index ++) {\r
- usageInstance =(UsageInstance)producers.get(index);\r
- if (usageInstance.moduleName.equalsIgnoreCase(moduleName)) {\r
- return usageInstance.usage;\r
- }\r
- }\r
-\r
- for (index = 0; index < consumers.size(); index ++) {\r
- usageInstance =(UsageInstance)consumers.get(index);\r
- if (usageInstance.moduleName.equalsIgnoreCase(moduleName)) {\r
- return usageInstance.usage;\r
- }\r
- }\r
- return PCD_USAGE.UNKNOWN;\r
- }\r
-\r
- /**\r
- Get usage instance according to a MSA file name\r
- \r
- @param moduleName The file path string of MSA file.\r
-\r
- @return usage instance object.\r
- **/\r
- public UsageInstance getUsageInstance(String moduleName) {\r
- int usageIndex;\r
- UsageInstance usageInstance;\r
-\r
- if (moduleName == null) {\r
- ActionMessage.warning(this, "Error parameter for isUsageInstanceExist() function!");\r
- return null;\r
- }\r
-\r
- if (moduleName.length() == 0) {\r
- return null;\r
- }\r
-\r
- if (producers.size() != 0) {\r
- for (usageIndex = 0; usageIndex < producers.size(); usageIndex ++) {\r
- usageInstance =(UsageInstance)producers.get(usageIndex);\r
- if (usageInstance.moduleName.equalsIgnoreCase(moduleName)) {\r
- return usageInstance;\r
- }\r
- }\r
- }\r
-\r
- if (consumers.size() != 0) {\r
- for (usageIndex = 0; usageIndex < consumers.size(); usageIndex ++) {\r
- usageInstance =(UsageInstance)consumers.get(usageIndex);\r
- if (usageInstance.moduleName.equalsIgnoreCase(moduleName)) {\r
- return usageInstance;\r
- }\r
- }\r
- }\r
- return null;\r
+ Judge whether exist an usage instance for this token\r
+ \r
+ @param moduleName the name of module\r
+ @param moduleGuid the GUID name of modules\r
+ @param packageName the name of package contains this module\r
+ @param packageGuid the GUID name of package contains this module\r
+ @param arch the architecture string\r
+ @param version the version string\r
+ \r
+ @return boolean whether exist an usage instance for this token.\r
+ */\r
+ public boolean isUsageInstanceExist(String moduleName,\r
+ UUID moduleGuid,\r
+ String packageName,\r
+ UUID packageGuid,\r
+ String arch,\r
+ String version) {\r
+ String keyStr = UsageInstance.getPrimaryKey(moduleName, \r
+ moduleGuid, \r
+ packageName, \r
+ packageGuid, \r
+ arch, \r
+ version);\r
+ return (consumers.get(keyStr) != null);\r
}\r
\r
/**\r