2008-05-12 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>

Changed method signature:
	BtRequestFactory::createRequestMessages,
	BtRequestFactory::createRequestMessagesOnEndGame
	* src/BtRequestFactory.h
	* src/DefaultBtInteractive.cc
	* src/DefaultBtRequestFactory.cc
	* src/DefaultBtRequestFactory.h
	* test/DefaultBtRequestFactoryTest.cc
	* test/MockBtRequestFactory.h
This commit is contained in:
Tatsuhiro Tsujikawa 2008-05-12 10:54:36 +00:00
parent d2110dc697
commit ddd1206b42
7 changed files with 39 additions and 23 deletions

View file

@ -1,3 +1,15 @@
2008-05-12 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Changed method signature:
BtRequestFactory::createRequestMessages,
BtRequestFactory::createRequestMessagesOnEndGame
* src/BtRequestFactory.h
* src/DefaultBtInteractive.cc
* src/DefaultBtRequestFactory.cc
* src/DefaultBtRequestFactory.h
* test/DefaultBtRequestFactoryTest.cc
* test/MockBtRequestFactory.h
2008-05-11 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com> 2008-05-11 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Changed method signature: Changed method signature:

View file

@ -65,15 +65,15 @@ public:
* addTargetPiece() and returns them. * addTargetPiece() and returns them.
* The number of objects returned is capped by max. * The number of objects returned is capped by max.
*/ */
virtual std::deque<SharedHandle<BtMessage> > virtual void createRequestMessages
createRequestMessages(size_t max) = 0; (std::deque<SharedHandle<BtMessage> >& requests, size_t max) = 0;
/** /**
* Use this method in end game mode. * Use this method in end game mode.
* *
*/ */
virtual std::deque<SharedHandle<BtMessage> > virtual void createRequestMessagesOnEndGame
createRequestMessagesOnEndGame(size_t max) = 0; (std::deque<SharedHandle<BtMessage> >& requests, size_t max) = 0;
}; };
typedef SharedHandle<BtRequestFactory> BtRequestFactoryHandle; typedef SharedHandle<BtRequestFactory> BtRequestFactoryHandle;

View file

@ -332,9 +332,9 @@ void DefaultBtInteractive::addRequests() {
if(reqNumToCreate > 0) { if(reqNumToCreate > 0) {
BtMessages requests; BtMessages requests;
if(pieceStorage->isEndGame()) { if(pieceStorage->isEndGame()) {
requests = btRequestFactory->createRequestMessagesOnEndGame(reqNumToCreate); btRequestFactory->createRequestMessagesOnEndGame(requests, reqNumToCreate);
} else { } else {
requests = btRequestFactory->createRequestMessages(reqNumToCreate); btRequestFactory->createRequestMessages(requests, reqNumToCreate);
} }
dispatcher->addMessageToQueue(requests); dispatcher->addMessageToQueue(requests);
} }

View file

@ -105,9 +105,9 @@ void DefaultBtRequestFactory::removeAllTargetPiece() {
pieces.clear(); pieces.clear();
} }
BtMessages DefaultBtRequestFactory::createRequestMessages(size_t max) void DefaultBtRequestFactory::createRequestMessages
(std::deque<SharedHandle<BtMessage> >& requests, size_t max)
{ {
BtMessages requests;
for(Pieces::iterator itr = pieces.begin(); for(Pieces::iterator itr = pieces.begin();
itr != pieces.end() && requests.size() < max; itr++) { itr != pieces.end() && requests.size() < max; itr++) {
PieceHandle& piece = *itr; PieceHandle& piece = *itr;
@ -117,12 +117,11 @@ BtMessages DefaultBtRequestFactory::createRequestMessages(size_t max)
requests.push_back(messageFactory->createRequestMessage(piece, blockIndex)); requests.push_back(messageFactory->createRequestMessage(piece, blockIndex));
} }
} }
return requests;
} }
BtMessages DefaultBtRequestFactory::createRequestMessagesOnEndGame(size_t max) void DefaultBtRequestFactory::createRequestMessagesOnEndGame
(std::deque<SharedHandle<BtMessage> >& requests, size_t max)
{ {
BtMessages requests;
for(Pieces::iterator itr = pieces.begin(); for(Pieces::iterator itr = pieces.begin();
itr != pieces.end() && requests.size() < max; itr++) { itr != pieces.end() && requests.size() < max; itr++) {
PieceHandle& piece = *itr; PieceHandle& piece = *itr;
@ -138,7 +137,6 @@ BtMessages DefaultBtRequestFactory::createRequestMessagesOnEndGame(size_t max)
} }
} }
} }
return requests;
} }
std::deque<SharedHandle<Piece> >& DefaultBtRequestFactory::getTargetPieces() std::deque<SharedHandle<Piece> >& DefaultBtRequestFactory::getTargetPieces()

