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.
72 lines
2.2 KiB
72 lines
2.2 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 ── */ |
|
|
|
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); |
|
|
|
/* ── Shutdown uTun core ── */ |
|
void utun_bridge_destroy(void); |
|
|
|
/* ── Background poll (alternative to running uasync loop) ── */ |
|
/* Called from main/uasync thread periodically to process */ |
|
void utun_bridge_poll(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); |
|
|
|
/* ── Queries ── */ |
|
|
|
char* utun_bridge_get_channels_json(void); |
|
char* utun_bridge_get_messages_json(const char* channel_id, int limit); |
|
|
|
/* ── Debug ── */ |
|
|
|
void utun_bridge_set_debug_level(const char* category, const char* level); |
|
|
|
#ifdef __cplusplus |
|
} |
|
#endif |
|
#endif /* ANDROID_JNI_BRIDGE_H */
|
|
|