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

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_LOFF_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 'd version of the one from .

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.

Enumeration values:
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 63 of file Filecache.cpp.

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

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

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 76 of file Filecache.cpp.

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

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

ACE_Filecache_Handle::~ACE_Filecache_Handle void   ) 
 

Closes any open handles, release acquired file.

Definition at line 97 of file Filecache.cpp.

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

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

ACE_Filecache_Handle::ACE_Filecache_Handle void   )  [protected]
 

Default do nothing constructor. Prevent it from being called.

Definition at line 57 of file Filecache.cpp.

References init().

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


Member Function Documentation

void * ACE_Filecache_Handle::address void   )  const
 

Base address of memory mapped file.

Definition at line 107 of file Filecache.cpp.

References ACE_Filecache_Object::address(), and file_.

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

int ACE_Filecache_Handle::error void   )  const
 

Any associated error in handle creation and acquisition.

Definition at line 125 of file Filecache.cpp.

References ACE_Filecache_Object::error(), and file_.

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

ACE_HANDLE ACE_Filecache_Handle::handle void   )  const
 

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

Definition at line 113 of file Filecache.cpp.

References ACE_OS::dup(), file_, and handle_.

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

void ACE_Filecache_Handle::init void   )  [protected]
 

Common initializations for constructors.

Definition at line 51 of file Filecache.cpp.

References file_.

Referenced by ACE_Filecache_Handle().

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

ACE_LOFF_T ACE_Filecache_Handle::size void   )  const
 

The size of the file.

Definition at line 134 of file Filecache.cpp.

References file_, and ACE_Filecache_Object::size().

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


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(), handle(), init(), and size().

ACE_HANDLE ACE_Filecache_Handle::handle_ [private]
 

A 'd version of the one from .

Definition at line 147 of file Filecache.h.

Referenced by handle().

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 Thu Nov 9 11:22:18 2006 for ACE by doxygen 1.3.6