/* * 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); /* 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 */