You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
117 lines
4.1 KiB
117 lines
4.1 KiB
/* |
|
* android_jni_bridge.h — JNI bridge API (C side) |
|
* |
|
* Provides lifecycle management and callbacks between C core and Kotlin. |
|
* For Android, compiled via NDK into libutun_lite.so. |
|
*/ |
|
#ifndef ANDROID_JNI_BRIDGE_H |
|
#define ANDROID_JNI_BRIDGE_H |
|
|
|
#include <stdint.h> |
|
#include <stddef.h> |
|
#include <stdbool.h> |
|
|
|
#ifdef __cplusplus |
|
extern "C" { |
|
#endif |
|
|
|
/* ── Callback types (C → Kotlin) ── */ |
|
|
|
typedef void (*utun_log_fn)(int level, const char* category, const char* message); |
|
|
|
typedef void (*utun_event_fn)(int event_type, const char* json_data); |
|
|
|
typedef const char* (*utun_config_string_fn)(const char* key); |
|
typedef int64_t (*utun_config_int64_fn)(const char* key); |
|
typedef int (*utun_config_int_fn)(const char* key); |
|
|
|
struct utun_bridge_config { |
|
utun_config_string_fn get_string; |
|
utun_config_int64_fn get_int64; |
|
utun_config_int_fn get_int; |
|
}; |
|
|
|
/* ── Initialize uTun core (legacy stub — use start for real init) ── */ |
|
|
|
bool utun_bridge_init(const char* db_path, int control_port, |
|
utun_log_fn on_log, |
|
utun_event_fn on_event, |
|
const struct utun_bridge_config* config); |
|
|
|
/* ── Start full uTun stack from INI config text ── */ |
|
int utun_bridge_start(const char* config_text); |
|
|
|
/* ── Shutdown uTun core ── */ |
|
void utun_bridge_destroy(void); |
|
|
|
/* ── Actions (Kotlin → C) ── */ |
|
|
|
void utun_bridge_send_message(const char* channel_id, const char* text); |
|
void utun_bridge_create_channel(const char* name, const char* channel_id); |
|
void utun_bridge_connect_node(const char* address, int port, const char* pubkey_hex); |
|
|
|
/* Join channel via invite link. |
|
addr_data format: family(1) + socketId(1) + address(4|16) + port(2 BE) per addr */ |
|
void utun_bridge_join_channel(uint64_t channel_id, uint64_t node_id, |
|
const uint8_t* pubkey_bin, |
|
const uint8_t* addrs_data, int addr_count); |
|
|
|
/* Connect to all peers of a channel (auto-connect on select) */ |
|
void utun_bridge_connect_channel(const char* channel_id); |
|
|
|
/* ── Queries ── */ |
|
|
|
char* utun_bridge_get_channels_json(void); |
|
char* utun_bridge_get_messages_json(const char* channel_id, int limit); |
|
uint64_t utun_bridge_get_my_node_id(void); |
|
|
|
/* ── Restart (config update, key regen, DB clear) ── */ |
|
|
|
void utun_bridge_restart(const char* config_text); |
|
|
|
/* ── Health check ── */ |
|
|
|
void utun_bridge_ping(void); |
|
int utun_bridge_is_responsive(void); |
|
|
|
/* ── Voice recording ── */ |
|
|
|
int utun_bridge_voice_start(const char* channel_id); |
|
int utun_bridge_voice_feed(const int16_t* samples, int count); |
|
int utun_bridge_voice_stop(int* out_duration_ms); |
|
void utun_bridge_voice_cancel(void); |
|
int utun_bridge_voice_is_active(void); |
|
void utun_bridge_voice_set_preset(int preset); |
|
int utun_bridge_voice_get_preset(void); |
|
void utun_bridge_voice_set_compressor(int enabled); |
|
int utun_bridge_voice_get_compressor(void); |
|
void utun_bridge_voice_set_compressor_config(int max_gain_db, int lookback_ms, int lookahead_ms, |
|
float rise_rate_per_sec, float target_level_db); |
|
float utun_bridge_voice_get_peak_level(void); |
|
|
|
/* ── Attachment ── */ |
|
|
|
int utun_bridge_attachment_send(const char* channel_id, const char* file_path, const char* db_path); |
|
int utun_bridge_attachment_download(const char* channel_id, int64_t msg_id); |
|
|
|
/* ── Voice playback (Opus decode) ── */ |
|
|
|
void* utun_bridge_voice_decode_open(const char* file_path, |
|
int* out_sample_rate, int* out_channels, |
|
int* out_total_samples); |
|
int utun_bridge_voice_decode_read(void* handle, int16_t* buf, int max_samples); |
|
void utun_bridge_voice_decode_close(void* handle); |
|
|
|
/* ── Debug ── */ |
|
|
|
void utun_bridge_set_debug_level(const char* category, const char* level); |
|
|
|
/* ── Chat settings ── */ |
|
|
|
void utun_bridge_chat_setting_set(const char* name, const char* value); |
|
int utun_bridge_chat_setting_get_int(const char* name, int def); |
|
|
|
#ifdef __cplusplus |
|
} |
|
#endif |
|
#endif /* ANDROID_JNI_BRIDGE_H */
|
|
|