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

A handler for a model known only by its registered type id. More...

#include <bridge.hpp>

Public Member Functions

 RawHandler (Bridge &bridge, ::morph::exec::IExecutor *cbExec, std::string typeId, BindSharing sharing=BindSharing::Private, std::string instanceKey={})
 Binds the model registered as typeId.
 ~RawHandler ()
 Deregisters the binding, on the owner.
 RawHandler (const RawHandler &)=delete
RawHandler & operator= (const RawHandler &)=delete
 RawHandler (RawHandler &&)=delete
RawHandler & operator= (RawHandler &&)=delete
::morph::async::Completion< std::string > execute (std::string actionId, std::string bodyJson)
 Dispatches the action registered as actionId with bodyJson.
::morph::async::Completion< std::string > execute (std::string actionId, std::string bodyJson, ::core::async::StopToken stop)
 execute, cancellable through stop.
::morph::async::Completion< std::string > executeOn (std::string instanceKey, std::string actionId, std::string bodyJson)
 execute on the instance for instanceKey, attaching this shared handler to it first; see Bridge::executeRawOn.
void attach (std::string instanceKey)
 Attaches (or re-points) this shared handler to the instance for instanceKey, as BridgeHandler::attach does for a typed one.
std::string primary () const
 This handler's current instance key.
bool isBound () const noexcept
 Whether the handler holds a live instance now.
const std::string & typeId () const noexcept
 The model's registered type id.

Detailed Description

A handler for a model known only by its registered type id.

What a client compiled without the model's C++ type holds: binds through Bridge::bindByType on construction, dispatches through Bridge::executeRaw, and deregisters on destruction — on the owner, with every guarantee a BridgeHandler has. Non-copyable and non-movable.

Definition at line 2950 of file bridge.hpp.

Constructor & Destructor Documentation

◆ RawHandler()

morph::bridge::RawHandler::RawHandler ( Bridge & bridge,
::morph::exec::IExecutor * cbExec,
std::string typeId,
BindSharing sharing = BindSharing::Private,
std::string instanceKey = {} )
inline

Binds the model registered as typeId.

Parameters
bridgeThe bridge to bind on. Borrowed: it must outlive every call made on this handler.
cbExecExecutor the Completion callbacks are posted on. Borrowed: it must outlive this handler.
typeIdThe model's registered type id.
sharingPrivate or shared.
instanceKeyFor a shared handler, the key to attach to now, or empty.
Exceptions
std::invalid_argumentfor a private handler with a key.
std::logic_errorfor a key given off the owner, inside a running action: attaching is the owner's.

Definition at line 2963 of file bridge.hpp.

◆ ~RawHandler()

morph::bridge::RawHandler::~RawHandler ( )
inline

Deregisters the binding, on the owner.

Every call still held for a bind in flight is rejected with HandlerDestroyedError. Destroyed after its bridge — still on the owner — it finds the bridge's token expired and deregisters nothing.

Definition at line 2976 of file bridge.hpp.

Member Function Documentation

◆ execute() [1/2]

::morph::async::Completion< std::string > morph::bridge::RawHandler::execute ( std::string actionId,
std::string bodyJson )
inlinenodiscard

Dispatches the action registered as actionId with bodyJson.

Parameters
actionIdThe action's registered type id.
bodyJsonThe action's JSON body.
Returns
Completion resolving with the reply's JSON text.

Definition at line 2992 of file bridge.hpp.

◆ execute() [2/2]

::morph::async::Completion< std::string > morph::bridge::RawHandler::execute ( std::string actionId,
std::string bodyJson,
::core::async::StopToken stop )
inlinenodiscard

execute, cancellable through stop.

Parameters
actionIdThe action's registered type id.
bodyJsonThe action's JSON body.
stopThe caller's cancel.
Returns
Completion resolving with the reply's JSON text, or rejected with core::async::OperationCancelled.

Definition at line 3002 of file bridge.hpp.

◆ executeOn()

::morph::async::Completion< std::string > morph::bridge::RawHandler::executeOn ( std::string instanceKey,
std::string actionId,
std::string bodyJson )
inlinenodiscard

execute on the instance for instanceKey, attaching this shared handler to it first; see Bridge::executeRawOn.

The way to send a keyed action: a refused attach rejects the call rather than running it on the instance the handler held before.

Parameters
instanceKeyCanonical string encoding of the primary key.
actionIdThe action's registered type id.
bodyJsonThe action's JSON body.
Returns
Completion resolving with the reply's JSON text.
Exceptions
std::invalid_argumentfor an empty instanceKey.
std::logic_erroron a private handler.

Definition at line 3018 of file bridge.hpp.

◆ attach()

void morph::bridge::RawHandler::attach ( std::string instanceKey)
inline

Attaches (or re-points) this shared handler to the instance for instanceKey, as BridgeHandler::attach does for a typed one.

Issued, not awaited, and a refusal is logged rather than reported: a call that must run on instanceKey goes through executeOn.

Parameters
instanceKeyCanonical string encoding of the primary key.
Exceptions
std::invalid_argumentfor an empty instanceKey.
std::logic_erroron a private handler.

Definition at line 3032 of file bridge.hpp.

◆ primary()

std::string morph::bridge::RawHandler::primary ( ) const
inlinenodiscard

This handler's current instance key.

Returns
The attached key, or empty before the first attach settles.

Definition at line 3036 of file bridge.hpp.

◆ isBound()

bool morph::bridge::RawHandler::isBound ( ) const
inlinenodiscardnoexcept

Whether the handler holds a live instance now.

Returns
true when bound.

Definition at line 3040 of file bridge.hpp.

◆ typeId()

const std::string & morph::bridge::RawHandler::typeId ( ) const
inlinenodiscardnoexcept

The model's registered type id.

Returns
The id given at construction.

Definition at line 3044 of file bridge.hpp.


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