mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-23 13:04:23 +00:00
Use new alert dispathing API
This commit is contained in:
parent
14b867e1f6
commit
a318040eaa
@ -48,8 +48,6 @@
|
|||||||
#include <queue>
|
#include <queue>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <boost/bind.hpp>
|
|
||||||
|
|
||||||
#include <libtorrent/alert_types.hpp>
|
#include <libtorrent/alert_types.hpp>
|
||||||
#include <libtorrent/bencode.hpp>
|
#include <libtorrent/bencode.hpp>
|
||||||
#include <libtorrent/error_code.hpp>
|
#include <libtorrent/error_code.hpp>
|
||||||
@ -227,7 +225,17 @@ Session::Session(QObject *parent)
|
|||||||
|
|
||||||
logger->addMessage(tr("Peer ID: ") + Utils::String::fromStdString(fingerprint.to_string()));
|
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
|
// Enabling plugins
|
||||||
//m_nativeSession->add_extension(&libt::create_metadata_plugin);
|
//m_nativeSession->add_extension(&libt::create_metadata_plugin);
|
||||||
@ -1638,7 +1646,7 @@ void Session::saveResumeData()
|
|||||||
generateResumeData(true);
|
generateResumeData(true);
|
||||||
|
|
||||||
while (m_numResumeData > 0) {
|
while (m_numResumeData > 0) {
|
||||||
QVector<libt::alert *> alerts;
|
std::vector<libt::alert *> alerts;
|
||||||
getPendingAlerts(alerts, 30 * 1000);
|
getPendingAlerts(alerts, 30 * 1000);
|
||||||
if (alerts.empty()) {
|
if (alerts.empty()) {
|
||||||
std::cerr << " aborting with " << m_numResumeData
|
std::cerr << " aborting with " << m_numResumeData
|
||||||
@ -1647,7 +1655,7 @@ void Session::saveResumeData()
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (libt::alert *const a, alerts) {
|
for (const auto a: alerts) {
|
||||||
switch (a->type()) {
|
switch (a->type()) {
|
||||||
case libt::save_resume_data_failed_alert::alert_type:
|
case libt::save_resume_data_failed_alert::alert_type:
|
||||||
case libt::save_resume_data_alert::alert_type:
|
case libt::save_resume_data_alert::alert_type:
|
||||||
@ -1656,8 +1664,9 @@ void Session::saveResumeData()
|
|||||||
torrent->handleAlert(a);
|
torrent->handleAlert(a);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
#if LIBTORRENT_VERSION_NUM < 10100
|
||||||
delete a;
|
delete a;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2282,41 +2291,51 @@ void Session::handleIPFilterError()
|
|||||||
emit ipFilterParsed(true, 0);
|
emit ipFilterParsed(true, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if LIBTORRENT_VERSION_NUM < 10100
|
||||||
void Session::dispatchAlerts(std::auto_ptr<libt::alert> alertPtr)
|
void Session::dispatchAlerts(std::auto_ptr<libt::alert> alertPtr)
|
||||||
{
|
{
|
||||||
QMutexLocker lock(&m_alertsMutex);
|
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) {
|
if (wasEmpty) {
|
||||||
m_alertsWaitCondition.wakeAll();
|
m_alertsWaitCondition.wakeAll();
|
||||||
QMetaObject::invokeMethod(this, "readAlerts", Qt::QueuedConnection);
|
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());
|
Q_ASSERT(out.empty());
|
||||||
|
|
||||||
|
#if LIBTORRENT_VERSION_NUM < 10100
|
||||||
QMutexLocker lock(&m_alertsMutex);
|
QMutexLocker lock(&m_alertsMutex);
|
||||||
|
|
||||||
if (m_alerts.empty())
|
if (m_alerts.empty())
|
||||||
m_alertsWaitCondition.wait(&m_alertsMutex, time);
|
m_alertsWaitCondition.wait(&m_alertsMutex, time);
|
||||||
|
|
||||||
m_alerts.swap(out);
|
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
|
// Read alerts sent by the BitTorrent session
|
||||||
void Session::readAlerts()
|
void Session::readAlerts()
|
||||||
{
|
{
|
||||||
QVector<libt::alert *> alerts;
|
std::vector<libt::alert *> alerts;
|
||||||
getPendingAlerts(alerts);
|
getPendingAlerts(alerts);
|
||||||
|
|
||||||
foreach (libt::alert *const a, alerts) {
|
for (const auto a: alerts) {
|
||||||
handleAlert(a);
|
handleAlert(a);
|
||||||
|
#if LIBTORRENT_VERSION_NUM < 10100
|
||||||
delete a;
|
delete a;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -388,8 +388,10 @@ namespace BitTorrent
|
|||||||
|
|
||||||
void saveResumeData();
|
void saveResumeData();
|
||||||
|
|
||||||
|
#if LIBTORRENT_VERSION_NUM < 10100
|
||||||
void dispatchAlerts(std::auto_ptr<libtorrent::alert> alertPtr);
|
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;
|
SettingsStorage *m_settings;
|
||||||
|
|
||||||
@ -437,9 +439,11 @@ namespace BitTorrent
|
|||||||
TorrentStatusReport m_torrentStatusReport;
|
TorrentStatusReport m_torrentStatusReport;
|
||||||
QStringMap m_categories;
|
QStringMap m_categories;
|
||||||
|
|
||||||
|
#if LIBTORRENT_VERSION_NUM < 10100
|
||||||
QMutex m_alertsMutex;
|
QMutex m_alertsMutex;
|
||||||
QWaitCondition m_alertsWaitCondition;
|
QWaitCondition m_alertsWaitCondition;
|
||||||
QVector<libtorrent::alert *> m_alerts;
|
std::vector<libtorrent::alert *> m_alerts;
|
||||||
|
#endif
|
||||||
|
|
||||||
QNetworkConfigurationManager m_networkManager;
|
QNetworkConfigurationManager m_networkManager;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user