[PATCH v2 07/14] OdevAttribute: Add support for integer attributes

Peter Hutterer peter.hutterer at who-t.net
Tue Feb 11 06:55:42 CET 2014


On Tue, Feb 04, 2014 at 12:49:13PM +0100, Hans de Goede wrote:
> Add a couple of new functions for dealing with storing integer values into
> OdevAttributes.
> 
> Signed-off-by: Hans de Goede <hdegoede at redhat.com>
> ---
>  config/config.c                     | 40 +++++++++++++++++++++++++++++++++++++
>  hw/xfree86/common/xf86platformBus.c | 18 +++++++++++++++++
>  hw/xfree86/common/xf86platformBus.h |  6 ++++++
>  include/hotplug.h                   | 16 ++++++++++++++-
>  4 files changed, 79 insertions(+), 1 deletion(-)
> 
> diff --git a/config/config.c b/config/config.c
> index aaef746..5833992 100644
> --- a/config/config.c
> +++ b/config/config.c
> @@ -172,6 +172,26 @@ config_odev_add_attribute(struct OdevAttributes *attribs, int attrib,
>      oa->attrib_id = attrib;
>      free(oa->attrib_name);
>      oa->attrib_name = strdup(attrib_name);
> +    oa->attrib_type = odev_attrib_string;
> +    xorg_list_append(&oa->member, &attribs->list);
> +    return TRUE;
> +}
> +
> +Bool
> +config_odev_add_int_attribute(struct OdevAttributes *attribs, int attrib,
> +                              int attrib_value)
> +{
> +    struct OdevAttribute *oa;
> +
> +    oa = config_odev_find_attribute(attribs, attrib);
> +    if (!oa)
> +        oa = calloc(1, sizeof(struct OdevAttribute));
> +    if (!oa)
> +        return FALSE;
> +
> +    oa->attrib_id = attrib;
> +    oa->attrib_value = attrib_value;
> +    oa->attrib_type = odev_attrib_int;
>      xorg_list_append(&oa->member, &attribs->list);
>      return TRUE;
>  }
> @@ -184,9 +204,29 @@ char *config_odev_get_attribute(struct OdevAttributes *attribs, int attrib_id)
>      if (!oa)
>          return NULL;
>  
> +    if (oa->attrib_type != odev_attrib_string) {
> +        LogMessage(X_ERROR, "Error config_odev_get_attribute called for non string attrib %d\n", attrib_id);

these error messages have a tendency to become outdated, let's use __func__
here please. 

> +        return NULL;
> +    }
>      return oa->attrib_name;
>  }
>  
> +int config_odev_get_int_attribute(struct OdevAttributes *attribs, int attrib_id, int def)
> +{
> +    struct OdevAttribute *oa;
> +
> +    oa = config_odev_find_attribute(attribs, attrib_id);
> +    if (!oa)
> +        return def;
> +
> +    if (oa->attrib_type != odev_attrib_int) {
> +        LogMessage(X_ERROR, "Error config_odev_get_int_attribute called for non int attrib %d\n", attrib_id);

same here.

otherwise, Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>

Cheers,
   Peter

> +        return def;
> +    }
> +
> +    return oa->attrib_value;
> +}
> +
>  void
>  config_odev_free_attributes(struct OdevAttributes *attribs)
>  {
> diff --git a/hw/xfree86/common/xf86platformBus.c b/hw/xfree86/common/xf86platformBus.c
> index 6d3816d..7a9600a 100644
> --- a/hw/xfree86/common/xf86platformBus.c
> +++ b/hw/xfree86/common/xf86platformBus.c
> @@ -89,6 +89,12 @@ xf86_add_platform_device_attrib(int index, int attrib_id, char *attrib_name)
>      return config_odev_add_attribute(device->attribs, attrib_id, attrib_name);
>  }
>  
> +Bool
> +xf86_add_platform_device_int_attrib(int index, int attrib_id, int attrib_value)
> +{
> +    return config_odev_add_int_attribute(xf86_platform_devices[index].attribs, attrib_id, attrib_value);
> +}
> +
>  char *
>  xf86_get_platform_attrib(int index, int attrib_id)
>  {
> @@ -101,6 +107,18 @@ xf86_get_platform_device_attrib(struct xf86_platform_device *device, int attrib_
>      return config_odev_get_attribute(device->attribs, attrib_id);
>  }
>  
> +int
> +xf86_get_platform_int_attrib(int index, int attrib_id, int def)
> +{
> +    return config_odev_get_int_attribute(xf86_platform_devices[index].attribs, attrib_id, def);
> +}
> +
> +int
> +xf86_get_platform_device_int_attrib(struct xf86_platform_device *device, int attrib_id, int def)
> +{
> +    return config_odev_get_int_attribute(device->attribs, attrib_id, def);
> +}
> +
>  Bool
>  xf86_get_platform_device_unowned(int index)
>  {
> diff --git a/hw/xfree86/common/xf86platformBus.h b/hw/xfree86/common/xf86platformBus.h
> index 4e17578..d764026 100644
> --- a/hw/xfree86/common/xf86platformBus.h
> +++ b/hw/xfree86/common/xf86platformBus.h
> @@ -41,12 +41,16 @@ extern int xf86_num_platform_devices;
>  extern char *
>  xf86_get_platform_attrib(int index, int attrib_id);
>  extern int
> +xf86_get_platform_int_attrib(int index, int attrib_id, int def);
> +extern int
>  xf86_add_platform_device(struct OdevAttributes *attribs);
>  extern int
>  xf86_remove_platform_device(int dev_index);
>  extern Bool
>  xf86_add_platform_device_attrib(int index, int attrib_id, char *attrib_str);
>  extern Bool
> +xf86_add_platform_device_int_attrib(int index, int attrib_id, int attrib_value);
> +extern Bool
>  xf86_get_platform_device_unowned(int index);
>  
>  extern int
> @@ -56,6 +60,8 @@ xf86platformRemoveDevice(int index);
>  
>  extern _X_EXPORT char *
>  xf86_get_platform_device_attrib(struct xf86_platform_device *device, int attrib_id);
> +extern _X_EXPORT int
> +xf86_get_platform_device_int_attrib(struct xf86_platform_device *device, int attrib_id, int def);
>  extern _X_EXPORT Bool
>  xf86PlatformDeviceCheckBusID(struct xf86_platform_device *device, const char *busid);
>  
> diff --git a/include/hotplug.h b/include/hotplug.h
> index ee7b7d7..6aa7d8d 100644
> --- a/include/hotplug.h
> +++ b/include/hotplug.h
> @@ -32,10 +32,16 @@ extern _X_EXPORT void config_pre_init(void);
>  extern _X_EXPORT void config_init(void);
>  extern _X_EXPORT void config_fini(void);
>  
> +enum { odev_attrib_string, odev_attrib_int };

I personally prefer uppercase enum values, it's a lot more obvious in the
code.

> +
>  struct OdevAttribute {
>      struct xorg_list member;
>      int attrib_id;
> -    char *attrib_name;
> +    union {
> +        char *attrib_name;
> +        int attrib_value;
> +    };
> +    int attrib_type;
>  };
>  
>  struct OdevAttributes {
> @@ -56,6 +62,14 @@ config_odev_add_attribute(struct OdevAttributes *attribs, int attrib,
>  char *
>  config_odev_get_attribute(struct OdevAttributes *attribs, int attrib_id);
>  
> +Bool
> +config_odev_add_int_attribute(struct OdevAttributes *attribs, int attrib,
> +                              int attrib_value);
> +
> +int
> +config_odev_get_int_attribute(struct OdevAttributes *attribs, int attrib,
> +                              int def);
> +
>  void
>  config_odev_free_attributes(struct OdevAttributes *attribs);
>  


More information about the xorg-devel mailing list