GVariant: add support for single precision floats
[platform/upstream/glib.git] / gio / fen / gfenfilemonitor.c
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
4  * 
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
8  * reserved.
9  *
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.
14  *
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.
19  *
20  * You should have received a copy of the GNU Lesser General
21  * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
22  *
23  * Authors: Alexander Larsson <alexl@redhat.com>
24  *          John McCutchan <john@johnmccutchan.com> 
25  *          Sebastian Dröge <slomo@circular-chaos.org>
26  *          Lin Ma <lin.ma@sun.com>
27  */
28
29 #include "config.h"
30
31 #include "gfenfilemonitor.h"
32 #include <gio/giomodule.h>
33
34 #include "fen-helper.h"
35
36 struct _GFenFileMonitor
37 {
38     GLocalFileMonitor parent_instance;
39     gboolean enabled;
40 };
41
42 static gboolean g_fen_file_monitor_cancel (GFileMonitor* monitor);
43
44 #define g_fen_file_monitor_get_type _g_fen_file_monitor_get_type
45 G_DEFINE_TYPE_WITH_CODE (GFenFileMonitor, g_fen_file_monitor, G_TYPE_LOCAL_FILE_MONITOR,
46   g_io_extension_point_implement (G_LOCAL_FILE_MONITOR_EXTENSION_POINT_NAME,
47     g_define_type_id,
48     "fen",
49     20))
50
51 static void
52 g_fen_file_monitor_finalize (GObject *object)
53 {
54     GFenFileMonitor *self = G_FEN_FILE_MONITOR (object);
55     
56     if (self->enabled) {
57         fen_remove (G_LOCAL_FILE_MONITOR (self)->filename, self, FALSE);
58         self->enabled = FALSE;
59     }
60     
61     if (G_OBJECT_CLASS (g_fen_file_monitor_parent_class)->finalize)
62         (*G_OBJECT_CLASS (g_fen_file_monitor_parent_class)->finalize) (object);
63 }
64
65 static GObject *
66 g_fen_file_monitor_constructor (GType type,
67   guint n_construct_properties,
68   GObjectConstructParam *construct_properties)
69 {
70     GObject *obj;
71     GFenFileMonitorClass *klass;
72     GObjectClass *parent_class;
73     GFenFileMonitor *self;
74     const gchar *filename = NULL;
75   
76     klass = G_FEN_FILE_MONITOR_CLASS (g_type_class_peek (G_TYPE_FEN_FILE_MONITOR));
77     parent_class = g_fen_file_monitor_parent_class;
78     obj = parent_class->constructor (type,
79       n_construct_properties,
80       construct_properties);
81
82     self = G_FEN_FILE_MONITOR (obj);
83
84     filename = G_LOCAL_FILE_MONITOR (obj)->filename;
85
86     g_assert (filename != NULL);
87
88     /* Will never fail as is_supported() should be called before instanciating
89      * anyway */
90     if (!fen_init ())
91         g_assert_not_reached ();
92     
93     /* FIXME: what to do about errors here? we can't return NULL or another
94      * kind of error and an assertion is probably too hard */
95     fen_add (filename, self, FALSE);
96     self->enabled = TRUE;
97
98     return obj;
99 }
100
101 static gboolean
102 g_fen_file_monitor_is_supported (void)
103 {
104     return fen_init ();
105 }
106
107 static void
108 g_fen_file_monitor_class_init (GFenFileMonitorClass* klass)
109 {
110     GObjectClass* gobject_class = G_OBJECT_CLASS (klass);
111     GFileMonitorClass *file_monitor_class = G_FILE_MONITOR_CLASS (klass);
112     GLocalFileMonitorClass *local_file_monitor_class = G_LOCAL_FILE_MONITOR_CLASS (klass);
113   
114     gobject_class->finalize = g_fen_file_monitor_finalize;
115     gobject_class->constructor = g_fen_file_monitor_constructor;
116     file_monitor_class->cancel = g_fen_file_monitor_cancel;
117
118     local_file_monitor_class->is_supported = g_fen_file_monitor_is_supported;
119 }
120
121 static void
122 g_fen_file_monitor_init (GFenFileMonitor* monitor)
123 {
124 }
125
126 static gboolean
127 g_fen_file_monitor_cancel (GFileMonitor* monitor)
128 {
129     GFenFileMonitor *self = G_FEN_FILE_MONITOR (monitor);
130     
131     if (self->enabled) {
132         fen_remove (G_LOCAL_FILE_MONITOR (self)->filename, self, FALSE);
133         self->enabled = FALSE;
134     }
135     
136     if (G_FILE_MONITOR_CLASS (g_fen_file_monitor_parent_class)->cancel)
137         (*G_FILE_MONITOR_CLASS (g_fen_file_monitor_parent_class)->cancel) (monitor);
138
139     return TRUE;
140 }