DownloadFileRequest.h 2.6 KB
Newer Older
1 2 3 4 5 6 7 8 9
/*****************************************************************************
 * DownloadFileRequest.h : DownloadFileRequest headers
 *
 *****************************************************************************
 * Copyright (C) 2016-2016 VideoLAN
 *
 * Authors: Paweł Wegner <pawel.wegner95@gmail.com>
 *
 * This program is free software; you can redistribute it and/or
Paweł Wegner's avatar
Paweł Wegner committed
10
 * modify it under the terms of the GNU Lesser General Public License
11 12 13 14 15 16
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Paweł Wegner's avatar
Paweł Wegner committed
17
 * GNU Lesser General Public License for more details.
18
 *
Paweł Wegner's avatar
Paweł Wegner committed
19
 * You should have received a copy of the GNU Lesser General Public License
20 21 22 23 24 25 26
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
 *****************************************************************************/

#ifndef DOWNLOADFILEREQUEST_H
#define DOWNLOADFILEREQUEST_H

27
#include "IItem.h"
28 29 30 31
#include "Request.h"

namespace cloudstorage {

32 33 34
class DownloadStreamWrapper : public std::streambuf {
 public:
  DownloadStreamWrapper(std::function<void(const char*, uint32_t)> callback);
Paweł Wegner's avatar
Paweł Wegner committed
35 36
  std::streamsize xsputn(const char_type* data,
                         std::streamsize length) override;
37 38 39 40 41

 private:
  std::function<void(const char*, uint32_t)> callback_;
};

42
class DownloadFileRequest : public Request<EitherError<void>> {
43
 public:
44
  using RequestFactory =
45
      std::function<IHttpRequest::Pointer(const IItem&, std::ostream&)>;
Paweł Wegner's avatar
Paweł Wegner committed
46
  using ICallback = IDownloadFileCallback;
47 48

  DownloadFileRequest(std::shared_ptr<CloudProvider>, IItem::Pointer file,
49 50
                      ICallback::Pointer, Range,
                      RequestFactory request_factory);
51 52
  ~DownloadFileRequest();

53
 private:
54 55 56
  void resolve(Request::Pointer request, IItem::Pointer file, ICallback*, Range,
               RequestFactory request_factory);

57 58 59
  DownloadStreamWrapper stream_wrapper_;
};

60 61 62 63 64 65 66 67 68
class DownloadFileFromUrlRequest : public Request<EitherError<void>> {
 public:
  using ICallback = IDownloadFileCallback;

  DownloadFileFromUrlRequest(std::shared_ptr<CloudProvider>, IItem::Pointer,
                             ICallback::Pointer, Range);
  ~DownloadFileFromUrlRequest();

 private:
69 70
  void resolve(Request::Pointer, IItem::Pointer, ICallback*, Range);

71 72 73
  DownloadStreamWrapper stream_wrapper_;
};

74 75 76
}  // namespace cloudstorage

#endif  // DOWNLOADFILEREQUEST_H