X-Git-Url: http://git.maemo.org/git/?a=blobdiff_plain;ds=sidebyside;f=src%2Fengine%2FAlertWaiterThread.cpp;h=4f18636c29f670743977d73f5fa3bdd7a397f21d;hb=f576091800144d69317250a69d40c711505a4f34;hp=7a2f90ffbc45ba00ef13f5a3a42b83b2482118e6;hpb=afa034e0adbbeaf337e34671efd44f5e487c17ba;p=qtrapids diff --git a/src/engine/AlertWaiterThread.cpp b/src/engine/AlertWaiterThread.cpp index 7a2f90f..4f18636 100644 --- a/src/engine/AlertWaiterThread.cpp +++ b/src/engine/AlertWaiterThread.cpp @@ -18,11 +18,20 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ + #include #include "AlertWaiterThread.h" -AlertWaiterThread::AlertWaiterThread(QObject* parent): QThread(parent) +// Constants: +// Timeout for waiting alerts +const libtorrent::time_duration ALERT_WAIT_TIMEOUT + = libtorrent::time_duration(libtorrent::seconds(15)); + + +AlertWaiterThread::AlertWaiterThread(TorrentSession *const session, QObject* parent) : + QThread(parent), + btSession_(session) { } @@ -32,20 +41,31 @@ AlertWaiterThread::~AlertWaiterThread() } +void AlertWaiterThread::allAlerts(bool enable) +{ + // If all enabled, set all alert cateogries: + if (enable) { + btSession_->set_alert_mask(libtorrent::alert::all_categories); + } else { + // Otherwise set to default, which is only error notifications. + btSession_->set_alert_mask(libtorrent::alert::error_notification); + } +} + + void AlertWaiterThread::run() { + Alert const *alertTemp = NULL; while (true) { +#ifdef QTRAPIDS_DEBUG qDebug() << "AlertWaiter running"; - emit alert(); - sleep(2); +#endif + // wait_for_alert() call blocks. Returns libtorrent alert. + // Returns NULL, if no alerts in timeout period. + alertTemp = btSession_->wait_for_alert(ALERT_WAIT_TIMEOUT); + emit alert(alertTemp); + // 2000 us = 2ms. Gives main thread time to handle alert signal. + usleep(2000); } } - - -// =================== SIGNALS ======================= -// AlertWaiterThread::alert() -// { -// } - -