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