MCPcopy Create free account
hub / github.com/OpenImageDebugger/OpenImageDebugger / IpcClient

Class IpcClient

src/host/ipc/ipc_client.h:49–125  ·  view source on GitHub ↗

Qt-free port of the window-side of the Qt MessageHandler: decodes inbound messages (SetAvailableSymbols, GetObservedSymbols, PlotBufferContents, PlotBufferBegin/Chunk/End) into the IpcBufferModel + symbol list, and sends outbound requests (PlotBufferRequest, BufferRemoved). The transport is injected as oid::ITransport& so this is unit-testable against a fake transport with no live socket.

Source from the content-addressed store, hash-verified

47// is injected as oid::ITransport& so this is unit-testable against a fake
48// transport with no live socket.
49class IpcClient {
50 public:
51 IpcClient(oid::ITransport& transport, IpcBufferModel& model);
52
53 // Drains all currently-available inbound messages into the model /
54 // symbol list. Called once per frame. Never blocks the caller beyond
55 // the transport's own bounded reads; catches std::runtime_error
56 // (SocketTimeoutError) if a message header/body isn't fully available
57 // yet.
58 void poll();
59
60 // Outbound (from the chrome):
61 void request_plot(const std::string& variable_name); // PlotBufferRequest
62 void notify_removed(const std::string& variable_name); // BufferRemoved
63
64 // Sends SessionStateChanged (type 7): a single JSON string, verbatim
65 // (no parsing/validation here -- the caller owns the JSON shape).
66 void send_session_state_changed(const std::string& json);
67
68 // Sends ExportBufferRequest (type 5): variable name, export format, and
69 // an 8-entry contrast vector. Mirrors the Qt sender
70 // (MessageHandler::request_export_buffer): entries beyond `contrast`'s
71 // size are padded with 0.0f, and only the first 8 entries of `contrast`
72 // are sent (extras ignored), matching the wire's fixed 8-float layout.
73 void send_export_buffer_request(const std::string& variable_name,
74 int format,
75 const std::vector<float>& contrast);
76
77 // Registers the callback invoked when an inbound ApplySessionState
78 // (type 6) message is decoded; called with the JSON string verbatim.
79 // Not required to be set: if unset, the message is still fully
80 // consumed from the transport (so the stream isn't left desynced) and
81 // silently dropped.
82 void
83 set_session_state_callback(std::function<void(const std::string& json)> cb);
84
85 // Registers the callback invoked when an inbound ExportSelectedBuffer
86 // (type 8) message is decoded. ExportSelectedBuffer carries no payload
87 // (mirrors the Qt side, which just emits exportSelectedBufferRequested()
88 // with no arguments). Not required to be set.
89 void set_export_selected_callback(std::function<void()> cb);
90
91 // Latest available-symbols list (from SetAvailableSymbols); UiState
92 // reads it.
93 [[nodiscard]] const std::vector<std::string>& available_symbols() const;
94
95 // Seed the previous-session buffers to auto-restore. On the next
96 // SetAvailableSymbols, each entry that is available, not already loaded,
97 // not expired (now < expiry) is re-requested via request_plot.
98 // Idempotent.
99 void set_restore_buffers(std::vector<oid::host::PreviousBuffer> buffers);
100
101 private:
102 void dispatch(oid::MessageType header);
103
104 // Per-message-type handlers: each decodes (or applies) exactly one
105 // oid::MessageType and fully consumes its wire payload.
106 void handle_set_available_symbols();

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected