AsyncFileDevice

Files CCore/inc/AsyncFileDevice.h CCore/src/AsyncFileDevice.cpp

AsyncFileDevice is an async file device (AsyncFile). It performs operations on the local file system. You may create an object of this class and register it in the default object register. After this you can use classes for async file input-output like PrintAsyncFile to work with files.


class AsyncFileDevice : public ObjBase , public Sys::AsyncFileDevice
 {
   ....

  public:
   
   static const ulen DefaultMaxSlots = .... ;
   
   explicit AsyncFileDevice(ulen max_slots=DefaultMaxSlots);
   
   virtual ~AsyncFileDevice();
   
   // Sys::AsyncFileDevice
  
   virtual Sys::AsyncFileState * createState(const ObjHook &hook) noexcept ;
 };

This class is implemented upon the target classes Sys::AltAsyncFile and Sys::AsyncFileWait, declared in the header sys/SysFile.h.


struct Sys::AltAsyncFile
 {
  // private

  ....

  // public
  
  static const ulen MaxRWLen = ... ; // like 1_MByte
  
  struct AsyncState;

  using Async = AsyncState * ;
  
  struct Result
   {
    FilePosType file_len;
    FileError error;
   };
  
  struct RWResult
   {
    bool pending;
    FileError error;
   };
 
  Result open(StrLen file_name,FileOpenFlags oflags) noexcept;
  
  void close(FileMultiError &errout,bool preserve_file=false) noexcept; 
  
  void close() noexcept; 
  
  FileError testRead(FilePosType off,ulen len) noexcept;
  
  Result setWrite(FilePosType off,ulen len) noexcept;
  
  RWResult startRead(Async async,FilePosType off,uint8 *buf,ulen len) noexcept;
  
  FileError completeRead(Async async,ulen len) noexcept;
  
  RWResult startWrite(Async async,FilePosType off,const uint8 *buf,ulen len) noexcept;
  
  FileError completeWrite(Async async,ulen len) noexcept;
 };


struct Sys::AsyncFileWait
 {
  // private

  ....

  // public
  
  static const ulen MaxAsyncs = .... ;
  
  FileError init(ulen async_count) noexcept;
  
  void exit() noexcept;
  
  AltAsyncFile::Async getAsync(ulen index) noexcept;
  
  bool addWait(ulen index) noexcept;
  
  bool delWait(ulen index) noexcept;
  
  WaitResult wait(MSec timeout) noexcept;
  
  WaitResult wait(TimeScope time_scope) noexcept;
  
  void interrupt() noexcept; // async , semaphore
 };