summaryrefslogtreecommitdiffstats
path: root/src/main/java/org/openslx/libvirt/domain/device/GraphicsSpice.java
blob: be672009c572981d5427dc121df7e21332675940 (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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
package org.openslx.libvirt.domain.device;

import java.net.InetAddress;

import org.openslx.libvirt.xml.LibvirtXmlNode;

/**
 * A graphics SPICE device node in a Libvirt domain XML document.
 * 
 * @author Manuel Bentele
 * @version 1.0
 */
public class GraphicsSpice extends Graphics
{
	/**
	 * Default address of a SPICE graphics listener.
	 */
	public static final InetAddress DEFAULT_ADDRESS = InetAddress.getLoopbackAddress();

	/**
	 * Default port of a SPICE graphics listener.
	 */
	public static final int DEFAULT_PORT = 59000;

	/**
	 * Creates an empty graphics SPICE device.
	 */
	public GraphicsSpice()
	{
		super();
	}

	/**
	 * Creates a graphics SPICE device representing an existing Libvirt XML graphics SPICE device
	 * element.
	 * 
	 * @param xmlNode existing Libvirt XML graphics SPCIE device element.
	 */
	public GraphicsSpice( LibvirtXmlNode xmlNode )
	{
		super( xmlNode );
	}

	/**
	 * Returns the state whether OpenGL hardware acceleration is enabled or not.
	 * 
	 * @return state whether OpenGL hardware acceleration is enabled or not.
	 */
	public boolean isOpenGlEnabled()
	{
		return this.getXmlElementAttributeValueAsBool( "gl", "enable" );
	}

	/**
	 * Sets the state whether OpenGL hardware acceleration is enabled or not.
	 * 
	 * @param enabled state whether OpenGL hardware acceleration is enabled or not.
	 */
	public void setOpenGl( boolean enabled )
	{
		this.setXmlElementAttributeValueYesNo( "gl", "enable", enabled );
	}

	/**
	 * Returns the image compression type.
	 * 
	 * @return image compression type.
	 */
	public ImageCompression getImageCompression()
	{
		final String imageCompression = this.getXmlElementAttributeValue( "image", "compression" );
		return ImageCompression.fromString( imageCompression );
	}

	/**
	 * Sets the image compression type.
	 * 
	 * @param type image compression type.
	 */
	public void setImageCompression( ImageCompression type )
	{
		this.setXmlElementAttributeValue( "image", "compression", type.toString() );
	}

	/**
	 * Checks if audio playback compression is enabled or not.
	 * 
	 * @return state whether audio playback compression is enabled or not.
	 */
	public boolean isPlaybackCompressionOn()
	{
		return this.getXmlElementAttributeValueAsBool( "playback", "compression" );
	}

	/**
	 * Sets the state whether audio playback compression is enabled or not.
	 * 
	 * @param enabled state whether audio playback compression is enabled or not.
	 */
	public void setPlaybackCompression( boolean enabled )
	{
		this.setXmlElementAttributeValueOnOff( "playback", "compression", enabled );
	}

	/**
	 * Returns the streaming mode.
	 * 
	 * @return streaming mode type.
	 */
	public StreamingMode getStreamingMode()
	{
		final String streamingMode = this.getXmlElementAttributeValue( "streaming", "mode" );
		return StreamingMode.fromString( streamingMode );
	}

	/**
	 * Sets the streaming mode.
	 * 
	 * @param type streaming mode type.
	 */
	public void setStreamingMode( StreamingMode type )
	{
		this.setXmlElementAttributeValue( "streaming", "mode", type.toString() );
	}

	/**
	 * Creates a non-existent graphics SPICE device as Libvirt XML device element.
	 * 
	 * @param xmlNode Libvirt XML node of the Libvirt XML device that is created.
	 * @return created graphics SPICE device instance.
	 */
	public static GraphicsSpice createInstance( LibvirtXmlNode xmlNode )
	{
		return GraphicsSpice.newInstance( xmlNode );
	}

	/**
	 * Creates a graphics SPICE device representing an existing Libvirt XML graphics SPICE device
	 * element.
	 * 
	 * @param xmlNode existing Libvirt XML graphics SPICE device element.
	 * @return graphics SPICE device instance.
	 */
	public static GraphicsSpice newInstance( LibvirtXmlNode xmlNode )
	{
		return new GraphicsSpice( xmlNode );
	}

	/**
	 * Image compression type of graphics device.
	 * 
	 * @author Manuel Bentele
	 * @version 1.0
	 */
	public enum ImageCompression
	{
		// @formatter:off
		AUTO_GLZ( "auto_glz" ),
		AUTO_LZ ( "auto_lz" ),
		QUIC    ( "quic" ),
		GLZ     ( "glz" ),
		LZ      ( "lz" ),
		OFF     ( "off" );
      // @formatter:on

		/**
		 * Name of graphics device image compression type.
		 */
		private String type = null;

		/**
		 * Creates graphics device image compression type.
		 * 
		 * @param type valid name of the graphics device image compression type in a Libvirt domain
		 *           XML document.
		 */
		ImageCompression( String type )
		{
			this.type = type;
		}

		@Override
		public String toString()
		{
			return this.type;
		}

		/**
		 * Creates graphics device image compression type from its name with error check.
		 * 
		 * @param type name of the graphics device image compression type in a Libvirt domain XML
		 *           document.
		 * @return valid graphics device image compression type.
		 */
		public static ImageCompression fromString( String type )
		{
			for ( ImageCompression t : ImageCompression.values() ) {
				if ( t.type.equalsIgnoreCase( type ) ) {
					return t;
				}
			}

			return null;
		}
	}

	/**
	 * Streaming mode type of graphics device.
	 * 
	 * @author Manuel Bentele
	 * @version 1.0
	 */
	public enum StreamingMode
	{
		// @formatter:off
		ALL   ( "all" ),
		FILTER( "filter" ),
		OFF   ( "off" );
      // @formatter:on

		/**
		 * Name of graphics device image compression type.
		 */
		private String type = null;

		/**
		 * Creates graphics device streaming mode type.
		 * 
		 * @param type valid name of the graphics device streaming mode type in a Libvirt domain XML
		 *           document.
		 */
		StreamingMode( String type )
		{
			this.type = type;
		}

		@Override
		public String toString()
		{
			return this.type;
		}

		/**
		 * Creates graphics device streaming mode type from its name with error check.
		 * 
		 * @param type name of the graphics device streaming mode type in a Libvirt domain XML
		 *           document.
		 * @return valid graphics device streaming mode type.
		 */
		public static StreamingMode fromString( String type )
		{
			for ( StreamingMode t : StreamingMode.values() ) {
				if ( t.type.equalsIgnoreCase( type ) ) {
					return t;
				}
			}

			return null;
		}
	}
}