Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 90 additions & 15 deletions Documentation/Plan.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ contracts. D-Bus is PureSwift/DBus, in Swift, without libdbus.
| arm64 and x86_64 Linux with glibc (Debian 13, Ubuntu 24.04+) | armv7, musl |
| Native slices, loaded by the runner | `App.wasm`, in an engine in the runner; wasm2c for a target a bundle lacks, before it's installed |
| Wayland and X11 through SDL3; a headless driver for tests | Multiple windows |
| `Renderer`, `BluetoothCentral` and friends, GL surfaces, web views, files, settings, model stores, date and number formatting, HTTP, the device, location, documents, the built-ins | Motion (iio-sensor-proxy), NFC (neard) |
| `Renderer`, `BluetoothCentral` and friends, GL surfaces, web views, files, settings, model stores, date and number formatting, HTTP, the device, location, documents, motion, the built-ins | NFC (neard) |

## 2. Process model

Expand Down Expand Up @@ -99,12 +99,13 @@ timers for `schedule`.
| `LinuxGraphics` | `Surface` over EGL and GLES 2.0, loaded at run time; the player's `GLSurface` view shows it (§7) |
| `LinuxWebKit` | `WebContent` over WPE WebKit, loaded at run time; the player's `WebView` view shows it (§8) |
| `LinuxCoreModel` | `LinuxModelStore`: the model store over CoreModel-SQLite, through AppRuntime's `HostModelStore` (§9) |
| `LinuxDevice` | `Device` from `/etc`, DMI, the device tree, and power and heat in sysfs (§10) |
| `LinuxDevice` | `Device` from `/etc`, DMI, the device tree, and power and heat in sysfs; orientation and proximity from iio-sensor-proxy (§10) |
| `LinuxDBus` | `Bus`: the system and session buses, for the modules that talk to system services: method calls, properties and signals by match rule, delivered on the main loop (§11.1) |
| `LinuxLocation` | `LocationManager`, `Location` and `Heading` over GeoClue 2 (§11) |
| `LinuxDocuments` | `Documents`: AppRuntime's `HostDocuments` with the desktop portal's file chooser, and bookmarks (§12) |
| `LinuxMotion` | `MotionManager` and `Altimeter` over the kernel's IIO sensors in sysfs, and an unavailable `Pedometer` and `ActivityRecognizer` (§13) |
| `LinuxHostApp` | `main`: reads the app's keys, starts the host, and runs Cacao's SDL loop with one window showing the guest's first renderer |
| `LinuxPackager`, `linux-app` | The packager (§14, [Packager.md](Packager.md)) |
| `LinuxPackager`, `linux-app` | The packager (§15, [Packager.md](Packager.md)) |

