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

Re: [libvirt] [PATCH 1/7] libvirt.h: consolidate typed parameter handling



On Tue, May 17, 2011 at 04:42:09PM -0600, Eric Blake wrote:
> * include/libvirt/libvirt.h.in (virTypedParameterType)
> (VIR_TYPED_PARAM_FIELD_LENGTH, _virTypedParameter): New enum,
> macro, and type.
> (virSchedParameter, virBlkioParameter, virMemoryParameter):
> Rewrite in terms of a common type, while keeping all old public
> names for backwards compatibility.
> (struct _virSchedParameter, struct _virBlkioParameter)
> (struct _virMemoryParameter): Delete - these are private names.
> * python/generator.py (enum): Cope with the refactoring.
> ---
>  include/libvirt/libvirt.h.in |  144 +++++++++++++++++++++++------------------
>  python/generator.py          |   12 ++++
>  2 files changed, 93 insertions(+), 63 deletions(-)
> 
> diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
> index a174201..7cd6e13 100644
> --- a/include/libvirt/libvirt.h.in
> +++ b/include/libvirt/libvirt.h.in
> @@ -281,18 +281,70 @@ struct _virNodeInfo {
>  };
> 
> 
> +/* Common data types shared among interfaces with name/type/value lists.  */
> +
> +/**
> + * virTypedParameterType:
> + *
> + * Express the type of a virTypedParameter
> + */
> +typedef enum {
> +    VIR_TYPED_PARAM_INT     = 1, /* integer case */
> +    VIR_TYPED_PARAM_UINT    = 2, /* unsigned integer case */
> +    VIR_TYPED_PARAM_LLONG   = 3, /* long long case */
> +    VIR_TYPED_PARAM_ULLONG  = 4, /* unsigned long long case */
> +    VIR_TYPED_PARAM_DOUBLE  = 5, /* double case */
> +    VIR_TYPED_PARAM_BOOLEAN = 6  /* boolean(character) case */
> +} virTypedParameterType;
> +
> +/**
> + * VIR_TYPED_PARAM_FIELD_LENGTH:
> + *
> + * Macro providing the field length of virTypedParameter name
> + */
> +#define VIR_TYPED_PARAM_FIELD_LENGTH 80
> +
> +/**
> + * virTypedParameter:
> + *
> + * A named parameter, including a type and value.
> + */
> +typedef struct _virTypedParameter virTypedParameter;
> +
> +struct _virTypedParameter {
> +    char field[VIR_TYPED_PARAM_FIELD_LENGTH];  /* parameter name */
> +    int type;   /* parameter type, virTypedParameterType */

virTypedParameterType type; ?

> +    union {
> +        int i;                      /* type is INT */
> +        unsigned int ui;            /* type is UINT */
> +        long long int l;            /* type is LLONG */
> +        unsigned long long int ul;  /* type is ULLONG */
> +        double d;                   /* type is DOUBLE */
> +        char b;                     /* type is BOOLEAN */
> +    } value; /* parameter value */
> +};
> +
> +/**
> + * virTypedParameterPtr:
> + *
> + * a pointer to a virTypedParameter structure.
> + */
> +typedef virTypedParameter *virTypedParameterPtr;
> +
> +/* Management of scheduler parameters */
> +
>  /**
>   * virDomainSchedParameterType:
>   *
>   * A scheduler parameter field type
>   */
>  typedef enum {
> -    VIR_DOMAIN_SCHED_FIELD_INT     = 1, /* integer case */
> -    VIR_DOMAIN_SCHED_FIELD_UINT    = 2, /* unsigned integer case */
> -    VIR_DOMAIN_SCHED_FIELD_LLONG   = 3, /* long long case */
> -    VIR_DOMAIN_SCHED_FIELD_ULLONG  = 4, /* unsigned long long case */
> -    VIR_DOMAIN_SCHED_FIELD_DOUBLE  = 5, /* double case */
> -    VIR_DOMAIN_SCHED_FIELD_BOOLEAN = 6  /* boolean(character) case */
> +    VIR_DOMAIN_SCHED_FIELD_INT     = VIR_TYPED_PARAM_INT,
> +    VIR_DOMAIN_SCHED_FIELD_UINT    = VIR_TYPED_PARAM_UINT,
> +    VIR_DOMAIN_SCHED_FIELD_LLONG   = VIR_TYPED_PARAM_LLONG,
> +    VIR_DOMAIN_SCHED_FIELD_ULLONG  = VIR_TYPED_PARAM_ULLONG,
> +    VIR_DOMAIN_SCHED_FIELD_DOUBLE  = VIR_TYPED_PARAM_DOUBLE,
> +    VIR_DOMAIN_SCHED_FIELD_BOOLEAN = VIR_TYPED_PARAM_BOOLEAN,
>  } virSchedParameterType;

