forked from premiere/premiere-libtorrent
added alert for torrent state changes. Fixes #360
This commit is contained in:
parent
d2b37572fa
commit
ecb538b4b2
|
@ -584,6 +584,10 @@ libtorrent::torrent_handle get_active_torrent(handles_t const& handles)
|
|||
return i->second;
|
||||
}
|
||||
|
||||
static char const* state_str[] =
|
||||
{"checking (q)", "checking", "connecting", "dl metadata"
|
||||
, "downloading", "finished", "seeding", "allocating"};
|
||||
|
||||
int main(int ac, char* av[])
|
||||
{
|
||||
#if BOOST_VERSION < 103400
|
||||
|
@ -1181,6 +1185,12 @@ int main(int ac, char* av[])
|
|||
if (h.is_paused() && !h.is_auto_managed()) ses.remove_torrent(h);
|
||||
}
|
||||
}
|
||||
else if (state_changed_alert* p = dynamic_cast<state_changed_alert*>(a.get()))
|
||||
{
|
||||
std::string name;
|
||||
if (p->handle.is_valid()) name = p->handle.name();
|
||||
event_string << "(" << name << ") " << p->msg() << " " << state_str[p->state];
|
||||
}
|
||||
else if (torrent_alert* p = dynamic_cast<torrent_alert*>(a.get()))
|
||||
{
|
||||
std::string name;
|
||||
|
@ -1266,13 +1276,7 @@ int main(int ac, char* av[])
|
|||
|
||||
if (paused && !auto_managed) out << "paused";
|
||||
else if (paused && auto_managed) out << "queued";
|
||||
else
|
||||
{
|
||||
static char const* state_str[] =
|
||||
{"checking (q)", "checking", "connecting", "dl metadata"
|
||||
, "downloading", "finished", "seeding", "allocating"};
|
||||
out << state_str[s.state];
|
||||
}
|
||||
else out << state_str[s.state];
|
||||
|
||||
int seeds = 0;
|
||||
int downloaders = 0;
|
||||
|
|
|
@ -68,6 +68,21 @@ namespace libtorrent
|
|||
std::string name;
|
||||
};
|
||||
|
||||
struct TORRENT_EXPORT state_changed_alert: torrent_alert
|
||||
{
|
||||
state_changed_alert(torrent_handle const& h
|
||||
, torrent_status::state_t const& state_
|
||||
, std::string const& msg)
|
||||
: torrent_alert(h, alert::info, msg)
|
||||
, state(state_)
|
||||
{}
|
||||
|
||||
virtual std::auto_ptr<alert> clone() const
|
||||
{ return std::auto_ptr<alert>(new state_changed_alert(*this)); }
|
||||
|
||||
torrent_status::state_t state;
|
||||
};
|
||||
|
||||
struct TORRENT_EXPORT tracker_alert: torrent_alert
|
||||
{
|
||||
tracker_alert(torrent_handle const& h
|
||||
|
|
|
@ -167,6 +167,7 @@ namespace libtorrent
|
|||
bool is_aborted() const { return m_abort; }
|
||||
|
||||
torrent_status::state_t state() const { return m_state; }
|
||||
void set_state(torrent_status::state_t s);
|
||||
|
||||
session_settings const& settings() const;
|
||||
|
||||
|
|
|
@ -446,7 +446,7 @@ namespace libtorrent
|
|||
std::copy(url_seeds.begin(), url_seeds.end(), std::inserter(m_web_seeds
|
||||
, m_web_seeds.begin()));
|
||||
|
||||
m_state = torrent_status::queued_for_checking;
|
||||
set_state(torrent_status::queued_for_checking);
|
||||
|
||||
if (m_resume_entry.type() == lazy_entry::dict_t)
|
||||
{
|
||||
|
@ -654,7 +654,7 @@ namespace libtorrent
|
|||
, int((m_torrent_file->total_size()+m_block_size-1)/m_block_size));
|
||||
// assume that we don't have anything
|
||||
m_files_checked = false;
|
||||
m_state = torrent_status::queued_for_checking;
|
||||
set_state(torrent_status::queued_for_checking);
|
||||
|
||||
if (m_auto_managed)
|
||||
set_queue_position((std::numeric_limits<int>::max)());
|
||||
|
@ -691,7 +691,7 @@ namespace libtorrent
|
|||
|
||||
void torrent::start_checking()
|
||||
{
|
||||
m_state = torrent_status::checking_files;
|
||||
set_state(torrent_status::checking_files);
|
||||
|
||||
m_storage->async_check_files(bind(
|
||||
&torrent::on_piece_checked
|
||||
|
@ -3061,7 +3061,7 @@ namespace libtorrent
|
|||
, "torrent has finished downloading"));
|
||||
}
|
||||
|
||||
m_state = torrent_status::finished;
|
||||
set_state(torrent_status::finished);
|
||||
set_queue_position(-1);
|
||||
|
||||
// we have to call completed() before we start
|
||||
|
@ -3102,7 +3102,7 @@ namespace libtorrent
|
|||
INVARIANT_CHECK;
|
||||
|
||||
TORRENT_ASSERT(!is_finished());
|
||||
m_state = torrent_status::downloading;
|
||||
set_state(torrent_status::downloading);
|
||||
set_queue_position((std::numeric_limits<int>::max)());
|
||||
}
|
||||
|
||||
|
@ -3116,7 +3116,7 @@ namespace libtorrent
|
|||
// make the next tracker request
|
||||
// be a completed-event
|
||||
m_event = tracker_request::completed;
|
||||
m_state = torrent_status::seeding;
|
||||
set_state(torrent_status::seeding);
|
||||
force_tracker_request();
|
||||
}
|
||||
|
||||
|
@ -3188,7 +3188,7 @@ namespace libtorrent
|
|||
TORRENT_ASSERT(m_torrent_file->is_valid());
|
||||
INVARIANT_CHECK;
|
||||
|
||||
m_state = torrent_status::connecting_to_tracker;
|
||||
set_state(torrent_status::connecting_to_tracker);
|
||||
|
||||
if (!is_seed())
|
||||
{
|
||||
|
@ -4039,6 +4039,17 @@ namespace libtorrent
|
|||
}
|
||||
}
|
||||
|
||||
void torrent::set_state(torrent_status::state_t s)
|
||||
{
|
||||
if (m_state == s) return;
|
||||
m_state = s;
|
||||
if (m_ses.m_alerts.should_post(alert::info))
|
||||
{
|
||||
m_ses.m_alerts.post_alert(state_changed_alert(get_handle()
|
||||
, s, "torrent status changed"));
|
||||
}
|
||||
}
|
||||
|
||||
torrent_status torrent::status() const
|
||||
{
|
||||
INVARIANT_CHECK;
|
||||
|
|
Loading…
Reference in New Issue