ACE_Filecache_Handle Class Reference

Abstraction over a real file. This is meant to be the entry point into the Cached Virtual Filesystem. More...

#include <Filecache.h>

Collaboration diagram for ACE_Filecache_Handle:

Collaboration graph
[legend]
List of all members.

Public Types

 ACE_SUCCESS = 0
 ACE_ACCESS_FAILED
 ACE_OPEN_FAILED
 ACE_COPY_FAILED
 ACE_STAT_FAILED
 ACE_MEMMAP_FAILED
 ACE_WRITE_FAILED
enum  {
  ACE_SUCCESS = 0, ACE_ACCESS_FAILED, ACE_OPEN_FAILED, ACE_COPY_FAILED,
  ACE_STAT_FAILED, ACE_MEMMAP_FAILED, ACE_WRITE_FAILED
}
 These come from ACE_Filecache_Object, which is an internal class. More...

Public Member Functions

 ACE_Filecache_Handle (const ACE_TCHAR *filename, ACE_Filecache_Flag mapit=ACE_MAPIT)
 ACE_Filecache_Handle (const ACE_TCHAR *filename, int size, ACE_Filecache_Flag mapit=ACE_MAPIT)
 ~ACE_Filecache_Handle (void)
 Closes any open handles, release acquired file.
void * address (void) const
 Base address of memory mapped file.
ACE_HANDLE handle (void) const
 A handle (e.g., UNIX file descriptor, or NT file handle).
int error (void) const
 Any associated error in handle creation and acquisition.
ACE_OFF_T size (void) const
 The size of the file.

Protected Member Functions

 ACE_Filecache_Handle (void)
 Default do nothing constructor. Prevent it from being called.
void init (void)
 Common initializations for constructors.

Private Attributes

ACE_Filecache_Objectfile_
 A reference to the low level instance.
ACE_HANDLE handle_
 A <dup>'d version of the one from <file_>.
int mapit_

Detailed Description

Abstraction over a real file. This is meant to be the entry point into the Cached Virtual Filesystem.

This is a cached filesystem implementation based loosely on the implementation of JAWS_File. The interfaces will be nearly the same. The under-the-hood implementation should hopefully be a much faster thing. These will be given their own implementations later. For now, we borrow the implementation provided by JAWS. On creation, the cache is checked, and reference count is incremented. On destruction, reference count is decremented. If the reference count is 0, the file is removed from the cache. E.g. 1, { ACE_Filecache_Handle foo("foo.html"); this->peer ().send (foo.address (), foo.size ()); } E.g. 2, { ACE_Filecache_Handle foo("foo.html"); io->transmitfile (foo.handle (), this->peer ().handle ()); } E.g. 3, { ACE_Filecache_Handle foo("foo.html", content_length); this->peer ().recv (foo.address (), content_length); } TODO:

Definition at line 73 of file Filecache.h.


Member Enumeration Documentation

anonymous enum

These come from ACE_Filecache_Object, which is an internal class.

Enumerator:
ACE_SUCCESS 
ACE_ACCESS_FAILED 
ACE_OPEN_FAILED 
ACE_COPY_FAILED 
ACE_STAT_FAILED 
ACE_MEMMAP_FAILED 
ACE_WRITE_FAILED 

Definition at line 131 of file Filecache.h.

00132   {
00133     ACE_SUCCESS = 0,
00134     ACE_ACCESS_FAILED,
00135     ACE_OPEN_FAILED,
00136     ACE_COPY_FAILED,
00137     ACE_STAT_FAILED,
00138     ACE_MEMMAP_FAILED,
00139     ACE_WRITE_FAILED
00140   };


Constructor & Destructor Documentation

ACE_Filecache_Handle::ACE_Filecache_Handle ( const ACE_TCHAR filename,
ACE_Filecache_Flag  mapit = ACE_MAPIT 
)

Query cache for file, and acquire it. Assumes the file is being opened for reading.

Definition at line 64 of file Filecache.cpp.

References ACE_Filecache::fetch(), file_, init(), and ACE_Filecache::instance().

00066   : file_ (0), handle_ (0), mapit_ (mapit)
00067 {
00068   this->init ();
00069   // Fetch the file from the Virtual_Filesystem let the
00070   // Virtual_Filesystem do the work of cache coherency.
00071 
00072   // Filecache will also do the acquire, since it holds the lock at
00073   // that time.
00074   this->file_ = ACE_Filecache::instance ()->fetch (filename, mapit);
00075 }

