Let the user describe a network endpoint in a few Forma windows.
Chains pickers and one line prompts, the way choose_camera() chains its two pickers, and blocks until the user finishes or closes a window. It must not be called from the event thread. Portal::Forma must be initialized and the engine running. Nothing is opened: the result is a description to hand to on_message_received(), or to Portal::Network::to_stream_config() for a sink.
The first window picks the transport and whether to listen or connect. Then:
- Unix socket, listen: a socket name, placed in the runtime directory.
- Unix socket, connect: a pick from the sockets in the runtime directory, or a name or path to type when there are none.
- TCP or UDP, listen or receive: a port.
- TCP or UDP, connect or send: "host:port", with an IPv6 host in brackets.
- Unix socket and TCP: how messages are delimited, as lines, length prefixed bytes or raw bytes.
Text that is not valid is tinted and cannot be accepted.
- Returns
- The endpoint, or nothing if any window was closed or cancelled.
Definition at line 491 of file Chronie.cpp.
492{
493 const std::vector<EndpointChoice> kinds {
500 };
501
503 [](const EndpointChoice& choice) { return choice.label; });
504 if (!kind) {
505 return std::nullopt;
506 }
507
510 info.role = kind->role;
512
514 if (listens) {
515 const auto name =
ask_one(
"Socket name",
"mayaflux.sock", is_socket_name);
516 if (!name) {
517 return std::nullopt;
518 }
519 info.local_path = *name;
520 } else {
521 const auto path = choose_socket_to_connect();
522 if (!path) {
523 return std::nullopt;
524 }
525 info.remote_path = *path;
526 }
527 } else if (listens) {
528 const auto text =
ask_one(
"Port to listen on",
"9000", is_port);
529 if (!text) {
530 return std::nullopt;
531 }
533 } else {
534 const auto text =
ask_one(
"Host and port",
"127.0.0.1:9000", is_host_port);
535 if (!text) {
536 return std::nullopt;
537 }
539 info.remote_address = target.host;
540 info.remote_port = target.port;
541 }
542
543 if (has_stream_framing(info.transport)) {
544 const std::vector<FramingChoice> framings {
548 };
549
551 [](const FramingChoice& choice) { return choice.label; });
552 if (!framing) {
553 return std::nullopt;
554 }
555 info.framing = framing->framing;
556 }
557
558 info.label = describe_endpoint(info);
559 return info;
560}
std::optional< HostPort > parse_host_port(std::string_view text)
Read "host:port", where the host is a name, an IPv4 address or a bracketed IPv6 address.
constexpr std::optional< uint16_t > parse_port(std::string_view text) noexcept
Read a port number, 1 to 65535.
std::optional< std::string > ask_one(std::string title, std::string initial, Portal::Forma::AskValidator validator)
Open a text prompt and wait for the text.
std::optional< T > pick_one(std::string title, std::vector< T > items, std::function< std::string(const T &)> label)
Open a picker and wait for the choice.
NetworkTransport transport
Describes one logical send/receive endpoint managed by a backend.
References ask_one(), MayaFlux::Core::BIDIRECTIONAL, MayaFlux::Core::EndpointInfo::framing, MayaFlux::Core::EndpointInfo::label, MayaFlux::Core::LENGTH_PREFIX, MayaFlux::Core::LINE, MayaFlux::Core::EndpointInfo::local_path, MayaFlux::Core::EndpointInfo::local_port, MayaFlux::Core::NONE, MayaFlux::Transitive::Protocol::parse_host_port(), MayaFlux::Transitive::Protocol::parse_port(), pick_one(), MayaFlux::Core::RECEIVE, MayaFlux::Core::EndpointInfo::remote_address, MayaFlux::Core::EndpointInfo::remote_path, MayaFlux::Core::EndpointInfo::remote_port, MayaFlux::Core::EndpointInfo::role, MayaFlux::Core::SEND, MayaFlux::Core::TCP, MayaFlux::Core::EndpointInfo::transport, MayaFlux::Core::UDP, and MayaFlux::Core::UDS.