/* * TinyBlocks - tb_api.h * Library tinyblocks-api: gestor publico de modulos/libraries e "cola" entre * plugins (.so), libraries registradas e o registro de tipos do runtime. * * Responsabilidades: * - carregar/descarregar/recarregar plugins .so (dlopen + tb_library_register) * - adotar libraries embutidas (registradas estaticamente no runtime) * - hot reload por mtime * - introspeccao: enumerar modulos e tipos de bloco disponiveis * * NAO desenha UI: quem desenha e o editor. */ #ifndef TINYBLOCKS_API_H #define TINYBLOCKS_API_H #include #include #include #ifdef __cplusplus extern "C" { #endif #define TB_API_MAX_MODULES 64 #define TB_API_PATH_LEN 512 /* Um modulo/library conhecido pelo processo (embutido ou .so dinamico). */ typedef struct TbApiModule { char name[64]; /* nome da library (desc->name) */ char version[32]; char path[TB_API_PATH_LEN]; /* .so de origem; "" se embutido */ void* handle; /* dlopen; NULL se embutido */ TinyBlocks_LibraryBlock* lib; const TinyBlocks_Category* category; /* pode ser NULL */ unsigned block_count; time_t mtime; /* mtime do .so (hot reload) */ } TbApiModule; /* -- Ciclo de vida --- */ TB_API bool tb_api_init(TinyBlocks* rt); TB_API void tb_api_shutdown(void); TB_API TinyBlocks* tb_api_runtime(void); TB_API const char* tb_api_last_error(void); /* -- Registro de modulos --- */ /* Adota as libraries ja registradas no runtime (embutidas). Retorna o total. */ TB_API int tb_api_adopt_all(void); TB_API int tb_api_module_count(void); TB_API const TbApiModule* tb_api_module(int i); TB_API const TbApiModule* tb_api_module_find(const char* name); /* -- Carregamento dinamico --- */ /* Carrega um .so; retorna o indice (>=0) ou -1 (erro em tb_api_last_error). */ TB_API int tb_api_load(const char* path); TB_API bool tb_api_unload(int idx); TB_API bool tb_api_reload(int idx); TB_API bool tb_api_is_loaded(const char* name); /* -- Modulos de codigo (bundle de um app, ex: libraries privadas do editor) * Nao registram libraries/blocos: sao so codigo (.so) carregado por dlopen. * Usados para HOT RELOAD: recompile a parte que mudou e o app recarrega. --- */ #define TB_API_MAX_CODE 32 TB_API int tb_api_code_load(const char* name, const char* path); /* idx ou -1 */ TB_API bool tb_api_code_unload(const char* name); TB_API void tb_api_code_unload_all(void); TB_API int tb_api_code_count(void); TB_API const char* tb_api_code_name(int i); TB_API const char* tb_api_code_path(int i); TB_API void* tb_api_code_handle(const char* name); TB_API void* tb_api_code_symbol(const char* name, const char* symbol); /* Recarrega TODOS os modulos de codigo na ordem de carga (unload inverso, * load direto) - resolve dependencias entre eles. Retorna quantos voltaram. */ TB_API int tb_api_code_reload_all(void); /* true se algum modulo de codigo mudou no disco (usa watcher/mtime). */ TB_API bool tb_api_code_changed(void); /* -- Watcher de arquivos (inotify quando disponivel, senao mtime) --- */ TB_API bool tb_api_watch(const char* path); TB_API int tb_api_poll_watch(void); /* eventos pendentes (0 = nada) */ /* Hot reload: true se algum .so mudou no disco desde o ultimo load. */ TB_API bool tb_api_any_changed(void); /* Recarrega os .so que mudaram; retorna quantos. */ TB_API int tb_api_poll_reload(void); /* -- Introspeccao de tipos de bloco (API publica) --- */ TB_API int tb_api_type_count(void); TB_API const TinyBlocks_TypeBlock* tb_api_type(int i); TB_API const TinyBlocks_TypeBlock* tb_api_type_find(const char* name); #ifdef __cplusplus } #endif #endif /* TINYBLOCKS_API_H */