Commit 2a7516c4 authored by pierre's avatar pierre Committed by Pierre Wieser

Review usage of g_assert and dispose_has_run

parent 02c404b8
......@@ -2,6 +2,36 @@
* data/nautilus-actions.schemas.in: Migrate misnamed keys.
* src/common/na-gconf-monitor.c:
* src/common/na-gconf-monitor.h:
* src/common/na-gconf-provider.c:
* src/common/na-gconf-utils.c:
* src/common/na-iio-provider.c:
* src/common/na-ipivot-consumer.c:
* src/common/na-iprefs.c:
* src/common/na-object-action-class.h:
* src/common/na-object-action.c:
* src/common/na-object-action.h:
* src/common/na-object-class.h:
* src/common/na-object-fn.h:
* src/common/na-object-id-class.h:
* src/common/na-object-id-fn.h:
* src/common/na-object-id.c:
* src/common/na-object-item-class.h:
* src/common/na-object-item-fn.h:
* src/common/na-object-item.c:
* src/common/na-object-menu.c:
* src/common/na-object-menu.h:
* src/common/na-object-profile-class.h:
* src/common/na-object-profile.c:
* src/common/na-object-profile.h:
* src/common/na-object.c:
* src/common/na-pivot.c:
* src/common/na-utils.c:
* src/common/na-xml-writer.c:
* src/common/na-xml-writer.h:
Review code, usage of g_assert, test dispose_has_run.
* src/nact/base-iprefs.c:
* src/nact/base-iprefs.h (base_iprefs_migrate_key): New function.
......
......@@ -142,11 +142,11 @@ instance_dispose( GObject *object )
if( !self->private->dispose_has_run ){
self->private->dispose_has_run = TRUE;
/* release the installed monitor */
/* release the installed monitor before setting dispose_has_run */
release_monitor( self );
self->private->dispose_has_run = TRUE;
/* chain up to the parent class */
if( G_OBJECT_CLASS( st_parent_class )->dispose ){
G_OBJECT_CLASS( st_parent_class )->dispose( object );
......@@ -249,12 +249,15 @@ install_monitor( NAGConfMonitor *monitor )
* Release allocated monitors.
*/
void
na_gconf_monitor_release_monitors( GSList *monitors )
na_gconf_monitor_release_monitors( GList *monitors )
{
g_slist_foreach( monitors, ( GFunc ) g_object_unref, NULL );
g_slist_free( monitors );
g_list_foreach( monitors, ( GFunc ) g_object_unref, NULL );
g_list_free( monitors );
}
/*
* this is called by instance_dispose, before setting dispose_has_run
*/
static void
release_monitor( NAGConfMonitor *monitor )
{
......@@ -262,8 +265,8 @@ release_monitor( NAGConfMonitor *monitor )
GError *error = NULL;
g_debug( "%s: monitor=%p", thisfn, ( void * ) monitor );
g_return_if_fail( NA_IS_GCONF_MONITOR( monitor ));
g_return_if_fail( !monitor->private->dispose_has_run );
if( monitor->private->monitor_id ){
gconf_client_notify_remove( monitor->private->gconf, monitor->private->monitor_id );
......@@ -272,7 +275,7 @@ release_monitor( NAGConfMonitor *monitor )
gconf_client_remove_dir( monitor->private->gconf, monitor->private->path, &error );
if( error ){
g_warning( "%s[gconf_client_remove_dir] path=%s, error=%s", thisfn, monitor->private->path, error->message );
g_warning( "%s: path=%s, error=%s", thisfn, monitor->private->path, error->message );
g_error_free( error );
}
}
......@@ -70,7 +70,7 @@ GType na_gconf_monitor_get_type( void );
NAGConfMonitor *na_gconf_monitor_new( GConfClient *client, const gchar *path, gint preload, GConfClientNotifyFunc handler, gpointer user_data );
void na_gconf_monitor_release_monitors( GSList *monitors );
void na_gconf_monitor_release_monitors( GList *monitors );
G_END_DECLS
......
......@@ -57,7 +57,7 @@ struct NAGConfProviderPrivate {
gboolean dispose_has_run;
GConfClient *gconf;
NAPivot *pivot;
GSList *monitors;
GList *monitors;
};
static GObjectClass *st_parent_class = NULL;
......@@ -272,7 +272,7 @@ na_gconf_provider_new( NAPivot *handler )
static void
install_monitors( NAGConfProvider *provider )
{
GSList *list = NULL;
GList *list = NULL;
g_return_if_fail( NA_IS_GCONF_PROVIDER( provider ));
g_return_if_fail( NA_IS_IIO_PROVIDER( provider ));
......@@ -281,7 +281,8 @@ install_monitors( NAGConfProvider *provider )
/* monitor the configurations/ directory which contains all menus,
* actions and profiles definitions
*/
list = g_slist_prepend( list,
list = g_list_prepend( list,
na_gconf_monitor_new(
provider->private->gconf,
NA_GCONF_CONFIG_PATH,
......@@ -294,23 +295,30 @@ install_monitors( NAGConfProvider *provider )
/*
* this callback is triggered each time a value is changed under our
* configurations/ directory
* configurations/ directory ; as each object has several entries which
* describe it, this callback is triggered several times for each object
* update
*
* up to and including 1.10.1, the user interface took care of writing
* a special key in GConf at the end of each update operations ;
* as GConf monitored only this special key, it triggered this callback
* once for each global update operation
*
* if the modification is made from nautilus-actions-config ui, then
* the callback is triggered several times (one time for each rewritten
* property) as action/profile are edited as blocs of data ; in this
* case, the ui takes care (as of of 1.10) of also writing at last a
* particular key of the form xxx:yyyyyyyy-yyyy-yyyy-..., where :
* this special key was of the form xxx:yyyyyyyy-yyyy-yyyy-..., where :
* xxx was a sequential number (inside of the ui session)
* yyyyyyyy-yyyy-yyyy-... was the uuid of the involved action
*
* this was so a sort of hack which simplifies a lot the notification
* system (take the new action, replace it in the current global list)
* but didn't work if the modification was made from outside of the ui
* this was a sort of hack which simplified a lot the notification
* system, but didn't take into account any modification which might
* come from outside of the ui
*
* if the modification is made elsewhere (an action is imported as a
* xml file in gconf, or gconf is directly edited), we'd have to rely
* only on the standard mmonitor (GConf watch) mechanism
* only on the standard monitor (GConf watch) mechanism
*
* this is what we do below, thus triggering NAPivot for each and every
* modification in the GConf underlying system ; this is the prerogative
* of NAPivot to decide what to do with them
*/
static void
config_path_changed_cb( GConfClient *client, guint cnxn_id, GConfEntry *entry, NAGConfProvider *provider )
......@@ -318,15 +326,16 @@ config_path_changed_cb( GConfClient *client, guint cnxn_id, GConfEntry *entry, N
/*static const gchar *thisfn = "na_gconf_provider_config_path_changed_cb";*/
NAPivotNotify *npn;
g_return_if_fail( NA_IS_GCONF_PROVIDER( provider ));
g_return_if_fail( NA_IS_IIO_PROVIDER( provider ));
g_return_if_fail( !provider->private->dispose_has_run );
/*g_debug( "%s: client=%p, cnxnid=%u, entry=%p, provider=%p",
thisfn, ( void * ) client, cnxn_id, ( void * ) entry, ( void * ) provider );*/
npn = entry_to_notify( entry );
g_signal_emit_by_name( provider->private->pivot, NA_IIO_PROVIDER_SIGNAL_ACTION_CHANGED, npn );
g_return_if_fail( NA_IS_GCONF_PROVIDER( provider ));
g_return_if_fail( NA_IS_IIO_PROVIDER( provider ));
if( !provider->private->dispose_has_run ){
npn = entry_to_notify( entry );
g_signal_emit_by_name( provider->private->pivot, NA_IIO_PROVIDER_SIGNAL_ACTION_CHANGED, npn );
}
}
/*
......@@ -438,21 +447,21 @@ iio_provider_read_items_list( const NAIIOProvider *provider )
g_return_val_if_fail( NA_IS_IIO_PROVIDER( provider ), NULL );
g_return_val_if_fail( NA_IS_GCONF_PROVIDER( provider ), NULL );
self = NA_GCONF_PROVIDER( provider );
g_return_val_if_fail( !self->private->dispose_has_run, NULL );
listpath = na_gconf_utils_get_subdirs( self->private->gconf, NA_GCONF_CONFIG_PATH );
if( !self->private->dispose_has_run ){
for( ip = listpath ; ip ; ip = ip->next ){
listpath = na_gconf_utils_get_subdirs( self->private->gconf, NA_GCONF_CONFIG_PATH );
const gchar *path = ( const gchar * ) ip->data;
for( ip = listpath ; ip ; ip = ip->next ){
item = read_item( self, path );
const gchar *path = ( const gchar * ) ip->data;
item = read_item( self, path );
items_list = g_list_prepend( items_list, item );
}
items_list = g_list_prepend( items_list, item );
na_gconf_utils_free_subdirs( listpath );
}
na_gconf_utils_free_subdirs( listpath );
return( items_list );
}
......@@ -730,24 +739,38 @@ read_object_item_properties( NAGConfProvider *provider, GSList *entries, NAObjec
static gboolean
iio_provider_is_willing_to_write( const NAIIOProvider *provider )
{
NAGConfProvider *self;
gboolean willing_to = FALSE;
g_return_val_if_fail( NA_IS_GCONF_PROVIDER( provider ), FALSE );
g_return_val_if_fail( NA_IS_IIO_PROVIDER( provider ), FALSE );
g_return_val_if_fail( !NA_GCONF_PROVIDER( provider )->private->dispose_has_run, FALSE );
self = NA_GCONF_PROVIDER( provider );
/* TODO: na_gconf_provider_iio_provider_is_willing_to_write */
return( TRUE );
if( !self->private->dispose_has_run ){
willing_to = TRUE;
}
return( willing_to );
}
static gboolean
iio_provider_is_writable( const NAIIOProvider *provider, const NAObject *item )
{
NAGConfProvider *self;
gboolean willing_to = FALSE;
g_return_val_if_fail( NA_IS_GCONF_PROVIDER( provider ), FALSE );
g_return_val_if_fail( NA_IS_IIO_PROVIDER( provider ), FALSE );
g_return_val_if_fail( !NA_GCONF_PROVIDER( provider )->private->dispose_has_run, FALSE );
g_return_val_if_fail( NA_IS_OBJECT_ITEM( item ), FALSE );
self = NA_GCONF_PROVIDER( provider );
/* TODO: na_gconf_provider_iio_provider_is_writable */
return( TRUE );
if( !self->private->dispose_has_run ){
willing_to = TRUE;
}
return( willing_to );
}
static guint
......@@ -756,16 +779,22 @@ iio_provider_write_item( const NAIIOProvider *provider, NAObject *item, gchar **
static const gchar *thisfn = "na_gconf_provider_iio_provider_write_item";
NAGConfProvider *self;
g_debug( "%s: provider=%p, item=%p, message=%p",
thisfn, ( void * ) provider, ( void * ) item, ( void * ) message );
g_debug( "%s: provider=%p, item=%p (%s), message=%p",
thisfn, ( void * ) provider,
( void * ) item, G_OBJECT_TYPE_NAME( item ), ( void * ) message );
g_return_val_if_fail( NA_IS_GCONF_PROVIDER( provider ), NA_IIO_PROVIDER_PROGRAM_ERROR );
g_return_val_if_fail( NA_IS_IIO_PROVIDER( provider ), NA_IIO_PROVIDER_PROGRAM_ERROR );
g_return_val_if_fail( !NA_GCONF_PROVIDER( provider )->private->dispose_has_run, NA_IIO_PROVIDER_PROGRAM_ERROR );
g_return_val_if_fail( NA_IS_OBJECT_ITEM( item ), NA_IIO_PROVIDER_PROGRAM_ERROR );
self = NA_GCONF_PROVIDER( provider );
message = NULL;
if( message ){
*message = NULL;
}
if( self->private->dispose_has_run ){
return( NA_IIO_PROVIDER_NOT_WILLING_TO_WRITE );
}
if( NA_IS_OBJECT_ACTION( item )){
if( !write_item_action( self, NA_OBJECT_ACTION( item ), message )){
......@@ -880,17 +909,24 @@ iio_provider_delete_item( const NAIIOProvider *provider, const NAObject *item, g
gchar *uuid, *path;
GError *error = NULL;
g_debug( "%s: provider=%p, item=%p, message=%p",
thisfn, ( void * ) provider, ( void * ) item, ( void * ) message );
g_debug( "%s: provider=%p, item=%p (%s), message=%p",
thisfn, ( void * ) provider,
( void * ) item, G_OBJECT_TYPE_NAME( item ), ( void * ) message );
g_return_val_if_fail( NA_IS_IIO_PROVIDER( provider ), NA_IIO_PROVIDER_PROGRAM_ERROR );
g_return_val_if_fail( NA_IS_GCONF_PROVIDER( provider ), NA_IIO_PROVIDER_PROGRAM_ERROR );
g_return_val_if_fail( !NA_GCONF_PROVIDER( provider )->private->dispose_has_run, NA_IIO_PROVIDER_PROGRAM_ERROR );
g_return_val_if_fail( NA_IS_OBJECT_ITEM( item ), NA_IIO_PROVIDER_PROGRAM_ERROR );
self = NA_GCONF_PROVIDER( provider );
message = NULL;
if( self->private->dispose_has_run ){
return( NA_IIO_PROVIDER_NOT_WILLING_TO_WRITE );
}
if( message ){
*message = NULL;
}
ret = NA_IIO_PROVIDER_WRITE_OK;
uuid = na_object_get_id( NA_OBJECT( item ));
......
......@@ -39,9 +39,17 @@
static gboolean sync_gconf( GConfClient *gconf, gchar **message );
/*
* load the keys which are the subdirs of the given path
* returns a list of keys as full path
/**
* na_gconf_utils_get_subdirs:
* @gconf: a #GConfClient instance.
* @path: a full path to be readen.
*
* Loads the subdirs of the given path.
*
* Returns: a GSList of full path subdirectories.
*
* The returned list should be na_gconf_utils_free_subdirs() by the
* caller.
*/
GSList *
na_gconf_utils_get_subdirs( GConfClient *gconf, const gchar *path )
......@@ -61,12 +69,26 @@ na_gconf_utils_get_subdirs( GConfClient *gconf, const gchar *path )
return( list_subdirs );
}
/**
* na_gconf_utils_free_subdirs:
* @subdirs: a list of subdirs as returned by na_gconf_utils_get_subdirs().
*
* Release the list of subdirs.
*/
void
na_gconf_utils_free_subdirs( GSList *subdirs )
{
na_utils_free_string_list( subdirs );
}
/**
* na_gconf_utils_have_subdir:
* @gconf: a #GConfClient instance.
* @path: a full path to be readen.
*
* Returns: %TRUE if the specified path has at least one subdirectory,
* %FALSE else.
*/
gboolean
na_gconf_utils_have_subdir( GConfClient *gconf, const gchar *path )
{
......@@ -80,12 +102,18 @@ na_gconf_utils_have_subdir( GConfClient *gconf, const gchar *path )
return( have_subdir );
}
/*
* load all the key=value pairs of this key specified as a full path,
* returning them as a list of GConfEntry.
/**
* na_gconf_utils_get_entries:
* @gconf: a #GConfClient instance.
* @path: a full path to be readen.
*
* Loads all the key=value pairs of the specified key.
*
* Returns: a list of #GConfEntry.
*
* The list is not recursive, it contains only the immediate children of
* path. To free the returned list, call na_gconf_utils_free_entries().
* The returned list is not recursive : it contains only the immediate
* children of @path. To free the returned list, call
* na_gconf_utils_free_entries().
*/
GSList *
na_gconf_utils_get_entries( GConfClient *gconf, const gchar *path )
......@@ -105,6 +133,12 @@ na_gconf_utils_get_entries( GConfClient *gconf, const gchar *path )
return( list_entries );
}
/**
* na_gconf_utils_free_entries:
* @list: a list of #GConfEntry as returned by na_gconf_utils_get_entries().
*
* Releases the provided list.
*/
void
na_gconf_utils_free_entries( GSList *list )
{
......@@ -112,6 +146,15 @@ na_gconf_utils_free_entries( GSList *list )
g_slist_free( list );
}
/**
* na_gconf_utils_have_entry:
* @gconf: a #GConfClient instance.
* @path: the full path of a key.
* @entry: the entry to be tested.
*
* Returns: %TRUE if the given @entry exists for the given @path,
* %FALSE else.
*/
gboolean
na_gconf_utils_have_entry( GConfClient *gconf, const gchar *path, const gchar *entry )
{
......@@ -144,6 +187,17 @@ na_gconf_utils_have_entry( GConfClient *gconf, const gchar *path, const gchar *e
return( have_entry );
}
/**
* na_gconf_utils_get_bool_from_entries:
* @entries: a list of #GConfEntry as returned by na_gconf_utils_get_entries().
* @entry: the searched entry.
* @value: a pointer to a gboolean to be set to the found value.
*
* Returns: %TRUE if the entry was found, %FALSE else.
*
* If the entry was not found, or was not of boolean type, @value is set
* to %FALSE.
*/
gboolean
na_gconf_utils_get_bool_from_entries( GSList *entries, const gchar *entry, gboolean *value )
{
......@@ -178,6 +232,19 @@ na_gconf_utils_get_bool_from_entries( GSList *entries, const gchar *entry, gbool
return( found );
}
/**
* na_gconf_utils_get_string_from_entries:
* @entries: a list of #GConfEntry as returned by na_gconf_utils_get_entries().
* @entry: the searched entry.
* @value: a pointer to a gchar * to be set to the found value.
*
* Returns: %TRUE if the entry was found, %FALSE else.
*
* If the entry was not found, or was not of string type, @value is set
* to %NULL.
*
* If @value is returned not NULL, it should be g_free() by the caller.
*/
gboolean
na_gconf_utils_get_string_from_entries( GSList *entries, const gchar *entry, gchar **value )
{
......@@ -212,6 +279,20 @@ na_gconf_utils_get_string_from_entries( GSList *entries, const gchar *entry, gch
return( found );
}
/**
* na_gconf_utils_get_string_list_from_entries:
* @entries: a list of #GConfEntry as returned by na_gconf_utils_get_entries().
* @entry: the searched entry.
* @value: a pointer to a GSList * to be set to the found value.
*
* Returns: %TRUE if the entry was found, %FALSE else.
*
* If the entry was not found, or was not of string list type, @value
* is set to %NULL.
*
* If @value is returned not NULL, it should be na_utils_free_string_list()
* by the caller.
*/
gboolean
na_gconf_utils_get_string_list_from_entries( GSList *entries, const gchar *entry, GSList **value )
{
......@@ -250,12 +331,31 @@ na_gconf_utils_get_string_list_from_entries( GSList *entries, const gchar *entry
return( found );
}
/**
* na_gconf_utils_path_to_key:
* @path: the full path of a key.
*
* Returns: the key itself, i.e. the last part of the @path.
*
* The returned string should be g_free() by the caller.
*/
gchar *
na_gconf_utils_path_to_key( const gchar *path )
{
return( na_utils_path_extract_last_dir( path ));
}
/**
* na_gconf_utils_read_bool:
* @gconf: a #GConfClient instance.
* @path: the full path to the key.
* @use_schema: whether to use a default value from schema, or not.
* @default_value: default value to be used if @use_schema is %FALSE.
*
* Returns: the boolean value read at the specified @path, taking into
* account a default value from schema (if @use_schema if %TRUE), or
* the specified @default_value.
*/
gboolean
na_gconf_utils_read_bool( GConfClient *gconf, const gchar *path, gboolean use_schema, gboolean default_value )
{
......@@ -292,7 +392,12 @@ na_gconf_utils_read_bool( GConfClient *gconf, const gchar *path, gboolean use_sc
}
/**
* Returns: a list of strings.
* na_gconf_utils_read_string_list:
* @gconf: a #GConfClient instance.
* @path: the full path to the key to be read.
*
* Returns: a list of strings,
* or %NULL if the entry was not found or was not of string list type.
*
* The returned list must be released with na_utils_free_string_list().
*/
......@@ -316,6 +421,20 @@ na_gconf_utils_read_string_list( GConfClient *gconf, const gchar *path )
return( list_strings );
}
/**
* na_gconf_utils_write_bool:
* @gconf: a #GConfClient instance.
* @path: the full path to the key.
* @value: the value to be written.
* @message: a pointer to a gchar * which will be allocated if needed.
*
* Writes a boolean at the given @path.
*
* Returns: %TRUE if the writing has been successfull, %FALSE else.
*
* If returned not NULL, the @message contains an error message.
* It should be g_free() by the caller.
*/
gboolean
na_gconf_utils_write_bool( GConfClient *gconf, const gchar *path, gboolean value, gchar **message )
{
......@@ -337,6 +456,20 @@ na_gconf_utils_write_bool( GConfClient *gconf, const gchar *path, gboolean value
return( ret );
}
/**
* na_gconf_utils_write_string:
* @gconf: a #GConfClient instance.
* @path: the full path to the key.
* @value: the value to be written.
* @message: a pointer to a gchar * which will be allocated if needed.
*
* Writes a string at the given @path.
*
* Returns: %TRUE if the writing has been successfull, %FALSE else.
*
* If returned not NULL, the @message contains an error message.
* It should be g_free() by the caller.
*/
gboolean
na_gconf_utils_write_string( GConfClient *gconf, const gchar *path, const gchar *value, gchar **message )
{
......@@ -358,6 +491,20 @@ na_gconf_utils_write_string( GConfClient *gconf, const gchar *path, const gchar
return( ret );
}
/**
* na_gconf_utils_write_string_list:
* @gconf: a #GConfClient instance.
* @path: the full path to the key.
* @value: the list of values to be written.
* @message: a pointer to a gchar * which will be allocated if needed.
*
* Writes a list of strings at the given @path.
*
* Returns: %TRUE if the writing has been successfull, %FALSE else.
*
* If returned not NULL, the @message contains an error message.
* It should be g_free() by the caller.
*/
gboolean
na_gconf_utils_write_string_list( GConfClient *gconf, const gchar *path, GSList *value, gchar **message )
{
......
......@@ -161,25 +161,28 @@ na_iio_provider_get_items_tree( const NAPivot *pivot )
GSList *level_zero;
g_debug( "%s: pivot=%p", thisfn, ( void * ) pivot );
g_return_val_if_fail( st_initialized && !st_finalized, NULL );
g_return_val_if_fail( NA_IS_PIVOT( pivot ), NULL );
g_return_val_if_fail( NA_IS_IPREFS( pivot ), NULL );
providers = na_pivot_get_providers( pivot, NA_IIO_PROVIDER_TYPE );
merged = get_merged_items_list( pivot, providers );
na_pivot_free_providers( providers );
hierarchy = NULL;
level_zero = na_iprefs_get_level_zero_items( NA_IPREFS( pivot ));
hierarchy = build_hierarchy( merged, level_zero, TRUE );
na_utils_free_string_list( level_zero );
na_object_free_items( merged );
if( st_initialized && !st_finalized ){
if( na_iprefs_is_alphabetical_order( NA_IPREFS( pivot ))){
hierarchy = sort_tree( pivot, hierarchy );
}
providers = na_pivot_get_providers( pivot, NA_IIO_PROVIDER_TYPE );
merged = get_merged_items_list( pivot, providers );
na_pivot_free_providers( providers );
na_object_dump_tree( hierarchy );
level_zero = na_iprefs_get_level_zero_items( NA_IPREFS( pivot ));
hierarchy = build_hierarchy( merged, level_zero, TRUE );
na_utils_free_string_list( level_zero );
na_object_free_items( merged );
if( na_iprefs_is_alphabetical_order( NA_IPREFS( pivot ))){
hierarchy = sort_tree( pivot, hierarchy );
}
na_object_dump_tree( hierarchy );
}
return( hierarchy );
}
......@@ -219,6 +222,7 @@ build_hierarchy( GList *tree, GSList *level_zero, gboolean list_if_empty )
}
}
}
/* if level-zero list is empty, we consider that all actions go to it
*/
else if( list_if_empty ){
......@@ -306,39 +310,43 @@ na_iio_provider_write_item( const NAPivot *pivot, NAObject *item, gchar **messag
( void * ) item, G_OBJECT_TYPE_NAME( item ),
( void * ) message );
g_return_val_if_fail( st_initialized && !st_finalized, NA_IIO_PROVIDER_PROGRAM_ERROR );
g_return_val_if_fail(( NA_IS_PIVOT( pivot ) || !pivot ), NA_IIO_PROVIDER_PROGRAM_ERROR );
g_return_val_if_fail( NA_IS_OBJECT_ITEM( item ), NA_IIO_PROVIDER_PROGRAM_ERROR );
ret = NA_IIO_PROVIDER_NOT_WRITABLE;
bad_instance = NULL;
ret = NA_IIO_PROVIDER_NOT_WILLING_TO_WRITE;
/* try to write to the original provider of the item
*/
instance = NA_IIO_PROVIDER( na_object_get_provider( item ));
if( instance ){
ret = try_write_item( instance, item, message );
if( ret == NA_IIO_PROVIDER_NOT_WILLING_TO_WRITE || ret == NA_IIO_PROVIDER_NOT_WRITABLE ){
bad_instance = instance;
instance = NULL;
}
}
if( st_initialized && !st_finalized ){
/* else, search for a provider which is willing to write the item
*/
if( !instance && pivot ){
providers = na_pivot_get_providers( pivot, NA_IIO_PROVIDER_TYPE );
for( ip = providers ; ip ; ip = ip->next ){
ret = NA_IIO_PROVIDER_NOT_WRITABLE;
bad_instance = NULL;
instance = NA_IIO_PROVIDER( ip->data );
if( !bad_instance || bad_instance != instance ){
ret = try_write_item( instance, item, message );
if( ret == NA_IIO_PROVIDER_WRITE_OK ){
break;
/* try to write to the original provider of the item
*/
instance = NA_IIO_PROVIDER( na_object_get_provider( item ));
if( instance ){
ret = try_write_item( instance, item, message );
if( ret == NA_IIO_PROVIDER_NOT_WILLING_TO_WRITE || ret == NA_IIO_PROVIDER_NOT_WRITABLE ){
bad_instance = instance;
instance = NULL;
}
}
/* else, search for a provider which is willing to write the item
*/
if( !instance && pivot ){
providers = na_pivot_get_providers( pivot, NA_IIO_PROVIDER_TYPE );
for( ip = providers ; ip ; ip = ip->next ){
instance = NA_IIO_PROVIDER( ip->data );
if( !bad_instance || bad_instance != instance ){
ret = try_write_item( instance, item, message );
if( ret == NA_IIO_PROVIDER_WRITE_OK ){
break;
}
}
}
na_pivot_free_providers( providers );
}
na_pivot_free_providers( providers );
}
return( ret );
......@@ -401,22 +409,23 @@ na_iio_provider_delete_item( const NAPivot *pivot, const NAObject *item, gchar *
( void * ) item, G_OBJECT_TYPE_NAME( item ),
( void * ) message );
g_return_val_if_fail( st_initialized && !st_finalized, NA_IIO_PROVIDER_PROGRAM_ERROR );
g_return_val_if_fail( NA_IS_PIVOT( pivot ), NA_IIO_PROVIDER_PROGRAM_ERROR );
g_return_val_if_fail( NA_IS_OBJECT_ITEM( item ), NA_IIO_PROVIDER_PROGRAM_ERROR );
ret = NA_IIO_PROVIDER_NOT_WRITABLE;
instance = NA_IIO_PROVIDER( na_object_get_provider( item ));
ret = NA_IIO_PROVIDER_NOT_WILLING_TO_WRITE;
if( st_initialized && !st_finalized ){
if( instance ){
g_assert( NA_IS_IIO_PROVIDER( instance ));
ret = NA_IIO_PROVIDER_NOT_WRITABLE;
instance = NA_IIO_PROVIDER( na_object_get_provider( item ));
if( NA_IIO_PROVIDER_GET_INTERFACE( instance )->delete_item ){
ret = NA_IIO_PROVIDER_GET_INTERFACE( instance )->delete_item( instance, item, message );
if( instance ){
g_return_val_if_fail( NA_IS_IIO_PROVIDER( instance ), NA_IIO_PROVIDER_PROGRAM_ERROR );
if( NA_IIO_PROVIDER_GET_INTERFACE( instance )->delete_item ){
ret = NA_IIO_PROVIDER_GET_INTERFACE( instance )->delete_item( instance, item, message );
}
}
/*} else {
*message = g_strdup( _( "Unable to delete the action: no I/O provider." ));
ret = NA_IIO_PROVIDER_NO_PROVIDER;*/
}
return( ret );
......
......@@ -104,6 +104,8 @@ interface_base_init( NAIPivotConsumerInterface *klass )
klass->private = g_new0( NAIPivotConsumerInterfacePrivate, 1 );