feat(core): 新增上行事件队列与 msgType=9 会话配置帧
- demo_server 增加 inbound 队列,mirror 应答与上行剪贴板入队供界面轮询(上限 64,丢最旧) - 新增 peek_inbound_event / pop_inbound_event,FFI 暴露 ttstd_event_next(缓冲不足时不出队) - 协议新增 MSG_CONFIG=9:payload 为 UTF-8 JSON,binary 编解码与 ffi 下发均已支持 - 补充 Config 事件编解码单测
This commit is contained in:
1 parent
cbbc2a642d
commit
e43e51d9c3
4 files changed
+154
-5
No files matched your search
@@ -301,6 +301,7 @@ pub unsafe extern "C" fn ttstd_control_decode(
|
||||
ControlEventKind::Wheel(_) => "wheel",
|
||||
ControlEventKind::Clipboard(_) => "clipboard",
|
||||
ControlEventKind::Mirror(_) => "mirror",
|
||||
ControlEventKind::Config(_) => "config",
|
||||
};
|
||||
let json = format!(
|
||||
"{{\"sequence\":{},\"msgType\":{},\"kind\":\"{}\"}}",
|
||||
@@ -313,6 +314,7 @@ pub unsafe extern "C" fn ttstd_control_decode(
|
||||
|
||||
/// 向当前被控端下发控制帧。payload 为各事件类型的二进制负载。
|
||||
/// msg_type: 0=touch 1=mouse 2=key 3=wheel 4=clipboard(UTF-8) 5=ping(u64 LE)
|
||||
/// 8=mirror([action:u8]+文本) 9=sessionConfig(UTF-8 JSON)
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn ttstd_demo_send_control(
|
||||
sequence: u16,
|
||||
@@ -365,6 +367,11 @@ pub unsafe extern "C" fn ttstd_demo_send_control(
|
||||
bytes[0],
|
||||
String::from_utf8_lossy(&bytes[1..]).to_string(),
|
||||
)),
|
||||
// 9 = 会话配置:payload 就是 UTF-8 JSON
|
||||
9 => Some(crate::demo_server::config_event(
|
||||
sequence,
|
||||
String::from_utf8_lossy(bytes).to_string(),
|
||||
)),
|
||||
_ => None,
|
||||
};
|
||||
match event {
|
||||
@@ -398,6 +405,26 @@ pub unsafe extern "C" fn ttstd_demo_status(out_json: *mut u8, capacity: usize) -
|
||||
copy_out(json.as_bytes(), out_json, capacity)
|
||||
}
|
||||
|
||||
/// 取出一个待处理的上行控制事件 JSON:`{"type":8,"action":2,"text":"..."}`。
|
||||
///
|
||||
/// - 返回正数:写入 `out_json` 的字节数,事件已出队。
|
||||
/// - 返回 `0`:队列为空。
|
||||
/// - 返回 [`ERR_BUFFER_TOO_SMALL`]:容量不足,事件**保留**在队列中。
|
||||
///
|
||||
/// # Safety
|
||||
/// out_json 可写且容量为 capacity。
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn ttstd_event_next(out_json: *mut u8, capacity: usize) -> i32 {
|
||||
let Some(json) = crate::demo_server::peek_inbound_event() else {
|
||||
return 0;
|
||||
};
|
||||
let written = copy_out(json.as_bytes(), out_json, capacity);
|
||||
if written >= 0 {
|
||||
crate::demo_server::pop_inbound_event();
|
||||
}
|
||||
written
|
||||
}
|
||||
|
||||
/// 视频访问单元元信息。字段布局需与 Windows 原生解码侧保持一致。
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Clone, Copy, Default)]
|
||||
|
||||
Reference in new issue
Block a user