diff options
author | Daniel P. Berrange <berrange@redhat.com> | 2010-08-13 12:59:24 -0400 |
---|---|---|
committer | Daniel P. Berrange <berrange@redhat.com> | 2010-08-25 15:21:45 +0100 |
commit | 5b91c4f6f19eb76e1b0a864fe3eb122ebb832bd5 (patch) | |
tree | 4e66012efb4f2d88979fa4f81a936cf059860ea7 /osinfo | |
parent | 991b87d7882966694b1ea545f9c1d612cc8e94c2 (diff) | |
download | libosinfo-5b91c4f6f19eb76e1b0a864fe3eb122ebb832bd5.tar.gz |
Remove GError from most APIs
GLib documents that GError should only be used for recoverable
runtime errors, not programmer errors. The latter should use
g_return_val_if_fail / g_return_if_fail macros to display the
programmer error
* osinfo/osinfo_common.c, osinfo/osinfo_common.h,
osinfo/osinfo_db.c, osinfo/osinfo_db.h,
osinfo/osinfo_device.c, osinfo/osinfo_device.h,
osinfo/osinfo_entity.c, osinfo/osinfo_entity.h,
osinfo/osinfo_filter.c, osinfo/osinfo_filter.h,
osinfo/osinfo_hypervisor.c, osinfo/osinfo_hypervisor.h,
osinfo/osinfo_os.c, osinfo/osinfo_os.h: Remove GError
from most public APIs
Diffstat (limited to 'osinfo')
-rw-r--r-- | osinfo/osinfo_common.c | 13 | ||||
-rw-r--r-- | osinfo/osinfo_common.h | 12 | ||||
-rw-r--r-- | osinfo/osinfo_db.c | 178 | ||||
-rw-r--r-- | osinfo/osinfo_db.h | 20 | ||||
-rw-r--r-- | osinfo/osinfo_device.c | 29 | ||||
-rw-r--r-- | osinfo/osinfo_device.h | 2 | ||||
-rw-r--r-- | osinfo/osinfo_entity.c | 86 | ||||
-rw-r--r-- | osinfo/osinfo_entity.h | 8 | ||||
-rw-r--r-- | osinfo/osinfo_filter.c | 106 | ||||
-rw-r--r-- | osinfo/osinfo_filter.h | 10 | ||||
-rw-r--r-- | osinfo/osinfo_hypervisor.c | 35 | ||||
-rw-r--r-- | osinfo/osinfo_hypervisor.h | 4 | ||||
-rw-r--r-- | osinfo/osinfo_os.c | 72 | ||||
-rw-r--r-- | osinfo/osinfo_os.h | 6 |
14 files changed, 113 insertions, 468 deletions
diff --git a/osinfo/osinfo_common.c b/osinfo/osinfo_common.c index bb9b680..63ce203 100644 --- a/osinfo/osinfo_common.c +++ b/osinfo/osinfo_common.c @@ -296,19 +296,6 @@ int __osinfoHypervisorPassesFilter(OsinfoFilter *filter, OsinfoHypervisor *hyper return __osinfoEntityPassesFilter(filter, OSINFO_ENTITY (hypervisor)); } -int __osinfoCheckGErrorParamValid(GError **err) -{ - // If err is not null and *err is not null, then invalid - if (err && *err) - return 0; - else return 1; -} - -int __osinfoCheckRelationshipValid(osinfoRelationship relshp) -{ - return (relshp > RELATIONSHIP_MIN && relshp < RELATIONSHIP_MAX); -} - gchar *__osinfoErrorToString(int err) { switch (err) { diff --git a/osinfo/osinfo_common.h b/osinfo/osinfo_common.h index 63f9432..7be6fd9 100644 --- a/osinfo/osinfo_common.h +++ b/osinfo/osinfo_common.h @@ -25,11 +25,9 @@ typedef struct _OsinfoFilter OsinfoFilter; typedef struct _OsinfoList OsinfoList; typedef enum OSI_RELATIONSHIP { - RELATIONSHIP_MIN = 0, DERIVES_FROM, UPGRADES, CLONES, - RELATIONSHIP_MAX } osinfoRelationship; @@ -61,11 +59,6 @@ struct __osinfoOsLink { OsinfoOs *directObjectOs; }; -struct __osinfoPtrArrayErr { - GPtrArray *array; - int err; -}; - struct __osinfoPopulateListArgs { OsinfoFilter *filter; OsinfoList *list; @@ -122,9 +115,6 @@ int __osinfoDevicePassesFilter(OsinfoFilter *filter, OsinfoDevice *device); int __osinfoOsPassesFilter(OsinfoFilter *filter, OsinfoOs *device); int __osinfoHypervisorPassesFilter(OsinfoFilter *filter, OsinfoHypervisor *device); -int __osinfoCheckGErrorParamValid(GError **err); -int __osinfoCheckRelationshipValid(osinfoRelationship relshp); - /** **************************************************************************** * Private structures for objects ******************************************************************************/ @@ -151,8 +141,6 @@ struct _OsinfoDbPrivate GTree *devices; GTree *hypervisors; GTree *oses; - - GError *error; }; struct _OsinfoDevicePrivate diff --git a/osinfo/osinfo_db.c b/osinfo/osinfo_db.c index e516f93..f509b02 100644 --- a/osinfo/osinfo_db.c +++ b/osinfo/osinfo_db.c @@ -17,7 +17,6 @@ enum OSI_DB_PROPERTIES { OSI_DB_BACKING_DIR, OSI_DB_LIBVIRT_VER, - OSI_DB_ERROR }; static void @@ -56,9 +55,6 @@ osinfo_db_set_property (GObject *object, self->priv->libvirt_ver = g_value_dup_string (value); break; - case OSI_DB_ERROR: - break; - default: /* We don't have any other property... */ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); @@ -84,10 +80,6 @@ osinfo_db_get_property (GObject *object, g_value_set_string (value, self->priv->libvirt_ver); break; - case OSI_DB_ERROR: - g_value_set_pointer(value, self->priv->error); - break; - default: /* We don't have any other property... */ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); @@ -124,14 +116,6 @@ osinfo_db_class_init (OsinfoDbClass *klass) OSI_DB_LIBVIRT_VER, pspec); - pspec = g_param_spec_pointer ("error", - "Error", - "GError object for db", - G_PARAM_READABLE); - g_object_class_install_property (g_klass, - OSI_DB_ERROR, - pspec); - g_type_class_add_private (klass, sizeof (OsinfoDbPrivate)); } @@ -146,7 +130,6 @@ osinfo_db_init (OsinfoDb *self) self->priv->hypervisors = g_tree_new_full(__osinfoStringCompare, NULL, g_free, g_object_unref); self->priv->oses = g_tree_new_full(__osinfoStringCompare, NULL, g_free, g_object_unref); - self->priv->error = NULL; self->priv->ready = 0; } @@ -174,56 +157,26 @@ int osinfo_db_initialize(OsinfoDb *self, GError **err) return ret; } -OsinfoHypervisor *osinfo_db_get_hypervisor(OsinfoDb *self, gchar *id, GError **err) +OsinfoHypervisor *osinfo_db_get_hypervisor(OsinfoDb *self, gchar *id) { - if (!__osinfoCheckGErrorParamValid(err)) - return NULL; - - if (!OSINFO_IS_DB(self)) { - g_set_error_literal(err, g_quark_from_static_string("libosinfo"), -EINVAL, OSINFO_OBJ_NOT_DB); - return NULL; - } - - if (!id) { - g_set_error_literal(err, g_quark_from_static_string("libosinfo"), -EINVAL, OSINFO_NO_ID); - return NULL; - } + g_return_val_if_fail(OSINFO_IS_DB(self), NULL); + g_return_val_if_fail(id != NULL, NULL); return g_tree_lookup(self->priv->hypervisors, id); } -OsinfoDevice *osinfo_db_get_device(OsinfoDb *self, gchar *id, GError **err) +OsinfoDevice *osinfo_db_get_device(OsinfoDb *self, gchar *id) { - if (!__osinfoCheckGErrorParamValid(err)) - return NULL; - - if (!OSINFO_IS_DB(self)) { - g_set_error_literal(err, g_quark_from_static_string("libosinfo"), -EINVAL, OSINFO_OBJ_NOT_DB); - return NULL; - } - - if (!id) { - g_set_error_literal(err, g_quark_from_static_string("libosinfo"), -EINVAL, OSINFO_NO_ID); - return NULL; - } + g_return_val_if_fail(OSINFO_IS_DB(self), NULL); + g_return_val_if_fail(id != NULL, NULL); return g_tree_lookup(self->priv->devices, id); } -OsinfoOs *osinfo_db_get_os(OsinfoDb *self, gchar *id, GError **err) +OsinfoOs *osinfo_db_get_os(OsinfoDb *self, gchar *id) { - if (!__osinfoCheckGErrorParamValid(err)) - return NULL; - - if (!OSINFO_IS_DB(self)) { - g_set_error_literal(err, g_quark_from_static_string("libosinfo"), -EINVAL, OSINFO_OBJ_NOT_DB); - return NULL; - } - - if (!id) { - g_set_error_literal(err, g_quark_from_static_string("libosinfo"), -EINVAL, OSINFO_NO_ID); - return NULL; - } + g_return_val_if_fail(OSINFO_IS_DB(self), NULL); + g_return_val_if_fail(id != NULL, NULL); return g_tree_lookup(self->priv->oses, id); } @@ -250,20 +203,10 @@ static void osinfo_db_populate_list(GTree *entities, OsinfoList *newList, Osinfo g_tree_foreach(entities, __osinfoFilteredAddToList, &args); } -OsinfoOsList *osinfo_db_get_os_list(OsinfoDb *self, OsinfoFilter *filter, GError **err) +OsinfoOsList *osinfo_db_get_os_list(OsinfoDb *self, OsinfoFilter *filter) { - if (!__osinfoCheckGErrorParamValid(err)) - return NULL; - - if (!OSINFO_IS_DB(self)) { - g_set_error_literal(err, g_quark_from_static_string("libosinfo"), -EINVAL, OSINFO_OBJ_NOT_DB); - return NULL; - } - - if (filter && !OSINFO_IS_FILTER(filter)) { - g_set_error_literal(err, g_quark_from_static_string("libosinfo"), -EINVAL, OSINFO_OBJ_NOT_FILTER); - return NULL; - } + g_return_val_if_fail(OSINFO_IS_DB(self), NULL); + g_return_val_if_fail(OSINFO_IS_FILTER(filter), NULL); // Create list OsinfoOsList *newList = g_object_new(OSINFO_TYPE_OSLIST, NULL); @@ -271,17 +214,10 @@ OsinfoOsList *osinfo_db_get_os_list(OsinfoDb *self, OsinfoFilter *filter, GError return newList; } -OsinfoHypervisorList *osinfo_db_get_hypervisor_list(OsinfoDb *self, OsinfoFilter *filter, GError **err) +OsinfoHypervisorList *osinfo_db_get_hypervisor_list(OsinfoDb *self, OsinfoFilter *filter) { - if (!OSINFO_IS_DB(self)) { - g_set_error_literal(err, g_quark_from_static_string("libosinfo"), -EINVAL, OSINFO_OBJ_NOT_DB); - return NULL; - } - - if (filter && !OSINFO_IS_FILTER(filter)) { - g_set_error_literal(err, g_quark_from_static_string("libosinfo"), -EINVAL, OSINFO_OBJ_NOT_FILTER); - return NULL; - } + g_return_val_if_fail(OSINFO_IS_DB(self), NULL); + g_return_val_if_fail(OSINFO_IS_FILTER(filter), NULL); // Create list OsinfoHypervisorList *newList = g_object_new(OSINFO_TYPE_HYPERVISORLIST, NULL); @@ -289,17 +225,10 @@ OsinfoHypervisorList *osinfo_db_get_hypervisor_list(OsinfoDb *self, OsinfoFilter return newList; } -OsinfoDeviceList *osinfo_db_get_device_list(OsinfoDb *self, OsinfoFilter *filter, GError **err) +OsinfoDeviceList *osinfo_db_get_device_list(OsinfoDb *self, OsinfoFilter *filter) { - if (!OSINFO_IS_DB(self)) { - g_set_error_literal(err, g_quark_from_static_string("libosinfo"), -EINVAL, OSINFO_OBJ_NOT_DB); - return NULL; - } - - if (filter && !OSINFO_IS_FILTER(filter)) { - g_set_error_literal(err, g_quark_from_static_string("libosinfo"), -EINVAL, OSINFO_OBJ_NOT_FILTER); - return NULL; - } + g_return_val_if_fail(OSINFO_IS_DB(self), NULL); + g_return_val_if_fail(OSINFO_IS_FILTER(filter), NULL); // Create list OsinfoDeviceList *newList = g_object_new(OSINFO_TYPE_DEVICELIST, NULL); @@ -346,7 +275,7 @@ static gboolean __osinfoPutKeysInList(gpointer key, gpointer value, gpointer dat } -static GPtrArray *osinfo_db_unique_values_for_property_in_entity(GTree *entities, gchar *propName, GError **err) +static GPtrArray *osinfo_db_unique_values_for_property_in_entity(GTree *entities, gchar *propName) { GTree *values = g_tree_new(__osinfoStringCompareBase); @@ -362,60 +291,30 @@ static GPtrArray *osinfo_db_unique_values_for_property_in_entity(GTree *entities } // Get me all unique values for property "vendor" among operating systems -GPtrArray *osinfo_db_unique_values_for_property_in_os(OsinfoDb *self, gchar *propName, GError **err) +GPtrArray *osinfo_db_unique_values_for_property_in_os(OsinfoDb *self, gchar *propName) { - if (!__osinfoCheckGErrorParamValid(err)) - return NULL; + g_return_val_if_fail(OSINFO_IS_DB(self), NULL); + g_return_val_if_fail(propName != NULL, NULL); - if (!OSINFO_IS_DB(self)) { - g_set_error_literal(err, g_quark_from_static_string("libosinfo"), -EINVAL, OSINFO_OBJ_NOT_DB); - return NULL; - } - - if (!propName) { - g_set_error_literal(err, g_quark_from_static_string("libosinfo"), -EINVAL, OSINFO_NO_PROPNAME); - return NULL; - } - - return osinfo_db_unique_values_for_property_in_entity(self->priv->oses, propName, err); + return osinfo_db_unique_values_for_property_in_entity(self->priv->oses, propName); } // Get me all unique values for property "vendor" among hypervisors -GPtrArray *osinfo_db_unique_values_for_property_in_hv(OsinfoDb *self, gchar *propName, GError **err) +GPtrArray *osinfo_db_unique_values_for_property_in_hv(OsinfoDb *self, gchar *propName) { - if (!__osinfoCheckGErrorParamValid(err)) - return NULL; - - if (!OSINFO_IS_DB(self)) { - g_set_error_literal(err, g_quark_from_static_string("libosinfo"), -EINVAL, OSINFO_OBJ_NOT_DB); - return NULL; - } - - if (!propName) { - g_set_error_literal(err, g_quark_from_static_string("libosinfo"), -EINVAL, OSINFO_NO_PROPNAME); - return NULL; - } + g_return_val_if_fail(OSINFO_IS_DB(self), NULL); + g_return_val_if_fail(propName != NULL, NULL); - return osinfo_db_unique_values_for_property_in_entity(self->priv->hypervisors, propName, err); + return osinfo_db_unique_values_for_property_in_entity(self->priv->hypervisors, propName); } // Get me all unique values for property "vendor" among devices -GPtrArray *osinfo_db_unique_values_for_property_in_dev(OsinfoDb *self, gchar *propName, GError **err) +GPtrArray *osinfo_db_unique_values_for_property_in_dev(OsinfoDb *self, gchar *propName) { - if (!__osinfoCheckGErrorParamValid(err)) - return NULL; + g_return_val_if_fail(OSINFO_IS_DB(self), NULL); + g_return_val_if_fail(propName != NULL, NULL); - if (!OSINFO_IS_DB(self)) { - g_set_error_literal(err, g_quark_from_static_string("libosinfo"), -EINVAL, OSINFO_OBJ_NOT_DB); - return NULL; - } - - if (!propName) { - g_set_error_literal(err, g_quark_from_static_string("libosinfo"), -EINVAL, OSINFO_NO_PROPNAME); - return NULL; - } - - return osinfo_db_unique_values_for_property_in_entity(self->priv->devices, propName, err); + return osinfo_db_unique_values_for_property_in_entity(self->priv->devices, propName); } static gboolean __osinfoAddOsIfRelationship(gpointer key, gpointer value, gpointer data) @@ -435,20 +334,9 @@ static gboolean __osinfoAddOsIfRelationship(gpointer key, gpointer value, gpoint } // Get me all OSes that 'upgrade' another OS (or whatever relationship is specified) -OsinfoOsList *osinfo_db_unique_values_for_os_relationship(OsinfoDb *self, osinfoRelationship relshp, GError **err) +OsinfoOsList *osinfo_db_unique_values_for_os_relationship(OsinfoDb *self, osinfoRelationship relshp) { - if (!__osinfoCheckGErrorParamValid(err)) - return NULL; - - if (!OSINFO_IS_DB(self)) { - g_set_error_literal(err, g_quark_from_static_string("libosinfo"), -EINVAL, OSINFO_OBJ_NOT_DB); - return NULL; - } - - if (!__osinfoCheckRelationshipValid(relshp)) { - g_set_error_literal(err, g_quark_from_static_string("libosinfo"), -EINVAL, OSINFO_INVALID_RELATIONSHIP); - return NULL; - } + g_return_val_if_fail(OSINFO_IS_DB(self), NULL); // Create list OsinfoOsList *newList = g_object_new(OSINFO_TYPE_OSLIST, NULL); diff --git a/osinfo/osinfo_db.h b/osinfo/osinfo_db.h index fa212b0..d50d0ee 100644 --- a/osinfo/osinfo_db.h +++ b/osinfo/osinfo_db.h @@ -68,25 +68,25 @@ OsinfoDb *osinfo_db_new(const gchar *backingDir); int osinfo_db_initialize(OsinfoDb *self, GError **err); -OsinfoHypervisor *osinfo_db_get_hypervisor(OsinfoDb *self, gchar *hvId, GError **err); -OsinfoDevice *osinfo_db_get_device(OsinfoDb *self, gchar *devId, GError **err); -OsinfoOs *osinfo_db_get_os(OsinfoDb *self, gchar *osId, GError **err); +OsinfoHypervisor *osinfo_db_get_hypervisor(OsinfoDb *self, gchar *hvId); +OsinfoDevice *osinfo_db_get_device(OsinfoDb *self, gchar *devId); +OsinfoOs *osinfo_db_get_os(OsinfoDb *self, gchar *osId); -OsinfoOsList *osinfo_db_get_os_list(OsinfoDb *self, OsinfoFilter *filter, GError **err); -OsinfoHypervisorList *osinfo_db_get_hypervisor_list(OsinfoDb *self, OsinfoFilter *filter, GError **err); -OsinfoDeviceList *osinfo_db_get_device_list(OsinfoDb *self, OsinfoFilter *filter, GError **err); +OsinfoOsList *osinfo_db_get_os_list(OsinfoDb *self, OsinfoFilter *filter); +OsinfoHypervisorList *osinfo_db_get_hypervisor_list(OsinfoDb *self, OsinfoFilter *filter); +OsinfoDeviceList *osinfo_db_get_device_list(OsinfoDb *self, OsinfoFilter *filter); // Get me all unique values for property "vendor" among operating systems -GPtrArray *osinfo_db_unique_values_for_property_in_os(OsinfoDb *self, gchar *propName, GError **err); +GPtrArray *osinfo_db_unique_values_for_property_in_os(OsinfoDb *self, gchar *propName); // Get me all unique values for property "vendor" among hypervisors -GPtrArray *osinfo_db_unique_values_for_property_in_hv(OsinfoDb *self, gchar *propName, GError **err); +GPtrArray *osinfo_db_unique_values_for_property_in_hv(OsinfoDb *self, gchar *propName); // Get me all unique values for property "vendor" among devices -GPtrArray *osinfo_db_unique_values_for_property_in_dev(OsinfoDb *self, gchar *propName, GError **err); +GPtrArray *osinfo_db_unique_values_for_property_in_dev(OsinfoDb *self, gchar *propName); // Get me all OSes that 'upgrade' another OS (or whatever relationship is specified) -OsinfoOsList *osinfo_db_unique_values_for_os_relationship(OsinfoDb *self, osinfoRelationship relshp, GError **err); +OsinfoOsList *osinfo_db_unique_values_for_os_relationship(OsinfoDb *self, osinfoRelationship relshp); void osinfo_db_add_device(OsinfoDb *db, OsinfoDevice *dev); void osinfo_db_add_hypervisor(OsinfoDb *db, OsinfoHypervisor *hv); diff --git a/osinfo/osinfo_device.c b/osinfo/osinfo_device.c index a477fae..bddc5e9 100644 --- a/osinfo/osinfo_device.c +++ b/osinfo/osinfo_device.c @@ -35,31 +35,12 @@ osinfo_device_init (OsinfoDevice *self) gchar *osinfo_device_get_driver(OsinfoDevice *self, gchar *devType, OsinfoOs *os, - OsinfoHypervisor *hv, - GError **err) + OsinfoHypervisor *hv) { - if (!__osinfoCheckGErrorParamValid(err)) - return NULL; - - if (!OSINFO_IS_DEVICE(self)) { - g_set_error_literal(err, g_quark_from_static_string("libosinfo"), -EINVAL, OSINFO_OBJ_NOT_DEVICE); - return NULL; - } - - if (!OSINFO_IS_OS(os)) { - g_set_error_literal(err, g_quark_from_static_string("libosinfo"), -EINVAL, OSINFO_OBJ_NOT_OS); - return NULL; - } - - if (!OSINFO_IS_HYPERVISOR(hv)) { - g_set_error_literal(err, g_quark_from_static_string("libosinfo"), -EINVAL, OSINFO_OBJ_NOT_HV); - return NULL; - } - - if (!devType) { - g_set_error_literal(err, g_quark_from_static_string("libosinfo"), -EINVAL, OSINFO_NO_DEVTYPE); - return NULL; - } + g_return_val_if_fail(OSINFO_IS_DEVICE(self), NULL); + g_return_val_if_fail(OSINFO_IS_OS(os), NULL); + g_return_val_if_fail(OSINFO_IS_HYPERVISOR(hv), NULL); + g_return_val_if_fail(devType != NULL, NULL); gchar *driver = NULL; diff --git a/osinfo/osinfo_device.h b/osinfo/osinfo_device.h index 9883f1f..d218229 100644 --- a/osinfo/osinfo_device.h +++ b/osinfo/osinfo_device.h @@ -46,6 +46,6 @@ struct _OsinfoDeviceClass GType osinfo_device_get_type(void); -gchar *osinfo_device_get_driver(OsinfoDevice *self, gchar *devType, OsinfoOs *os, OsinfoHypervisor *hv, GError **err); +gchar *osinfo_device_get_driver(OsinfoDevice *self, gchar *devType, OsinfoOs *os, OsinfoHypervisor *hv); #endif /* __OSINFO_DEVICE_H__ */ diff --git a/osinfo/osinfo_entity.c b/osinfo/osinfo_entity.c index fd3767f..0fd8c59 100644 --- a/osinfo/osinfo_entity.c +++ b/osinfo/osinfo_entity.c @@ -147,8 +147,7 @@ void osinfo_entity_clear_param(OsinfoEntity *self, gchar *key) gboolean osinfo_get_keys(gpointer key, gpointer value, gpointer data) { - struct __osinfoPtrArrayErr *arrayErr = (struct __osinfoPtrArrayErr *) data; - GPtrArray *results = arrayErr->array; + GPtrArray *results = data; gchar *keyDup = g_strdup(key); g_ptr_array_add(results, keyDup); @@ -157,74 +156,36 @@ gboolean osinfo_get_keys(gpointer key, gpointer value, gpointer data) void osinfo_dup_array(gpointer data, gpointer user_data) { - struct __osinfoPtrArrayErr *arrayErr = (struct __osinfoPtrArrayErr *) data; - GPtrArray *results = arrayErr->array; - - if (arrayErr->err != 0) - return; - - gchar *valueDup = g_strdup((gchar *)data); + GPtrArray *results = data; + gchar *valueDup = g_strdup(data); g_ptr_array_add(results, valueDup); } -gchar *osinfo_entity_get_id(OsinfoEntity *self, GError **err) +gchar *osinfo_entity_get_id(OsinfoEntity *self) { - if (!__osinfoCheckGErrorParamValid(err)) - return NULL; - - if (!OSINFO_IS_ENTITY(self)) { - g_set_error_literal(err, g_quark_from_static_string("libosinfo"), -EINVAL, OSINFO_OBJ_NOT_ENTITY); - return NULL; - } + g_return_val_if_fail(OSINFO_IS_ENTITY(self), NULL); gchar *dupId = g_strdup(self->priv->id); return dupId; } -GPtrArray *osinfo_entity_get_params(OsinfoEntity *self, GError **err) +GPtrArray *osinfo_entity_get_params(OsinfoEntity *self) { - if (!__osinfoCheckGErrorParamValid(err)) - return NULL; - - if (!OSINFO_IS_ENTITY(self)) { - g_set_error_literal(err, g_quark_from_static_string("libosinfo"), -EINVAL, OSINFO_OBJ_NOT_ENTITY); - return NULL; - } + g_return_val_if_fail(OSINFO_IS_ENTITY(self), NULL); GPtrArray *params = g_ptr_array_new(); - struct __osinfoPtrArrayErr arrayErr = {params, 0}; - g_tree_foreach(self->priv->params, osinfo_get_keys, &arrayErr); - - // If we had an error, cleanup and return NULL - if (arrayErr.err != 0) { - int i; - for (i = 0; i < params->len; i++) - g_free(g_ptr_array_index(params, i)); - g_ptr_array_free(params, TRUE); - g_set_error_literal(err, g_quark_from_static_string("libosinfo"), arrayErr.err, __osinfoErrorToString(arrayErr.err)); - return NULL; - } + g_tree_foreach(self->priv->params, osinfo_get_keys, params); return params; } -gchar *osinfo_entity_get_param_value(OsinfoEntity *self, gchar *key, GError **err) +gchar *osinfo_entity_get_param_value(OsinfoEntity *self, gchar *key) { - if (!__osinfoCheckGErrorParamValid(err)) - return NULL; - - if (!OSINFO_IS_ENTITY(self)) { - g_set_error_literal(err, g_quark_from_static_string("libosinfo"), -EINVAL, OSINFO_OBJ_NOT_ENTITY); - return NULL; - } - - if (!key) { - g_set_error_literal(err, g_quark_from_static_string("libosinfo"), -EINVAL, OSINFO_NO_PROPNAME); - return NULL; - } + g_return_val_if_fail(OSINFO_IS_ENTITY(self), NULL); + g_return_val_if_fail(key != NULL, NULL); gboolean found; gpointer origKey, value; @@ -243,20 +204,10 @@ gchar *osinfo_entity_get_param_value(OsinfoEntity *self, gchar *key, GError **er return firstValueDup; } -GPtrArray *osinfo_entity_get_param_all_values(OsinfoEntity *self, gchar *key, GError **err) +GPtrArray *osinfo_entity_get_param_all_values(OsinfoEntity *self, gchar *key) { - if (!__osinfoCheckGErrorParamValid(err)) - return NULL; - - if (!OSINFO_IS_ENTITY(self)) { - g_set_error_literal(err, g_quark_from_static_string("libosinfo"), -EINVAL, OSINFO_OBJ_NOT_ENTITY); - return NULL; - } - - if (!key) { - g_set_error_literal(err, g_quark_from_static_string("libosinfo"), -EINVAL, OSINFO_NO_PROPNAME); - return NULL; - } + g_return_val_if_fail(OSINFO_IS_ENTITY(self), NULL); + g_return_val_if_fail(key != NULL, NULL); gboolean found; gpointer origKey, value; @@ -271,14 +222,7 @@ GPtrArray *osinfo_entity_get_param_all_values(OsinfoEntity *self, gchar *key, GE if (srcArray->len == 0) return retArray; - struct __osinfoPtrArrayErr arrayErr = {retArray, 0}; - g_ptr_array_foreach(srcArray, osinfo_dup_array, &arrayErr); - if (arrayErr.err) { - g_set_error_literal(err, g_quark_from_static_string("libosinfo"), arrayErr.err, __osinfoErrorToString(arrayErr.err)); - g_ptr_array_set_free_func(retArray, g_free); - g_ptr_array_free(retArray, TRUE); - return NULL; - } + g_ptr_array_foreach(srcArray, osinfo_dup_array, retArray); return retArray; } diff --git a/osinfo/osinfo_entity.h b/osinfo/osinfo_entity.h index e5a2bc1..75c529f 100644 --- a/osinfo/osinfo_entity.h +++ b/osinfo/osinfo_entity.h @@ -45,10 +45,10 @@ struct _OsinfoEntityClass GType osinfo_entity_get_type(void); -gchar *osinfo_entity_get_id(OsinfoEntity *self, GError **err); -GPtrArray *osinfo_entity_get_params(OsinfoEntity *self, GError **err); -gchar *osinfo_entity_get_param_value(OsinfoEntity *self, gchar *key, GError **err); -GPtrArray *osinfo_entity_get_param_all_values(OsinfoEntity *self, gchar *key, GError **err); +gchar *osinfo_entity_get_id(OsinfoEntity *self); +GPtrArray *osinfo_entity_get_params(OsinfoEntity *self); +gchar *osinfo_entity_get_param_value(OsinfoEntity *self, gchar *key); +GPtrArray *osinfo_entity_get_param_all_values(OsinfoEntity *self, gchar *key); int osinfo_entity_add_param(OsinfoEntity *self, gchar *key, gchar *value); void osinfo_entity_clear_param(OsinfoEntity *self, gchar *key); diff --git a/osinfo/osinfo_filter.c b/osinfo/osinfo_filter.c index cb81da8..0424eb7 100644 --- a/osinfo/osinfo_filter.c +++ b/osinfo/osinfo_filter.c @@ -48,25 +48,11 @@ osinfo_filter_init (OsinfoFilter *self) } -gint osinfo_filter_add_constraint(OsinfoFilter *self, gchar *propName, gchar *propVal, GError **err) +gint osinfo_filter_add_constraint(OsinfoFilter *self, gchar *propName, gchar *propVal) { - if (!__osinfoCheckGErrorParamValid(err)) - return -EINVAL; - - if (!OSINFO_IS_FILTER(self)) { - g_set_error_literal(err, g_quark_from_static_string("libosinfo"), -EINVAL, OSINFO_OBJ_NOT_FILTER); - return -EINVAL; - } - - if (!propName) { - g_set_error_literal(err, g_quark_from_static_string("libosinfo"), -EINVAL, OSINFO_NO_PROPNAME); - return -EINVAL; - } - - if (!propVal) { - g_set_error_literal(err, g_quark_from_static_string("libosinfo"), -EINVAL, OSINFO_NO_PROPVAL); - return -EINVAL; - } + g_return_val_if_fail(OSINFO_IS_FILTER(self), -1); + g_return_val_if_fail(propName != NULL, -1); + g_return_val_if_fail(propVal != NULL, -1); // First check if there exists an array of entries for this key // If not, create a ptrarray of strings for this key and insert into map @@ -93,25 +79,10 @@ gint osinfo_filter_add_constraint(OsinfoFilter *self, gchar *propName, gchar *pr } // Only applicable to OSes, ignored by other types of objects -gint osinfo_filter_add_relation_constraint(OsinfoFilter *self, osinfoRelationship relshp, OsinfoOs *os, GError **err) +gint osinfo_filter_add_relation_constraint(OsinfoFilter *self, osinfoRelationship relshp, OsinfoOs *os) { - if (!__osinfoCheckGErrorParamValid(err)) - return -EINVAL; - - if (!OSINFO_IS_FILTER(self)) { - g_set_error_literal(err, g_quark_from_static_string("libosinfo"), -EINVAL, OSINFO_OBJ_NOT_FILTER); - return -EINVAL; - } - - if (!__osinfoCheckRelationshipValid(relshp)) { - g_set_error_literal(err, g_quark_from_static_string("libosinfo"), -EINVAL, OSINFO_INVALID_RELATIONSHIP); - return -EINVAL; - } - - if (!OSINFO_IS_OS(os)) { - g_set_error_literal(err, g_quark_from_static_string("libosinfo"), -EINVAL, OSINFO_OBJ_NOT_OS); - return -EINVAL; - } + g_return_val_if_fail(OSINFO_IS_FILTER(self), -1); + g_return_val_if_fail(OSINFO_IS_OS(os), -1); // First check if there exists an array of entries for this key // If not, create a ptrarray of strings for this key and insert into map @@ -157,49 +128,22 @@ void osinfo_filter_clear_all_constraints(OsinfoFilter *self) } // get keyset for constraints map -GPtrArray *osinfo_filter_get_constraint_keys(OsinfoFilter *self, GError **err) +GPtrArray *osinfo_filter_get_constraint_keys(OsinfoFilter *self) { - if (!__osinfoCheckGErrorParamValid(err)) - return NULL; - - if (!OSINFO_IS_FILTER(self)) { - g_set_error_literal(err, g_quark_from_static_string("libosinfo"), -EINVAL, OSINFO_OBJ_NOT_FILTER); - return NULL; - } + g_return_val_if_fail(OSINFO_IS_FILTER(self), NULL); GPtrArray *constraints = g_ptr_array_new(); - struct __osinfoPtrArrayErr arrayErr = {constraints, 0}; - g_tree_foreach(self->priv->propertyConstraints, osinfo_get_keys, &arrayErr); - - // If we had an error, cleanup and return NULL - if (arrayErr.err != 0) { - int i; - for (i = 0; i < constraints->len; i++) - g_free(g_ptr_array_index(constraints, i)); - g_ptr_array_free(constraints, TRUE); - g_set_error_literal(err, g_quark_from_static_string("libosinfo"), arrayErr.err, __osinfoErrorToString(arrayErr.err)); - return NULL; - } + g_tree_foreach(self->priv->propertyConstraints, osinfo_get_keys, constraints); return constraints; } // get values for given key -GPtrArray *osinfo_filter_get_constraint_values(OsinfoFilter *self, gchar *propName, GError **err) +GPtrArray *osinfo_filter_get_constraint_values(OsinfoFilter *self, gchar *propName) { - if (!__osinfoCheckGErrorParamValid(err)) - return NULL; - - if (!OSINFO_IS_FILTER(self)) { - g_set_error_literal(err, g_quark_from_static_string("libosinfo"), -EINVAL, OSINFO_OBJ_NOT_FILTER); - return NULL; - } - - if (!propName) { - g_set_error_literal(err, g_quark_from_static_string("libosinfo"), -EINVAL, OSINFO_NO_PROPNAME); - return NULL; - } + g_return_val_if_fail(OSINFO_IS_FILTER(self), NULL); + g_return_val_if_fail(propName != NULL, NULL); gboolean found; gpointer origKey, value; @@ -214,33 +158,15 @@ GPtrArray *osinfo_filter_get_constraint_values(OsinfoFilter *self, gchar *propNa if (srcArray->len == 0) return retArray; - struct __osinfoPtrArrayErr arrayErr = {retArray, 0}; - g_ptr_array_foreach(srcArray, osinfo_dup_array, &arrayErr); - if (arrayErr.err) { - g_set_error_literal(err, g_quark_from_static_string("libosinfo"), arrayErr.err, __osinfoErrorToString(arrayErr.err)); - g_ptr_array_set_free_func(retArray, g_free); - g_ptr_array_free(retArray, TRUE); - return NULL; - } + g_ptr_array_foreach(srcArray, osinfo_dup_array, retArray); return retArray; } // get oses for given relshp -OsinfoOsList *osinfo_filter_get_relationship_constraint_value(OsinfoFilter *self, osinfoRelationship relshp, GError **err) +OsinfoOsList *osinfo_filter_get_relationship_constraint_value(OsinfoFilter *self, osinfoRelationship relshp) { - if (!__osinfoCheckGErrorParamValid(err)) - return NULL; - - if (!OSINFO_IS_FILTER(self)) { - g_set_error_literal(err, g_quark_from_static_string("libosinfo"), -EINVAL, OSINFO_OBJ_NOT_FILTER); - return NULL; - } - - if (!__osinfoCheckRelationshipValid(relshp)) { - g_set_error_literal(err, g_quark_from_static_string("libosinfo"), -EINVAL, OSINFO_INVALID_RELATIONSHIP); - return NULL; - } + g_return_val_if_fail(OSINFO_IS_FILTER(self), NULL); // Create our list OsinfoOsList *newList = g_object_new(OSINFO_TYPE_OSLIST, NULL); diff --git a/osinfo/osinfo_filter.h b/osinfo/osinfo_filter.h index 8116261..75cfee8 100644 --- a/osinfo/osinfo_filter.h +++ b/osinfo/osinfo_filter.h @@ -48,17 +48,17 @@ struct _OsinfoFilterClass GType osinfo_filter_get_type(void); -gint osinfo_filter_add_constraint(OsinfoFilter *self, gchar *propName, gchar *propVal, GError **err); +gint osinfo_filter_add_constraint(OsinfoFilter *self, gchar *propName, gchar *propVal); // Only applicable to OSes, ignored by other types of objects -gint osinfo_filter_add_relation_constraint(OsinfoFilter *self, osinfoRelationship relshp, OsinfoOs *os, GError **err); +gint osinfo_filter_add_relation_constraint(OsinfoFilter *self, osinfoRelationship relshp, OsinfoOs *os); void osinfo_filter_clear_constraint(OsinfoFilter *self, gchar *propName); void osinfo_filter_clear_relationship_constraint(OsinfoFilter *self, osinfoRelationship relshp); void osinfo_filter_clear_all_constraints(OsinfoFilter *self); -GPtrArray *osinfo_filter_get_constraint_keys(OsinfoFilter *self, GError **err); -GPtrArray *osinfo_filter_get_constraint_values(OsinfoFilter *self, gchar *propName, GError **err); -OsinfoOsList *osinfo_filter_get_relationship_constraint_value(OsinfoFilter *self, osinfoRelationship relshp, GError **err); +GPtrArray *osinfo_filter_get_constraint_keys(OsinfoFilter *self); +GPtrArray *osinfo_filter_get_constraint_values(OsinfoFilter *self, gchar *propName); +OsinfoOsList *osinfo_filter_get_relationship_constraint_value(OsinfoFilter *self, osinfoRelationship relshp); #endif /* __OSINFO_FILTER_H__ */ diff --git a/osinfo/osinfo_hypervisor.c b/osinfo/osinfo_hypervisor.c index 900689b..2f6d0c9 100644 --- a/osinfo/osinfo_hypervisor.c +++ b/osinfo/osinfo_hypervisor.c @@ -54,43 +54,22 @@ void __osinfoClearDeviceSectionHv(OsinfoHypervisor *self, gchar *section) __osinfoClearDeviceSection(self->priv->sections, self->priv->sectionsAsList, section); } -GPtrArray *osinfo_hypervisor_get_device_types(OsinfoHypervisor *self, GError **err) +GPtrArray *osinfo_hypervisor_get_device_types(OsinfoHypervisor *self) { - if (!__osinfoCheckGErrorParamValid(err)) - return NULL; - - if (!OSINFO_IS_HYPERVISOR(self)) { - g_set_error_literal(err, g_quark_from_static_string("libosinfo"), -EINVAL, OSINFO_OBJ_NOT_HV); - return NULL; - } + g_return_val_if_fail(OSINFO_IS_HYPERVISOR(self), NULL); GPtrArray *deviceTypes = g_ptr_array_sized_new(g_tree_nnodes(self->priv->sections)); // For each key in our tree of device sections, dup and add to the array - struct __osinfoPtrArrayErr arrayErr = {deviceTypes, 0}; - g_tree_foreach(self->priv->sections, osinfo_get_keys, &arrayErr); + g_tree_foreach(self->priv->sections, osinfo_get_keys, deviceTypes); return deviceTypes; } -OsinfoDeviceList *osinfo_hypervisor_get_devices_by_type(OsinfoHypervisor *self, gchar *devType, OsinfoFilter *filter, GError **err) +OsinfoDeviceList *osinfo_hypervisor_get_devices_by_type(OsinfoHypervisor *self, gchar *devType, OsinfoFilter *filter) { - if (!__osinfoCheckGErrorParamValid(err)) - return NULL; - - if (!OSINFO_IS_HYPERVISOR(self)) { - g_set_error_literal(err, g_quark_from_static_string("libosinfo"), -EINVAL, OSINFO_OBJ_NOT_HV); - return NULL; - } - - if (filter && !OSINFO_IS_FILTER(filter)) { - g_set_error_literal(err, g_quark_from_static_string("libosinfo"), -EINVAL, OSINFO_OBJ_NOT_FILTER); - return NULL; - } - - if (!devType) { - g_set_error_literal(err, g_quark_from_static_string("libosinfo"), -EINVAL, OSINFO_NO_DEVTYPE); - return NULL; - } + g_return_val_if_fail(OSINFO_IS_HYPERVISOR(self), NULL); + g_return_val_if_fail(OSINFO_IS_FILTER(filter), NULL); + g_return_val_if_fail(devType != NULL, NULL); // Create our device list OsinfoDeviceList *newList = g_object_new(OSINFO_TYPE_DEVICELIST, NULL); diff --git a/osinfo/osinfo_hypervisor.h b/osinfo/osinfo_hypervisor.h index d7f1f56..658b6b9 100644 --- a/osinfo/osinfo_hypervisor.h +++ b/osinfo/osinfo_hypervisor.h @@ -48,7 +48,7 @@ struct _OsinfoHypervisorClass GType osinfo_hypervisor_get_type(void); -GPtrArray *osinfo_hypervisor_get_device_types(OsinfoHypervisor *self, GError **err); -OsinfoDeviceList *osinfo_hypervisor_get_devices_by_type(OsinfoHypervisor *self, gchar *devType, OsinfoFilter *filter, GError **err); +GPtrArray *osinfo_hypervisor_get_device_types(OsinfoHypervisor *self); +OsinfoDeviceList *osinfo_hypervisor_get_devices_by_type(OsinfoHypervisor *self, gchar *devType, OsinfoFilter *filter); #endif /* __OSINFO_HYPERVISOR_H__ */ diff --git a/osinfo/osinfo_os.c b/osinfo/osinfo_os.c index bf93182..51862cb 100644 --- a/osinfo/osinfo_os.c +++ b/osinfo/osinfo_os.c @@ -218,31 +218,12 @@ void __osinfoRemoveHvSectionFromOs(OsinfoOs *self, gchar *hvId) g_tree_remove(self->priv->hypervisors, hvId); } -OsinfoDevice *osinfo_os_get_preferred_device(OsinfoOs *self, OsinfoHypervisor *hv, gchar *devType, OsinfoFilter *filter, GError **err) +OsinfoDevice *osinfo_os_get_preferred_device(OsinfoOs *self, OsinfoHypervisor *hv, gchar *devType, OsinfoFilter *filter) { - if (!__osinfoCheckGErrorParamValid(err)) - return NULL; - - if (!OSINFO_IS_OS(self)) { - g_set_error_literal(err, g_quark_from_static_string("libosinfo"), -EINVAL, OSINFO_OBJ_NOT_OS); - return NULL; - } - - if (hv && !OSINFO_IS_HYPERVISOR(hv)) { - g_set_error_literal(err, g_quark_from_static_string("libosinfo"), -EINVAL, OSINFO_OBJ_NOT_HV); - return NULL; - } - - if (!devType) { - g_set_error_literal(err, g_quark_from_static_string("libosinfo"), -EINVAL, OSINFO_NO_DEVTYPE); - return NULL; - } - - if (filter && !OSINFO_IS_FILTER(filter)) { - g_set_error_literal(err, g_quark_from_static_string("libosinfo"), -EINVAL, OSINFO_OBJ_NOT_FILTER); - return NULL; - } - + g_return_val_if_fail(OSINFO_IS_OS(self), NULL); + g_return_val_if_fail(OSINFO_IS_HYPERVISOR(hv), NULL); + g_return_val_if_fail(OSINFO_IS_FILTER(filter), NULL); + g_return_val_if_fail(devType != NULL, NULL); // Check if device type info present for <os,hv>, else return NULL. GPtrArray *sectionList = NULL; @@ -276,20 +257,9 @@ OsinfoDevice *osinfo_os_get_preferred_device(OsinfoOs *self, OsinfoHypervisor *h return NULL; } -OsinfoOsList *osinfo_os_get_related(OsinfoOs *self, osinfoRelationship relshp, GError **err) +OsinfoOsList *osinfo_os_get_related(OsinfoOs *self, osinfoRelationship relshp) { - if (!__osinfoCheckGErrorParamValid(err)) - return NULL; - - if (!OSINFO_IS_OS(self)) { - g_set_error_literal(err, g_quark_from_static_string("libosinfo"), -EINVAL, OSINFO_OBJ_NOT_OS); - return NULL; - } - - if (!__osinfoCheckRelationshipValid(relshp)) { - g_set_error_literal(err, g_quark_from_static_string("libosinfo"), -EINVAL, OSINFO_INVALID_RELATIONSHIP); - return NULL; - } + g_return_val_if_fail(OSINFO_IS_OS(self), NULL); // Create our list OsinfoOsList *newList = g_object_new(OSINFO_TYPE_OSLIST, NULL); @@ -308,30 +278,12 @@ OsinfoOsList *osinfo_os_get_related(OsinfoOs *self, osinfoRelationship relshp, G return newList; } -OsinfoDeviceList *osinfo_os_get_devices(OsinfoOs *self, OsinfoHypervisor *hv, gchar *devType, OsinfoFilter *filter, GError **err) +OsinfoDeviceList *osinfo_os_get_devices(OsinfoOs *self, OsinfoHypervisor *hv, gchar *devType, OsinfoFilter *filter) { - if (!__osinfoCheckGErrorParamValid(err)) - return NULL; - - if (!OSINFO_IS_OS(self)) { - g_set_error_literal(err, g_quark_from_static_string("libosinfo"), -EINVAL, OSINFO_OBJ_NOT_OS); - return NULL; - } - - if (!OSINFO_IS_HYPERVISOR(hv)) { - g_set_error_literal(err, g_quark_from_static_string("libosinfo"), -EINVAL, OSINFO_OBJ_NOT_HV); - return NULL; - } - - if (!devType) { - g_set_error_literal(err, g_quark_from_static_string("libosinfo"), -EINVAL, OSINFO_NO_DEVTYPE); - return NULL; - } - - if (filter && !OSINFO_IS_FILTER(filter)) { - g_set_error_literal(err, g_quark_from_static_string("libosinfo"), -EINVAL, OSINFO_OBJ_NOT_FILTER); - return NULL; - } + g_return_val_if_fail(OSINFO_IS_OS(self), NULL); + g_return_val_if_fail(OSINFO_IS_HYPERVISOR(hv), NULL); + g_return_val_if_fail(OSINFO_IS_FILTER(filter), NULL); + g_return_val_if_fail(devType != NULL, NULL); GPtrArray *sectionList = NULL; diff --git a/osinfo/osinfo_os.h b/osinfo/osinfo_os.h index 48db03a..82d50ae 100644 --- a/osinfo/osinfo_os.h +++ b/osinfo/osinfo_os.h @@ -50,8 +50,8 @@ struct _OsinfoOsClass GType osinfo_os_get_type(void); -OsinfoDevice *osinfo_os_get_preferred_device(OsinfoOs *self, OsinfoHypervisor *hv, gchar *devType, OsinfoFilter *filter, GError **err); -OsinfoOsList *osinfo_os_get_related(OsinfoOs *self, osinfoRelationship relshp, GError **err); -OsinfoDeviceList *osinfo_os_get_devices(OsinfoOs *self, OsinfoHypervisor *hv, gchar *devType, OsinfoFilter *filter, GError **err); +OsinfoDevice *osinfo_os_get_preferred_device(OsinfoOs *self, OsinfoHypervisor *hv, gchar *devType, OsinfoFilter *filter); +OsinfoOsList *osinfo_os_get_related(OsinfoOs *self, osinfoRelationship relshp); +OsinfoDeviceList *osinfo_os_get_devices(OsinfoOs *self, OsinfoHypervisor *hv, gchar *devType, OsinfoFilter *filter); #endif /* __OSINFO_OS_H__ */ |