connection_engine::connection_engine(class handler &h, const connection_options& opts) { connection_ = proton::connection(take_ownership(pn_connection()).get()); pn_ptr<pn_transport_t> transport = take_ownership(pn_transport()); pn_ptr<pn_collector_t> collector = take_ownership(pn_collector()); if (!connection_ || !transport || !collector) throw proton::error("engine create"); int err = pn_transport_bind(transport.get(), connection_.pn_object()); if (err) throw error(msg() << "transport bind:" << pn_code(err)); pn_connection_collect(connection_.pn_object(), collector.get()); ctx_ = &connection_engine_context::get(connection_); // Creates context ctx_->engine_handler = &h; ctx_->transport = transport.release(); ctx_->collector = collector.release(); opts.apply(connection_); // Provide defaults for connection_id and link_prefix if not set. std::string cid = connection_.container_id(); if (cid.empty()) { cid = make_id(); pn_connection_set_container(connection_.pn_object(), cid.c_str()); } id_generator &link_gen = connection_context::get(connection_).link_gen; if (link_gen.prefix().empty()) { link_gen.prefix(make_id()+"/"); } }
void connection_engine::configure(const connection_options& opts) { opts.apply(connection_); handler_ = opts.handler(); if (handler_) { collector_ = internal::take_ownership(pn_collector()); pn_connection_collect(unwrap(connection_), collector_.get()); } connection_context::get(connection_).collector = collector_.get(); }
pn_connection_t *pn_reactor_connection(pn_reactor_t *reactor, pn_handler_t *handler) { assert(reactor); pn_connection_t *connection = pn_connection(); pn_record_t *record = pn_connection_attachments(connection); pn_record_set_handler(record, handler); pn_connection_collect(connection, pn_reactor_collector(reactor)); pn_list_add(pn_reactor_children(reactor), connection); pni_record_init_reactor(record, reactor); pn_decref(connection); return connection; }
connection_engine::connection_engine(class container& cont, link_namer& namer, event_loop* loop) : handler_(0), connection_(make_wrapper(internal::take_ownership(pn_connection()).get())), transport_(make_wrapper(internal::take_ownership(pn_transport()).get())), collector_(internal::take_ownership(pn_collector()).get()), container_(cont) { if (!connection_ || !transport_ || !collector_) throw proton::error("connection_engine create failed"); pn_transport_bind(unwrap(transport_), unwrap(connection_)); pn_connection_collect(unwrap(connection_), collector_.get()); connection_context& ctx = connection_context::get(connection_); ctx.container = &container_; ctx.link_gen = &namer; ctx.event_loop.reset(loop); }