Random_File.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 //=============================================================================
00004 /**
00005  *  @file    Random_File.h
00006  *
00007  *  Random_File.h,v 1.5 2006/03/14 06:14:34 jtc Exp
00008  *
00009  *  This class implements a a random-access file containing
00010  *  fixed-size blocks.
00011  *
00012  *  @author Jonathan Pollack <pollack_j@ociweb.com>
00013  */
00014 //=============================================================================
00015 
00016 #ifndef RANDOM_FILE_H
00017 #define RANDOM_FILE_H
00018 #include /**/ "ace/pre.h"
00019 #include /**/ "ace/config-all.h"
00020 
00021 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00022 #pragma once
00023 #endif /* ACE_LACKS_PRAGMA_ONCE */
00024 
00025 #include "orbsvcs/Notify/notify_serv_export.h"
00026 #include "tao/Versioned_Namespace.h"
00027 #include "ace/FILE.h"
00028 #include "ace/streams.h"
00029 #include "ace/Synch_T.h"
00030 
00031 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00032 
00033 namespace TAO_Notify
00034 {
00035 
00036 /**
00037  * \brief A random file class.
00038  *
00039  * Derived from ACE_FILE, this class provides access to a
00040  * file of fixed-size blocks.
00041  *
00042  */
00043 class TAO_Notify_Serv_Export Random_File : public ACE_FILE
00044 {
00045 public:
00046   /// The constructor.
00047   Random_File();
00048 
00049   /// The destructor, which closes the open file.
00050   ~Random_File();
00051 
00052   /// Open a file with default permissions.
00053   bool open(const ACE_TCHAR* filename, size_t block_size = 512);
00054 
00055   /// Accessor for the block size.
00056   /// Note signed size_t is used to be compatible with
00057   /// ACE_FILE.
00058   size_t block_size() const;
00059 
00060   /// Return the current file size, in number of blocks.
00061   size_t size() const;
00062 
00063   /// Write a block to our file, potentially as an "atomic" write.
00064   /// If the atomic argument is true, then the operating system's
00065   /// write-through cache for this file is flushed both before and
00066   /// after the write.
00067   /// The flush before ensures that any record pointers in this block
00068   /// will point to records that actually appear in the file.
00069   /// The flush after provides the caller with a guarantee that
00070   /// the data will appear in the file even if the system fails
00071   /// immediately after this method returns.
00072   bool write(const size_t block_number, void* buffer, bool atomic = false);
00073 
00074   /// Read a block from our file.
00075   bool read(const size_t block_number, void* buffer);
00076 
00077 private:
00078   /// Seek to a given block number, used by reads and writes.
00079   bool seek(const size_t block_number);
00080 
00081   /// Synchronize the file to disk, used to implement atomic.
00082   bool sync();
00083 
00084 private:
00085   size_t block_size_;
00086   ACE_SYNCH_MUTEX lock_;
00087 };
00088 
00089 } /* namespace TAO_Notify */
00090 
00091 TAO_END_VERSIONED_NAMESPACE_DECL
00092 
00093 #include /**/ "ace/post.h"
00094 #endif /* RANDOM_FILE_H */

Generated on Thu Nov 9 13:24:14 2006 for TAO_CosNotification by doxygen 1.3.6