inotify: stop using constructor()

and start using the new start() vcall on the local monitor classes.

I only port inotify because I am uncomfortable making changes to the
other monitor backends without having a way of testing them.

https://bugzilla.gnome.org/show_bug.cgi?id=704887
This commit is contained in:
Ryan Lortie 2013-07-25 13:48:50 -04:00
parent b050dc3c0a
commit 700677de51
2 changed files with 28 additions and 70 deletions

View File

@ -59,42 +59,28 @@ g_inotify_directory_monitor_finalize (GObject *object)
inotify_monitor->sub = NULL; inotify_monitor->sub = NULL;
} }
if (G_OBJECT_CLASS (g_inotify_directory_monitor_parent_class)->finalize) G_OBJECT_CLASS (g_inotify_directory_monitor_parent_class)->finalize (object);
(*G_OBJECT_CLASS (g_inotify_directory_monitor_parent_class)->finalize) (object);
} }
static GObject * static void
g_inotify_directory_monitor_constructor (GType type, g_inotify_directory_monitor_start (GLocalDirectoryMonitor *local_monitor)
guint n_construct_properties,
GObjectConstructParam *construct_properties)
{ {
GObject *obj; GInotifyDirectoryMonitor *inotify_monitor = G_INOTIFY_DIRECTORY_MONITOR (local_monitor);
GInotifyDirectoryMonitorClass *klass;
GObjectClass *parent_class;
GInotifyDirectoryMonitor *inotify_monitor;
const gchar *dirname = NULL; const gchar *dirname = NULL;
inotify_sub *sub = NULL; inotify_sub *sub = NULL;
gboolean ret_ih_startup; /* return value of _ih_startup, for asserting */ gboolean ret_ih_startup; /* return value of _ih_startup, for asserting */
gboolean pair_moves; gboolean pair_moves;
klass = G_INOTIFY_DIRECTORY_MONITOR_CLASS (g_type_class_peek (G_TYPE_INOTIFY_DIRECTORY_MONITOR)); dirname = local_monitor->dirname;
parent_class = G_OBJECT_CLASS (g_type_class_peek_parent (klass));
obj = parent_class->constructor (type,
n_construct_properties,
construct_properties);
inotify_monitor = G_INOTIFY_DIRECTORY_MONITOR (obj);
dirname = G_LOCAL_DIRECTORY_MONITOR (obj)->dirname;
g_assert (dirname != NULL); g_assert (dirname != NULL);
/* Will never fail as is_supported() should be called before instanciating /* Will never fail as is_supported() should be called before instantiating
* anyway */ * anyway */
/* assert on return value */ /* assert on return value */
ret_ih_startup = _ih_startup(); ret_ih_startup = _ih_startup();
g_assert (ret_ih_startup); g_assert (ret_ih_startup);
pair_moves = G_LOCAL_DIRECTORY_MONITOR (obj)->flags & G_FILE_MONITOR_SEND_MOVED; pair_moves = local_monitor->flags & G_FILE_MONITOR_SEND_MOVED;
sub = _ih_sub_new (dirname, NULL, pair_moves, FALSE, inotify_monitor); sub = _ih_sub_new (dirname, NULL, pair_moves, FALSE, inotify_monitor);
/* FIXME: what to do about errors here? we can't return NULL or another /* FIXME: what to do about errors here? we can't return NULL or another
@ -106,8 +92,6 @@ g_inotify_directory_monitor_constructor (GType type,
_ih_sub_add(sub); _ih_sub_add(sub);
inotify_monitor->sub = sub; inotify_monitor->sub = sub;
return obj;
} }
static gboolean static gboolean
@ -124,11 +108,11 @@ g_inotify_directory_monitor_class_init (GInotifyDirectoryMonitorClass* klass)
GLocalDirectoryMonitorClass *local_directory_monitor_class = G_LOCAL_DIRECTORY_MONITOR_CLASS (klass); GLocalDirectoryMonitorClass *local_directory_monitor_class = G_LOCAL_DIRECTORY_MONITOR_CLASS (klass);
gobject_class->finalize = g_inotify_directory_monitor_finalize; gobject_class->finalize = g_inotify_directory_monitor_finalize;
gobject_class->constructor = g_inotify_directory_monitor_constructor;
directory_monitor_class->cancel = g_inotify_directory_monitor_cancel; directory_monitor_class->cancel = g_inotify_directory_monitor_cancel;
local_directory_monitor_class->mount_notify = TRUE; local_directory_monitor_class->mount_notify = TRUE;
local_directory_monitor_class->is_supported = g_inotify_directory_monitor_is_supported; local_directory_monitor_class->is_supported = g_inotify_directory_monitor_is_supported;
local_directory_monitor_class->start = g_inotify_directory_monitor_start;
} }
static void static void

View File

@ -62,60 +62,36 @@ g_inotify_file_monitor_finalize (GObject *object)
inotify_monitor->sub = NULL; inotify_monitor->sub = NULL;
} }
if (inotify_monitor->filename)
{
g_free (inotify_monitor->filename); g_free (inotify_monitor->filename);
inotify_monitor->filename = NULL;
}
if (inotify_monitor->dirname)
{
g_free (inotify_monitor->dirname); g_free (inotify_monitor->dirname);
inotify_monitor->dirname = NULL;
G_OBJECT_CLASS (g_inotify_file_monitor_parent_class)->finalize (object);
} }
if (G_OBJECT_CLASS (g_inotify_file_monitor_parent_class)->finalize) static void
(*G_OBJECT_CLASS (g_inotify_file_monitor_parent_class)->finalize) (object); g_inotify_file_monitor_start (GLocalFileMonitor *local_monitor)
}
static GObject *
g_inotify_file_monitor_constructor (GType type,
guint n_construct_properties,
GObjectConstructParam *construct_properties)
{ {
GObject *obj; GInotifyFileMonitor *inotify_monitor = G_INOTIFY_FILE_MONITOR (local_monitor);
GInotifyFileMonitorClass *klass;
GObjectClass *parent_class;
GInotifyFileMonitor *inotify_monitor;
const gchar *filename = NULL; const gchar *filename = NULL;
gboolean watch_hardlinks; gboolean watch_hardlinks;
inotify_sub *sub = NULL; inotify_sub *sub = NULL;
gboolean pair_moves; gboolean pair_moves;
gboolean ret_ih_startup; /* return value of _ih_startup, for asserting */ gboolean ret_ih_startup; /* return value of _ih_startup, for asserting */
klass = G_INOTIFY_FILE_MONITOR_CLASS (g_type_class_peek (G_TYPE_INOTIFY_FILE_MONITOR)); filename = local_monitor->filename;
parent_class = G_OBJECT_CLASS (g_type_class_peek_parent (klass));
obj = parent_class->constructor (type,
n_construct_properties,
construct_properties);
inotify_monitor = G_INOTIFY_FILE_MONITOR (obj);
filename = G_LOCAL_FILE_MONITOR (obj)->filename;
g_assert (filename != NULL); g_assert (filename != NULL);
inotify_monitor->filename = g_path_get_basename (filename); inotify_monitor->filename = g_path_get_basename (filename);
inotify_monitor->dirname = g_path_get_dirname (filename); inotify_monitor->dirname = g_path_get_dirname (filename);
/* Will never fail as is_supported() should be called before instanciating /* Will never fail as is_supported() should be called before instantiating
* anyway */ * anyway */
/* assert on return value */ /* assert on return value */
ret_ih_startup = _ih_startup(); ret_ih_startup = _ih_startup();
g_assert (ret_ih_startup); g_assert (ret_ih_startup);
pair_moves = G_LOCAL_FILE_MONITOR (obj)->flags & G_FILE_MONITOR_SEND_MOVED; pair_moves = local_monitor->flags & G_FILE_MONITOR_SEND_MOVED;
watch_hardlinks = G_LOCAL_FILE_MONITOR (obj)->flags & G_FILE_MONITOR_WATCH_HARD_LINKS; watch_hardlinks = local_monitor->flags & G_FILE_MONITOR_WATCH_HARD_LINKS;
sub = _ih_sub_new (inotify_monitor->dirname, sub = _ih_sub_new (inotify_monitor->dirname,
inotify_monitor->filename, inotify_monitor->filename,
@ -132,8 +108,6 @@ g_inotify_file_monitor_constructor (GType type,
_ih_sub_add (sub); _ih_sub_add (sub);
inotify_monitor->sub = sub; inotify_monitor->sub = sub;
return obj;
} }
static gboolean static gboolean
@ -150,10 +124,10 @@ g_inotify_file_monitor_class_init (GInotifyFileMonitorClass* klass)
GLocalFileMonitorClass *local_file_monitor_class = G_LOCAL_FILE_MONITOR_CLASS (klass); GLocalFileMonitorClass *local_file_monitor_class = G_LOCAL_FILE_MONITOR_CLASS (klass);
gobject_class->finalize = g_inotify_file_monitor_finalize; gobject_class->finalize = g_inotify_file_monitor_finalize;
gobject_class->constructor = g_inotify_file_monitor_constructor;
file_monitor_class->cancel = g_inotify_file_monitor_cancel; file_monitor_class->cancel = g_inotify_file_monitor_cancel;
local_file_monitor_class->is_supported = g_inotify_file_monitor_is_supported; local_file_monitor_class->is_supported = g_inotify_file_monitor_is_supported;
local_file_monitor_class->start = g_inotify_file_monitor_start;
} }
static void static void