Fix connect accumulation; add display sinks to enum-devices

- controller_cli: drain semaphore and reset pending_cmd in do_connect
  so stale posts from old connection don't unblock the next command
- protocol: add Proto_Display_Device_Info; extend
  proto_write_enum_devices_response and proto_read_enum_devices_response
  with display section; backward-compatible (absent in older messages)
- node: handle_enum_devices snapshots active Display_Slots under mutex
  and includes them in the response
- controller_cli: on_display callback prints display window info in
  enum-devices output
- query_cli: updated to pass NULL on_display (no display interest)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-29 19:48:22 +00:00
parent 961933e714
commit 835cbbafba
5 changed files with 120 additions and 5 deletions

View File

@@ -51,6 +51,14 @@ static struct App_Error wbuf_u16(struct Wbuf *b, uint16_t v) {
return APP_OK;
}
static struct App_Error wbuf_i16(struct Wbuf *b, int16_t v) {
struct App_Error e = wbuf_grow(b, 2);
if (!APP_IS_OK(e)) { return e; }
put_i16(b->data, b->len, v);
b->len += 2;
return APP_OK;
}
static struct App_Error wbuf_u32(struct Wbuf *b, uint32_t v) {
struct App_Error e = wbuf_grow(b, 4);
if (!APP_IS_OK(e)) { return e; }
@@ -366,7 +374,8 @@ struct App_Error proto_write_get_control_response(struct Transport_Conn *conn,
struct App_Error proto_write_enum_devices_response(struct Transport_Conn *conn,
uint16_t request_id, uint16_t status,
const struct Proto_Media_Device_Info *media_devices, uint16_t media_count,
const struct Proto_Standalone_Device_Info *standalone, uint16_t standalone_count)
const struct Proto_Standalone_Device_Info *standalone, uint16_t standalone_count,
const struct Proto_Display_Device_Info *displays, uint16_t display_count)
{
struct Wbuf b;
struct App_Error e = wbuf_init(&b, 128);
@@ -402,6 +411,18 @@ struct App_Error proto_write_enum_devices_response(struct Transport_Conn *conn,
e = wbuf_str8(&b, standalone[i].name); if (!APP_IS_OK(e)) { goto fail; }
}
e = wbuf_u16(&b, display_count); if (!APP_IS_OK(e)) { goto fail; }
for (uint16_t i = 0; i < display_count; i++) {
const struct Proto_Display_Device_Info *d = &displays[i];
e = wbuf_u16(&b, d->stream_id); if (!APP_IS_OK(e)) { goto fail; }
e = wbuf_i16(&b, d->win_x); if (!APP_IS_OK(e)) { goto fail; }
e = wbuf_i16(&b, d->win_y); if (!APP_IS_OK(e)) { goto fail; }
e = wbuf_u16(&b, d->win_w); if (!APP_IS_OK(e)) { goto fail; }
e = wbuf_u16(&b, d->win_h); if (!APP_IS_OK(e)) { goto fail; }
e = wbuf_u8 (&b, d->scale); if (!APP_IS_OK(e)) { goto fail; }
e = wbuf_u8 (&b, d->anchor); if (!APP_IS_OK(e)) { goto fail; }
}
e = transport_send_frame(conn, PROTO_MSG_CONTROL_RESPONSE, b.data, b.len);
fail:
wbuf_free(&b);
@@ -705,6 +726,12 @@ struct App_Error proto_read_enum_devices_response(
const char *path, uint8_t path_len,
const char *name, uint8_t name_len,
void *userdata),
void (*on_display)(
uint16_t stream_id,
int16_t win_x, int16_t win_y,
uint16_t win_w, uint16_t win_h,
uint8_t scale, uint8_t anchor,
void *userdata),
void *userdata)
{
struct Cursor c;
@@ -759,6 +786,26 @@ struct App_Error proto_read_enum_devices_response(
if (on_standalone) { on_standalone(path, path_len, name, name_len, userdata); }
}
/* Display section — optional; absent in messages from older nodes */
if (c.ok && c.pos + 2 <= c.len) {
uint16_t display_count = cur_u16(&c);
CUR_CHECK(c);
for (uint16_t i = 0; i < display_count; i++) {
uint16_t stream_id = cur_u16(&c);
int16_t win_x = (int16_t)cur_u16(&c);
int16_t win_y = (int16_t)cur_u16(&c);
uint16_t win_w = cur_u16(&c);
uint16_t win_h = cur_u16(&c);
uint8_t scale = cur_u8(&c);
uint8_t anchor = cur_u8(&c);
CUR_CHECK(c);
if (on_display) {
on_display(stream_id, win_x, win_y,
win_w, win_h, scale, anchor, userdata);
}
}
}
return APP_OK;
}