summaryrefslogtreecommitdiffstats
path: root/src/main/java/org/openslx/libvirt/domain/device/RedirDevice.java
blob: d841413a5e32e1611d1163e62bef88688e062b6c (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
package org.openslx.libvirt.domain.device;

import org.openslx.libvirt.xml.LibvirtXmlNode;

/**
 * A video (GPU) device node in a Libvirt domain XML document.
 * 
 * @author Manuel Bentele
 * @version 1.0
 */
public class RedirDevice extends Device
{
	/**
	 * Creates an empty video device.
	 */
	public RedirDevice()
	{
		super();
	}

	/**
	 * Creates a redirect device representing an existing Libvirt XML redirect device element.
	 */
	public RedirDevice( LibvirtXmlNode xmlNode )
	{
		super( xmlNode );
	}

	/**
	 * Returns type of redirect device.
	 */
	public SrcType getSrcType()
	{
		String type = this.getXmlElementAttributeValue( "type" );
		return SrcType.fromString( type );
	}

	/**
	 * Sets type for the redirect device.
	 */
	public void setSrcType( SrcType type )
	{
		this.setXmlElementAttributeValue( "type", type.toString() );
	}

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

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

	/**
	 * Type of redirected device.
	 */
	public enum SrcType
	{
		// @formatter:off
		DEV         ( "dev" ),
		FILE        ( "file" ),
		PIPE        ( "pipe" ),
		UNIX        ( "unix" ),
		TCP         ( "tcp" ),
		UDP         ( "udp" ),
		NULL        ( "null" ),
		STDIO       ( "stdio" ),
		VC          ( "vc" ),
		PTY         ( "pty" ),
		SPICEVMC    ( "spicevmc" ),
		SPICEPORT   ( "spiceport" ),
		NMDM        ( "nmdm" ),
		QEMU_VDAGENT( "qemu-vdagent" ),
		DBUS        ( "dbus" );
		// @formatter:on

		/**
		 * Type of device redirect, as expected in the xml file.
		 */
		private String typeString = null;

		SrcType( String typeString )
		{
			this.typeString = typeString;
		}

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

		/**
		 * Returns Type instance from its name with error check.
		 */
		public static SrcType fromString( String model )
		{
			for ( SrcType m : SrcType.values() ) {
				if ( m.typeString.equalsIgnoreCase( model ) ) {
					return m;
				}
			}

			return null;
		}
	}

	public void setBusType( BusType usb )
	{
		this.setXmlElementAttributeValue( "bus", usb.toString() );
	}
}