From 506eed4ebd7c2c60b8762433ee37c3673f75f307 Mon Sep 17 00:00:00 2001 From: Tor Lillqvist Date: Sun, 3 Aug 2008 00:17:39 +0000 Subject: [PATCH] win32/gwin32directorymonitor.h Whitespace cleanup to match GLib style. 2008-08-03 Tor Lillqvist * win32/gwin32directorymonitor.h * win32/gwin32directorymonitor.c: Whitespace cleanup to match GLib style. svn path=/trunk/; revision=7291 --- gio/ChangeLog | 6 + gio/win32/gwin32directorymonitor.c | 270 +++++++++++++++++++++---------------- gio/win32/gwin32directorymonitor.h | 6 +- 3 files changed, 165 insertions(+), 117 deletions(-) diff --git a/gio/ChangeLog b/gio/ChangeLog index a4187aa..cd14c55 100644 --- a/gio/ChangeLog +++ b/gio/ChangeLog @@ -1,5 +1,11 @@ 2008-08-03 Tor Lillqvist + * win32/gwin32directorymonitor.h + * win32/gwin32directorymonitor.c: Whitespace cleanup to match GLib + style. + +2008-08-03 Tor Lillqvist + * win32/gwin32directorymonitor.c (g_win32_directory_monitor_callback): Make prototype match LPOVERLAPPED_COMPLETION_ROUTINE to avoid warning. Cast diff --git a/gio/win32/gwin32directorymonitor.c b/gio/win32/gwin32directorymonitor.c index 75c36f9..4f2b8b6 100644 --- a/gio/win32/gwin32directorymonitor.c +++ b/gio/win32/gwin32directorymonitor.c @@ -28,145 +28,187 @@ #include "giomodule.h" #include -G_DEFINE_TYPE_WITH_CODE (GWin32DirectoryMonitor, g_win32_directory_monitor, G_TYPE_LOCAL_DIRECTORY_MONITOR, -g_io_extension_point_implement (G_LOCAL_DIRECTORY_MONITOR_EXTENSION_POINT_NAME, +G_DEFINE_TYPE_WITH_CODE (GWin32DirectoryMonitor, + g_win32_directory_monitor, + G_TYPE_LOCAL_DIRECTORY_MONITOR, + g_io_extension_point_implement (G_LOCAL_DIRECTORY_MONITOR_EXTENSION_POINT_NAME, g_define_type_id, "readdirectorychanges", 20)) struct _GWin32DirectoryMonitorPrivate { - OVERLAPPED overlapped; - DWORD buffer_allocated_bytes; - gchar* file_notify_buffer; - DWORD buffer_filled_bytes; - HANDLE hDirectory; - /** needed in the APC where we only have this private struct */ - GFileMonitor * self; + OVERLAPPED overlapped; + DWORD buffer_allocated_bytes; + gchar *file_notify_buffer; + DWORD buffer_filled_bytes; + HANDLE hDirectory; + /* Needed in the APC where we only have this private struct */ + GFileMonitor *self; }; -static void g_win32_directory_monitor_finalize (GObject* base); -static gboolean g_win32_directory_monitor_cancel (GFileMonitor* base); -static GObject * g_win32_directory_monitor_constructor (GType type, guint n_construct_properties, GObjectConstructParam * construct_properties); +static void g_win32_directory_monitor_finalize (GObject *base); +static gboolean g_win32_directory_monitor_cancel (GFileMonitor *base); -static gboolean g_win32_directory_monitor_is_supported(void) { - return TRUE; -} +static GObject *g_win32_directory_monitor_constructor (GType type, + guint n_construct_properties, + GObjectConstructParam *construct_properties); -static void g_win32_directory_monitor_finalize (GObject* base) { - GWin32DirectoryMonitor * self; - self = G_WIN32_DIRECTORY_MONITOR (base); +static gboolean +g_win32_directory_monitor_is_supported (void) +{ + return TRUE; +} - g_free (self->priv->file_notify_buffer); - g_free (self->priv); - - if (G_OBJECT_CLASS (g_win32_directory_monitor_parent_class)->finalize) - (*G_OBJECT_CLASS (g_win32_directory_monitor_parent_class)->finalize) (base); +static void +g_win32_directory_monitor_finalize (GObject *base) +{ + GWin32DirectoryMonitor *self; + self = G_WIN32_DIRECTORY_MONITOR (base); + + g_free (self->priv->file_notify_buffer); + g_free (self->priv); + + if (G_OBJECT_CLASS (g_win32_directory_monitor_parent_class)->finalize) + (*G_OBJECT_CLASS (g_win32_directory_monitor_parent_class)->finalize) (base); } +static gboolean +g_win32_directory_monitor_cancel (GFileMonitor *base) +{ + GWin32DirectoryMonitor *self; + self = G_WIN32_DIRECTORY_MONITOR (base); -static gboolean g_win32_directory_monitor_cancel (GFileMonitor* base) { - GWin32DirectoryMonitor * self; - self = G_WIN32_DIRECTORY_MONITOR (base); - - /* this triggers a last callback() with nBytes=0 */ - if (self->priv->hDirectory != INVALID_HANDLE_VALUE) - CloseHandle (self->priv->hDirectory); + /* This triggers a last callback() with nBytes=0 */ + if (self->priv->hDirectory != INVALID_HANDLE_VALUE) + CloseHandle (self->priv->hDirectory); - if (G_FILE_MONITOR_CLASS (g_win32_directory_monitor_parent_class)->cancel) - (*G_FILE_MONITOR_CLASS (g_win32_directory_monitor_parent_class)->cancel) (base); - return TRUE; + if (G_FILE_MONITOR_CLASS (g_win32_directory_monitor_parent_class)->cancel) + (*G_FILE_MONITOR_CLASS (g_win32_directory_monitor_parent_class)->cancel) (base); + return TRUE; } -void CALLBACK g_win32_directory_monitor_callback (DWORD error, DWORD nBytes, LPOVERLAPPED lpOverlapped) +static void CALLBACK +g_win32_directory_monitor_callback (DWORD error, + DWORD nBytes, + LPOVERLAPPED lpOverlapped) { - gulong offset; - PFILE_NOTIFY_INFORMATION pfile_notify_walker; - gulong file_name_len; - gchar* file_name; - GFile * file; - GWin32DirectoryMonitorPrivate *priv = (GWin32DirectoryMonitorPrivate *) lpOverlapped; - - static GFileMonitorEvent events[] = {0, - G_FILE_MONITOR_EVENT_CREATED, /* FILE_ACTION_ADDED */ - G_FILE_MONITOR_EVENT_DELETED, /* FILE_ACTION_REMOVED */ - G_FILE_MONITOR_EVENT_CHANGED, /* FILE_ACTION_MODIFIED */ - G_FILE_MONITOR_EVENT_DELETED, /* FILE_ACTION_RENAMED_OLD_NAME */ - G_FILE_MONITOR_EVENT_CREATED, /* FILE_ACTION_RENAMED_NEW_NAME */ - }; - - if (!nBytes) /* monitor was cancelled/finalized */ - return; - - if (g_file_monitor_is_cancelled (G_FILE_MONITOR (priv->self))) - return; /* and ReadDirectoryChangesW doesn't get called this time */ - - offset = 0; - do { - pfile_notify_walker = (PFILE_NOTIFY_INFORMATION)(priv->file_notify_buffer + offset); - offset += pfile_notify_walker->NextEntryOffset; - file_name = g_utf16_to_utf8 (pfile_notify_walker->FileName, pfile_notify_walker->FileNameLength / sizeof(WCHAR), NULL, &file_name_len, NULL); - file = g_file_new_for_path (file_name); - g_file_monitor_emit_event (priv->self, file, NULL, events [pfile_notify_walker->Action]); - g_object_unref (file); - g_free (file_name); - } while (pfile_notify_walker->NextEntryOffset); - - ReadDirectoryChangesW (priv->hDirectory, (gpointer)priv->file_notify_buffer, priv->buffer_allocated_bytes, FALSE, - FILE_NOTIFY_CHANGE_FILE_NAME | FILE_NOTIFY_CHANGE_DIR_NAME | FILE_NOTIFY_CHANGE_ATTRIBUTES | - FILE_NOTIFY_CHANGE_SIZE, &priv->buffer_filled_bytes, &priv->overlapped, g_win32_directory_monitor_callback); + gulong offset; + PFILE_NOTIFY_INFORMATION pfile_notify_walker; + gulong file_name_len; + gchar *file_name; + GFile *file; + GWin32DirectoryMonitorPrivate *priv = (GWin32DirectoryMonitorPrivate *) lpOverlapped; + + static GFileMonitorEvent events[] = + { + 0, + G_FILE_MONITOR_EVENT_CREATED, /* FILE_ACTION_ADDED */ + G_FILE_MONITOR_EVENT_DELETED, /* FILE_ACTION_REMOVED */ + G_FILE_MONITOR_EVENT_CHANGED, /* FILE_ACTION_MODIFIED */ + G_FILE_MONITOR_EVENT_DELETED, /* FILE_ACTION_RENAMED_OLD_NAME */ + G_FILE_MONITOR_EVENT_CREATED, /* FILE_ACTION_RENAMED_NEW_NAME */ + }; + + if (!nBytes) /* Monitor was cancelled/finalized */ + return; + + if (g_file_monitor_is_cancelled (G_FILE_MONITOR (priv->self))) + return; /* and ReadDirectoryChangesW doesn't get called this time */ + + offset = 0; + do { + pfile_notify_walker = (PFILE_NOTIFY_INFORMATION)(priv->file_notify_buffer + offset); + offset += pfile_notify_walker->NextEntryOffset; + file_name = g_utf16_to_utf8 (pfile_notify_walker->FileName, pfile_notify_walker->FileNameLength / sizeof(WCHAR), NULL, &file_name_len, NULL); + file = g_file_new_for_path (file_name); + g_file_monitor_emit_event (priv->self, file, NULL, events [pfile_notify_walker->Action]); + g_object_unref (file); + g_free (file_name); + } while (pfile_notify_walker->NextEntryOffset); + + ReadDirectoryChangesW (priv->hDirectory, + (gpointer)priv->file_notify_buffer, + priv->buffer_allocated_bytes, + FALSE, + FILE_NOTIFY_CHANGE_FILE_NAME | + FILE_NOTIFY_CHANGE_DIR_NAME | + FILE_NOTIFY_CHANGE_ATTRIBUTES | + FILE_NOTIFY_CHANGE_SIZE, + &priv->buffer_filled_bytes, + &priv->overlapped, + g_win32_directory_monitor_callback); } -static GObject * g_win32_directory_monitor_constructor (GType type, guint n_construct_properties, GObjectConstructParam * construct_properties) { - GObject * obj; - GWin32DirectoryMonitorClass * klass; - GObjectClass * parent_class; - GWin32DirectoryMonitor * self; - wchar_t * wdirname; - gboolean result; - - klass = G_WIN32_DIRECTORY_MONITOR_CLASS (g_type_class_peek (G_TYPE_WIN32_DIRECTORY_MONITOR)); - parent_class = G_OBJECT_CLASS (g_type_class_peek_parent (klass)); - obj = parent_class->constructor (type, n_construct_properties, construct_properties); - self = G_WIN32_DIRECTORY_MONITOR (obj); - wdirname = g_utf8_to_utf16 (G_LOCAL_DIRECTORY_MONITOR (obj)->dirname, -1, NULL, NULL, NULL); - - self->priv->hDirectory = CreateFileW (wdirname, FILE_LIST_DIRECTORY, FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE, - NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OVERLAPPED, NULL); - g_free (wdirname); - if (self->priv->hDirectory == INVALID_HANDLE_VALUE) - { - /* Ignore errors */ - return obj; - } - - result = ReadDirectoryChangesW (self->priv->hDirectory, (gpointer)self->priv->file_notify_buffer, self->priv->buffer_allocated_bytes, FALSE, - FILE_NOTIFY_CHANGE_FILE_NAME | FILE_NOTIFY_CHANGE_DIR_NAME | FILE_NOTIFY_CHANGE_ATTRIBUTES | - FILE_NOTIFY_CHANGE_SIZE, &self->priv->buffer_filled_bytes, &self->priv->overlapped, g_win32_directory_monitor_callback); - /* Ignore errors */ - - return obj; +static GObject * +g_win32_directory_monitor_constructor (GType type, + guint n_construct_properties, + GObjectConstructParam *construct_properties) { + GObject *obj; + GWin32DirectoryMonitorClass *klass; + GObjectClass *parent_class; + GWin32DirectoryMonitor *self; + wchar_t *wdirname; + gboolean result; + + klass = G_WIN32_DIRECTORY_MONITOR_CLASS (g_type_class_peek (G_TYPE_WIN32_DIRECTORY_MONITOR)); + parent_class = G_OBJECT_CLASS (g_type_class_peek_parent (klass)); + obj = parent_class->constructor (type, n_construct_properties, construct_properties); + self = G_WIN32_DIRECTORY_MONITOR (obj); + wdirname = g_utf8_to_utf16 (G_LOCAL_DIRECTORY_MONITOR (obj)->dirname, -1, NULL, NULL, NULL); + + self->priv->hDirectory = CreateFileW (wdirname, + FILE_LIST_DIRECTORY, + FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE, + + NULL, + OPEN_EXISTING, + FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OVERLAPPED, + NULL); + g_free (wdirname); + if (self->priv->hDirectory == INVALID_HANDLE_VALUE) + { + /* Ignore errors */ + return obj; + } + + result = ReadDirectoryChangesW (self->priv->hDirectory, + (gpointer)self->priv->file_notify_buffer, + self->priv->buffer_allocated_bytes, + FALSE, + FILE_NOTIFY_CHANGE_FILE_NAME | + FILE_NOTIFY_CHANGE_DIR_NAME | + FILE_NOTIFY_CHANGE_ATTRIBUTES | + FILE_NOTIFY_CHANGE_SIZE, + &self->priv->buffer_filled_bytes, + &self->priv->overlapped, + g_win32_directory_monitor_callback); + /* Ignore errors */ + + return obj; } -static void g_win32_directory_monitor_class_init (GWin32DirectoryMonitorClass * klass) { - - g_win32_directory_monitor_parent_class = g_type_class_peek_parent (klass); +static void +g_win32_directory_monitor_class_init (GWin32DirectoryMonitorClass *klass) +{ + g_win32_directory_monitor_parent_class = g_type_class_peek_parent (klass); - G_OBJECT_CLASS (klass)->constructor = g_win32_directory_monitor_constructor; - G_OBJECT_CLASS (klass)->finalize = g_win32_directory_monitor_finalize; - G_FILE_MONITOR_CLASS (klass)->cancel = g_win32_directory_monitor_cancel; - - G_LOCAL_DIRECTORY_MONITOR_CLASS (klass)->mount_notify = FALSE; - G_LOCAL_DIRECTORY_MONITOR_CLASS (klass)->is_supported = g_win32_directory_monitor_is_supported; + G_OBJECT_CLASS (klass)->constructor = g_win32_directory_monitor_constructor; + G_OBJECT_CLASS (klass)->finalize = g_win32_directory_monitor_finalize; + G_FILE_MONITOR_CLASS (klass)->cancel = g_win32_directory_monitor_cancel; + + G_LOCAL_DIRECTORY_MONITOR_CLASS (klass)->mount_notify = FALSE; + G_LOCAL_DIRECTORY_MONITOR_CLASS (klass)->is_supported = g_win32_directory_monitor_is_supported; } -static void g_win32_directory_monitor_init (GWin32DirectoryMonitor * self) +static void +g_win32_directory_monitor_init (GWin32DirectoryMonitor *self) { - self->priv = (GWin32DirectoryMonitorPrivate*)g_new0 (GWin32DirectoryMonitorPrivate, 1); - g_assert (self->priv != 0); + self->priv = (GWin32DirectoryMonitorPrivate*)g_new0 (GWin32DirectoryMonitorPrivate, 1); + g_assert (self->priv != 0); - self->priv->buffer_allocated_bytes = 32768; - self->priv->file_notify_buffer = g_new0 (gchar, self->priv->buffer_allocated_bytes); - g_assert (self->priv->file_notify_buffer); + self->priv->buffer_allocated_bytes = 32768; + self->priv->file_notify_buffer = g_new0 (gchar, self->priv->buffer_allocated_bytes); + g_assert (self->priv->file_notify_buffer); - self->priv->self = G_FILE_MONITOR (self); + self->priv->self = G_FILE_MONITOR (self); } diff --git a/gio/win32/gwin32directorymonitor.h b/gio/win32/gwin32directorymonitor.h index fedc8f8..1504bd4 100644 --- a/gio/win32/gwin32directorymonitor.h +++ b/gio/win32/gwin32directorymonitor.h @@ -47,11 +47,11 @@ typedef struct _GWin32DirectoryMonitorClass GWin32DirectoryMonitorClass; typedef struct _GWin32DirectoryMonitorPrivate GWin32DirectoryMonitorPrivate; struct _GWin32DirectoryMonitor { - GLocalDirectoryMonitor parent_instance; - GWin32DirectoryMonitorPrivate * priv; + GLocalDirectoryMonitor parent_instance; + GWin32DirectoryMonitorPrivate * priv; }; struct _GWin32DirectoryMonitorClass { - GLocalDirectoryMonitorClass parent_class; + GLocalDirectoryMonitorClass parent_class; }; GType g_win32_directory_monitor_get_type (void); -- 2.7.4