AbstractBtMessage.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. /* <!-- copyright */
  2. /*
  3. * aria2 - The high speed download utility
  4. *
  5. * Copyright (C) 2006 Tatsuhiro Tsujikawa
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. *
  21. * In addition, as a special exception, the copyright holders give
  22. * permission to link the code of portions of this program with the
  23. * OpenSSL library under certain conditions as described in each
  24. * individual source file, and distribute linked combinations
  25. * including the two.
  26. * You must obey the GNU General Public License in all respects
  27. * for all of the code used other than OpenSSL. If you modify
  28. * file(s) with this exception, you may extend this exception to your
  29. * version of the file(s), but you are not obligated to do so. If you
  30. * do not wish to do so, delete this exception statement from your
  31. * version. If you delete this exception statement from all source
  32. * files in the program, then also delete it here.
  33. */
  34. /* copyright --> */
  35. #ifndef D_ABSTRACT_BT_MESSAGE_H
  36. #define D_ABSTRACT_BT_MESSAGE_H
  37. #include "BtMessage.h"
  38. #include "Command.h"
  39. namespace aria2 {
  40. class PieceStorage;
  41. class Peer;
  42. class BtMessageDispatcher;
  43. class BtMessageFactory;
  44. class BtRequestFactory;
  45. class PeerConnection;
  46. class BtMessageValidator;
  47. class AbstractBtMessage : public BtMessage {
  48. private:
  49. bool sendingInProgress_;
  50. bool invalidate_;
  51. bool uploading_;
  52. cuid_t cuid_;
  53. std::string name_;
  54. SharedHandle<PieceStorage> pieceStorage_;
  55. SharedHandle<Peer> peer_;
  56. BtMessageDispatcher* dispatcher_;
  57. BtMessageFactory* messageFactory_;
  58. BtRequestFactory* requestFactory_;
  59. PeerConnection* peerConnection_;
  60. SharedHandle<BtMessageValidator> validator_;
  61. bool metadataGetMode_;
  62. protected:
  63. const SharedHandle<PieceStorage>& getPieceStorage() const
  64. {
  65. return pieceStorage_;
  66. }
  67. PeerConnection* getPeerConnection() const
  68. {
  69. return peerConnection_;
  70. }
  71. BtMessageDispatcher* getBtMessageDispatcher() const
  72. {
  73. return dispatcher_;
  74. }
  75. BtRequestFactory* getBtRequestFactory() const
  76. {
  77. return requestFactory_;
  78. }
  79. BtMessageFactory* getBtMessageFactory() const
  80. {
  81. return messageFactory_;
  82. }
  83. bool isMetadataGetMode() const
  84. {
  85. return metadataGetMode_;
  86. }
  87. public:
  88. AbstractBtMessage(uint8_t id, const std::string& name);
  89. virtual ~AbstractBtMessage();
  90. virtual bool isSendingInProgress() {
  91. return sendingInProgress_;
  92. }
  93. void setSendingInProgress(bool sendingInProgress) {
  94. sendingInProgress_ = sendingInProgress;
  95. }
  96. virtual bool isInvalidate() {
  97. return invalidate_;
  98. }
  99. void setInvalidate(bool invalidate) {
  100. invalidate_ = invalidate;
  101. }
  102. virtual bool isUploading() {
  103. return uploading_;
  104. }
  105. void setUploading(bool uploading) {
  106. uploading_ = uploading;
  107. }
  108. cuid_t getCuid() const {
  109. return cuid_;
  110. }
  111. void setCuid(cuid_t cuid) {
  112. cuid_ = cuid;
  113. }
  114. const SharedHandle<Peer>& getPeer() const
  115. {
  116. return peer_;
  117. }
  118. void setPeer(const SharedHandle<Peer>& peer);
  119. virtual void doReceivedAction() {}
  120. virtual void validate();
  121. virtual void onQueued() {}
  122. virtual void onAbortOutstandingRequestEvent
  123. (const BtAbortOutstandingRequestEvent& event) {}
  124. virtual void onCancelSendingPieceEvent
  125. (const BtCancelSendingPieceEvent& event) {}
  126. virtual void onChokingEvent(const BtChokingEvent& event) {}
  127. void setBtMessageValidator(const SharedHandle<BtMessageValidator>& validator);
  128. void setPieceStorage(const SharedHandle<PieceStorage>& pieceStorage);
  129. void setBtMessageDispatcher(BtMessageDispatcher* dispatcher);
  130. void setPeerConnection(PeerConnection* peerConnection);
  131. void setBtMessageFactory(BtMessageFactory* factory);
  132. void setBtRequestFactory(BtRequestFactory* factory);
  133. const std::string& getName() const
  134. {
  135. return name_;
  136. }
  137. void enableMetadataGetMode()
  138. {
  139. metadataGetMode_ = true;
  140. }
  141. };
  142. typedef SharedHandle<AbstractBtMessage> AbstractBtMessageHandle;
  143. } // namespace aria2
  144. #endif // D_ABSTRACT_BT_MESSAGE_H