void blocking_connection_impl::wait(const condition &condition, const std::string &msg, duration wait_timeout) { reactor& reactor = container_->reactor(); if (wait_timeout == duration(-1)) wait_timeout = container_->reactor().timeout(); if (wait_timeout == duration::FOREVER) { while (!condition()) { reactor.process(); } } else { save_timeout st(reactor); reactor.timeout(wait_timeout); pn_timestamp_t deadline = pn_reactor_mark(pn_cast(&reactor)) + wait_timeout.milliseconds; while (!condition()) { reactor.process(); if (!condition()) { pn_timestamp_t now = pn_reactor_mark(pn_cast(&reactor)); if (now < deadline) reactor.timeout(duration(deadline - now)); else throw timeout_error("connection timed out " + msg); } } } }
bool encoder::encode(char* buffer, size_t& size) { save_state ss(pn_cast(this)); // In case of error ssize_t result = pn_data_encode(pn_cast(this), buffer, size); if (result == PN_OVERFLOW) { result = pn_data_encoded_size(pn_cast(this)); if (result >= 0) { size = result; return false; } } check(result, pn_cast(this)); size = result; ss.cancel(); // Don't restore state, all is well. pn_data_clear(pn_cast(this)); return true; }
blocking_connection_impl::blocking_connection_impl(const url& url, duration timeout) : container_(new container()) { container_->reactor().start(); container_->reactor().timeout(timeout); connection_ = container_->connect(url, this).ptr(); // Set this as handler. wait(connection_opening(pn_cast(connection_.get()))); }
session& connection::default_session() { struct connection_context& ctx = connection_context::get(pn_cast(this)); if (!ctx.default_session) { ctx.default_session = &create_session(); ctx.default_session->open(); } return *ctx.default_session; }
encoder& operator<<(encoder& e, const start& s) { switch (s.type) { case ARRAY: pn_data_put_array(pn_cast(&e), s.is_described, pn_type_t(s.element)); break; case MAP: pn_data_put_map(pn_cast(&e)); break; case LIST: pn_data_put_list(pn_cast(&e)); break; case DESCRIBED: pn_data_put_described(pn_cast(&e)); break; default: throw encode_error(MSG("" << s.type << " is not a container type")); } pn_data_enter(pn_cast(&e)); return e; }
encoder& operator<<(encoder& e, amqp_long value) { return insert(e, pn_cast(&e), value, pn_data_put_long); }
encoder& operator<<(encoder& e, amqp_timestamp value) { return insert(e, pn_cast(&e), value, pn_data_put_timestamp); }
data& encoder::data() { return *data::cast(pn_cast(this)); }
terminus& link::remote_target() const { return *terminus::cast(pn_link_remote_target(pn_cast(this))); }
encoder& operator<<(encoder& e, amqp_symbol value) { return insert(e, pn_cast(&e), value, pn_data_put_symbol); }
encoder& operator<<(encoder& e, const data& v) { if (pn_cast(&e) == pn_cast(&v)) throw encode_error("cannot insert into self"); check(pn_data_append(pn_cast(&e), pn_cast(&v)), pn_cast(&e)); return e; }
endpoint::state link::state() const { return pn_link_state(pn_cast(this)); }
encoder& operator<<(encoder& e, amqp_decimal128 value) { return insert(e, pn_cast(&e), value, pn_data_put_decimal128); }
void link::handler(class handler &h) { pn_record_t *record = pn_link_attachments(pn_cast(this)); connection_context& cc(connection_context::get(pn_cast(&connection()))); counted_ptr<pn_handler_t> chandler = cc.container_impl->cpp_handler(&h); pn_record_set_handler(record, chandler.get()); }
void link::detach_handler() { pn_record_t *record = pn_link_attachments(pn_cast(this)); pn_record_set_handler(record, 0); }
class session &link::session() const { return *session::cast(pn_link_session(pn_cast(this))); }
class connection &link::connection() const { return *connection::cast(pn_session_connection(pn_link_session(pn_cast(this)))); }
std::string link::name() const { return std::string(pn_link_name(pn_cast(this)));}
encoder& operator<<(encoder& e, amqp_float value) { return insert(e, pn_cast(&e), value, pn_data_put_float); }
delivery& blocking_sender::send(const message_value &msg, duration timeout) { delivery& dlv = sender().send(msg); connection_.impl_->wait(delivery_settled(pn_cast(&dlv)), "sending on sender " + link_->name(), timeout); return dlv; }
encoder& operator<<(encoder& e, amqp_double value) { return insert(e, pn_cast(&e), value, pn_data_put_double); }
encoder& operator<<(encoder& e, finish) { pn_data_exit(pn_cast(&e)); return e; }
encoder& operator<<(encoder& e, amqp_uuid value) { return insert(e, pn_cast(&e), value, pn_data_put_uuid); }
int link::credit() const { return pn_link_credit(pn_cast(this)); }
encoder& operator<<(encoder& e, amqp_binary value) { return insert(e, pn_cast(&e), value, pn_data_put_binary); }
encoder& operator<<(encoder& e, amqp_boolean value) { return insert(e, pn_cast(&e), value, pn_data_put_bool); }
const receiver* link::receiver() const { return pn_link_is_receiver(pn_cast(this)) ? reinterpret_cast<const class receiver*>(this) : 0; }
encoder& operator<<(encoder& e, amqp_char value) { return insert(e, pn_cast(&e), value, pn_data_put_char); }
encoder& operator<<(encoder& e, amqp_null) { pn_data_put_null(pn_cast(&e)); return e; }
terminus& link::remote_source() const { return *terminus::cast(pn_link_remote_source(pn_cast(this))); }