An interface client
An interface client is anything that reaches an application from outside it — a panel, a browser's back end, a command-line tool — and it reaches it through a channel the description declares. It speaks the interface contract, and nothing it holds gives it administrative reach.
| A managed interface | An attached client | |
|---|---|---|
| started by | the Core, as a unit of kind interface | whoever runs it |
| finds its channel | in YOKE_SOCKET, which the Core hands it | from the instance's name and the channel's |
| example | a device's own panel | the tool on this page |
Both attach the same way and are arbitrated the same way (attaching, arbitration).
The program
The Go family's interface library is the package iface of the module
github.com/yoke-project/yoke-sdk-go, the same module a Plugin in Go uses. This client asks one unit one
question, so it serves for both Plugins of the example.
mkdir ask && cd ask
go mod init example.com/ask
go get github.com/yoke-project/yoke-sdk-go@latest
// Command ask is an interface client: it attaches to a channel of a running instance, asks one unit one
// question, and prints the answer.
package main
import (
"context"
"fmt"
"os"
"time"
"github.com/yoke-project/yoke-sdk-go/iface"
)
func main() {
if len(os.Args) != 5 && len(os.Args) != 6 {
fmt.Fprintln(os.Stderr, "usage: ask <instance> <channel> <unit> <question> [<payload>]")
os.Exit(2)
}
instance, channel, unit, question := os.Args[1], os.Args[2], os.Args[3], os.Args[4]
var payload []byte
if len(os.Args) == 6 {
payload = []byte(os.Args[5])
}
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
// In an application instance a channel's socket derives from the instance's name.
address, err := iface.Application(instance, channel, os.Getenv)
if err != nil {
fmt.Fprintln(os.Stderr, "ask:", err)
os.Exit(1)
}
a, err := iface.Attach(ctx, address)
if err != nil {
fmt.Fprintln(os.Stderr, "ask:", err)
os.Exit(1)
}
defer a.Close()
answer, err := a.Ask(ctx, unit, question, payload)
if err != nil {
fmt.Fprintln(os.Stderr, "ask:", err)
os.Exit(1)
}
fmt.Println(string(answer))
}
go mod tidy
CGO_ENABLED=0 go build -o ask .
| Call | What it does |
|---|---|
iface.Application | the channel's socket in an application instance; iface.Service is the service form's, iface.Managed a managed interface's |
iface.Attach | attaches, and waits for the opening: what the channel may address and observe — attaching |
a.Ask | asks a unit a question and returns its answer; Command, Read, Subscribe and the stream calls are the other operations — the operations |
a.Close | ends the attachment in order |
The library never retries and never reconnects: an attachment that ended has ended, and a client that wants another attaches again (the interface library).
The channel it attaches to
A channel is declared in the description, with its transport and how many clients it holds at once.
This client needs one on the local socket, local; a browser would need http+ws
(channels, the projections).
The project declared one, cli, and running it attaches this client to it:
./ask <instance> cli clock clock.now.
In another language
| Family | A client imports |
|---|---|
| Go | iface, in github.com/yoke-project/yoke-sdk-go |
| Rust | yoke_sdk::interface |
| Python | yoke_sdk.interface |
| C | yoke/interface.h |
| C++ | yoke/interface.hpp |
yoke-reference holds clients written with four of them: a terminal client in Rust and in Python, and
an instrument's panel in C++ with Qt and in C with LVGL.