From 928aab913be06640eeb9d051946e65d0813c9abc Mon Sep 17 00:00:00 2001 From: Sebastian Ramacher Date: Mon, 17 Sep 2018 22:57:25 +0200 Subject: [PATCH] Implement noop file monitor --- meson.build | 1 + zathura/file-monitor-noop.c | 50 +++++++++++++++++++++++++++++++++++++ zathura/file-monitor-noop.h | 33 ++++++++++++++++++++++++ zathura/file-monitor.c | 6 +++++ zathura/file-monitor.h | 3 ++- 5 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 zathura/file-monitor-noop.c create mode 100644 zathura/file-monitor-noop.h diff --git a/meson.build b/meson.build index d118e8a..b3ee82f 100644 --- a/meson.build +++ b/meson.build @@ -131,6 +131,7 @@ sources = files( 'zathura/document.c', 'zathura/file-monitor.c', 'zathura/file-monitor-glib.c', + 'zathura/file-monitor-noop.c', 'zathura/file-monitor-signal.c', 'zathura/jumplist.c', 'zathura/links.c', diff --git a/zathura/file-monitor-noop.c b/zathura/file-monitor-noop.c new file mode 100644 index 0000000..82e108d --- /dev/null +++ b/zathura/file-monitor-noop.c @@ -0,0 +1,50 @@ +/* See LICENSE file for license and copyright information */ + +#include "file-monitor-noop.h" + +#include +#ifdef G_OS_UNIX +#include +#endif + +struct zathura_noopfilemonitor_s +{ + ZathuraFileMonitor parent; +}; + +G_DEFINE_TYPE(ZathuraNoopFileMonitor, zathura_noopfilemonitor, + ZATHURA_TYPE_FILEMONITOR) + +static void +start(ZathuraFileMonitor* GIRARA_UNUSED(file_monitor)) +{ +} + +static void +stop(ZathuraFileMonitor* GIRARA_UNUSED(file_monitor)) +{ +} + +static void +zathura_noopfilemonitor_finalize(GObject* object) +{ + stop(ZATHURA_FILEMONITOR(object)); + + G_OBJECT_CLASS(zathura_noopfilemonitor_parent_class)->finalize(object); +} + +static void +zathura_noopfilemonitor_class_init(ZathuraNoopFileMonitorClass* class) +{ + ZathuraFileMonitorClass* filemonitor_class = ZATHURA_FILEMONITOR_CLASS(class); + filemonitor_class->start = start; + filemonitor_class->stop = stop; + + GObjectClass* object_class = G_OBJECT_CLASS(class); + object_class->finalize = zathura_noopfilemonitor_finalize; +} + +static void +zathura_noopfilemonitor_init(ZathuraNoopFileMonitor* GIRARA_UNUSED(noopfilemonitor)) +{ +} diff --git a/zathura/file-monitor-noop.h b/zathura/file-monitor-noop.h new file mode 100644 index 0000000..86cdf65 --- /dev/null +++ b/zathura/file-monitor-noop.h @@ -0,0 +1,33 @@ +/* See LICENSE file for license and copyright information */ + +#ifndef FILEMONITOR_NOOP_H +#define FILEMONITOR_NOOP_H + +#include "file-monitor.h" + +#define ZATHURA_TYPE_NOOPFILEMONITOR (zathura_noopfilemonitor_get_type()) +#define ZATHURA_NOOPFILEMONITOR(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST((obj), ZATHURA_TYPE_NOOPFILEMONITOR, \ + ZathuraNoopFileMonitor)) +#define ZATHURA_NOOPFILEMONITOR_CLASS(obj) \ + (G_TYPE_CHECK_CLASS_CAST((obj), ZATHURA_TYPE_NOOPFILEMONITOR, \ + ZathuraNoopFileMonitorClass)) +#define ZATHURA_IS_NOOPFILEMONITOR(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE((obj), ZATHURA_TYPE_NOOPFILEMONITOR)) +#define ZATHURA_IS_NOOPFILEMONITOR_CLASS(obj) \ + (G_TYPE_CHECK_CLASS_TYPE((obj), ZATHURA_TYPE_NOOPFILEMONITOR)) +#define ZATHURA_NOOPFILEMONITOR_GET_CLASS(obj) \ + (G_TYPE_INSTANCE_GET_CLASS((obj), ZATHURA_TYPE_NOOPFILEMONITOR, \ + ZathuraNoopFileMonitorClass)) + +typedef struct zathura_noopfilemonitor_s ZathuraNoopFileMonitor; +typedef struct zathura_noopfilemonitor_class_s ZathuraNoopFileMonitorClass; + +struct zathura_noopfilemonitor_class_s +{ + ZathuraFileMonitorClass parent_class; +}; + +GType zathura_noopfilemonitor_get_type(void) G_GNUC_CONST; + +#endif diff --git a/zathura/file-monitor.c b/zathura/file-monitor.c index e14c673..a11f05b 100644 --- a/zathura/file-monitor.c +++ b/zathura/file-monitor.c @@ -5,6 +5,7 @@ #ifdef G_OS_UNIX #include "file-monitor-signal.h" #endif +#include "file-monitor-noop.h" #include "macros.h" #include @@ -141,6 +142,11 @@ zathura_filemonitor_new(const char* file_path, NULL); break; #endif + case ZATHURA_FILEMONITOR_NOOP: + girara_debug("using noop file monitor"); + ret = g_object_new(ZATHURA_TYPE_NOOPFILEMONITOR, "file-path", file_path, + NULL); + break; default: girara_debug("invalid filemonitor type: %d", filemonitor_type); g_return_val_if_fail(false, NULL); diff --git a/zathura/file-monitor.h b/zathura/file-monitor.h index 1c056bc..0cd8cfc 100644 --- a/zathura/file-monitor.h +++ b/zathura/file-monitor.h @@ -55,7 +55,8 @@ GType zathura_filemonitor_get_type(void) G_GNUC_CONST; */ typedef enum zathura_filemonitor_type_e { ZATHURA_FILEMONITOR_GLIB, /**< Use filemonitor from GLib */ - ZATHURA_FILEMONITOR_SIGNAL /**< Reload when receiving SIGHUP */ + ZATHURA_FILEMONITOR_SIGNAL, /**< Reload when receiving SIGHUP */ + ZATHURA_FILEMONITOR_NOOP /**< Monitor that does nothing */ } zathura_filemonitor_type_t; /**