Random_File.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 //=============================================================================
00004 /**
00005  *  @file    Random_File.h
00006  *
00007  *  $Id: Random_File.h 80166 2007-12-03 13:53:49Z sowayaa $
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 #include "tao/orbconf.h"
00032 
00033 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00034 
00035 namespace TAO_Notify
00036 {
00037 
00038 /**
00039  * \brief A random file class.
00040  *
00041  * Derived from ACE_FILE, this class provides access to a
00042  * file of fixed-size blocks.
00043  *
00044  */
00045 class TAO_Notify_Serv_Export Random_File : public ACE_FILE
00046 {
00047 public:
00048   /// The constructor.
00049   Random_File();
00050 
00051   /// The destructor, which closes the open file.
00052   ~Random_File();
00053 
00054   /// Open a file with default permissions.
00055   bool open(const ACE_TCHAR* filename, size_t block_size = 512);
00056 
00057   /// Accessor for the block size.
00058   /// Note signed size_t is used to be compatible with
00059   /// ACE_FILE.
00060   size_t block_size() const;
00061 
00062   /// Return the current file size, in number of blocks.
00063   ACE_OFF_T size() const;
00064 
00065   /// Write a block to our file, potentially as an "atomic" write.
00066   /// If the atomic argument is true, then the operating system's
00067   /// write-through cache for this file is flushed both before and
00068   /// after the write.
00069   /// The flush before ensures that any record pointers in this block
00070   /// will point to records that actually appear in the file.
00071   /// The flush after provides the caller with a guarantee that
00072   /// the data will appear in the file even if the system fails
00073   /// immediately after this method returns.
00074   bool write(const size_t block_number, void* buffer, bool atomic = false);
00075 
00076   /// Read a block from our file.
00077   bool read(const size_t block_number, void* buffer);
00078 
00079 private:
00080   /// Seek to a given block number, used by reads and writes.
00081   bool seek(const size_t block_number);
00082 
00083   /// Synchronize the file to disk, used to implement atomic.
00084   bool sync();
00085 
00086 private:
00087   size_t block_size_;
00088   mutable TAO_SYNCH_MUTEX lock_;
00089 };
00090 
00091 } /* namespace TAO_Notify */
00092 
00093 TAO_END_VERSIONED_NAMESPACE_DECL
00094 
00095 #include /**/ "ace/post.h"
00096 #endif /* RANDOM_FILE_H */

Generated on Tue Feb 2 17:45:29 2010 for TAO_CosNotification by  doxygen 1.4.7