Can we remove VIR_DOMAIN_SCHED_FIELD_XXX and use VIR_TYPED_PARAM_XXX
directly since parameter types are basically types like int, long, ...
and don't depend on what parameters are?

Likewise for other PARAMs in this patch.

> 
>  typedef enum {
> @@ -307,7 +359,7 @@ typedef enum {
>   * Macro providing the field length of virSchedParameter
>   */
> 
> -#define VIR_DOMAIN_SCHED_FIELD_LENGTH 80
> +#define VIR_DOMAIN_SCHED_FIELD_LENGTH VIR_TYPED_PARAM_FIELD_LENGTH
> 
>  /**
>   * virDomainSchedParameter:
> @@ -315,20 +367,7 @@ typedef enum {
>   * a virDomainSchedParameter is the set of scheduler parameters
>   */
> 
> -typedef struct _virSchedParameter virSchedParameter;
> -
> -struct _virSchedParameter {
> -    char field[VIR_DOMAIN_SCHED_FIELD_LENGTH];  /* parameter name */
> -    int type;   /* parameter type */
> -    union {
> -        int i;                          /* data for integer case */
> -        unsigned int ui;        /* data for unsigned integer case */
> -        long long int l;        /* data for long long integer case */
> -        unsigned long long int ul;      /* data for unsigned long long integer case */
> -        double d;       /* data for double case */
> -        char b;         /* data for char case */
> -    } value; /* parameter value */
> -};
> +typedef struct _virTypedParameter virSchedParameter;
> 
>  /**
>   * virSchedParameterPtr:
> @@ -758,18 +797,21 @@ int                     virDomainGetState       (virDomainPtr domain,
>   */
>  char *                  virDomainGetSchedulerType(virDomainPtr domain,
>                                                   int *nparams);
> +
> +/* Manage blkio parameters.  */
> +
>  /**
>   * virDomainBlkioParameterType:
>   *
>   * A blkio parameter field type
>   */
>  typedef enum {
> -    VIR_DOMAIN_BLKIO_PARAM_INT     = 1, /* integer case */
> -    VIR_DOMAIN_BLKIO_PARAM_UINT    = 2, /* unsigned integer case */
> -    VIR_DOMAIN_BLKIO_PARAM_LLONG   = 3, /* long long case */
> -    VIR_DOMAIN_BLKIO_PARAM_ULLONG  = 4, /* unsigned long long case */
> -    VIR_DOMAIN_BLKIO_PARAM_DOUBLE  = 5, /* double case */
> -    VIR_DOMAIN_BLKIO_PARAM_BOOLEAN = 6  /* boolean(character) case */
> +    VIR_DOMAIN_BLKIO_PARAM_INT     = VIR_TYPED_PARAM_INT,
> +    VIR_DOMAIN_BLKIO_PARAM_UINT    = VIR_TYPED_PARAM_UINT,
> +    VIR_DOMAIN_BLKIO_PARAM_LLONG   = VIR_TYPED_PARAM_LLONG,
> +    VIR_DOMAIN_BLKIO_PARAM_ULLONG  = VIR_TYPED_PARAM_ULLONG,
> +    VIR_DOMAIN_BLKIO_PARAM_DOUBLE  = VIR_TYPED_PARAM_DOUBLE,
> +    VIR_DOMAIN_BLKIO_PARAM_BOOLEAN = VIR_TYPED_PARAM_BOOLEAN,
>  } virBlkioParameterType;
> 
>  /**
> @@ -778,7 +820,7 @@ typedef enum {
>   * Macro providing the field length of virBlkioParameter
>   */
> 
> -#define VIR_DOMAIN_BLKIO_FIELD_LENGTH 80
> +#define VIR_DOMAIN_BLKIO_FIELD_LENGTH VIR_TYPED_PARAM_FIELD_LENGTH
> 
>  /**
>   * VIR_DOMAIN_BLKIO_WEIGHT:
> @@ -795,20 +837,7 @@ typedef enum {
>   * a virDomainBlkioParameter is the set of blkio parameters
>   */
> 
> -typedef struct _virBlkioParameter virBlkioParameter;
> -
> -struct _virBlkioParameter {
> -    char field[VIR_DOMAIN_BLKIO_FIELD_LENGTH];  /* parameter name */
> -    int type;   /* parameter type */
> -    union {
> -        int i;                          /* data for integer case */
> -        unsigned int ui;        /* data for unsigned integer case */
> -        long long int l;        /* data for long long integer case */
> -        unsigned long long int ul;      /* data for unsigned long long integer case */
> -        double d;       /* data for double case */
> -        char b;         /* data for char case */
> -    } value; /* parameter value */
> -};
> +typedef struct _virTypedParameter virBlkioParameter;
> 
>  /**
>   * virBlkioParameterPtr:
> @@ -826,18 +855,20 @@ int     virDomainGetBlkioParameters(virDomainPtr domain,
>                                       virBlkioParameterPtr params,
>                                       int *nparams, unsigned int flags);
> 
> +/* Manage memory parameters.  */
> +
>  /**
>   * virDomainMemoryParameterType:
>   *
>   * A memory parameter field type
>   */
>  typedef enum {
> -    VIR_DOMAIN_MEMORY_PARAM_INT     = 1, /* integer case */
> -    VIR_DOMAIN_MEMORY_PARAM_UINT    = 2, /* unsigned integer case */
> -    VIR_DOMAIN_MEMORY_PARAM_LLONG   = 3, /* long long case */
> -    VIR_DOMAIN_MEMORY_PARAM_ULLONG  = 4, /* unsigned long long case */
> -    VIR_DOMAIN_MEMORY_PARAM_DOUBLE  = 5, /* double case */
> -    VIR_DOMAIN_MEMORY_PARAM_BOOLEAN = 6  /* boolean(character) case */
> +    VIR_DOMAIN_MEMORY_PARAM_INT     = VIR_TYPED_PARAM_INT,
> +    VIR_DOMAIN_MEMORY_PARAM_UINT    = VIR_TYPED_PARAM_UINT,
> +    VIR_DOMAIN_MEMORY_PARAM_LLONG   = VIR_TYPED_PARAM_LLONG,
> +    VIR_DOMAIN_MEMORY_PARAM_ULLONG  = VIR_TYPED_PARAM_ULLONG,
> +    VIR_DOMAIN_MEMORY_PARAM_DOUBLE  = VIR_TYPED_PARAM_DOUBLE,
> +    VIR_DOMAIN_MEMORY_PARAM_BOOLEAN = VIR_TYPED_PARAM_BOOLEAN,
>  } virMemoryParameterType;
> 
>  /**
> @@ -846,7 +877,7 @@ typedef enum {
>   * Macro providing the field length of virMemoryParameter
>   */
> 
> -#define VIR_DOMAIN_MEMORY_FIELD_LENGTH 80
> +#define VIR_DOMAIN_MEMORY_FIELD_LENGTH VIR_TYPED_PARAM_FIELD_LENGTH
> 
>  /**
>   * VIR_DOMAIN_MEMORY_PARAM_UNLIMITED:
> @@ -899,20 +930,7 @@ typedef enum {
>   * a virDomainMemoryParameter is the set of scheduler parameters
>   */
> 
> -typedef struct _virMemoryParameter virMemoryParameter;
> -
> -struct _virMemoryParameter {
> -    char field[VIR_DOMAIN_MEMORY_FIELD_LENGTH];  /* parameter name */
> -    int type;   /* parameter type */
> -    union {
> -        int i;                          /* data for integer case */
> -        unsigned int ui;        /* data for unsigned integer case */
> -        long long int l;        /* data for long long integer case */
> -        unsigned long long int ul;      /* data for unsigned long long integer case */
> -        double d;       /* data for double case */
> -        char b;         /* data for char case */
> -    } value; /* parameter value */
> -};
> +typedef struct _virTypedParameter virMemoryParameter;
> 
>  /**
>   * virMemoryParameterPtr:
> diff --git a/python/generator.py b/python/generator.py
> index 9f9deb2..1741bba 100755
> --- a/python/generator.py
> +++ b/python/generator.py
> @@ -154,6 +154,18 @@ def function(name, desc, ret, args, file, cond):
>  def enum(type, name, value):
>      if not enums.has_key(type):
>          enums[type] = {}
> +    if value == 'VIR_TYPED_PARAM_INT':
> +        value = 1
> +    elif value == 'VIR_TYPED_PARAM_UINT':
> +        value = 2
> +    elif value == 'VIR_TYPED_PARAM_LLONG':
> +        value = 3
> +    elif value == 'VIR_TYPED_PARAM_ULLONG':
> +        value = 4
> +    elif value == 'VIR_TYPED_PARAM_DOUBLE':
> +        value = 5
> +    elif value == 'VIR_TYPED_PARAM_BOOLEAN':
> +        value = 6
>      enums[type][name] = value
> 
>  #######################################################################
> -- 
> 1.7.4.4
> 
> --
> libvir-list mailing list
> libvir-list redhat com
> https://www.redhat.com/mailman/listinfo/libvir-list


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