• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* GIO - GLib Input, Output and Streaming Library
2  *
3  * Copyright (C) 2006-2007 Red Hat, Inc.
4  * Copyright (C) 2006-2007 Red Hat, Inc.
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.1 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  * Author: Vlad Grecescu <b100dian@gmail.com>
20  * Author: Chun-wei Fan <fanc999@yahoo.com.tw>
21  *
22  */
23 
24 #include "config.h"
25 
26 #include "gwin32filemonitor.h"
27 #include "gwin32fsmonitorutils.h"
28 
29 #include <windows.h>
30 
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))
34 
35 static void
g_win32_file_monitor_start(GLocalFileMonitor * monitor,const gchar * dirname,const gchar * basename,const gchar * filename,GFileMonitorSource * source)36 g_win32_file_monitor_start (GLocalFileMonitor  *monitor,
37                             const gchar        *dirname,
38                             const gchar        *basename,
39                             const gchar        *filename,
40                             GFileMonitorSource *source)
41 {
42   GWin32FileMonitor *win32_monitor = G_WIN32_FILE_MONITOR (monitor);
43 
44   win32_monitor->priv->fms = source;
45 
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);
52 }
53 
54 static gboolean
g_win32_file_monitor_is_supported(void)55 g_win32_file_monitor_is_supported (void)
56 {
57   return TRUE;
58 }
59 
60 static void
g_win32_file_monitor_init(GWin32FileMonitor * monitor)61 g_win32_file_monitor_init (GWin32FileMonitor *monitor)
62 {
63   monitor->priv = g_win32_fs_monitor_create (TRUE);
64 
65   monitor->priv->self = G_FILE_MONITOR (monitor);
66 }
67 
68 static void
g_win32_file_monitor_finalize(GObject * object)69 g_win32_file_monitor_finalize (GObject *object)
70 {
71   GWin32FileMonitor *monitor;
72 
73   monitor = G_WIN32_FILE_MONITOR (object);
74 
75   g_win32_fs_monitor_finalize (monitor->priv);
76 
77   G_OBJECT_CLASS (g_win32_file_monitor_parent_class)->finalize (object);
78 }
79 
80 static gboolean
g_win32_file_monitor_cancel(GFileMonitor * monitor)81 g_win32_file_monitor_cancel (GFileMonitor* monitor)
82 {
83   GWin32FileMonitor *file_monitor;
84 
85   file_monitor = G_WIN32_FILE_MONITOR (monitor);
86 
87   g_win32_fs_monitor_close_handle (file_monitor->priv);
88 
89   return TRUE;
90 }
91 
92 static void
g_win32_file_monitor_class_init(GWin32FileMonitorClass * klass)93 g_win32_file_monitor_class_init (GWin32FileMonitorClass *klass)
94 {
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);
98 
99   gobject_class->finalize = g_win32_file_monitor_finalize;
100   file_monitor_class->cancel = g_win32_file_monitor_cancel;
101 
102   local_file_monitor_class->is_supported = g_win32_file_monitor_is_supported;
103   local_file_monitor_class->start = g_win32_file_monitor_start;
104 }
105