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