The package depends on AppRuntime without its `GuestExports` trait, like
DarwinAppRuntime, so the slice's `rt_dispatch` and `rt_finalize` are the
Expand Down Expand Up @@ -439,8 +440,17 @@ asked of D-Bus:
monitoring is on, low power and thermal state always.
- **Firmware placeholders** in DMI ("To be filled by O.E.M.", "Default
string") count as nothing.
- **Orientation and proximity** read as unknown and off: they come from
iio-sensor-proxy, with the motion contracts.
- **Orientation and proximity** are iio-sensor-proxy's
(`net.hadess.SensorProxy`, on the system bus). Enabling orientation
claims its accelerometer, if it has one, and `AccelerometerOrientation`
is the orientation: `normal` portrait (the device's natural
orientation), `bottom-up` upside down, `left-up` (the top to the right)
`landscapeRight`, `right-up` `landscapeLeft`; it has no face up or down.
Enabling proximity asks whether it has a sensor, waiting for the answer,
and claims it if so; `ProximityNear` is the state. Each change from
`PropertiesChanged` reaches the delegate once, and disabling releases
the sensor. Without iio-sensor-proxy, orientation reads as unknown and
proximity monitoring stays off.

## 11. Location

Expand Down Expand Up @@ -502,8 +512,9 @@ of its own, made when it first needs one:

### 11.1 D-Bus

`LinuxDBus` is what Bluetooth and Location, and later Motion
(iio-sensor-proxy), NFC (neard) and the desktop portal, share. `Bus.system`
`LinuxDBus` is what Bluetooth, Location, the device's orientation and
proximity (iio-sensor-proxy) and the desktop portal, and later NFC (neard),
share. `Bus.system`
and `Bus.session` are one connection each per process, made on first use
through PureSwift/DBus, which speaks D-Bus in Swift, without libdbus; its
values are `DBusMessageArgument`s, whose arrays and dictionaries carry
Expand Down Expand Up @@ -576,7 +587,61 @@ another, outside the app.
handle from xdg-foreign. The titles and the filter's name are English.
The photo picker is the file chooser for images and videos.

## 13. Testing
## 13. Motion

`LinuxMotion` is the Motion contracts (AppRuntime's `Motion.md`).
iio-sensor-proxy only says which way the screen is up, which is the
device's orientation (§10), so the samples come from the kernel's
Industrial I/O sensors themselves, read through sysfs
(`/sys/bus/iio/devices/iio:deviceN`), as iio-sensor-proxy reads the ones it
polls. Reading them needs no permission.

| Sensor | IIO channel | Contract |
|---|---|---|
| Accelerometer | `in_accel_{x,y,z}`, m/s² | as it is: face up, z ≈ +9.81 |
| Gyroscope | `in_anglvel_{x,y,z}`, rad/s | as it is |
| Magnetometer | `in_magn_{x,y,z}`, gauss | ×100, µT; accuracy `uncalibrated` |
| Device motion | the accelerometer and gyroscope | fused (below) |
| Barometer | `in_pressure`, kPa | `Altimeter` |

- **Sensors** are the first IIO device, by number, with each one's
channels. A channel's value is its `_input`, or `(_raw + offset) ×
scale`, its own scale and offset or its type's. Its mount matrix (the
type's `_mount_matrix`, or the device's `mount_matrix`) turns the
sensor's axes into the device's, which are the contract's: x to the
right, y toward the top, z out of the screen.
- **Samples** are polled off the main thread, since a driver may answer
over I²C, on one queue for every sensor, at the interval asked for: no
faster than 100 Hz, as on iOS, or than the sensor's fastest
`sampling_frequency_available`, which is `minimumInterval`. Each is
stamped with `CLOCK_BOOTTIME` as it's read, and posted to the main loop;
none arrives after `stop`. Each attribute's file stays open, and is read
again from its start.
- **Device motion** is a Mahony filter: it integrates the rotation rate and
pulls the attitude toward the gravity the accelerometer measures. It
starts level with the first reading, so its attitude has z vertical and
x where the device's x pointed, as Android's game rotation vector does;
nothing corrects drift around the vertical. Gravity is the vertical in
the device's axes, and user acceleration what's left without it.
- **Failing**: a sensor that isn't there fails at `start` with
`unavailable`. One that stops reading stops, `unavailable` once it's gone
and `unknown` otherwise. A driver streaming to its buffer, as one does
while iio-sensor-proxy has it claimed, may answer busy: those readings
are skipped.
- **The altimeter** reads the pressure once a second, as CoreMotion
delivers it, and the relative altitude is the standard atmosphere's from
the first reading, as Android's `SensorManager.getAltitude` computes it.
Nothing asks the user, as on Android: it's `authorized`, and `motion`
asks for nothing.
- **The pedometer and activity recognition** have nothing under them on
Linux. They're registered, so an app written for phones runs: not
available, `authorized`, and updates and queries fail with
`unavailable`.
- **Not yet**: an IIO device plugged in or out while a sensor runs isn't
noticed until it's started again, and the magnetometer isn't calibrated.
None of it has run on real sensors.

## 14. Testing

- `LinuxUI`: DarwinUI's tests, on Cacao (§5).
- `LinuxBluetooth`: the contract against a fake `BlueZBus` that plays
Expand All @@ -596,7 +661,17 @@ another, outside the app.
temporary root: identity, idioms, batteries (energy and capacity, a
mouse's left out, each status), thermal states, low power, the vendor
identifier kept per vendor, and changes reaching the delegate once each,
by themselves on the main loop.
by themselves on the main loop. Orientation and proximity against a fake
iio-sensor-proxy: claimed and released, each change once, turned off
before the proxy answered, and no sensor or no proxy.
- `LinuxMotion`: IIO devices' attributes under a temporary root: scaled
readings in the device's axes by the mount matrix, inputs, offsets and
units, the first device by number, the fastest sampling; the fusion
starting level with gravity, integrating a quarter turn, and following
gravity back; samples reaching the delegate on the main loop and none
after `stop`, a missing sensor, one that stops reading, the
magnetometer's accuracy; the altimeter's altitude, and no barometer; the
pedometer and activity recognizer unavailable; the module's contracts.
- `LinuxLocation`: the contract against a fake `GeoClueBus` that plays
GeoClue's manager, clients, agent and locations. Runs on macOS and Linux:
nothing asked until a client's needed; the client's desktop ID and
Expand Down Expand Up @@ -649,22 +724,22 @@ another, outside the app.
`bluetoothd`. Real GeoClue needs a session with an agent, or the app
allowed in `geoclue.conf`.

## 14. Phases
## 15. Phases

1. **Host runtime and player**: `LinuxHost`, `LinuxUI`, `LinuxBluetooth`,
`LinuxHostApp`; `ExampleUI` runs in Docker.
2. **Packager**: `linux-app` checks an app and installs it: its bundle
thinned to the target's `libapp.so`, a `.desktop` file and icon, for
the runner; later Flatpak and AppImage, whose manifests carry the
capabilities (`--system-talk-name=org.bluez` for `bluetooth`).
3. **More contracts**: Motion (iio-sensor-proxy), NFC (neard).
Formatting and HTTP are done: AppRuntime's `RuntimeFormatting` and
`RuntimeNetworking` (§3), and so are the device (§10), location
(§11), over GeoClue2, and documents (§12), over the desktop portal.
3. **More contracts**: NFC (neard). Formatting and HTTP are done:
AppRuntime's `RuntimeFormatting` and `RuntimeNetworking` (§3), and so
are the device (§10), location (§11), over GeoClue2, documents (§12),
over the desktop portal, and motion (§13), over IIO.
4. **Player**: what DarwinUI and Cacao add: Cacao's AT-SPI bridge, input
replay for end-to-end tests.

## 15. Open questions
## 16. Open questions

- **Permissions.** Desktop Linux has no prompts for Bluetooth; Flatpak's
portals cover location and the camera. `Permissions.request` answers from
Expand Down
23 changes: 18 additions & 5 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ let package = Package(
.library(name: "LinuxDevice", targets: ["LinuxDevice"]),
.library(name: "LinuxDBus", targets: ["LinuxDBus"]),
.library(name: "LinuxLocation", targets: ["LinuxLocation"]),
.library(name: "LinuxMotion", targets: ["LinuxMotion"]),
.library(name: "LinuxHostApp", targets: ["LinuxHostApp"]),
.executable(name: "linux-app-host", targets: ["LinuxAppHost"]),
.executable(name: "linux-app", targets: ["LinuxAppTool"]),
Expand Down Expand Up @@ -159,10 +160,10 @@ let package = Package(
// MARK: - Device

// The machine: /etc, DMI, the device tree, and power and heat in
// sysfs.
// sysfs; orientation and proximity from iio-sensor-proxy.
.target(
name: "LinuxDevice",
dependencies: ["LinuxHost", runtime("DynamicDevice"), runtime("DynamicRuntime")],
dependencies: ["LinuxHost", "LinuxDBus", runtime("DynamicDevice"), runtime("DynamicRuntime"), .product(name: "DBus", package: "DBus")],
swiftSettings: host
),

Expand Down Expand Up @@ -199,14 +200,24 @@ let package = Package(
swiftSettings: host
),

// MARK: - Motion

// The kernel's IIO sensors in sysfs: accelerometer, gyroscope,
// magnetometer and barometer.
.target(
name: "LinuxMotion",
dependencies: ["LinuxHost", runtime("DynamicMotion"), runtime("DynamicRuntime"), runtime("RuntimeHost")],
swiftSettings: host
),

// MARK: - App

// What the runner's process supplies that libc may not
// (arc4random_buf), and prctl, which Swift can't call.
.target(name: "CLinuxHost"),
.target(
name: "LinuxHostApp",
dependencies: ["LinuxHost", "LinuxUI", "LinuxBluetooth", "LinuxGraphics", "LinuxWebKit", "LinuxCoreModel", "LinuxDevice", "LinuxLocation", "LinuxDocuments", "CLinuxHost", runtime("CRuntime"), runtime("RuntimeFormatting"), runtime("RuntimeNetworking"),
dependencies: ["LinuxHost", "LinuxUI", "LinuxBluetooth", "LinuxGraphics", "LinuxWebKit", "LinuxCoreModel", "LinuxDevice", "LinuxLocation", "LinuxDocuments", "LinuxMotion", "CLinuxHost", runtime("CRuntime"), runtime("RuntimeFormatting"), runtime("RuntimeNetworking"),
runtime("DynamicGraphics"), .product(name: "CacaoSDL", package: "Cacao")],
swiftSettings: host
),
Expand All @@ -230,7 +241,7 @@ let package = Package(
// doesn't build Cacao.
.target(
name: "LinuxPackager",
dependencies: ["LinuxHost", "LinuxBluetooth", "LinuxGraphics", "LinuxWebKit", "LinuxCoreModel", "LinuxDevice", "LinuxLocation", "LinuxDocuments", runtime("RuntimeFormatting"), runtime("RuntimeNetworking"), runtime("DynamicUI"),
dependencies: ["LinuxHost", "LinuxBluetooth", "LinuxGraphics", "LinuxWebKit", "LinuxCoreModel", "LinuxDevice", "LinuxLocation", "LinuxDocuments", "LinuxMotion", runtime("RuntimeFormatting"), runtime("RuntimeNetworking"), runtime("DynamicUI"),
.product(name: "Crypto", package: "swift-crypto")]
),
.executableTarget(
Expand All @@ -255,14 +266,16 @@ let package = Package(
.product(name: "CoreModelSQLite", package: "CoreModel-SQLite")],
swiftSettings: host
),
.testTarget(name: "LinuxDeviceTests", dependencies: ["LinuxDevice", runtime("DynamicDevice")], swiftSettings: host),
.testTarget(name: "LinuxDeviceTests", dependencies: ["LinuxDevice", "LinuxDBus", runtime("DynamicDevice"), .product(name: "DBus", package: "DBus")],
swiftSettings: host),
.testTarget(name: "LinuxDBusTests", dependencies: ["LinuxDBus", .product(name: "DBus", package: "DBus")], swiftSettings: host),
.testTarget(name: "LinuxLocationTests", dependencies: ["LinuxLocation", "LinuxDBus", runtime("DynamicLocation"), .product(name: "DBus", package: "DBus")],
swiftSettings: host),
.testTarget(name: "LinuxDocumentsTests", dependencies: ["LinuxDocuments", "LinuxDBus", runtime("DynamicDocuments"), runtime("RuntimeDocuments"),
runtime("DynamicFiles"), runtime("RuntimeHost"), runtime("RuntimeNative"),
.product(name: "DBus", package: "DBus")],
swiftSettings: host),
.testTarget(name: "LinuxMotionTests", dependencies: ["LinuxMotion", runtime("DynamicMotion")], swiftSettings: host),
.testTarget(name: "LinuxWebKitTests", dependencies: ["LinuxWebKit", runtime("DynamicWebKit")], swiftSettings: host),
.testTarget(name: "LinuxPackagerTests", dependencies: ["LinuxPackager", "LinuxHostApp", runtime("RuntimeNetworking")]),
]
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,11 @@ added to its database between launches:
| `LinuxGraphics` | `Surface`: GLES 2.0 drawn in EGL pbuffers, loaded at run time, and read back into the player's `GLSurface` view ([plan](Documentation/Plan.md) §7) |
| `LinuxWebKit` | `WebContent`: WPE WebKit pages, loaded at run time, drawn into shared memory and shown by the player's `WebView` view ([plan](Documentation/Plan.md) §8) |
| `LinuxCoreModel` | `LinuxModelStore`: the app's CoreModel stores in SQLite, through AppRuntime's `HostModelStore` and CoreModel-SQLite ([plan](Documentation/Plan.md) §9) |
| `LinuxDevice` | `Device`: the machine, its battery, power mode and heat, from `/etc`, DMI, the device tree and sysfs ([plan](Documentation/Plan.md) §10) |
| `LinuxDevice` | `Device`: the machine, its battery, power mode and heat, from `/etc`, DMI, the device tree and sysfs, and its orientation and proximity from iio-sensor-proxy ([plan](Documentation/Plan.md) §10) |
| `LinuxDBus` | `Bus`: the system and session buses for the modules that talk to system services, over PureSwift/DBus, with calls, properties and signals delivered on the main loop ([plan](Documentation/Plan.md) §11.1) |
| `LinuxLocation` | `LocationManager`: the device's location from GeoClue 2 on the system bus, which its agent authorizes by the app's desktop ID; no heading ([plan](Documentation/Plan.md) §11) |
| `LinuxDocuments` | `Documents`: AppRuntime's `HostDocuments` with the desktop portal's file chooser on the session bus, for opening, folders and saving, and bookmarks in the app's data ([plan](Documentation/Plan.md) §12) |
| `LinuxMotion` | Motion: the accelerometer, gyroscope, magnetometer and barometer from the kernel's IIO sensors in sysfs, device motion fused from them, and a pedometer and activity recognizer that are unavailable ([plan](Documentation/Plan.md) §13) |
| `LinuxHostApp`, `linux-app-host` | The app's `main`: the host, and Cacao's window and loop. It also registers AppRuntime's `RuntimeFormatting`, dates and numbers over Swift Foundation, and `RuntimeNetworking`, HTTP over `URLSession` and libcurl ([plan](Documentation/Plan.md) §3) |
| `LinuxPackager`, `linux-app` | The packager: validation, thinning a bundle to one target, the install tree, PortMaster ports |

Expand Down
Loading
Loading