Branch data Line data Source code
1 : : /* GIO - GLib Input, Output and Streaming Library 2 : : * 3 : : * Copyright (C) 2006-2007 Red Hat, Inc. 4 : : * Copyright (C) 2007 Sebastian Dröge. 5 : : * 6 : : * SPDX-License-Identifier: LGPL-2.1-or-later 7 : : * 8 : : * This library is free software; you can redistribute it and/or 9 : : * modify it under the terms of the GNU Lesser General Public 10 : : * License as published by the Free Software Foundation; either 11 : : * version 2.1 of the License, or (at your option) any later version. 12 : : * 13 : : * This library is distributed in the hope that it will be useful, 14 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 : : * Lesser General Public License for more details. 17 : : * 18 : : * You should have received a copy of the GNU Lesser General 19 : : * Public License along with this library; if not, see <http://www.gnu.org/licenses/>. 20 : : * 21 : : * Authors: Alexander Larsson <alexl@redhat.com> 22 : : * John McCutchan <john@johnmccutchan.com> 23 : : * Sebastian Dröge <slomo@circular-chaos.org> 24 : : * Ryan Lortie <desrt@desrt.ca> 25 : : */ 26 : : 27 : : #include "config.h" 28 : : 29 : : #include "ginotifyfilemonitor.h" 30 : : #include <gio/giomodule.h> 31 : : 32 : : #define USE_INOTIFY 1 33 : : #include "inotify-helper.h" 34 : : 35 : : struct _GInotifyFileMonitor 36 : : { 37 : : GLocalFileMonitor parent_instance; 38 : : 39 : : inotify_sub *sub; 40 : : }; 41 : : 42 [ + + + - : 1789 : G_DEFINE_TYPE_WITH_CODE (GInotifyFileMonitor, g_inotify_file_monitor, G_TYPE_LOCAL_FILE_MONITOR, + + ] 43 : : g_io_extension_point_implement (G_LOCAL_FILE_MONITOR_EXTENSION_POINT_NAME, 44 : : g_define_type_id, "inotify", 20)) 45 : : 46 : : static gboolean 47 : 57 : g_inotify_file_monitor_is_supported (void) 48 : : { 49 : 57 : return _ih_startup (); 50 : : } 51 : : 52 : : static void 53 : 636 : g_inotify_file_monitor_start (GLocalFileMonitor *local_monitor, 54 : : const gchar *dirname, 55 : : const gchar *basename, 56 : : const gchar *filename, 57 : : GFileMonitorSource *source) 58 : : { 59 : 636 : GInotifyFileMonitor *inotify_monitor = G_INOTIFY_FILE_MONITOR (local_monitor); 60 : : gboolean success G_GNUC_UNUSED /* when compiling with G_DISABLE_ASSERT */; 61 : : 62 : : /* should already have been called, from is_supported() */ 63 : 636 : success = _ih_startup (); 64 : 636 : g_assert (success); 65 : : 66 : 636 : inotify_monitor->sub = _ih_sub_new (dirname, basename, filename, source); 67 : 636 : _ih_sub_add (inotify_monitor->sub); 68 : 636 : } 69 : : 70 : : static gboolean 71 : 434 : g_inotify_file_monitor_cancel (GFileMonitor *monitor) 72 : : { 73 : 434 : GInotifyFileMonitor *inotify_monitor = G_INOTIFY_FILE_MONITOR (monitor); 74 : : 75 [ + - ]: 434 : if (inotify_monitor->sub) 76 : : { 77 : 434 : _ih_sub_cancel (inotify_monitor->sub); 78 : 434 : _ih_sub_free (inotify_monitor->sub); 79 : 434 : inotify_monitor->sub = NULL; 80 : : } 81 : : 82 : 434 : return TRUE; 83 : : } 84 : : 85 : : static void 86 : 434 : g_inotify_file_monitor_finalize (GObject *object) 87 : : { 88 : : #ifndef G_DISABLE_ASSERT 89 : 434 : GInotifyFileMonitor *inotify_monitor = G_INOTIFY_FILE_MONITOR (object); 90 : : #endif 91 : : 92 : : /* must surely have been cancelled already */ 93 : 434 : g_assert (!inotify_monitor->sub); 94 : : 95 : 434 : G_OBJECT_CLASS (g_inotify_file_monitor_parent_class)->finalize (object); 96 : 434 : } 97 : : 98 : : static void 99 : 636 : g_inotify_file_monitor_init (GInotifyFileMonitor* monitor) 100 : : { 101 : 636 : } 102 : : 103 : : static void 104 : 57 : g_inotify_file_monitor_class_init (GInotifyFileMonitorClass* klass) 105 : : { 106 : 57 : GObjectClass* gobject_class = G_OBJECT_CLASS (klass); 107 : 57 : GFileMonitorClass *file_monitor_class = G_FILE_MONITOR_CLASS (klass); 108 : 57 : GLocalFileMonitorClass *local_file_monitor_class = G_LOCAL_FILE_MONITOR_CLASS (klass); 109 : : 110 : 57 : local_file_monitor_class->is_supported = g_inotify_file_monitor_is_supported; 111 : 57 : local_file_monitor_class->start = g_inotify_file_monitor_start; 112 : 57 : local_file_monitor_class->mount_notify = TRUE; 113 : 57 : file_monitor_class->cancel = g_inotify_file_monitor_cancel; 114 : : 115 : 57 : gobject_class->finalize = g_inotify_file_monitor_finalize; 116 : 57 : }