|
morph 0.1.0
Asynchronous bridge between GUI thread and business models
|
What screens of one client session share (spec 5 §5, §12b): the query cache, the mounted queries, the principal's permitted actions, the formatting facts and the client's env, session and host values. More...
#include <interpreter.hpp>
Public Member Functions | |
| Session (reactive::Runtime &runtime, SessionOptions options={}) | |
| An empty session. | |
| Session (Session const &)=delete | |
| Session & | operator= (Session const &)=delete |
| Session (Session &&)=delete | |
| Session & | operator= (Session &&)=delete |
| reactive::Runtime & | runtime () const noexcept |
| The runtime. | |
| SessionOptions const & | options () const noexcept |
| The options. | |
| void | setPermitted (std::set< std::string, std::less<> > permitted) |
| Sets the action ids the principal may run, as the catalog reply lists them; {"can": ...} follows them. | |
| bool | can (std::string_view action) const |
| Whether the principal may run an action, or the client can run a host command now. A tracked read. | |
| void | setFormatting (FormatContext format) |
| Replaces the formatting facts; every t and display function re-evaluates. | |
| FormatContext const & | formatting () const |
| The formatting facts. A tracked read. | |
| void | setLocale (std::string locale) |
| Changes the active locale, keeping the other formatting facts. | |
| void | setTranslations (render::TranslationProvider translations) |
| Replaces the message catalogue, keeping the other formatting facts; every t re-resolves. | |
| void | setEnvironment (ValueRecord values) |
| Sets the env values (widthClass, locale, platform, online, backend). | |
| void | setSessionValues (ValueRecord values) |
| Sets the session values (principal, userName, …). | |
| void | setHostValues (ValueRecord values) |
| Sets the host values the application registered. | |
| void | setHostCommands (HostCommands commands) |
| Sets the client's host commands: the names {"can": "host:name"} answers for, and what runs them. A session without a runner asks InterpreterHost::hostCommand. | |
| std::function< HostCommandResult(std::string const &, Value const &)> const & | hostCommandRunner () const noexcept |
| What runs host commands. | |
| Value | client (ExprKind form, std::string_view name) const |
| Reads env, session or host. A tracked read. | |
| detail::RtScope const * | appScope () const noexcept |
| The app document's scope, which {"ref": "app.name"} reads and {"set": "app.name"} writes; set by Interpreter::mountApp for as long as the AppRoot lives. | |
| void | setAppScope (detail::RtScope const *scope) noexcept |
| Installs or clears the app document's scope. Called by AppRoot, nothing else. | |
| void | clear () |
| Drops every cache entry: signOut and a principal change (spec 5 §5, "Isolation"). | |
| void | backendChanged (std::string const &backend) |
Carries out a committed backend switch (spec 6 §9), in one batch: every mounted screen's onBackendChange runs first, then every entry is marked stale and the mounted queries refetch, and {"env": "backend"} becomes backend. A query on a private alias therefore never fetches before its screen has recovered from the switch. | |
| void | attachScreen (detail::ScreenCore &screen) |
| Registers a mounted screen or app document, whose onBackendChange a backend switch runs. | |
| void | detachScreen (detail::ScreenCore &screen) |
| Forgets a screen or app document. | |
| void | prefetch (std::shared_ptr< ModelChannel > const &channel, std::string const &token, std::string const &typeId, std::string const &action, Value const &body) |
| Starts a query's request before its screen mounts, so the screen mounts on a warm cache. | |
| std::size_t | cacheSize () const noexcept |
| The number of entries in the cache. | |
| std::string | privateToken () |
| A fresh instance token for a private alias: what the cache key holds for its instance. | |
| bool | lastWriteByUser () const noexcept |
| Whether the newest write to a document source was made by a user event (spec 5 §6, source: "user"). | |
| void | noteWrite () noexcept |
| Records a write to a document source. | |
| void | asUser (std::function< void()> const &body) |
Runs body as a user event: what it writes counts as the user's. | |
| std::shared_ptr< detail::CacheEntry > | acquire (std::string const &token, std::string const &typeId, std::string const &action, bool evaluate, Value const &body) |
| Finds or makes an entry and counts one more user. | |
| void | release (std::shared_ptr< detail::CacheEntry > const &entry) |
| Counts one user less; an entry nobody uses is dropped after keepUnused. | |
| void | fetch (std::shared_ptr< detail::CacheEntry > const &entry, std::shared_ptr< ModelChannel > const &channel) |
| Sends an entry's request under a new generation; a reply of an older generation is dropped. | |
| void | confirm (detail::CacheEntry &entry, Value const &confirmed) |
| Writes an entry's confirmed value and re-applies its optimistic layers over it. | |
| void | showLayers (detail::CacheEntry &entry) |
| Recomputes what an entry shows from its confirmed value and its layers. | |
| std::string | classify (std::exception_ptr const &error) const |
| The error kind of a failure. | |
| std::chrono::milliseconds | now () const |
| The clock. | |
| void | attachQuery (detail::QueryRuntime &query) |
| Registers a mounted query, which a reconnect and a backend switch refetch. | |
| void | forgetQuery (detail::QueryRuntime &query) |
| Unregisters a mounted query. | |
| void | actionSucceeded (std::string const &typeId, std::string const &actionId, Value const &reply, ReplyUse use, std::string const &instanceToken) |
A call of actionId on a model of typeId succeeded: applies the action's effects to the cache (spec 8 §9). | |
| void | reconnected () |
| The connection to the server was made again (spec 8 §7, "Reconnect"): sends the whole watch set with replace: true, then marks every entry but an evaluate one stale. A mounted entry refetches, and one whose fetch is in flight fetches once more when that fetch settles, so a change missed while the connection was down is read again. | |
| wire::WatchBody | watchSet () const |
| The topics the cache holds now: every record an entry holds, and the keyed shared instance of every entry whose action holds no record. What reconnected sends. | |
| void | deliverEvent (wire::EventBody const &event) |
| Applies a server event to the cache (spec 8 §9). | |
| void | applyChanges (wire::ChangesBody const &changes) |
| Applies a changes event's payload to the cache, in one reactive batch. | |
Static Public Member Functions | |
| static std::string | cacheKey (std::string const &token, std::string const &typeId, std::string const &action, bool evaluate, std::string const &body) |
| The cache key of a query. | |
| static void | markStale (detail::CacheEntry &entry) |
| Marks an entry stale. While its fetch is in flight, the entry also refetches once that fetch settles, because the fetch may have read before the change. | |
What screens of one client session share (spec 5 §5, §12b): the query cache, the mounted queries, the principal's permitted actions, the formatting facts and the client's env, session and host values.
It belongs to the runtime's owner, outlives every screen mounted on it, and is cleared by signOut and on a principal change.
Definition at line 888 of file interpreter.hpp.
|
inlineexplicit |
An empty session.
| runtime | The runtime. Borrowed. |
| options | Timers, clock, catalog and the inline cap. |
| std::invalid_argument | when maxInlineFileBytes is 0 or above kMaxInlineFileBytes. |
Definition at line 894 of file interpreter.hpp.
|
inlinenodiscardnoexcept |
|
inlinenodiscardnoexcept |
|
inline |
Sets the action ids the principal may run, as the catalog reply lists them; {"can": ...} follows them.
| permitted | The ids. |
Definition at line 920 of file interpreter.hpp.
|
inlinenodiscard |
Whether the principal may run an action, or the client can run a host command now. A tracked read.
A host: name is answered from the client's own commands (setHostCommands), never from the server's permitted set: the two have different owners, and a catalog refresh must not drop the client's commands.
| action | The action id, or host:<command>. |
Definition at line 928 of file interpreter.hpp.
|
inline |
Replaces the formatting facts; every t and display function re-evaluates.
| format | The facts. |
Definition at line 938 of file interpreter.hpp.
|
inlinenodiscard |
|
inline |
Changes the active locale, keeping the other formatting facts.
| locale | The BCP 47 locale. |
Definition at line 946 of file interpreter.hpp.
|
inline |
Replaces the message catalogue, keeping the other formatting facts; every t re-resolves.
| translations | The provider, such as MessageCatalogues::provider(); empty shows every fallback. |
Definition at line 954 of file interpreter.hpp.
|
inline |
Sets the env values (widthClass, locale, platform, online, backend).
| values | The values. |
Definition at line 962 of file interpreter.hpp.
|
inline |
Sets the session values (principal, userName, …).
| values | The values. |
Definition at line 966 of file interpreter.hpp.
|
inline |
Sets the host values the application registered.
| values | The values. |
Definition at line 970 of file interpreter.hpp.
|
inline |
Sets the client's host commands: the names {"can": "host:name"} answers for, and what runs them. A session without a runner asks InterpreterHost::hostCommand.
| commands | The names and the runner. |
Definition at line 975 of file interpreter.hpp.
|
inlinenodiscardnoexcept |
What runs host commands.
Definition at line 982 of file interpreter.hpp.
Reads env, session or host. A tracked read.
| form | Env, Session or Host. |
| name | The name. |
Definition at line 991 of file interpreter.hpp.
|
inlinenodiscardnoexcept |
The app document's scope, which {"ref": "app.name"} reads and {"set": "app.name"} writes; set by Interpreter::mountApp for as long as the AppRoot lives.
Definition at line 1005 of file interpreter.hpp.
|
inlinenoexcept |
Installs or clears the app document's scope. Called by AppRoot, nothing else.
| scope | The scope, or nullptr. |
Definition at line 1009 of file interpreter.hpp.
|
inline |
Drops every cache entry: signOut and a principal change (spec 5 §5, "Isolation").
Definition at line 1012 of file interpreter.hpp.
|
inline |
Carries out a committed backend switch (spec 6 §9), in one batch: every mounted screen's onBackendChange runs first, then every entry is marked stale and the mounted queries refetch, and {"env": "backend"} becomes backend. A query on a private alias therefore never fetches before its screen has recovered from the switch.
| backend | The backend now in use. |
Definition at line 3046 of file interpreter.hpp.
|
inline |
Registers a mounted screen or app document, whose onBackendChange a backend switch runs.
| screen | It. Borrowed until detachScreen. |
Definition at line 1036 of file interpreter.hpp.
|
inline |
Forgets a screen or app document.
| screen | It. |
Definition at line 1040 of file interpreter.hpp.
|
inline |
Starts a query's request before its screen mounts, so the screen mounts on a warm cache.
| channel | The alias's channel. |
| token | The alias's instance token (Screen::instanceToken). |
| typeId | The model type. |
| action | The action. |
| body | The body. |
Definition at line 1048 of file interpreter.hpp.
|
inlinenodiscardnoexcept |
|
inlinenodiscard |
A fresh instance token for a private alias: what the cache key holds for its instance.
Definition at line 1063 of file interpreter.hpp.
|
inlinenodiscardnoexcept |
Whether the newest write to a document source was made by a user event (spec 5 §6, source: "user").
Definition at line 1067 of file interpreter.hpp.
|
inlinenoexcept |
Records a write to a document source.
Definition at line 1070 of file interpreter.hpp.
|
inline |
Runs body as a user event: what it writes counts as the user's.
| body | The body. |
Definition at line 1074 of file interpreter.hpp.
|
inlinestaticnodiscard |
The cache key of a query.
| token | The alias's instance token. |
| typeId | The model type. |
| action | The action. |
| evaluate | Whether it is an evaluate query. |
| body | The canonical body. |
Definition at line 1092 of file interpreter.hpp.
|
inline |
Finds or makes an entry and counts one more user.
| token | The alias's instance token. |
| typeId | The model type. |
| action | The action. |
| evaluate | Whether it is an evaluate query. |
| body | The body. |
Definition at line 1104 of file interpreter.hpp.
|
inline |
Counts one user less; an entry nobody uses is dropped after keepUnused.
| entry | The entry. |
Definition at line 1135 of file interpreter.hpp.
|
inline |
Sends an entry's request under a new generation; a reply of an older generation is dropped.
| entry | The entry. |
| channel | The channel to send it through; nullptr fails the request at once. |
Definition at line 1153 of file interpreter.hpp.
|
inline |
Writes an entry's confirmed value and re-applies its optimistic layers over it.
| entry | The entry. |
| confirmed | The confirmed value. |
Definition at line 1188 of file interpreter.hpp.
|
inline |
Recomputes what an entry shows from its confirmed value and its layers.
| entry | The entry. |
Definition at line 1195 of file interpreter.hpp.
|
inlinenodiscard |
The error kind of a failure.
| error | The failure. |
Definition at line 1209 of file interpreter.hpp.
|
inlinenodiscard |
|
inline |
Registers a mounted query, which a reconnect and a backend switch refetch.
| query | The query. |
Definition at line 1225 of file interpreter.hpp.
|
inline |
Unregisters a mounted query.
| query | The query. |
Definition at line 1229 of file interpreter.hpp.
|
inline |
A call of actionId on a model of typeId succeeded: applies the action's effects to the cache (spec 8 §9).
updates R merges the reply's rows of R into each entry holding R, matched by the record's key field at the entry's paths, with no fetch; an entry whose fetch is in flight also fetches once more, since that fetch may have read before the write. changes R marks each entry holding R stale. changesInstance marks each entry read through the same instance. A marked entry refetches through a mounted query that uses it. A discarded reply only marks: its updates act as changes.
| typeId | The model type. |
| actionId | The action. |
| reply | The reply's value. |
| use | Whether the reply was applied or discarded. |
| instanceToken | The instance token of the alias the call went through. |
Definition at line 3320 of file interpreter.hpp.
|
inline |
The connection to the server was made again (spec 8 §7, "Reconnect"): sends the whole watch set with replace: true, then marks every entry but an evaluate one stale. A mounted entry refetches, and one whose fetch is in flight fetches once more when that fetch settles, so a change missed while the connection was down is read again.
Definition at line 3233 of file interpreter.hpp.
|
inlinenodiscard |
The topics the cache holds now: every record an entry holds, and the keyed shared instance of every entry whose action holds no record. What reconnected sends.
Definition at line 3206 of file interpreter.hpp.
|
inline |
Applies a server event to the cache (spec 8 §9).
A changes event marks the entries it names stale, and a resync sends the whole watch set again, as reconnected does, and marks every entry but an evaluate one; each marked entry refetches through a mounted query that uses it, and one no query uses refetches when a query mounts on it. An event of another topic, or a payload that cannot be read, is ignored.
| event | The event. |
Definition at line 3247 of file interpreter.hpp.
|
inline |
Applies a changes event's payload to the cache, in one reactive batch.
A record change with keys marks each entry holding the record whose value has a row with one of the keys, and an entry holding it keyless; a record change without keys marks every entry holding the record. An instance change marks every entry read through that instance: the keyed shared one its primary key names, or, with no primary key, the connection's own private ones of that model type.
| changes | The payload. |
Definition at line 3260 of file interpreter.hpp.
|
inlinestatic |
Marks an entry stale. While its fetch is in flight, the entry also refetches once that fetch settles, because the fetch may have read before the change.
| entry | The entry. |
Definition at line 1279 of file interpreter.hpp.