GVariant: add support for single precision floats
[platform/upstream/glib.git] / gio / fen / gfendirectorymonitor.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 "gfendirectorymonitor.h"
32 #include <gio/giomodule.h>
33
34 #include "fen-helper.h"
35
36 struct _GFenDirectoryMonitor
37 {
38     GLocalDirectoryMonitor parent_instance;
39     gboolean enabled;
40 };
41
42 static gboolean g_fen_directory_monitor_cancel (GFileMonitor* monitor);
43
44 #define g_fen_directory_monitor_get_type _g_fen_directory_monitor_get_type
45 G_DEFINE_TYPE_WITH_CODE (GFenDirectoryMonitor, g_fen_directory_monitor, G_TYPE_LOCAL_DIRECTORY_MONITOR,
46   g_io_extension_point_implement (G_LOCAL_DIRECTORY_MONITOR_EXTENSION_POINT_NAME,
47     g_define_type_id,
48     "fen",
49     20))
50
51 static void
52 g_fen_directory_monitor_finalize (GObject *object)
53 {
54     GFenDirectoryMonitor *self = G_FEN_DIRECTORY_MONITOR (object);
55     
56     if (self->enabled) {
57         fen_remove (G_LOCAL_DIRECTORY_MONITOR (self)->dirname, self, TRUE);
58         self->enabled = FALSE;
59     }
60
61     if (G_OBJECT_CLASS (g_fen_directory_monitor_parent_class)->finalize)
62         (*G_OBJECT_CLASS (g_fen_directory_monitor_parent_class)->finalize) (object);
63 }
64
65 static GObject *
66 g_fen_directory_monitor_constructor (GType type,
67   guint n_construct_properties,
68   GObjectConstructParam *construct_properties)
69 {
70     GObject *obj;
71     GFenDirectoryMonitorClass *klass;
72     GObjectClass *parent_class;
73     GFenDirectoryMonitor *self;
74     const gchar *dirname = NULL;
75   
76     klass = G_FEN_DIRECTORY_MONITOR_CLASS (g_type_class_peek (G_TYPE_FEN_DIRECTORY_MONITOR));
77     parent_class = g_fen_directory_monitor_parent_class;
78     obj = parent_class->constructor (type,
79       n_construct_properties,
80       construct_properties);
81
82     self = G_FEN_DIRECTORY_MONITOR (obj);
83
84     dirname = G_LOCAL_DIRECTORY_MONITOR (self)->dirname;
85     g_assert (dirname != NULL);
86
87     /* Will never fail as is_supported() should be called before instanciating
88      * anyway */
89     if (!fen_init ())
90         g_assert_not_reached ();
91
92     /* FIXME: what to do about errors here? we can't return NULL or another
93      * kind of error and an assertion is probably too hard */
94     fen_add (dirname, self, TRUE);
95     self->enabled = TRUE;
96
97     return obj;
98 }
99
100 static gboolean
101 g_fen_directory_monitor_is_supported (void)
102 {
103     return fen_init ();
104 }
105
106 static void
107 g_fen_directory_monitor_class_init (GFenDirectoryMonitorClass* klass)
108 {
109     GObjectClass* gobject_class = G_OBJECT_CLASS (klass);
110     GFileMonitorClass *directory_monitor_class = G_FILE_MONITOR_CLASS (klass);
111     GLocalDirectoryMonitorClass *local_directory_monitor_class = G_LOCAL_DIRECTORY_MONITOR_CLASS (klass);
112   
113     gobject_class->finalize = g_fen_directory_monitor_finalize;
114     gobject_class->constructor = g_fen_directory_monitor_constructor;
115     directory_monitor_class->cancel = g_fen_directory_monitor_cancel;
116
117     local_directory_monitor_class->mount_notify = TRUE;
118     local_directory_monitor_class->is_supported = g_fen_directory_monitor_is_supported;
119 }
120
121 static void
122 g_fen_directory_monitor_init (GFenDirectoryMonitor* monitor)
123 {
124 }
125
126 static gboolean
127 g_fen_directory_monitor_cancel (GFileMonitor* monitor)
128 {
129     GFenDirectoryMonitor *self = G_FEN_DIRECTORY_MONITOR (monitor);
130     
131     if (self->enabled) {
132         fen_remove (G_LOCAL_DIRECTORY_MONITOR (self)->dirname, self, TRUE);
133         self->enabled = FALSE;
134     }
135     
136     if (G_FILE_MONITOR_CLASS (g_fen_directory_monitor_parent_class)->cancel)
137         (*G_FILE_MONITOR_CLASS (g_fen_directory_monitor_parent_class)->cancel) (monitor);
138
139     return TRUE;
140 }