morph 0.1.0
Asynchronous bridge between GUI thread and business models
Loading...
Searching...
No Matches
envelope_transport.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
2
3#pragma once
4
5#include "completion.hpp"
6#include "executor.hpp"
7#include "wire.hpp"
8
9/// @file
10/// @brief `IEnvelopeTransport`: a transport that sends a request envelope of a kind its backend verbs do not build,
11/// such as the UI service's `ui-*` kinds, and settles with the peer's reply.
12///
13/// Specified in `docs/spec/core/backend.md`, "Envelope requests".
14
15namespace morph::backend {
16
17/// @brief What a wire transport offers beside `IBackend`: one request, one reply, matched by `callId`.
18///
19/// `SocketBackend` and `QtWebSocketBackend` implement it. A backend without a wire, such as `LocalBackend`, has no
20/// peer and does not.
21class IEnvelopeTransport {
22public:
23 IEnvelopeTransport() = default;
24 IEnvelopeTransport(IEnvelopeTransport const&) = delete;
25 IEnvelopeTransport& operator=(IEnvelopeTransport const&) = delete;
26 IEnvelopeTransport(IEnvelopeTransport&&) = delete;
27 IEnvelopeTransport& operator=(IEnvelopeTransport&&) = delete;
28
29 /// @brief Sends one request envelope and settles with its reply.
30 ///
31 /// The envelope travels with the session it carries: the transport assigns its `callId` and stamps nothing else,
32 /// because a protocol that passes its session explicitly (`ui::UiClient::open`) must not have it replaced by the
33 /// transport's default. The reply resolves the `Completion` whether it is `ok` or `err`, since reading an `err`
34 /// is the caller's protocol; only a failure to deliver the request or its reply rejects it. A request made while
35 /// the connection is down is held and sent at the next connect; `cancelPending`, a drop and the transport's
36 /// destruction reject what is pending or held.
37 /// @param envelope The request. Its `callId` is replaced.
38 /// @param cbExec Executor the answer is delivered on. Borrowed: it must outlive the returned `Completion`.
39 /// @return A `Completion` resolved with the reply envelope, or rejected with the transport's failure
40 /// (`DisconnectedError` for a dropped or closed connection).
41 virtual ::morph::async::Completion<::morph::wire::Envelope> request(::morph::wire::Envelope envelope,
42 ::morph::exec::IExecutor& cbExec) = 0;
43
44protected:
45 ~IEnvelopeTransport() = default;
46};
47
48} // namespace morph::backend
virtual ::morph::async::Completion<::morph::wire::Envelope > request(::morph::wire::Envelope envelope, ::morph::exec::IExecutor &cbExec)=0
Sends one request envelope and settles with its reply.
Abstract executor interface.
Definition executor.hpp:70
JSON wire envelope used between any client and RemoteServer.
Definition wire.hpp:91