Commit e4914cb6 authored by Philippe Rouquier's avatar Philippe Rouquier Committed by Philippe Rouquier

Fix #510480 – Migrate from GnomeVFS to GIO Removed GnomeVFS dependency.

2008-02-25  Philippe Rouquier  <philippr@svn.gnome.org>

	Fix #510480 – Migrate from GnomeVFS to GIO
	Removed GnomeVFS dependency. Now brasero uses Gio and requires glib 2.15.5 at least
	Some memleaks fixed.
	Fixed crash (division by 0)

	* configure.in:
	* src/Makefile.am:
	* src/brasero-async-task-manager.c:
	(brasero_async_task_manager_finalize),
	(brasero_async_task_manager_insert_task),
	(brasero_async_task_manager_thread),
	(brasero_async_task_manager_queue),
	(brasero_async_task_manager_foreach_active),
	(brasero_async_task_manager_foreach_active_remove),
	(brasero_async_task_manager_foreach_unprocessed_remove),
	(brasero_async_task_manager_find_urgent_task):
	* src/brasero-async-task-manager.h:
	* src/brasero-audio-disc.c: (brasero_audio_disc_init),
	(brasero_audio_disc_reset_real), (brasero_audio_disc_finalize),
	(brasero_audio_disc_validate_utf8_name),
	(brasero_audio_disc_set_row_from_metadata),
	(brasero_audio_disc_result),
	(brasero_audio_disc_vfs_operation_finished),
	(brasero_audio_disc_visit_dir_async),
	(brasero_audio_disc_add_playlist),
	(brasero_audio_disc_unreadable_dialog),
	(brasero_audio_disc_new_row_cb), (brasero_audio_disc_add_uri_real),
	(brasero_audio_disc_clipboard_text_cb),
	(brasero_audio_disc_start_monitoring),
	(brasero_audio_disc_inotify_modify),
	(brasero_audio_disc_inotify_attributes_changed_cb),
	(brasero_audio_disc_inotify_attributes_changed),
	(brasero_audio_disc_inotify_monitor_cb):
	* src/brasero-data-disc.c: (brasero_data_disc_clipboard_text_cb),
	(brasero_data_disc_unreadable_uri_cb):
	* src/brasero-data-project.c: (brasero_data_project_uri_to_nodes),
	(brasero_data_project_uri_is_graft_needed),
	(brasero_data_project_node_loaded),
	(brasero_data_project_node_reloaded),
	(brasero_data_project_add_node_from_info),
	(brasero_data_project_add_excluded_uri),
	(brasero_data_project_file_added),
	(brasero_data_project_file_update_URI),
	(brasero_data_project_file_graft):
	* src/brasero-data-project.h:
	* src/brasero-data-tree-model.c:
	(brasero_data_tree_model_get_value):
	* src/brasero-data-vfs.c: (brasero_data_vfs_check_uri_result),
	(brasero_data_vfs_directory_load_end),
	(brasero_data_vfs_directory_check_symlink_loop),
	(brasero_data_vfs_directory_load_result),
	(brasero_data_vfs_load_directory),
	(brasero_data_vfs_loading_node_end),
	(brasero_data_vfs_loading_node_result),
	(brasero_data_vfs_load_node), (brasero_data_vfs_loading_node),
	(brasero_data_vfs_require_higher_priority),
	(brasero_data_vfs_require_directory_contents),
	(brasero_data_vfs_require_node_load), (brasero_data_vfs_load_mime),
	(brasero_data_vfs_clear), (brasero_data_vfs_init),
	(brasero_data_vfs_finalize), (brasero_data_vfs_class_init):
	* src/brasero-disc-message.c: (brasero_disc_message_finalize):
	* src/brasero-drive-info.c: (brasero_drive_info_update_info):
	* src/brasero-drive-properties.c:
	(brasero_drive_properties_set_tmpdir):
	* src/brasero-file-filtered.c: (brasero_file_filtered_add):
	* src/brasero-file-monitor.c:
	(brasero_file_monitor_start_monitoring_real):
	* src/brasero-file-node.c: (brasero_file_node_validate_utf8_name),
	(brasero_file_node_set_from_info),
	(brasero_file_node_get_uri_name),
	(brasero_file_node_new_from_info):
	* src/brasero-file-node.h:
	* src/brasero-image-option-dialog.c:
	(brasero_image_option_dialog_image_info_cb),
	(brasero_image_option_dialog_get_format),
	(brasero_image_option_dialog_finalize):
	* src/brasero-metadata.c: (brasero_metadata_stop),
	(brasero_metadata_cancel), (brasero_metadata_completed),
	(brasero_metadata_process_pending_tag_messages),
	(brasero_metadata_success), (brasero_metadata_bus_messages),
	(brasero_metadata_new_decoded_pad_cb),
	(brasero_metadata_set_new_uri), (brasero_metadata_cancelled_cb),
	(brasero_metadata_get_info_wait), (brasero_metadata_get_info_sync),
	(brasero_metadata_info_copy), (brasero_metadata_set_info),
	(brasero_metadata_init), (brasero_metadata_finalize):
	* src/brasero-metadata.h:
	* src/brasero-mime-filter.c: (brasero_mime_filter_add_mime):
	* src/brasero-ncb.c: (NCB_DRIVE_GET_VFS_DRIVE),
	(NCB_VOLUME_GET_MOUNT_POINT):
	* src/brasero-player-bacon.c:
	* src/brasero-player.c: (brasero_player_image),
	(brasero_player_metadata_completed),
	(brasero_player_retrieve_metadata), (brasero_player_set_uri),
	(brasero_player_destroy):
	* src/brasero-playlist.c: (brasero_playlist_init),
	(brasero_playlist_destroy), (brasero_playlist_parse_end),
	(brasero_playlist_parse_result),
	(brasero_playlist_add_uri_playlist):
	* src/brasero-project-manager.c:
	(brasero_project_manager_set_statusbar),
	(brasero_project_manager_size_preview),
	(brasero_project_manager_size_preview_progress),
	(brasero_project_manager_selected_uris_changed),
	(brasero_project_manager_load_session),
	(brasero_project_manager_save_session),
	(brasero_project_manager_finalize):
	* src/brasero-project.c: (brasero_project_open_project_xml),
	(brasero_project_save_project_xml):
	* src/brasero-search-beagle.c:
	* src/brasero-sum-dialog.c: (brasero_sum_dialog_download),
	(brasero_sum_dialog_get_file_checksum):
	* src/brasero-utils.c: (brasero_utils_launch_app):
	* src/brasero-utils.h:
	* src/brasero-vfs.c: (brasero_vfs_check_for_parent_symlink),
	(brasero_utils_get_symlink_target), (brasero_vfs_info_thread),
	(brasero_vfs_load_thread), (brasero_vfs_metadata_ctx_new),
	(brasero_vfs_metadata_result), (brasero_vfs_count_result_audio),
	(brasero_vfs_count_result_data),
	(brasero_vfs_playlist_subtask_result):
	* src/brasero-vfs.h:
	* src/brasero-xfer.c: (brasero_xfer_result_cb),
	(brasero_xfer_progress_cb), (brasero_xfer), (brasero_xfer_cancel):
	* src/brasero-xfer.h:
	* src/burn-basics.c:
	* src/burn-basics.h:
	* src/burn-caps.c: (brasero_caps_add_processing_plugins_to_task):
	* src/burn-job.c: (brasero_job_check_output_volume_space):
	* src/burn-mkisofs-base.c: (brasero_mkisofs_base_write_excluded),
	(_build_graft_point):
	* src/burn-session.c:
	* src/burn-track.c: (brasero_track_get_localpath),
	(brasero_track_get_uri):
	* src/burn-volume.c:
	* src/burn.c:
	* src/main.c: (brasero_app_parse_options), (main):
	* src/plugins/cdrdao/burn-cdrdao.c:
	* src/plugins/checksum/burn-md5sum-file.c:
	(brasero_md5sum_file_grafts):
	* src/plugins/checksum/burn-md5sum.c:
	* src/plugins/libburnia/burn-libisofs.c:
	(brasero_libisofs_create_volume_thread):
	* src/plugins/local-track/burn-local-image.c:
	(brasero_local_track_get_download_size),
	(brasero_local_track_progress_cb),
	(brasero_local_track_file_transfer),
	(brasero_local_track_recursive_transfer),
	(brasero_local_track_transfer),
	(brasero_local_track_read_checksum),
	(brasero_local_track_download_checksum),
	(brasero_local_track_thread_finished),
	(brasero_local_track_thread), (brasero_local_track_start_thread),
	(_foreach_non_local_cb), (brasero_local_track_add_if_non_local),
	(brasero_local_track_start), (brasero_local_track_stop):
	* src/scsi-read-cd.c: (brasero_mmc1_read_block):

