DiskAdaptor.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /* <!-- copyright */
  2. /*
  3. * aria2 - a simple utility for downloading files faster
  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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. */
  21. /* copyright --> */
  22. #ifndef _D_DISK_ADAPTOR_H_
  23. #define _D_DISK_ADAPTOR_H_
  24. #include "common.h"
  25. #include "FileEntry.h"
  26. #include "Directory.h"
  27. #include "DiskWriter.h"
  28. #include "Logger.h"
  29. class DiskAdaptor {
  30. protected:
  31. DiskWriter* diskWriter;
  32. string storeDir;
  33. FileEntries fileEntries;
  34. const Directory* topDir;
  35. const Logger* logger;
  36. virtual string getFilePath() const = 0;
  37. public:
  38. DiskAdaptor(DiskWriter* diskWriter);
  39. virtual ~DiskAdaptor();
  40. virtual void openFile();
  41. virtual void closeFile();
  42. virtual void openExistingFile();
  43. virtual void initAndOpenFile();
  44. void writeData(const char* data, int len, long long int position);
  45. int readData(char* data, int len, long long int position);
  46. string sha1Sum(long long int offset, long long int length);
  47. virtual void onDownloadComplete() = 0;
  48. void setFileEntries(const FileEntries& fileEntries) {
  49. this->fileEntries = fileEntries;
  50. }
  51. FileEntry getFileEntryFromPath(const string& fileEntryPath) const;
  52. const FileEntries& getFileEntries() const { return fileEntries; }
  53. bool addDownloadEntry(const string& fileEntryPath);
  54. bool addDownloadEntry(int index);
  55. void addAllDownloadEntry();
  56. void removeAllDownloadEntry();
  57. void setStoreDir(const string& storeDir) { this->storeDir = storeDir; }
  58. string getStoreDir() const { return this->storeDir; }
  59. void setTopDir(const Directory* dirctory) {
  60. if(this->topDir != NULL) {
  61. delete topDir;
  62. }
  63. this->topDir = dirctory;
  64. }
  65. const Directory* getTopDir() const { return this->topDir; }
  66. };
  67. #endif // _D_DISK_ADAPTOR_H_