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, write to the
18 * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
19 * Boston, MA 02111-1307, USA.
21 * Authors: Alexander Larsson <alexl@redhat.com>
22 * John McCutchan <john@johnmccutchan.com>
23 * Sebastian Dröge <slomo@circular-chaos.org>
28 #include "gfamdirectorymonitor.h"
29 #include "giomodule.h"
31 #include "fam-helper.h"
33 struct _GFamDirectoryMonitor
35 GLocalDirectoryMonitor parent_instance;
39 static gboolean g_fam_directory_monitor_cancel (GFileMonitor* monitor);
41 G_DEFINE_DYNAMIC_TYPE (GFamDirectoryMonitor, g_fam_directory_monitor, G_TYPE_LOCAL_DIRECTORY_MONITOR)
44 g_fam_directory_monitor_finalize (GObject *object)
46 GFamDirectoryMonitor *fam_monitor = G_FAM_DIRECTORY_MONITOR (object);
47 fam_sub *sub = fam_monitor->sub;
50 if (!_fam_sub_cancel (sub))
51 g_warning ("Unexpected error cancelling fam monitor");
53 fam_monitor->sub = NULL;
56 if (G_OBJECT_CLASS (g_fam_directory_monitor_parent_class)->finalize)
57 (*G_OBJECT_CLASS (g_fam_directory_monitor_parent_class)->finalize) (object);
61 g_fam_directory_monitor_constructor (GType type,
62 guint n_construct_properties,
63 GObjectConstructParam *construct_properties)
66 GFamDirectoryMonitorClass *klass;
67 GObjectClass *parent_class;
68 GFamDirectoryMonitor *fam_monitor;
69 const gchar *dirname = NULL;
72 klass = G_FAM_DIRECTORY_MONITOR_CLASS (g_type_class_peek (G_TYPE_FAM_DIRECTORY_MONITOR));
73 parent_class = G_OBJECT_CLASS (g_type_class_peek_parent (klass));
74 obj = parent_class->constructor (type,
75 n_construct_properties,
76 construct_properties);
78 fam_monitor = G_FAM_DIRECTORY_MONITOR (obj);
80 dirname = G_LOCAL_DIRECTORY_MONITOR (obj)->dirname;
81 g_assert (dirname != NULL);
83 sub = _fam_sub_add (dirname, TRUE, fam_monitor);
84 /* FIXME: what to do about errors here? we can't return NULL or another
85 * kind of error and an assertion is probably too hard */
86 g_assert (sub != NULL);
88 fam_monitor->sub = sub;
94 g_fam_directory_monitor_class_finalize (GFamDirectoryMonitorClass *klass)
99 g_fam_directory_monitor_is_supported (void)
101 return _fam_sub_startup ();
105 g_fam_directory_monitor_class_init (GFamDirectoryMonitorClass* klass)
107 GObjectClass* gobject_class = G_OBJECT_CLASS (klass);
108 GFileMonitorClass *file_monitor_class = G_FILE_MONITOR_CLASS (klass);
109 GLocalDirectoryMonitorClass *local_directory_monitor_class = G_LOCAL_DIRECTORY_MONITOR_CLASS (klass);
111 gobject_class->finalize = g_fam_directory_monitor_finalize;
112 gobject_class->constructor = g_fam_directory_monitor_constructor;
113 file_monitor_class->cancel = g_fam_directory_monitor_cancel;
115 local_directory_monitor_class->mount_notify = FALSE;
116 local_directory_monitor_class->is_supported = g_fam_directory_monitor_is_supported;
120 g_fam_directory_monitor_init (GFamDirectoryMonitor* monitor)
126 g_fam_directory_monitor_cancel (GFileMonitor* monitor)
128 GFamDirectoryMonitor *fam_monitor = G_FAM_DIRECTORY_MONITOR (monitor);
129 fam_sub *sub = fam_monitor->sub;
132 if (!_fam_sub_cancel (sub))
133 g_warning ("Unexpected error cancelling fam monitor");
135 fam_monitor->sub = NULL;
138 if (G_FILE_MONITOR_CLASS (g_fam_directory_monitor_parent_class)->cancel)
139 (*G_FILE_MONITOR_CLASS (g_fam_directory_monitor_parent_class)->cancel) (monitor);
145 g_fam_directory_monitor_register (GIOModule *module)
147 g_fam_directory_monitor_register_type (G_TYPE_MODULE (module));
148 g_io_extension_point_implement (G_LOCAL_DIRECTORY_MONITOR_EXTENSION_POINT_NAME,
149 G_TYPE_FAM_DIRECTORY_MONITOR,