From 4e0c03500cb4d78cd873086072c9fac3cc8bc573 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Wed, 11 Mar 2009 15:44:04 +0000 Subject: [PATCH] 2009-03-12 Tatsuhiro Tsujikawa BtMessage now holds _id attribute. MESSAGE_LENGTH that is declared as non-const previously is now const and defined in class definition. * src/AbstractBtMessage.cc * src/AbstractBtMessage.h * src/BtAllowedFastMessage.cc * src/BtAllowedFastMessage.h * src/BtBitfieldMessage.h * src/BtCancelMessage.cc * src/BtCancelMessage.h * src/BtChokeMessage.cc * src/BtChokeMessage.h * src/BtExtendedMessage.cc * src/BtExtendedMessage.h * src/BtHandshakeMessage.cc * src/BtHandshakeMessage.h * src/BtHaveAllMessage.cc * src/BtHaveAllMessage.h * src/BtHaveMessage.cc * src/BtHaveMessage.h * src/BtHaveNoneMessage.cc * src/BtHaveNoneMessage.h * src/BtInterestedMessage.cc * src/BtInterestedMessage.h * src/BtKeepAliveMessage.cc * src/BtKeepAliveMessage.h * src/BtMessage.h * src/BtNotInterestedMessage.cc * src/BtNotInterestedMessage.h * src/BtPieceMessage.h * src/BtPortMessage.cc * src/BtPortMessage.h * src/BtRejectMessage.cc * src/BtRejectMessage.h * src/BtRequestMessage.cc * src/BtRequestMessage.h * src/BtSuggestPieceMessage.cc * src/BtSuggestPieceMessage.h * src/BtUnchokeMessage.cc * src/BtUnchokeMessage.h * src/SimpleBtMessage.cc * src/SimpleBtMessage.h * test/MockBtMessage.h --- ChangeLog | 46 +++++++++++++++++++++++++++++++++++ src/AbstractBtMessage.cc | 12 +++++---- src/AbstractBtMessage.h | 2 +- src/BtAllowedFastMessage.cc | 2 -- src/BtAllowedFastMessage.h | 6 ++--- src/BtBitfieldMessage.h | 6 ++--- src/BtCancelMessage.cc | 2 -- src/BtCancelMessage.h | 6 ++--- src/BtChokeMessage.cc | 2 -- src/BtChokeMessage.h | 6 ++--- src/BtExtendedMessage.cc | 7 +++++- src/BtExtendedMessage.h | 2 -- src/BtHandshakeMessage.cc | 6 +++-- src/BtHandshakeMessage.h | 2 -- src/BtHaveAllMessage.cc | 2 -- src/BtHaveAllMessage.h | 6 ++--- src/BtHaveMessage.cc | 2 -- src/BtHaveMessage.h | 6 ++--- src/BtHaveNoneMessage.cc | 2 -- src/BtHaveNoneMessage.h | 6 ++--- src/BtInterestedMessage.cc | 2 -- src/BtInterestedMessage.h | 7 ++---- src/BtKeepAliveMessage.cc | 2 -- src/BtKeepAliveMessage.h | 6 ++--- src/BtMessage.h | 6 ++++- src/BtNotInterestedMessage.cc | 2 -- src/BtNotInterestedMessage.h | 6 ++--- src/BtPieceMessage.h | 5 ++-- src/BtPortMessage.cc | 3 ++- src/BtPortMessage.h | 2 -- src/BtRejectMessage.cc | 2 -- src/BtRejectMessage.h | 7 +++--- src/BtRequestMessage.cc | 2 -- src/BtRequestMessage.h | 7 +++--- src/BtSuggestPieceMessage.cc | 2 -- src/BtSuggestPieceMessage.h | 6 ++--- src/BtUnchokeMessage.cc | 2 -- src/BtUnchokeMessage.h | 6 ++--- src/SimpleBtMessage.cc | 2 +- src/SimpleBtMessage.h | 2 +- test/MockBtMessage.h | 13 +++------- 41 files changed, 108 insertions(+), 115 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9886f75b..94587ed4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,49 @@ +2009-03-12 Tatsuhiro Tsujikawa + + BtMessage now holds _id attribute. MESSAGE_LENGTH that is + declared as non-const previously is now const and defined in class + definition. + * src/AbstractBtMessage.cc + * src/AbstractBtMessage.h + * src/BtAllowedFastMessage.cc + * src/BtAllowedFastMessage.h + * src/BtBitfieldMessage.h + * src/BtCancelMessage.cc + * src/BtCancelMessage.h + * src/BtChokeMessage.cc + * src/BtChokeMessage.h + * src/BtExtendedMessage.cc + * src/BtExtendedMessage.h + * src/BtHandshakeMessage.cc + * src/BtHandshakeMessage.h + * src/BtHaveAllMessage.cc + * src/BtHaveAllMessage.h + * src/BtHaveMessage.cc + * src/BtHaveMessage.h + * src/BtHaveNoneMessage.cc + * src/BtHaveNoneMessage.h + * src/BtInterestedMessage.cc + * src/BtInterestedMessage.h + * src/BtKeepAliveMessage.cc + * src/BtKeepAliveMessage.h + * src/BtMessage.h + * src/BtNotInterestedMessage.cc + * src/BtNotInterestedMessage.h + * src/BtPieceMessage.h + * src/BtPortMessage.cc + * src/BtPortMessage.h + * src/BtRejectMessage.cc + * src/BtRejectMessage.h + * src/BtRequestMessage.cc + * src/BtRequestMessage.h + * src/BtSuggestPieceMessage.cc + * src/BtSuggestPieceMessage.h + * src/BtUnchokeMessage.cc + * src/BtUnchokeMessage.h + * src/SimpleBtMessage.cc + * src/SimpleBtMessage.h + * test/MockBtMessage.h + 2009-03-12 Tatsuhiro Tsujikawa Use FileEntry::exists() diff --git a/src/AbstractBtMessage.cc b/src/AbstractBtMessage.cc index 51777769..455dbc7b 100644 --- a/src/AbstractBtMessage.cc +++ b/src/AbstractBtMessage.cc @@ -43,11 +43,13 @@ namespace aria2 { -AbstractBtMessage::AbstractBtMessage():sendingInProgress(false), - invalidate(false), - uploading(false), - cuid(0), - logger(LogFactory::getInstance()) +AbstractBtMessage::AbstractBtMessage(uint8_t id): + BtMessage(id), + sendingInProgress(false), + invalidate(false), + uploading(false), + cuid(0), + logger(LogFactory::getInstance()) {} AbstractBtMessage::~AbstractBtMessage() {} diff --git a/src/AbstractBtMessage.h b/src/AbstractBtMessage.h index d1663eb3..3acb1c5b 100644 --- a/src/AbstractBtMessage.h +++ b/src/AbstractBtMessage.h @@ -78,7 +78,7 @@ protected: Logger* logger; public: - AbstractBtMessage(); + AbstractBtMessage(uint8_t id); virtual ~AbstractBtMessage(); diff --git a/src/BtAllowedFastMessage.cc b/src/BtAllowedFastMessage.cc index 434a053c..b9d557fe 100644 --- a/src/BtAllowedFastMessage.cc +++ b/src/BtAllowedFastMessage.cc @@ -66,8 +66,6 @@ void BtAllowedFastMessage::doReceivedAction() { peer->addPeerAllowedIndex(index); } -size_t BtAllowedFastMessage::MESSAGE_LENGTH = 9; - const unsigned char* BtAllowedFastMessage::getMessage() { if(!msg) { /** diff --git a/src/BtAllowedFastMessage.h b/src/BtAllowedFastMessage.h index b435b5e8..8d25d388 100644 --- a/src/BtAllowedFastMessage.h +++ b/src/BtAllowedFastMessage.h @@ -48,10 +48,10 @@ private: size_t index; unsigned char* msg; - static size_t MESSAGE_LENGTH; + static const size_t MESSAGE_LENGTH = 9; public: BtAllowedFastMessage(size_t index = 0) - :SimpleBtMessage(), + :SimpleBtMessage(ID), index(index), msg(0) {} @@ -68,8 +68,6 @@ public: static BtAllowedFastMessageHandle create(const unsigned char* data, size_t dataLength); - virtual uint8_t getId() { return ID; } - virtual void doReceivedAction(); virtual const unsigned char* getMessage(); diff --git a/src/BtBitfieldMessage.h b/src/BtBitfieldMessage.h index 0808d917..03fe02a8 100644 --- a/src/BtBitfieldMessage.h +++ b/src/BtBitfieldMessage.h @@ -57,13 +57,13 @@ private: msgLength = 0; } public: - BtBitfieldMessage():SimpleBtMessage() + BtBitfieldMessage():SimpleBtMessage(ID) { init(); } BtBitfieldMessage(const unsigned char* bitfield, - size_t bitfieldLength):SimpleBtMessage() + size_t bitfieldLength):SimpleBtMessage(ID) { init(); setBitfield(bitfield, bitfieldLength); @@ -84,8 +84,6 @@ public: static BtBitfieldMessageHandle create(const unsigned char* data, size_t dataLength); - virtual uint8_t getId() { return ID; } - virtual void doReceivedAction(); virtual const unsigned char* getMessage(); diff --git a/src/BtCancelMessage.cc b/src/BtCancelMessage.cc index ef6d3dac..a87e904c 100644 --- a/src/BtCancelMessage.cc +++ b/src/BtCancelMessage.cc @@ -63,8 +63,6 @@ void BtCancelMessage::doReceivedAction() { dispatcher->doCancelSendingPieceAction(index, begin, length); } -size_t BtCancelMessage::MESSAGE_LENGTH = 17; - const unsigned char* BtCancelMessage::getMessage() { if(!msg) { /** diff --git a/src/BtCancelMessage.h b/src/BtCancelMessage.h index d6fd5569..8dd6f12c 100644 --- a/src/BtCancelMessage.h +++ b/src/BtCancelMessage.h @@ -50,10 +50,10 @@ private: size_t length; unsigned char* msg; - static size_t MESSAGE_LENGTH; + static const size_t MESSAGE_LENGTH = 17; public: BtCancelMessage(size_t index = 0, uint32_t begin = 0, size_t length = 0) - :SimpleBtMessage(), + :SimpleBtMessage(ID), index(index), begin(begin), length(length), @@ -79,8 +79,6 @@ public: static BtCancelMessageHandle create(const unsigned char* data, size_t dataLength); - virtual uint8_t getId() { return ID; } - virtual void doReceivedAction(); virtual const unsigned char* getMessage(); diff --git a/src/BtChokeMessage.cc b/src/BtChokeMessage.cc index e158ebbc..6854386b 100644 --- a/src/BtChokeMessage.cc +++ b/src/BtChokeMessage.cc @@ -67,8 +67,6 @@ bool BtChokeMessage::sendPredicate() const { return !peer->amChoking(); } -size_t BtChokeMessage::MESSAGE_LENGTH = 5; - const unsigned char* BtChokeMessage::getMessage() { if(!msg) { /** diff --git a/src/BtChokeMessage.h b/src/BtChokeMessage.h index dba5223f..442097fe 100644 --- a/src/BtChokeMessage.h +++ b/src/BtChokeMessage.h @@ -47,9 +47,9 @@ class BtChokeMessage : public SimpleBtMessage { private: unsigned char* msg; - static size_t MESSAGE_LENGTH; + static const size_t MESSAGE_LENGTH = 5; public: - BtChokeMessage():SimpleBtMessage(), msg(0) {} + BtChokeMessage():SimpleBtMessage(ID), msg(0) {} virtual ~BtChokeMessage() { delete [] msg; @@ -57,8 +57,6 @@ public: static const uint8_t ID = 0; - virtual uint8_t getId() { return ID; } - virtual void doReceivedAction(); virtual const unsigned char* getMessage(); diff --git a/src/BtExtendedMessage.cc b/src/BtExtendedMessage.cc index 1eac1117..ec626cf2 100644 --- a/src/BtExtendedMessage.cc +++ b/src/BtExtendedMessage.cc @@ -47,7 +47,12 @@ namespace aria2 { -BtExtendedMessage::BtExtendedMessage(const ExtensionMessageHandle& extensionMessage):_extensionMessage(extensionMessage), _msg(0), _msgLength(0) +BtExtendedMessage::BtExtendedMessage +(const ExtensionMessageHandle& extensionMessage): + SimpleBtMessage(ID), + _extensionMessage(extensionMessage), + _msg(0), + _msgLength(0) {} BtExtendedMessage::~BtExtendedMessage() diff --git a/src/BtExtendedMessage.h b/src/BtExtendedMessage.h index 9dfbb8a1..c231c869 100644 --- a/src/BtExtendedMessage.h +++ b/src/BtExtendedMessage.h @@ -66,8 +66,6 @@ public: const unsigned char* data, size_t dataLength); - virtual uint8_t getId() { return ID; } - virtual void doReceivedAction(); virtual const unsigned char* getMessage(); diff --git a/src/BtHandshakeMessage.cc b/src/BtHandshakeMessage.cc index 22b384a7..5fd5aff4 100644 --- a/src/BtHandshakeMessage.cc +++ b/src/BtHandshakeMessage.cc @@ -42,12 +42,14 @@ namespace aria2 { const unsigned char* BtHandshakeMessage::BT_PSTR = (const unsigned char*)"BitTorrent protocol"; -BtHandshakeMessage::BtHandshakeMessage() { +BtHandshakeMessage::BtHandshakeMessage():SimpleBtMessage(ID) +{ init(); } BtHandshakeMessage::BtHandshakeMessage(const unsigned char* infoHash, - const unsigned char* peerId) + const unsigned char* peerId): + SimpleBtMessage(ID) { init(); memcpy(this->infoHash, infoHash, INFO_HASH_LENGTH); diff --git a/src/BtHandshakeMessage.h b/src/BtHandshakeMessage.h index 91447253..ef36a3bb 100644 --- a/src/BtHandshakeMessage.h +++ b/src/BtHandshakeMessage.h @@ -74,8 +74,6 @@ public: static const uint8_t ID = INT8_MAX; - virtual uint8_t getId() { return ID; } - virtual void doReceivedAction() {}; virtual const unsigned char* getMessage(); diff --git a/src/BtHaveAllMessage.cc b/src/BtHaveAllMessage.cc index 38c763bf..efdc6f9b 100644 --- a/src/BtHaveAllMessage.cc +++ b/src/BtHaveAllMessage.cc @@ -67,8 +67,6 @@ void BtHaveAllMessage::doReceivedAction() { pieceStorage->addPieceStats(peer->getBitfield(), peer->getBitfieldLength()); } -size_t BtHaveAllMessage::MESSAGE_LENGTH = 5; - const unsigned char* BtHaveAllMessage::getMessage() { if(!msg) { /** diff --git a/src/BtHaveAllMessage.h b/src/BtHaveAllMessage.h index 7f9c08f7..4eb79c1f 100644 --- a/src/BtHaveAllMessage.h +++ b/src/BtHaveAllMessage.h @@ -47,9 +47,9 @@ class BtHaveAllMessage : public SimpleBtMessage { private: unsigned char* msg; - static size_t MESSAGE_LENGTH; + static const size_t MESSAGE_LENGTH = 5; public: - BtHaveAllMessage():msg(0) {} + BtHaveAllMessage():SimpleBtMessage(ID), msg(0) {} virtual ~BtHaveAllMessage() { delete [] msg; @@ -59,8 +59,6 @@ public: static BtHaveAllMessageHandle create(const unsigned char* data, size_t dataLength); - virtual uint8_t getId() { return ID; } - virtual void doReceivedAction(); virtual const unsigned char* getMessage(); diff --git a/src/BtHaveMessage.cc b/src/BtHaveMessage.cc index 92489311..1afd48df 100644 --- a/src/BtHaveMessage.cc +++ b/src/BtHaveMessage.cc @@ -63,8 +63,6 @@ void BtHaveMessage::doReceivedAction() { pieceStorage->addPieceStats(index); } -size_t BtHaveMessage::MESSAGE_LENGTH = 9; - const unsigned char* BtHaveMessage::getMessage() { if(!msg) { /** diff --git a/src/BtHaveMessage.h b/src/BtHaveMessage.h index a8d28645..9ff9423f 100644 --- a/src/BtHaveMessage.h +++ b/src/BtHaveMessage.h @@ -47,9 +47,9 @@ class BtHaveMessage : public SimpleBtMessage { private: size_t index; unsigned char* msg; - static size_t MESSAGE_LENGTH; + static const size_t MESSAGE_LENGTH = 9; public: - BtHaveMessage(size_t index = 0):index(index), msg(0) {} + BtHaveMessage(size_t index = 0):SimpleBtMessage(ID), index(index), msg(0) {} virtual ~BtHaveMessage() { delete [] msg; @@ -65,8 +65,6 @@ public: static BtHaveMessageHandle create(const unsigned char* data, size_t dataLength); - virtual uint8_t getId() { return ID; } - virtual void doReceivedAction(); virtual const unsigned char* getMessage(); diff --git a/src/BtHaveNoneMessage.cc b/src/BtHaveNoneMessage.cc index 17eec5ca..3981a20a 100644 --- a/src/BtHaveNoneMessage.cc +++ b/src/BtHaveNoneMessage.cc @@ -63,8 +63,6 @@ void BtHaveNoneMessage::doReceivedAction() { } } -size_t BtHaveNoneMessage::MESSAGE_LENGTH = 5; - const unsigned char* BtHaveNoneMessage::getMessage() { if(!msg) { /** diff --git a/src/BtHaveNoneMessage.h b/src/BtHaveNoneMessage.h index 1df2367a..4aaee64c 100644 --- a/src/BtHaveNoneMessage.h +++ b/src/BtHaveNoneMessage.h @@ -47,9 +47,9 @@ class BtHaveNoneMessage : public SimpleBtMessage { private: unsigned char* msg; - static size_t MESSAGE_LENGTH; + static const size_t MESSAGE_LENGTH = 5; public: - BtHaveNoneMessage():msg(0) {} + BtHaveNoneMessage():SimpleBtMessage(ID), msg(0) {} virtual ~BtHaveNoneMessage() { delete [] msg; @@ -59,8 +59,6 @@ public: static BtHaveNoneMessageHandle create(const unsigned char* data, size_t dataLength); - virtual uint8_t getId() { return ID; } - virtual void doReceivedAction(); virtual const unsigned char* getMessage(); diff --git a/src/BtInterestedMessage.cc b/src/BtInterestedMessage.cc index 0224f747..18ae56c2 100644 --- a/src/BtInterestedMessage.cc +++ b/src/BtInterestedMessage.cc @@ -68,8 +68,6 @@ bool BtInterestedMessage::sendPredicate() const { return !peer->amInterested(); } -size_t BtInterestedMessage::MESSAGE_LENGTH = 5; - const unsigned char* BtInterestedMessage::getMessage() { if(!msg) { /** diff --git a/src/BtInterestedMessage.h b/src/BtInterestedMessage.h index 08727f09..0a3fe8ec 100644 --- a/src/BtInterestedMessage.h +++ b/src/BtInterestedMessage.h @@ -50,10 +50,9 @@ private: SharedHandle _peerStorage; - static size_t MESSAGE_LENGTH; - + static const size_t MESSAGE_LENGTH = 5; public: - BtInterestedMessage():msg(0) {} + BtInterestedMessage():SimpleBtMessage(ID), msg(0) {} virtual ~BtInterestedMessage() { delete [] msg; @@ -63,8 +62,6 @@ public: static BtInterestedMessageHandle create(const unsigned char* data, size_t dataLength); - virtual uint8_t getId() { return ID; } - virtual void doReceivedAction(); virtual const unsigned char* getMessage(); diff --git a/src/BtKeepAliveMessage.cc b/src/BtKeepAliveMessage.cc index 3b62669e..6998ba49 100644 --- a/src/BtKeepAliveMessage.cc +++ b/src/BtKeepAliveMessage.cc @@ -37,8 +37,6 @@ namespace aria2 { -size_t BtKeepAliveMessage::MESSAGE_LENGTH = 4; - const unsigned char* BtKeepAliveMessage::getMessage() { if(!msg) { /** diff --git a/src/BtKeepAliveMessage.h b/src/BtKeepAliveMessage.h index 2876bad2..f100c7cb 100644 --- a/src/BtKeepAliveMessage.h +++ b/src/BtKeepAliveMessage.h @@ -47,9 +47,9 @@ class BtKeepAliveMessage : public SimpleBtMessage { private: unsigned char* msg; - static size_t MESSAGE_LENGTH; + static const size_t MESSAGE_LENGTH = 4; public: - BtKeepAliveMessage():msg(0) {} + BtKeepAliveMessage():SimpleBtMessage(ID), msg(0) {} virtual ~BtKeepAliveMessage() { delete [] msg; @@ -57,8 +57,6 @@ public: static const uint8_t ID = 99; - virtual uint8_t getId() { return ID; } - virtual void doReceivedAction() {} virtual const unsigned char* getMessage(); diff --git a/src/BtMessage.h b/src/BtMessage.h index 4303b8a1..6a10cf7f 100644 --- a/src/BtMessage.h +++ b/src/BtMessage.h @@ -45,7 +45,11 @@ namespace aria2 { class BtEvent; class BtMessage { +private: + uint8_t _id; public: + BtMessage(uint8_t id):_id(id) {} + virtual ~BtMessage() {} virtual bool isSendingInProgress() = 0; @@ -54,7 +58,7 @@ public: virtual bool isUploading() = 0; - virtual uint8_t getId() = 0; + uint8_t getId() { return _id; } virtual void doReceivedAction() = 0; diff --git a/src/BtNotInterestedMessage.cc b/src/BtNotInterestedMessage.cc index 8db23d4f..37829be8 100644 --- a/src/BtNotInterestedMessage.cc +++ b/src/BtNotInterestedMessage.cc @@ -68,8 +68,6 @@ bool BtNotInterestedMessage::sendPredicate() const { return peer->amInterested(); } -size_t BtNotInterestedMessage::MESSAGE_LENGTH = 5; - const unsigned char* BtNotInterestedMessage::getMessage() { if(!msg) { /** diff --git a/src/BtNotInterestedMessage.h b/src/BtNotInterestedMessage.h index ba37c9d6..329dda1a 100644 --- a/src/BtNotInterestedMessage.h +++ b/src/BtNotInterestedMessage.h @@ -50,9 +50,9 @@ private: SharedHandle _peerStorage; - static size_t MESSAGE_LENGTH; + static const size_t MESSAGE_LENGTH = 5; public: - BtNotInterestedMessage():msg(0) {} + BtNotInterestedMessage():SimpleBtMessage(ID), msg(0) {} virtual ~BtNotInterestedMessage() { delete [] msg; @@ -62,8 +62,6 @@ public: static BtNotInterestedMessageHandle create(const unsigned char* data, size_t dataLength); - virtual uint8_t getId() { return ID; } - virtual void doReceivedAction(); virtual const unsigned char* getMessage(); diff --git a/src/BtPieceMessage.h b/src/BtPieceMessage.h index 4abd05ea..3b4a83b5 100644 --- a/src/BtPieceMessage.h +++ b/src/BtPieceMessage.h @@ -93,7 +93,8 @@ private: typedef SharedHandle BtCancelSendingPieceEventListenerHandle; public: BtPieceMessage(size_t index = 0, uint32_t begin = 0, size_t blockLength = 0) - :index(index), + :AbstractBtMessage(ID), + index(index), begin(begin), blockLength(blockLength), block(0), @@ -135,8 +136,6 @@ public: static BtPieceMessageHandle create(const unsigned char* data, size_t dataLength); - virtual uint8_t getId() { return ID; } - virtual void doReceivedAction(); const unsigned char* getMessageHeader(); diff --git a/src/BtPortMessage.cc b/src/BtPortMessage.cc index 17cd1c8b..f4d3c6b3 100644 --- a/src/BtPortMessage.cc +++ b/src/BtPortMessage.cc @@ -48,7 +48,8 @@ namespace aria2 { -BtPortMessage::BtPortMessage(uint16_t port): _port(port), _msg(0) {} +BtPortMessage::BtPortMessage(uint16_t port): + SimpleBtMessage(ID), _port(port), _msg(0) {} BtPortMessage::~BtPortMessage() { diff --git a/src/BtPortMessage.h b/src/BtPortMessage.h index d8ad98e1..47fabaeb 100644 --- a/src/BtPortMessage.h +++ b/src/BtPortMessage.h @@ -68,8 +68,6 @@ public: static SharedHandle create(const unsigned char* data, size_t dataLength); - virtual uint8_t getId() { return ID; } - virtual void doReceivedAction(); virtual const unsigned char* getMessage(); diff --git a/src/BtRejectMessage.cc b/src/BtRejectMessage.cc index 79213a1e..51f796a9 100644 --- a/src/BtRejectMessage.cc +++ b/src/BtRejectMessage.cc @@ -78,8 +78,6 @@ void BtRejectMessage::doReceivedAction() { } -size_t BtRejectMessage::MESSAGE_LENGTH = 17; - const unsigned char* BtRejectMessage::getMessage() { if(!msg) { /** diff --git a/src/BtRejectMessage.h b/src/BtRejectMessage.h index df215fbf..50b98ed0 100644 --- a/src/BtRejectMessage.h +++ b/src/BtRejectMessage.h @@ -49,10 +49,11 @@ private: uint32_t begin; size_t length; unsigned char* msg; - static size_t MESSAGE_LENGTH; + static const size_t MESSAGE_LENGTH = 17; public: BtRejectMessage(size_t index = 0, uint32_t begin = 0, size_t length = 0) - :index(index), + :SimpleBtMessage(ID), + index(index), begin(begin), length(length), msg(0) {} @@ -74,8 +75,6 @@ public: static BtRejectMessageHandle create(const unsigned char* data, size_t dataLength); - virtual uint8_t getId() { return ID; } - virtual void doReceivedAction(); virtual const unsigned char* getMessage(); diff --git a/src/BtRequestMessage.cc b/src/BtRequestMessage.cc index d554ad66..c6b188db 100644 --- a/src/BtRequestMessage.cc +++ b/src/BtRequestMessage.cc @@ -83,8 +83,6 @@ void BtRequestMessage::doReceivedAction() { } } -size_t BtRequestMessage::MESSAGE_LENGTH = 17; - const unsigned char* BtRequestMessage::getMessage() { if(!msg) { /** diff --git a/src/BtRequestMessage.h b/src/BtRequestMessage.h index 5c762b8b..97d66ca3 100644 --- a/src/BtRequestMessage.h +++ b/src/BtRequestMessage.h @@ -52,7 +52,7 @@ private: size_t blockIndex; unsigned char* msg; - static size_t MESSAGE_LENGTH; + static const size_t MESSAGE_LENGTH = 17; class BtAbortOutstandingRequestEventListener : public AbstractBtEventListener { private: @@ -71,7 +71,8 @@ public: uint32_t begin = 0, uint32_t length = 0, size_t blockIndex = 0) - :index(index), + :SimpleBtMessage(ID), + index(index), begin(begin), length(length), blockIndex(blockIndex), @@ -101,8 +102,6 @@ public: static BtRequestMessageHandle create(const unsigned char* data, size_t dataLength); - virtual uint8_t getId() { return ID; } - virtual void doReceivedAction(); virtual const unsigned char* getMessage(); diff --git a/src/BtSuggestPieceMessage.cc b/src/BtSuggestPieceMessage.cc index b2cb7670..e946504d 100644 --- a/src/BtSuggestPieceMessage.cc +++ b/src/BtSuggestPieceMessage.cc @@ -56,8 +56,6 @@ BtSuggestPieceMessageHandle BtSuggestPieceMessage::create(const unsigned char* d return message; } -size_t BtSuggestPieceMessage::MESSAGE_LENGTH = 9; - const unsigned char* BtSuggestPieceMessage::getMessage() { if(!msg) { /** diff --git a/src/BtSuggestPieceMessage.h b/src/BtSuggestPieceMessage.h index f114b428..b12662ca 100644 --- a/src/BtSuggestPieceMessage.h +++ b/src/BtSuggestPieceMessage.h @@ -47,9 +47,9 @@ class BtSuggestPieceMessage : public SimpleBtMessage { private: size_t index; unsigned char* msg; - static size_t MESSAGE_LENGTH; + static const size_t MESSAGE_LENGTH = 9; public: - BtSuggestPieceMessage():index(0), msg(0) {} + BtSuggestPieceMessage():SimpleBtMessage(ID), index(0), msg(0) {} virtual ~BtSuggestPieceMessage() { delete [] msg; @@ -65,8 +65,6 @@ public: static BtSuggestPieceMessageHandle create(const unsigned char* data, size_t dataLength); - virtual uint8_t getId() { return ID; } - virtual void doReceivedAction() { // TODO Current implementation ignores this message. } diff --git a/src/BtUnchokeMessage.cc b/src/BtUnchokeMessage.cc index 40327e4b..92b73db2 100644 --- a/src/BtUnchokeMessage.cc +++ b/src/BtUnchokeMessage.cc @@ -63,8 +63,6 @@ bool BtUnchokeMessage::sendPredicate() const { return peer->amChoking(); } -size_t BtUnchokeMessage::MESSAGE_LENGTH = 5; - const unsigned char* BtUnchokeMessage::getMessage() { if(!msg) { /** diff --git a/src/BtUnchokeMessage.h b/src/BtUnchokeMessage.h index 2bab378c..d318ba15 100644 --- a/src/BtUnchokeMessage.h +++ b/src/BtUnchokeMessage.h @@ -46,9 +46,9 @@ typedef SharedHandle BtUnchokeMessageHandle; class BtUnchokeMessage : public SimpleBtMessage { private: unsigned char* msg; - static size_t MESSAGE_LENGTH; + static const size_t MESSAGE_LENGTH = 5; public: - BtUnchokeMessage():msg(0) {} + BtUnchokeMessage():SimpleBtMessage(ID), msg(0) {} virtual ~BtUnchokeMessage() { delete [] msg; @@ -58,8 +58,6 @@ public: static BtUnchokeMessageHandle create(const unsigned char* data, size_t dataLength); - virtual uint8_t getId() { return ID; } - virtual void doReceivedAction(); virtual const unsigned char* getMessage(); diff --git a/src/SimpleBtMessage.cc b/src/SimpleBtMessage.cc index c22c34a5..d333adef 100644 --- a/src/SimpleBtMessage.cc +++ b/src/SimpleBtMessage.cc @@ -40,7 +40,7 @@ namespace aria2 { -SimpleBtMessage::SimpleBtMessage() {}//:leftDataLength(0) {} +SimpleBtMessage::SimpleBtMessage(uint8_t id):AbstractBtMessage(id) {} SimpleBtMessage::~SimpleBtMessage() {} diff --git a/src/SimpleBtMessage.h b/src/SimpleBtMessage.h index 87abfeb1..3387b810 100644 --- a/src/SimpleBtMessage.h +++ b/src/SimpleBtMessage.h @@ -41,7 +41,7 @@ namespace aria2 { class SimpleBtMessage : public AbstractBtMessage { public: - SimpleBtMessage(); + SimpleBtMessage(uint8_t id); virtual ~SimpleBtMessage(); diff --git a/test/MockBtMessage.h b/test/MockBtMessage.h index 1afb9053..d4010b62 100644 --- a/test/MockBtMessage.h +++ b/test/MockBtMessage.h @@ -44,9 +44,10 @@ private: bool sendingInProgress; bool invalidate; bool uploading; - uint8_t id; public: - MockBtMessage() {} + MockBtMessage():BtMessage(0) {} + + MockBtMessage(uint8_t id):BtMessage(id) {} virtual ~MockBtMessage() {} @@ -74,14 +75,6 @@ public: this->uploading = flag; } - virtual uint8_t getId() { - return id; - } - - void setId(uint8_t id) { - this->id = id; - } - virtual void doReceivedAction() { }