morph 0.1.0
Asynchronous bridge between GUI thread and business models
Loading...
Searching...
No Matches
morph::ui::InterpreterHost Class Reference

What the application answers for the commands a document cannot carry out alone (spec 6). Every default answers "not supported", which the interpreter reports as a diagnostic. More...

#include <interpreter.hpp>

Inheritance diagram for morph::ui::InterpreterHost:
morph::client::ApplicationHost morph::ui::DocumentScreenHost

Public Member Functions

 InterpreterHost (InterpreterHost const &)=delete
InterpreterHost & operator= (InterpreterHost const &)=delete
 InterpreterHost (InterpreterHost &&)=delete
InterpreterHost & operator= (InterpreterHost &&)=delete
virtual bool navigate (NavigateRequest const &request, std::function< void(Value)> onResult, std::function< void()> onCancel)
 Opens another screen.
virtual bool closeSelf (std::string const &screen, std::optional< Value > result)
 Ends the screen that ran return or close: self.
virtual bool hostCommand (std::string const &name, Value const &args)
 Runs a command the application registered (host/1).
virtual bool switchBackend (std::string const &name, std::function< void(std::expected< void, std::string >)> done)
 Switches to a backend the application's source lists (AppSource::switchBackend, spec 6 §9).
virtual void resetPrefs (std::string const &screen, std::string const &point)
 The document reset a customization point, or all of them; the host forgets the stored choice.
virtual void setLocale (std::string const &locale)
 Stores the active locale as a preference. The interpreter has already re-resolved every t.
virtual bool notify (std::string const &text, std::string const &role)
 Shows a transient message.
virtual bool signIn (Value const &reply)
 Installs the session the reply of a sign-in mutation carries, and reloads the catalog.
virtual void signOut ()
 Ends the session. The interpreter has already cleared the session's query cache.
virtual bool setAppValue (std::string const &name, Value const &value)
 Writes app.name with set (spec 6 §5).
virtual bool upload (Value const &file, std::function< void(Value)> progress, std::function< void(std::expected< Value, std::string >)> done)
 Sends a file through the server's file side channel (files/1).
virtual bool uploadFor (UploadRequest const &request, std::function< void(Value)> progress, std::function< void(std::expected< Value, std::string >)> done)
 Sends a file through the server's file side channel, knowing the mutation that will reference it. The interpreter calls this one; the default calls upload(file, …), so a host that overrides only that keeps working.
virtual bool download (Value const &file, std::string const &option, Value const &name, std::function< void(std::expected< Value, std::string >)> done)
 Fetches a file by reference to save it, or to a local temporary reference for a viewer.
virtual bool readFile (Value const &file, std::size_t maxBytes, std::function< void(std::expected< InlineFile, std::string >)> done)
 Reads a file's bytes for upload into bytes. A host reads the file's size first and refuses one over maxBytes without reading it; the interpreter refuses a reply over the cap as well.
virtual bool saveFile (InlineFile const &file, std::string const &option, std::function< void(std::expected< Value, std::string >)> done)
 Saves a file a document holds the bytes of, for download from bytes.
virtual void preferenceChanged (std::string const &screen, std::string const &point, Value const &value)
 The user chose at a customization point through a customize editor; the host stores the choice.
virtual void permissionsStale ()
 A call was refused with error kind denied: the permitted set is a snapshot, so the host asks the server again and calls Session::setPermitted.

Detailed Description

What the application answers for the commands a document cannot carry out alone (spec 6). Every default answers "not supported", which the interpreter reports as a diagnostic.

Definition at line 227 of file interpreter.hpp.

Member Function Documentation

◆ navigate()

virtual bool morph::ui::InterpreterHost::navigate ( NavigateRequest const & request,
std::function< void(Value)> onResult,
std::function< void()> onCancel )
inlinevirtual

Opens another screen.

Parameters
requestWhat to open.
onResultCalled with the value a screen opened as a dialog, drawer or window returns.
onCancelCalled when such a screen closes without a value.
Returns
Whether the host opened it.

Definition at line 244 of file interpreter.hpp.

◆ closeSelf()

virtual bool morph::ui::InterpreterHost::closeSelf ( std::string const & screen,
std::optional< Value > result )
inlinevirtual

Ends the screen that ran return or close: self.

Parameters
screenThe screen's id.
resultThe value of return; std::nullopt for close: self.
Returns
Whether the screen was opened as something that can end.

Definition at line 256 of file interpreter.hpp.

◆ hostCommand()

virtual bool morph::ui::InterpreterHost::hostCommand ( std::string const & name,
Value const & args )
inlinevirtual

Runs a command the application registered (host/1).

Parameters
nameThe command.
argsIts arguments; null when none.
Returns
Whether the command exists.

Definition at line 266 of file interpreter.hpp.

◆ switchBackend()

virtual bool morph::ui::InterpreterHost::switchBackend ( std::string const & name,
std::function< void(std::expected< void, std::string >)> done )
inlinevirtual

Switches to a backend the application's source lists (AppSource::switchBackend, spec 6 §9).

The switch is asynchronous: the host calls done once, on the runtime's owner, when it committed or failed. A failed switch leaves the old backend in place.

Parameters
nameThe backend.
doneCalled once with nothing when the switch committed, or with why it failed. Not called when the backend is not listed.
Returns
Whether it is listed.

Definition at line 280 of file interpreter.hpp.

◆ resetPrefs()

