mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-25 23:16:14 +01:00
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
This commit is contained in:
parent
3a7b44c007
commit
c83600e8ae
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user