Wrap any fallible libvirt function in a call to ErrorHandler.processError(..). Signed-off-by: Claudio Bley <cbley@xxxxxxxxxx> --- src/main/java/org/libvirt/Device.java | 49 ++++++++++----------------------- 1 file changed, 14 insertions(+), 35 deletions(-) diff --git a/src/main/java/org/libvirt/Device.java b/src/main/java/org/libvirt/Device.java index d55321e..a3b20b8 100644 --- a/src/main/java/org/libvirt/Device.java +++ b/src/main/java/org/libvirt/Device.java @@ -2,6 +2,9 @@ package org.libvirt; import org.libvirt.jna.DevicePointer; import static org.libvirt.Library.libvirt; +import static org.libvirt.ErrorHandler.processError; + +import com.sun.jna.Pointer; import com.sun.jna.Pointer; @@ -43,8 +46,7 @@ public class Device { public int destroy() throws LibvirtException { int success = 0; if (VDP != null) { - success = libvirt.virNodeDeviceDestroy(VDP); - processError(); + success = processError(libvirt.virNodeDeviceDestroy(VDP)); VDP = null; } @@ -58,9 +60,7 @@ public class Device { * @throws LibvirtException */ public int detach() throws LibvirtException { - int num = libvirt.virNodeDeviceDettach(VDP); - processError(); - return num; + return processError(libvirt.virNodeDeviceDettach(VDP)); } @Override @@ -78,8 +78,7 @@ public class Device { public int free() throws LibvirtException { int success = 0; if (VDP != null) { - success = libvirt.virNodeDeviceFree(VDP); - processError(); + success = processError(libvirt.virNodeDeviceFree(VDP)); VDP = null; } @@ -92,9 +91,7 @@ public class Device { * @throws LibvirtException */ public String getName() throws LibvirtException { - String name = libvirt.virNodeDeviceGetName(VDP); - processError(); - return name; + return processError(libvirt.virNodeDeviceGetName(VDP)); } /** @@ -103,9 +100,7 @@ public class Device { * @throws LibvirtException */ public int getNumberOfCapabilities() throws LibvirtException { - int num = libvirt.virNodeDeviceNumOfCaps(VDP); - processError(); - return num; + return processError(libvirt.virNodeDeviceNumOfCaps(VDP)); } /** @@ -114,9 +109,7 @@ public class Device { * @throws LibvirtException */ public String getParent() throws LibvirtException { - String parent = libvirt.virNodeDeviceGetParent(VDP); - processError(); - return parent; + return processError(libvirt.virNodeDeviceGetParent(VDP)); } /** @@ -125,9 +118,7 @@ public class Device { * @throws LibvirtException */ public String getXMLDescription() throws LibvirtException { - String desc = libvirt.virNodeDeviceGetXMLDesc(VDP); - processError(); - return desc; + return processError(libvirt.virNodeDeviceGetXMLDesc(VDP)); } /** @@ -140,8 +131,8 @@ public class Device { if (maxCaps > 0) { Pointer[] ptrs = new Pointer[maxCaps]; - int got = libvirt.virNodeDeviceListCaps(VDP, ptrs, maxCaps); - processError(); + int got = processError(libvirt.virNodeDeviceListCaps(VDP, ptrs, maxCaps)); + return Library.toStringArray(ptrs, got); } else { return Library.NO_STRINGS; @@ -149,22 +140,12 @@ public class Device { } /** - * Error handling logic to throw errors. Must be called after every libvirt - * call. - */ - protected void processError() throws LibvirtException { - virConnect.processError(); - } - - /** * ReAttach a device to the node. * * @throws LibvirtException */ public int reAttach() throws LibvirtException { - int num = libvirt.virNodeDeviceReAttach(VDP); - processError(); - return num; + return processError(libvirt.virNodeDeviceReAttach(VDP)); } /** @@ -174,8 +155,6 @@ public class Device { * @throws LibvirtException */ public int reset() throws LibvirtException { - int num = libvirt.virNodeDeviceReset(VDP); - processError(); - return num; + return processError(libvirt.virNodeDeviceReset(VDP)); } } -- 1.7.9.5 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list