/src/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 | | * 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. |
10 | | * |
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. |
15 | | * |
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/>. |
18 | | * |
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> |
23 | | */ |
24 | | |
25 | | #include "config.h" |
26 | | |
27 | | #include "ginotifyfilemonitor.h" |
28 | | #include <gio/giomodule.h> |
29 | | |
30 | | #define USE_INOTIFY 1 |
31 | | #include "inotify-helper.h" |
32 | | |
33 | | struct _GInotifyFileMonitor |
34 | | { |
35 | | GLocalFileMonitor parent_instance; |
36 | | |
37 | | inotify_sub *sub; |
38 | | }; |
39 | | |
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)) |
43 | | |
44 | | static gboolean |
45 | | g_inotify_file_monitor_is_supported (void) |
46 | 0 | { |
47 | 0 | return _ih_startup (); |
48 | 0 | } |
49 | | |
50 | | static void |
51 | | g_inotify_file_monitor_start (GLocalFileMonitor *local_monitor, |
52 | | const gchar *dirname, |
53 | | const gchar *basename, |
54 | | const gchar *filename, |
55 | | GFileMonitorSource *source) |
56 | 0 | { |
57 | 0 | GInotifyFileMonitor *inotify_monitor = G_INOTIFY_FILE_MONITOR (local_monitor); |
58 | 0 | gboolean success G_GNUC_UNUSED /* when compiling with G_DISABLE_ASSERT */; |
59 | | |
60 | | /* should already have been called, from is_supported() */ |
61 | 0 | success = _ih_startup (); |
62 | 0 | g_assert (success); |
63 | | |
64 | 0 | inotify_monitor->sub = _ih_sub_new (dirname, basename, filename, source); |
65 | 0 | _ih_sub_add (inotify_monitor->sub); |
66 | 0 | } |
67 | | |
68 | | static gboolean |
69 | | g_inotify_file_monitor_cancel (GFileMonitor *monitor) |
70 | 0 | { |
71 | 0 | GInotifyFileMonitor *inotify_monitor = G_INOTIFY_FILE_MONITOR (monitor); |
72 | |
|
73 | 0 | if (inotify_monitor->sub) |
74 | 0 | { |
75 | 0 | _ih_sub_cancel (inotify_monitor->sub); |
76 | 0 | _ih_sub_free (inotify_monitor->sub); |
77 | 0 | inotify_monitor->sub = NULL; |
78 | 0 | } |
79 | |
|
80 | 0 | return TRUE; |
81 | 0 | } |
82 | | |
83 | | static void |
84 | | g_inotify_file_monitor_finalize (GObject *object) |
85 | 0 | { |
86 | 0 | #ifndef G_DISABLE_ASSERT |
87 | 0 | GInotifyFileMonitor *inotify_monitor = G_INOTIFY_FILE_MONITOR (object); |
88 | 0 | #endif |
89 | | |
90 | | /* must surely have been cancelled already */ |
91 | 0 | g_assert (!inotify_monitor->sub); |
92 | | |
93 | 0 | G_OBJECT_CLASS (g_inotify_file_monitor_parent_class)->finalize (object); |
94 | 0 | } |
95 | | |
96 | | static void |
97 | | g_inotify_file_monitor_init (GInotifyFileMonitor* monitor) |
98 | 0 | { |
99 | 0 | } |
100 | | |
101 | | static void |
102 | | g_inotify_file_monitor_class_init (GInotifyFileMonitorClass* klass) |
103 | 0 | { |
104 | 0 | GObjectClass* gobject_class = G_OBJECT_CLASS (klass); |
105 | 0 | GFileMonitorClass *file_monitor_class = G_FILE_MONITOR_CLASS (klass); |
106 | 0 | GLocalFileMonitorClass *local_file_monitor_class = G_LOCAL_FILE_MONITOR_CLASS (klass); |
107 | |
|
108 | 0 | local_file_monitor_class->is_supported = g_inotify_file_monitor_is_supported; |
109 | 0 | local_file_monitor_class->start = g_inotify_file_monitor_start; |
110 | 0 | local_file_monitor_class->mount_notify = TRUE; |
111 | 0 | file_monitor_class->cancel = g_inotify_file_monitor_cancel; |
112 | |
|
113 | 0 | gobject_class->finalize = g_inotify_file_monitor_finalize; |
114 | 0 | } |