Browse Source

Merge pull request #5258 from glassez/alert_notify

Use new alert dispathing API. Fixes compilation with libtorrent-1.1.x
adaptive-webui-19844
sledgehammer999 9 years ago
parent
commit
673b86c6e3
  1. 41
      src/base/bittorrent/session.cpp
  2. 8
      src/base/bittorrent/session.h

41
src/base/bittorrent/session.cpp

@ -48,8 +48,6 @@ @@ -48,8 +48,6 @@
#include <queue>
#include <vector>
#include <boost/bind.hpp>
#include <libtorrent/alert_types.hpp>
#include <libtorrent/bencode.hpp>
#include <libtorrent/error_code.hpp>
@ -227,7 +225,17 @@ Session::Session(QObject *parent) @@ -227,7 +225,17 @@ Session::Session(QObject *parent)
logger->addMessage(tr("Peer ID: ") + Utils::String::fromStdString(fingerprint.to_string()));
m_nativeSession->set_alert_dispatch(boost::bind(&Session::dispatchAlerts, this, _1));
#if LIBTORRENT_VERSION_NUM < 10100
m_nativeSession->set_alert_dispatch([this](std::auto_ptr<libt::alert> alertPtr)
{
dispatchAlerts(alertPtr);
});
#else
m_nativeSession->set_alert_notify([this]()
{
QMetaObject::invokeMethod(this, "readAlerts", Qt::QueuedConnection);
});
#endif
// Enabling plugins
//m_nativeSession->add_extension(&libt::create_metadata_plugin);
@ -1638,7 +1646,7 @@ void Session::saveResumeData() @@ -1638,7 +1646,7 @@ void Session::saveResumeData()
generateResumeData(true);
while (m_numResumeData > 0) {
QVector<libt::alert *> alerts;
std::vector<libt::alert *> alerts;
getPendingAlerts(alerts, 30 * 1000);
if (alerts.empty()) {
std::cerr << " aborting with " << m_numResumeData
@ -1647,7 +1655,7 @@ void Session::saveResumeData() @@ -1647,7 +1655,7 @@ void Session::saveResumeData()
break;
}
foreach (libt::alert *const a, alerts) {
for (const auto a: alerts) {
switch (a->type()) {
case libt::save_resume_data_failed_alert::alert_type:
case libt::save_resume_data_alert::alert_type:
@ -1656,8 +1664,9 @@ void Session::saveResumeData() @@ -1656,8 +1664,9 @@ void Session::saveResumeData()
torrent->handleAlert(a);
break;
}
#if LIBTORRENT_VERSION_NUM < 10100
delete a;
#endif
}
}
}
@ -2282,41 +2291,51 @@ void Session::handleIPFilterError() @@ -2282,41 +2291,51 @@ void Session::handleIPFilterError()
emit ipFilterParsed(true, 0);
}
#if LIBTORRENT_VERSION_NUM < 10100
void Session::dispatchAlerts(std::auto_ptr<libt::alert> alertPtr)
{
QMutexLocker lock(&m_alertsMutex);
bool wasEmpty = m_alerts.isEmpty();
bool wasEmpty = m_alerts.empty();
m_alerts.append(alertPtr.release());
m_alerts.push_back(alertPtr.release());
if (wasEmpty) {
m_alertsWaitCondition.wakeAll();
QMetaObject::invokeMethod(this, "readAlerts", Qt::QueuedConnection);
}
}
#endif
void Session::getPendingAlerts(QVector<libt::alert *> &out, ulong time)
void Session::getPendingAlerts(std::vector<libt::alert *> &out, ulong time)
{
Q_ASSERT(out.empty());
#if LIBTORRENT_VERSION_NUM < 10100
QMutexLocker lock(&m_alertsMutex);
if (m_alerts.empty())
m_alertsWaitCondition.wait(&m_alertsMutex, time);
m_alerts.swap(out);
#else
if (time > 0)
m_nativeSession->wait_for_alert(libt::milliseconds(time));
m_nativeSession->pop_alerts(&out);
#endif
}
// Read alerts sent by the BitTorrent session
void Session::readAlerts()
{
QVector<libt::alert *> alerts;
std::vector<libt::alert *> alerts;
getPendingAlerts(alerts);
foreach (libt::alert *const a, alerts) {
for (const auto a: alerts) {
handleAlert(a);
#if LIBTORRENT_VERSION_NUM < 10100
delete a;
#endif
}
}

8
src/base/bittorrent/session.h

@ -388,8 +388,10 @@ namespace BitTorrent @@ -388,8 +388,10 @@ namespace BitTorrent
void saveResumeData();
#if LIBTORRENT_VERSION_NUM < 10100
void dispatchAlerts(std::auto_ptr<libtorrent::alert> alertPtr);
void getPendingAlerts(QVector<libtorrent::alert *> &out, ulong time = 0);
#endif
void getPendingAlerts(std::vector<libtorrent::alert *> &out, ulong time = 0);
SettingsStorage *m_settings;
@ -437,9 +439,11 @@ namespace BitTorrent @@ -437,9 +439,11 @@ namespace BitTorrent
TorrentStatusReport m_torrentStatusReport;
QStringMap m_categories;
#if LIBTORRENT_VERSION_NUM < 10100
QMutex m_alertsMutex;
QWaitCondition m_alertsWaitCondition;
QVector<libtorrent::alert *> m_alerts;
std::vector<libtorrent::alert *> m_alerts;
#endif
QNetworkConfigurationManager m_networkManager;

Loading…
Cancel
Save