Files
hiload/src/filewatcher/filewatcher.h

70 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.
*
* Paths are stored as absolute, and this doesn't handle symlinks in watched
* files. So if you have e.g. a symlink 'my-proj' to your project folder in
* '/workspace/code/my-proj' paths might exist from either side and they are
* not interpreted as equal.
*/
/**
* 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 {
/** Path of the file this event is about. Do not free. */
const char *pathname;
/** Might not be only those given to @a file_watcher_add. */
FileWatchType type;
} FileEvent;
typedef struct FileWatcher FileWatcher;
/**
* FileEvents is a thread safe list of events.
*
* Events will be popped mostly in reverse chronological order, but strict
* chronology is not guaranteed.
*/
typedef struct FileEvents FileEvents;
/**
* Create watcher and necessary data to run it.
*
* Starts a new watcher thread immediately.
*/
FileWatcher *file_watcher_create(void);
/**
* Destroy a previously created file watcher.
*
* Will join the thread and destroy event stack. Any FileEvent still in
* existence will contain invalid data after this call.
*/
void file_watcher_destroy(FileWatcher *fw);
/**
* Start watching for events on a file.
*
* @param fw The watcher instance
* @param pathname Absolute path to the file or directory
* @param flags The event mask for the events to watch for
*/
HiResult file_watcher_add(FileWatcher *fw, const char *pathname, u32 flags);
/**
* Pop an event from event stack.
*/
FileEvent file_event_pop(FileWatcher *ctx);
#endif // HI_FILEWATCHER_H_