refactor(WIP): replace event stubs with module identification logic

Replace the placeholder TODO logs in the polling loop with logic to
resolve filesystem events into specific module indices.

- Centralizing State: Refactored is_module_loaded to is_mod_loaded to
  check against the global stk_module_ids array, removing the need to
  pass local buffers and preparing for unified lifetime management.
- Standardizing Identity: Updated extract_module_id to use a
  consistent output buffer.
- Categorized Event Processing: Implemented a two-pass approach in
  stk_poll to count event types (LOAD, UNLOAD, RELOAD) and allocate
  tracking arrays, replacing the previous stubbed switch statement.
- Mapping Events to Indices: The poll loop now resolves filenames
  back to their specific loaded indices via is_mod_loaded to
  identify exactly which mod_id and index require action.
- Improved Flow Control: Introduced a finish_stk_poll label to
  ensure consistent cleanup and return values when no events are
  detected or processing is complete.
This commit is contained in:
2026-01-27 07:54:51 +01:00
parent c558032ea0
commit 9491b070d2
3 changed files with 52 additions and 39 deletions
+5 -4
View File
@@ -24,9 +24,9 @@
#include <unistd.h>
#endif
int is_module_loaded(const char *filename,
char (*loaded_ids)[STK_MOD_ID_BUFFER], size_t count);
int is_mod_loaded(const char *module_name);
uint8_t is_valid_module_file(const char *filename);
void extract_module_id(const char *path, char *out_id);
#ifdef _WIN32
static uint8_t is_file_ready(const char *dir_path, const char *filename)
@@ -629,8 +629,9 @@ stk_module_event_t *platform_directory_watch_check(
event_type = STK_MOD_UNLOAD;
if (e->mask & (IN_CLOSE_WRITE | IN_MOVED_TO)) {
if (is_module_loaded(e->name, loaded_ids,
loaded_count) >= 0)
char event_module_name[STK_MOD_ID_BUFFER];
extract_module_id(e->name, event_module_name);
if (is_mod_loaded(event_module_name) >= 0)
event_type = STK_MOD_RELOAD;
else
event_type = STK_MOD_LOAD;