diff --git a/docs/manual.rst b/docs/manual.rst index ef023a871..4c5cd2f91 100644 --- a/docs/manual.rst +++ b/docs/manual.rst @@ -4480,6 +4480,24 @@ upload or download rate performance. }; +state_changed_alert +------------------- + +Generated whenever a torrent changes its state. + +:: + + struct state_changed_alert: torrent_alert + { + // ... + + torrent_status::state_t state; + torrent_status::state_t prev_state; + }; + +``state`` is the new state of the torrent. ``prev_state`` is the previous state. + + metadata_failed_alert --------------------- diff --git a/include/libtorrent/alert_types.hpp b/include/libtorrent/alert_types.hpp index 3522c9164..97641a10b 100644 --- a/include/libtorrent/alert_types.hpp +++ b/include/libtorrent/alert_types.hpp @@ -196,9 +196,11 @@ namespace libtorrent struct TORRENT_EXPORT state_changed_alert: torrent_alert { state_changed_alert(torrent_handle const& h - , torrent_status::state_t const& state_) + , torrent_status::state_t state_ + , torrent_status::state_t prev_state_) : torrent_alert(h) , state(state_) + , prev_state(prev_state_) {} virtual std::auto_ptr clone() const @@ -220,6 +222,7 @@ namespace libtorrent virtual int category() const { return static_category; } torrent_status::state_t state; + torrent_status::state_t prev_state; }; struct TORRENT_EXPORT tracker_error_alert: tracker_alert diff --git a/src/torrent.cpp b/src/torrent.cpp index 6510c6332..26852d0c9 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -4600,9 +4600,9 @@ namespace libtorrent #endif if (m_state == s) return; - m_state = s; if (m_ses.m_alerts.should_post()) - m_ses.m_alerts.post_alert(state_changed_alert(get_handle(), s)); + m_ses.m_alerts.post_alert(state_changed_alert(get_handle(), s, m_state)); + m_state = s; } torrent_status torrent::status() const