summaryrefslogtreecommitdiffstats
path: root/src/main/java/org/openslx/firmware/QemuFirmware.java
blob: 7a81217231dcd6f6d52080f14fbeefb24e9fec1d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
package org.openslx.firmware;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.Reader;
import java.util.ArrayList;

import com.google.gson.Gson;
import com.google.gson.JsonIOException;
import com.google.gson.JsonSyntaxException;
import com.google.gson.annotations.SerializedName;

/**
 * Data representation of QEMU firmware specification files (*.json).
 * 
 * @author Manuel Bentele
 * @version 1.0
 */
public class QemuFirmware
{
	/**
	 * Default QEMU firmware specification directory under Linux-based systems.
	 */
	public final static String DEFAULT_SPEC_DIR = "/usr/share/qemu/firmware";

	@SerializedName( "description" )
	private String description;
	@SerializedName( "interface-types" )
	private ArrayList<String> interfaceTypes;
	@SerializedName( "mapping" )
	private FirmwareMapping mapping;
	@SerializedName( "targets" )
	private ArrayList<FirmwareTarget> targets;
	@SerializedName( "features" )
	private ArrayList<String> features;
	@SerializedName( "tags" )
	private ArrayList<String> tags;

	public String getDescription()
	{
		return description;
	}

	public ArrayList<String> getInterfaceTypes()
	{
		return interfaceTypes;
	}

	public FirmwareMapping getMapping()
	{
		return mapping;
	}

	public ArrayList<FirmwareTarget> getTargets()
	{
		return targets;
	}

	public ArrayList<String> getFeatures()
	{
		return features;
	}

	public ArrayList<String> getTags()
	{
		return tags;
	}

	/**
	 * Parse QEMU firmware specification from firmware specification Json file.
	 * 
	 * @param fwSpecFile firmware specification Json file.
	 * @return QEMU firmware specification.
	 */
	public static QemuFirmware fromFwSpec( File fwSpecFile )
	{
		final Gson gson = new Gson();
		QemuFirmware firmware = null;

		try {
			final Reader jsonContent = new FileReader( fwSpecFile );
			firmware = gson.fromJson( jsonContent, QemuFirmware.class );
		} catch ( FileNotFoundException | NullPointerException | JsonSyntaxException | JsonIOException e ) {
			firmware = null;
		}

		return firmware;
	}
}

class FirmwareMapping
{
	@SerializedName( "device" )
	private String device;
	@SerializedName( "executable" )
	private FirmwareMappingExecutable executable;
	@SerializedName( "nvram-template" )
	private FirmwareMappingNvramTemplate nvramTemplate;

	public String getDevice()
	{
		return device;
	}

	public FirmwareMappingExecutable getExecutable()
	{
		return executable;
	}

	public FirmwareMappingNvramTemplate getNvramTemplate()
	{
		return nvramTemplate;
	}
}

class FirmwareMappingExecutable
{
	@SerializedName( "filename" )
	private String fileName;
	@SerializedName( "format" )
	private String format;

	public String getFileName()
	{
		return fileName;
	}

	public String getFormat()
	{
		return format;
	}
}

class FirmwareMappingNvramTemplate
{
	@SerializedName( "filename" )
	private String fileName;
	@SerializedName( "format" )
	private String format;

	public String getFileName()
	{
		return fileName;
	}

	public String getFormat()
	{
		return format;
	}
}

class FirmwareTarget
{
	@SerializedName( "architecture" )
	private String architecture;
	@SerializedName( "machines" )
	private ArrayList<String> machines;

	public String getArchitecture()
	{
		return architecture;
	}

	public ArrayList<String> getMachines()
	{
		return machines;
	}
}