Files
utun2/tools/chatgui-android/libutun_lite/instance_lite.h
T
evgeny f521bb37f4 fix(call): align audio frontend ownership with core lifecycle
Keep the borrowed audio provider on UTUN_INSTANCE across chat service restarts.
Attach and detach Android voice from the core worker and reject DSP startup
after detach. Preserve TX owner epochs, pending slots and foreign-instance RX
isolation. Remove the unused cross-thread online API and keep its check local
to call.c.

Add eight lifecycle regressions with real cores and the Android host bridge.
Audit public call, DSP, clock, headless and desktop audio contracts and record
the findings and validation scope.

Validation: voice/desktop 38/38, four native call suites, native and both Android
ABI builds, full check 204/204 plus proxy/burst/load. JVM results remain Gradle
UP-TO-DATE (155 app and 15 router). No hardware runtime validation.
2026-10-26 20:22:46 +01:00

69 lines
3.7 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 выключен по умолчанию; [gui] utun_enabled=yes включает его явно. Поток владеет instance/ua; UI передаёт работу через uasync.
* С UTUN_WITH_VOICE worker регистрирует call_audio до SERVICE_STARTED и снимает привязку перед уничтожением ядра.
* Полученные handles заимствованы и могут смениться при restart; сохранять их между рестартами нельзя.
*/
#ifndef INSTANCE_LITE_H
#define INSTANCE_LITE_H
#include <stdint.h>
#include <stddef.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 и дождаться потока; поток снимает media-привязки, уничтожает instance, затем uasync.
* Управляющий frontend предварительно останавливает аудио I/O и освобождает DSP звонка.
* Вызывать с управляющего потока при существующем 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);
/* Потокобезопасный JOIN: 0 — принят с request, <0 — отказ без события. */
int instance_lite_join_link(uint64_t request, const char* link, size_t len);
/* 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 */