svn path=/trunk/; revision=648
parent 4e181766
2008-02-25 Philippe Rouquier <philippr@svn.gnome.org>
Fix #510480 – Migrate from GnomeVFS to GIO
Removed GnomeVFS dependency. Now brasero uses Gio and requires glib 2.15.5 at least
Some memleaks fixed.
Fixed crash (division by 0)
* configure.in:
* src/Makefile.am:
* src/brasero-async-task-manager.c:
(brasero_async_task_manager_finalize),
(brasero_async_task_manager_insert_task),
(brasero_async_task_manager_thread),
(brasero_async_task_manager_queue),
(brasero_async_task_manager_foreach_active),
(brasero_async_task_manager_foreach_active_remove),
(brasero_async_task_manager_foreach_unprocessed_remove),
(brasero_async_task_manager_find_urgent_task):
* src/brasero-async-task-manager.h:
* src/brasero-audio-disc.c: (brasero_audio_disc_init),
(brasero_audio_disc_reset_real), (brasero_audio_disc_finalize),
(brasero_audio_disc_validate_utf8_name),
(brasero_audio_disc_set_row_from_metadata),
(brasero_audio_disc_result),
(brasero_audio_disc_vfs_operation_finished),
(brasero_audio_disc_visit_dir_async),
(brasero_audio_disc_add_playlist),
(brasero_audio_disc_unreadable_dialog),
(brasero_audio_disc_new_row_cb), (brasero_audio_disc_add_uri_real),
(brasero_audio_disc_clipboard_text_cb),
(brasero_audio_disc_start_monitoring),
(brasero_audio_disc_inotify_modify),
(brasero_audio_disc_inotify_attributes_changed_cb),
(brasero_audio_disc_inotify_attributes_changed),
(brasero_audio_disc_inotify_monitor_cb):
* src/brasero-data-disc.c: (brasero_data_disc_clipboard_text_cb),
(brasero_data_disc_unreadable_uri_cb):
* src/brasero-data-project.c: (brasero_data_project_uri_to_nodes),
(brasero_data_project_uri_is_graft_needed),
(brasero_data_project_node_loaded),
(brasero_data_project_node_reloaded),
(brasero_data_project_add_node_from_info),
(brasero_data_project_add_excluded_uri),
(brasero_data_project_file_added),
(brasero_data_project_file_update_URI),
(brasero_data_project_file_graft):
* src/brasero-data-project.h:
* src/brasero-data-tree-model.c:
(brasero_data_tree_model_get_value):
* src/brasero-data-vfs.c: (brasero_data_vfs_check_uri_result),
(brasero_data_vfs_directory_load_end),
(brasero_data_vfs_directory_check_symlink_loop),
(brasero_data_vfs_directory_load_result),
(brasero_data_vfs_load_directory),
(brasero_data_vfs_loading_node_end),
(brasero_data_vfs_loading_node_result),
(brasero_data_vfs_load_node), (brasero_data_vfs_loading_node),
(brasero_data_vfs_require_higher_priority),
(brasero_data_vfs_require_directory_contents),
(brasero_data_vfs_require_node_load), (brasero_data_vfs_load_mime),
(brasero_data_vfs_clear), (brasero_data_vfs_init),
(brasero_data_vfs_finalize), (brasero_data_vfs_class_init):
* src/brasero-disc-message.c: (brasero_disc_message_finalize):
* src/brasero-drive-info.c: (brasero_drive_info_update_info):
* src/brasero-drive-properties.c:
(brasero_drive_properties_set_tmpdir):
* src/brasero-file-filtered.c: (brasero_file_filtered_add):
* src/brasero-file-monitor.c:
(brasero_file_monitor_start_monitoring_real):
* src/brasero-file-node.c: (brasero_file_node_validate_utf8_name),
(brasero_file_node_set_from_info),
(brasero_file_node_get_uri_name),
(brasero_file_node_new_from_info):
* src/brasero-file-node.h:
* src/brasero-image-option-dialog.c:
(brasero_image_option_dialog_image_info_cb),
(brasero_image_option_dialog_get_format),
(brasero_image_option_dialog_finalize):
* src/brasero-metadata.c: (brasero_metadata_stop),
(brasero_metadata_cancel), (brasero_metadata_completed),
(brasero_metadata_process_pending_tag_messages),
(brasero_metadata_success), (brasero_metadata_bus_messages),
(brasero_metadata_new_decoded_pad_cb),
(brasero_metadata_set_new_uri), (brasero_metadata_cancelled_cb),
(brasero_metadata_get_info_wait), (brasero_metadata_get_info_sync),
(brasero_metadata_info_copy), (brasero_metadata_set_info),
(brasero_metadata_init), (brasero_metadata_finalize):
* src/brasero-metadata.h:
* src/brasero-mime-filter.c: (brasero_mime_filter_add_mime):
* src/brasero-ncb.c: (NCB_DRIVE_GET_VFS_DRIVE),
(NCB_VOLUME_GET_MOUNT_POINT):
* src/brasero-player-bacon.c:
* src/brasero-player.c: (brasero_player_image),
(brasero_player_metadata_completed),
(brasero_player_retrieve_metadata), (brasero_player_set_uri),
(brasero_player_destroy):
* src/brasero-playlist.c: (brasero_playlist_init),
(brasero_playlist_destroy), (brasero_playlist_parse_end),
(brasero_playlist_parse_result),
(brasero_playlist_add_uri_playlist):
* src/brasero-project-manager.c:
(brasero_project_manager_set_statusbar),
(brasero_project_manager_size_preview),
(brasero_project_manager_size_preview_progress),
(brasero_project_manager_selected_uris_changed),
(brasero_project_manager_load_session),
(brasero_project_manager_save_session),
(brasero_project_manager_finalize):
* src/brasero-project.c: (brasero_project_open_project_xml),
(brasero_project_save_project_xml):
* src/brasero-search-beagle.c:
* src/brasero-sum-dialog.c: (brasero_sum_dialog_download),
(brasero_sum_dialog_get_file_checksum):
* src/brasero-utils.c: (brasero_utils_launch_app):
* src/brasero-utils.h:
* src/brasero-vfs.c: (brasero_vfs_check_for_parent_symlink),
(brasero_utils_get_symlink_target), (brasero_vfs_info_thread),
(brasero_vfs_load_thread), (brasero_vfs_metadata_ctx_new),
(brasero_vfs_metadata_result), (brasero_vfs_count_result_audio),
(brasero_vfs_count_result_data),
(brasero_vfs_playlist_subtask_result):
* src/brasero-vfs.h:
* src/brasero-xfer.c: (brasero_xfer_result_cb),
(brasero_xfer_progress_cb), (brasero_xfer), (brasero_xfer_cancel):
* src/brasero-xfer.h:
* src/burn-basics.c:
* src/burn-basics.h:
* src/burn-caps.c: (brasero_caps_add_processing_plugins_to_task):
* src/burn-job.c: (brasero_job_check_output_volume_space):
* src/burn-mkisofs-base.c: (brasero_mkisofs_base_write_excluded),
(_build_graft_point):
* src/burn-session.c:
* src/burn-track.c: (brasero_track_get_localpath),
(brasero_track_get_uri):
* src/burn-volume.c:
* src/burn.c:
* src/main.c: (brasero_app_parse_options), (main):
* src/plugins/cdrdao/burn-cdrdao.c:
* src/plugins/checksum/burn-md5sum-file.c:
(brasero_md5sum_file_grafts):
* src/plugins/checksum/burn-md5sum.c:
* src/plugins/libburnia/burn-libisofs.c:
(brasero_libisofs_create_volume_thread):
* src/plugins/local-track/burn-local-image.c:
(brasero_local_track_get_download_size),
(brasero_local_track_progress_cb),
(brasero_local_track_file_transfer),
(brasero_local_track_recursive_transfer),
(brasero_local_track_transfer),
(brasero_local_track_read_checksum),
(brasero_local_track_download_checksum),
(brasero_local_track_thread_finished),
(brasero_local_track_thread), (brasero_local_track_start_thread),
(_foreach_non_local_cb), (brasero_local_track_add_if_non_local),
(brasero_local_track_start), (brasero_local_track_stop):
* src/scsi-read-cd.c: (brasero_mmc1_read_block):
2008-02-17 Philippe Rouquier <philippr@svn.gnome.org>
Add FreeBSD support
......
......@@ -63,13 +63,14 @@ dnl ***************** LARGE FILE SUPPORT ***********************
AC_SYS_LARGEFILE
dnl ********** GNOME2 ******************************
GLIB_REQUIRED=2.6.0
GLIB_REQUIRED=2.15.5
GMODULE_REQUIRED=2.6.0
GIO_REQUIRED=2.15.5
GDK_REQUIRED=2.6.0
GTK_REQUIRED=2.11.6
LIBGNOME_REQUIRED=2.10.0
LIBGNOMEUI_REQUIRED=2.10.0
GNOME_VFS_REQUIRED=2.14.2
GCONF_REQUIRED=2.0.0
GSTREAMER_REQUIRED=0.10.6
GSTREAMER_BASE_REQUIRED=0.10.0
LIBXML2_REQUIRED=2.6.0
......@@ -87,25 +88,25 @@ BRASERO_GSTREAMER_CFLAGS="$BRASERO_GSTREAMER_CFLAGS $CFLAGS"
BRASERO_GSTREAMER_LIBS="$BRASERO_GSTREAMER_LIBS $LDFLAGS"
dnl ** used by brasero and one plugin
PKG_CHECK_MODULES(BRASERO_GNOMEVFS, \
gnome-vfs-2.0 >= $GNOME_VFS_REQUIRED \
gnome-vfs-module-2.0)
AC_SUBST(BRASERO_GNOMEVFS_CFLAGS)
AC_SUBST(BRASERO_GNOMEVFS_LIBS)
PKG_CHECK_MODULES(BRASERO_GIO, \
gio-2.0 >= $GIO_REQUIRED)
BRASERO_GNOMEVFS_CFLAGS="$BRASERO_GNOMEVFS_CFLAGS $CFLAGS"
BRASERO_GNOMEVFS_LIBS="$BRASERO_GNOMEVFS_LIBS $LDFLAGS"
AC_SUBST(BRASERO_GIO_CFLAGS)
AC_SUBST(BRASERO_GIO_LIBS)
BRASERO_GIO_CFLAGS="$BRASERO_GIO_CFLAGS $CFLAGS"
BRASERO_GIO_LIBS="$BRASERO_GIO_LIBS $LDFLAGS"
dnl ** used by brasero and all modules
PKG_CHECK_MODULES(BRASERO_BASE, \
libnautilus-burn >= $NAUTILUS_BURN_REQUIRED \
gconf-2.0 >= $GCONF_REQUIRED \
glib-2.0 >= $GLIB_REQUIRED)
AC_SUBST(BRASERO_BASE_CFLAGS)
AC_SUBST(BRASERO_BASE_LIBS)
BRASERO_BASE_CFLAGS="$BRASERO_BASE_CFLAGS $BRASERO_GNOMEVFS_CFLAGS $CFLAGS"
BRASERO_BASE_CFLAGS="$BRASERO_BASE_CFLAGS $BRASERO_GIO_CFLAGS $CFLAGS"
BRASERO_BASE_LIBS="$BRASERO_BASE_LIBS $LDFLAGS"
dnl ** used only by brasero app itself ***
......@@ -116,11 +117,11 @@ PKG_CHECK_MODULES(BRASERO, \
libgnome-2.0 >= $LIBGNOME_REQUIRED \
libgnomeui-2.0 >= $LIBGNOMEUI_REQUIRED \
libxml-2.0 >= $LIBXML2_REQUIRED)
AC_SUBST(BRASERO_CFLAGS)
AC_SUBST(BRASERO_LIBS)
BRASERO_CFLAGS="$BRASERO_BASE_CFLAGS $BRASERO_GSTREAMER_CFLAGS $BRASERO_GNOMEVFS_CFLAGS $BRASERO_CFLAGS $CFLAGS"
BRASERO_LIBS="$BRASERO_BASE_LIBS $BRASERO_GSTREAMER_LIBS $BRASERO_GNOMEVFS_LIBS $BRASERO_LIBS $BRASERO_SCSI_LIBS $LDFLAGS"
BRASERO_CFLAGS="$BRASERO_BASE_CFLAGS $BRASERO_GSTREAMER_CFLAGS $BRASERO_GIO_CFLAGS $BRASERO_CFLAGS $CFLAGS"
BRASERO_LIBS="$BRASERO_BASE_LIBS $BRASERO_GSTREAMER_LIBS $BRASERO_GIO_LIBS $BRASERO_LIBS $BRASERO_SCSI_LIBS $LDFLAGS"
dnl ****************check for libburn (optional)**************
LIBBURN_REQUIRED=0.4.0
......
......@@ -106,8 +106,6 @@ brasero_SOURCES = \
brasero-ncb.c \
burn-task.c \
burn-task.h \
brasero-vfs.c \
brasero-vfs.h \
brasero-async-task-manager.c \
brasero-async-task-manager.h \
eggtreemultidnd.c \
......@@ -231,7 +229,9 @@ brasero_SOURCES = \
brasero-disc-message.c \
baobab-cell-renderer-progress.c \
baobab-cell-renderer-progress.h \
scsi-device.h
scsi-device.h \
brasero-io.h \
brasero-io.c
if BUILD_INOTIFY
brasero_SOURCES += brasero-file-monitor.c brasero-file-monitor.h
......
......@@ -22,6 +22,14 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <glib.h>
#include <gio/gio.h>
#include <glib-object.h>
#include "brasero-async-task-manager.h"
static void brasero_async_task_manager_class_init (BraseroAsyncTaskManagerClass *klass);
......@@ -36,32 +44,22 @@ struct BraseroAsyncTaskManagerPrivate {
GSList *waiting_tasks;
GSList *active_tasks;
GSList *results;
gint num_threads;
gint unused_threads;
gint results_id;
GHashTable *types;
BraseroAsyncTaskTypeID type_num;
gint cancelled:1;
};
struct _BraseroAsyncTaskType {
BraseroAsyncThread thread;
BraseroSyncResult result;
};
typedef struct _BraseroAsyncTaskType BraseroAsyncTaskType;
struct _BraseroAsyncTaskCtx {
BraseroAsyncTaskType *common;
BraseroAsyncPriority priority;
const BraseroAsyncTaskType *type;
GCancellable *cancel;
gpointer data;
};
typedef struct _BraseroAsyncTaskCtx BraseroAsyncTaskCtx;
#define MANAGER_MAX_THREAD 1
#define MANAGER_MAX_THREAD 2
static GObjectClass *parent_class = NULL;
......@@ -142,25 +140,8 @@ brasero_async_task_manager_finalize (GObject *object)
while (cobj->priv->num_threads)
g_cond_wait (cobj->priv->thread_finished, cobj->priv->lock);
if (cobj->priv->results_id) {
g_source_remove (cobj->priv->results_id);
cobj->priv->results_id = 0;
}
/* remove all the results in case one got added */
g_slist_foreach (cobj->priv->results,
(GFunc) g_free,
NULL);
g_slist_free (cobj->priv->results);
cobj->priv->results = NULL;
g_mutex_unlock (cobj->priv->lock);
if (cobj->priv->types) {
g_hash_table_destroy (cobj->priv->types);
cobj->priv->types = NULL;
}
if (cobj->priv->task_finished) {
g_cond_free (cobj->priv->task_finished);
cobj->priv->task_finished = NULL;
......@@ -185,79 +166,57 @@ brasero_async_task_manager_finalize (GObject *object)
G_OBJECT_CLASS (parent_class)->finalize (object);
}
BraseroAsyncTaskTypeID
brasero_async_task_manager_register_type (BraseroAsyncTaskManager *self,
BraseroAsyncThread thread,
BraseroSyncResult result)
static void
brasero_async_task_manager_insert_task (BraseroAsyncTaskManager *self,
BraseroAsyncTaskCtx *ctx)
{
BraseroAsyncTaskType *type;
g_return_val_if_fail (self != 0, 0);
self->priv->type_num ++;
if (self->priv->type_num == G_MAXINT) {
self->priv->type_num = 1;
GSList *iter;
GSList *node;
BraseroAsyncTaskCtx *tmp;
while (g_hash_table_lookup (self->priv->types, GINT_TO_POINTER (self->priv->type_num))) {
self->priv->type_num ++;
node = g_slist_alloc ();
node->data = ctx;
if (self->priv->type_num == G_MAXINT) {
g_warning ("ERROR: reached the max number of types\n");
return 0;
}
}
if (!self->priv->waiting_tasks) {
self->priv->waiting_tasks = node;
return;
}
type = g_new0 (BraseroAsyncTaskType, 1);
type->thread = thread;
type->result = result;
if (!self->priv->types)
self->priv->types = g_hash_table_new_full (g_direct_hash,
g_direct_equal,
NULL,
g_free);
g_hash_table_insert (self->priv->types,
GINT_TO_POINTER (self->priv->type_num),
type);
return self->priv->type_num;
}
static gboolean
brasero_async_task_manager_result (BraseroAsyncTaskManager *self)
{
BraseroAsyncTaskCtx *ctx;
g_mutex_lock (self->priv->lock);
tmp = self->priv->waiting_tasks->data;
if (!self->priv->results) {
self->priv->results_id = 0;
g_mutex_unlock (self->priv->lock);
return FALSE;
if (tmp->priority < ctx->priority) {
node->next = self->priv->waiting_tasks;
self->priv->waiting_tasks = node;
return;
}
ctx = self->priv->results->data;
self->priv->results = g_slist_remove (self->priv->results, ctx);
g_mutex_unlock (self->priv->lock);
for (iter = self->priv->waiting_tasks; iter->next; iter = iter->next) {
tmp = iter->next->data;
ctx->common->result (self, ctx->data);
g_free (ctx);
if (tmp->priority < ctx->priority) {
node->next = iter->next;
iter->next = node;
return;
}
}
return TRUE;
iter->next = node;
}
static gpointer
brasero_async_task_manager_thread (BraseroAsyncTaskManager *self)
{
gboolean result;
GCancellable *cancel;
BraseroAsyncTaskCtx *ctx;
cancel = g_cancellable_new ();
g_mutex_lock (self->priv->lock);
while (1) {
BraseroAsyncTaskResult res;
/* say we are unused */
self->priv->unused_threads ++;
......@@ -290,21 +249,46 @@ brasero_async_task_manager_thread (BraseroAsyncTaskManager *self)
/* get the data from the list */
ctx = self->priv->waiting_tasks->data;
ctx->cancel = cancel;
ctx->priority &= ~BRASERO_ASYNC_RESCHEDULE;
self->priv->waiting_tasks = g_slist_remove (self->priv->waiting_tasks, ctx);
self->priv->active_tasks = g_slist_prepend (self->priv->active_tasks, ctx);
g_mutex_unlock (self->priv->lock);
ctx->common->thread (self, ctx->data);
res = ctx->type->thread (self, cancel, ctx->data);
g_mutex_lock (self->priv->lock);
/* we remove the task from the list and signal it is finished */
self->priv->active_tasks = g_slist_remove (self->priv->active_tasks, ctx);
g_cond_signal (self->priv->task_finished);
/* insert the task in the results queue */
self->priv->results = g_slist_append (self->priv->results, ctx);
if (!self->priv->results_id)
self->priv->results_id = g_idle_add ((GSourceFunc) brasero_async_task_manager_result, self);
if (g_cancellable_is_cancelled (cancel)) {
if (ctx->type->destroy)
ctx->type->destroy (self, ctx->data);
g_free (ctx);
}
else if (res == BRASERO_ASYNC_TASK_RESCHEDULE) {
if (self->priv->waiting_tasks) {
BraseroAsyncTaskCtx *next;
next = self->priv->waiting_tasks->data;
if (next->priority > ctx->priority)
brasero_async_task_manager_insert_task (self, ctx);
else
self->priv->waiting_tasks = g_slist_prepend (self->priv->waiting_tasks, ctx);
}
else
self->priv->waiting_tasks = g_slist_prepend (self->priv->waiting_tasks, ctx);
}
else {
if (ctx->type->destroy)
ctx->type->destroy (self, ctx->data);
g_free (ctx);
}
g_cancellable_reset (cancel);
}
end:
......@@ -316,6 +300,8 @@ end:
g_cond_signal (self->priv->thread_finished);
g_mutex_unlock (self->priv->lock);
g_object_unref (cancel);
g_thread_exit (NULL);
return NULL;
......@@ -323,25 +309,26 @@ end:
gboolean
brasero_async_task_manager_queue (BraseroAsyncTaskManager *self,
BraseroAsyncTaskTypeID type,
BraseroAsyncPriority priority,
const BraseroAsyncTaskType *type,
gpointer data)
{
BraseroAsyncTaskCtx *ctx;
BraseroAsyncTaskType *task_type;
g_return_val_if_fail (self != NULL, FALSE);
g_return_val_if_fail (type > 0, FALSE);
task_type = g_hash_table_lookup (self->priv->types, GINT_TO_POINTER (type));
if (!task_type)
return FALSE;
ctx = g_new0 (BraseroAsyncTaskCtx, 1);
ctx->priority = priority;
ctx->type = type;
ctx->data = data;
ctx->common = task_type;
g_mutex_lock (self->priv->lock);
self->priv->waiting_tasks = g_slist_append (self->priv->waiting_tasks, ctx);
if (priority == BRASERO_ASYNC_IDLE)
self->priv->waiting_tasks = g_slist_append (self->priv->waiting_tasks, ctx);
else if (priority == BRASERO_ASYNC_NORMAL)
brasero_async_task_manager_insert_task (self, ctx);
else if (priority == BRASERO_ASYNC_URGENT)
self->priv->waiting_tasks = g_slist_prepend (self->priv->waiting_tasks, ctx);
if (self->priv->unused_threads) {
/* wake up one thread in the list */
......@@ -356,7 +343,6 @@ brasero_async_task_manager_queue (BraseroAsyncTaskManager *self,
self,
FALSE,
&error);
if (!thread) {
g_warning ("Can't start thread : %s\n", error->message);
g_error_free (error);
......@@ -380,6 +366,29 @@ gboolean
brasero_async_task_manager_foreach_active (BraseroAsyncTaskManager *self,
BraseroAsyncFindTask func,
gpointer user_data)
{
GSList *iter;
BraseroAsyncTaskCtx *ctx;
gboolean result = FALSE;
g_return_val_if_fail (self != NULL, FALSE);
g_return_val_if_fail (func != NULL, FALSE);
g_mutex_lock (self->priv->lock);
for (iter = self->priv->active_tasks; iter; iter = iter->next) {
ctx = iter->data;
if (func (self, ctx->data, user_data))
result = TRUE;
}
g_mutex_unlock (self->priv->lock);
return result;
}
gboolean
brasero_async_task_manager_foreach_active_remove (BraseroAsyncTaskManager *self,
BraseroAsyncFindTask func,
gpointer user_data)
{
GSList *iter, *tasks = NULL;
BraseroAsyncTaskCtx *ctx;
......@@ -391,8 +400,10 @@ brasero_async_task_manager_foreach_active (BraseroAsyncTaskManager *self,
for (iter = self->priv->active_tasks; iter; iter = iter->next) {
ctx = iter->data;
if (func (self, ctx->data, user_data))
if (func (self, ctx->data, user_data)) {
g_cancellable_cancel (ctx->cancel);
tasks = g_slist_prepend (tasks, ctx);
}
}
while (tasks) {
......@@ -402,37 +413,20 @@ brasero_async_task_manager_foreach_active (BraseroAsyncTaskManager *self,
for (iter = tasks; iter; iter = iter->next) {
ctx = iter->data;
if (g_slist_find (self->priv->active_tasks, ctx) == NULL) {
tasks = g_slist_remove (tasks, ctx);
break;
}
}
}
g_mutex_unlock (self->priv->lock);
return TRUE;
}
static GSList *
brasero_async_task_manager_foreach_remove (BraseroAsyncTaskManager *self,
GSList *list,
BraseroAsyncFindTask func,
gpointer user_data)
{
BraseroAsyncTaskCtx *ctx;
GSList *iter, *next;
if (g_slist_find (self->priv->active_tasks, ctx))
continue;
for (iter = list; iter; iter = next) {
ctx = iter->data;
next = iter->next;
tasks = g_slist_remove (tasks, ctx);
if (func (self, ctx->data, user_data)) {
list = g_slist_remove (list, ctx);
g_free (ctx);
/* NOTE: no need to call destroy callback here
* since it was done in the thread loop. */
break;
}
}
return list;
g_mutex_unlock (self->priv->lock);
return TRUE;
}
gboolean
......@@ -440,32 +434,28 @@ brasero_async_task_manager_foreach_unprocessed_remove (BraseroAsyncTaskManager *
BraseroAsyncFindTask func,
gpointer user_data)
{
BraseroAsyncTaskCtx *ctx;
GSList *iter, *next;
g_return_val_if_fail (self != NULL, FALSE);
g_return_val_if_fail (func != NULL, FALSE);
g_mutex_lock (self->priv->lock);
self->priv->waiting_tasks = brasero_async_task_manager_foreach_remove (self,
self->priv->waiting_tasks,
func,
user_data);
g_mutex_unlock (self->priv->lock);
return TRUE;
}
for (iter = self->priv->waiting_tasks; iter; iter = next) {
ctx = iter->data;
next = iter->next;
gboolean
brasero_async_task_manager_foreach_processed_remove (BraseroAsyncTaskManager *self,
BraseroAsyncFindTask func,
gpointer user_data)
{
g_return_val_if_fail (self != NULL, FALSE);
g_return_val_if_fail (func != NULL, FALSE);
if (func (self, ctx->data, user_data)) {
self->priv->waiting_tasks = g_slist_remove (self->priv->waiting_tasks, ctx);
g_mutex_lock (self->priv->lock);
self->priv->results = brasero_async_task_manager_foreach_remove (self,
self->priv->results,
func,
user_data);
/* call the destroy callback */
if (ctx->type->destroy)
ctx->type->destroy (self, ctx->data);
g_free (ctx);
}
}
g_mutex_unlock (self->priv->lock);
return TRUE;
......@@ -487,6 +477,8 @@ brasero_async_task_manager_find_urgent_task (BraseroAsyncTaskManager *self,
ctx = iter->data;
if (func (self, ctx->data, user_data)) {
ctx->priority = BRASERO_ASYNC_URGENT;
self->priv->waiting_tasks = g_slist_remove (self->priv->waiting_tasks, ctx);
self->priv->waiting_tasks = g_slist_prepend (self->priv->waiting_tasks, ctx);
g_mutex_unlock (self->priv->lock);
......
......@@ -28,6 +28,8 @@
#include <glib.h>
#include <glib-object.h>
#include <gio/gio.h>
G_BEGIN_DECLS
#define BRASERO_TYPE_ASYNC_TASK_MANAGER (brasero_async_task_manager_get_type ())
......@@ -48,18 +50,41 @@ typedef struct {
GObjectClass parent_class;
} BraseroAsyncTaskManagerClass;
typedef void (*BraseroAsyncThread) (BraseroAsyncTaskManager *manager, gpointer user_data);
typedef void (*BraseroSyncResult) (BraseroAsyncTaskManager *manager, gpointer user_data);
typedef gboolean (*BraseroAsyncFindTask) (BraseroAsyncTaskManager *manager, gpointer task, gpointer user_data);
GType brasero_async_task_manager_get_type ();
typedef guint BraseroAsyncTaskTypeID;
typedef enum {
BRASERO_ASYNC_TASK_FINISHED = 0,
BRASERO_ASYNC_TASK_RESCHEDULE = 1
} BraseroAsyncTaskResult;
typedef BraseroAsyncTaskResult (*BraseroAsyncThread) (BraseroAsyncTaskManager *manager,
GCancellable *cancel,
gpointer user_data);
typedef void (*BraseroAsyncDestroy) (BraseroAsyncTaskManager *manager,
gpointer user_data);
typedef gboolean (*BraseroAsyncFindTask) (BraseroAsyncTaskManager *manager,
gpointer task,
gpointer user_data);
struct _BraseroAsyncTaskType {
BraseroAsyncThread thread;
BraseroAsyncDestroy destroy;
};
typedef struct _BraseroAsyncTaskType BraseroAsyncTaskType;
typedef enum {