make filewatcher more robust
This commit is contained in:
@@ -1,27 +1,25 @@
|
||||
#ifndef HI_FILEWATCHER_H_
|
||||
#define HI_FILEWATCHER_H_
|
||||
|
||||
#include "filewatch_type.h"
|
||||
#include "types.h"
|
||||
|
||||
/**
|
||||
* File event watching related functionality and types
|
||||
* File event watcher using inotify.
|
||||
*/
|
||||
|
||||
typedef enum {
|
||||
HI_FILE_NONE = 0,
|
||||
HI_FILE_ACCESS = 1 << 0,
|
||||
HI_FILE_MODIFY = 1 << 1,
|
||||
HI_FILE_CREATE = 1 << 2,
|
||||
HI_FILE_DELETE = 1 << 3,
|
||||
HI_FILE_ALL =
|
||||
(HI_FILE_ACCESS | HI_FILE_MODIFY | HI_FILE_CREATE | HI_FILE_DELETE)
|
||||
} HiFileEventType;
|
||||
|
||||
/**
|
||||
* File Event produced by FileWatcher.
|
||||
*
|
||||
* As long as the event queue is cleared before making modifications to the File
|
||||
* Watcher, pointers are safe to use and don't need freeing, as they refer to
|
||||
* memory inside the file watcher struct.
|
||||
*/
|
||||
typedef struct {
|
||||
const char *watcher; // Path given to the corresponding wd. Not owning.
|
||||
const char *file; // Owning, should be freed by the event handler by calling
|
||||
// `hi_file_event_destroy`)
|
||||
HiFileEventType type;
|
||||
const char *pathname; // Pathname given with the `hi_file_watcher_add` call.
|
||||
// Do not free.
|
||||
HiFileWatchType type;
|
||||
} hiFileEvent;
|
||||
|
||||
struct hiFileWatcher;
|
||||
@@ -60,18 +58,10 @@ HiloadResult hi_file_watcher_add(struct hiFileWatcher *context,
|
||||
*/
|
||||
void hi_file_watcher_notify(struct hiFileWatcher *context);
|
||||
|
||||
/**
|
||||
* Frees held memory but doesn't zero fields
|
||||
*/
|
||||
void hi_file_event_free(hiFileEvent *event);
|
||||
/**
|
||||
* Pop an event from event stack. Call `hi_file_event_destroy` when done with
|
||||
* it.
|
||||
*/
|
||||
hiFileEvent hi_file_event_pop(struct hiFileWatcher *ctx);
|
||||
/**
|
||||
* Free and zero held memory. Call after pop.
|
||||
*/
|
||||
void hi_file_event_destroy(hiFileEvent *event);
|
||||
|
||||
#endif // HI_FILEWATCHER_H_
|
||||
|
||||
Reference in New Issue
Block a user