/src/pango/subprojects/glib/gio/inotify/ginotifyfilemonitor.c
Line | Count | Source (jump to first uncovered line) |
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 | | 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 | | g_inotify_file_monitor_is_supported (void) |
48 | 0 | { |
49 | 0 | return _ih_startup (); |
50 | 0 | } |
51 | | |
52 | | static void |
53 | | g_inotify_file_monitor_start (GLocalFileMonitor *local_monitor, |
54 | | const gchar *dirname, |
55 | | const gchar *basename, |
56 | | const gchar *filename, |
57 | | GFileMonitorSource *source) |
58 | 0 | { |
59 | 0 | GInotifyFileMonitor *inotify_monitor = G_INOTIFY_FILE_MONITOR (local_monitor); |
60 | 0 | gboolean success G_GNUC_UNUSED /* when compiling with G_DISABLE_ASSERT */; |
61 | | |
62 | | /* should already have been called, from is_supported() */ |
63 | 0 | success = _ih_startup (); |
64 | 0 | g_assert (success); |
65 | | |
66 | 0 | inotify_monitor->sub = _ih_sub_new (dirname, basename, filename, source); |
67 | 0 | _ih_sub_add (inotify_monitor->sub); |
68 | 0 | } |
69 | | |
70 | | static gboolean |
71 | | g_inotify_file_monitor_cancel (GFileMonitor *monitor) |
72 | 0 | { |
73 | 0 | GInotifyFileMonitor *inotify_monitor = G_INOTIFY_FILE_MONITOR (monitor); |
74 | |
|
75 | 0 | if (inotify_monitor->sub) |
76 | 0 | { |
77 | 0 | _ih_sub_cancel (inotify_monitor->sub); |
78 | 0 | _ih_sub_free (inotify_monitor->sub); |
79 | 0 | inotify_monitor->sub = NULL; |
80 | 0 | } |
81 | |
|
82 | 0 | return TRUE; |
83 | 0 | } |
84 | | |
85 | | static void |
86 | | g_inotify_file_monitor_finalize (GObject *object) |
87 | 0 | { |
88 | 0 | #ifndef G_DISABLE_ASSERT |
89 | 0 | GInotifyFileMonitor *inotify_monitor = G_INOTIFY_FILE_MONITOR (object); |
90 | 0 | #endif |
91 | | |
92 | | /* must surely have been cancelled already */ |
93 | 0 | g_assert (!inotify_monitor->sub); |
94 | | |
95 | 0 | G_OBJECT_CLASS (g_inotify_file_monitor_parent_class)->finalize (object); |
96 | 0 | } |
97 | | |
98 | | static void |
99 | | g_inotify_file_monitor_init (GInotifyFileMonitor* monitor) |
100 | 0 | { |
101 | 0 | } |
102 | | |
103 | | static void |
104 | | g_inotify_file_monitor_class_init (GInotifyFileMonitorClass* klass) |
105 | 0 | { |
106 | 0 | GObjectClass* gobject_class = G_OBJECT_CLASS (klass); |
107 | 0 | GFileMonitorClass *file_monitor_class = G_FILE_MONITOR_CLASS (klass); |
108 | 0 | GLocalFileMonitorClass *local_file_monitor_class = G_LOCAL_FILE_MONITOR_CLASS (klass); |
109 | |
|
110 | 0 | local_file_monitor_class->is_supported = g_inotify_file_monitor_is_supported; |
111 | 0 | local_file_monitor_class->start = g_inotify_file_monitor_start; |
112 | 0 | local_file_monitor_class->mount_notify = TRUE; |
113 | 0 | file_monitor_class->cancel = g_inotify_file_monitor_cancel; |
114 | |
|
115 | 0 | gobject_class->finalize = g_inotify_file_monitor_finalize; |
116 | 0 | } |