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 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>
26 #include "gfamdirectorymonitor.h"
27 #include <gio/giomodule.h>
29 #include "fam-helper.h"
31 struct _GFamDirectoryMonitor
33 GLocalDirectoryMonitor parent_instance;
37 static gboolean g_fam_directory_monitor_cancel (GFileMonitor* monitor);
39 G_DEFINE_DYNAMIC_TYPE (GFamDirectoryMonitor, g_fam_directory_monitor, G_TYPE_LOCAL_DIRECTORY_MONITOR)
42 g_fam_directory_monitor_finalize (GObject *object)
44 GFamDirectoryMonitor *fam_monitor = G_FAM_DIRECTORY_MONITOR (object);
45 fam_sub *sub = fam_monitor->sub;
48 if (!_fam_sub_cancel (sub))
49 g_warning ("Unexpected error cancelling fam monitor");
51 fam_monitor->sub = NULL;
54 if (G_OBJECT_CLASS (g_fam_directory_monitor_parent_class)->finalize)
55 (*G_OBJECT_CLASS (g_fam_directory_monitor_parent_class)->finalize) (object);
59 g_fam_directory_monitor_constructor (GType type,
60 guint n_construct_properties,
61 GObjectConstructParam *construct_properties)
64 GFamDirectoryMonitorClass *klass;
65 GObjectClass *parent_class;
66 GFamDirectoryMonitor *fam_monitor;
67 const gchar *dirname = NULL;
70 klass = G_FAM_DIRECTORY_MONITOR_CLASS (g_type_class_peek (G_TYPE_FAM_DIRECTORY_MONITOR));
71 parent_class = G_OBJECT_CLASS (g_type_class_peek_parent (klass));
72 obj = parent_class->constructor (type,
73 n_construct_properties,
74 construct_properties);
76 fam_monitor = G_FAM_DIRECTORY_MONITOR (obj);
78 dirname = G_LOCAL_DIRECTORY_MONITOR (obj)->dirname;
79 g_assert (dirname != NULL);
81 sub = _fam_sub_add (dirname, TRUE, fam_monitor);
82 /* FIXME: what to do about errors here? we can't return NULL or another
83 * kind of error and an assertion is probably too hard */
84 g_assert (sub != NULL);
86 fam_monitor->sub = sub;
92 g_fam_directory_monitor_class_finalize (GFamDirectoryMonitorClass *klass)
97 g_fam_directory_monitor_is_supported (void)
99 return _fam_sub_startup ();
103 g_fam_directory_monitor_class_init (GFamDirectoryMonitorClass* klass)
105 GObjectClass* gobject_class = G_OBJECT_CLASS (klass);
106 GFileMonitorClass *file_monitor_class = G_FILE_MONITOR_CLASS (klass);
107 GLocalDirectoryMonitorClass *local_directory_monitor_class = G_LOCAL_DIRECTORY_MONITOR_CLASS (klass);
109 gobject_class->finalize = g_fam_directory_monitor_finalize;
110 gobject_class->constructor = g_fam_directory_monitor_constructor;
111 file_monitor_class->cancel = g_fam_directory_monitor_cancel;
113 local_directory_monitor_class->mount_notify = FALSE;
114 local_directory_monitor_class->is_supported = g_fam_directory_monitor_is_supported;
118 g_fam_directory_monitor_init (GFamDirectoryMonitor* monitor)
124 g_fam_directory_monitor_cancel (GFileMonitor* monitor)
126 GFamDirectoryMonitor *fam_monitor = G_FAM_DIRECTORY_MONITOR (monitor);
127 fam_sub *sub = fam_monitor->sub;
130 if (!_fam_sub_cancel (sub))
131 g_warning ("Unexpected error cancelling fam monitor");
133 fam_monitor->sub = NULL;
136 if (G_FILE_MONITOR_CLASS (g_fam_directory_monitor_parent_class)->cancel)
137 (*G_FILE_MONITOR_CLASS (g_fam_directory_monitor_parent_class)->cancel) (monitor);
143 g_fam_directory_monitor_register (GIOModule *module)
145 g_fam_directory_monitor_register_type (G_TYPE_MODULE (module));
146 g_io_extension_point_implement (G_LOCAL_DIRECTORY_MONITOR_EXTENSION_POINT_NAME,
147 G_TYPE_FAM_DIRECTORY_MONITOR,
150 g_io_extension_point_implement (G_NFS_DIRECTORY_MONITOR_EXTENSION_POINT_NAME,
151 G_TYPE_FAM_DIRECTORY_MONITOR,