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

The client's host vocabulary: what it registered, and whether its documents came over a verified connection. More...

#include <host_vocabulary.hpp>

Public Member Functions

void add (HostCommand command)
 Registers a command.
void add (HostValue value)
 Registers a value.
bool set (std::string const &name, Value value)
 Changes a value; every binding on it updates.
void setConnectionVerified (bool verified)
 Says whether the documents came over a verified connection. A command not marked safeForUntrusted runs, and can is true for it, only while this is true. It starts false.
void connect (Session &session)
 Gives session the values, the names {"can": "host:name"} answers for, and the runner for {"host": name} commands. Later registrations and changes reach it too.
void describe (HelloRequest &hello) const
 Fills the host command and value names and versions of a ui-hello request, so the server knows what this client can do before it serves a document that needs it.
HostCommandResult run (std::string const &name, Value const &args) const
 Runs a command as a document's {"host": name, "args": args} does.

Detailed Description

The client's host vocabulary: what it registered, and whether its documents came over a verified connection.

An application builds one at start-up, registers its commands and values, connects it to the interpreter's Session, and tells it when the connection is verified (spec 5 §13: a verified TLS connection, or loopback with the development flag). Until then a command not marked safeForUntrusted is refused. It lives on the runtime's owner, like the session, and outlives the session it is connected to.

Definition at line 69 of file host_vocabulary.hpp.

Member Function Documentation

◆ add() [1/2]

void morph::ui::HostVocabulary::add ( HostCommand command)
inline

Registers a command.

Parameters
commandThe command. Refused (std::invalid_argument): an invalid name, a duplicate, an argument whose name is empty or repeated or whose type does not parse, or no run.

Definition at line 74 of file host_vocabulary.hpp.

◆ add() [2/2]

void morph::ui::HostVocabulary::add ( HostValue value)
inline

Registers a value.

Parameters
valueThe value. Refused (std::invalid_argument): an invalid name, a duplicate, a type that does not parse, or an initial value not of the type.

Definition at line 98 of file host_vocabulary.hpp.

◆ set()

bool morph::ui::HostVocabulary::set ( std::string const & name,
Value value )
inline

Changes a value; every binding on it updates.

Parameters
nameThe value.
valueIts new value.
Returns
Whether the value is registered and value has its type; otherwise nothing changes.

Definition at line 117 of file host_vocabulary.hpp.

◆ setConnectionVerified()

void morph::ui::HostVocabulary::setConnectionVerified ( bool verified)
inline

Says whether the documents came over a verified connection. A command not marked safeForUntrusted runs, and can is true for it, only while this is true. It starts false.

Parameters
verifiedWhether the connection is verified.

Definition at line 132 of file host_vocabulary.hpp.

◆ connect()

void morph::ui::HostVocabulary::connect ( Session & session)
inline

Gives session the values, the names {"can": "host:name"} answers for, and the runner for {"host": name} commands. Later registrations and changes reach it too.

Parameters
sessionThe session. Borrowed: this vocabulary outlives its use of it.

Definition at line 140 of file host_vocabulary.hpp.

◆ describe()

void morph::ui::HostVocabulary::describe ( HelloRequest & hello) const
inline

Fills the host command and value names and versions of a ui-hello request, so the server knows what this client can do before it serves a document that needs it.

Parameters
helloThe request.

Definition at line 148 of file host_vocabulary.hpp.

◆ run()

HostCommandResult morph::ui::HostVocabulary::run ( std::string const & name,
Value const & args ) const
inlinenodiscard

Runs a command as a document's {"host": name, "args": args} does.

Parameters
nameThe command.
argsIts arguments: a record, or null for none.
Returns
Ran; Missing for a command nobody registered; Refused, with the reason, for an argument that is missing, of the wrong type or not declared, or for an unsafe command on an unverified connection.

Definition at line 162 of file host_vocabulary.hpp.


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