From 215d1d3d0bf7530e27ea83aab873528c1500478d Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Thu, 27 Sep 2012 23:40:25 +0900 Subject: [PATCH] Made static create function of BtMessage subclass return raw pointer --- src/BtAllowedFastMessage.cc | 2 +- src/BtAllowedFastMessage.h | 6 +- src/BtBitfieldMessage.cc | 4 +- src/BtBitfieldMessage.h | 6 +- src/BtCancelMessage.cc | 2 +- src/BtCancelMessage.h | 7 +- src/BtChokeMessage.cc | 2 +- src/BtChokeMessage.h | 7 +- src/BtExtendedMessage.cc | 8 +- src/BtExtendedMessage.h | 5 +- src/BtHaveAllMessage.cc | 2 +- src/BtHaveAllMessage.h | 6 +- src/BtHaveMessage.cc | 2 +- src/BtHaveMessage.h | 7 +- src/BtHaveNoneMessage.cc | 2 +- src/BtHaveNoneMessage.h | 6 +- src/BtInterestedMessage.cc | 2 +- src/BtInterestedMessage.h | 4 +- src/BtNotInterestedMessage.cc | 2 +- src/BtNotInterestedMessage.h | 4 +- src/BtPieceMessage.cc | 4 +- src/BtPieceMessage.h | 8 +- src/BtPortMessage.cc | 4 +- src/BtPortMessage.h | 3 +- src/BtRejectMessage.cc | 2 +- src/BtRejectMessage.h | 7 +- src/BtRequestMessage.cc | 2 +- src/BtRequestMessage.h | 6 +- src/BtSuggestPieceMessage.cc | 2 +- src/BtSuggestPieceMessage.h | 6 +- src/BtUnchokeMessage.cc | 2 +- src/BtUnchokeMessage.h | 6 +- src/DefaultBtMessageFactory.cc | 256 ++++++++++++++--------------- src/DefaultBtMessageFactory.h | 14 +- src/IndexBtMessage.h | 4 +- src/RangeBtMessage.h | 5 +- src/ZeroBtMessage.h | 4 +- test/BtAllowedFastMessageTest.cc | 3 +- test/BtBitfieldMessageTest.cc | 4 +- test/BtCancelMessageTest.cc | 2 +- test/BtChokeMessageTest.cc | 2 +- test/BtExtendedMessageTest.cc | 8 +- test/BtHaveAllMessageTest.cc | 2 +- test/BtHaveMessageTest.cc | 2 +- test/BtHaveNoneMessageTest.cc | 2 +- test/BtInterestedMessageTest.cc | 3 +- test/BtNotInterestedMessageTest.cc | 3 +- test/BtPieceMessageTest.cc | 2 +- test/BtPortMessageTest.cc | 2 +- test/BtRejectMessageTest.cc | 2 +- test/BtRequestMessageTest.cc | 2 +- test/BtSuggestPieceMessageTest.cc | 3 +- test/BtUnchokeMessageTest.cc | 2 +- 53 files changed, 198 insertions(+), 267 deletions(-) diff --git a/src/BtAllowedFastMessage.cc b/src/BtAllowedFastMessage.cc index 629b3e41..14b53ce0 100644 --- a/src/BtAllowedFastMessage.cc +++ b/src/BtAllowedFastMessage.cc @@ -44,7 +44,7 @@ const char BtAllowedFastMessage::NAME[] = "allowed fast"; BtAllowedFastMessage::BtAllowedFastMessage(size_t index): IndexBtMessage(ID, NAME, index) {} -SharedHandle BtAllowedFastMessage::create +BtAllowedFastMessage* BtAllowedFastMessage::create (const unsigned char* data, size_t dataLength) { return IndexBtMessage::create(data, dataLength); diff --git a/src/BtAllowedFastMessage.h b/src/BtAllowedFastMessage.h index aefcda8d..c32aa0d7 100644 --- a/src/BtAllowedFastMessage.h +++ b/src/BtAllowedFastMessage.h @@ -39,10 +39,6 @@ namespace aria2 { -class BtAllowedFastMessage; - -typedef SharedHandle BtAllowedFastMessageHandle; - class BtAllowedFastMessage : public IndexBtMessage { public: BtAllowedFastMessage(size_t index = 0); @@ -51,7 +47,7 @@ public: static const char NAME[]; - static SharedHandle create + static BtAllowedFastMessage* create (const unsigned char* data, size_t dataLength); virtual void doReceivedAction(); diff --git a/src/BtBitfieldMessage.cc b/src/BtBitfieldMessage.cc index f5181ed8..1da36dad 100644 --- a/src/BtBitfieldMessage.cc +++ b/src/BtBitfieldMessage.cc @@ -78,12 +78,12 @@ void BtBitfieldMessage::setBitfield memcpy(bitfield_, bitfield, bitfieldLength_); } -BtBitfieldMessageHandle +BtBitfieldMessage* BtBitfieldMessage::create(const unsigned char* data, size_t dataLength) { bittorrent::assertPayloadLengthGreater(1,dataLength, NAME); bittorrent::assertID(ID, data, NAME); - BtBitfieldMessageHandle message(new BtBitfieldMessage()); + BtBitfieldMessage* message(new BtBitfieldMessage()); message->setBitfield(data+1, dataLength-1); return message; } diff --git a/src/BtBitfieldMessage.h b/src/BtBitfieldMessage.h index 0b4dd680..e14009e6 100644 --- a/src/BtBitfieldMessage.h +++ b/src/BtBitfieldMessage.h @@ -39,10 +39,6 @@ namespace aria2 { -class BtBitfieldMessage; - -typedef SharedHandle BtBitfieldMessageHandle; - class BtBitfieldMessage : public SimpleBtMessage { private: unsigned char* bitfield_; @@ -64,7 +60,7 @@ public: size_t getBitfieldLength() const { return bitfieldLength_; } - static BtBitfieldMessageHandle create + static BtBitfieldMessage* create (const unsigned char* data, size_t dataLength); virtual void doReceivedAction(); diff --git a/src/BtCancelMessage.cc b/src/BtCancelMessage.cc index 183291a0..d2575c56 100644 --- a/src/BtCancelMessage.cc +++ b/src/BtCancelMessage.cc @@ -43,7 +43,7 @@ BtCancelMessage::BtCancelMessage (size_t index, int32_t begin, int32_t length) :RangeBtMessage(ID, NAME, index, begin, length) {} -SharedHandle BtCancelMessage::create +BtCancelMessage* BtCancelMessage::create (const unsigned char* data, size_t dataLength) { return RangeBtMessage::create(data, dataLength); diff --git a/src/BtCancelMessage.h b/src/BtCancelMessage.h index 84f450ba..a0ec9e3e 100644 --- a/src/BtCancelMessage.h +++ b/src/BtCancelMessage.h @@ -39,10 +39,6 @@ namespace aria2 { -class BtCancelMessage; - -typedef SharedHandle BtCancelMessageHandle; - class BtCancelMessage : public RangeBtMessage { public: BtCancelMessage(size_t index = 0, int32_t begin = 0, int32_t length = 0); @@ -51,8 +47,7 @@ public: static const char NAME[]; - static BtCancelMessageHandle create - (const unsigned char* data, size_t dataLength); + static BtCancelMessage* create(const unsigned char* data, size_t dataLength); virtual void doReceivedAction(); }; diff --git a/src/BtChokeMessage.cc b/src/BtChokeMessage.cc index a8956823..ed230f5d 100644 --- a/src/BtChokeMessage.cc +++ b/src/BtChokeMessage.cc @@ -43,7 +43,7 @@ const char BtChokeMessage::NAME[] = "choke"; BtChokeMessage::BtChokeMessage():ZeroBtMessage(ID, NAME) {} -SharedHandle BtChokeMessage::create +BtChokeMessage* BtChokeMessage::create (const unsigned char* data, size_t dataLength) { return ZeroBtMessage::create(data, dataLength); diff --git a/src/BtChokeMessage.h b/src/BtChokeMessage.h index 849dded7..73c357d7 100644 --- a/src/BtChokeMessage.h +++ b/src/BtChokeMessage.h @@ -39,10 +39,6 @@ namespace aria2 { -class BtChokeMessage; - -typedef SharedHandle BtChokeMessageHandle; - class BtChokeMessage : public ZeroBtMessage { public: BtChokeMessage(); @@ -53,8 +49,7 @@ public: virtual void doReceivedAction(); - static SharedHandle create - (const unsigned char* data, size_t dataLength); + static BtChokeMessage* create(const unsigned char* data, size_t dataLength); virtual bool sendPredicate() const; diff --git a/src/BtExtendedMessage.cc b/src/BtExtendedMessage.cc index 7954b59c..cd048a35 100644 --- a/src/BtExtendedMessage.cc +++ b/src/BtExtendedMessage.cc @@ -96,7 +96,7 @@ std::string BtExtendedMessage::toString() const { return s; } -BtExtendedMessageHandle +BtExtendedMessage* BtExtendedMessage::create(const SharedHandle& factory, const SharedHandle& peer, const unsigned char* data, size_t dataLength) @@ -104,9 +104,9 @@ BtExtendedMessage::create(const SharedHandle& factory, bittorrent::assertPayloadLengthGreater(1, dataLength, NAME); bittorrent::assertID(ID, data, NAME); assert(factory); - ExtensionMessageHandle extmsg = factory->createMessage(data+1, - dataLength-1); - BtExtendedMessageHandle message(new BtExtendedMessage(extmsg)); + SharedHandle extmsg = factory->createMessage(data+1, + dataLength-1); + BtExtendedMessage* message(new BtExtendedMessage(extmsg)); return message; } diff --git a/src/BtExtendedMessage.h b/src/BtExtendedMessage.h index 9238083d..e4be471b 100644 --- a/src/BtExtendedMessage.h +++ b/src/BtExtendedMessage.h @@ -41,9 +41,6 @@ namespace aria2 { class ExtensionMessage; class ExtensionMessageFactory; -class BtExtendedMessage; -typedef SharedHandle BtExtendedMessageHandle; - class BtExtendedMessage:public SimpleBtMessage { private: @@ -59,7 +56,7 @@ public: static const char NAME[]; - static BtExtendedMessageHandle create + static BtExtendedMessage* create (const SharedHandle& factory, const SharedHandle& peer, const unsigned char* data, diff --git a/src/BtHaveAllMessage.cc b/src/BtHaveAllMessage.cc index 771ec342..81f74203 100644 --- a/src/BtHaveAllMessage.cc +++ b/src/BtHaveAllMessage.cc @@ -45,7 +45,7 @@ const char BtHaveAllMessage::NAME[] = "have all"; BtHaveAllMessage::BtHaveAllMessage():ZeroBtMessage(ID, NAME) {} -SharedHandle BtHaveAllMessage::create +BtHaveAllMessage* BtHaveAllMessage::create (const unsigned char* data, size_t dataLength) { return ZeroBtMessage::create(data, dataLength); diff --git a/src/BtHaveAllMessage.h b/src/BtHaveAllMessage.h index 3af3ff11..c19ca004 100644 --- a/src/BtHaveAllMessage.h +++ b/src/BtHaveAllMessage.h @@ -39,10 +39,6 @@ namespace aria2 { -class BtHaveAllMessage; - -typedef SharedHandle BtHaveAllMessageHandle; - class BtHaveAllMessage : public ZeroBtMessage { public: BtHaveAllMessage(); @@ -51,7 +47,7 @@ public: static const char NAME[]; - static SharedHandle create + static BtHaveAllMessage* create (const unsigned char* data, size_t dataLength); virtual void doReceivedAction(); diff --git a/src/BtHaveMessage.cc b/src/BtHaveMessage.cc index e88643fb..50b40f39 100644 --- a/src/BtHaveMessage.cc +++ b/src/BtHaveMessage.cc @@ -44,7 +44,7 @@ const char BtHaveMessage::NAME[] = "have"; BtHaveMessage::BtHaveMessage(size_t index):IndexBtMessage(ID, NAME, index) {} -SharedHandle BtHaveMessage::create +BtHaveMessage* BtHaveMessage::create (const unsigned char* data, size_t dataLength) { return IndexBtMessage::create(data, dataLength); diff --git a/src/BtHaveMessage.h b/src/BtHaveMessage.h index 1c4146fe..03c3f565 100644 --- a/src/BtHaveMessage.h +++ b/src/BtHaveMessage.h @@ -39,10 +39,6 @@ namespace aria2 { -class BtHaveMessage; - -typedef SharedHandle BtHaveMessageHandle; - class BtHaveMessage : public IndexBtMessage { public: BtHaveMessage(size_t index = 0); @@ -51,8 +47,7 @@ public: static const char NAME[]; - static SharedHandle create - (const unsigned char* data, size_t dataLength); + static BtHaveMessage* create(const unsigned char* data, size_t dataLength); virtual void doReceivedAction(); }; diff --git a/src/BtHaveNoneMessage.cc b/src/BtHaveNoneMessage.cc index e85814de..1257b7e5 100644 --- a/src/BtHaveNoneMessage.cc +++ b/src/BtHaveNoneMessage.cc @@ -43,7 +43,7 @@ const char BtHaveNoneMessage::NAME[] = "have none"; BtHaveNoneMessage::BtHaveNoneMessage():ZeroBtMessage(ID, NAME) {} -SharedHandle BtHaveNoneMessage::create +BtHaveNoneMessage* BtHaveNoneMessage::create (const unsigned char* data, size_t dataLength) { return ZeroBtMessage::create(data, dataLength); diff --git a/src/BtHaveNoneMessage.h b/src/BtHaveNoneMessage.h index e1ca6034..fcc3f4a2 100644 --- a/src/BtHaveNoneMessage.h +++ b/src/BtHaveNoneMessage.h @@ -39,10 +39,6 @@ namespace aria2 { -class BtHaveNoneMessage; - -typedef SharedHandle BtHaveNoneMessageHandle; - class BtHaveNoneMessage : public ZeroBtMessage { public: BtHaveNoneMessage(); @@ -51,7 +47,7 @@ public: static const char NAME[]; - static SharedHandle create + static BtHaveNoneMessage* create (const unsigned char* data, size_t dataLength); virtual void doReceivedAction(); diff --git a/src/BtInterestedMessage.cc b/src/BtInterestedMessage.cc index f0b36e85..e2391bc1 100644 --- a/src/BtInterestedMessage.cc +++ b/src/BtInterestedMessage.cc @@ -44,7 +44,7 @@ BtInterestedMessage::BtInterestedMessage():ZeroBtMessage(ID, NAME) {} BtInterestedMessage::~BtInterestedMessage() {} -SharedHandle BtInterestedMessage::create +BtInterestedMessage* BtInterestedMessage::create (const unsigned char* data, size_t dataLength) { return ZeroBtMessage::create(data, dataLength); diff --git a/src/BtInterestedMessage.h b/src/BtInterestedMessage.h index 740ce81a..1630db93 100644 --- a/src/BtInterestedMessage.h +++ b/src/BtInterestedMessage.h @@ -42,8 +42,6 @@ namespace aria2 { class PeerStorage; class BtInterestedMessage; -typedef SharedHandle BtInterestedMessageHandle; - class BtInterestedMessage : public ZeroBtMessage { private: SharedHandle peerStorage_; @@ -55,7 +53,7 @@ public: static const char NAME[]; - static SharedHandle create + static BtInterestedMessage* create (const unsigned char* data, size_t dataLength); virtual void doReceivedAction(); diff --git a/src/BtNotInterestedMessage.cc b/src/BtNotInterestedMessage.cc index cf8b794a..33f3ec3c 100644 --- a/src/BtNotInterestedMessage.cc +++ b/src/BtNotInterestedMessage.cc @@ -44,7 +44,7 @@ BtNotInterestedMessage::BtNotInterestedMessage():ZeroBtMessage(ID, NAME) {} BtNotInterestedMessage::~BtNotInterestedMessage() {} -SharedHandle BtNotInterestedMessage::create +BtNotInterestedMessage* BtNotInterestedMessage::create (const unsigned char* data, size_t dataLength) { return ZeroBtMessage::create(data, dataLength); diff --git a/src/BtNotInterestedMessage.h b/src/BtNotInterestedMessage.h index e42948e6..c4e47847 100644 --- a/src/BtNotInterestedMessage.h +++ b/src/BtNotInterestedMessage.h @@ -42,8 +42,6 @@ namespace aria2 { class PeerStorage; class BtNotInterestedMessage; -typedef SharedHandle BtNotInterestedMessageHandle; - class BtNotInterestedMessage : public ZeroBtMessage { private: SharedHandle peerStorage_; @@ -55,7 +53,7 @@ public: static const char NAME[]; - static SharedHandle create + static BtNotInterestedMessage* create (const unsigned char* data, size_t dataLength); virtual void doReceivedAction(); diff --git a/src/BtPieceMessage.cc b/src/BtPieceMessage.cc index e4c72289..1d44af7a 100644 --- a/src/BtPieceMessage.cc +++ b/src/BtPieceMessage.cc @@ -80,12 +80,12 @@ void BtPieceMessage::setMsgPayload(const unsigned char* data) data_ = data; } -BtPieceMessageHandle BtPieceMessage::create +BtPieceMessage* BtPieceMessage::create (const unsigned char* data, size_t dataLength) { bittorrent::assertPayloadLengthGreater(9, dataLength, NAME); bittorrent::assertID(ID, data, NAME); - BtPieceMessageHandle message(new BtPieceMessage()); + BtPieceMessage* message(new BtPieceMessage()); message->setIndex(bittorrent::getIntParam(data, 1)); message->setBegin(bittorrent::getIntParam(data, 5)); message->setBlockLength(dataLength-9); diff --git a/src/BtPieceMessage.h b/src/BtPieceMessage.h index c26d6855..4fbb5d0d 100644 --- a/src/BtPieceMessage.h +++ b/src/BtPieceMessage.h @@ -40,12 +40,9 @@ namespace aria2 { class Piece; -class BtPieceMessage; class DownloadContext; class PeerStorage; -typedef SharedHandle BtPieceMessageHandle; - class BtPieceMessage : public AbstractBtMessage { private: size_t index_; @@ -97,8 +94,7 @@ public: void setPeerStorage(const SharedHandle& peerStorage); - static BtPieceMessageHandle create - (const unsigned char* data, size_t dataLength); + static BtPieceMessage* create(const unsigned char* data, size_t dataLength); virtual void doReceivedAction(); @@ -111,7 +107,7 @@ public: virtual std::string toString() const; virtual void onChokingEvent(const BtChokingEvent& event); - + virtual void onCancelSendingPieceEvent (const BtCancelSendingPieceEvent& event); }; diff --git a/src/BtPortMessage.cc b/src/BtPortMessage.cc index d9bedd74..2d241d49 100644 --- a/src/BtPortMessage.cc +++ b/src/BtPortMessage.cc @@ -61,13 +61,13 @@ BtPortMessage::BtPortMessage(uint16_t port) taskFactory_(0) {} -SharedHandle BtPortMessage::create +BtPortMessage* BtPortMessage::create (const unsigned char* data, size_t dataLength) { bittorrent::assertPayloadLengthEqual(3, dataLength, NAME); bittorrent::assertID(ID, data, NAME); uint16_t port = bittorrent::getShortIntParam(data, 1); - SharedHandle message(new BtPortMessage(port)); + BtPortMessage* message(new BtPortMessage(port)); return message; } diff --git a/src/BtPortMessage.h b/src/BtPortMessage.h index a3226ef3..75d459fd 100644 --- a/src/BtPortMessage.h +++ b/src/BtPortMessage.h @@ -65,8 +65,7 @@ public: uint16_t getPort() const { return port_; } - static SharedHandle create - (const unsigned char* data, size_t dataLength); + static BtPortMessage* create(const unsigned char* data, size_t dataLength); virtual void doReceivedAction(); diff --git a/src/BtRejectMessage.cc b/src/BtRejectMessage.cc index 82afb800..c71d6439 100644 --- a/src/BtRejectMessage.cc +++ b/src/BtRejectMessage.cc @@ -47,7 +47,7 @@ BtRejectMessage::BtRejectMessage (size_t index, int32_t begin, int32_t length): RangeBtMessage(ID, NAME, index, begin, length) {} -SharedHandle BtRejectMessage::create +BtRejectMessage* BtRejectMessage::create (const unsigned char* data, size_t dataLength) { return RangeBtMessage::create(data, dataLength); diff --git a/src/BtRejectMessage.h b/src/BtRejectMessage.h index 8505df5a..644a022a 100644 --- a/src/BtRejectMessage.h +++ b/src/BtRejectMessage.h @@ -39,10 +39,6 @@ namespace aria2 { -class BtRejectMessage; - -typedef SharedHandle BtRejectMessageHandle; - class BtRejectMessage : public RangeBtMessage { public: BtRejectMessage(size_t index = 0, int32_t begin = 0, int32_t length = 0); @@ -51,8 +47,7 @@ public: static const char NAME[]; - static SharedHandle create - (const unsigned char* data, size_t dataLength); + static BtRejectMessage* create(const unsigned char* data, size_t dataLength); virtual void doReceivedAction(); }; diff --git a/src/BtRequestMessage.cc b/src/BtRequestMessage.cc index ea2aa1a4..5a8c76c8 100644 --- a/src/BtRequestMessage.cc +++ b/src/BtRequestMessage.cc @@ -48,7 +48,7 @@ BtRequestMessage::BtRequestMessage RangeBtMessage(ID, NAME, index, begin, length), blockIndex_(blockIndex) {} -SharedHandle BtRequestMessage::create +BtRequestMessage* BtRequestMessage::create (const unsigned char* data, size_t dataLength) { return RangeBtMessage::create(data, dataLength); diff --git a/src/BtRequestMessage.h b/src/BtRequestMessage.h index 42a90d43..ce10b6b6 100644 --- a/src/BtRequestMessage.h +++ b/src/BtRequestMessage.h @@ -39,10 +39,6 @@ namespace aria2 { -class BtRequestMessage; - -typedef SharedHandle BtRequestMessageHandle; - class BtRequestMessage : public RangeBtMessage { private: size_t blockIndex_; @@ -59,7 +55,7 @@ public: size_t getBlockIndex() const { return blockIndex_; } void setBlockIndex(size_t blockIndex) { blockIndex_ = blockIndex; } - static SharedHandle create + static BtRequestMessage* create (const unsigned char* data, size_t dataLength); virtual void doReceivedAction(); diff --git a/src/BtSuggestPieceMessage.cc b/src/BtSuggestPieceMessage.cc index 61caba6b..79739f1f 100644 --- a/src/BtSuggestPieceMessage.cc +++ b/src/BtSuggestPieceMessage.cc @@ -38,7 +38,7 @@ namespace aria2 { const char BtSuggestPieceMessage::NAME[] = "suggest piece"; -SharedHandle BtSuggestPieceMessage::create +BtSuggestPieceMessage* BtSuggestPieceMessage::create (const unsigned char* data, size_t dataLength) { return IndexBtMessage::create(data, dataLength); diff --git a/src/BtSuggestPieceMessage.h b/src/BtSuggestPieceMessage.h index 659f9ee0..05c9c1f2 100644 --- a/src/BtSuggestPieceMessage.h +++ b/src/BtSuggestPieceMessage.h @@ -39,10 +39,6 @@ namespace aria2 { -class BtSuggestPieceMessage; - -typedef SharedHandle BtSuggestPieceMessageHandle; - class BtSuggestPieceMessage : public IndexBtMessage { public: BtSuggestPieceMessage():IndexBtMessage(ID, NAME, 0) {} @@ -51,7 +47,7 @@ public: static const char NAME[]; - static SharedHandle create + static BtSuggestPieceMessage* create (const unsigned char* data, size_t dataLength); virtual void doReceivedAction() { diff --git a/src/BtUnchokeMessage.cc b/src/BtUnchokeMessage.cc index 327fd710..74100689 100644 --- a/src/BtUnchokeMessage.cc +++ b/src/BtUnchokeMessage.cc @@ -41,7 +41,7 @@ const char BtUnchokeMessage::NAME[] = "unchoke"; BtUnchokeMessage::BtUnchokeMessage():ZeroBtMessage(ID, NAME) {} -SharedHandle BtUnchokeMessage::create +BtUnchokeMessage* BtUnchokeMessage::create (const unsigned char* data, size_t dataLength) { return ZeroBtMessage::create(data, dataLength); diff --git a/src/BtUnchokeMessage.h b/src/BtUnchokeMessage.h index e9229440..b5474a84 100644 --- a/src/BtUnchokeMessage.h +++ b/src/BtUnchokeMessage.h @@ -39,10 +39,6 @@ namespace aria2 { -class BtUnchokeMessage; - -typedef SharedHandle BtUnchokeMessageHandle; - class BtUnchokeMessage : public ZeroBtMessage { private: static const size_t MESSAGE_LENGTH = 5; @@ -53,7 +49,7 @@ public: static const char NAME[]; - static SharedHandle create + static BtUnchokeMessage* create (const unsigned char* data, size_t dataLength); virtual void doReceivedAction(); diff --git a/src/DefaultBtMessageFactory.cc b/src/DefaultBtMessageFactory.cc index 1726a3d1..637d6704 100644 --- a/src/DefaultBtMessageFactory.cc +++ b/src/DefaultBtMessageFactory.cc @@ -85,11 +85,11 @@ DefaultBtMessageFactory::DefaultBtMessageFactory(): DefaultBtMessageFactory::~DefaultBtMessageFactory() {} -BtMessageHandle +SharedHandle DefaultBtMessageFactory::createBtMessage (const unsigned char* data, size_t dataLength) { - AbstractBtMessageHandle msg; + SharedHandle msg; if(dataLength == 0) { // keep-alive msg.reset(new BtKeepAliveMessage()); @@ -97,148 +97,139 @@ DefaultBtMessageFactory::createBtMessage uint8_t id = bittorrent::getId(data); switch(id) { case BtChokeMessage::ID: - msg = BtChokeMessage::create(data, dataLength); + msg.reset(BtChokeMessage::create(data, dataLength)); break; case BtUnchokeMessage::ID: - msg = BtUnchokeMessage::create(data, dataLength); + msg.reset(BtUnchokeMessage::create(data, dataLength)); break; case BtInterestedMessage::ID: { - SharedHandle m = - BtInterestedMessage::create(data, dataLength); + BtInterestedMessage* m = BtInterestedMessage::create(data, dataLength); m->setPeerStorage(peerStorage_); - msg = m; + msg.reset(m); } break; case BtNotInterestedMessage::ID: { - SharedHandle m = + BtNotInterestedMessage* m = BtNotInterestedMessage::create(data, dataLength); m->setPeerStorage(peerStorage_); - msg = m; + msg.reset(m); } break; case BtHaveMessage::ID: - msg = BtHaveMessage::create(data, dataLength); - { - if(!metadataGetMode_) { - SharedHandle v - (new IndexBtMessageValidator(static_cast(msg.get()), - downloadContext_->getNumPieces())); - msg->setBtMessageValidator(v); - } + msg.reset(BtHaveMessage::create(data, dataLength)); + if(!metadataGetMode_) { + SharedHandle v + (new IndexBtMessageValidator(static_cast(msg.get()), + downloadContext_->getNumPieces())); + msg->setBtMessageValidator(v); } break; case BtBitfieldMessage::ID: - msg = BtBitfieldMessage::create(data, dataLength); - { - if(!metadataGetMode_) { - SharedHandle v - (new BtBitfieldMessageValidator - (static_cast(msg.get()), - downloadContext_->getNumPieces())); - msg->setBtMessageValidator(v); - } + msg.reset(BtBitfieldMessage::create(data, dataLength)); + if(!metadataGetMode_) { + SharedHandle v + (new BtBitfieldMessageValidator + (static_cast(msg.get()), + downloadContext_->getNumPieces())); + msg->setBtMessageValidator(v); } break; case BtRequestMessage::ID: { - BtRequestMessageHandle temp = BtRequestMessage::create(data, dataLength); + BtRequestMessage* m = BtRequestMessage::create(data, dataLength); if(!metadataGetMode_) { SharedHandle validator (new RangeBtMessageValidator - (temp.get(), + (m, downloadContext_->getNumPieces(), - pieceStorage_->getPieceLength(temp->getIndex()))); - temp->setBtMessageValidator(validator); + pieceStorage_->getPieceLength(m->getIndex()))); + m->setBtMessageValidator(validator); } - msg = temp; + msg.reset(m); break; } case BtCancelMessage::ID: { - BtCancelMessageHandle temp = BtCancelMessage::create(data, dataLength); + BtCancelMessage* m = BtCancelMessage::create(data, dataLength); if(!metadataGetMode_) { SharedHandle validator (new RangeBtMessageValidator - (temp.get(), + (m, downloadContext_->getNumPieces(), - pieceStorage_->getPieceLength(temp->getIndex()))); - temp->setBtMessageValidator(validator); + pieceStorage_->getPieceLength(m->getIndex()))); + m->setBtMessageValidator(validator); } - msg = temp; + msg.reset(m); break; } case BtPieceMessage::ID: { - BtPieceMessageHandle temp = BtPieceMessage::create(data, dataLength); + BtPieceMessage* m = BtPieceMessage::create(data, dataLength); if(!metadataGetMode_) { BtMessageValidatorHandle validator (new BtPieceMessageValidator - (temp.get(), + (m, downloadContext_->getNumPieces(), - pieceStorage_->getPieceLength(temp->getIndex()))); - temp->setBtMessageValidator(validator); + pieceStorage_->getPieceLength(m->getIndex()))); + m->setBtMessageValidator(validator); } - temp->setDownloadContext(downloadContext_); - temp->setPeerStorage(peerStorage_); - msg = temp; + m->setDownloadContext(downloadContext_); + m->setPeerStorage(peerStorage_); + msg.reset(m); break; } case BtHaveAllMessage::ID: - msg = BtHaveAllMessage::create(data, dataLength); + msg.reset(BtHaveAllMessage::create(data, dataLength)); break; case BtHaveNoneMessage::ID: - msg = BtHaveNoneMessage::create(data, dataLength); + msg.reset(BtHaveNoneMessage::create(data, dataLength)); break; case BtRejectMessage::ID: { - BtRejectMessageHandle temp = BtRejectMessage::create(data, dataLength); + BtRejectMessage* m = BtRejectMessage::create(data, dataLength); if(!metadataGetMode_) { SharedHandle validator (new RangeBtMessageValidator - (temp.get(), + (m, downloadContext_->getNumPieces(), - pieceStorage_->getPieceLength(temp->getIndex()))); - temp->setBtMessageValidator(validator); + pieceStorage_->getPieceLength(m->getIndex()))); + m->setBtMessageValidator(validator); } - msg = temp; + msg.reset(m); break; } case BtSuggestPieceMessage::ID: { - BtSuggestPieceMessageHandle temp = + BtSuggestPieceMessage* m = BtSuggestPieceMessage::create(data, dataLength); if(!metadataGetMode_) { SharedHandle validator - (new IndexBtMessageValidator(temp.get(), - downloadContext_->getNumPieces())); - temp->setBtMessageValidator(validator); + (new IndexBtMessageValidator(m, downloadContext_->getNumPieces())); + m->setBtMessageValidator(validator); } - msg = temp; + msg.reset(m); break; } case BtAllowedFastMessage::ID: { - BtAllowedFastMessageHandle temp = - BtAllowedFastMessage::create(data, dataLength); + BtAllowedFastMessage* m = BtAllowedFastMessage::create(data, dataLength); if(!metadataGetMode_) { SharedHandle validator - (new IndexBtMessageValidator(temp.get(), - downloadContext_->getNumPieces())); - temp->setBtMessageValidator(validator); + (new IndexBtMessageValidator(m, downloadContext_->getNumPieces())); + m->setBtMessageValidator(validator); } - msg = temp; + msg.reset(m); break; } case BtPortMessage::ID: { - SharedHandle temp = - BtPortMessage::create(data, dataLength); - temp->setLocalNode(localNode_); - temp->setRoutingTable(routingTable_); - temp->setTaskQueue(taskQueue_); - temp->setTaskFactory(taskFactory_); - msg = temp; + BtPortMessage* m = BtPortMessage::create(data, dataLength); + m->setLocalNode(localNode_); + m->setRoutingTable(routingTable_); + m->setTaskQueue(taskQueue_); + m->setTaskFactory(taskFactory_); + msg.reset(m); break; } case BtExtendedMessage::ID: { if(peer_->isExtendedMessagingEnabled()) { - msg = BtExtendedMessage::create(extensionMessageFactory_, - peer_, data, dataLength); + msg.reset(BtExtendedMessage::create(extensionMessageFactory_, + peer_, data, dataLength)); } else { throw DL_ABORT_EX("Received extended message from peer during" " a session with extended messaging disabled."); @@ -249,12 +240,12 @@ DefaultBtMessageFactory::createBtMessage throw DL_ABORT_EX(fmt("Invalid message ID. id=%u", id)); } } - setCommonProperty(msg); + setCommonProperty(msg.get()); return msg; } -void DefaultBtMessageFactory::setCommonProperty -(const AbstractBtMessageHandle& msg) { +void DefaultBtMessageFactory::setCommonProperty(AbstractBtMessage* msg) +{ msg->setCuid(cuid_); msg->setPeer(peer_); msg->setPieceStorage(pieceStorage_); @@ -277,7 +268,7 @@ DefaultBtMessageFactory::createHandshakeMessage (new BtHandshakeMessageValidator (msg.get(), bittorrent::getInfoHash(downloadContext_))); msg->setBtMessageValidator(validator); - setCommonProperty(msg); + setCommonProperty(msg.get()); return msg; } @@ -292,181 +283,180 @@ DefaultBtMessageFactory::createHandshakeMessage(const unsigned char* infoHash, (msg.get(), bittorrent::getInfoHash(downloadContext_))); msg->setBtMessageValidator(validator); msg->setDHTEnabled(dhtEnabled_); - setCommonProperty(msg); + setCommonProperty(msg.get()); return msg; } -BtMessageHandle +SharedHandle DefaultBtMessageFactory::createRequestMessage (const SharedHandle& piece, size_t blockIndex) { - BtRequestMessageHandle msg + BtRequestMessage* msg (new BtRequestMessage(piece->getIndex(), blockIndex*piece->getBlockLength(), piece->getBlockLength(blockIndex), blockIndex)); SharedHandle validator (new RangeBtMessageValidator - (msg.get(), + (msg, downloadContext_->getNumPieces(), pieceStorage_->getPieceLength(msg->getIndex()))); msg->setBtMessageValidator(validator); setCommonProperty(msg); - return msg; + return SharedHandle(msg); } -BtMessageHandle +SharedHandle DefaultBtMessageFactory::createCancelMessage (size_t index, int32_t begin, int32_t length) { - BtCancelMessageHandle msg(new BtCancelMessage(index, begin, length)); + BtCancelMessage* msg(new BtCancelMessage(index, begin, length)); SharedHandle validator (new RangeBtMessageValidator - (msg.get(), + (msg, downloadContext_->getNumPieces(), pieceStorage_->getPieceLength(index))); msg->setBtMessageValidator(validator); setCommonProperty(msg); - return msg; + return SharedHandle(msg); } -BtMessageHandle +SharedHandle DefaultBtMessageFactory::createPieceMessage (size_t index, int32_t begin, int32_t length) { - BtPieceMessageHandle msg(new BtPieceMessage(index, begin, length)); + BtPieceMessage* msg(new BtPieceMessage(index, begin, length)); BtMessageValidatorHandle validator - (new BtPieceMessageValidator(msg.get(), + (new BtPieceMessageValidator(msg, downloadContext_->getNumPieces(), pieceStorage_->getPieceLength(index))); msg->setBtMessageValidator(validator); msg->setDownloadContext(downloadContext_); setCommonProperty(msg); - return msg; + return SharedHandle(msg); } -BtMessageHandle +SharedHandle DefaultBtMessageFactory::createHaveMessage(size_t index) { - BtHaveMessageHandle msg(new BtHaveMessage(index)); + BtHaveMessage* msg(new BtHaveMessage(index)); SharedHandle v - (new IndexBtMessageValidator(msg.get(), downloadContext_->getNumPieces())); + (new IndexBtMessageValidator(msg, downloadContext_->getNumPieces())); msg->setBtMessageValidator(v); setCommonProperty(msg); - return msg; + return SharedHandle(msg); } -BtMessageHandle +SharedHandle DefaultBtMessageFactory::createChokeMessage() { - BtChokeMessageHandle msg(new BtChokeMessage()); + BtChokeMessage* msg(new BtChokeMessage()); setCommonProperty(msg); - return msg; + return SharedHandle(msg); } -BtMessageHandle +SharedHandle DefaultBtMessageFactory::createUnchokeMessage() { - BtUnchokeMessageHandle msg(new BtUnchokeMessage()); + BtUnchokeMessage* msg(new BtUnchokeMessage()); setCommonProperty(msg); - return msg; + return SharedHandle(msg); } - -BtMessageHandle + +SharedHandle DefaultBtMessageFactory::createInterestedMessage() { - BtInterestedMessageHandle msg(new BtInterestedMessage()); + BtInterestedMessage* msg(new BtInterestedMessage()); setCommonProperty(msg); - return msg; + return SharedHandle(msg); } -BtMessageHandle +SharedHandle DefaultBtMessageFactory::createNotInterestedMessage() { - BtNotInterestedMessageHandle msg(new BtNotInterestedMessage()); + BtNotInterestedMessage* msg(new BtNotInterestedMessage()); setCommonProperty(msg); - return msg; + return SharedHandle(msg); } -BtMessageHandle +SharedHandle DefaultBtMessageFactory::createBitfieldMessage() { - BtBitfieldMessageHandle msg + BtBitfieldMessage* msg (new BtBitfieldMessage(pieceStorage_->getBitfield(), pieceStorage_->getBitfieldLength())); SharedHandle v - (new BtBitfieldMessageValidator(msg.get(), - downloadContext_->getNumPieces())); + (new BtBitfieldMessageValidator(msg, downloadContext_->getNumPieces())); msg->setBtMessageValidator(v); setCommonProperty(msg); - return msg; + return SharedHandle(msg); } -BtMessageHandle +SharedHandle DefaultBtMessageFactory::createKeepAliveMessage() { - BtKeepAliveMessageHandle msg(new BtKeepAliveMessage()); + BtKeepAliveMessage* msg(new BtKeepAliveMessage()); setCommonProperty(msg); - return msg; -} + return SharedHandle(msg); +} -BtMessageHandle +SharedHandle DefaultBtMessageFactory::createHaveAllMessage() { - BtHaveAllMessageHandle msg(new BtHaveAllMessage()); + BtHaveAllMessage* msg(new BtHaveAllMessage()); setCommonProperty(msg); - return msg; + return SharedHandle(msg); } -BtMessageHandle +SharedHandle DefaultBtMessageFactory::createHaveNoneMessage() { - BtHaveNoneMessageHandle msg(new BtHaveNoneMessage()); + BtHaveNoneMessage* msg(new BtHaveNoneMessage()); setCommonProperty(msg); - return msg; + return SharedHandle(msg); } -BtMessageHandle +SharedHandle DefaultBtMessageFactory::createRejectMessage (size_t index, int32_t begin, int32_t length) { - BtRejectMessageHandle msg(new BtRejectMessage(index, begin, length)); + BtRejectMessage* msg(new BtRejectMessage(index, begin, length)); SharedHandle validator (new RangeBtMessageValidator - (msg.get(), + (msg, downloadContext_->getNumPieces(), pieceStorage_->getPieceLength(index))); msg->setBtMessageValidator(validator); setCommonProperty(msg); - return msg; + return SharedHandle(msg); } -BtMessageHandle +SharedHandle DefaultBtMessageFactory::createAllowedFastMessage(size_t index) { - BtAllowedFastMessageHandle msg(new BtAllowedFastMessage(index)); + BtAllowedFastMessage* msg(new BtAllowedFastMessage(index)); SharedHandle validator - (new IndexBtMessageValidator(msg.get(), downloadContext_->getNumPieces())); + (new IndexBtMessageValidator(msg, downloadContext_->getNumPieces())); msg->setBtMessageValidator(validator); setCommonProperty(msg); - return msg; + return SharedHandle(msg); } -BtMessageHandle +SharedHandle DefaultBtMessageFactory::createPortMessage(uint16_t port) { - SharedHandle msg(new BtPortMessage(port)); + BtPortMessage* msg(new BtPortMessage(port)); setCommonProperty(msg); - return msg; + return SharedHandle(msg); } -BtMessageHandle +SharedHandle DefaultBtMessageFactory::createBtExtendedMessage (const ExtensionMessageHandle& msg) { - BtExtendedMessageHandle m(new BtExtendedMessage(msg)); + BtExtendedMessage* m(new BtExtendedMessage(msg)); setCommonProperty(m); - return m; + return SharedHandle(m); } void DefaultBtMessageFactory::setTaskQueue(DHTTaskQueue* taskQueue) diff --git a/src/DefaultBtMessageFactory.h b/src/DefaultBtMessageFactory.h index d71c3b20..c6875e6d 100644 --- a/src/DefaultBtMessageFactory.h +++ b/src/DefaultBtMessageFactory.h @@ -71,7 +71,7 @@ private: PeerConnection* peerConnection_; SharedHandle extensionMessageFactory_; - + DHTNode* localNode_; DHTRoutingTable* routingTable_; @@ -82,7 +82,7 @@ private: bool metadataGetMode_; - void setCommonProperty(const SharedHandle& msg); + void setCommonProperty(AbstractBtMessage* msg); public: DefaultBtMessageFactory(); @@ -112,7 +112,7 @@ public: virtual SharedHandle createChokeMessage(); virtual SharedHandle createUnchokeMessage(); - + virtual SharedHandle createInterestedMessage(); virtual SharedHandle createNotInterestedMessage(); @@ -120,7 +120,7 @@ public: virtual SharedHandle createBitfieldMessage(); virtual SharedHandle createKeepAliveMessage(); - + virtual SharedHandle createHaveAllMessage(); virtual SharedHandle createHaveNoneMessage(); @@ -154,7 +154,7 @@ public: void setBtMessageDispatcher (BtMessageDispatcher* dispatcher); - + void setBtRequestFactory(BtRequestFactory* factory); void setPeerConnection(PeerConnection* connection); @@ -165,7 +165,7 @@ public: void setLocalNode(DHTNode* localNode); void setRoutingTable(DHTRoutingTable* routingTable); - + void setTaskQueue(DHTTaskQueue* taskQueue); void setTaskFactory(DHTTaskFactory* taskFactory); @@ -176,8 +176,6 @@ public: } }; -typedef SharedHandle DefaultBtMessageFactoryHandle; - } // namespace aria2 #endif // D_DEFAULT_BT_MESSAGE_FACTORY_H diff --git a/src/IndexBtMessage.h b/src/IndexBtMessage.h index a685480a..6ee16758 100644 --- a/src/IndexBtMessage.h +++ b/src/IndexBtMessage.h @@ -47,11 +47,11 @@ private: static const size_t MESSAGE_LENGTH = 9; protected: template - static SharedHandle create(const unsigned char* data, size_t dataLength) + static T* create(const unsigned char* data, size_t dataLength) { bittorrent::assertPayloadLengthEqual(5, dataLength, T::NAME); bittorrent::assertID(T::ID, data, T::NAME); - SharedHandle message(new T()); + T* message(new T()); message->setIndex(bittorrent::getIntParam(data, 1)); return message; } diff --git a/src/RangeBtMessage.h b/src/RangeBtMessage.h index a36c2e79..3ba2179f 100644 --- a/src/RangeBtMessage.h +++ b/src/RangeBtMessage.h @@ -49,12 +49,11 @@ private: static const size_t MESSAGE_LENGTH = 17; protected: template - static SharedHandle create - (const unsigned char* data, size_t dataLength) + static T* create(const unsigned char* data, size_t dataLength) { bittorrent::assertPayloadLengthEqual(13, dataLength, T::NAME); bittorrent::assertID(T::ID, data, T::NAME); - SharedHandle message(new T()); + T* message(new T()); message->setIndex(bittorrent::getIntParam(data, 1)); message->setBegin(bittorrent::getIntParam(data, 5)); message->setLength(bittorrent::getIntParam(data, 9)); diff --git a/src/ZeroBtMessage.h b/src/ZeroBtMessage.h index f13dc995..f387cc70 100644 --- a/src/ZeroBtMessage.h +++ b/src/ZeroBtMessage.h @@ -45,11 +45,11 @@ private: static const size_t MESSAGE_LENGTH = 5; protected: template - static SharedHandle create(const unsigned char* data, size_t dataLength) + static T* create(const unsigned char* data, size_t dataLength) { bittorrent::assertPayloadLengthEqual(1, dataLength, T::NAME); bittorrent::assertID(T::ID, data, T::NAME); - SharedHandle message(new T()); + T* message(new T()); return message; } diff --git a/test/BtAllowedFastMessageTest.cc b/test/BtAllowedFastMessageTest.cc index d334b9a0..5e996660 100644 --- a/test/BtAllowedFastMessageTest.cc +++ b/test/BtAllowedFastMessageTest.cc @@ -38,7 +38,8 @@ void BtAllowedFastMessageTest::testCreate() { unsigned char msg[9]; bittorrent::createPeerMessageString(msg, sizeof(msg), 5, 17); bittorrent::setIntParam(&msg[5], 12345); - SharedHandle pm = BtAllowedFastMessage::create(&msg[4], 5); + SharedHandle pm + (BtAllowedFastMessage::create(&msg[4], 5)); CPPUNIT_ASSERT_EQUAL((uint8_t)17, pm->getId()); CPPUNIT_ASSERT_EQUAL((size_t)12345, pm->getIndex()); diff --git a/test/BtBitfieldMessageTest.cc b/test/BtBitfieldMessageTest.cc index 8ad2e0b5..826b219d 100644 --- a/test/BtBitfieldMessageTest.cc +++ b/test/BtBitfieldMessageTest.cc @@ -44,7 +44,7 @@ void BtBitfieldMessageTest::testCreate() { unsigned char bitfield[2]; memset(bitfield, 0xff, sizeof(bitfield)); memcpy(&msg[5], bitfield, sizeof(bitfield)); - SharedHandle pm = BtBitfieldMessage::create(&msg[4], 3); + SharedHandle pm(BtBitfieldMessage::create(&msg[4], 3)); CPPUNIT_ASSERT_EQUAL((uint8_t)5, pm->getId()); CPPUNIT_ASSERT(memcmp(bitfield, pm->getBitfield(), sizeof(bitfield)) == 0); CPPUNIT_ASSERT_EQUAL((size_t)2, pm->getBitfieldLength()); @@ -89,7 +89,7 @@ void BtBitfieldMessageTest::testDoReceivedAction() { msg.setPieceStorage(pieceStorage); unsigned char bitfield[] = { 0xff, 0xff }; msg.setBitfield(bitfield, sizeof(bitfield)); - + CPPUNIT_ASSERT_EQUAL(std::string("0000"), util::toHex(peer->getBitfield(), peer->getBitfieldLength())); msg.doReceivedAction(); diff --git a/test/BtCancelMessageTest.cc b/test/BtCancelMessageTest.cc index 79621841..e69e3269 100644 --- a/test/BtCancelMessageTest.cc +++ b/test/BtCancelMessageTest.cc @@ -58,7 +58,7 @@ void BtCancelMessageTest::testCreate() { bittorrent::setIntParam(&msg[5], 12345); bittorrent::setIntParam(&msg[9], 256); bittorrent::setIntParam(&msg[13], 1024); - SharedHandle pm = BtCancelMessage::create(&msg[4], 13); + SharedHandle pm(BtCancelMessage::create(&msg[4], 13)); CPPUNIT_ASSERT_EQUAL((uint8_t)8, pm->getId()); CPPUNIT_ASSERT_EQUAL((size_t)12345, pm->getIndex()); CPPUNIT_ASSERT_EQUAL(256, pm->getBegin()); diff --git a/test/BtChokeMessageTest.cc b/test/BtChokeMessageTest.cc index dc89483c..94ed070e 100644 --- a/test/BtChokeMessageTest.cc +++ b/test/BtChokeMessageTest.cc @@ -71,7 +71,7 @@ CPPUNIT_TEST_SUITE_REGISTRATION(BtChokeMessageTest); void BtChokeMessageTest::testCreate() { unsigned char msg[5]; bittorrent::createPeerMessageString(msg, sizeof(msg), 1, 0); - SharedHandle pm = BtChokeMessage::create(&msg[4], 1); + SharedHandle pm(BtChokeMessage::create(&msg[4], 1)); CPPUNIT_ASSERT_EQUAL((uint8_t)0, pm->getId()); // case: payload size is wrong diff --git a/test/BtExtendedMessageTest.cc b/test/BtExtendedMessageTest.cc index a8bceff2..877b8701 100644 --- a/test/BtExtendedMessageTest.cc +++ b/test/BtExtendedMessageTest.cc @@ -45,11 +45,11 @@ void BtExtendedMessageTest::testCreate() { bittorrent::createPeerMessageString((unsigned char*)msg, sizeof(msg), 13, 20); msg[5] = 1; // Set dummy extended message ID 1 memcpy(msg+6, payload.c_str(), payload.size()); - SharedHandle pm = BtExtendedMessage::create(exmsgFactory, - peer, - &msg[4], 13); + SharedHandle pm(BtExtendedMessage::create(exmsgFactory, + peer, + &msg[4], 13)); CPPUNIT_ASSERT_EQUAL((uint8_t)20, pm->getId()); - + // case: payload size is wrong try { unsigned char msg[5]; diff --git a/test/BtHaveAllMessageTest.cc b/test/BtHaveAllMessageTest.cc index 78c1988f..5a965608 100644 --- a/test/BtHaveAllMessageTest.cc +++ b/test/BtHaveAllMessageTest.cc @@ -38,7 +38,7 @@ CPPUNIT_TEST_SUITE_REGISTRATION(BtHaveAllMessageTest); void BtHaveAllMessageTest::testCreate() { unsigned char msg[5]; bittorrent::createPeerMessageString(msg, sizeof(msg), 1, 14); - SharedHandle pm = BtHaveAllMessage::create(&msg[4], 1); + SharedHandle pm(BtHaveAllMessage::create(&msg[4], 1)); CPPUNIT_ASSERT_EQUAL((uint8_t)14, pm->getId()); // case: payload size is wrong diff --git a/test/BtHaveMessageTest.cc b/test/BtHaveMessageTest.cc index 4e6b0602..593a6605 100644 --- a/test/BtHaveMessageTest.cc +++ b/test/BtHaveMessageTest.cc @@ -41,7 +41,7 @@ void BtHaveMessageTest::testCreate() { unsigned char msg[9]; bittorrent::createPeerMessageString(msg, sizeof(msg), 5, 4); bittorrent::setIntParam(&msg[5], 12345); - SharedHandle pm = BtHaveMessage::create(&msg[4], 5); + SharedHandle pm(BtHaveMessage::create(&msg[4], 5)); CPPUNIT_ASSERT_EQUAL((uint8_t)4, pm->getId()); CPPUNIT_ASSERT_EQUAL((size_t)12345, pm->getIndex()); diff --git a/test/BtHaveNoneMessageTest.cc b/test/BtHaveNoneMessageTest.cc index 534b7eb9..50fff402 100644 --- a/test/BtHaveNoneMessageTest.cc +++ b/test/BtHaveNoneMessageTest.cc @@ -35,7 +35,7 @@ CPPUNIT_TEST_SUITE_REGISTRATION(BtHaveNoneMessageTest); void BtHaveNoneMessageTest::testCreate() { unsigned char msg[5]; bittorrent::createPeerMessageString(msg, sizeof(msg), 1, 15); - SharedHandle pm = BtHaveNoneMessage::create(&msg[4], 1); + SharedHandle pm(BtHaveNoneMessage::create(&msg[4], 1)); CPPUNIT_ASSERT_EQUAL((uint8_t)15, pm->getId()); // case: payload size is wrong diff --git a/test/BtInterestedMessageTest.cc b/test/BtInterestedMessageTest.cc index 068192f4..e0accffe 100644 --- a/test/BtInterestedMessageTest.cc +++ b/test/BtInterestedMessageTest.cc @@ -33,7 +33,8 @@ CPPUNIT_TEST_SUITE_REGISTRATION(BtInterestedMessageTest); void BtInterestedMessageTest::testCreate() { unsigned char msg[5]; bittorrent::createPeerMessageString(msg, sizeof(msg), 1, 2); - BtInterestedMessageHandle pm = BtInterestedMessage::create(&msg[4], 1); + SharedHandle pm + (BtInterestedMessage::create(&msg[4], 1)); CPPUNIT_ASSERT_EQUAL((uint8_t)2, pm->getId()); // case: payload size is wrong diff --git a/test/BtNotInterestedMessageTest.cc b/test/BtNotInterestedMessageTest.cc index 0e651cc5..d9a8e5f1 100644 --- a/test/BtNotInterestedMessageTest.cc +++ b/test/BtNotInterestedMessageTest.cc @@ -33,7 +33,8 @@ CPPUNIT_TEST_SUITE_REGISTRATION(BtNotInterestedMessageTest); void BtNotInterestedMessageTest::testCreate() { unsigned char msg[5]; bittorrent::createPeerMessageString(msg, sizeof(msg), 1, 3); - BtNotInterestedMessageHandle pm = BtNotInterestedMessage::create(&msg[4], 1); + SharedHandle pm + (BtNotInterestedMessage::create(&msg[4], 1)); CPPUNIT_ASSERT_EQUAL((uint8_t)3, pm->getId()); // case: payload size is wrong diff --git a/test/BtPieceMessageTest.cc b/test/BtPieceMessageTest.cc index c1338dc7..cd7f446a 100644 --- a/test/BtPieceMessageTest.cc +++ b/test/BtPieceMessageTest.cc @@ -110,7 +110,7 @@ void BtPieceMessageTest::testCreate() { bittorrent::setIntParam(&msg[5], 12345); bittorrent::setIntParam(&msg[9], 256); memcpy(&msg[13], data, sizeof(data)); - SharedHandle pm = BtPieceMessage::create(&msg[4], 11); + SharedHandle pm(BtPieceMessage::create(&msg[4], 11)); CPPUNIT_ASSERT_EQUAL((uint8_t)7, pm->getId()); CPPUNIT_ASSERT_EQUAL((size_t)12345, pm->getIndex()); CPPUNIT_ASSERT_EQUAL(256, pm->getBegin()); diff --git a/test/BtPortMessageTest.cc b/test/BtPortMessageTest.cc index 6d6a9446..dff262f3 100644 --- a/test/BtPortMessageTest.cc +++ b/test/BtPortMessageTest.cc @@ -62,7 +62,7 @@ void BtPortMessageTest::testCreate() { unsigned char msg[7]; bittorrent::createPeerMessageString(msg, sizeof(msg), 3, 9); bittorrent::setShortIntParam(&msg[5], 12345); - SharedHandle pm = BtPortMessage::create(&msg[4], 3); + SharedHandle pm(BtPortMessage::create(&msg[4], 3)); CPPUNIT_ASSERT_EQUAL((uint8_t)9, pm->getId()); CPPUNIT_ASSERT_EQUAL((uint16_t)12345, pm->getPort()); diff --git a/test/BtRejectMessageTest.cc b/test/BtRejectMessageTest.cc index 6caf8bae..678d6b9c 100644 --- a/test/BtRejectMessageTest.cc +++ b/test/BtRejectMessageTest.cc @@ -90,7 +90,7 @@ void BtRejectMessageTest::testCreate() { bittorrent::setIntParam(&msg[5], 12345); bittorrent::setIntParam(&msg[9], 256); bittorrent::setIntParam(&msg[13], 1024); - SharedHandle pm = BtRejectMessage::create(&msg[4], 13); + SharedHandle pm(BtRejectMessage::create(&msg[4], 13)); CPPUNIT_ASSERT_EQUAL((uint8_t)16, pm->getId()); CPPUNIT_ASSERT_EQUAL((size_t)12345, pm->getIndex()); CPPUNIT_ASSERT_EQUAL(256, pm->getBegin()); diff --git a/test/BtRequestMessageTest.cc b/test/BtRequestMessageTest.cc index 20f0ba93..23a9132e 100644 --- a/test/BtRequestMessageTest.cc +++ b/test/BtRequestMessageTest.cc @@ -132,7 +132,7 @@ void BtRequestMessageTest::testCreate() { bittorrent::setIntParam(&msg[5], 12345); bittorrent::setIntParam(&msg[9], 256); bittorrent::setIntParam(&msg[13], 1024); - SharedHandle pm = BtRequestMessage::create(&msg[4], 13); + SharedHandle pm(BtRequestMessage::create(&msg[4], 13)); CPPUNIT_ASSERT_EQUAL((uint8_t)6, pm->getId()); CPPUNIT_ASSERT_EQUAL((size_t)12345, pm->getIndex()); CPPUNIT_ASSERT_EQUAL(256, pm->getBegin()); diff --git a/test/BtSuggestPieceMessageTest.cc b/test/BtSuggestPieceMessageTest.cc index 8a56d4b9..cad8cff2 100644 --- a/test/BtSuggestPieceMessageTest.cc +++ b/test/BtSuggestPieceMessageTest.cc @@ -32,7 +32,8 @@ void BtSuggestPieceMessageTest::testCreate() { unsigned char msg[9]; bittorrent::createPeerMessageString(msg, sizeof(msg), 5, 13); bittorrent::setIntParam(&msg[5], 12345); - SharedHandle pm = BtSuggestPieceMessage::create(&msg[4], 5); + SharedHandle pm + (BtSuggestPieceMessage::create(&msg[4], 5)); CPPUNIT_ASSERT_EQUAL((uint8_t)13, pm->getId()); CPPUNIT_ASSERT_EQUAL((size_t)12345, pm->getIndex()); diff --git a/test/BtUnchokeMessageTest.cc b/test/BtUnchokeMessageTest.cc index 77e078a0..639a8406 100644 --- a/test/BtUnchokeMessageTest.cc +++ b/test/BtUnchokeMessageTest.cc @@ -33,7 +33,7 @@ CPPUNIT_TEST_SUITE_REGISTRATION(BtUnchokeMessageTest); void BtUnchokeMessageTest::testCreate() { unsigned char msg[5]; bittorrent::createPeerMessageString(msg, sizeof(msg), 1, 1); - SharedHandle pm = BtUnchokeMessage::create(&msg[4], 1); + SharedHandle pm(BtUnchokeMessage::create(&msg[4], 1)); CPPUNIT_ASSERT_EQUAL((uint8_t)1, pm->getId()); // case: payload size is wrong