Merge branch 'test-ip_mreq_source-android-only' into 'master'
[glib.git] / gio / win32 / gwin32filemonitor.c
blob8383570112285a751337fdb291cec051eaf1f07a
1 /* GIO - GLib Input, Output and Streaming Library
3 * Copyright (C) 2006-2007 Red Hat, Inc.
4 * Copyright (C) 2006-2007 Red Hat, Inc.
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.1 of the License, or (at your option) any later version.
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.
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/>.
19 * Author: Vlad Grecescu <b100dian@gmail.com>
20 * Author: Chun-wei Fan <fanc999@yahoo.com.tw>
24 #include "config.h"
26 #include "gwin32filemonitor.h"
27 #include "gwin32fsmonitorutils.h"
29 #include <windows.h>
31 G_DEFINE_TYPE_WITH_CODE (GWin32FileMonitor, g_win32_file_monitor, G_TYPE_LOCAL_FILE_MONITOR,
32 g_io_extension_point_implement (G_LOCAL_FILE_MONITOR_EXTENSION_POINT_NAME,
33 g_define_type_id, "win32filemonitor", 20))
35 static void
36 g_win32_file_monitor_start (GLocalFileMonitor *monitor,
37 const gchar *dirname,
38 const gchar *basename,
39 const gchar *filename,
40 GFileMonitorSource *source)
42 GWin32FileMonitor *win32_monitor = G_WIN32_FILE_MONITOR (monitor);
44 win32_monitor->priv->fms = source;
46 if (filename == NULL && basename == NULL)
47 g_win32_fs_monitor_init (win32_monitor->priv, dirname, NULL, FALSE);
48 else if (basename != NULL)
49 g_win32_fs_monitor_init (win32_monitor->priv, dirname, basename, TRUE);
50 else
51 g_win32_fs_monitor_init (win32_monitor->priv, NULL, filename, TRUE);
54 static gboolean
55 g_win32_file_monitor_is_supported (void)
57 return TRUE;
60 static void
61 g_win32_file_monitor_init (GWin32FileMonitor *monitor)
63 monitor->priv = g_win32_fs_monitor_create (TRUE);
65 monitor->priv->self = G_FILE_MONITOR (monitor);
68 static void
69 g_win32_file_monitor_finalize (GObject *object)
71 GWin32FileMonitor *monitor;
73 monitor = G_WIN32_FILE_MONITOR (object);
75 g_win32_fs_monitor_finalize (monitor->priv);
77 G_OBJECT_CLASS (g_win32_file_monitor_parent_class)->finalize (object);
80 static gboolean
81 g_win32_file_monitor_cancel (GFileMonitor* monitor)
83 GWin32FileMonitor *file_monitor;
85 file_monitor = G_WIN32_FILE_MONITOR (monitor);
87 g_win32_fs_monitor_close_handle (file_monitor->priv);
89 return TRUE;
92 static void
93 g_win32_file_monitor_class_init (GWin32FileMonitorClass *klass)
95 GObjectClass* gobject_class = G_OBJECT_CLASS (klass);
96 GFileMonitorClass *file_monitor_class = G_FILE_MONITOR_CLASS (klass);
97 GLocalFileMonitorClass *local_file_monitor_class = G_LOCAL_FILE_MONITOR_CLASS (klass);
99 gobject_class->finalize = g_win32_file_monitor_finalize;
100 file_monitor_class->cancel = g_win32_file_monitor_cancel;
102 local_file_monitor_class->is_supported = g_win32_file_monitor_is_supported;
103 local_file_monitor_class->start = g_win32_file_monitor_start;