]>
Commit | Line | Data |
---|---|---|
1 | /** @file\r | |
2 | UsageInstance class.\r | |
3 | \r | |
4 | This class indicate an usage instance for a PCD token. This instance maybe a module\r | |
5 | or platform setting. When a module produce or cosume a PCD token, then this module\r | |
6 | is an usage instance for this PCD token.\r | |
7 | \r | |
8 | Copyright (c) 2006, Intel Corporation\r | |
9 | All rights reserved. This program and the accompanying materials\r | |
10 | are licensed and made available under the terms and conditions of the BSD License\r | |
11 | which accompanies this distribution. The full text of the license may be found at\r | |
12 | http://opensource.org/licenses/bsd-license.php\r | |
13 | \r | |
14 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
15 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
16 | \r | |
17 | **/ \r | |
18 | package org.tianocore.build.pcd.entity;\r | |
19 | \r | |
20 | \r | |
21 | import java.util.UUID;\r | |
22 | \r | |
23 | import org.tianocore.build.autogen.CommonDefinition;\r | |
24 | import org.tianocore.build.pcd.action.ActionMessage;\r | |
25 | import org.tianocore.build.pcd.exception.EntityException;\r | |
26 | \r | |
27 | /**\r | |
28 | This class indicate an usage instance for a PCD token. This instance maybe a module\r | |
29 | or platform setting. When a module produce or cosume a PCD token, then this module\r | |
30 | is an usage instance for this PCD token.\r | |
31 | **/\r | |
32 | public class UsageInstance {\r | |
33 | ///\r | |
34 | /// The module type of usage instance.\r | |
35 | /// \r | |
36 | public enum MODULE_TYPE {SEC, PEI_CORE, PEIM, DXE_CORE, DXE_DRIVERS, OTHER_COMPONENTS}\r | |
37 | \r | |
38 | ///\r | |
39 | /// This parent that this usage instance belongs to.\r | |
40 | ///\r | |
41 | public Token parentToken;\r | |
42 | \r | |
43 | ///\r | |
44 | /// The name of the module who contains this PCD.\r | |
45 | ///\r | |
46 | public String moduleName;\r | |
47 | \r | |
48 | ///\r | |
49 | /// The GUID of the module who contains this PCD. \r | |
50 | /// \r | |
51 | public UUID moduleGUID;\r | |
52 | \r | |
53 | ///\r | |
54 | /// The name of the package whose module contains this PCD.\r | |
55 | ///\r | |
56 | public String packageName;\r | |
57 | \r | |
58 | ///\r | |
59 | /// The GUID of the package whose module contains this PCD.\r | |
60 | /// \r | |
61 | public UUID packageGUID;\r | |
62 | \r | |
63 | ///\r | |
64 | /// The PCD type defined for module \r | |
65 | /// \r | |
66 | public Token.PCD_TYPE modulePcdType;\r | |
67 | \r | |
68 | ///\r | |
69 | /// The arch string of module contains this PCD\r | |
70 | ///\r | |
71 | public String arch;\r | |
72 | \r | |
73 | ///\r | |
74 | /// The version of module contains this PCD\r | |
75 | /// \r | |
76 | public String version;\r | |
77 | \r | |
78 | ///\r | |
79 | /// The module type for this usage instance.\r | |
80 | ///\r | |
81 | public MODULE_TYPE moduleType;\r | |
82 | \r | |
83 | ///\r | |
84 | /// The value of the PCD in this usage instance. \r | |
85 | /// \r | |
86 | public String datum;\r | |
87 | \r | |
88 | ///\r | |
89 | /// The maxDatumSize could be different for same PCD in different module\r | |
90 | /// But this case is allow for FeatureFlag, FixedAtBuild, PatchableInModule\r | |
91 | /// type.\r | |
92 | /// \r | |
93 | public int maxDatumSize;\r | |
94 | \r | |
95 | ///\r | |
96 | /// Autogen string for header file.\r | |
97 | ///\r | |
98 | public String hAutogenStr;\r | |
99 | \r | |
100 | ///\r | |
101 | /// Auotgen string for C code file.\r | |
102 | /// \r | |
103 | public String cAutogenStr;\r | |
104 | \r | |
105 | /**\r | |
106 | Constructure function\r | |
107 | \r | |
108 | @param parentToken Member variable.\r | |
109 | @param moduleName Member variable.\r | |
110 | @param moduleGUID Member variable.\r | |
111 | @param packageName Member variable.\r | |
112 | @param packageGUID Member variable.\r | |
113 | @param moduleType Member variable.\r | |
114 | @param modulePcdType Member variable.\r | |
115 | @param arch Member variable.\r | |
116 | @param version Member variable.\r | |
117 | @param value Member variable.\r | |
118 | @param maxDatumSize Member variable.\r | |
119 | */\r | |
120 | public UsageInstance (Token parentToken,\r | |
121 | String moduleName,\r | |
122 | UUID moduleGUID,\r | |
123 | String packageName,\r | |
124 | UUID packageGUID,\r | |
125 | MODULE_TYPE moduleType,\r | |
126 | Token.PCD_TYPE modulePcdType,\r | |
127 | String arch,\r | |
128 | String version,\r | |
129 | String value,\r | |
130 | int maxDatumSize) {\r | |
131 | this.parentToken = parentToken;\r | |
132 | this.moduleName = moduleName;\r | |
133 | this.moduleGUID = moduleGUID;\r | |
134 | this.packageName = packageName;\r | |
135 | this.packageGUID = packageGUID;\r | |
136 | this.moduleType = moduleType;\r | |
137 | this.modulePcdType = modulePcdType;\r | |
138 | this.arch = arch;\r | |
139 | this.version = version;\r | |
140 | this.datum = value;\r | |
141 | this.maxDatumSize = maxDatumSize;\r | |
142 | }\r | |
143 | \r | |
144 | /**\r | |
145 | Get the primary key for usage instance array for every token.\r | |
146 | \r | |
147 | @param moduleName the name of module\r | |
148 | @param moduleGUID the GUID name of module\r | |
149 | @param packageName the name of package who contains this module\r | |
150 | @param packageGUID the GUID name of package\r | |
151 | @param arch the archtecture string\r | |
152 | @param version the version of this module\r | |
153 | \r | |
154 | @return String primary key\r | |
155 | */\r | |
156 | public static String getPrimaryKey(String moduleName, \r | |
157 | UUID moduleGUID, \r | |
158 | String packageName, \r | |
159 | UUID packageGUID,\r | |
160 | String arch,\r | |
161 | String version) {\r | |
162 | //\r | |
163 | // Because currently transition schema not require write moduleGuid, package Name, Packge GUID in\r | |
164 | // <ModuleSA> section, So currently no expect all paramter must be valid.\r | |
165 | return (moduleName + "_" +\r | |
166 | ((moduleGUID != null) ? moduleGUID.toString() : "NullModuleGuid") + "_" +\r | |
167 | ((packageName != null) ? packageName : "NullPackageName") + "_" +\r | |
168 | ((packageGUID != null) ? packageGUID.toString() : "NullPackageGuid") + "_" +\r | |
169 | ((arch != null) ? arch : "NullArch") + "_" +\r | |
170 | ((version != null) ? version : "NullVersion"));\r | |
171 | }\r | |
172 | \r | |
173 | /**\r | |
174 | Get primary key string for this usage instance\r | |
175 | \r | |
176 | @return String primary key string\r | |
177 | **/\r | |
178 | public String getPrimaryKey() {\r | |
179 | return UsageInstance.getPrimaryKey(moduleName, moduleGUID, packageName, packageGUID, arch, version);\r | |
180 | }\r | |
181 | \r | |
182 | /**\r | |
183 | Judget whether current module is PEI driver\r | |
184 | \r | |
185 | @return boolean\r | |
186 | */\r | |
187 | public boolean isPeiPhaseComponent() {\r | |
188 | if ((moduleType == MODULE_TYPE.PEI_CORE) ||\r | |
189 | (moduleType == MODULE_TYPE.PEIM)) {\r | |
190 | return true;\r | |
191 | }\r | |
192 | return false;\r | |
193 | }\r | |
194 | \r | |
195 | /**\r | |
196 | Generate autogen string for header file and C code file.\r | |
197 | \r | |
198 | @throws EntityException Fail to generate.\r | |
199 | \r | |
200 | @param isBuildUsedLibrary whether the autogen is for library.\r | |
201 | */\r | |
202 | public void generateAutoGen(boolean isBuildUsedLibrary) \r | |
203 | throws EntityException {\r | |
204 | \r | |
205 | hAutogenStr = "";\r | |
206 | cAutogenStr = "";\r | |
207 | \r | |
208 | hAutogenStr += String.format("#define _PCD_TOKEN_%s 0x%016x\r\n", \r | |
209 | parentToken.cName, parentToken.tokenNumber);\r | |
210 | switch(modulePcdType) {\r | |
211 | case FEATURE_FLAG:\r | |
212 | if(isBuildUsedLibrary) {\r | |
213 | hAutogenStr += String.format("extern const BOOLEAN _gPcd_FixedAtBuild_%s;\r\n", \r | |
214 | parentToken.cName);\r | |
215 | hAutogenStr += String.format("#define _PCD_MODE_%s_%s _gPcd_FixedAtBuild_%s\r\n",\r | |
216 | parentToken.GetAutogenDefinedatumTypeString(parentToken.datumType),\r | |
217 | parentToken.cName,\r | |
218 | parentToken.cName);\r | |
219 | } else {\r | |
220 | hAutogenStr += String.format("#define _PCD_VALUE_%s %s\r\n", \r | |
221 | parentToken.cName, \r | |
222 | datum.toString());\r | |
223 | hAutogenStr += String.format("extern const BOOLEAN _gPcd_FixedAtBuild_%s;\r\n", \r | |
224 | parentToken.cName);\r | |
225 | cAutogenStr += String.format("GLOBAL_REMOVE_IF_UNREFERENCED const BOOLEAN _gPcd_FixedAtBuild_%s = _PCD_VALUE_%s;\r\n",\r | |
226 | parentToken.cName,\r | |
227 | parentToken.cName);\r | |
228 | hAutogenStr += String.format("#define _PCD_MODE_%s_%s _PCD_VALUE_%s\r\n",\r | |
229 | Token.GetAutogenDefinedatumTypeString(parentToken.datumType),\r | |
230 | parentToken.cName,\r | |
231 | parentToken.cName);\r | |
232 | }\r | |
233 | break;\r | |
234 | case FIXED_AT_BUILD:\r | |
235 | if(isBuildUsedLibrary) {\r | |
236 | hAutogenStr += String.format("extern const %s _gPcd_FixedAtBuild_%s;\r\n",\r | |
237 | Token.getAutogendatumTypeString(parentToken.datumType),\r | |
238 | parentToken.cName);\r | |
239 | hAutogenStr += String.format("#define _PCD_MODE_%s_%s _gPcd_FixedAtBuild_%s\r\n",\r | |
240 | Token.GetAutogenDefinedatumTypeString(parentToken.datumType),\r | |
241 | parentToken.cName,\r | |
242 | parentToken.cName);\r | |
243 | } else {\r | |
244 | hAutogenStr += String.format("#define _PCD_VALUE_%s %s\r\n", \r | |
245 | parentToken.cName, \r | |
246 | datum.toString());\r | |
247 | hAutogenStr += String.format("extern const %s _gPcd_FixedAtBuild_%s;\r\n",\r | |
248 | Token.getAutogendatumTypeString(parentToken.datumType),\r | |
249 | parentToken.cName);\r | |
250 | cAutogenStr += String.format("GLOBAL_REMOVE_IF_UNREFERENCED const %s _gPcd_FixedAtBuild_%s = _PCD_VALUE_%s;\r\n",\r | |
251 | Token.getAutogendatumTypeString(parentToken.datumType),\r | |
252 | parentToken.cName,\r | |
253 | parentToken.cName);\r | |
254 | hAutogenStr += String.format("#define _PCD_MODE_%s_%s _PCD_VALUE_%s\r\n",\r | |
255 | Token.GetAutogenDefinedatumTypeString(parentToken.datumType),\r | |
256 | parentToken.cName,\r | |
257 | parentToken.cName);\r | |
258 | }\r | |
259 | break;\r | |
260 | case PATCHABLE_IN_MODULE:\r | |
261 | if(isBuildUsedLibrary) {\r | |
262 | hAutogenStr += String.format("extern %s _gPcd_BinaryPatch_%s;\r\n",\r | |
263 | Token.getAutogendatumTypeString(parentToken.datumType),\r | |
264 | parentToken.cName);\r | |
265 | hAutogenStr += String.format("#define _PCD_MODE_%s_%s _gPcd_BinaryPatch_%s\r\n",\r | |
266 | Token.GetAutogenDefinedatumTypeString(parentToken.datumType),\r | |
267 | parentToken.cName,\r | |
268 | parentToken.cName);\r | |
269 | } else {\r | |
270 | hAutogenStr += String.format("#define _PCD_VALUE_%s %s\r\n", \r | |
271 | parentToken.cName, \r | |
272 | datum.toString());\r | |
273 | hAutogenStr += String.format("extern %s _gPcd_BinaryPatch_%s;\r\n",\r | |
274 | Token.getAutogendatumTypeString(parentToken.datumType),\r | |
275 | parentToken.cName);\r | |
276 | cAutogenStr += String.format("GLOBAL_REMOVE_IF_UNREFERENCED %s _gPcd_BinaryPatch_%s = _PCD_VALUE_%s;\r\n",\r | |
277 | Token.getAutogendatumTypeString(parentToken.datumType),\r | |
278 | parentToken.cName,\r | |
279 | parentToken.cName);\r | |
280 | hAutogenStr += String.format("#define _PCD_MODE_%s_%s _gPcd_BinaryPatch_%s\r\n",\r | |
281 | Token.GetAutogenDefinedatumTypeString(parentToken.datumType),\r | |
282 | parentToken.cName,\r | |
283 | parentToken.cName);\r | |
284 | }\r | |
285 | \r | |
286 | break;\r | |
287 | case DYNAMIC:\r | |
288 | hAutogenStr += String.format("#define _PCD_MODE_%s_%s LibPcdGet%s(_PCD_TOKEN_%s)\r\n",\r | |
289 | Token.GetAutogenDefinedatumTypeString(parentToken.datumType),\r | |
290 | parentToken.cName,\r | |
291 | Token.getAutogenLibrarydatumTypeString(parentToken.datumType),\r | |
292 | parentToken.cName);\r | |
293 | break;\r | |
294 | case DYNAMIC_EX:\r | |
295 | break;\r | |
296 | }\r | |
297 | }\r | |
298 | \r | |
299 | /**\r | |
300 | Get the autogen string for header file.\r | |
301 | \r | |
302 | @return The string of header file.\r | |
303 | **/\r | |
304 | public String getHAutogenStr() {\r | |
305 | return hAutogenStr;\r | |
306 | }\r | |
307 | \r | |
308 | /**\r | |
309 | Get the autogen string for C code file.\r | |
310 | \r | |
311 | @return The string of C Code file.\r | |
312 | **/\r | |
313 | public String getCAutogenStr() {\r | |
314 | return cAutogenStr;\r | |
315 | }\r | |
316 | }\r | |
317 | \r |