Remove hi_ prefixes from internal code. Add documentation.

This commit is contained in:
2025-05-02 01:42:58 +03:00
parent fc9cdb5885
commit c6c1435f8a
15 changed files with 2943 additions and 174 deletions

View File

@@ -22,6 +22,9 @@
sc_array_def(FileEvent, fwevent);
typedef struct sc_array_fwevent VectorFileEvent;
/**
* All context and state required to run a file watcher.
*/
typedef struct FileWatcher {
thrd_t thread;
mtx_t mutex;
@@ -31,10 +34,10 @@ typedef struct FileWatcher {
VectorFileEvent events;
} FileWatcher;
/*
* Watch Params
*/
static inline WatchParams watch_params_create(const char *path, u32 mask) {
return (WatchParams){.path = strdup(path), .mask = mask};
}
@@ -46,7 +49,7 @@ static inline void watch_params_destroy(WatchParams *params) {
static WatchParams *watch_params_find_by_path(const char *path,
FileWatcherContext *ctx,
size_t *index) {
const struct sc_array_fwparam *params = &ctx->params;
const VectorWatchParams *params = &ctx->params;
for (size_t i = 0; i < sc_array_size(params); ++i) {
WatchParams *param = &sc_array_at(params, i);
if (strcmp(path, param->path) == 0) {
@@ -140,7 +143,7 @@ static FileEvent file_event_create(const struct inotify_event *inevent,
return NULL_EVENT;
}
FileEvent hi_file_event_pop(FileWatcher *fw) {
FileEvent file_event_pop(FileWatcher *fw) {
mtx_lock(&fw->mutex);
FileEvent e = NULL_EVENT;
@@ -178,7 +181,7 @@ static void file_watcher_ctx_destroy(FileWatcherContext *ctx) {
// Declare the thread func
int file_watcher_watch(void *arg);
FileWatcher *hi_file_watcher_create() {
FileWatcher *file_watcher_create() {
// Allocate context
FileWatcher *fw = malloc(sizeof(FileWatcher));
@@ -204,7 +207,7 @@ FileWatcher *hi_file_watcher_create() {
return NULL;
}
HiResult hi_file_watcher_add(FileWatcher *fw, const char *filename, u32 flags) {
HiResult file_watcher_add(FileWatcher *fw, const char *filename, u32 flags) {
if (!fw) {
sc_log_error("Attempted to add file watcher for '%s' with null context\n",
filename);
@@ -257,19 +260,19 @@ HiResult hi_file_watcher_remove(FileWatcher *fw, const char *filename) {
return HI_OK;
}
void hi_file_watcher_notify(FileWatcher *fw) {
void file_watcher_notify(FileWatcher *fw) {
if (fw && fw->running) {
cnd_signal(&fw->cond);
}
}
void hi_file_watcher_destroy(FileWatcher *fw) {
void file_watcher_destroy(FileWatcher *fw) {
if (!fw)
return;
if (fw->running) {
fw->running = false;
hi_file_watcher_notify(fw);
file_watcher_notify(fw);
thrd_join(fw->thread, NULL);
}