Malloy
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | Friends | List of all members
malloy::client::controller Class Reference

#include <controller.hpp>

Classes

struct  config
 

Public Types

using session = malloy::detail::controller_run_result< std::shared_ptr< boost::asio::ssl::context > >
 

Public Member Functions

 controller (config cfg)
 
 ~controller ()=default
 
bool init_tls ()
 
template<malloy::http::concepts::body ReqBody, typename Callback , concepts::response_filter Filter = detail::default_resp_filter>
requires concepts::http_callback<Callback, Filter>
auto http_request (malloy::http::request< ReqBody > req, Callback &&done, Filter filter={}) -> std::future< malloy::error_code >
 
template<malloy::http::concepts::body ReqBody, typename Callback , concepts::response_filter Filter = detail::default_resp_filter>
requires concepts::http_callback<Callback, Filter>
auto https_request (malloy::http::request< ReqBody > req, Callback &&done, Filter filter={}) -> std::future< malloy::error_code >
 
void wss_connect (const std::string &host, std::uint16_t port, const std::string &resource, std::invocable< malloy::error_code, std::shared_ptr< websocket::connection > > auto &&handler)
 Same as ws_connect() but uses TLS.
 
void add_ca_file (const std::filesystem::path &file)
 Load a certificate authority for use with TLS validation.
 
void add_ca (const std::string &contents)
 Like add_ca_file(std::filesystem::path) but loads from an in-memory string.
 
void ws_connect (const std::string &host, std::uint16_t port, const std::string &resource, std::invocable< malloy::error_code, std::shared_ptr< websocket::connection > > auto &&handler)
 

Friends

auto start (controller &ctrl) -> session
 

Detailed Description

High-level controller for client activities.

Member Typedef Documentation

◆ session

using malloy::client::controller::session = malloy::detail::controller_run_result<std::shared_ptr<boost::asio::ssl::context> >

Session type.

Constructor & Destructor Documentation

◆ controller()

controller::controller ( config  cfg)
explicit

Constructor.

Parameters
cfgThe configuration.

◆ ~controller()

malloy::client::controller::~controller ( )
default

Destructor.

Member Function Documentation

◆ add_ca()

void controller::add_ca ( const std::string &  contents)

Like add_ca_file(std::filesystem::path) but loads from an in-memory string.

Warning
tls_init() MUST be called before this.
Parameters
contentsThe certificate to be added to the keychain
See also
add_ca_file()

◆ add_ca_file()

void controller::add_ca_file ( const std::filesystem::path &  file)

Load a certificate authority for use with TLS validation.

Warning
tls_init() MUST be called before this.
Parameters
fileThe path to the certificate to be added to the keychain
See also
add_ca()

◆ http_request()

template<malloy::http::concepts::body ReqBody, typename Callback , concepts::response_filter Filter = detail::default_resp_filter>
requires concepts::http_callback<Callback, Filter>
auto malloy::client::controller::http_request ( malloy::http::request< ReqBody >  req,
Callback &&  done,
Filter  filter = {} 
) -> std::future<malloy::error_code>
inline

Perform a plain (unencrypted) HTTP request.

Parameters
reqThe HTTP request.
doneCallback invoked on completion. Must satisfy http_callback (Client Concepts) with Filter
filterFilter to use when parsing the response. Must satisfy response_filter Client Concepts
Returns
A future for reporting errors. Will be filled with a falsy error_code on success.
See also
https_request()

◆ https_request()

template<malloy::http::concepts::body ReqBody, typename Callback , concepts::response_filter Filter = detail::default_resp_filter>
requires concepts::http_callback<Callback, Filter>
auto malloy::client::controller::https_request ( malloy::http::request< ReqBody >  req,
Callback &&  done,
Filter  filter = {} 
) -> std::future<malloy::error_code>
inline

Same as http_request() but encrypted with TLS.

See also
http_request()

◆ init_tls()

bool controller::init_tls ( )

Initialize the TLS context.

Returns
Whether initialization was successful.

◆ ws_connect()

void malloy::client::controller::ws_connect ( const std::string &  host,
std::uint16_t  port,
const std::string &  resource,
std::invocable< malloy::error_code, std::shared_ptr< websocket::connection > > auto &&  handler 
)
inline

Create a websocket connection.

Parameters
hostThe host.
portThe port.
resourceThe suburl to connect to (e.g. /api/websocket)
handlerCallback invoked when the connection is established (successfully or otherwise). Must satisfy f(e, c), where:
Warning
If the error code passed to handler is truthy (an error) the connection will be nullptr
See also
wss_connect()

◆ wss_connect()

void malloy::client::controller::wss_connect ( const std::string &  host,
std::uint16_t  port,
const std::string &  resource,
std::invocable< malloy::error_code, std::shared_ptr< websocket::connection > > auto &&  handler 
)
inline

Same as ws_connect() but uses TLS.

Warning
tls_init MUST be called before this
See also
ws_connect()

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