View file

@ -74,11 +74,11 @@ public:
virtual void doChokedAction(); virtual void doChokedAction();
virtual std::deque<SharedHandle<BtMessage> > virtual void createRequestMessages
createRequestMessages(size_t max); (std::deque<SharedHandle<BtMessage> >& requests, size_t max);
virtual std::deque<SharedHandle<BtMessage> > virtual void createRequestMessagesOnEndGame
createRequestMessagesOnEndGame(size_t max); (std::deque<SharedHandle<BtMessage> >& requests, size_t max);
std::deque<SharedHandle<Piece> >& getTargetPieces(); std::deque<SharedHandle<Piece> >& getTargetPieces();

View file

@ -147,7 +147,8 @@ void DefaultBtRequestFactoryTest::testCreateRequestMessages() {
btRequestFactory->addTargetPiece(piece1); btRequestFactory->addTargetPiece(piece1);
btRequestFactory->addTargetPiece(piece2); btRequestFactory->addTargetPiece(piece2);
std::deque<SharedHandle<BtMessage> > msgs = btRequestFactory->createRequestMessages(3); std::deque<SharedHandle<BtMessage> > msgs;
btRequestFactory->createRequestMessages(msgs, 3);
CPPUNIT_ASSERT_EQUAL((size_t)3, msgs.size()); CPPUNIT_ASSERT_EQUAL((size_t)3, msgs.size());
std::deque<SharedHandle<BtMessage> >::iterator itr = msgs.begin(); std::deque<SharedHandle<BtMessage> >::iterator itr = msgs.begin();
@ -163,7 +164,11 @@ void DefaultBtRequestFactoryTest::testCreateRequestMessages() {
CPPUNIT_ASSERT_EQUAL((size_t)1, msg->index); CPPUNIT_ASSERT_EQUAL((size_t)1, msg->index);
CPPUNIT_ASSERT_EQUAL((size_t)0, msg->blockIndex); CPPUNIT_ASSERT_EQUAL((size_t)0, msg->blockIndex);
CPPUNIT_ASSERT_EQUAL((size_t)1, btRequestFactory->createRequestMessages(3).size()); {
std::deque<SharedHandle<BtMessage> > msgs;
btRequestFactory->createRequestMessages(msgs, 3);
CPPUNIT_ASSERT_EQUAL((size_t)1, msgs.size());
}
} }
void DefaultBtRequestFactoryTest::testCreateRequestMessages_onEndGame() { void DefaultBtRequestFactoryTest::testCreateRequestMessages_onEndGame() {
@ -178,7 +183,8 @@ void DefaultBtRequestFactoryTest::testCreateRequestMessages_onEndGame() {
btRequestFactory->addTargetPiece(piece1); btRequestFactory->addTargetPiece(piece1);
btRequestFactory->addTargetPiece(piece2); btRequestFactory->addTargetPiece(piece2);
std::deque<SharedHandle<BtMessage> > msgs = btRequestFactory->createRequestMessagesOnEndGame(3); std::deque<SharedHandle<BtMessage> > msgs;
btRequestFactory->createRequestMessagesOnEndGame(msgs, 3);
std::deque<SharedHandle<MockBtRequestMessage> > mmsgs; std::deque<SharedHandle<MockBtRequestMessage> > mmsgs;
for(std::deque<SharedHandle<BtMessage> >::iterator i = msgs.begin(); for(std::deque<SharedHandle<BtMessage> >::iterator i = msgs.begin();

View file

@ -21,11 +21,11 @@ public:
virtual void doChokedAction() {} virtual void doChokedAction() {}
virtual std::deque<SharedHandle<BtMessage> > virtual void createRequestMessages
createRequestMessages(size_t max) { return std::deque<SharedHandle<BtMessage> >(); } (std::deque<SharedHandle<BtMessage> >& requests, size_t max) {}
virtual std::deque<SharedHandle<BtMessage> > virtual void createRequestMessagesOnEndGame
createRequestMessagesOnEndGame(size_t max) { return std::deque<SharedHandle<BtMessage> >(); } (std::deque<SharedHandle<BtMessage> >& requests, size_t max) {}
}; };
} // namespace aria2 } // namespace aria2