2009-03-12 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>

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
pull/1/head
Tatsuhiro Tsujikawa 2009-03-11 15:44:04 +00:00
parent aecd8bbfeb
commit 4e0c03500c
41 changed files with 108 additions and 115 deletions

View File

@ -1,3 +1,49 @@
2009-03-12 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
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 <t-tujikawa@users.sourceforge.net>
Use FileEntry::exists()

View File

@ -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() {}

View File

@ -78,7 +78,7 @@ protected:
Logger* logger;
public:
AbstractBtMessage();
AbstractBtMessage(uint8_t id);
virtual ~AbstractBtMessage();

View File

@ -66,8 +66,6 @@ void BtAllowedFastMessage::doReceivedAction() {
peer->addPeerAllowedIndex(index);
}
size_t BtAllowedFastMessage::MESSAGE_LENGTH = 9;
const unsigned char* BtAllowedFastMessage::getMessage() {
if(!msg) {
/**

View File

@ -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();

View File

@ -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();

View File

@ -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) {
/**

View File

@ -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();

View File

@ -67,8 +67,6 @@ bool BtChokeMessage::sendPredicate() const {
return !peer->amChoking();
}
size_t BtChokeMessage::MESSAGE_LENGTH = 5;
const unsigned char* BtChokeMessage::getMessage() {
if(!msg) {
/**

View File

@ -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();

View File

@ -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()

View File

@ -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();

View File

@ -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);

View File

@ -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();

View File

@ -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) {
/**

View File

@ -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();

View File

@ -63,8 +63,6 @@ void BtHaveMessage::doReceivedAction() {
pieceStorage->addPieceStats(index);
}
size_t BtHaveMessage::MESSAGE_LENGTH = 9;
const unsigned char* BtHaveMessage::getMessage() {
if(!msg) {
/**

View File

@ -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();

View File

@ -63,8 +63,6 @@ void BtHaveNoneMessage::doReceivedAction() {
}
}
size_t BtHaveNoneMessage::MESSAGE_LENGTH = 5;
const unsigned char* BtHaveNoneMessage::getMessage() {
if(!msg) {
/**

View File

@ -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();

View File

@ -68,8 +68,6 @@ bool BtInterestedMessage::sendPredicate() const {
return !peer->amInterested();
}
size_t BtInterestedMessage::MESSAGE_LENGTH = 5;
const unsigned char* BtInterestedMessage::getMessage() {
if(!msg) {
/**

View File

@ -50,10 +50,9 @@ private:
SharedHandle<PeerStorage> _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();

View File

@ -37,8 +37,6 @@
namespace aria2 {
size_t BtKeepAliveMessage::MESSAGE_LENGTH = 4;
const unsigned char* BtKeepAliveMessage::getMessage() {
if(!msg) {
/**

View File

@ -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();

View File

@ -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;

View File

@ -68,8 +68,6 @@ bool BtNotInterestedMessage::sendPredicate() const {
return peer->amInterested();
}
size_t BtNotInterestedMessage::MESSAGE_LENGTH = 5;
const unsigned char* BtNotInterestedMessage::getMessage() {
if(!msg) {
/**

View File

@ -50,9 +50,9 @@ private:
SharedHandle<PeerStorage> _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();

View File

@ -93,7 +93,8 @@ private:
typedef SharedHandle<BtCancelSendingPieceEventListener> 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();

View File

@ -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()
{

View File

@ -68,8 +68,6 @@ public:
static SharedHandle<BtPortMessage> create(const unsigned char* data, size_t dataLength);
virtual uint8_t getId() { return ID; }
virtual void doReceivedAction();
virtual const unsigned char* getMessage();

View File

@ -78,8 +78,6 @@ void BtRejectMessage::doReceivedAction() {
}
size_t BtRejectMessage::MESSAGE_LENGTH = 17;
const unsigned char* BtRejectMessage::getMessage() {
if(!msg) {
/**

View File

@ -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();

View File

@ -83,8 +83,6 @@ void BtRequestMessage::doReceivedAction() {
}
}
size_t BtRequestMessage::MESSAGE_LENGTH = 17;
const unsigned char* BtRequestMessage::getMessage() {
if(!msg) {
/**

View File

@ -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();

View File

@ -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) {
/**

View File

@ -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.
}

View File

@ -63,8 +63,6 @@ bool BtUnchokeMessage::sendPredicate() const {
return peer->amChoking();
}
size_t BtUnchokeMessage::MESSAGE_LENGTH = 5;
const unsigned char* BtUnchokeMessage::getMessage() {
if(!msg) {
/**

View File

@ -46,9 +46,9 @@ typedef SharedHandle<BtUnchokeMessage> 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();

View File

@ -40,7 +40,7 @@
namespace aria2 {
SimpleBtMessage::SimpleBtMessage() {}//:leftDataLength(0) {}
SimpleBtMessage::SimpleBtMessage(uint8_t id):AbstractBtMessage(id) {}
SimpleBtMessage::~SimpleBtMessage() {}

View File

@ -41,7 +41,7 @@ namespace aria2 {
class SimpleBtMessage : public AbstractBtMessage {
public:
SimpleBtMessage();
SimpleBtMessage(uint8_t id);
virtual ~SimpleBtMessage();

View File

@ -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() {
}