|
morph 0.1.0
Asynchronous bridge between GUI thread and business models
|
An AppSource that also hands the shell what it mounts screens with, once it delivered a bundle. More...
#include <source.hpp>
Classes | |
| struct | Transport |
| What a concrete source opens with: the bridge's backend and the exchange the UI service is reached by. More... | |
Public Member Functions | |
| ui::Dispatcher & | dispatcher () |
| Where the screens' model calls go. | |
| ui::Catalog | catalog () const |
| The catalog facts the screens load with. | |
| std::vector< std::string > | screens () const |
| The screens the principal may open, in catalog order: each catalog entry that is available or public and whose document the bundle holds. | |
| bool | isPublic (std::string_view screenId) const |
Whether the catalog marks screenId public: a screen served before sign-in, such as a login screen. | |
| void | open (ui::AppContext &context, std::function< void(std::expected< ui::Bundle, ui::ConnectError >)> ready) final |
| Opens the source: the transport, the bridge and the bundle, verified. | |
| void | switchBackend (ui::Backend backend, std::function< void(std::expected< void, std::string >)> done) final |
| Refused: a switch between backends is the hosting layer's (spec 6 §9). | |
| void | close () final |
| Drops a ready not yet delivered and releases the bridge, the transport and the bundle. | |
| void | signIn (std::string principal, std::string token, std::function< void(bool)> done) |
Installs a sign-in (spec 6 §5): a session built from the current one with principal and token replaced, carried by every later model call and UI-service request, then the catalog reloaded for it. | |
| void | signOut (std::function< void(bool)> done) |
| Ends the session: back to the principal before any sign-in, with no token, and the catalog reloaded for it. | |
| std::function< std::shared_ptr< ui::Document const >(std::string_view)> | documents (std::function< void(ui::Refusal const &)> onRefused={}) |
| The lookup a DocumentScreenHost takes (DocumentScreenHostOptions::documents), over the loaded bundle: each screen the source lists, loaded against the current catalog facts the first time it is asked for after a load, so a shell of an application's own mounts with the same source. | |
| ui::Bundle const * | bundle () const noexcept |
| The bundle the catalog currently lists. | |
| ui::CatalogReply const * | catalogReply () const noexcept |
| The catalog for the current principal: its entries, what the principal may run, and the facts. | |
| ui::SchemasByModel const & | schemasByModel () const noexcept |
| The schemas document of every model the catalog names, by model type, or why it did not arrive: what the explorer lists each model's actions from. | |
| std::string const & | principal () const noexcept |
| The principal the source's session carries now. | |
| std::optional< ui::FileTransfer > | files () const |
| The file side channel (files/1) over the source's exchange, carrying its session: what a screen's upload and download move bytes through. | |
| void | poll (std::function< void(std::vector< std::string > changed)> changed) |
| One step of development reload (spec 5 §12): sends ui-hello, and when the manifest digest changed, fetches the changed bundle and the catalog for it. Nothing is sent while a poll is still in flight. | |
| void | onConnected (std::function< void()> const &listener) final |
| Adds a listener called on the owner after each successful connect, the first included. On a reconnect the source first sends ui-hello again, so the new connection negotiates events, then calls the listeners. | |
| void | onEvent (std::function< void(wire::EventBody const &)> listener) |
| Adds a listener for the events the server sends: what a shell hands to Session::deliverEvent. | |
| ui::Watcher | watcher () |
| What the session's SessionOptions::watcher sends the cache's watch changes through: watcherOver the source's exchange, stamping the session current at each send. Empty for a source whose transport carries no server events, such as an in-process one. | |
| virtual std::string | signedOutPrincipal () const |
| The principal before any sign-in, which signOut returns to. | |
| Public Member Functions inherited from morph::ui::AppSource | |
| AppSource (AppSource const &)=delete | |
| AppSource & | operator= (AppSource const &)=delete |
| AppSource (AppSource &&)=delete | |
| AppSource & | operator= (AppSource &&)=delete |
| virtual void | open (AppContext &context, std::function< void(std::expected< Bundle, ConnectError >)> ready)=0 |
| Connects (or, local, sets up the models), signs the user in natively if the application needs it, and delivers the bundle. | |
Protected Member Functions | |
| virtual std::expected< Transport, ui::ConnectError > | connect (ui::AppContext &context)=0 |
Makes the transport on context. | |
| virtual std::chrono::milliseconds | openTimeout () const |
| How long open waits for the bundle before it reports the source unreachable; zero waits forever. | |
| virtual void | disconnect () |
| Releases what connect made beside the backend; called by close, after the bridge is gone. | |
| virtual void | fetchSchemas (std::string const &modelType, std::function< void(std::expected< std::string, std::string >)> done) |
| Fetches the {actionType: schema} document of one model type, which a form, collection or wizard node is built from. The default sends a schemas envelope over the source's exchange. | |
| session::Context & | requestSession () noexcept |
| The session every request carries, for a source to fill before open sends anything. | |
An AppSource that also hands the shell what it mounts screens with, once it delivered a bundle.
Opened, it holds a bridge over its backend, owned by the context's executor, and the verified bundle with its catalog. Everything it hands out is valid from a successful ready until close.
Definition at line 72 of file source.hpp.
|
nodiscard |
Where the screens' model calls go.
| std::logic_error | before a bundle was delivered. |
|
nodiscard |
The catalog facts the screens load with.
|
nodiscard |
The screens the principal may open, in catalog order: each catalog entry that is available or public and whose document the bundle holds.
|
nodiscard |
Whether the catalog marks screenId public: a screen served before sign-in, such as a login screen.
| screenId | The screen. |
|
final |
Opens the source: the transport, the bridge and the bundle, verified.
| context | The running frontend's context. |
| ready | Called once, on the owner, unless close comes first. |
|
finalvirtual |
Refused: a switch between backends is the hosting layer's (spec 6 §9).
| backend | Ignored. |
| done | Called with the refusal. |
Implements morph::ui::AppSource.
|
finalvirtual |
Drops a ready not yet delivered and releases the bridge, the transport and the bundle.
Implements morph::ui::AppSource.
| void morph::client::Source::signIn | ( | std::string | principal, |
| std::string | token, | ||
| std::function< void(bool)> | done ) |
Installs a sign-in (spec 6 §5): a session built from the current one with principal and token replaced, carried by every later model call and UI-service request, then the catalog reloaded for it.
| principal | The principal the sign-in mutation answered. |
| token | The session token it answered; empty when the source's server needs none, as in process. |
| done | Called once, on the owner, once the catalog for the new session is current, with whether it loaded; not called after close. |
| void morph::client::Source::signOut | ( | std::function< void(bool)> | done | ) |
Ends the session: back to the principal before any sign-in, with no token, and the catalog reloaded for it.
| done | As signIn's. |
|
nodiscard |
The lookup a DocumentScreenHost takes (DocumentScreenHostOptions::documents), over the loaded bundle: each screen the source lists, loaded against the current catalog facts the first time it is asked for after a load, so a shell of an application's own mounts with the same source.
| onRefused | Called with each document that does not load; may be empty. |
|
inlinenodiscardnoexcept |
The bundle the catalog currently lists.
Definition at line 130 of file source.hpp.
|
inlinenodiscardnoexcept |
The catalog for the current principal: its entries, what the principal may run, and the facts.
Definition at line 134 of file source.hpp.
|
inlinenodiscardnoexcept |
The schemas document of every model the catalog names, by model type, or why it did not arrive: what the explorer lists each model's actions from.
Definition at line 141 of file source.hpp.
|
inlinenodiscardnoexcept |
The principal the source's session carries now.
Definition at line 145 of file source.hpp.
|
nodiscard |
The file side channel (files/1) over the source's exchange, carrying its session: what a screen's upload and download move bytes through.
| void morph::client::Source::poll | ( | std::function< void(std::vector< std::string > changed)> | changed | ) |
One step of development reload (spec 5 §12): sends ui-hello, and when the manifest digest changed, fetches the changed bundle and the catalog for it. Nothing is sent while a poll is still in flight.
| changed | Called on the owner once the changed bundle is current, with the ids of the documents it changed; not called for an unchanged digest, a failed poll, or after close. |
|
finalvirtual |
Adds a listener called on the owner after each successful connect, the first included. On a reconnect the source first sends ui-hello again, so the new connection negotiates events, then calls the listeners.
| listener | Called on the owner; it must stay callable while the source is open. |
Reimplemented from morph::ui::AppSource.
| void morph::client::Source::onEvent | ( | std::function< void(wire::EventBody const &)> | listener | ) |
Adds a listener for the events the server sends: what a shell hands to Session::deliverEvent.
| listener | Called on the owner, once per event, in the order they arrived. |
|
nodiscard |
What the session's SessionOptions::watcher sends the cache's watch changes through: watcherOver the source's exchange, stamping the session current at each send. Empty for a source whose transport carries no server events, such as an in-process one.
|
inlinenodiscardvirtual |
The principal before any sign-in, which signOut returns to.
Reimplemented in morph::client::LocalSource.
Definition at line 176 of file source.hpp.
|
nodiscardprotectedpure virtual |
Makes the transport on context.
| context | The running frontend's context. |
Implemented in morph::client::LocalSource, and morph::client::RemoteSource.
|
inlinenodiscardprotectedvirtual |
How long open waits for the bundle before it reports the source unreachable; zero waits forever.
Reimplemented in morph::client::RemoteSource.
Definition at line 197 of file source.hpp.
|
inlineprotectedvirtual |
Releases what connect made beside the backend; called by close, after the bridge is gone.
Reimplemented in morph::client::LocalSource.
Definition at line 200 of file source.hpp.
|
protectedvirtual |
Fetches the {actionType: schema} document of one model type, which a form, collection or wizard node is built from. The default sends a schemas envelope over the source's exchange.
| modelType | The model type id. |
| done | Called once with the document's JSON text, or why there is none. |
Reimplemented in morph::client::LocalSource.
|
inlinenodiscardprotectednoexcept |
The session every request carries, for a source to fill before open sends anything.
Definition at line 211 of file source.hpp.