CCDownloader-android.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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 "network/CCIDownloaderImpl.h"
  23. class _jobject;
  24. namespace cocos2d { namespace network
  25. {
  26. class DownloadTaskAndroid;
  27. class DownloaderHints;
  28. class DownloaderAndroid : public IDownloaderImpl
  29. {
  30. public:
  31. DownloaderAndroid(const DownloaderHints& hints);
  32. virtual ~DownloaderAndroid();
  33. virtual IDownloadTask *createCoTask(std::shared_ptr<const DownloadTask>& task) override;
  34. // designed called by internal
  35. void _onProcess(int taskId, int64_t dl, int64_t dlNow, int64_t dlTotal);
  36. void _onFinish(int taskId, int errCode, const char *errStr, std::vector<unsigned char>& data);
  37. protected:
  38. int _id;
  39. _jobject* _impl;
  40. std::unordered_map<int, DownloadTaskAndroid*> _taskMap;
  41. };
  42. // Load java downloader class from main thread, to void addImageAsync function
  43. // perform in sub-thread cause java downloader unusable
  44. void _preloadJavaDownloaderClass();
  45. }} // namespace cocos2d::network