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 "gfamfilemonitor.h"
29 #include "giomodule.h"
31 #include "fam-helper.h"
33 struct _GFamFileMonitor
35 GLocalFileMonitor parent_instance;
39 static gboolean g_fam_file_monitor_cancel (GFileMonitor* monitor);
41 G_DEFINE_DYNAMIC_TYPE (GFamFileMonitor, g_fam_file_monitor, G_TYPE_LOCAL_FILE_MONITOR)
44 g_fam_file_monitor_finalize (GObject *object)
46 GFamFileMonitor *fam_monitor = G_FAM_FILE_MONITOR (object);
47 fam_sub *sub = fam_monitor->sub;
50 if (!_fam_sub_cancel (sub))
51 g_warning ("Unexpected error cancelling fam monitor");
52 fam_monitor->sub = NULL;
55 if (G_OBJECT_CLASS (g_fam_file_monitor_parent_class)->finalize)
56 (*G_OBJECT_CLASS (g_fam_file_monitor_parent_class)->finalize) (object);
60 g_fam_file_monitor_constructor (GType type,
61 guint n_construct_properties,
62 GObjectConstructParam *construct_properties)
65 GFamFileMonitorClass *klass;
66 GObjectClass *parent_class;
67 GFamFileMonitor *fam_monitor;
68 const gchar *filename = NULL;
71 klass = G_FAM_FILE_MONITOR_CLASS (g_type_class_peek (G_TYPE_FAM_FILE_MONITOR));
72 parent_class = G_OBJECT_CLASS (g_type_class_peek_parent (klass));
73 obj = parent_class->constructor (type,
74 n_construct_properties,
75 construct_properties);
77 fam_monitor = G_FAM_FILE_MONITOR (obj);
79 filename = G_LOCAL_FILE_MONITOR (obj)->filename;
81 g_assert (filename != NULL);
83 sub = _fam_sub_add (filename, FALSE, 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_file_monitor_class_finalize (GFamFileMonitorClass *klass)
99 g_fam_file_monitor_is_supported (void)
101 return _fam_sub_startup ();
105 g_fam_file_monitor_class_init (GFamFileMonitorClass* klass)
107 GObjectClass* gobject_class = G_OBJECT_CLASS (klass);
108 GFileMonitorClass *file_monitor_class = G_FILE_MONITOR_CLASS (klass);
109 GLocalFileMonitorClass *local_file_monitor_class = G_LOCAL_FILE_MONITOR_CLASS (klass);
111 gobject_class->finalize = g_fam_file_monitor_finalize;
112 gobject_class->constructor = g_fam_file_monitor_constructor;
113 file_monitor_class->cancel = g_fam_file_monitor_cancel;
115 local_file_monitor_class->is_supported = g_fam_file_monitor_is_supported;
119 g_fam_file_monitor_init (GFamFileMonitor* monitor)
125 g_fam_file_monitor_cancel (GFileMonitor* monitor)
127 GFamFileMonitor *fam_monitor = G_FAM_FILE_MONITOR (monitor);
128 fam_sub *sub = fam_monitor->sub;
131 if (!_fam_sub_cancel (sub))
132 g_warning ("Unexpected error cancelling fam monitor");
133 fam_monitor->sub = NULL;
136 if (G_FILE_MONITOR_CLASS (g_fam_file_monitor_parent_class)->cancel)
137 (*G_FILE_MONITOR_CLASS (g_fam_file_monitor_parent_class)->cancel) (monitor);
143 g_fam_file_monitor_register (GIOModule *module)
145 g_fam_file_monitor_register_type (G_TYPE_MODULE (module));
146 g_io_extension_point_implement (G_LOCAL_FILE_MONITOR_EXTENSION_POINT_NAME,
147 G_TYPE_FAM_FILE_MONITOR,