Ejemplo n.º 1
0
 void handle_reconnect(std::unique_lock<std::mutex>& lock, SyncSession& session) const override
 {
     // Ask the binding to retry getting the token for this session.
     std::shared_ptr<SyncSession> session_ptr = session.shared_from_this();
     lock.unlock();
     session.m_config.bind_session_handler(session_ptr->m_realm_path, session_ptr->m_config, session_ptr);
 }
Ejemplo n.º 2
0
 bool access_token_expired(std::unique_lock<std::mutex>& lock, SyncSession& session) const override
 {
     session.advance_state(lock, waiting_for_access_token);
     std::shared_ptr<SyncSession> session_ptr = session.shared_from_this();
     lock.unlock();
     session.m_config.bind_session_handler(session_ptr->m_realm_path, session_ptr->m_config, session_ptr);
     return false;
 }
Ejemplo n.º 3
0
    void enter_state(std::unique_lock<std::mutex>& lock, SyncSession& session) const override
    {
        // If we have no session, we cannot possibly upload anything.
        if (!session.m_session) {
            session.advance_state(lock, inactive);
            return;
        }

        size_t current_death_count = ++session.m_death_count;
        std::weak_ptr<SyncSession> weak_session = session.shared_from_this();
        session.m_session->async_wait_for_upload_completion([weak_session, current_death_count](std::error_code) {
            if (auto session = weak_session.lock()) {
                std::unique_lock<std::mutex> lock(session->m_state_mutex);
                if (session->m_state == &State::dying && session->m_death_count == current_death_count) {
                    session->advance_state(lock, inactive);
                }
            }
        });
    }