68 lines
1.8 KiB
C
68 lines
1.8 KiB
C
#ifndef HI_FILEWATCHER_H_
|
|
#define HI_FILEWATCHER_H_
|
|
|
|
#include "filewatch_type.h"
|
|
#include "types.h"
|
|
|
|
/**
|
|
* File event watcher using inotify.
|
|
*/
|
|
|
|
|
|
/**
|
|
* 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 *pathname; // Pathname given with the `hi_file_watcher_add` call.
|
|
// Do not free.
|
|
HiFileWatchType type;
|
|
} hiFileEvent;
|
|
|
|
struct hiFileWatcher;
|
|
/**
|
|
* FileEvents is a thread safe list of events.
|
|
*
|
|
* It is implemented as a stack, so the events will be popped
|
|
* in reverse chronological order.
|
|
* */
|
|
struct hiFileEvents;
|
|
|
|
/**
|
|
* Create watcher and necessary data to run it.
|
|
*
|
|
* Will start the watcher thread immediately.
|
|
*/
|
|
struct hiFileWatcher *hi_file_watcher_create(void);
|
|
/**
|
|
* Destroy a previously created file watcher context.
|
|
*
|
|
* Will join the thread and destroy event stack.
|
|
*/
|
|
void hi_file_watcher_destroy(struct hiFileWatcher *context);
|
|
/**
|
|
* Add a file to the watch list of a file watcher.
|
|
*
|
|
* @param context Previously created watcher context
|
|
* @param pathname Absolute path to the file or directory
|
|
* @param flags The events that will be watched for
|
|
*/
|
|
HiloadResult hi_file_watcher_add(struct hiFileWatcher *context,
|
|
const char *pathname, u32 flags);
|
|
/**
|
|
* Can be used to poke file watcher thread to make sure it empties
|
|
* events before doing something, e.g. for shutting it down.
|
|
*/
|
|
void hi_file_watcher_notify(struct hiFileWatcher *context);
|
|
|
|
/**
|
|
* Pop an event from event stack. Call `hi_file_event_destroy` when done with
|
|
* it.
|
|
*/
|
|
hiFileEvent hi_file_event_pop(struct hiFileWatcher *ctx);
|
|
|
|
#endif // HI_FILEWATCHER_H_
|