1 /* GIO - GLib Input, Output and Streaming Library
3 * Copyright (C) 2006-2007 Red Hat, Inc.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General
16 * Public License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
18 * Boston, MA 02111-1307, USA.
20 * Author: Alexander Larsson <alexl@redhat.com>
25 #include "glocalfilemonitor.h"
26 #include "giomodule-priv.h"
39 G_DEFINE_ABSTRACT_TYPE (GLocalFileMonitor, g_local_file_monitor, G_TYPE_FILE_MONITOR)
42 g_local_file_monitor_init (GLocalFileMonitor* local_monitor)
47 g_local_file_monitor_set_property (GObject *object,
58 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
64 g_local_file_monitor_constructor (GType type,
65 guint n_construct_properties,
66 GObjectConstructParam *construct_properties)
69 GLocalFileMonitorClass *klass;
70 GObjectClass *parent_class;
71 GLocalFileMonitor *local_monitor;
72 const gchar *filename = NULL;
75 klass = G_LOCAL_FILE_MONITOR_CLASS (g_type_class_peek (G_TYPE_LOCAL_FILE_MONITOR));
76 parent_class = G_OBJECT_CLASS (g_type_class_peek_parent (klass));
77 obj = parent_class->constructor (type,
78 n_construct_properties,
79 construct_properties);
81 local_monitor = G_LOCAL_FILE_MONITOR (obj);
83 for (i = 0; i < n_construct_properties; i++)
85 if (strcmp ("filename", g_param_spec_get_name (construct_properties[i].pspec)) == 0)
87 g_warn_if_fail (G_VALUE_HOLDS_STRING (construct_properties[i].value));
88 filename = g_value_get_string (construct_properties[i].value);
93 g_warn_if_fail (filename != NULL);
95 local_monitor->filename = g_strdup (filename);
100 g_local_file_monitor_finalize (GObject *object)
102 GLocalFileMonitor *local_monitor = G_LOCAL_FILE_MONITOR (object);
103 if (local_monitor->filename)
105 g_free (local_monitor->filename);
106 local_monitor->filename = NULL;
109 G_OBJECT_CLASS (g_local_file_monitor_parent_class)->finalize (object);
112 static void g_local_file_monitor_class_init (GLocalFileMonitorClass *klass)
114 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
116 gobject_class->set_property = g_local_file_monitor_set_property;
117 gobject_class->finalize = g_local_file_monitor_finalize;
118 gobject_class->constructor = g_local_file_monitor_constructor;
120 g_object_class_install_property (gobject_class,
122 g_param_spec_string ("filename",
124 P_("File name to monitor"),
126 G_PARAM_CONSTRUCT_ONLY|
128 G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB));
132 get_default_local_file_monitor (gpointer data)
134 GLocalFileMonitorClass *chosen_class;
135 GLocalFileMonitorClass **ret = data;
136 GIOExtensionPoint *ep;
137 GList *extensions, *l;
139 _g_io_modules_ensure_loaded ();
141 ep = g_io_extension_point_lookup (G_LOCAL_FILE_MONITOR_EXTENSION_POINT_NAME);
143 extensions = g_io_extension_point_get_extensions (ep);
146 for (l = extensions; l != NULL; l = l->next)
148 GIOExtension *extension = l->data;
149 GLocalFileMonitorClass *klass;
151 klass = G_LOCAL_FILE_MONITOR_CLASS (g_io_extension_ref_class (extension));
153 if (klass->is_supported ())
155 chosen_class = klass;
159 g_type_class_unref (klass);
165 return (gpointer)G_TYPE_FROM_CLASS (chosen_class);
168 return (gpointer)G_TYPE_INVALID;
172 * g_local_file_monitor_new:
173 * @pathname: path name to monitor.
174 * @flags: #GFileMonitorFlags.
176 * Returns: a new #GFileMonitor for the given @pathname.
179 _g_local_file_monitor_new (const char *pathname,
180 GFileMonitorFlags flags,
183 static GOnce once_init = G_ONCE_INIT;
184 GTypeClass *type_class;
185 GFileMonitor *monitor;
189 g_once (&once_init, get_default_local_file_monitor, &type_class);
190 type = (GType)once_init.retval;
193 if (type != G_TYPE_INVALID)
194 monitor = G_FILE_MONITOR (g_object_new (type, "filename", pathname, NULL));
196 g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, _("Unable to find default local file monitor type"));
198 /* This is non-null on first pass here. Unref the class now.
199 * This is to avoid unloading the module and then loading it
200 * again which would happen if we unrefed the class
201 * before creating the monitor.
205 g_type_class_unref (type_class);
210 #define __G_LOCAL_FILE_MONITOR_C__
211 #include "gioaliasdef.c"