morph 0.1.0
Asynchronous bridge between GUI thread and business models
Loading...
Searching...
No Matches
transport.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
2#pragma once
3
4#include <expected>
5#include <memory>
6#include <string>
7
8#include "../core/backend.hpp"
10#include "../ui/frontend.hpp"
11
12/// @file
13/// @brief The transport a remote client connects with, chosen by the frontend it runs under (spec 4 ยง3).
14///
15/// Specified in `docs/spec/client/client.md`.
16
17namespace morph::client {
18
19/// @brief A connection to a server: the bridge's backend and its request verb, which are one object.
21 /// @brief The backend.
22 std::unique_ptr<backend::detail::IBackend> backend;
23 /// @brief The same object's `IEnvelopeTransport`; owned by `backend`.
25};
26
27/// @brief Connects to @p url with the transport the frontend calls for: a `SocketBackend` on the context's I/O loop
28/// when it has one (the terminal frontend), a `QtWebSocketBackend` otherwise (Qt Quick).
29/// @param context The running frontend's context.
30/// @param url `ws://host:port`.
31/// @return The transport, connecting; or why there is none: the transport the frontend needs is not built, or the
32/// URL is refused.
33[[nodiscard]] std::expected<RemoteTransport, std::string> makeTransport(ui::AppContext& context,
34 std::string const& url);
35
36namespace detail {
37
38/// @brief A `SocketBackend` on @p context's loop; defined only where `morph::net` is built.
39/// @param context The context; its loop must not be null.
40/// @param url The server.
41/// @return The transport, or why the URL is refused.
42[[nodiscard]] std::expected<RemoteTransport, std::string> socketTransport(ui::AppContext& context,
43 std::string const& url);
44
45/// @brief A `QtWebSocketBackend`; defined only where `morph::qt` is built.
46/// @param url The server.
47/// @return The transport, or why the URL is refused.
48[[nodiscard]] std::expected<RemoteTransport, std::string> qtTransport(std::string const& url);
49
50} // namespace detail
51
52} // namespace morph::client
What a wire transport offers beside IBackend: one request, one reply, matched by callId.
What a frontend lends the source it opens and the screens it mounts.
Definition frontend.hpp:50
IEnvelopeTransport: a transport that sends a request envelope of a kind its backend verbs do not buil...
A connection to a server: the bridge's backend and its request verb, which are one object.
Definition transport.hpp:20
std::unique_ptr< backend::detail::IBackend > backend
The backend.
Definition transport.hpp:22
backend::IEnvelopeTransport * requests
The same object's IEnvelopeTransport; owned by backend.
Definition transport.hpp:24
std::expected< RemoteTransport, std::string > socketTransport(ui::AppContext &context, std::string const &url)
A SocketBackend on context's loop; defined only where morph::net is built.
std::expected< RemoteTransport, std::string > makeTransport(ui::AppContext &context, std::string const &url)
Connects to url with the transport the frontend calls for: a SocketBackend on the context's I/O loop ...
std::expected< RemoteTransport, std::string > qtTransport(std::string const &url)
A QtWebSocketBackend; defined only where morph::qt is built.
The frontend seam: main picks a frontend at runtime, and the frontend runs whatever an AppSource open...