void messaging_adapter::on_session_remote_open(proton_event &pe) {
    pn_session_t *session = pn_event_session(pe.pn_event());
    class session s(make_wrapper(session));
    delegate_.on_session_open(s);
    if (!is_local_open(pn_session_state(session)) && is_local_unititialised(pn_session_state(session))) {
        pn_session_open(session);
    }
}
void messaging_adapter::on_link_remote_open(proton_event &pe) {
    pn_link_t *lnk = pn_event_link(pe.pn_event());
    container& c = pe.container();
    if (pn_link_is_receiver(lnk)) {
        receiver r(make_wrapper<receiver>(lnk));
        delegate_.on_receiver_open(r);
        if (is_local_unititialised(pn_link_state(lnk))) {
            r.open(c.receiver_options());
        }
    } else {
        sender s(make_wrapper<sender>(lnk));
        delegate_.on_sender_open(s);
        if (is_local_unititialised(pn_link_state(lnk))) {
            s.open(c.sender_options());
        }
    }
    credit_topup(lnk);
}
void messaging_adapter::on_connection_remote_open(proton_event &pe) {
    pn_connection_t *conn = pn_event_connection(pe.pn_event());
    connection c(make_wrapper(conn));
    transport t(make_wrapper(pn_event_transport(pe.pn_event())));
    delegate_.on_transport_open(t);
    delegate_.on_connection_open(c);
    if (!is_local_open(pn_connection_state(conn)) && is_local_unititialised(pn_connection_state(conn))) {
        pn_connection_open(conn);
    }
}
void messaging_adapter::on_link_remote_open(event &e) {
    proton_event *pe = dynamic_cast<proton_event*>(&e);
    if (pe) {
        messaging_event mevent(messaging_event::LINK_OPEN, *pe);
        on_link_open(mevent);
        pn_link_t *link = pn_event_link(pe->pn_event());
        if (!is_local_open(pn_link_state(link)) && is_local_unititialised(pn_link_state(link))) {
            pn_link_open(link);
        }
    }
}
void messaging_adapter::on_session_remote_open(event &e) {
    proton_event *pe = dynamic_cast<proton_event*>(&e);
    if (pe) {
        messaging_event mevent(messaging_event::SESSION_OPEN, *pe);
        on_session_open(mevent);
        pn_session_t *session = pn_event_session(pe->pn_event());
        if (!is_local_open(pn_session_state(session)) && is_local_unititialised(pn_session_state(session))) {
            pn_session_open(session);
        }
    }
}
void messaging_adapter::on_connection_remote_open(event &e) {
    proton_event *pe = dynamic_cast<proton_event*>(&e);
    if (pe) {
        pn_connection_t *connection = pn_event_connection(pe->pn_event());
        if (is_local_open(pn_connection_state(connection))) {
            messaging_event mevent(messaging_event::CONNECTION_OPENED, *pe);
            on_connection_opened(mevent);
        }
        else if (is_local_unititialised(pn_connection_state(connection))) {
            messaging_event mevent(messaging_event::CONNECTION_OPENING, *pe);
            on_connection_opening(mevent);
            pn_connection_open(connection);
        }
    }
}