Permalink
Browse files

Core file monitoring implementation. Squashed commit of the following:

commit f5dc91f
Author: Dmitry Matveev <me@dmitrymatveev.co.uk>
Date:   Sat Jun 4 22:32:52 2011 +0000

    Moved kqueue thread and its stuff to a separate file

commit bde25c4
Author: Dmitry Matveev <me@dmitrymatveev.co.uk>
Date:   Sat Jun 4 21:06:14 2011 +0000

    Finished the monitoring implementation. The following events are handled:
      G_FILE_MONITOR_EVENT_DELETED (via kqueue's NOTE_DELETE)
      G_FILE_MONITOR_EVENT_ATTRIBUTE_CHANGED (via kqueue's NOTE_ATTRIB)
      G_FILE_MONITOR_EVENT_CHANGED (via kqueue's NOTE_WRITE and NOTE_EXTEND)
      G_FILE_MONITOR_EVENT_MOVED (via kqueue's NOTE_RENAME)

commit c5bf30c
Author: Dmitry Matveev <me@dmitrymatveev.co.uk>
Date:   Sat Jun 4 14:33:36 2011 +0000

    Started work on the core of GKqueueFileMonitor and GKqueueDirectoryMonitor

commit 3cfb9cd
Author: Dmitry Matveev <me@dmitrymatveev.co.uk>
Date:   Fri Jun 3 00:58:18 2011 +0000

    Work on kqueue helper
  • Loading branch information...
1 parent 9c8335c commit 8863323ce25ecaa33bbc285a20cf319be2c9c5a7 @dmatveev committed Jun 4, 2011
View
@@ -9,6 +9,12 @@ libkqueue_la_SOURCES = \
gkqueuefilemonitor.h \
gkqueuedirectorymonitor.c \
gkqueuedirectorymonitor.h \
+ kqueue-helper.c \
+ kqueue-helper.h \
+ kqueue-thread.c \
+ kqueue-thread.h \
+ kqueue-sub.c \
+ kqueue-sub.h \
$(NULL)
libkqueue_la_CFLAGS = \
@@ -1,11 +1,16 @@
#include "config.h"
#include "gkqueuedirectorymonitor.h"
+#include "kqueue-helper.h"
#include <gio/giomodule.h>
+#include <assert.h>
struct _GKqueueDirectoryMonitor
{
GLocalDirectoryMonitor parent_instance;
+ gchar *filename;
+ kqueue_sub *sub;
+ gboolean pair_moves;
};
static gboolean g_kqueue_directory_monitor_cancel (GFileMonitor *monitor);
@@ -21,6 +26,20 @@ static void
g_kqueue_directory_monitor_finalize (GObject *object)
{
GKqueueDirectoryMonitor *kqueue_monitor = G_KQUEUE_DIRECTORY_MONITOR (object);
+ kqueue_sub *sub = kqueue_monitor->sub;
+
+ if (sub)
+ {
+ /* TODO: cancel the subscription here */
+ _kh_sub_free (sub);
+ kqueue_monitor->sub = NULL;
+ }
+
+ if (kqueue_monitor->filename)
+ {
+ g_free (kqueue_monitor->filename);
+ kqueue_monitor->filename = NULL;
+ }
if (G_OBJECT_CLASS (g_kqueue_directory_monitor_parent_class)->finalize)
(*G_OBJECT_CLASS (g_kqueue_directory_monitor_parent_class)->finalize) (object);
@@ -35,6 +54,8 @@ g_kqueue_directory_monitor_constructor (GType type,
GKqueueDirectoryMonitorClass *klass;
GObjectClass *parent_class;
GKqueueDirectoryMonitor *kqueue_monitor;
+ kqueue_sub *sub = NULL;
+ gboolean ret_kh_startup;
klass = G_KQUEUE_DIRECTORY_MONITOR_CLASS (g_type_class_peek (G_TYPE_KQUEUE_DIRECTORY_MONITOR));
parent_class = G_OBJECT_CLASS (g_type_class_peek_parent (klass));
@@ -43,14 +64,31 @@ g_kqueue_directory_monitor_constructor (GType type,
construct_properties);
kqueue_monitor = G_KQUEUE_DIRECTORY_MONITOR (obj);
+ kqueue_monitor->filename = g_strdup (G_LOCAL_DIRECTORY_MONITOR (obj)->dirname);
+
+ ret_kh_startup = _kh_startup();
+ assert (ret_kh_startup);
+
+ /* TODO: pair moves. */
+ sub = _kh_sub_new (kqueue_monitor->filename,
+ FALSE,
+ kqueue_monitor);
+
+ /* FIXME: what to do about errors here? we can't return NULL or another
+ * kind of error and an assertion is probably too hard (same issue as in
+ * the inotify backend) */
+ g_assert (sub != NULL);
+
+ _kh_add_sub (sub);
+ kqueue_monitor->sub = sub;
return obj;
}
static gboolean
g_kqueue_directory_monitor_is_supported (void)
{
- return TRUE; /* TODO kqueue startup here */
+ return _kh_startup();
}
static void
@@ -78,6 +116,8 @@ g_kqueue_directory_monitor_cancel (GFileMonitor *monitor)
{
GKqueueDirectoryMonitor *kqueue_monitor = G_KQUEUE_DIRECTORY_MONITOR (monitor);
+ /* TODO: Implementation */
+
if (G_FILE_MONITOR_CLASS (g_kqueue_directory_monitor_parent_class)->cancel)
(*G_FILE_MONITOR_CLASS (g_kqueue_directory_monitor_parent_class)->cancel) (monitor);
}
@@ -7,10 +7,10 @@
G_BEGIN_DECLS
-#define G_TYPE_KQUEUE_DIRECTORY_MONITOR (_g_kqueue_directory_monitor_get_type ())
-#define G_KQUEUE_DIRECTORY_MONITOR(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), G_TYPE_KQUEUE_DIRECTORY_MONITOR, GKqueueDirectoryMonitor))
-#define G_KQUEUE_DIRECTORY_MONITOR_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), G_TYPE_KQUEUE_DIRECTORY_MONITOR, GKqueueDirectoryMonitorClass))
-#define G_IS_KQUEUE_DIRECTORY_MONITOR(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), G_TYPE_KQUEUE_DIRECTORY_MONITOR))
+#define G_TYPE_KQUEUE_DIRECTORY_MONITOR (_g_kqueue_directory_monitor_get_type ())
+#define G_KQUEUE_DIRECTORY_MONITOR(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), G_TYPE_KQUEUE_DIRECTORY_MONITOR, GKqueueDirectoryMonitor))
+#define G_KQUEUE_DIRECTORY_MONITOR_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), G_TYPE_KQUEUE_DIRECTORY_MONITOR, GKqueueDirectoryMonitorClass))
+#define G_IS_KQUEUE_DIRECTORY_MONITOR(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), G_TYPE_KQUEUE_DIRECTORY_MONITOR))
#define G_IS_KQUEUE_DIRECTORY_MONITOR_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), G_TYPE_KQUEUE_DIRECTORY_MONITOR))
typedef struct _GKqueueDirectoryMonitor GKqueueDirectoryMonitor;
@@ -1,11 +1,20 @@
#include "config.h"
#include "gkqueuefilemonitor.h"
+#include "kqueue-helper.h"
#include <gio/giomodule.h>
+#include <assert.h>
+/* TODO: This code is also written as in the inotify backend, but wait.
+ * kqueue_sub already contains `filename' and `pair_moves' fields. Do
+ * we need it in the `GKqueueFileMonitor', since we already have a `sub'
+ * field? Probably I will drop it. */
struct _GKqueueFileMonitor
{
GLocalFileMonitor parent_instance;
+ gchar *filename;
+ kqueue_sub *sub;
+ gboolean pair_moves;
};
static gboolean g_kqueue_file_monitor_cancel (GFileMonitor* monitor);
@@ -21,6 +30,20 @@ static void
g_kqueue_file_monitor_finalize (GObject *object)
{
GKqueueFileMonitor *kqueue_monitor = G_KQUEUE_FILE_MONITOR (object);
+ kqueue_sub *sub = kqueue_monitor->sub;
@jmmv

jmmv Jun 27, 2011

Is it there any specific reason for this auxiliary variable? You risk reusing sub after you have NULLified it.

I would just get rid of it. There does not seem to be any advantage for this: the code is not more readable, and there won't be any runtime differences. Also, you are accessing kqueue_monitor->filename anyway without an auxiliary variable, so consistency would be good.

@dmatveev

dmatveev Jul 3, 2011

Owner

I have used the inotify plugin as a starting point, and this code is almost 1-to-1 clone from that sources :)

Really, it is unnecessary, removed at 911cb2a

+
+ if (sub)
+ {
+ /* TODO: cancel the subscription here */
+ _kh_sub_free (sub);
+ kqueue_monitor->sub = NULL;
+ }
+
+ if (kqueue_monitor->filename)
+ {
+ g_free (kqueue_monitor->filename);
+ kqueue_monitor->filename = NULL;
+ }
if (G_OBJECT_CLASS (g_kqueue_file_monitor_parent_class)->finalize)
(*G_OBJECT_CLASS (g_kqueue_file_monitor_parent_class)->finalize) (object);
@@ -35,6 +58,8 @@ g_kqueue_file_monitor_constructor (GType type,
GKqueueFileMonitorClass *klass;
GObjectClass *parent_class;
GKqueueFileMonitor *kqueue_monitor;
+ kqueue_sub *sub = NULL;
+ gboolean ret_kh_startup;
klass = G_KQUEUE_FILE_MONITOR_CLASS (g_type_class_peek (G_TYPE_KQUEUE_FILE_MONITOR));
parent_class = G_OBJECT_CLASS (g_type_class_peek_parent (klass));
@@ -43,14 +68,31 @@ g_kqueue_file_monitor_constructor (GType type,
construct_properties);
kqueue_monitor = G_KQUEUE_FILE_MONITOR (obj);
+ kqueue_monitor->filename = g_strdup (G_LOCAL_FILE_MONITOR (obj)->filename);
+
+ ret_kh_startup = _kh_startup();
+ assert (ret_kh_startup);
+
+ /* TODO: pair moves. */
+ sub = _kh_sub_new (kqueue_monitor->filename,
+ FALSE,
+ kqueue_monitor);
+
+ /* FIXME: what to do about errors here? we can't return NULL or another
+ * kind of error and an assertion is probably too hard (same issue as in
+ * the inotify backend) */
+ g_assert (sub != NULL);
+
+ _kh_add_sub (sub);
+ kqueue_monitor->sub = sub;
return obj;
}
static gboolean
g_kqueue_file_monitor_is_supported (void)
{
- return TRUE; /* todo: kqueue startup code here */
+ return _kh_startup();
}
static void
@@ -77,6 +119,8 @@ g_kqueue_file_monitor_cancel (GFileMonitor *monitor)
{
GKqueueFileMonitor *kqueue_monitor = G_KQUEUE_FILE_MONITOR (monitor);
+ /* TODO: Implementation */
+
if (G_FILE_MONITOR_CLASS (g_kqueue_file_monitor_parent_class)->cancel)
(*G_FILE_MONITOR_CLASS (g_kqueue_file_monitor_parent_class)->cancel) (monitor);
Oops, something went wrong.

0 comments on commit 8863323

Please sign in to comment.