CCIDownloaderImpl.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /****************************************************************************
  2. Copyright (c) 2015-2016 Chukong Technologies Inc.
  3. Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
  4. http://www.cocos2d-x.org
  5. Permission is hereby granted, free of charge, to any person obtaining a copy
  6. of this software and associated documentation files (the "Software"), to deal
  7. in the Software without restriction, including without limitation the rights
  8. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. copies of the Software, and to permit persons to whom the Software is
  10. furnished to do so, subject to the following conditions:
  11. The above copyright notice and this permission notice shall be included in
  12. all copies or substantial portions of the Software.
  13. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  19. THE SOFTWARE.
  20. ****************************************************************************/
  21. #pragma once
  22. #include <string>
  23. #include <unordered_map>
  24. #include <memory>
  25. #include "base/CCConsole.h"
  26. //#define CC_DOWNLOADER_DEBUG
  27. #ifdef CC_DOWNLOADER_DEBUG
  28. #define DLLOG(format, ...) cocos2d::log(format, ##__VA_ARGS__)
  29. #else
  30. #define DLLOG(...) do {} while (0)
  31. #endif
  32. namespace cocos2d { namespace network
  33. {
  34. class DownloadTask;
  35. class CC_DLL IDownloadTask
  36. {
  37. public:
  38. virtual ~IDownloadTask(){}
  39. };
  40. class IDownloaderImpl
  41. {
  42. public:
  43. virtual ~IDownloaderImpl(){}
  44. std::function<void(const DownloadTask& task,
  45. int64_t bytesReceived,
  46. int64_t totalBytesReceived,
  47. int64_t totalBytesExpected,
  48. std::function<int64_t(void *buffer, int64_t len)>& transferDataToBuffer)> onTaskProgress;
  49. std::function<void(const DownloadTask& task,
  50. int errorCode,
  51. int errorCodeInternal,
  52. const std::string& errorStr,
  53. std::vector<unsigned char>& data)> onTaskFinish;
  54. virtual IDownloadTask *createCoTask(std::shared_ptr<const DownloadTask>& task) = 0;
  55. };
  56. }} // namespace cocos2d::network