ACE_Filecache_Handle::ACE_Filecache_Handle ( const ACE_TCHAR filename,
int  size,
ACE_Filecache_Flag  mapit = ACE_MAPIT 
)

Create new entry, and acquire it. Presence of SIZE assumes the file is being opened for writing. If SIZE is zero, assumes the file is to be removed from the cache.

Definition at line 77 of file Filecache.cpp.

References ACE_Filecache::create(), file_, init(), ACE_Filecache::instance(), and ACE_Filecache::remove().

00080   : file_ (0), handle_ (0), mapit_ (mapit)
00081 {
00082   this->init ();
00083 
00084   if (size == 0)
00085     ACE_Filecache::instance ()->remove (filename);
00086   else
00087     {
00088       // Since this is being opened for a write, simply create a new
00089       // ACE_Filecache_Object now, and let the destructor add it into CVF
00090       // later
00091 
00092       // Filecache will also do the acquire, since it holds the lock at
00093       // that time.
00094       this->file_ = ACE_Filecache::instance ()->create (filename, size);
00095     }
00096 }

ACE_Filecache_Handle::~ACE_Filecache_Handle ( void   ) 

Closes any open handles, release acquired file.

Definition at line 98 of file Filecache.cpp.

References ACE_OS::close(), ACE_Filecache::finish(), and ACE_Filecache::instance().

00099 {
00100   if (this->handle_ != ACE_INVALID_HANDLE)
00101     // this was dup ()'d
00102     ACE_OS::close (this->handle_);
00103 
00104   ACE_Filecache::instance ()->finish (this->file_);
00105 }

ACE_Filecache_Handle::ACE_Filecache_Handle ( void   )  [protected]

Default do nothing constructor. Prevent it from being called.

Definition at line 58 of file Filecache.cpp.

References init().

00059   : file_ (0), handle_ (0), mapit_ (0)
00060 {
00061   this->init ();
00062 }


Member Function Documentation

void * ACE_Filecache_Handle::address ( void   )  const

Base address of memory mapped file.

Definition at line 108 of file Filecache.cpp.

References ACE_Filecache_Object::address(), and file_.

00109 {
00110   return this->file_ == 0 ? 0 : this->file_->address ();
00111 }

int ACE_Filecache_Handle::error ( void   )  const

Any associated error in handle creation and acquisition.

Definition at line 126 of file Filecache.cpp.

References ACE_Filecache_Object::error(), and file_.

00127 {
00128   if (this->file_ == 0)
00129     return -1;
00130   else
00131     return this->file_->error ();
00132 }

ACE_HANDLE ACE_Filecache_Handle::handle ( void   )  const

A handle (e.g., UNIX file descriptor, or NT file handle).

Definition at line 114 of file Filecache.cpp.

References ACE_OS::dup(), and handle_.

00115 {
00116   if (this->handle_ == ACE_INVALID_HANDLE && this->file_ != 0)
00117     {
00118       ACE_Filecache_Handle *mutable_this =
00119         const_cast<ACE_Filecache_Handle *> (this);
00120       mutable_this->handle_ = ACE_OS::dup (this->file_->handle ());
00121     }
00122   return this->handle_;
00123 }

void ACE_Filecache_Handle::init ( void   )  [protected]

Common initializations for constructors.

Definition at line 52 of file Filecache.cpp.

References file_, and handle_.

Referenced by ACE_Filecache_Handle().

00053 {
00054   this->file_ = 0;
00055   this->handle_ = ACE_INVALID_HANDLE;
00056 }

ACE_OFF_T ACE_Filecache_Handle::size ( void   )  const

The size of the file.

Definition at line 135 of file Filecache.cpp.

References file_, and ACE_Filecache_Object::size().

00136 {
00137   if (this->file_ == 0)
00138     return -1;
00139   else
00140     return this->file_->size ();
00141 }


Member Data Documentation

ACE_Filecache_Object* ACE_Filecache_Handle::file_ [private]

A reference to the low level instance.

Definition at line 144 of file Filecache.h.

Referenced by ACE_Filecache_Handle(), address(), error(), init(), and size().

ACE_HANDLE ACE_Filecache_Handle::handle_ [private]

A <dup>'d version of the one from <file_>.

Definition at line 147 of file Filecache.h.

Referenced by handle(), and init().

int ACE_Filecache_Handle::mapit_ [private]

Definition at line 149 of file Filecache.h.


The documentation for this class was generated from the following files:
Generated on Tue Feb 2 17:35:08 2010 for ACE by  doxygen 1.4.7