Skip to content

Commit 4ae5f91

Browse files
committed
Redfish JSON C Structure Convertor v1.3
- Fix unused variable build error under GCC. - Link child JSON object to the parent CS. - Generate edk2 FDF file. - Update copyright.
1 parent ee34c91 commit 4ae5f91

6 files changed

+60
-16
lines changed

AUTHORS.md

+2
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,6 @@
44

55

66
# Other Key Contributions:
7+
* Abner Chang - Advanced Micro Devices, Inc.
8+
79

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11

22
# Change Log
33

4+
## [1.3] - 2024-1-8
5+
- Fix unused variable build error under GCC.
6+
- Link child JSON object to the parent CS.
7+
- Generate edk2 FDF file.
8+
49
## [1.2] - 2021-8-17
510
- Fixe the issue when turn nested JSON object into nested C structure.
611
- Fix the duplicated function name issue.

GenCRelatedFile.py

+16-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Redfish JSON resource to C structure converter source code generator.
33
#
44
# Copyright Notice:
5-
# Copyright 2021-2022 DMTF. All rights reserved.
5+
# Copyright 2021-2024 DMTF. All rights reserved.
66
# License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/Redfish-Tacklebox/blob/main/LICENSE.md
77
#
88
import os
@@ -818,18 +818,31 @@ def GenCStructureJSonStructureCode (self, ResourceType, SchemaVersion, Structure
818818

819819
CodeStr = self.GenCStructToJsonCCodeForStructure (ResourceType, SchemaVersion, StructnameShort, NestedStructName, PrecedentKey, CStructPointer + "->" + key, False)
820820
if "RedfishCS_status CS_To_JSON_" + PrecedentKey in self.CStructureToJsonStructureExistFunc:
821-
# Funciton already exist.
821+
# Function already exist.
822822
return
823823
self.CStructureToJsonStructureExistFunc.append ("RedfishCS_status CS_To_JSON_" + PrecedentKey)
824824

825825
self.CStructureToJsonStructureFuncions += "static RedfishCS_status CS_To_JSON_" + PrecedentKey + "(json_t *CsJson, char *Key, " + StructureMemberDataType + " *CSPtr)\n"
826826
self.CStructureToJsonStructureFuncions += "{\n"
827+
828+
if CodeStr != "":
829+
self.CStructureToJsonStructureFuncions += C_SRC_TAB_SPACE + "json_t *CsParentJson;\n\n"
830+
827831
self.CStructureToJsonStructureFuncions += C_SRC_TAB_SPACE + "if (CSPtr == NULL) {\n"
828832
self.CStructureToJsonStructureFuncions += C_SRC_TAB_SPACE * 2 + "return RedfishCS_status_success;\n"
829-
self.CStructureToJsonStructureFuncions += C_SRC_TAB_SPACE + "}\n"
833+
self.CStructureToJsonStructureFuncions += C_SRC_TAB_SPACE + "}\n\n"
834+
835+
if CodeStr != "":
836+
self.CStructureToJsonStructureFuncions += C_SRC_TAB_SPACE + "CsParentJson = CsJson;\n"
837+
self.CStructureToJsonStructureFuncions += C_SRC_TAB_SPACE + "CsJson = json_object();\n"
838+
self.CStructureToJsonStructureFuncions += C_SRC_TAB_SPACE + "if (CsJson == NULL) {\n"
839+
self.CStructureToJsonStructureFuncions += C_SRC_TAB_SPACE * 2 + "return RedfishCS_status_unsupported;\n"
840+
self.CStructureToJsonStructureFuncions += C_SRC_TAB_SPACE + "}\n\n"
830841

831842
if CodeStr != "":
832843
self.CStructureToJsonStructureFuncions += CodeStr
844+
self.CStructureToJsonStructureFuncions += C_SRC_TAB_SPACE + "// Set to parent JSON object.\n"
845+
self.CStructureToJsonStructureFuncions += C_SRC_TAB_SPACE + "if (json_object_set_new (CsParentJson, Key, CsJson) == -1) {goto Error;}\n\n"
833846
else:
834847
self.CStructureToJsonStructureFuncions += C_SRC_TAB_SPACE + "// Check if this is RedfishCS_Type_CS_EmptyProp.\n"
835848
self.CStructureToJsonStructureFuncions += C_SRC_TAB_SPACE + "CsEmptyPropLinkToJson(CsJson, Key, &CSPtr->Prop);\n"

GenEdk2Files.py

+34-10
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Redfish JSON resource to C structure converter source code generator.
33
#
44
# Copyright Notice:
5-
# Copyright 2021-2022 DMTF. All rights reserved.
5+
# Copyright 2021-2024 DMTF. All rights reserved.
66
# License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/Redfish-Tacklebox/blob/main/LICENSE.md
77
#
88
import os
@@ -109,7 +109,8 @@ def __init__ (self, RedfishCSInstance, SchemaFileInstance, RedfishCSStructList,
109109
self.Edk2RedfishIntpTempDxeInf = ""
110110
self.Edk2RedfishIntpTempInclude = ""
111111
self.Edk2RedfishIntpComponentDsc = ""
112-
self.Edk2RedfishIntpLibDsc = ""
112+
self.Edk2RedfishIntpLibDsc = ""
113+
self.Edk2RedfishIntpFdf = ""
113114
self.Edk2RedfishintpKeywordsDict = {}
114115
self.Edk2CStructureName = ""
115116

@@ -292,6 +293,7 @@ def GenEdk2RedfishIntpFile(self):
292293

293294
self.Edk2RedfishIntpComponentDsc = "RedfishSchemaCsInterpreter_Component.dsc"
294295
self.Edk2RedfishIntpLibDsc = "RedfishSchemaCsInterpreter_Lib.dsc"
296+
self.Edk2RedfishIntpFdf = "RedfishSchemaCsInterpreter_Component.fdf"
295297

296298
self.Edk2RedfishIntpTempDxeC = self.Edk2RedfishIntpTempFilesDir + os.path.normpath("/RedfishCsDxe.temp")
297299
self.Edk2RedfishIntpTempDxeInf = self.Edk2RedfishIntpTempFilesDir + os.path.normpath("/RedfishCsInf.temp")
@@ -356,28 +358,50 @@ def GenEdk2RedfishIntpFile(self):
356358
if not os.path.exists (self.Edk2RedfishIntpOutputDir + os.path.normpath("/" + self.Edk2RedfishIntpLibDsc)):
357359
fo = open(self.Edk2RedfishIntpOutputDir + os.path.normpath("/" + self.Edk2RedfishIntpLibDsc),"w")
358360
fo.close()
359-
361+
if not os.path.exists (self.Edk2RedfishIntpOutputDir + os.path.normpath("/" + self.Edk2RedfishIntpFdf)):
362+
fo = open(self.Edk2RedfishIntpOutputDir + os.path.normpath("/" + self.Edk2RedfishIntpFdf),"w")
363+
fo.close()
364+
365+
#
366+
# edk2 driver DSC
367+
#
360368
fo = open(self.Edk2RedfishIntpOutputDir + os.path.normpath("/" + self.Edk2RedfishIntpComponentDsc),"a")
361369
if SchemaVersion == "":
362-
fo.write("!if $(REDFISH_" + RedfishCs.ResourceType.upper() + ") OR $(REDFISH_CLIENT_ALL_AUTOGENED)\n")
370+
fo.write("!if ($(REDFISH_" + RedfishCs.ResourceType.upper() + ") == TRUE) OR ($(REDFISH_CLIENT_ALL_AUTOGENED) == TRUE)\n")
363371
fo.write(" " + self.Edk2RedfishJsonCsPackagePath + "RedfishClientPkg/Converter/" + RedfishCs.ResourceType + "/" + RedfishCsSchemaDxe_INF_File + "\n")
364372
fo.write("!endif\n")
365373
else:
366-
fo.write("!if $(REDFISH_" + RedfishCs.ResourceType.upper() + "_" + SchemaVersion.upper() + ") OR $(REDFISH_CLIENT_ALL_AUTOGENED)\n")
374+
fo.write("!if ($(REDFISH_" + RedfishCs.ResourceType.upper() + "_" + SchemaVersion.upper() + ") == TRUE) OR ($(REDFISH_CLIENT_ALL_AUTOGENED) == TRUE)\n")
367375
fo.write(" " + self.Edk2RedfishJsonCsPackagePath + "RedfishClientPkg/Converter/" + RedfishCs.ResourceType + "/" + SchemaVersion + "/" + RedfishCsSchemaDxe_INF_File + "\n")
368-
fo.write("!endif\n")
376+
fo.write("!endif\n")
369377
fo.close()
370378

379+
#
380+
# edk2 library DSC
381+
#
371382
fo = open(self.Edk2RedfishIntpOutputDir + os.path.normpath("/" + self.Edk2RedfishIntpLibDsc),"a")
372383
if SchemaVersion == "":
373-
fo.write("!if $(REDFISH_" + RedfishCs.ResourceType.upper() + ") OR $(REDFISH_CLIENT_ALL_AUTOGENED)\n")
384+
fo.write("!if ($(REDFISH_" + RedfishCs.ResourceType.upper() + ") == TRUE) OR ($(REDFISH_CLIENT_ALL_AUTOGENED) == TRUE)\n")
374385
fo.write(" " + self.LibClass + "|" + self.Edk2RedfishJsonCsPackagePath + "RedfishClientPkg/ConverterLib" + Edk2BindingDir + "/" + RedfishCs.ResourceType + "/Lib.inf" + "\n")
375386
fo.write("!endif\n")
376387
else:
377-
fo.write("!if $(REDFISH_" + RedfishCs.ResourceType.upper() + "_" + SchemaVersion.upper() + ") OR $(REDFISH_CLIENT_ALL_AUTOGENED)\n")
388+
fo.write("!if ($(REDFISH_" + RedfishCs.ResourceType.upper() + "_" + SchemaVersion.upper() + ") == TRUE) OR ($(REDFISH_CLIENT_ALL_AUTOGENED) == TRUE)\n")
378389
fo.write(" " + self.LibClass + "|" + self.Edk2RedfishJsonCsPackagePath + "RedfishClientPkg/ConverterLib" + Edk2BindingDir + "/" + RedfishCs.ResourceType + "/" + SchemaVersion + "/Lib.inf" + "\n")
379-
fo.write("!endif\n")
380-
fo.close()
390+
fo.write("!endif\n")
391+
fo.close()
392+
#
393+
# edk2 driver FDF
394+
#
395+
fo = open(self.Edk2RedfishIntpOutputDir + os.path.normpath("/" + self.Edk2RedfishIntpFdf),"a")
396+
if SchemaVersion == "":
397+
fo.write("!if ($(REDFISH_" + RedfishCs.ResourceType.upper() + ") == TRUE) OR ($(REDFISH_CLIENT_ALL_AUTOGENED) == TRUE)\n")
398+
fo.write(" INF " + self.Edk2RedfishJsonCsPackagePath + "RedfishClientPkg/Converter/" + RedfishCs.ResourceType + "/" + RedfishCsSchemaDxe_INF_File + "\n")
399+
fo.write("!endif\n")
400+
else:
401+
fo.write("!if ($(REDFISH_" + RedfishCs.ResourceType.upper() + "_" + SchemaVersion.upper() + ") == TRUE) OR ($(REDFISH_CLIENT_ALL_AUTOGENED) == TRUE)\n")
402+
fo.write(" INF " + self.Edk2RedfishJsonCsPackagePath + "RedfishClientPkg/Converter/" + RedfishCs.ResourceType + "/" + SchemaVersion + "/" + RedfishCsSchemaDxe_INF_File + "\n")
403+
fo.write("!endif\n")
404+
fo.close()
381405

382406
fo = open(os.path.normpath(RedfishCsInterpreter_Source_Schema_dir + "/" + RedfishCsSchemaDxe_C_File),"w")
383407
Edk2RedfishIntpTempDxeCLines = self.Replacekeyworkds(Edk2RedfishIntpTempDxeCLines)

GenRedfishSchemaCS.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Redfish JSON resource to C structure converter source code generator.
33
#
44
# Copyright Notice:
5-
# Copyright 2021 DMTF. All rights reserved.
5+
# Copyright 2021-2024 DMTF. All rights reserved.
66
# License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/Redfish-Tacklebox/blob/main/LICENSE.md
77
#
88
import os
@@ -816,7 +816,7 @@ def PrintHelpMessageExit (str):
816816
#JsonFileIo.close()
817817
# Test Redfish property
818818

819-
print ("\n\nDMTF Redfish Schema to C Structure Generator Copyrights 2018-2024 v1.2_schema2020.4")
819+
print ("\n\nDMTF Redfish Schema to C Structure Generator Copyrights 2018-2024 v1.3_schema2021.4")
820820

821821
if "-logfile" in sys.argv:
822822
ToolLogInformation = ToolLogger.ToolLog (TOOL_LOG_TO_FILE, "RedfishCs.log")

LICENSE.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ other rights are granted by DMTF. This software might be subject to other rights
66

77
### Copyrights.
88

9-
Copyright (c) 2021-2022, Contributing Member(s) of Distributed Management Task Force,
9+
Copyright (c) 2021-2024, Contributing Member(s) of Distributed Management Task Force,
1010
Inc.. All rights reserved.
1111

1212
Redistribution and use in source and binary forms, with or without modification,

0 commit comments

Comments
 (0)