An interface in QML
A QML document can be an interface client. The C++ family's interface library has a binding to QML,
the module Yoke.Interface: a document instantiates an Attachment to a channel, reads what the channel
sees as properties, issues every operation as a call that returns at once and answers later, and follows
subscriptions and streams as signals. It is the same contract a client in any language speaks, spelled in
QML's terms, and it is how a desktop shell or a kiosk written in QML reaches an application.
| In the library | In QML |
|---|---|
| attaching, and the opening picture | an Attachment, its status, attached, picture and records |
read, command, ask, startStream, stopStream, confirm | methods returning the call's number; answered and refused, or the functions passed |
| a subscription | a Subscription, its snapshot, received and overflow signals |
| a stream's delivery | a Delivery, its frame signal: sequence, sentAt, payload as bytes |
| the channel yielding to another | suspended, and suspension: grade, by, reason |
Building the binding
The binding is built with the family, where it is asked for, against Qt 6.4 or newer; built without it, the family is the same and nothing of it links Qt.
curl -fsSLO https://github.com/yoke-project/yoke-sdk-cpp/releases/download/v0.11.0/yoke-sdk-cpp-0.11.0-source.tar.gz
tar -xzf yoke-sdk-cpp-0.11.0-source.tar.gz
cmake -S yoke-sdk-cpp-0.11.0 -B yoke-sdk-cpp-build -DCMAKE_BUILD_TYPE=Release \
-DYOKE_SDK_CPP_TESTING=OFF -DYOKE_SDK_CPP_QML=ON
cmake --build yoke-sdk-cpp-build -j
cmake --install yoke-sdk-cpp-build --prefix ~/.local
The module is installed under lib/qt6/qml of the prefix: that directory is the import path a
document is run with. A C++ program that loads documents finds it with
find_package(yoke-sdk-cpp COMPONENTS qml), which sets YOKE_SDK_CPP_QML_IMPORT_PATH.
A document
This document attaches to the channel desktop of an instance, follows hw-monitor's CPU stream, and
shows the present without a gap. A subscription to a stream is given what flows next and nothing of
what is, so the document subscribes first, starts the stream, and only then asks the unit for its
present; the frames that arrive meanwhile are held, and those at or below the sequence the answer states
are dropped as already in it.
import QtQuick
import QtQuick.Window
import Yoke.Interface
Window {
id: panel
width: 320; height: 120; visible: true
property var held: []
property var applied: -1
property real cpu: NaN
function show(value) {
if (value.sequence <= applied) return
applied = value.sequence
cpu = value.aggregate_usage_percent
}
Attachment {
id: yoke
instance: "desktop-1"
channel: "desktop"
attachAgain: true
}
Delivery {
attachment: yoke
unit: "hw-monitor"
stream: "hw.cpu"
onOpenChanged: {
if (!open) return
panel.held = []; panel.applied = -1
yoke.startStream("hw-monitor", "hw.cpu")
yoke.ask("hw-monitor", "hw.snapshot", "", answer => {
const now = JSON.parse(yoke.text(answer)).cpu
if (now) panel.show(now)
for (const v of panel.held) panel.show(v)
panel.held = null
})
}
onFrame: frame => {
const value = JSON.parse(yoke.text(frame.payload))
if (panel.held !== null) panel.held.push(value)
else panel.show(value)
}
}
Text {
anchors.centerIn: parent
color: yoke.suspended ? "gray" : "black"
text: !yoke.attached ? "not attached"
: yoke.suspended ? "held by " + yoke.suspension.by
: "CPU " + (isNaN(panel.cpu) ? "—" : panel.cpu.toFixed(1) + " %")
}
}
qml -I ~/.local/lib/qt6/qml panel.qml
A payload is bytes, and the document decodes it: the binding never reads a unit's payload.
yoke.text(bytes) reads bytes as UTF-8 for a payload the document knows is text.
When the Core is away
An attachment the Core ended reads Ended, with its failure, and a call that was waiting is
answered as refused, never sent again. With attachAgain set, the binding attaches again once the
channel's socket is made again — it is told by the host, and tries nothing at an interval — and the
document is given a new opening: its picture replaced, and every Subscription and Delivery opened
again as a new one, so the document above joins the present again from the start. With attachAgain
unset, an attachment that ended stays ended. A channel reached at an address is not watched.
When another channel prevails
A channel that yields to another under arbitration says so as a property, not as a failed call:
suspended holds, and suspension says what the channel keeps — read-only or dark — which channel
prevails, and why. It is read from the channel's own record and its events; the binding asks nothing to
learn it (arbitration).