GApplication:handle-local-options: document return value
[platform/upstream/glib.git] / gio / fam / gfamdirectorymonitor.c
1 /* GIO - GLib Input, Output and Streaming Library
2  * 
3  * Copyright (C) 2006-2007 Red Hat, Inc.
4  * Copyright (C) 2007 Sebastian Dröge.
5  *
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.
10  *
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.
15  *
16  * You should have received a copy of the GNU Lesser General
17  * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
18  *
19  * Authors: Alexander Larsson <alexl@redhat.com>
20  *          John McCutchan <john@johnmccutchan.com> 
21  *          Sebastian Dröge <slomo@circular-chaos.org>
22  */
23
24 #include "config.h"
25
26 #include "gfamdirectorymonitor.h"
27 #include <gio/giomodule.h>
28
29 #include "fam-helper.h"
30
31 struct _GFamDirectoryMonitor
32 {
33   GLocalDirectoryMonitor parent_instance;
34   fam_sub *sub;
35 };
36
37 static gboolean g_fam_directory_monitor_cancel (GFileMonitor* monitor);
38
39 G_DEFINE_DYNAMIC_TYPE (GFamDirectoryMonitor, g_fam_directory_monitor, G_TYPE_LOCAL_DIRECTORY_MONITOR)
40
41 static void
42 g_fam_directory_monitor_finalize (GObject *object)
43 {
44   GFamDirectoryMonitor *fam_monitor = G_FAM_DIRECTORY_MONITOR (object);
45   fam_sub *sub = fam_monitor->sub;
46
47   if (sub) {
48     if (!_fam_sub_cancel (sub))
49       g_warning ("Unexpected error cancelling fam monitor");
50
51     fam_monitor->sub = NULL;
52   }
53
54   if (G_OBJECT_CLASS (g_fam_directory_monitor_parent_class)->finalize)
55     (*G_OBJECT_CLASS (g_fam_directory_monitor_parent_class)->finalize) (object);
56 }
57
58 static GObject *
59 g_fam_directory_monitor_constructor (GType type,
60                                     guint n_construct_properties,
61                                     GObjectConstructParam *construct_properties)
62 {
63   GObject *obj;
64   GFamDirectoryMonitorClass *klass;
65   GObjectClass *parent_class;
66   GFamDirectoryMonitor *fam_monitor;
67   const gchar *dirname = NULL;
68   fam_sub *sub = NULL;
69   
70   klass = G_FAM_DIRECTORY_MONITOR_CLASS (g_type_class_peek (G_TYPE_FAM_DIRECTORY_MONITOR));
71   parent_class = G_OBJECT_CLASS (g_type_class_peek_parent (klass));
72   obj = parent_class->constructor (type,
73                                    n_construct_properties,
74                                    construct_properties);
75
76   fam_monitor = G_FAM_DIRECTORY_MONITOR (obj);
77
78   dirname = G_LOCAL_DIRECTORY_MONITOR (obj)->dirname;
79   g_assert (dirname != NULL);
80
81   sub = _fam_sub_add (dirname, TRUE, fam_monitor);
82   /* FIXME: what to do about errors here? we can't return NULL or another
83    * kind of error and an assertion is probably too hard */
84   g_assert (sub != NULL);
85
86   fam_monitor->sub = sub;
87
88   return obj;
89 }
90
91 static void
92 g_fam_directory_monitor_class_finalize (GFamDirectoryMonitorClass *klass)
93 {
94 }
95
96 static gboolean
97 g_fam_directory_monitor_is_supported (void)
98 {
99   return _fam_sub_startup ();
100 }
101
102 static void
103 g_fam_directory_monitor_class_init (GFamDirectoryMonitorClass* klass)
104 {
105   GObjectClass* gobject_class = G_OBJECT_CLASS (klass);
106   GFileMonitorClass *file_monitor_class = G_FILE_MONITOR_CLASS (klass);
107   GLocalDirectoryMonitorClass *local_directory_monitor_class = G_LOCAL_DIRECTORY_MONITOR_CLASS (klass);
108   
109   gobject_class->finalize = g_fam_directory_monitor_finalize;
110   gobject_class->constructor = g_fam_directory_monitor_constructor;
111   file_monitor_class->cancel = g_fam_directory_monitor_cancel;
112
113   local_directory_monitor_class->mount_notify = FALSE;
114   local_directory_monitor_class->is_supported = g_fam_directory_monitor_is_supported;
115 }
116
117 static void
118 g_fam_directory_monitor_init (GFamDirectoryMonitor* monitor)
119 {
120
121 }
122
123 static gboolean
124 g_fam_directory_monitor_cancel (GFileMonitor* monitor)
125 {
126   GFamDirectoryMonitor *fam_monitor = G_FAM_DIRECTORY_MONITOR (monitor);
127   fam_sub *sub = fam_monitor->sub;
128
129   if (sub) {
130     if (!_fam_sub_cancel (sub))
131       g_warning ("Unexpected error cancelling fam monitor");
132
133     fam_monitor->sub = NULL;
134   }
135
136   if (G_FILE_MONITOR_CLASS (g_fam_directory_monitor_parent_class)->cancel)
137     (*G_FILE_MONITOR_CLASS (g_fam_directory_monitor_parent_class)->cancel) (monitor);
138
139   return TRUE;
140 }
141
142 void
143 g_fam_directory_monitor_register (GIOModule *module)
144 {
145   g_fam_directory_monitor_register_type (G_TYPE_MODULE (module));
146   g_io_extension_point_implement (G_LOCAL_DIRECTORY_MONITOR_EXTENSION_POINT_NAME,
147                                   G_TYPE_FAM_DIRECTORY_MONITOR,
148                                   "fam",
149                                   10);
150   g_io_extension_point_implement (G_NFS_DIRECTORY_MONITOR_EXTENSION_POINT_NAME,
151                                   G_TYPE_FAM_DIRECTORY_MONITOR,
152                                   "fam",
153                                   10);
154 }
155