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

Declarative control: Query, Mutation and Subscription turn server interaction into reactive state, so a controller states what it depends on and what a write invalidates instead of sequencing calls by hand. More...

#include <chrono>
#include <cstddef>
#include <cstdint>
#include <exception>
#include <functional>
#include <map>
#include <memory>
#include <optional>
#include <stdexcept>
#include <string>
#include <utility>
#include <vector>
#include "../attributes.hpp"
#include "../core/bridge.hpp"
#include "../core/callback_scope.hpp"
#include "../core/completion.hpp"
#include "../core/registry.hpp"
#include "detail/graph.hpp"
#include "runtime.hpp"
#include "scheduler.hpp"
#include "signal.hpp"

Go to the source code of this file.

Classes

class  morph::reactive::Refetchable
 Something a Mutation can tell to fetch again after it succeeds. More...
 A query's registration with the mutations that invalidate it. More...
struct  morph::reactive::QueryOptions
 How a Query refreshes besides key changes, and how long it lets a key settle. More...
class  morph::reactive::Query< A, R >
 A derived async resource: the result of fetching whatever its tracked key names. More...
struct  morph::reactive::MutationOptions< A >
 How a Mutation sequences its runs, and what a success invalidates. More...
class  morph::reactive::Mutation< A, R >
 A command: issues a write and tracks it, then refetches what the write invalidates. More...
class  morph::reactive::Subscription< R >
 The latest R the bridge published on a handler's instance, as reactive state. More...

Enumerations

enum class  morph::reactive::Concurrency : std::uint8_t { Exclusive , Serial , Latest , Parallel }
 What a Mutation does with a run while another is in flight. More...

Functions

std::string morph::reactive::errorMessage (std::exception_ptr const &error)
 The one place an exception_ptr becomes display text.
template<typename M, typename S>
void morph::reactive::detail::checkHandlerExecutor (Runtime const &runtime, bridge::BridgeHandler< M, S > const &handler)
 Checks that handler delivers its callbacks on runtime's owner, reporting site::kHandlerExecutor when it does not.

Detailed Description

Declarative control: Query, Mutation and Subscription turn server interaction into reactive state, so a controller states what it depends on and what a write invalidates instead of sequencing calls by hand.

Specified in docs/spec/reactive/control.md.

Definition in file control.hpp.

Enumeration Type Documentation

◆ Concurrency

enum class morph::reactive::Concurrency : std::uint8_t
strong

What a Mutation does with a run while another is in flight.

Enumerator
Exclusive 

Refuses the run: run() returns false and nothing is sent. The default: a second click on a pending button does nothing.

Serial 

Queues the run and sends it when the previous one settles, a failure included; one queue per MutationOptions::serialKey.

Latest 

Sends the run; only the newest run's reply is applied.

Parallel 

Sends the run; every reply is applied as it arrives.

Definition at line 444 of file control.hpp.

Function Documentation

◆ errorMessage()

std::string morph::reactive::errorMessage ( std::exception_ptr const & error)
inlinenodiscard

The one place an exception_ptr becomes display text.

Parameters
errorThe captured exception, or null.
Returns
what() for a std::exception, "unknown error" for anything else, empty for null.

Definition at line 39 of file control.hpp.

◆ checkHandlerExecutor()

template<typename M, typename S>
void morph::reactive::detail::checkHandlerExecutor ( Runtime const & runtime,
bridge::BridgeHandler< M, S > const & handler )

Checks that handler delivers its callbacks on runtime's owner, reporting site::kHandlerExecutor when it does not.

A control node writes its signals from the handler's callbacks, so they must run where the runtime runs. The check is by affinity, not by pointer identity: a distinct serial executor that runs its tasks on the owner's thread is accepted. An executor that is not serial is reported at once. Any other serial executor is checked where it runs, by one posted task, which reports when it finds itself off the owner. No callback executor means the bridge's owner.

Template Parameters
MThe handler's model type.
SThe handler's sharing policy.
Parameters
runtimeThe runtime the node belongs to.
handlerThe handler the node is built over.

Definition at line 109 of file control.hpp.