[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [libvirt] [PATCH] Domain object is converted



On Sat, Jul 25, 2009 at 08:02:11AM -0400, Bryan Kearney wrote:
> ---
>  src/org/libvirt/Connect.java                     |    9 +
>  src/org/libvirt/Domain.java                      |  307 +++++++++++++---------
>  src/org/libvirt/DomainBlockStats.java            |   13 +
>  src/org/libvirt/DomainInfo.java                  |   14 +
>  src/org/libvirt/DomainInterfaceStats.java        |   17 ++
>  src/org/libvirt/ErrorHandler.java                |   11 +-
>  src/org/libvirt/Network.java                     |    8 +-
>  src/org/libvirt/NodeInfo.java                    |    4 +-
>  src/org/libvirt/SchedBooleanParameter.java       |   20 ++-
>  src/org/libvirt/SchedDoubleParameter.java        |   13 +
>  src/org/libvirt/SchedIntParameter.java           |   13 +
>  src/org/libvirt/SchedLongParameter.java          |   14 +
>  src/org/libvirt/SchedParameter.java              |   43 +++
>  src/org/libvirt/SchedUintParameter.java          |   13 +
>  src/org/libvirt/SchedUlongParameter.java         |   13 +
>  src/org/libvirt/VcpuInfo.java                    |   13 +
>  src/org/libvirt/jna/Libvirt.java                 |   42 +++-
>  src/org/libvirt/jna/virDomainBlockStats.java     |   12 +
>  src/org/libvirt/jna/virDomainInfo.java           |   13 +
>  src/org/libvirt/jna/virDomainInterfaceStats.java |   16 ++
>  src/org/libvirt/jna/virSchedParameter.java       |   11 +
>  src/org/libvirt/jna/virSchedParameterValue.java  |   13 +
>  src/org/libvirt/jna/virVcpuInfo.java             |   12 +
>  src/test.java                                    |  154 ++++++-----
>  24 files changed, 595 insertions(+), 203 deletions(-)
>  create mode 100644 src/org/libvirt/jna/virDomainBlockStats.java
>  create mode 100644 src/org/libvirt/jna/virDomainInfo.java
>  create mode 100644 src/org/libvirt/jna/virDomainInterfaceStats.java
>  create mode 100644 src/org/libvirt/jna/virSchedParameter.java
>  create mode 100644 src/org/libvirt/jna/virSchedParameterValue.java
>  create mode 100644 src/org/libvirt/jna/virVcpuInfo.java
[...]
>      }
> +    
> +    public static int[] convertUUIDBytes(byte bytes[]) {
> +        int[] returnValue = new int[Libvirt.VIR_UUID_BUFLEN] ;
> +        for (int x = 0 ; x < Libvirt.VIR_UUID_BUFLEN ; x++) {
> +            returnValue[x] = (int) bytes[x] ;
> +        }
> +        return returnValue ;
> +    }
> +                      

  bahh, it's not too bad :-)

[..]
> +import com.sun.jna.ptr.IntByReference;
[..]
>  	public boolean getAutostart() throws LibvirtException{
> -//		return _getAutostart(VDP);
> -        throw new RuntimeException("Not Implemented") ;	    
> +        IntByReference autoStart = new IntByReference() ;
> +        libvirt.virDomainGetAutostart(VDP, autoStart) ;
> +        processError() ;        
> +        return autoStart.getValue() != 0 ? true : false ; 
>  	}

  oh, it can handle int * ... cool :-)

[...]
>  	public SchedParameter[] getSchedulerParameters() throws LibvirtException{
> -//		return _getSchedulerParameters(VDP);
> -        throw new RuntimeException("Not Implemented") ;	    
> +	    IntByReference nParams = new IntByReference() ;
> +	    SchedParameter[] returnValue = new SchedParameter[0] ; 
> +	    String scheduler = libvirt.virDomainGetSchedulerType(VDP, nParams) ;
> +	    processError() ;
> +	    if (scheduler != null) {
> +	        virSchedParameter[] nativeParams = new virSchedParameter[nParams.getValue()] ;
> +	        returnValue = new SchedParameter[nParams.getValue()] ;
> +	        libvirt.virDomainGetSchedulerParameters(VDP, nativeParams, nParams) ;
> +	        processError() ;
> +	        for (int x = 0 ; x < nParams.getValue() ; x++ ) {
> +	            returnValue[x] = SchedParameter.create(nativeParams[x]) ;
> +	        }
> +	    } 
> +	    
> +	    return returnValue ;
>  	}
>  
> -//	private native SchedParameter[] _getSchedulerParameters (long VDP) throws LibvirtException;
>  
>  	/**
>  	 * Changes the scheduler parameters
> @@ -220,11 +248,16 @@ public class Domain {
>  	 * @throws LibvirtException
>  	 */
>  	public void setSchedulerParameters(SchedParameter[] params) throws LibvirtException{
> -//		_setSchedulerParameters(VDP, params);
> -        throw new RuntimeException("Not Implemented") ;	    
> +        IntByReference nParams = new IntByReference() ;
> +        nParams.setValue(params.length) ;
> +        virSchedParameter[] input = new virSchedParameter[params.length] ; 
> +        for (int x = 0 ; x < params.length ; x++) {
> +            input[x] = SchedParameter.toNative(params[x]) ;
> +        }
> +        libvirt.virDomainSetSchedulerParameters(VDP, input, nParams) ;
> +        processError() ;	    
>  	}

  Get and SetSchedulerParameters are the most free-form APIs in libvirt,
if that's all it takes, I would say congrats to JNA design,  of course
there is a separate classes for them but they are really simple and the
the result looks natural, great !

[...]
> +++ b/src/org/libvirt/jna/virDomainBlockStats.java
> @@ -0,0 +1,12 @@
> +package org.libvirt.jna;
> +
> +import com.sun.jna.Structure;
> +
> +public class virDomainBlockStats extends Structure
> +{
> +    public long rd_req ;
> +    public long rd_bytes ;    
> +    public long wr_req ;
> +    public long wr_bytes ;    
> +    public long errs ;    
> +}

  Hum ... in C we have

struct _virDomainBlockStats {
  long long rd_req; /* number of read requests */
  long long rd_bytes; /* number of read bytes */
  long long wr_req; /* number of write requests */
  long long wr_bytes; /* number of written bytes */
  long long errs;   /* In Xen this returns the mysterious 'oo_req'. */
};

  will java long really be able to match C long long scope ?

> +package org.libvirt.jna;
> +
> +import com.sun.jna.Structure;
> +
> +public class virDomainInterfaceStats extends Structure
> +{
> +    public long rx_bytes;
> +    public long rx_packets;
> +    public long rx_errs;
> +    public long rx_drop;
> +    public long tx_bytes;
> +    public long tx_packets;
> +    public long tx_errs;
> +    public long tx_drop;
> +    
> +}

  and same question here.

  Except for this question looks fine, ACK !

Daniel

-- 
Daniel Veillard      | libxml Gnome XML XSLT toolkit  http://xmlsoft.org/
daniel veillard com  | Rpmfind RPM search engine http://rpmfind.net/
http://veillard.com/ | virtualization library  http://libvirt.org/


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]