diff options
author | Ryan Lortie <desrt@desrt.ca> | 2013-01-18 18:30:36 -0500 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2013-01-19 14:04:49 -0500 |
commit | c83600e8ae419df7c30b16d267d71d706a29936f (patch) | |
tree | 47b1a1f085e9f882d701315a7c75678a375c5dff /gio | |
parent | 3a7b44c007c2d80d9adfa883eca82124ec39deee (diff) | |
download | glib-c83600e8ae419df7c30b16d267d71d706a29936f.tar.gz glib-c83600e8ae419df7c30b16d267d71d706a29936f.tar.bz2 glib-c83600e8ae419df7c30b16d267d71d706a29936f.zip |
file monitors: use new giomodule function
Get rid of the complicated default module detection code in
GLocalFileMonitor and GLocalDirectoryMonitor and use the new
_gio_module_get_default_type() function instead.
This change also adds the ability to override the default file monitor
via the GIO_USE_FILE_MONITOR environment variable in the same way as can
be done for GIO_USE_VFS.
https://bugzilla.gnome.org/show_bug.cgi?id=592211
Diffstat (limited to 'gio')
-rw-r--r-- | gio/glocaldirectorymonitor.c | 60 | ||||
-rw-r--r-- | gio/glocalfilemonitor.c | 60 |
2 files changed, 8 insertions, 112 deletions
diff --git a/gio/glocaldirectorymonitor.c b/gio/glocaldirectorymonitor.c index c5e7088b9..319b87a78 100644 --- a/gio/glocaldirectorymonitor.c +++ b/gio/glocaldirectorymonitor.c @@ -226,76 +226,24 @@ mounts_changed (GUnixMountMonitor *mount_monitor, } } -static gpointer -get_default_local_directory_monitor (gpointer data) -{ - GLocalDirectoryMonitorClass *chosen_class; - GLocalDirectoryMonitorClass **ret = data; - GIOExtensionPoint *ep; - GList *extensions, *l; - - _g_io_modules_ensure_loaded (); - - ep = g_io_extension_point_lookup (G_LOCAL_DIRECTORY_MONITOR_EXTENSION_POINT_NAME); - - extensions = g_io_extension_point_get_extensions (ep); - - chosen_class = NULL; - for (l = extensions; l != NULL; l = l->next) - { - GIOExtension *extension = l->data; - GLocalDirectoryMonitorClass *klass; - - klass = G_LOCAL_DIRECTORY_MONITOR_CLASS (g_io_extension_ref_class (extension)); - - if (klass->is_supported ()) - { - chosen_class = klass; - break; - } - else - g_type_class_unref (klass); - } - - if (chosen_class) - { - *ret = chosen_class; - return (gpointer)G_TYPE_FROM_CLASS (chosen_class); - } - else - return (gpointer)G_TYPE_INVALID; -} - GFileMonitor* _g_local_directory_monitor_new (const char *dirname, GFileMonitorFlags flags, GError **error) { - static GOnce once_init = G_ONCE_INIT; - GTypeClass *type_class; - GFileMonitor *monitor; + GFileMonitor *monitor = NULL; GType type; - type_class = NULL; - g_once (&once_init, get_default_local_directory_monitor, &type_class); - type = (GType)once_init.retval; + type = _g_io_module_get_default_type (G_LOCAL_DIRECTORY_MONITOR_EXTENSION_POINT_NAME, + "GIO_USE_FILE_MONITOR", + G_STRUCT_OFFSET (GLocalDirectoryMonitorClass, is_supported)); - monitor = NULL; if (type != G_TYPE_INVALID) monitor = G_FILE_MONITOR (g_object_new (type, "dirname", dirname, "flags", flags, NULL)); else g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED, _("Unable to find default local directory monitor type")); - /* This is non-null on first pass here. Unref the class now. - * This is to avoid unloading the module and then loading it - * again which would happen if we unrefed the class - * before creating the monitor. - */ - - if (type_class) - g_type_class_unref (type_class); - return monitor; } diff --git a/gio/glocalfilemonitor.c b/gio/glocalfilemonitor.c index 91d524f5e..a8925c04f 100644 --- a/gio/glocalfilemonitor.c +++ b/gio/glocalfilemonitor.c @@ -150,75 +150,23 @@ static void g_local_file_monitor_class_init (GLocalFileMonitorClass *klass) G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB)); } -static gpointer -get_default_local_file_monitor (gpointer data) -{ - GLocalFileMonitorClass *chosen_class; - GLocalFileMonitorClass **ret = data; - GIOExtensionPoint *ep; - GList *extensions, *l; - - _g_io_modules_ensure_loaded (); - - ep = g_io_extension_point_lookup (G_LOCAL_FILE_MONITOR_EXTENSION_POINT_NAME); - - extensions = g_io_extension_point_get_extensions (ep); - - chosen_class = NULL; - for (l = extensions; l != NULL; l = l->next) - { - GIOExtension *extension = l->data; - GLocalFileMonitorClass *klass; - - klass = G_LOCAL_FILE_MONITOR_CLASS (g_io_extension_ref_class (extension)); - - if (klass->is_supported ()) - { - chosen_class = klass; - break; - } - else - g_type_class_unref (klass); - } - - if (chosen_class) - { - *ret = chosen_class; - return (gpointer)G_TYPE_FROM_CLASS (chosen_class); - } - else - return (gpointer)G_TYPE_INVALID; -} - GFileMonitor* _g_local_file_monitor_new (const char *pathname, GFileMonitorFlags flags, GError **error) { - static GOnce once_init = G_ONCE_INIT; - GTypeClass *type_class; - GFileMonitor *monitor; + GFileMonitor *monitor = NULL; GType type; - type_class = NULL; - g_once (&once_init, get_default_local_file_monitor, &type_class); - type = (GType)once_init.retval; + type = _g_io_module_get_default_type (G_LOCAL_FILE_MONITOR_EXTENSION_POINT_NAME, + "GIO_USE_FILE_MONITOR", + G_STRUCT_OFFSET (GLocalFileMonitorClass, is_supported)); - monitor = NULL; if (type != G_TYPE_INVALID) monitor = G_FILE_MONITOR (g_object_new (type, "filename", pathname, "flags", flags, NULL)); else g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED, _("Unable to find default local file monitor type")); - /* This is non-null on first pass here. Unref the class now. - * This is to avoid unloading the module and then loading it - * again which would happen if we unrefed the class - * before creating the monitor. - */ - - if (type_class) - g_type_class_unref (type_class); - return monitor; } |