virtual void morph::ui::InterpreterHost::resetPrefs ( std::string const & screen,
std::string const & point )
inlinevirtual

The document reset a customization point, or all of them; the host forgets the stored choice.

Parameters
screenThe screen's id.
pointThe point, or all.

Definition at line 289 of file interpreter.hpp.

◆ setLocale()

virtual void morph::ui::InterpreterHost::setLocale ( std::string const & locale)
inlinevirtual

Stores the active locale as a preference. The interpreter has already re-resolved every t.

Parameters
localeThe BCP 47 locale.

Definition at line 296 of file interpreter.hpp.

◆ notify()

virtual bool morph::ui::InterpreterHost::notify ( std::string const & text,
std::string const & role )
inlinevirtual

Shows a transient message.

Parameters
textThe message.
roleinfo, success, warning or error; empty for the default.
Returns
Whether it was shown.

Reimplemented in morph::client::ApplicationHost.

Definition at line 302 of file interpreter.hpp.

◆ signIn()

virtual bool morph::ui::InterpreterHost::signIn ( Value const & reply)
inlinevirtual

Installs the session the reply of a sign-in mutation carries, and reloads the catalog.

Parameters
replyThe mutation's reply, secret fields included.
Returns
Whether the host installed it.

Reimplemented in morph::client::ApplicationHost.

Definition at line 311 of file interpreter.hpp.

◆ signOut()

virtual void morph::ui::InterpreterHost::signOut ( )
inlinevirtual

Ends the session. The interpreter has already cleared the session's query cache.

Reimplemented in morph::client::ApplicationHost.

Definition at line 317 of file interpreter.hpp.

◆ setAppValue()

virtual bool morph::ui::InterpreterHost::setAppValue ( std::string const & name,
Value const & value )
inlinevirtual

Writes app.name with set (spec 6 §5).

Parameters
nameThe app state's name.
valueThe value.
Returns
Whether the app document declares it.

Definition at line 323 of file interpreter.hpp.

◆ upload()

virtual bool morph::ui::InterpreterHost::upload ( Value const & file,
std::function< void(Value)> progress,
std::function< void(std::expected< Value, std::string >)> done )
inlinevirtual

Sends a file through the server's file side channel (files/1).

Parameters
fileWhat the user picked or dropped.
progressCalled with the progress, 0 to 1.
doneCalled once with the file's reference, or the failure's text.
Returns
Whether the host can send files.

Definition at line 334 of file interpreter.hpp.

◆ uploadFor()

virtual bool morph::ui::InterpreterHost::uploadFor ( UploadRequest const & request,
std::function< void(Value)> progress,
std::function< void(std::expected< Value, std::string >)> done )
inlinevirtual

Sends a file through the server's file side channel, knowing the mutation that will reference it. The interpreter calls this one; the default calls upload(file, …), so a host that overrides only that keeps working.

Parameters
requestThe file and the mutation.
progressCalled with the progress, 0 to 1.
doneCalled once with the file's reference, or the failure's text.
Returns
Whether the host can send files.

Definition at line 349 of file interpreter.hpp.

◆ download()

virtual bool morph::ui::InterpreterHost::download ( Value const & file,
std::string const & option,
Value const & name,
std::function< void(std::expected< Value, std::string >)> done )
inlinevirtual

Fetches a file by reference to save it, or to a local temporary reference for a viewer.

Parameters
fileThe file's reference.
optiondialog to save, preview for a local reference.
nameThe suggested file name; null when none.
doneCalled once with the local reference (preview) or null (dialog), or the failure.
Returns
Whether the host can fetch files.

Definition at line 360 of file interpreter.hpp.

◆ readFile()

virtual bool morph::ui::InterpreterHost::readFile ( Value const & file,
std::size_t maxBytes,
std::function< void(std::expected< InlineFile, std::string >)> done )
inlinevirtual

Reads a file's bytes for upload into bytes. A host reads the file's size first and refuses one over maxBytes without reading it; the interpreter refuses a reply over the cap as well.

Parameters
fileWhat the user picked or dropped.
maxBytesThe session's inline cap.
doneCalled once with the file, or the failure's text.
Returns
Whether the host can read files.

Definition at line 375 of file interpreter.hpp.

◆ saveFile()

virtual bool morph::ui::InterpreterHost::saveFile ( InlineFile const & file,
std::string const & option,
std::function< void(std::expected< Value, std::string >)> done )
inlinevirtual

Saves a file a document holds the bytes of, for download from bytes.

Parameters
fileThe file.
optiondialog to save, preview for a local reference.
doneCalled once with the local reference (preview) or null (dialog), or the failure.
Returns
Whether the host can save files.

Definition at line 388 of file interpreter.hpp.

◆ preferenceChanged()

virtual void morph::ui::InterpreterHost::preferenceChanged ( std::string const & screen,
std::string const & point,
Value const & value )
inlinevirtual

The user chose at a customization point through a customize editor; the host stores the choice.

Parameters
screenThe screen's id.
pointThe point.
valueThe choice.

Definition at line 400 of file interpreter.hpp.

◆ permissionsStale()

virtual void morph::ui::InterpreterHost::permissionsStale ( )
inlinevirtual

A call was refused with error kind denied: the permitted set is a snapshot, so the host asks the server again and calls Session::setPermitted.

Definition at line 408 of file interpreter.hpp.


The documentation for this class was generated from the following file: