Files
utun2/tools/chatgui-android/libutun_lite/instance_lite.h
T
evgeny a97e8bcc1f docs: update file inventory and module header contracts
Refresh both AGENTS guides and clarify module purpose, usage, ownership, threading, return values and wire formats in headers. Remove the unused timeout_heap freed_count field and unimplemented getter.
2026-10-04 13:10:01 +02:00

64 lines
3.1 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/*
* Android-владелец одного ядра: INI из Kotlin → pthread с uasync → core_start + chat_service_start.
* UTUN-сервис не запускается. Поток владеет instance/ua; UI передаёт работу через uasync.
* Полученные handles заимствованы и могут смениться при restart; сохранять их между рестартами нельзя.
*/
#ifndef INSTANCE_LITE_H
#define INSTANCE_LITE_H
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
struct UASYNC;
struct UTUN_INSTANCE;
/* Копирует INI и запускает поток. 0 = поток создан либо уже запущен, -1 = ошибка запуска.
* Готовность самого ядра появляется позже: проверять is_running и события инициализации. */
int instance_lite_start(const char* config_text);
/* Сигнализировать stop и дождаться потока; поток уничтожает instance, затем uasync.
* Вызывать с управляющего потока при существующем instance, не из callback ядра. */
void instance_lite_stop(void);
/* Returns non-zero if instance is running. */
int instance_lite_is_running(void);
/* Get current uasync handle (NULL if not running). */
struct UASYNC* instance_lite_get_uasync(void);
/* Get current UTUN_INSTANCE handle (NULL if not running). */
struct UTUN_INSTANCE* instance_lite_get_instance(void);
/* Set Kotlin callback for chat events (CONNECT_RESULT, MSG_RECEIVED, ...) */
typedef void (*instance_lite_event_fn)(int type, const uint8_t* data, int len);
void instance_lite_set_event_handler(instance_lite_event_fn handler);
/* Regenerate X25519 keys in the worker thread. Saves to keys.conf file.
* Call from any thread. Keys are regenerated asynchronously. */
void instance_lite_regenerate_keys(void);
/* Копирует INI, будит poll-loop и пересоздаёт instance и uasync внутри worker.
* Если ядро не работает, выполняет stop/start. Обновление асинхронное; старые handles утрачивают силу. */
void instance_lite_restart(const char* new_config_text);
/* Лёгкое обновление сокетов (auto_sockets=android): перечитывает [server] секции
* из нового конфига и сверяет сокеты без полного рестарта. Posts to uasync thread.
* Если ядро не запущено — только логирует ошибку и дропает вызов. */
void instance_lite_update_sockets(const char* config_text);
/* Health check: posts a ping to uasync, returns responsiveness after delay */
void instance_lite_ping(void);
int instance_lite_is_responsive(void);
/* Connection monitor: post collect_conn_list/conn_metrics to uasync thread */
void instance_lite_collect_conn_list(void);
void instance_lite_collect_conn_metrics(uint64_t peer_node_id);
#ifdef __cplusplus
}
#endif
#endif /* INSTANCE_LITE_H */