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, 2010 Oracle and/or its affiliates, Inc. All rights
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"
38 struct _GFenFileMonitor
40 GLocalFileMonitor parent_instance;
44 static gboolean g_fen_file_monitor_cancel (GFileMonitor* monitor);
46 #define g_fen_file_monitor_get_type _g_fen_file_monitor_get_type
47 G_DEFINE_TYPE_WITH_CODE (GFenFileMonitor, g_fen_file_monitor, G_TYPE_LOCAL_FILE_MONITOR,
48 g_io_extension_point_implement (G_LOCAL_FILE_MONITOR_EXTENSION_POINT_NAME,
54 g_fen_file_monitor_finalize (GObject *object)
56 GFenFileMonitor *self = G_FEN_FILE_MONITOR (object);
59 fen_remove (G_LOCAL_FILE_MONITOR (self)->filename, self, FALSE);
60 self->enabled = FALSE;
63 if (G_OBJECT_CLASS (g_fen_file_monitor_parent_class)->finalize)
64 (*G_OBJECT_CLASS (g_fen_file_monitor_parent_class)->finalize) (object);
68 g_fen_file_monitor_constructor (GType type,
69 guint n_construct_properties,
70 GObjectConstructParam *construct_properties)
73 GFenFileMonitorClass *klass;
74 GObjectClass *parent_class;
75 GFenFileMonitor *self;
76 const gchar *filename = NULL;
78 klass = G_FEN_FILE_MONITOR_CLASS (g_type_class_peek (G_TYPE_FEN_FILE_MONITOR));
79 parent_class = g_fen_file_monitor_parent_class;
80 obj = parent_class->constructor (type,
81 n_construct_properties,
82 construct_properties);
84 self = G_FEN_FILE_MONITOR (obj);
86 filename = G_LOCAL_FILE_MONITOR (obj)->filename;
88 g_assert (filename != NULL);
90 /* Will never fail as is_supported() should be called before instanciating
93 g_assert_not_reached ();
95 /* FIXME: what to do about errors here? we can't return NULL or another
96 * kind of error and an assertion is probably too hard */
97 fen_add (filename, self, FALSE);
104 g_fen_file_monitor_is_supported (void)
110 g_fen_file_monitor_class_init (GFenFileMonitorClass* klass)
112 GObjectClass* gobject_class = G_OBJECT_CLASS (klass);
113 GFileMonitorClass *file_monitor_class = G_FILE_MONITOR_CLASS (klass);
114 GLocalFileMonitorClass *local_file_monitor_class = G_LOCAL_FILE_MONITOR_CLASS (klass);
116 gobject_class->finalize = g_fen_file_monitor_finalize;
117 gobject_class->constructor = g_fen_file_monitor_constructor;
118 file_monitor_class->cancel = g_fen_file_monitor_cancel;
120 local_file_monitor_class->is_supported = g_fen_file_monitor_is_supported;
124 g_fen_file_monitor_init (GFenFileMonitor* monitor)
129 g_fen_file_monitor_cancel (GFileMonitor* monitor)
131 GFenFileMonitor *self = G_FEN_FILE_MONITOR (monitor);
134 fen_remove (G_LOCAL_FILE_MONITOR (self)->filename, self, FALSE);
135 self->enabled = FALSE;
138 if (G_FILE_MONITOR_CLASS (g_fen_file_monitor_parent_class)->cancel)
139 (*G_FILE_MONITOR_CLASS (g_fen_file_monitor_parent_class)->cancel) (monitor);