1 package org.libvirt; 2 3 import org.libvirt.jna.Libvirt; 4 import org.libvirt.jna.NetworkFilterPointer; 5 import static org.libvirt.Library.libvirt; 6 import static org.libvirt.ErrorHandler.processError; 7 8 import com.sun.jna.Native; 9 10 public class NetworkFilter { 11 /** 12 * the native virNWFilterPtr. 13 */ 14 NetworkFilterPointer nfp; 15 16 /** 17 * The Connect Object that represents the Hypervisor of this Filter 18 */ 19 private final Connect virConnect; 20 NetworkFilter(final Connect virConnect, final NetworkFilterPointer nfp)21 public NetworkFilter(final Connect virConnect, final NetworkFilterPointer nfp) { 22 this.nfp = nfp; 23 this.virConnect = virConnect; 24 } 25 26 @Override finalize()27 protected void finalize() throws LibvirtException { 28 free(); 29 } 30 31 /** 32 * Release the network filter handle. The underlying snapshot continues to 33 * exist. 34 * 35 * @throws LibvirtException 36 * @return <em>ignore</em> (always 0) 37 */ free()38 public int free() throws LibvirtException { 39 int success = 0; 40 if (nfp != null) { 41 success = processError(libvirt.virNWFilterFree(nfp)); 42 nfp = null; 43 } 44 45 return success; 46 } 47 48 /** 49 * Gets the public name for this network filter 50 * 51 * @return the name 52 * @throws LibvirtException 53 */ getName()54 public String getName() throws LibvirtException { 55 return processError(libvirt.virNWFilterGetName(nfp)); 56 } 57 58 /** 59 * Get the UUID for this network filter. 60 * 61 * @return the UUID as an unpacked int array 62 * @throws LibvirtException 63 * @see <a href="http://www.ietf.org/rfc/rfc4122.txt">rfc4122</a> 64 */ getUUID()65 public int[] getUUID() throws LibvirtException { 66 byte[] bytes = new byte[Libvirt.VIR_UUID_BUFLEN]; 67 processError(libvirt.virNWFilterGetUUID(nfp, bytes)); 68 return Connect.convertUUIDBytes(bytes); 69 } 70 71 /** 72 * Gets the UUID for this network filter as string. 73 * 74 * @return the UUID in canonical String format 75 * @throws LibvirtException 76 * @see <a href="http://www.ietf.org/rfc/rfc4122.txt">rfc4122</a> 77 */ getUUIDString()78 public String getUUIDString() throws LibvirtException { 79 byte[] bytes = new byte[Libvirt.VIR_UUID_STRING_BUFLEN]; 80 processError(libvirt.virNWFilterGetUUIDString(nfp, bytes)); 81 return Native.toString(bytes); 82 } 83 84 /** 85 * Fetches an XML document describing attributes of the network filter. 86 * 87 * @throws org.libvirt.LibvirtException 88 * @see <a 89 * href="http://www.libvirt.org/html/libvirt-libvirt.html#virNWFilterGetXMLDesc">Libvirt 90 * Documentation</a> 91 * @return the XML document 92 */ getXMLDesc()93 public String getXMLDesc() throws LibvirtException { 94 return processError(libvirt.virNWFilterGetXMLDesc(nfp, 0)).toString(); 95 } 96 97 /** 98 * undefine the network filter 99 * 100 * @throws LibvirtException 101 */ undefine()102 public void undefine() throws LibvirtException { 103 processError(libvirt.virNWFilterUndefine(nfp)); 104 } 105 } 106