1 /* GIO - GLib Input, Output and Streaming Library
3 * Copyright (C) 2006-2007 Red Hat, Inc.
4 * Copyright (C) 2007 Sebastian Dröge.
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General
17 * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
19 * Authors: Alexander Larsson <alexl@redhat.com>
20 * John McCutchan <john@johnmccutchan.com>
21 * Sebastian Dröge <slomo@circular-chaos.org>
22 * Ryan Lortie <desrt@desrt.ca>
27 #include "ginotifyfilemonitor.h"
28 #include <gio/giomodule.h>
31 #include "inotify-helper.h"
33 struct _GInotifyFileMonitor
35 GLocalFileMonitor parent_instance
;
40 G_DEFINE_TYPE_WITH_CODE (GInotifyFileMonitor
, g_inotify_file_monitor
, G_TYPE_LOCAL_FILE_MONITOR
,
41 g_io_extension_point_implement (G_LOCAL_FILE_MONITOR_EXTENSION_POINT_NAME
,
42 g_define_type_id
, "inotify", 20))
45 g_inotify_file_monitor_is_supported (void)
47 return _ih_startup ();
51 g_inotify_file_monitor_start (GLocalFileMonitor
*local_monitor
,
53 const gchar
*basename
,
54 const gchar
*filename
,
55 GFileMonitorSource
*source
)
57 GInotifyFileMonitor
*inotify_monitor
= G_INOTIFY_FILE_MONITOR (local_monitor
);
60 /* should already have been called, from is_supported() */
61 success
= _ih_startup ();
64 inotify_monitor
->sub
= _ih_sub_new (dirname
, basename
, filename
, source
);
65 _ih_sub_add (inotify_monitor
->sub
);
69 g_inotify_file_monitor_cancel (GFileMonitor
*monitor
)
71 GInotifyFileMonitor
*inotify_monitor
= G_INOTIFY_FILE_MONITOR (monitor
);
73 if (inotify_monitor
->sub
)
75 _ih_sub_cancel (inotify_monitor
->sub
);
76 _ih_sub_free (inotify_monitor
->sub
);
77 inotify_monitor
->sub
= NULL
;
84 g_inotify_file_monitor_finalize (GObject
*object
)
86 GInotifyFileMonitor
*inotify_monitor
= G_INOTIFY_FILE_MONITOR (object
);
88 /* must surely have been cancelled already */
89 g_assert (!inotify_monitor
->sub
);
91 G_OBJECT_CLASS (g_inotify_file_monitor_parent_class
)->finalize (object
);
95 g_inotify_file_monitor_init (GInotifyFileMonitor
* monitor
)
100 g_inotify_file_monitor_class_init (GInotifyFileMonitorClass
* klass
)
102 GObjectClass
* gobject_class
= G_OBJECT_CLASS (klass
);
103 GFileMonitorClass
*file_monitor_class
= G_FILE_MONITOR_CLASS (klass
);
104 GLocalFileMonitorClass
*local_file_monitor_class
= G_LOCAL_FILE_MONITOR_CLASS (klass
);
106 local_file_monitor_class
->is_supported
= g_inotify_file_monitor_is_supported
;
107 local_file_monitor_class
->start
= g_inotify_file_monitor_start
;
108 local_file_monitor_class
->mount_notify
= TRUE
;
109 file_monitor_class
->cancel
= g_inotify_file_monitor_cancel
;
111 gobject_class
->finalize
= g_inotify_file_monitor_finalize
;