DefaultBtAnnounce: Use non-owning raw pointer for downloadContext_

pull/103/head
Tatsuhiro Tsujikawa 2013-06-23 12:14:17 +09:00
parent bfb732c5d4
commit 9db01bed71
4 changed files with 22 additions and 20 deletions

View File

@ -58,9 +58,8 @@
namespace aria2 { namespace aria2 {
DefaultBtAnnounce::DefaultBtAnnounce DefaultBtAnnounce::DefaultBtAnnounce
(const std::shared_ptr<DownloadContext>& downloadContext, (DownloadContext* downloadContext, const Option* option)
const Option* option) : downloadContext_{downloadContext},
: downloadContext_(downloadContext),
trackers_(0), trackers_(0),
prevAnnounceTimer_(0), prevAnnounceTimer_(0),
interval_(DEFAULT_ANNOUNCE_INTERVAL), interval_(DEFAULT_ANNOUNCE_INTERVAL),

View File

@ -50,7 +50,7 @@ class Randomizer;
class DefaultBtAnnounce : public BtAnnounce { class DefaultBtAnnounce : public BtAnnounce {
private: private:
std::shared_ptr<DownloadContext> downloadContext_; DownloadContext* downloadContext_;
int trackers_; int trackers_;
Timer prevAnnounceTimer_; Timer prevAnnounceTimer_;
time_t interval_; time_t interval_;
@ -69,8 +69,7 @@ private:
bool adjustAnnounceList(); bool adjustAnnounceList();
public: public:
DefaultBtAnnounce(const std::shared_ptr<DownloadContext>& downloadContext, DefaultBtAnnounce(DownloadContext* downloadContext, const Option* option);
const Option* option);
virtual ~DefaultBtAnnounce(); virtual ~DefaultBtAnnounce();

View File

@ -343,15 +343,15 @@ void RequestGroup::createInitialCommand
progressInfoFilePtr->setPeerStorage(peerStorage); progressInfoFilePtr->setPeerStorage(peerStorage);
} }
DefaultBtAnnounce* btAnnouncePtr auto btAnnouncePtr = new DefaultBtAnnounce(downloadContext_.get(),
(new DefaultBtAnnounce(downloadContext_, option_.get())); option_.get());
std::shared_ptr<BtAnnounce> btAnnounce(btAnnouncePtr);
btAnnouncePtr->setBtRuntime(btRuntime); btAnnouncePtr->setBtRuntime(btRuntime);
btAnnouncePtr->setPieceStorage(pieceStorage_); btAnnouncePtr->setPieceStorage(pieceStorage_);
btAnnouncePtr->setPeerStorage(peerStorage); btAnnouncePtr->setPeerStorage(peerStorage);
btAnnouncePtr->setUserDefinedInterval btAnnouncePtr->setUserDefinedInterval
(option_->getAsInt(PREF_BT_TRACKER_INTERVAL)); (option_->getAsInt(PREF_BT_TRACKER_INTERVAL));
btAnnouncePtr->shuffleAnnounce(); btAnnouncePtr->shuffleAnnounce();
std::shared_ptr<BtAnnounce> btAnnounce(btAnnouncePtr);
assert(!btRegistry->get(gid_->getNumericId())); assert(!btRegistry->get(gid_->getNumericId()));
btRegistry->put btRegistry->put

View File

@ -151,7 +151,7 @@ void DefaultBtAnnounceTest::testNoMoreAnnounce()
setAnnounceList(dctx_, announceList); setAnnounceList(dctx_, announceList);
DefaultBtAnnounce btAnnounce(dctx_, option_); DefaultBtAnnounce btAnnounce(dctx_.get(), option_);
btAnnounce.setPieceStorage(pieceStorage_); btAnnounce.setPieceStorage(pieceStorage_);
btAnnounce.setPeerStorage(peerStorage_); btAnnounce.setPeerStorage(peerStorage_);
btAnnounce.setBtRuntime(btRuntime_); btAnnounce.setBtRuntime(btRuntime_);
@ -200,7 +200,7 @@ void DefaultBtAnnounceTest::testGetAnnounceUrl()
announceList->append(createAnnounceTier("http://localhost/announce")); announceList->append(createAnnounceTier("http://localhost/announce"));
setAnnounceList(dctx_, announceList); setAnnounceList(dctx_, announceList);
DefaultBtAnnounce btAnnounce(dctx_, option_); DefaultBtAnnounce btAnnounce(dctx_.get(), option_);
btAnnounce.setPieceStorage(pieceStorage_); btAnnounce.setPieceStorage(pieceStorage_);
btAnnounce.setPeerStorage(peerStorage_); btAnnounce.setPeerStorage(peerStorage_);
btAnnounce.setBtRuntime(btRuntime_); btAnnounce.setBtRuntime(btRuntime_);
@ -257,7 +257,7 @@ void DefaultBtAnnounceTest::testGetAnnounceUrl_withQuery()
announceList->append(createAnnounceTier("http://localhost/announce?k=v")); announceList->append(createAnnounceTier("http://localhost/announce?k=v"));
setAnnounceList(dctx_, announceList); setAnnounceList(dctx_, announceList);
DefaultBtAnnounce btAnnounce(dctx_, option_); DefaultBtAnnounce btAnnounce(dctx_.get(), option_);
btAnnounce.setPieceStorage(pieceStorage_); btAnnounce.setPieceStorage(pieceStorage_);
btAnnounce.setPeerStorage(peerStorage_); btAnnounce.setPeerStorage(peerStorage_);
btAnnounce.setBtRuntime(btRuntime_); btAnnounce.setBtRuntime(btRuntime_);
@ -281,7 +281,7 @@ void DefaultBtAnnounceTest::testGetAnnounceUrl_externalIP()
setAnnounceList(dctx_, announceList); setAnnounceList(dctx_, announceList);
option_->put(PREF_BT_EXTERNAL_IP, "192.168.1.1"); option_->put(PREF_BT_EXTERNAL_IP, "192.168.1.1");
DefaultBtAnnounce btAnnounce(dctx_, option_); DefaultBtAnnounce btAnnounce(dctx_.get(), option_);
btAnnounce.setPieceStorage(pieceStorage_); btAnnounce.setPieceStorage(pieceStorage_);
btAnnounce.setPeerStorage(peerStorage_); btAnnounce.setPeerStorage(peerStorage_);
btAnnounce.setBtRuntime(btRuntime_); btAnnounce.setBtRuntime(btRuntime_);
@ -312,7 +312,7 @@ void DefaultBtAnnounceTest::testIsAllAnnounceFailed()
announceList->append(createAnnounceTier("http://backup/announce")); announceList->append(createAnnounceTier("http://backup/announce"));
setAnnounceList(dctx_, announceList); setAnnounceList(dctx_, announceList);
DefaultBtAnnounce btAnnounce(dctx_, option_); DefaultBtAnnounce btAnnounce(dctx_.get(), option_);
btAnnounce.setPieceStorage(pieceStorage_); btAnnounce.setPieceStorage(pieceStorage_);
btAnnounce.setPeerStorage(peerStorage_); btAnnounce.setPeerStorage(peerStorage_);
btAnnounce.setBtRuntime(btRuntime_); btAnnounce.setBtRuntime(btRuntime_);
@ -345,7 +345,7 @@ void DefaultBtAnnounceTest::testURLOrderInStoppedEvent()
announceList->append(createAnnounceTier(vbegin(urls), vend(urls))); announceList->append(createAnnounceTier(vbegin(urls), vend(urls)));
setAnnounceList(dctx_, announceList); setAnnounceList(dctx_, announceList);
DefaultBtAnnounce btAnnounce(dctx_, option_); DefaultBtAnnounce btAnnounce(dctx_.get(), option_);
btAnnounce.setPieceStorage(pieceStorage_); btAnnounce.setPieceStorage(pieceStorage_);
btAnnounce.setPeerStorage(peerStorage_); btAnnounce.setPeerStorage(peerStorage_);
btAnnounce.setBtRuntime(btRuntime_); btAnnounce.setBtRuntime(btRuntime_);
@ -376,7 +376,7 @@ void DefaultBtAnnounceTest::testURLOrderInCompletedEvent()
announceList->append(createAnnounceTier(vbegin(urls), vend(urls))); announceList->append(createAnnounceTier(vbegin(urls), vend(urls)));
setAnnounceList(dctx_, announceList); setAnnounceList(dctx_, announceList);
DefaultBtAnnounce btAnnounce(dctx_, option_); DefaultBtAnnounce btAnnounce(dctx_.get(), option_);
btAnnounce.setPieceStorage(pieceStorage_); btAnnounce.setPieceStorage(pieceStorage_);
btAnnounce.setPeerStorage(peerStorage_); btAnnounce.setPeerStorage(peerStorage_);
btAnnounce.setBtRuntime(btRuntime_); btAnnounce.setBtRuntime(btRuntime_);
@ -402,7 +402,9 @@ void DefaultBtAnnounceTest::testProcessAnnounceResponse_malformed()
{ {
try { try {
std::string res = "i123e"; std::string res = "i123e";
DefaultBtAnnounce(dctx_, option_).processAnnounceResponse(reinterpret_cast<const unsigned char*>(res.c_str()), res.size()); DefaultBtAnnounce(dctx_.get(), option_)
.processAnnounceResponse
(reinterpret_cast<const unsigned char*>(res.c_str()), res.size());
CPPUNIT_FAIL("exception must be thrown."); CPPUNIT_FAIL("exception must be thrown.");
} catch(Exception& e) { } catch(Exception& e) {
std::cerr << e.stackTrace() << std::endl; std::cerr << e.stackTrace() << std::endl;
@ -413,7 +415,9 @@ void DefaultBtAnnounceTest::testProcessAnnounceResponse_failureReason()
{ {
try { try {
std::string res = "d14:failure reason11:hello worlde"; std::string res = "d14:failure reason11:hello worlde";
DefaultBtAnnounce(dctx_, option_).processAnnounceResponse(reinterpret_cast<const unsigned char*>(res.c_str()), res.size()); DefaultBtAnnounce(dctx_.get(), option_)
.processAnnounceResponse
(reinterpret_cast<const unsigned char*>(res.c_str()), res.size());
CPPUNIT_FAIL("exception must be thrown."); CPPUNIT_FAIL("exception must be thrown.");
} catch(Exception& e) { } catch(Exception& e) {
std::cerr << e.stackTrace() << std::endl; std::cerr << e.stackTrace() << std::endl;
@ -435,7 +439,7 @@ void DefaultBtAnnounceTest::testProcessAnnounceResponse()
res += fromHex("100210354527354678541237324732171ae1"); res += fromHex("100210354527354678541237324732171ae1");
res += "e"; res += "e";
DefaultBtAnnounce an(dctx_, option_); DefaultBtAnnounce an(dctx_.get(), option_);
an.setPeerStorage(peerStorage_); an.setPeerStorage(peerStorage_);
an.setBtRuntime(btRuntime_); an.setBtRuntime(btRuntime_);
an.processAnnounceResponse(reinterpret_cast<const unsigned char*>(res.c_str()), res.size()); an.processAnnounceResponse(reinterpret_cast<const unsigned char*>(res.c_str()), res.size());
@ -465,7 +469,7 @@ void DefaultBtAnnounceTest::testProcessUDPTrackerResponse()
6890+i)); 6890+i));
} }
req->reply = reply; req->reply = reply;
DefaultBtAnnounce an(dctx_, option_); DefaultBtAnnounce an(dctx_.get(), option_);
an.setPeerStorage(peerStorage_); an.setPeerStorage(peerStorage_);
an.setBtRuntime(btRuntime_); an.setBtRuntime(btRuntime_);
an.processUDPTrackerResponse(req); an.processUDPTrackerResponse(req);