~ubuntu-branches/ubuntu/wily/aria2/wily-proposed

« back to all changes in this revision

Viewing changes to src/DownloadEngine.h

  • Committer: Package Import Robot
  • Author(s): Kartik Mistry, Kartik Mistry, Patrick Ruckstuhl
  • Date: 2013-09-22 18:52:14 UTC
  • mfrom: (2.5.19 sid)
  • Revision ID: package-import@ubuntu.com-20130922185214-upeu2ljgeqi7e7oo
Tags: 1.18.0-1
[ Kartik Mistry ]
* New upstream release.
* debian/control:
  + (really) Set priority to optional from extra (Closes: #697659).
  + wrap-and-sort some fields.

[ Patrick Ruckstuhl ]
* debian/rules:
  + Allow parallel building (Closes: #720977)
* debian/tests, debian/control:
  + autopkgtest infrastructure

Show diffs side-by-side

added added

removed removed

Lines of Context:
41
41
#include <deque>
42
42
#include <map>
43
43
#include <vector>
 
44
#include <memory>
44
45
 
45
 
#include "SharedHandle.h"
46
46
#include "a2netcompat.h"
47
47
#include "TimerA2.h"
48
48
#include "a2io.h"
68
68
#ifdef ENABLE_BITTORRENT
69
69
class BtRegistry;
70
70
#endif // ENABLE_BITTORRENT
 
71
#ifdef ENABLE_WEBSOCKET
 
72
namespace rpc {
 
73
class WebSocketSessionMan;
 
74
} // namespace rpc
 
75
#endif // ENABLE_WEBSOCKET
71
76
 
72
77
class DownloadEngine {
73
78
private:
75
80
 
76
81
  std::string sessionId_;
77
82
 
78
 
  SharedHandle<EventPoll> eventPoll_;
 
83
  std::unique_ptr<EventPoll> eventPoll_;
79
84
 
80
 
  SharedHandle<StatCalc> statCalc_;
 
85
  std::unique_ptr<StatCalc> statCalc_;
81
86
 
82
87
  int haltRequested_;
83
88
 
84
89
  class SocketPoolEntry {
85
90
  private:
86
 
    SharedHandle<SocketCore> socket_;
 
91
    std::shared_ptr<SocketCore> socket_;
87
92
    // protocol specific option string
88
93
    std::string options_;
89
94
 
91
96
 
92
97
    Timer registeredTime_;
93
98
  public:
94
 
    SocketPoolEntry(const SharedHandle<SocketCore>& socket,
 
99
    SocketPoolEntry(const std::shared_ptr<SocketCore>& socket,
95
100
                    const std::string& option,
96
101
                    time_t timeout);
97
102
 
98
 
    SocketPoolEntry(const SharedHandle<SocketCore>& socket,
 
103
    SocketPoolEntry(const std::shared_ptr<SocketCore>& socket,
99
104
                    time_t timeout);
100
105
 
101
106
    ~SocketPoolEntry();
102
107
 
103
108
    bool isTimeout() const;
104
109
 
105
 
    const SharedHandle<SocketCore>& getSocket() const
 
110
    const std::shared_ptr<SocketCore>& getSocket() const
106
111
    {
107
112
      return socket_;
108
113
    }
124
129
 
125
130
  // Milliseconds
126
131
  int64_t refreshInterval_;
127
 
 
128
 
  std::deque<Command*> routineCommands_;
129
 
 
130
 
  SharedHandle<CookieStorage> cookieStorage_;
 
132
  Timer lastRefresh_;
 
133
 
 
134
  std::deque<std::unique_ptr<Command>> routineCommands_;
 
135
 
 
136
  std::unique_ptr<CookieStorage> cookieStorage_;
131
137
 
132
138
#ifdef ENABLE_BITTORRENT
133
 
  SharedHandle<BtRegistry> btRegistry_;
 
139
  std::unique_ptr<BtRegistry> btRegistry_;
134
140
#endif // ENABLE_BITTORRENT
135
141
 
136
142
  CUIDCounter cuidCounter_;
139
145
  ares_addr_node* asyncDNSServers_;
140
146
#endif // HAVE_ARES_ADDR_NODE
141
147
 
142
 
  SharedHandle<DNSCache> dnsCache_;
143
 
 
144
 
  SharedHandle<AuthConfigFactory> authConfigFactory_;
 
148
  std::unique_ptr<DNSCache> dnsCache_;
 
149
 
 
150
  std::unique_ptr<AuthConfigFactory> authConfigFactory_;
 
151
 
 
152
#ifdef ENABLE_WEBSOCKET
 
153
  std::unique_ptr<rpc::WebSocketSessionMan> webSocketSessionMan_;
 
154
#endif // ENABLE_WEBSOCKET
145
155
 
146
156
  /**
147
157
   * Delegates to StatCalc
157
167
  std::multimap<std::string, SocketPoolEntry>::iterator
158
168
  findSocketPoolEntry(const std::string& key);
159
169
 
160
 
  std::deque<Command*> commands_;
161
 
  SharedHandle<RequestGroupMan> requestGroupMan_;
162
 
  SharedHandle<FileAllocationMan> fileAllocationMan_;
163
 
  SharedHandle<CheckIntegrityMan> checkIntegrityMan_;
 
170
  std::deque<std::unique_ptr<Command>> commands_;
 
171
  std::unique_ptr<RequestGroupMan> requestGroupMan_;
 
172
  std::unique_ptr<FileAllocationMan> fileAllocationMan_;
 
173
  std::unique_ptr<CheckIntegrityMan> checkIntegrityMan_;
164
174
  Option* option_;
165
175
public:
166
 
  DownloadEngine(const SharedHandle<EventPoll>& eventPoll);
 
176
  DownloadEngine(std::unique_ptr<EventPoll> eventPoll);
167
177
 
168
178
  ~DownloadEngine();
169
179
 
170
 
  void run();
171
 
 
172
 
  void cleanQueue();
173
 
 
174
 
  bool addSocketForReadCheck(const SharedHandle<SocketCore>& socket,
 
180
  // If oneshot is true, this function returns after one event polling
 
181
  // and performing action for them. This function returns 1 when
 
182
  // oneshot is true and there are still downloads to be
 
183
  // processed. Otherwise, returns 0.
 
184
  int run(bool oneshot=false);
 
185
 
 
186
  bool addSocketForReadCheck(const std::shared_ptr<SocketCore>& socket,
175
187
                             Command* command);
176
 
  bool deleteSocketForReadCheck(const SharedHandle<SocketCore>& socket,
 
188
  bool deleteSocketForReadCheck(const std::shared_ptr<SocketCore>& socket,
177
189
                                Command* command);
178
 
  bool addSocketForWriteCheck(const SharedHandle<SocketCore>& socket,
 
190
  bool addSocketForWriteCheck(const std::shared_ptr<SocketCore>& socket,
179
191
                              Command* command);
180
 
  bool deleteSocketForWriteCheck(const SharedHandle<SocketCore>& socket,
 
192
  bool deleteSocketForWriteCheck(const std::shared_ptr<SocketCore>& socket,
181
193
                                 Command* command);
182
194
 
183
195
#ifdef ENABLE_ASYNC_DNS
184
196
 
185
 
  bool addNameResolverCheck(const SharedHandle<AsyncNameResolver>& resolver,
 
197
  bool addNameResolverCheck(const std::shared_ptr<AsyncNameResolver>& resolver,
186
198
                            Command* command);
187
 
  bool deleteNameResolverCheck(const SharedHandle<AsyncNameResolver>& resolver,
 
199
  bool deleteNameResolverCheck(const std::shared_ptr<AsyncNameResolver>& resolver,
188
200
                               Command* command);
189
201
#endif // ENABLE_ASYNC_DNS
190
202
 
191
 
  void addCommand(const std::vector<Command*>& commands);
192
 
 
193
 
  void addCommand(Command* command);
194
 
 
195
 
  const SharedHandle<RequestGroupMan>& getRequestGroupMan() const
 
203
  void addCommand(std::vector<std::unique_ptr<Command>> commands);
 
204
 
 
205
  void addCommand(std::unique_ptr<Command> command);
 
206
 
 
207
  const std::unique_ptr<RequestGroupMan>& getRequestGroupMan() const
196
208
  {
197
209
    return requestGroupMan_;
198
210
  }
199
211
 
200
 
  void setRequestGroupMan(const SharedHandle<RequestGroupMan>& rgman);
 
212
  void setRequestGroupMan(std::unique_ptr<RequestGroupMan> rgman);
201
213
 
202
 
  const SharedHandle<FileAllocationMan>& getFileAllocationMan() const
 
214
  const std::unique_ptr<FileAllocationMan>& getFileAllocationMan() const
203
215
  {
204
216
    return fileAllocationMan_;
205
217
  }
206
218
 
207
 
  void setFileAllocationMan(const SharedHandle<FileAllocationMan>& faman);
 
219
  void setFileAllocationMan(std::unique_ptr<FileAllocationMan> faman);
208
220
 
209
 
  const SharedHandle<CheckIntegrityMan>& getCheckIntegrityMan() const
 
221
  const std::unique_ptr<CheckIntegrityMan>& getCheckIntegrityMan() const
210
222
  {
211
223
    return checkIntegrityMan_;
212
224
  }
213
225
 
214
 
  void setCheckIntegrityMan(const SharedHandle<CheckIntegrityMan>& ciman);
 
226
  void setCheckIntegrityMan(std::unique_ptr<CheckIntegrityMan> ciman);
215
227
 
216
228
  Option* getOption() const
217
229
  {
223
235
    option_ = op;
224
236
  }
225
237
 
226
 
  void setStatCalc(const SharedHandle<StatCalc>& statCalc);
 
238
  void setStatCalc(std::unique_ptr<StatCalc> statCalc);
227
239
 
228
240
  bool isHaltRequested() const
229
241
  {
241
253
 
242
254
  void setNoWait(bool b);
243
255
 
244
 
  void addRoutineCommand(Command* command);
245
 
 
246
 
  void poolSocket(const std::string& ipaddr, uint16_t port,
247
 
                  const std::string& username,
248
 
                  const std::string& proxyhost, uint16_t proxyport,
249
 
                  const SharedHandle<SocketCore>& sock,
250
 
                  const std::string& options,
251
 
                  time_t timeout = 15);
252
 
 
253
 
  void poolSocket(const SharedHandle<Request>& request,
254
 
                  const std::string& username,
255
 
                  const SharedHandle<Request>& proxyRequest,
256
 
                  const SharedHandle<SocketCore>& socket,
257
 
                  const std::string& options,
258
 
                  time_t timeout = 15);
259
 
 
260
 
  void poolSocket(const std::string& ipaddr, uint16_t port,
261
 
                  const std::string& proxyhost, uint16_t proxyport,
262
 
                  const SharedHandle<SocketCore>& sock,
263
 
                  time_t timeout = 15);
264
 
 
265
 
  void poolSocket(const SharedHandle<Request>& request,
266
 
                  const SharedHandle<Request>& proxyRequest,
267
 
                  const SharedHandle<SocketCore>& socket,
268
 
                  time_t timeout = 15);
269
 
 
270
 
  SharedHandle<SocketCore> popPooledSocket
 
256
  void addRoutineCommand(std::unique_ptr<Command> command);
 
257
 
 
258
  void poolSocket(const std::string& ipaddr, uint16_t port,
 
259
                  const std::string& username,
 
260
                  const std::string& proxyhost, uint16_t proxyport,
 
261
                  const std::shared_ptr<SocketCore>& sock,
 
262
                  const std::string& options,
 
263
                  time_t timeout = 15);
 
264
 
 
265
  void poolSocket(const std::shared_ptr<Request>& request,
 
266
                  const std::string& username,
 
267
                  const std::shared_ptr<Request>& proxyRequest,
 
268
                  const std::shared_ptr<SocketCore>& socket,
 
269
                  const std::string& options,
 
270
                  time_t timeout = 15);
 
271
 
 
272
  void poolSocket(const std::string& ipaddr, uint16_t port,
 
273
                  const std::string& proxyhost, uint16_t proxyport,
 
274
                  const std::shared_ptr<SocketCore>& sock,
 
275
                  time_t timeout = 15);
 
276
 
 
277
  void poolSocket(const std::shared_ptr<Request>& request,
 
278
                  const std::shared_ptr<Request>& proxyRequest,
 
279
                  const std::shared_ptr<SocketCore>& socket,
 
280
                  time_t timeout = 15);
 
281
 
 
282
  std::shared_ptr<SocketCore> popPooledSocket
271
283
  (const std::string& ipaddr,
272
284
   uint16_t port,
273
285
   const std::string& proxyhost, uint16_t proxyport);
274
286
 
275
 
  SharedHandle<SocketCore> popPooledSocket
 
287
  std::shared_ptr<SocketCore> popPooledSocket
276
288
  (std::string& options,
277
289
   const std::string& ipaddr,
278
290
   uint16_t port,
279
291
   const std::string& username,
280
292
   const std::string& proxyhost, uint16_t proxyport);
281
293
 
282
 
  SharedHandle<SocketCore>
 
294
  std::shared_ptr<SocketCore>
283
295
  popPooledSocket
284
296
  (const std::vector<std::string>& ipaddrs, uint16_t port);
285
297
 
286
 
  SharedHandle<SocketCore>
 
298
  std::shared_ptr<SocketCore>
287
299
  popPooledSocket
288
300
  (std::string& options,
289
301
   const std::vector<std::string>& ipaddrs,
290
302
   uint16_t port,
291
303
   const std::string& username);
292
304
 
293
 
  const SharedHandle<CookieStorage>& getCookieStorage() const
294
 
  {
295
 
    return cookieStorage_;
296
 
  }
 
305
  const std::unique_ptr<CookieStorage>& getCookieStorage() const;
297
306
 
298
307
#ifdef ENABLE_BITTORRENT
299
 
  const SharedHandle<BtRegistry>& getBtRegistry() const
 
308
  const std::unique_ptr<BtRegistry>& getBtRegistry() const
300
309
  {
301
310
    return btRegistry_;
302
311
  }
322
331
 
323
332
  void removeCachedIPAddress(const std::string& hostname, uint16_t port);
324
333
 
325
 
  void setAuthConfigFactory(const SharedHandle<AuthConfigFactory>& factory);
 
334
  void setAuthConfigFactory(std::unique_ptr<AuthConfigFactory> factory);
326
335
 
327
 
  const SharedHandle<AuthConfigFactory>& getAuthConfigFactory() const
328
 
  {
329
 
    return authConfigFactory_;
330
 
  }
 
336
  const std::unique_ptr<AuthConfigFactory>& getAuthConfigFactory() const;
331
337
 
332
338
  void setRefreshInterval(int64_t interval);
333
339
 
344
350
    return asyncDNSServers_;
345
351
  }
346
352
#endif // HAVE_ARES_ADDR_NODE
 
353
 
 
354
#ifdef ENABLE_WEBSOCKET
 
355
  void setWebSocketSessionMan(std::unique_ptr<rpc::WebSocketSessionMan> wsman);
 
356
  const std::unique_ptr<rpc::WebSocketSessionMan>& getWebSocketSessionMan()
 
357
    const
 
358
  {
 
359
    return webSocketSessionMan_;
 
360
  }
 
361
#endif // ENABLE_WEBSOCKET
347
362
};
348
363
 
349
364
} // namespace aria2