morph 0.1.0
Asynchronous bridge between GUI thread and business models
Loading...
Searching...
No Matches
service_client.hpp File Reference

The client side of the UI service (spec 5 §12, "Content addressing"): UiClient runs ui-hello, ui-catalog and ui-fetch over a transport the caller supplies, verifies every file against the manifest and the manifest against the ui-hello digest, and keeps what it verified in a VerifiedCache. More...

#include <algorithm>
#include <cstddef>
#include <exception>
#include <expected>
#include <functional>
#include <map>
#include <memory>
#include <mutex>
#include <optional>
#include <stdexcept>
#include <string>
#include <string_view>
#include <utility>
#include <vector>
#include "../attributes.hpp"
#include "../core/completion.hpp"
#include "../core/envelope_transport.hpp"
#include "../core/executor.hpp"
#include "../core/logger.hpp"
#include "../core/wire.hpp"
#include "../session/session.hpp"
#include "../ui/frontend.hpp"
#include "bundle.hpp"
#include "file_store.hpp"
#include "theme.hpp"

Go to the source code of this file.

Classes

class  morph::ui::IBundleStore
 Where a client keeps verified files between runs, by content hash, and the digest of each application's last verified bundle. More...
class  morph::ui::MemoryBundleStore
 An IBundleStore in memory: it lasts as long as the process. Safe to call from any thread. More...
class  morph::ui::VerifiedCache
 A content-addressed cache that hands out only bytes that hash to the hash they are asked for. More...
struct  morph::ui::LoadedBundle
 A bundle the client verified: what the shell mounts, and what it was verified against. More...
class  morph::ui::UiClient
 Opens an application's bundle through the UI service, verifying everything it fetches. More...
struct  morph::ui::DownloadedFile
 A file a download brought back. More...
class  morph::ui::FileTransfer
 The client of the file side channel (files/1, spec 6 §18): uploads and downloads through ui-file, one chunk of at most kMaxFileChunkBytes in flight at a time, reporting progress after each. More...

Typedefs

using morph::ui::ExchangeReply = std::expected<::morph::wire::Envelope, std::string>
 One reply, or why the transport could not deliver it.
using morph::ui::Exchange = std::function<void(::morph::wire::Envelope request, std::function<void(ExchangeReply reply)> done)>
 Sends one request and calls its callback once with the reply. The transport assigns the request's callId and matches the reply to it; a failure to deliver either is the error.

Functions

Exchange morph::ui::exchangeOver (::morph::backend::IEnvelopeTransport &backend, ::morph::exec::IExecutor &cbExec)
 An Exchange over a transport: each request is one IEnvelopeTransport::request, and its reply, ok or err, is the exchange's reply; a failure to deliver either is the error, as its message.
std::expected< std::string, std::string > morph::ui::evaluationValue (ExchangeReply reply)
 The value an evaluate query takes from a ui-evaluate reply: the evaluated body's members, with the field errors under errors and the verdict under ready, where errors.<field> attaches each to its element.
std::function<::morph::async::Completion< std::string >(std::string const &, std::string const &, std::string const &)> morph::ui::evaluatorOver (Exchange exchange, ::morph::session::Context session, ::morph::exec::IExecutor *cbExec)
 An evaluator over the UI service: each evaluation is one ui-evaluate request through exchange, and resolves with evaluationValue of its reply. What BridgeDispatcher takes as its Evaluator.
std::function<::morph::async::Completion< std::string >(std::string const &, std::string const &)> morph::ui::watcherOver (Exchange exchange, std::function<::morph::session::Context()> currentSession, ::morph::exec::IExecutor *cbExec)
 A watcher over the server (spec 8 §7): each watch or unwatch is one request of that kind through exchange, carrying the session currentSession returns when it is sent. What SessionOptions::watcher takes.

Detailed Description

