svc_fileread.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. #ifndef _SVC_FILEREAD_H
  2. #define _SVC_FILEREAD_H
  3. #include <bfc/dispatch.h>
  4. #include <bfc/platform/types.h>
  5. #include <api/service/services.h>
  6. #include <stdint.h>
  7. namespace SvcFileReader
  8. {
  9. enum {
  10. READ = 1,
  11. WRITE = 2,
  12. APPEND = 4,
  13. PLUS = 8,
  14. BINARY = 16,
  15. TEXT = 32,
  16. };
  17. };
  18. class api_readercallback;
  19. class NOVTABLE svc_fileReader : public Dispatchable
  20. {
  21. public:
  22. static FOURCC getServiceType() { return WaSvc::FILEREADER; }
  23. int isMine(const wchar_t *filename, int mode = SvcFileReader::READ); //don't really open. returns -1 if "don't know until I open it"
  24. int open(const wchar_t *filename, int mode = SvcFileReader::READ);
  25. size_t read(int8_t *buffer, size_t length);
  26. size_t write(const int8_t *buffer, size_t length);
  27. void close(); // safe to call even when not open
  28. int canSetEOF();
  29. /**
  30. Asks the file reader to change the file length to newlen. Will fail if file
  31. was not opened for writing.
  32. @ret 1 on success, 0 on failure, -1 if operation is unsupported by this reader.
  33. */
  34. int setEOF(uint64_t newlen);
  35. void abort();
  36. uint64_t getLength();
  37. uint64_t getPos();
  38. int canSeek();
  39. int seek(uint64_t position);
  40. uint64_t bytesAvailable(uint64_t requested);
  41. int hasHeaders();
  42. const char *getHeader(const char *header);
  43. int exists(const wchar_t *filename);
  44. int remove(const wchar_t *filename);
  45. int removeUndoable(const wchar_t *filename);
  46. int move(const wchar_t *filename, const wchar_t *destfilename);
  47. int canPrefetch();
  48. void setMetaDataCallback(api_readercallback *cb);
  49. enum
  50. {
  51. ISMINE = 0,
  52. OPEN = 10,
  53. READ = 20,
  54. WRITE = 30,
  55. CLOSE = 40,
  56. ABORT = 50,
  57. GETLENGTH = 60,
  58. GETPOS = 70,
  59. CANSEEK = 80,
  60. SEEK = 90,
  61. HASHEADERS = 100,
  62. GETHEADER = 110,
  63. EXISTS = 120,
  64. REMOVE = 130,
  65. REMOVEUNDOABLE = 135,
  66. BYTESAVAILABLE = 140,
  67. SETMETADATACALLBACK = 150,
  68. MOVE = 160,
  69. CANPREFETCH = 170,
  70. CANSETEOF = 180,
  71. SETEOF = 190,
  72. };
  73. };
  74. inline
  75. int svc_fileReader::isMine(const wchar_t *filename, int mode)
  76. {
  77. return _call(ISMINE, -1, filename, mode);
  78. }
  79. inline int svc_fileReader::open(const wchar_t *filename, int mode)
  80. {
  81. return _call(OPEN, 0, filename, mode);
  82. }
  83. inline size_t svc_fileReader::read(int8_t *buffer, size_t length)
  84. {
  85. return _call(READ, 0, buffer, length);
  86. }
  87. inline size_t svc_fileReader::write(const int8_t *buffer, size_t length)
  88. {
  89. return _call(WRITE, 0, buffer, length);
  90. }
  91. inline void svc_fileReader::close()
  92. {
  93. _voidcall(CLOSE);
  94. }
  95. inline int svc_fileReader::canSetEOF()
  96. {
  97. return _call(CANSETEOF, 0);
  98. }
  99. inline int svc_fileReader::setEOF(uint64_t newlen)
  100. {
  101. return _call(SETEOF, -1, newlen);
  102. }
  103. inline void svc_fileReader::abort()
  104. {
  105. _voidcall(ABORT);
  106. }
  107. inline uint64_t svc_fileReader::getLength()
  108. {
  109. return _call(GETLENGTH, (uint64_t)-1);
  110. }
  111. inline uint64_t svc_fileReader::getPos()
  112. {
  113. return _call(GETPOS, (uint64_t)0);
  114. }
  115. inline int svc_fileReader::canSeek()
  116. {
  117. return _call(CANSEEK, 0);
  118. }
  119. inline int svc_fileReader::seek(uint64_t position)
  120. {
  121. return _call(SEEK, 0, position);
  122. }
  123. inline uint64_t svc_fileReader::bytesAvailable(uint64_t requested)
  124. {
  125. return _call(BYTESAVAILABLE, requested, requested);
  126. }
  127. inline int svc_fileReader::hasHeaders()
  128. {
  129. return _call(HASHEADERS, 0);
  130. }
  131. inline const char *svc_fileReader::getHeader(const char *header)
  132. {
  133. return _call(GETHEADER, (const char *)NULL, header);
  134. }
  135. inline int svc_fileReader::exists(const wchar_t *filename)
  136. {
  137. return _call(EXISTS, -1, filename);
  138. }
  139. inline int svc_fileReader::remove(const wchar_t *filename)
  140. {
  141. return _call(REMOVE, 0, filename);
  142. }
  143. inline
  144. int svc_fileReader::removeUndoable(const wchar_t *filename)
  145. {
  146. return _call(REMOVEUNDOABLE, -1, filename);
  147. }
  148. inline int svc_fileReader::move(const wchar_t *filename, const wchar_t *destfilename)
  149. {
  150. return _call(MOVE, 0, filename, destfilename);
  151. }
  152. inline void svc_fileReader::setMetaDataCallback(api_readercallback *cb)
  153. {
  154. _voidcall(SETMETADATACALLBACK, cb);
  155. }
  156. inline int svc_fileReader::canPrefetch()
  157. {
  158. return _call(CANPREFETCH, 1);
  159. }
  160. #endif