1 #ifndef PROTON_IO_CONTAINER_IMPL_BASE_HPP
2 #define PROTON_IO_CONTAINER_IMPL_BASE_HPP
25 #include "./link_namer.hpp"
26 #include "../container.hpp"
46 store(client_copts_, opts);
51 return load(client_copts_);
56 store(server_copts_, opts);
61 return load(server_copts_);
66 store(sender_opts_, opts);
71 return load(sender_opts_);
76 store(receiver_opts_, opts);
81 return load(receiver_opts_);
99 template<
class T,
class Opts>
100 returned<T> open_link(
102 T (
connection::*open_fn)(
const std::string&,
const Opts&))
104 std::string addr =
url(url_str).
path();
105 std::shared_ptr<thread_safe<connection> > ts_connection =
connect(url_str, copts);
106 std::promise<returned<T> > result_promise;
107 auto do_open = [ts_connection, addr, opts, open_fn, &result_promise]() {
111 result_promise.set_value(s);
113 result_promise.set_exception(std::current_exception());
116 ts_connection->event_loop()->inject(do_open);
117 std::future<returned<T> > result_future = result_promise.get_future();
118 if (!result_future.valid())
119 throw error(url_str+
": connection closed");
120 return result_future.get();
123 mutable std::mutex lock_;
124 template <
class T> T load(
const T& v)
const {
125 std::lock_guard<std::mutex> g(lock_);
128 template <
class T>
void store(T& v,
const T& x)
const {
129 std::lock_guard<std::mutex> g(lock_);
132 connection_options client_copts_, server_copts_;
140 #endif // PROTON_IO_CONTAINER_IMPL_BASE_HPP
virtual returned< connection > connect(const std::string &url, const connection_options &)=0
Connect to url and send an open request to the remote peer.
std::string path() const
path is everything after the final "/".
A top-level container of connections, sessions, senders, and receivers.
Definition: container.hpp:59
class receiver_options receiver_options() const
Receiver options applied to receivers created by this container.
Definition: container_impl_base.hpp:80
receiver open_receiver(const std::string &addr)
Open a receiver for addr on default_session().
Options for creating a sender.
Definition: sender_options.hpp:64
void client_connection_options(const connection_options &opts)
Connection options that will be to outgoing connections.
Definition: container_impl_base.hpp:45
A connection to a remote AMQP peer.
Definition: connection.hpp:48
Options for creating a connection.
Definition: connection_options.hpp:67
connection_options server_connection_options() const
Connection options that will be applied to incoming connections.
Definition: container_impl_base.hpp:60
A Proton URL.
Definition: url.hpp:55
Experimental - A base container implementation.
Definition: container_impl_base.hpp:42
returned< sender > open_sender(const std::string &url, const class sender_options &opts, const connection_options &copts)
Open a connection and sender for url.
Definition: container_impl_base.hpp:85
Options for creating a receiver.
Definition: receiver_options.hpp:62
void sender_options(const class sender_options &opts)
Sender options applied to senders created by this container.
Definition: container_impl_base.hpp:65
sender open_sender(const std::string &addr)
Open a sender for addr on default_session().
void receiver_options(const class receiver_options &opts)
Receiver options applied to receivers created by this container.
Definition: container_impl_base.hpp:75
connection_options client_connection_options() const
Connection options that will be to outgoing connections.
Definition: container_impl_base.hpp:50
returned< receiver > open_receiver(const std::string &url, const class receiver_options &opts, const connection_options &copts)
Open a connection and receiver for url.
Definition: container_impl_base.hpp:92
void server_connection_options(const connection_options &opts)
Connection options that will be applied to incoming connections.
Definition: container_impl_base.hpp:55
class sender_options sender_options() const
Sender options applied to senders created by this container.
Definition: container_impl_base.hpp:70
returned< T > make_thread_safe(const T &obj)
Make a thread-safe wrapper for obj.
Definition: thread_safe.hpp:162