diff options
author | Manuel Bentele | 2021-09-01 12:30:25 +0200 |
---|---|---|
committer | Manuel Bentele | 2021-09-01 12:30:25 +0200 |
commit | e33d5e17b789fb180e9d24dce1d36caed2d83e16 (patch) | |
tree | 92c48e3201f81555af6b4d5dd3e437f072a4a92a /src/main | |
parent | Print debug output in transformation manager (diff) | |
download | master-sync-shared-e33d5e17b789fb180e9d24dce1d36caed2d83e16.tar.gz master-sync-shared-e33d5e17b789fb180e9d24dce1d36caed2d83e16.tar.xz master-sync-shared-e33d5e17b789fb180e9d24dce1d36caed2d83e16.zip |
Add getter/setter for listen address and port of Libvirt SPICE graphics
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/org/openslx/libvirt/domain/device/Graphics.java | 63 | ||||
-rw-r--r-- | src/main/java/org/openslx/libvirt/domain/device/GraphicsSpice.java | 12 |
2 files changed, 75 insertions, 0 deletions
diff --git a/src/main/java/org/openslx/libvirt/domain/device/Graphics.java b/src/main/java/org/openslx/libvirt/domain/device/Graphics.java index d10eb3f..3fd2f81 100644 --- a/src/main/java/org/openslx/libvirt/domain/device/Graphics.java +++ b/src/main/java/org/openslx/libvirt/domain/device/Graphics.java @@ -1,5 +1,8 @@ package org.openslx.libvirt.domain.device; +import java.net.InetAddress; +import java.net.UnknownHostException; + import org.openslx.libvirt.xml.LibvirtXmlNode; /** @@ -50,6 +53,66 @@ public class Graphics extends Device } /** + * Returns the listen address of the graphics device. + * + * @return listen address of the graphics device. + */ + public InetAddress getListenAddress() + { + InetAddress parsedListenAddress = null; + + if ( this.getListenType() == ListenType.ADDRESS ) { + // only read listen address, if address listen type is set + final String rawListenAddress = this.getXmlElementAttributeValue( "listen", "address" ); + + try { + parsedListenAddress = InetAddress.getByName( rawListenAddress ); + } catch ( UnknownHostException e ) { + parsedListenAddress = null; + } + } + + return parsedListenAddress; + } + + /** + * Sets the listen address for the graphics device. + * + * @param listenAddress listen address for the graphics device. + */ + public void setListenAddress( InetAddress listenAddress ) + { + if ( this.getListenType() == ListenType.ADDRESS && listenAddress != null ) { + // only set listen address, if address listen type is set + this.setXmlElementAttributeValue( "listen", "address", listenAddress.getHostAddress() ); + } + } + + /** + * Returns the listen port of the graphics device. + * + * @return listen port of the graphics device. + */ + public int getListenPort() + { + final String listenPort = this.getXmlElementAttributeValue( "port" ); + return Integer.valueOf( listenPort ); + } + + /** + * Sets the listen port for the graphics device. + * + * @param listenPort listen port for the graphics device. + */ + public void setListenPort( int listenPort ) + { + if ( this.getListenType() == ListenType.ADDRESS ) { + // only set listen port, if address listen type is set + this.setXmlElementAttributeValue( "port", Integer.toString( listenPort ) ); + } + } + + /** * Creates a non-existent graphics device as Libvirt XML device element. * * @param graphics graphics device that is created. diff --git a/src/main/java/org/openslx/libvirt/domain/device/GraphicsSpice.java b/src/main/java/org/openslx/libvirt/domain/device/GraphicsSpice.java index fbd115b..2c6068a 100644 --- a/src/main/java/org/openslx/libvirt/domain/device/GraphicsSpice.java +++ b/src/main/java/org/openslx/libvirt/domain/device/GraphicsSpice.java @@ -1,5 +1,7 @@ package org.openslx.libvirt.domain.device; +import java.net.InetAddress; + import org.openslx.libvirt.xml.LibvirtXmlNode; /** @@ -11,6 +13,16 @@ import org.openslx.libvirt.xml.LibvirtXmlNode; 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 = 5900; + + /** * Creates an empty graphics SPICE device. */ public GraphicsSpice() |