AbstractBtMessage.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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 Logger;
  48. class AbstractBtMessage : public BtMessage {
  49. private:
  50. bool sendingInProgress_;
  51. bool invalidate_;
  52. bool uploading_;
  53. cuid_t cuid_;
  54. std::string name_;
  55. SharedHandle<PieceStorage> pieceStorage_;
  56. SharedHandle<Peer> peer_;
  57. WeakHandle<BtMessageDispatcher> dispatcher_;
  58. WeakHandle<BtMessageFactory> messageFactory_;
  59. WeakHandle<BtRequestFactory> requestFactory_;
  60. WeakHandle<PeerConnection> peerConnection_;
  61. SharedHandle<BtMessageValidator> validator_;
  62. bool metadataGetMode_;
  63. Logger* logger_;
  64. protected:
  65. Logger* getLogger() const
  66. {
  67. return logger_;
  68. }
  69. const SharedHandle<PieceStorage>& getPieceStorage() const
  70. {
  71. return pieceStorage_;
  72. }
  73. const WeakHandle<PeerConnection>& getPeerConnection() const
  74. {
  75. return peerConnection_;
  76. }
  77. const WeakHandle<BtMessageDispatcher>& getBtMessageDispatcher() const
  78. {
  79. return dispatcher_;
  80. }
  81. const WeakHandle<BtRequestFactory>& getBtRequestFactory() const
  82. {
  83. return requestFactory_;
  84. }
  85. const WeakHandle<BtMessageFactory>& getBtMessageFactory() const
  86. {
  87. return messageFactory_;
  88. }
  89. bool isMetadataGetMode() const
  90. {
  91. return metadataGetMode_;
  92. }
  93. public:
  94. AbstractBtMessage(uint8_t id, const std::string& name);
  95. virtual ~AbstractBtMessage();
  96. virtual bool isSendingInProgress() {
  97. return sendingInProgress_;
  98. }
  99. void setSendingInProgress(bool sendingInProgress) {
  100. sendingInProgress_ = sendingInProgress;
  101. }
  102. virtual bool isInvalidate() {
  103. return invalidate_;
  104. }
  105. void setInvalidate(bool invalidate) {
  106. invalidate_ = invalidate;
  107. }
  108. virtual bool isUploading() {
  109. return uploading_;
  110. }
  111. void setUploading(bool uploading) {
  112. uploading_ = uploading;
  113. }
  114. cuid_t getCuid() const {
  115. return cuid_;
  116. }
  117. void setCuid(cuid_t cuid) {
  118. cuid_ = cuid;
  119. }
  120. const SharedHandle<Peer>& getPeer() const
  121. {
  122. return peer_;
  123. }
  124. void setPeer(const SharedHandle<Peer>& peer);
  125. virtual void doReceivedAction() {}
  126. virtual void validate();
  127. virtual void onQueued() {}
  128. virtual void onAbortOutstandingRequestEvent
  129. (const BtAbortOutstandingRequestEvent& event) {}
  130. virtual void onCancelSendingPieceEvent
  131. (const BtCancelSendingPieceEvent& event) {}
  132. virtual void onChokingEvent(const BtChokingEvent& event) {}
  133. void setBtMessageValidator(const SharedHandle<BtMessageValidator>& validator);
  134. void setPieceStorage(const SharedHandle<PieceStorage>& pieceStorage);
  135. void setBtMessageDispatcher
  136. (const WeakHandle<BtMessageDispatcher>& dispatcher);
  137. void setPeerConnection(const WeakHandle<PeerConnection>& peerConnection);
  138. void setBtMessageFactory(const WeakHandle<BtMessageFactory>& factory);
  139. void setBtRequestFactory(const WeakHandle<BtRequestFactory>& factory);
  140. const std::string& getName() const
  141. {
  142. return name_;
  143. }
  144. void enableMetadataGetMode()
  145. {
  146. metadataGetMode_ = true;
  147. }
  148. };
  149. typedef SharedHandle<AbstractBtMessage> AbstractBtMessageHandle;
  150. } // namespace aria2
  151. #endif // _D_ABSTRACT_BT_MESSAGE_H_