Public Types | Public Member Functions | Protected Member Functions | Private Attributes

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_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 74 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 132 of file Filecache.h.

  {
    ACE_SUCCESS = 0,
    ACE_ACCESS_FAILED,
    ACE_OPEN_FAILED,
    ACE_COPY_FAILED,
    ACE_STAT_FAILED,
    ACE_MEMMAP_FAILED,
    ACE_WRITE_FAILED
  };


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.

  : file_ (0), handle_ (0), mapit_ (mapit)
{
  this->init ();
  // Fetch the file from the Virtual_Filesystem let the
  // Virtual_Filesystem do the work of cache coherency.

  // Filecache will also do the acquire, since it holds the lock at
  // that time.
  this->file_ = ACE_Filecache::instance ()->fetch (filename, mapit);
}

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.

  : file_ (0), handle_ (0), mapit_ (mapit)
{
  this->init ();

  if (size == 0)
    ACE_Filecache::instance ()->remove (filename);
  else
    {
      // Since this is being opened for a write, simply create a new
      // ACE_Filecache_Object now, and let the destructor add it into CVF
      // later

      // Filecache will also do the acquire, since it holds the lock at
      // that time.
      this->file_ = ACE_Filecache::instance ()->create (filename, size);
    }
}

ACE_Filecache_Handle::~ACE_Filecache_Handle ( void   ) 

Closes any open handles, release acquired file.

Definition at line 98 of file Filecache.cpp.

{
  if (this->handle_ != ACE_INVALID_HANDLE)
    // this was dup ()'d
    ACE_OS::close (this->handle_);

  ACE_Filecache::instance ()->finish (this->file_);
}

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.

  : file_ (0), handle_ (0), mapit_ (0)
{
  this->init ();
}


Member Function Documentation

void * ACE_Filecache_Handle::address ( void   )  const

Base address of memory mapped file.

Definition at line 108 of file Filecache.cpp.

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

int ACE_Filecache_Handle::error ( void   )  const

Any associated error in handle creation and acquisition.

Definition at line 126 of file Filecache.cpp.

{
  if (this->file_ == 0)
    return -1;
  else
    return this->file_->error ();
}

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.

{
  if (this->handle_ == ACE_INVALID_HANDLE && this->file_ != 0)
    {
      ACE_Filecache_Handle *mutable_this =
        const_cast<ACE_Filecache_Handle *> (this);
      mutable_this->handle_ = ACE_OS::dup (this->file_->handle ());
    }
  return this->handle_;
}

void ACE_Filecache_Handle::init ( void   )  [protected]

Common initializations for constructors.

ACE_OFF_T ACE_Filecache_Handle::size ( void   )  const

The size of the file.

Definition at line 135 of file Filecache.cpp.

{
  if (this->file_ == 0)
    return -1;
  else
    return this->file_->size ();
}


Member Data Documentation

A reference to the low level instance.

Definition at line 145 of file Filecache.h.

ACE_HANDLE ACE_Filecache_Handle::handle_ [private]

A dup'd version of the one from file_.

Definition at line 148 of file Filecache.h.

Definition at line 150 of file Filecache.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines