glib/gio/inotify/inotify-sub.c
Ryan Lortie 2737ab3201 substantially rework file monitors
Remove all event merging and dispatch logic from GFileMonitor.  The only
implementation of GFileMonitor outside of glib is in gvfs and it already
does these things properly.

Get rid of GLocalDirectoryMonitor.  We will use a single class,
GLocalFileMonitor, for both directory and file monitoring.  This will
prevent every single backend from having to create two objects
separately (eg: ginotifydirectorymonitor.c and ginotifyfilemonitor.c).

Introduce GFileMonitorSource as a thread-safe cross-context dispatch
mechanism.  Put it in GLocalFileMonitor.  All backends will be expected
to dispatch via the source and not touch the GFileMonitor object at all
from the worker thread.

Remove all construct properties from GLocalFileMonitor and remove the
"context" construct property from GFileMonitor.  All backends must now
get the information about what file to monitor from the ->start() call
which is mandatory to implement.

Remove the implementation of rate limiting in GFileMonitor and add an
implementation in GLocalFileMonitor.  gvfs never did anything with this
anyway, but if it wanted to, it would have to implement it for itself.
This was done in order to get the rate_limit field into the
GFileMonitorSource so that it could be safely accessed from the worker
thread.

Expose g_local_file_is_remote() internally for NFS detection.

With the "is_remote" functionality exposed, we can now move all
functions for creating local file monitors to a proper location in
glocalfilemonitor.c

Port the inotify backend to adjust to the changes above.  None of the
other backends are ported yet.  Those will come in future commits.
2015-03-20 11:59:47 -04:00

72 lines
1.8 KiB
C

/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 2; tab-width: 8 -*- */
/* inotify-sub.c - GMonitor based on inotify.
Copyright (C) 2006 John McCutchan
The Gnome Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The Gnome Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the Gnome Library; see the file COPYING.LIB. If not,
see <http://www.gnu.org/licenses/>.
Authors:
John McCutchan <john@johnmccutchan.com>
*/
#include "config.h"
#include <string.h>
#include <glib.h>
#include "inotify-sub.h"
static gboolean is_debug_enabled = FALSE;
#define IS_W if (is_debug_enabled) g_warning
static gchar*
dup_dirname (const gchar *dirname)
{
gchar *d_dirname = g_strdup (dirname);
size_t len = strlen (d_dirname);
if (d_dirname[len - 1] == '/')
d_dirname[len - 1] = '\0';
return d_dirname;
}
inotify_sub*
_ih_sub_new (const gchar *dirname,
const gchar *filename,
gboolean watch_hardlinks,
gpointer user_data)
{
inotify_sub *sub = NULL;
sub = g_new0 (inotify_sub, 1);
sub->dirname = dup_dirname (dirname);
sub->filename = g_strdup (filename);
sub->hardlinks = watch_hardlinks;
sub->user_data = user_data;
IS_W ("new subscription for %s being setup\n", sub->dirname);
return sub;
}
void
_ih_sub_free (inotify_sub *sub)
{
g_free (sub->dirname);
g_free (sub->filename);
g_free (sub);
}