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.
64 lines
3.1 KiB
64 lines
3.1 KiB
#ifndef GUI_BRIDGE_H |
|
#define GUI_BRIDGE_H |
|
|
|
#ifdef __cplusplus |
|
extern "C" { |
|
#endif |
|
|
|
#include <stdint.h> |
|
#include <stddef.h> |
|
|
|
struct UASYNC; |
|
|
|
/* ── Операции uasync→GUI (chat_sync запрашивает работу с БД) ── */ |
|
|
|
#define GUI_OP_LIST_CHANNELS 0 /* → массив: [count:2][ch_id_len:1][ch_id:var][name_len:2][name:var]... */ |
|
#define GUI_OP_COUNT 1 /* req: [ch_id_len:1][ch_id:var] → resp: uint32 count (4 байта) */ |
|
#define GUI_OP_CHAIN_HASH_AT 2 /* req: [ch_id_len:1][ch_id:var][pos:4] → resp: 32 байта chain_hash */ |
|
#define GUI_OP_INSERT_RECORD 3 /* req: [ch_id_len:1][ch_id:var][record:var] → resp: 0=ok, 1=dup, -1=err (1 байт) */ |
|
#define GUI_OP_CURSOR_OPEN 4 /* req: [ch_id_len:1][ch_id:var] → resp: uint32 cursor_id (4 байта) */ |
|
#define GUI_OP_CURSOR_NEXT 5 /* req: cursor_id (4 байта) → resp: record или 0 байт = EOF */ |
|
#define GUI_OP_CURSOR_CLOSE 6 /* req: cursor_id (4 байта) → resp: 0 байт */ |
|
#define GUI_OP_MARK_SENT 7 /* req: [ch_id_len:1][ch_id:var][ts:8][dh:8][my_node_id:8] → resp: 0 байт */ |
|
#define GUI_OP_TTL_DELETE 8 /* req: [ch_id_len:1][ch_id:var][my_node_id:8][cutoff:8] → resp: 0 байт */ |
|
#define GUI_OP_LIST_PEERS 9 /* req: [ch_id_len:1][ch_id:var] → resp: [count:2][node_id:8]... */ |
|
#define GUI_OP_LOAD_NODEINFO 10 /* req: node_id (8 байт) → resp: nodeinfo или 0 байт если нет */ |
|
|
|
/* ── Типы уведомлений uasync→GUI (fire-and-forget) ── */ |
|
|
|
#define GUI_EVT_MSG_RECEIVED 1 /* data: [ch_id_len:1][ch_id:var][record:var] */ |
|
#define GUI_EVT_CONNECT_RESULT 2 /* data: [node_id:8][result:4] */ |
|
#define GUI_EVT_NEW_PEER 3 /* data: [node_id:8] */ |
|
#define GUI_EVT_CHANNEL_UPDATED 4 /* data: [ch_id_len:1][ch_id:var] */ |
|
|
|
/* ── Callback-типы ── */ |
|
|
|
typedef void (*gui_result_fn)(void* userdata, int op, |
|
const uint8_t* result, int result_len); |
|
|
|
/* ── API ── */ |
|
|
|
/* Регистрация (вызывается из GUI при старте) */ |
|
void gui_bridge_init(struct UASYNC* ua, gui_result_fn callback, void* gui_target); |
|
|
|
/* Установить указатель на DbManager (до первого вызова gui_bridge_call) */ |
|
void gui_bridge_set_db(void* db_ptr); |
|
|
|
/* uasync → GUI: запросить SQL-операцию */ |
|
void gui_bridge_call(int op, const uint8_t* request, int req_len, |
|
void* userdata, gui_result_fn callback); |
|
|
|
/* uasync → GUI: уведомление (fire-and-forget, callback не вызывается) */ |
|
void gui_bridge_post(int event_type, const uint8_t* data, int data_len); |
|
|
|
/* GUI → uasync: выполнить функцию в uasync-потоке */ |
|
void gui_bridge_post_uasync(struct UASYNC* ua, void (*fn)(void*), void* arg); |
|
|
|
/* Callback for connect results (called from GUI thread) */ |
|
typedef void (*gui_connect_result_fn)(uint64_t node_id, int result); |
|
void gui_bridge_set_connect_result_cb(gui_connect_result_fn cb); |
|
|
|
#ifdef __cplusplus |
|
} |
|
#endif |
|
#endif /* GUI_BRIDGE_H */
|
|
|