Blame gio/inotify/ginotifyfilemonitor.c

Packit ae235b
/* GIO - GLib Input, Output and Streaming Library
Packit ae235b
 * 
Packit ae235b
 * Copyright (C) 2006-2007 Red Hat, Inc.
Packit ae235b
 * Copyright (C) 2007 Sebastian Dröge.
Packit ae235b
 *
Packit ae235b
 * This library is free software; you can redistribute it and/or
Packit ae235b
 * modify it under the terms of the GNU Lesser General Public
Packit ae235b
 * License as published by the Free Software Foundation; either
Packit ae235b
 * version 2.1 of the License, or (at your option) any later version.
Packit ae235b
 *
Packit ae235b
 * This library is distributed in the hope that it will be useful,
Packit ae235b
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit ae235b
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit ae235b
 * Lesser General Public License for more details.
Packit ae235b
 *
Packit ae235b
 * You should have received a copy of the GNU Lesser General
Packit ae235b
 * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
Packit ae235b
 *
Packit ae235b
 * Authors: Alexander Larsson <alexl@redhat.com>
Packit ae235b
 *          John McCutchan <john@johnmccutchan.com> 
Packit ae235b
 *          Sebastian Dröge <slomo@circular-chaos.org>
Packit ae235b
 *          Ryan Lortie <desrt@desrt.ca>
Packit ae235b
 */
Packit ae235b
Packit ae235b
#include "config.h"
Packit ae235b
Packit ae235b
#include "ginotifyfilemonitor.h"
Packit ae235b
#include <gio/giomodule.h>
Packit ae235b
Packit ae235b
#define USE_INOTIFY 1
Packit ae235b
#include "inotify-helper.h"
Packit ae235b
Packit ae235b
struct _GInotifyFileMonitor
Packit ae235b
{
Packit ae235b
  GLocalFileMonitor parent_instance;
Packit ae235b
Packit ae235b
  inotify_sub *sub;
Packit ae235b
};
Packit ae235b
Packit ae235b
G_DEFINE_TYPE_WITH_CODE (GInotifyFileMonitor, g_inotify_file_monitor, G_TYPE_LOCAL_FILE_MONITOR,
Packit ae235b
                         g_io_extension_point_implement (G_LOCAL_FILE_MONITOR_EXTENSION_POINT_NAME,
Packit ae235b
                                                         g_define_type_id, "inotify", 20))
Packit ae235b
Packit ae235b
static gboolean
Packit ae235b
g_inotify_file_monitor_is_supported (void)
Packit ae235b
{
Packit ae235b
  return _ih_startup ();
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
g_inotify_file_monitor_start (GLocalFileMonitor  *local_monitor,
Packit ae235b
                              const gchar        *dirname,
Packit ae235b
                              const gchar        *basename,
Packit ae235b
                              const gchar        *filename,
Packit ae235b
                              GFileMonitorSource *source)
Packit ae235b
{
Packit ae235b
  GInotifyFileMonitor *inotify_monitor = G_INOTIFY_FILE_MONITOR (local_monitor);
Packit ae235b
  gboolean success;
Packit ae235b
Packit ae235b
  /* should already have been called, from is_supported() */
Packit ae235b
  success = _ih_startup ();
Packit ae235b
  g_assert (success);
Packit ae235b
Packit ae235b
  inotify_monitor->sub = _ih_sub_new (dirname, basename, filename != NULL, source);
Packit ae235b
  _ih_sub_add (inotify_monitor->sub);
Packit ae235b
}
Packit ae235b
Packit ae235b
static gboolean
Packit ae235b
g_inotify_file_monitor_cancel (GFileMonitor *monitor)
Packit ae235b
{
Packit ae235b
  GInotifyFileMonitor *inotify_monitor = G_INOTIFY_FILE_MONITOR (monitor);
Packit ae235b
Packit ae235b
  if (inotify_monitor->sub)
Packit ae235b
    {
Packit ae235b
      _ih_sub_cancel (inotify_monitor->sub);
Packit ae235b
      _ih_sub_free (inotify_monitor->sub);
Packit ae235b
      inotify_monitor->sub = NULL;
Packit ae235b
    }
Packit ae235b
Packit ae235b
  return TRUE;
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
g_inotify_file_monitor_finalize (GObject *object)
Packit ae235b
{
Packit ae235b
  GInotifyFileMonitor *inotify_monitor = G_INOTIFY_FILE_MONITOR (object);
Packit ae235b
Packit ae235b
  /* must surely have been cancelled already */
Packit ae235b
  g_assert (!inotify_monitor->sub);
Packit ae235b
Packit ae235b
  G_OBJECT_CLASS (g_inotify_file_monitor_parent_class)->finalize (object);
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
g_inotify_file_monitor_init (GInotifyFileMonitor* monitor)
Packit ae235b
{
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
g_inotify_file_monitor_class_init (GInotifyFileMonitorClass* klass)
Packit ae235b
{
Packit ae235b
  GObjectClass* gobject_class = G_OBJECT_CLASS (klass);
Packit ae235b
  GFileMonitorClass *file_monitor_class = G_FILE_MONITOR_CLASS (klass);
Packit ae235b
  GLocalFileMonitorClass *local_file_monitor_class = G_LOCAL_FILE_MONITOR_CLASS (klass);
Packit ae235b
Packit ae235b
  local_file_monitor_class->is_supported = g_inotify_file_monitor_is_supported;
Packit ae235b
  local_file_monitor_class->start = g_inotify_file_monitor_start;
Packit ae235b
  local_file_monitor_class->mount_notify = TRUE;
Packit ae235b
  file_monitor_class->cancel = g_inotify_file_monitor_cancel;
Packit ae235b
Packit ae235b
  gobject_class->finalize = g_inotify_file_monitor_finalize;
Packit ae235b
}