The client side of the UI service (spec 5 §12, "Content addressing"): UiClient runs ui-hello, ui-catalog and ui-fetch over a transport the caller supplies, verifies every file against the manifest and the manifest against the ui-hello digest, and keeps what it verified in a VerifiedCache.

Specified in docs/spec/ui/service.md.

Definition in file service_client.hpp.

Typedef Documentation

◆ ExchangeReply

using morph::ui::ExchangeReply = std::expected<::morph::wire::Envelope, std::string>

One reply, or why the transport could not deliver it.

Definition at line 208 of file service_client.hpp.

◆ Exchange

using morph::ui::Exchange = std::function<void(::morph::wire::Envelope request, std::function<void(ExchangeReply reply)> done)>

Sends one request and calls its callback once with the reply. The transport assigns the request's callId and matches the reply to it; a failure to deliver either is the error.

Definition at line 212 of file service_client.hpp.

Function Documentation

◆ exchangeOver()

Exchange morph::ui::exchangeOver ( ::morph::backend::IEnvelopeTransport & backend,
::morph::exec::IExecutor & cbExec )
inlinenodiscard

An Exchange over a transport: each request is one IEnvelopeTransport::request, and its reply, ok or err, is the exchange's reply; a failure to deliver either is the error, as its message.

Call it on cbExec's thread, where its replies arrive: UiClient sends each request from the reply before it, so a client opened there stays there.

Parameters
backendThe transport: SocketBackend or QtWebSocketBackend. Borrowed: it must outlive every request sent through the exchange, so a caller that may destroy it first guards the exchange itself.
cbExecThe executor replies are delivered on: the interpreter runtime's owner. Borrowed.
Returns
The exchange.

Definition at line 223 of file service_client.hpp.

◆ evaluationValue()

std::expected< std::string, std::string > morph::ui::evaluationValue ( ExchangeReply reply)
inlinenodiscard

The value an evaluate query takes from a ui-evaluate reply: the evaluated body's members, with the field errors under errors and the verdict under ready, where errors.<field> attaches each to its element.

An action field named errors or ready is shadowed by them.

Parameters
replyThe reply, or why the transport could not deliver it.
Returns
The value as JSON text, or why there is none: the transport's reason, the server's err message, or why the reply body was refused.

Definition at line 649 of file service_client.hpp.

◆ evaluatorOver()

std::function<::morph::async::Completion< std::string >(std::string const &, std::string const &, std::string const &)> morph::ui::evaluatorOver ( Exchange exchange,
::morph::session::Context session,
::morph::exec::IExecutor * cbExec )
inlinenodiscard

An evaluator over the UI service: each evaluation is one ui-evaluate request through exchange, and resolves with evaluationValue of its reply. What BridgeDispatcher takes as its Evaluator.

Parameters
exchangeThe transport.
sessionThe session every request carries.
cbExecThe executor the completion is delivered on: the interpreter runtime's owner. Borrowed.
Returns
The evaluator: the model's type id, the action id and its JSON body in, the query's value out.

Definition at line 682 of file service_client.hpp.

◆ watcherOver()

std::function<::morph::async::Completion< std::string >(std::string const &, std::string const &)> morph::ui::watcherOver ( Exchange exchange,
std::function<::morph::session::Context()> currentSession,
::morph::exec::IExecutor * cbExec )
inlinenodiscard

A watcher over the server (spec 8 §7): each watch or unwatch is one request of that kind through exchange, carrying the session currentSession returns when it is sent. What SessionOptions::watcher takes.

The session is read at each send, not fixed when the watcher is built, because a watch must carry whoever is signed in now: the exchange does not stamp it, and the server refuses an unsigned one.

Parameters
exchangeThe transport.
currentSessionThe session to stamp on each request, read when it is sent.
cbExecThe executor the completion is delivered on: the interpreter runtime's owner. Borrowed.
Returns
The watcher: the kind and the WatchBody JSON in; the reply body out, or the transport's or the server's reason as the failure.

Definition at line 717 of file service_client.hpp.