From: "Zeeshan Ali (Khattak)" <zeeshanak@xxxxxxxxx> Add: * osinfo_entity_get_param_value_enum * osinfo_entity_set_param_enum --- osinfo/libosinfo.syms | 3 +++ osinfo/osinfo_entity.c | 39 +++++++++++++++++++++++++++++++++++++++ osinfo/osinfo_entity.h | 5 +++++ 3 files changed, 47 insertions(+) diff --git a/osinfo/libosinfo.syms b/osinfo/libosinfo.syms index 2d28388..d291d7e 100644 --- a/osinfo/libosinfo.syms +++ b/osinfo/libosinfo.syms @@ -320,6 +320,9 @@ LIBOSINFO_0.2.2 { osinfo_install_config_param_policy_get_type; osinfo_media_error_get_type; osinfo_product_relationship_get_type; + + osinfo_entity_get_param_value_enum; + osinfo_entity_set_param_enum; } LIBOSINFO_0.2.1; diff --git a/osinfo/osinfo_entity.c b/osinfo/osinfo_entity.c index 33c73ea..9fabc46 100644 --- a/osinfo/osinfo_entity.c +++ b/osinfo/osinfo_entity.c @@ -211,6 +211,20 @@ void osinfo_entity_set_param_int64(OsinfoEntity *entity, const gchar *key, gint6 g_free(str); } +void osinfo_entity_set_param_enum(OsinfoEntity *entity, const gchar *key, gint value, GType enum_type) +{ + GEnumClass *enum_class; + GEnumValue *enum_value; + + g_return_if_fail(G_TYPE_IS_ENUM (enum_type)); + + enum_class = g_type_class_ref(enum_type); + enum_value = g_enum_get_value(enum_class, value); + g_type_class_unref(enum_class); + + osinfo_entity_set_param(entity, key, enum_value->value_nick); +} + /** * osinfo_entity_add_param: * @entity: OsinfoEntity containing the parameters @@ -373,6 +387,31 @@ gint64 osinfo_entity_get_param_value_int64_with_default(OsinfoEntity *entity, return value; } +gint osinfo_entity_get_param_value_enum(OsinfoEntity *entity, + const char *key, + GType enum_type, + gint default_value) +{ + const gchar *nick; + GEnumClass *enum_class; + GEnumValue *enum_value; + + g_return_val_if_fail(G_TYPE_IS_ENUM(enum_type), default_value); + + nick = osinfo_entity_get_param_value(entity, key); + if (nick == NULL) + return default_value; + + enum_class = g_type_class_ref(enum_type); + enum_value = g_enum_get_value_by_nick(enum_class, nick); + g_type_class_unref(enum_class); + + if (enum_value != NULL) + return enum_value->value; + + g_return_val_if_reached(default_value); +} + /** * osinfo_entity_get_param_value_list: * @entity: OsinfoEntity containing the parameters diff --git a/osinfo/osinfo_entity.h b/osinfo/osinfo_entity.h index 9ab97a9..7a2654c 100644 --- a/osinfo/osinfo_entity.h +++ b/osinfo/osinfo_entity.h @@ -74,6 +74,10 @@ gboolean osinfo_entity_get_param_value_boolean(OsinfoEntity *entity, const gchar gboolean osinfo_entity_get_param_value_boolean_with_default(OsinfoEntity *entity, const char *key, gboolean default_value); +gint osinfo_entity_get_param_value_enum(OsinfoEntity *entity, + const char *key, + GType enum_type, + gint default_value); gint64 osinfo_entity_get_param_value_int64(OsinfoEntity *entity, const gchar *key); gint64 osinfo_entity_get_param_value_int64_with_default(OsinfoEntity *entity, const gchar *key, @@ -82,6 +86,7 @@ GList *osinfo_entity_get_param_value_list(OsinfoEntity *entity, const gchar *key void osinfo_entity_set_param(OsinfoEntity *entity, const gchar *key, const gchar *value); void osinfo_entity_set_param_boolean(OsinfoEntity *entity, const gchar *key, gboolean value); void osinfo_entity_set_param_int64(OsinfoEntity *entity, const gchar *key, gint64 value); +void osinfo_entity_set_param_enum(OsinfoEntity *entity, const gchar *key, gint value, GType enum_type); void osinfo_entity_add_param(OsinfoEntity *entity, const gchar *key, const gchar *value); void osinfo_entity_clear_param(OsinfoEntity *entity, const gchar *key); -- 1.8.0