]> git.proxmox.com Git - mirror_edk2.git/blobdiff - Tools/Source/GenBuild/org/tianocore/build/pcd/entity/Token.java
Modify PCD tool according to final PCD schema modification.
[mirror_edk2.git] / Tools / Source / GenBuild / org / tianocore / build / pcd / entity / Token.java
index 3136864872a7559034622b6f7d437297b2fe6725..62e2be5cc969a80911e94d83b78a8cb9a7a11138 100644 (file)
@@ -70,9 +70,16 @@ public class Token {
     public int              tokenNumber;\r
 \r
     ///\r
-    /// pcdType is the PCD item type defined by platform developer.\r
+    /// All supported PCD type, this value can be retrieved from SPD\r
+    /// Currently, only record all PCD type for this token in FPD file.\r
+    /// \r
+    public List<PCD_TYPE>   supportedPcdType;\r
+\r
     ///\r
-    public PCD_TYPE         pcdType;\r
+    /// If the token's item type is Dynamic or DynamicEx type, isDynamicPCD\r
+    /// is true.\r
+    /// \r
+    public boolean          isDynamicPCD;\r
 \r
     ///\r
     /// datumSize is to descript the fix size or max size for this token. \r
@@ -82,77 +89,17 @@ public class Token {
 \r
     ///\r
     /// datum type is to descript what type can be expressed by a PCD token.\r
-    /// datumType is defined in SPD.\r
+    /// For same PCD used in different module, the datum type should be unique.\r
+    /// So it belong memeber to Token class.\r
     ///\r
     public DATUM_TYPE       datumType;\r
 \r
-    ///\r
-    /// hiiEnabled is to indicate whether the token support Hii functionality.\r
-    /// hiiEnabled is defined in FPD.\r
-    ///\r
-    public boolean          hiiEnabled;\r
-\r
-    ///\r
-    /// variableName is valid only when this token support Hii functionality. variableName\r
-    /// indicates the value of token is associated with what variable.\r
-    /// variableName is defined in FPD.\r
-    ///\r
-    public String           variableName;\r
-\r
-    ///\r
-    /// variableGuid is the GUID this token associated with.\r
-    /// variableGuid is defined in FPD.\r
-    ///\r
-    public UUID             variableGuid;\r
-\r
-    ///\r
-    /// Variable offset indicate the associated variable's offset in NV storage.\r
-    /// variableOffset is defined in FPD.\r
-    ///\r
-    public int              variableOffset;\r
-\r
-    ///\r
-    /// skuEnabled is to indicate whether the token support Sku functionality.\r
-    /// skuEnabled is defined in FPD.\r
-    ///\r
-    public boolean          skuEnabled;\r
-\r
     ///\r
     /// skuData contains all value for SkuNumber of token.\r
-    /// skuData is defined in FPD.\r
+    /// This field is for Dynamic or DynamicEx type PCD, \r
     ///\r
     public List<SkuInstance> skuData;\r
 \r
-    ///\r
-    /// maxSkuCount indicate the max count of sku data.\r
-    /// maxSkuCount is defined in FPD.\r
-    ///\r
-    public int              maxSkuCount;\r
-\r
-    ///\r
-    /// SkuId is the id of current selected SKU.\r
-    /// SkuId is defined in FPD.\r
-    ///\r
-    public int              skuId;\r
-\r
-    ///\r
-    /// datum is the value set by platform developer.\r
-    /// datum is defined in FPD.\r
-    ///\r
-    public Object           datum;\r
-\r
-    ///\r
-    /// BUGBUG: fix comment\r
-    /// vpdEnabled is defined in FPD.\r
-    ///\r
-    public boolean          vpdEnabled;\r
-\r
-    ///\r
-    /// BUGBUG: fix comment\r
-    /// vpdOffset is defined in FPD.\r
-    ///\r
-    public long             vpdOffset;\r
-\r
     ///\r
     /// consumers array record all module private information who consume this PCD token.\r
     ///\r
@@ -164,22 +111,51 @@ public class Token {
         this.cName                  = cName;\r
         this.tokenSpaceName         = (tokenSpaceName == null) ? nullUUID : tokenSpaceName;\r
         this.tokenNumber            = 0;\r
-        this.pcdType                = PCD_TYPE.UNKNOWN;\r
         this.datumType              = DATUM_TYPE.UNKNOWN;\r
         this.datumSize              = -1;\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.skuId                  = -1;\r
-        this.maxSkuCount            = -1;\r
         this.skuData                = new ArrayList<SkuInstance>();\r
-        this.vpdEnabled             = false;\r
-        this.vpdOffset              = -1;\r
 \r
         this.consumers              = new HashMap<String, UsageInstance>();\r
+        this.supportedPcdType       = new ArrayList<PCD_TYPE>();\r
+    }\r
+\r
+    /**\r
+      updateSupportPcdType\r
+      \r
+      SupportPcdType should be gotten from SPD file actually, but now it just\r
+      record all PCD type for this token in FPD file.\r
+      \r
+      @param pcdType    new PCD type found in FPD file for this token.\r
+    **/\r
+    public void updateSupportPcdType(PCD_TYPE pcdType) {\r
+        int     index = 0;\r
+        boolean found = false;\r
+        for (index = 0; index < this.supportedPcdType.size(); index ++) {\r
+            if (this.supportedPcdType.get(index) == pcdType) {\r
+                found = true;\r
+                break;\r
+            }\r
+        }\r
+        if (!found) {\r
+            this.supportedPcdType.add(pcdType);\r
+        }\r
+    }\r
+\r
+    /**\r
+       Judge whether pcdType is belong to dynamic type. Dynamic type includes\r
+       DYNAMIC and DYNAMIC_EX.\r
+       \r
+       @param pcdType\r
+       \r
+       @return boolean\r
+     */\r
+    public static boolean isDynamic(PCD_TYPE pcdType) {\r
+        if ((pcdType == PCD_TYPE.DYNAMIC   ) ||\r
+            (pcdType == PCD_TYPE.DYNAMIC_EX)) {\r
+            return true;\r
+        }\r
+\r
+        return false;\r
     }\r
 \r
     /**\r
@@ -201,6 +177,18 @@ public class Token {
         }\r
     }\r
 \r
+    /**\r
+       If skudata list contains more than one data, then Sku mechanism is enable.\r
+       \r
+       @return boolean\r
+     */\r
+    public boolean isSkuEnable() {\r
+        if (this.skuData.size() > 1) {\r
+            return true;\r
+        }\r
+        return false;\r
+    }\r
+\r
     /**\r
        Get the token primary key in token database.\r
        \r
@@ -540,29 +528,69 @@ public class Token {
         return uuid;\r
     }\r
 \r
+    public DynamicTokenValue getDefaultSku() {\r
+        DynamicTokenValue dynamicData;\r
+        int               index;\r
+        for (index = 0; index < this.skuData.size(); index ++) {\r
+            if (skuData.get(index).id == 0) {\r
+                return skuData.get(index).value;\r
+            }\r
+        }\r
+\r
+        return null;\r
+    }\r
     //\r
     // BugBug: We need change this algorithm accordingly when schema is updated\r
     //          to support no default value.\r
     //\r
     public boolean hasDefaultValue () {\r
-\r
-        if (hiiEnabled) {\r
-            return true;\r
+        int               value         = 0;\r
+        boolean           isInteger     = true;\r
+        DynamicTokenValue dynamicValue  = null;\r
+\r
+        if (this.isDynamicPCD) {\r
+            dynamicValue = getDefaultSku();\r
+            switch (dynamicValue.type) {\r
+            case HII_TYPE:\r
+                try {\r
+                    value = Integer.decode(dynamicValue.hiiDefaultValue);\r
+                } catch (NumberFormatException nfEx) {\r
+                    isInteger = false;\r
+                }\r
+                \r
+                if (isInteger && (value == 0)) {\r
+                    return false;\r
+                } else {\r
+                    return true;\r
+                }\r
+\r
+            case VPD_TYPE:\r
+                return false;\r
+\r
+            case DEFAULT_TYPE:\r
+                try{\r
+                    value = Integer.decode(dynamicValue.value);\r
+                } catch (NumberFormatException nfEx) {\r
+                    isInteger = false;\r
+                }\r
+\r
+                if (isInteger && (value == 0)) {\r
+                    return false;\r
+                } else {\r
+                    return true;\r
+                }\r
+\r
+            }\r
         }\r
 \r
-        if (vpdEnabled) {\r
-            return true;\r
-        }\r
-\r
-        if (datum.toString().compareTo("NoDefault") == 0) {\r
-            return false;\r
-        }\r
-\r
-        return true;\r
+        return false;\r
     }\r
 \r
+    //\r
+    // TODO: Need scott's confirmation\r
+    // \r
     public boolean isStringType () {\r
-        String str = datum.toString();\r
+        String str = getDefaultSku().value;\r
 \r
         if (datumType == Token.DATUM_TYPE.POINTER &&\r
             str.startsWith("L\"") && \r
@@ -574,7 +602,7 @@ public class Token {
     }\r
 \r
     public String getStringTypeString () {                       \r
-        return datum.toString().substring(2, datum.toString().length() - 1);\r
+        return getDefaultSku().value.substring(2, getDefaultSku().value.length() - 1);\r
     }\r
 }\r
 \r