1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* vim:set expandtab ts=4 shiftwidth=4: */
3 /* GIO - GLib Input, Output and Streaming Library
5 * Copyright (C) 2006-2007 Red Hat, Inc.
6 * Copyright (C) 2007 Sebastian Dröge.
7 * Copyright (C) 2008 Sun Microsystems, Inc. All rights reserved.
8 * Use is subject to license terms.
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General
21 * Public License along with this library; if not, write to the
22 * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
23 * Boston, MA 02111-1307, USA.
25 * Authors: Alexander Larsson <alexl@redhat.com>
26 * John McCutchan <john@johnmccutchan.com>
27 * Sebastian Dröge <slomo@circular-chaos.org>
28 * Lin Ma <lin.ma@sun.com>
33 #include "gfenfilemonitor.h"
34 #include <gio/giomodule.h>
36 #include "fen-helper.h"
40 struct _GFenFileMonitor
42 GLocalFileMonitor parent_instance;
46 static gboolean g_fen_file_monitor_cancel (GFileMonitor* monitor);
48 #define g_fen_file_monitor_get_type _g_fen_file_monitor_get_type
49 G_DEFINE_TYPE_WITH_CODE (GFenFileMonitor, g_fen_file_monitor, G_TYPE_LOCAL_FILE_MONITOR,
50 g_io_extension_point_implement (G_LOCAL_FILE_MONITOR_EXTENSION_POINT_NAME,
56 g_fen_file_monitor_finalize (GObject *object)
58 GFenFileMonitor *self = G_FEN_FILE_MONITOR (object);
61 fen_remove (G_LOCAL_FILE_MONITOR (self)->filename, self->sub, FALSE);
62 fen_sub_delete (self->sub);
66 if (G_OBJECT_CLASS (g_fen_file_monitor_parent_class)->finalize)
67 (*G_OBJECT_CLASS (g_fen_file_monitor_parent_class)->finalize) (object);
71 g_fen_file_monitor_constructor (GType type,
72 guint n_construct_properties,
73 GObjectConstructParam *construct_properties)
76 GFenFileMonitorClass *klass;
77 GObjectClass *parent_class;
78 GFenFileMonitor *self;
79 const gchar *filename = NULL;
81 klass = G_FEN_FILE_MONITOR_CLASS (g_type_class_peek (G_TYPE_FEN_FILE_MONITOR));
82 parent_class = g_fen_file_monitor_parent_class;
83 obj = parent_class->constructor (type,
84 n_construct_properties,
85 construct_properties);
87 self = G_FEN_FILE_MONITOR (obj);
89 filename = G_LOCAL_FILE_MONITOR (obj)->filename;
91 g_assert (filename != NULL);
93 /* Will never fail as is_supported() should be called before instanciating
96 g_assert_not_reached ();
98 /* FIXME: what to do about errors here? we can't return NULL or another
99 * kind of error and an assertion is probably too hard */
100 self->sub = fen_sub_new (self, FALSE);
101 g_assert (self->sub);
103 fen_add (filename, self->sub, FALSE);
109 g_fen_file_monitor_is_supported (void)
115 g_fen_file_monitor_class_init (GFenFileMonitorClass* klass)
117 GObjectClass* gobject_class = G_OBJECT_CLASS (klass);
118 GFileMonitorClass *file_monitor_class = G_FILE_MONITOR_CLASS (klass);
119 GLocalFileMonitorClass *local_file_monitor_class = G_LOCAL_FILE_MONITOR_CLASS (klass);
121 gobject_class->finalize = g_fen_file_monitor_finalize;
122 gobject_class->constructor = g_fen_file_monitor_constructor;
123 file_monitor_class->cancel = g_fen_file_monitor_cancel;
125 local_file_monitor_class->is_supported = g_fen_file_monitor_is_supported;
129 g_fen_file_monitor_init (GFenFileMonitor* monitor)
134 g_fen_file_monitor_cancel (GFileMonitor* monitor)
136 GFenFileMonitor *self = G_FEN_FILE_MONITOR (monitor);
139 fen_remove (G_LOCAL_FILE_MONITOR (self)->filename, self->sub, FALSE);
140 fen_sub_delete (self->sub);
144 if (G_FILE_MONITOR_CLASS (g_fen_file_monitor_parent_class)->cancel)
145 (*G_FILE_MONITOR_CLASS (g_fen_file_monitor_parent_class)->cancel) (monitor);