1
0

NXFileObject.h 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #pragma once
  2. #include "foundation/types.h"
  3. #include "foundation/error.h"
  4. #include "nx/nxuri.h"
  5. #include "nx/nxfile.h"
  6. #include "nu/nodelist.h"
  7. struct NXFileRegion : public queue_node_t
  8. {
  9. uint64_t start;
  10. uint64_t end;
  11. };
  12. class NXFileObject
  13. {
  14. public:
  15. size_t Retain();
  16. size_t Release();
  17. ns_error_t LockRegion(uint64_t start, uint64_t end);
  18. ns_error_t UnlockRegion();
  19. ns_error_t Stat(nx_file_stat_t out_stats);
  20. ns_error_t Length(uint64_t *length);
  21. virtual ns_error_t Read(void *buffer, size_t bytes_requested, size_t *bytes_read)=0;
  22. virtual ns_error_t Write(const void *buffer, size_t bytes)=0;
  23. virtual ns_error_t PeekByte(uint8_t *byte)=0;
  24. virtual ns_error_t Seek(uint64_t position)=0;
  25. virtual ns_error_t Tell(uint64_t *position)=0;
  26. virtual ns_error_t Sync()=0;
  27. virtual ns_error_t Truncate()=0;
  28. virtual ns_error_t EndOfFile();
  29. protected:
  30. NXFileObject();
  31. virtual ~NXFileObject();
  32. nx_file_stat_s file_stats;
  33. uint64_t position; /* note: this represents absolute position, _not_ position within the region */
  34. ns_error_t Initialize(nx_uri_t uri);
  35. NXFileRegion region;
  36. nodelist_s region_stack;
  37. nx_uri_t uri;
  38. volatile size_t reference_count;
  39. };