1 using System;
  
   2 
  
   3 namespace cmsx.kernel
  
   4 {
  
   5     public ulong hostFileCompletionKey = 0u;
  
   6 
  
   7     public class HostFile
  
   8     {
  
   9         public HostFile(const string& hostFilePath_, ulong key_, bool randomAccess) : hostFilePath(hostFilePath_), fileHandle(null), key(key_)
  
  10         {
  
  11             if (System.IO.File.Exists(hostFilePath))
  
  12             {
  
  13                 fileHandle = OsOpenHostFile(hostFilePath.Chars(), randomAccess);
  
  14             }
  
  15             else
  
  16             {
  
  17                 fileHandle = OsCreateHostFile(hostFilePath.Chars(), randomAccess);
  
  18             }
  
  19             if (fileHandle == null)
  
  20             {
  
  21                 throw Exception("error opening host file '" + hostFilePath + "': open failed");
  
  22             }
  
  23         }
  
  24         public ~HostFile()
  
  25         {
  
  26             if (fileHandle != null)
  
  27             {
  
  28                 OsCloseHostFile(fileHandle);
  
  29             }
  
  30         }
  
  31         public inline nothrow const string& GetHostFilePath() const
  
  32         {
  
  33             return hostFilePath;
  
  34         }
  
  35         public inline nothrow void* GetFileHandle() const
  
  36         {
  
  37             return fileHandle;
  
  38         }
  
  39         public inline nothrow ulong Key() const
  
  40         {
  
  41             return key;
  
  42         }
  
  43         private string hostFilePath;
  
  44         private void* fileHandle;
  
  45         private ulong key;
  
  46     }
  
  47 }