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

@@ -158,6 +158,31 @@ static void on_standalone(
(int)name_len, name);
}
static const char *scale_name(uint8_t s)
{
switch (s) {
case 0: return "stretch";
case 1: return "fit";
case 2: return "fill";
case 3: return "1:1";
default: return "?";
}
}
static 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 *ud)
{
(void)ud;
printf(" display stream=%u pos=%d,%d size=%ux%u scale=%s anchor=%s\n",
stream_id, win_x, win_y, win_w, win_h,
scale_name(scale),
anchor == 0 ? "center" : "topleft");
}
static void on_control(
uint32_t id, uint8_t type, uint32_t flags,
const char *name, uint8_t name_len,
@@ -208,7 +233,7 @@ static void on_frame(struct Transport_Conn *conn,
struct Proto_Response_Header hdr;
struct App_Error e = proto_read_enum_devices_response(
frame->payload, frame->payload_length, &hdr,
on_media_device, on_video_node, on_standalone, NULL);
on_media_device, on_video_node, on_standalone, on_display, NULL);
if (!APP_IS_OK(e)) { app_error_print(&e); }
else if (hdr.status != PROTO_STATUS_OK) {
fprintf(stderr, "ENUM_DEVICES: status=%u\n", hdr.status);
@@ -452,6 +477,9 @@ static struct Transport_Conn *do_connect(struct Ctrl_State *cs,
struct Transport_Conn *old_conn)
{
if (old_conn) { transport_conn_close(old_conn); }
/* Reset state — drain stale semaphore posts from the old connection */
cs->pending_cmd = 0;
while (sem_trywait(&cs->sem) == 0) { /* drain */ }
struct Transport_Conn *conn;
struct App_Error e = transport_connect(&conn, host, port,
TRANSPORT_DEFAULT_MAX_PAYLOAD, on_frame, on_disconnect, cs);