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();
}
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::open(const connection_options &opts) {
    connector *connector = dynamic_cast<class connector*>(
        connection_context::get(pn_object()).handler.get());
    if (connector)
        // connector has an internal copy of opts
        connector->apply_options();
    else
        opts.apply(*this);
    pn_connection_open(pn_object());
}
Beispiel #4
0
void connection::open(const connection_options &opts) {
    opts.apply_unbound(*this);
    pn_connection_open(pn_object());
}