GApplication:handle-local-options: document return value
[platform/upstream/glib.git] / gio / fam / gfamfilemonitor.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 "gfamfilemonitor.h"
27 #include <gio/giomodule.h>
28
29 #include "fam-helper.h"
30
31 struct _GFamFileMonitor
32 {
33   GLocalFileMonitor parent_instance;
34   fam_sub *sub;
35 };
36
37 static gboolean g_fam_file_monitor_cancel (GFileMonitor* monitor);
38
39 G_DEFINE_DYNAMIC_TYPE (GFamFileMonitor, g_fam_file_monitor, G_TYPE_LOCAL_FILE_MONITOR)
40
41 static void
42 g_fam_file_monitor_finalize (GObject *object)
43 {
44   GFamFileMonitor *fam_monitor = G_FAM_FILE_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     fam_monitor->sub = NULL;
51   }
52
53   if (G_OBJECT_CLASS (g_fam_file_monitor_parent_class)->finalize)
54     (*G_OBJECT_CLASS (g_fam_file_monitor_parent_class)->finalize) (object);
55 }
56
57 static GObject *
58 g_fam_file_monitor_constructor (GType type,
59                                 guint n_construct_properties,
60                                 GObjectConstructParam *construct_properties)
61 {
62   GObject *obj;
63   GFamFileMonitorClass *klass;
64   GObjectClass *parent_class;
65   GFamFileMonitor *fam_monitor;
66   const gchar *filename = NULL;
67   fam_sub *sub = NULL;
68   
69   klass = G_FAM_FILE_MONITOR_CLASS (g_type_class_peek (G_TYPE_FAM_FILE_MONITOR));
70   parent_class = G_OBJECT_CLASS (g_type_class_peek_parent (klass));
71   obj = parent_class->constructor (type,
72                                    n_construct_properties,
73                                    construct_properties);
74
75   fam_monitor = G_FAM_FILE_MONITOR (obj);
76
77   filename = G_LOCAL_FILE_MONITOR (obj)->filename;
78
79   g_assert (filename != NULL);
80
81   sub = _fam_sub_add (filename, FALSE, 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_file_monitor_class_finalize (GFamFileMonitorClass *klass)
93 {
94 }
95
96 static gboolean
97 g_fam_file_monitor_is_supported (void)
98 {
99   return _fam_sub_startup ();
100 }
101
102 static void
103 g_fam_file_monitor_class_init (GFamFileMonitorClass* klass)
104 {
105   GObjectClass* gobject_class = G_OBJECT_CLASS (klass);
106   GFileMonitorClass *file_monitor_class = G_FILE_MONITOR_CLASS (klass);
107   GLocalFileMonitorClass *local_file_monitor_class = G_LOCAL_FILE_MONITOR_CLASS (klass);
108   
109   gobject_class->finalize = g_fam_file_monitor_finalize;
110   gobject_class->constructor = g_fam_file_monitor_constructor;
111   file_monitor_class->cancel = g_fam_file_monitor_cancel;
112
113   local_file_monitor_class->is_supported = g_fam_file_monitor_is_supported;
114 }
115
116 static void
117 g_fam_file_monitor_init (GFamFileMonitor* monitor)
118 {
119
120 }
121
122 static gboolean
123 g_fam_file_monitor_cancel (GFileMonitor* monitor)
124 {
125   GFamFileMonitor *fam_monitor = G_FAM_FILE_MONITOR (monitor);
126   fam_sub *sub = fam_monitor->sub;
127
128   if (sub) {
129     if (!_fam_sub_cancel (sub))
130       g_warning ("Unexpected error cancelling fam monitor");
131     fam_monitor->sub = NULL;
132   }
133
134   if (G_FILE_MONITOR_CLASS (g_fam_file_monitor_parent_class)->cancel)
135     (*G_FILE_MONITOR_CLASS (g_fam_file_monitor_parent_class)->cancel) (monitor);
136
137   return TRUE;
138 }
139
140 void
141 g_fam_file_monitor_register (GIOModule *module)
142 {
143   g_fam_file_monitor_register_type (G_TYPE_MODULE (module));
144   g_io_extension_point_implement (G_LOCAL_FILE_MONITOR_EXTENSION_POINT_NAME,
145                                   G_TYPE_FAM_FILE_MONITOR,
146                                   "fam",
147                                   10);
148   g_io_extension_point_implement (G_NFS_FILE_MONITOR_EXTENSION_POINT_NAME,
149                                   G_TYPE_FAM_FILE_MONITOR,
150                                   "fam",
151                                   10);
152 }
153