diff options
author | Hans de Goede <hdegoede@redhat.com> | 2014-02-02 15:28:31 +0100 |
---|---|---|
committer | Hans de Goede <hdegoede@redhat.com> | 2014-03-03 08:13:55 +0100 |
commit | bc9d17fb566d57eabe4a3372773654fcf6ae5b44 (patch) | |
tree | c6ef15f558f5c0582e3b87bcdf4c564036711a99 /config | |
parent | 350559dcdcd8b0de57801302e385e25debcb91f1 (diff) |
OdevAttribute: Add support for integer attributes
Add a couple of new functions for dealing with storing integer values into
OdevAttributes.
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Dave Airlie <airlied@redhat.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Diffstat (limited to 'config')
-rw-r--r-- | config/config.c | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/config/config.c b/config/config.c index 776f1d850..ea2f744fa 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; } @@ -185,9 +205,32 @@ 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 %s called for non string attrib %d\n", + __func__, attrib_id); + 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 %s called for non integer attrib %d\n", + __func__, attrib_id); + return def; + } + + return oa->attrib_value; +} + void config_odev_free_attributes(struct OdevAttributes *attribs) { |