file-monitor.h 2.41 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
/* See LICENSE file for license and copyright information */

#ifndef FILEMONITOR_H
#define FILEMONITOR_H

#include <stdbool.h>
#include <girara/types.h>
#include <glib-object.h>

#define ZATHURA_TYPE_FILEMONITOR (zathura_filemonitor_get_type())
#define ZATHURA_FILEMONITOR(obj)                                               \
  (G_TYPE_CHECK_INSTANCE_CAST((obj), ZATHURA_TYPE_FILEMONITOR,                 \
                              ZathuraFileMonitor))
#define ZATHURA_FILEMONITOR_CLASS(obj)                                         \
  (G_TYPE_CHECK_CLASS_CAST((obj), ZATHURA_TYPE_FILEMONITOR,                    \
                           ZathuraFileMonitorClass))
#define ZATHURA_IS_FILEMONITOR(obj)                                            \
  (G_TYPE_CHECK_INSTANCE_TYPE((obj), ZATHURA_TYPE_FILEMONITOR))
#define ZATHURA_IS_FILEMONITOR_CLASS(obj)                                      \
  (G_TYPE_CHECK_CLASS_TYPE((obj), ZATHURA_TYPE_FILEMONITOR))
#define ZATHURA_FILEMONITOR_GET_CLASS(obj)                                     \
  (G_TYPE_INSTANCE_GET_CLASS((obj), ZATHURA_TYPE_FILEMONITOR,                  \
                             ZathuraFileMonitorClass))

typedef struct zathura_filemonitor_s       ZathuraFileMonitor;
typedef struct zathura_filemonitor_class_s ZathuraFileMonitorClass;

/**
 * Base class for all file monitors.
 *
 * The signal 'reload-file' is emitted if the monitored file changed.
 */
struct zathura_filemonitor_s
{
  GObject parent;
};

struct zathura_filemonitor_class_s
{
  GObjectClass parent_class;

  void (*start)(ZathuraFileMonitor*);
  void (*stop)(ZathuraFileMonitor*);
};

/**
 * Get the type of the filemonitor.
 *
 * @return the type
 */
51
GType zathura_filemonitor_get_type(void) G_GNUC_CONST;
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76

/**
 * Type of file monitor.
 */
typedef enum zathura_filemonitor_type_e {
  ZATHURA_FILEMONITOR_GLIB, /**< Use filemonitor from GLib */
  ZATHURA_FILEMONITOR_SIGNAL /**< Reload when receiving SIGHUP */
} zathura_filemonitor_type_t;

/**
 * Create a new file monitor.
 *
 * @param file_path file to monitor
 * @param filemonitor_type type of file monitor
 * @return new file monitor instance
 */
ZathuraFileMonitor*
zathura_filemonitor_new(const char*                file_path,
                        zathura_filemonitor_type_t filemonitor_type);

/**
 * Get path of the monitored file.
 *
 * @return path of monitored file
 */
Sebastian Ramacher's avatar
Sebastian Ramacher committed
77
const char* zathura_filemonitor_get_filepath(ZathuraFileMonitor* file_monitor);
78 79

#endif