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

@@ -62,67 +62,43 @@ g_inotify_file_monitor_finalize (GObject *object)
inotify_monitor->sub = NULL;
}
if (inotify_monitor->filename)
{
g_free (inotify_monitor->filename);
inotify_monitor->filename = NULL;
}
g_free (inotify_monitor->filename);
g_free (inotify_monitor->dirname);
if (inotify_monitor->dirname)
{
g_free (inotify_monitor->dirname);
inotify_monitor->dirname = NULL;
}
if (G_OBJECT_CLASS (g_inotify_file_monitor_parent_class)->finalize)
(*G_OBJECT_CLASS (g_inotify_file_monitor_parent_class)->finalize) (object);
G_OBJECT_CLASS (g_inotify_file_monitor_parent_class)->finalize (object);
}
static GObject *
g_inotify_file_monitor_constructor (GType type,
guint n_construct_properties,
GObjectConstructParam *construct_properties)
static void
g_inotify_file_monitor_start (GLocalFileMonitor *local_monitor)
{
GObject *obj;
GInotifyFileMonitorClass *klass;
GObjectClass *parent_class;
GInotifyFileMonitor *inotify_monitor;
GInotifyFileMonitor *inotify_monitor = G_INOTIFY_FILE_MONITOR (local_monitor);
const gchar *filename = NULL;
gboolean watch_hardlinks;
inotify_sub *sub = NULL;
gboolean pair_moves;
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));
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;
gboolean ret_ih_startup; /* return value of _ih_startup, for asserting */
filename = local_monitor->filename;
g_assert (filename != NULL);
inotify_monitor->filename = g_path_get_basename (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 */
/* assert on return value */
ret_ih_startup = _ih_startup();
g_assert (ret_ih_startup);
pair_moves = G_LOCAL_FILE_MONITOR (obj)->flags & G_FILE_MONITOR_SEND_MOVED;
watch_hardlinks = G_LOCAL_FILE_MONITOR (obj)->flags & G_FILE_MONITOR_WATCH_HARD_LINKS;
pair_moves = local_monitor->flags & G_FILE_MONITOR_SEND_MOVED;
watch_hardlinks = local_monitor->flags & G_FILE_MONITOR_WATCH_HARD_LINKS;
sub = _ih_sub_new (inotify_monitor->dirname,
inotify_monitor->filename,
pair_moves,
watch_hardlinks,
inotify_monitor);
inotify_monitor->filename,
pair_moves,
watch_hardlinks,
inotify_monitor);
/* FIXME: what to do about errors here? we can't return NULL or another
* kind of error and an assertion is probably too hard */
g_assert (sub != NULL);
@@ -132,8 +108,6 @@ g_inotify_file_monitor_constructor (GType type,
_ih_sub_add (sub);
inotify_monitor->sub = sub;
return obj;
}
static gboolean
@@ -148,12 +122,12 @@ g_inotify_file_monitor_class_init (GInotifyFileMonitorClass* klass)
GObjectClass* gobject_class = G_OBJECT_CLASS (klass);
GFileMonitorClass *file_monitor_class = G_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->constructor = g_inotify_file_monitor_constructor;
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->start = g_inotify_file_monitor_start;
}
static void