Revert "Minor modernization of DynamicAny code"
[ACE_TAO.git] / TAO / tao / Storable_FlatFileStream.h
blobb5d69b2ee010b80803e5e77d3a757dd31061fa86
1 // -*- C++ -*-
3 //=============================================================================
4 /**
5 * @file Storable_FlatFileStream.h
7 * @author Marina Spivak <marina@cs.wustl.edu>
8 * @author Byron Harris <harrisb@ociweb.com>
9 */
10 //=============================================================================
12 #ifndef STORABLE_FLATFILESTREAM_H
13 #define STORABLE_FLATFILESTREAM_H
15 #include /**/ "ace/pre.h"
16 #include "ace/config-lite.h"
18 #if !defined (ACE_LACKS_PRAGMA_ONCE)
19 #pragma once
20 #endif /* ACE_LACKS_PRAGMA_ONCE */
22 #include "tao/Storable_Base.h"
23 #include "tao/Storable_Factory.h"
24 #include "ace/OS_NS_stdio.h"
26 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
28 namespace TAO
30 /**
31 * @brief A Storable_Base derived class that works with a file stream.
33 class TAO_Export Storable_FlatFileStream : public Storable_Base
35 public:
36 Storable_FlatFileStream(const ACE_CString & file, const char * mode,
37 bool use_backup = Storable_Base::use_backup_default,
38 bool retry_on_ebadf = Storable_Base::retry_on_ebadf_default);
40 virtual ~Storable_FlatFileStream();
42 /// Check if a file exists on disk (file is not open)
43 virtual int exists ();
45 /// Open a file (the remaining methods below all require an open file)
46 virtual int open ();
48 /// When the locked file resides on an NFS mounted volume, occasionally
49 /// the FD of the opened file becomes stale, when that happens the handle
50 /// needs to be refreshed and the lock verified
51 virtual int reopen ();
53 /// Acquire a file lock
54 virtual int close ();
56 /// Acquire a file lock
57 virtual int flock (int whence, int start, int len);
59 /// Release a file lock
60 virtual int funlock (int whence, int start, int len);
62 /// Returns the last time an open file was changed
63 virtual time_t last_changed ();
65 virtual void rewind ();
67 virtual bool flush ();
69 /// Force write of storable data to storage.
70 /// Returns 0 on success, otherwise EOF
71 virtual int sync ();
73 virtual Storable_Base& operator << (const ACE_CString&);
74 virtual Storable_Base& operator >> (ACE_CString&);
75 virtual Storable_Base& operator << (ACE_UINT32 );
76 virtual Storable_Base& operator >> (ACE_UINT32 &);
77 virtual Storable_Base& operator << (ACE_UINT64 );
78 virtual Storable_Base& operator >> (ACE_UINT64 &);
79 virtual Storable_Base& operator << (ACE_INT32 );
80 virtual Storable_Base& operator >> (ACE_INT32 &);
81 virtual Storable_Base& operator << (ACE_INT64 );
82 virtual Storable_Base& operator >> (ACE_INT64 &);
84 virtual Storable_Base& operator << (const TAO_OutputCDR & cdr);
86 virtual size_t write (size_t size, const char * bytes);
88 virtual size_t read (size_t size, char * bytes);
90 virtual int restore_backup ();
92 protected:
93 virtual void do_remove ();
95 virtual void remove_backup ();
97 virtual int create_backup ();
99 private:
100 /// Throw a Storable_Read_Exception if the state
101 /// is not good due to a read error.
102 void throw_on_read_error (Storable_State state);
104 /// Throw a Storable_Write_Exception if the state
105 /// is not good due to a write error.
106 void throw_on_write_error (Storable_State state);
108 ACE_CString backup_file_name ();
110 ACE_OS::ace_flock_t filelock_;
111 FILE* fl_;
112 ACE_CString file_;
113 ACE_CString mode_;
116 class TAO_Export Storable_FlatFileFactory : public Storable_Factory
118 public:
119 /// @param directory Directory to contain file passed in
120 /// create_stream (). The directory is assumed to already exist.
121 Storable_FlatFileFactory(const ACE_CString & directory,
122 bool use_backup = Storable_Base::use_backup_default);
123 Storable_FlatFileFactory(const ACE_CString & directory,
124 bool use_backup,
125 bool retry_on_ebadf);
127 const ACE_CString & get_directory () const;
129 ~Storable_FlatFileFactory ();
131 // Factory Methods
133 /// Create the stream that can operate on a disk file
134 virtual Storable_Base *create_stream (const ACE_CString & file,
135 const char * mode,
136 bool = false);
137 private:
138 static bool is_nfs (const ACE_CString &dir);
139 ACE_CString directory_;
140 bool use_backup_;
141 bool retry_on_ebadf_;
145 TAO_END_VERSIONED_NAMESPACE_DECL
147 #include /**/ "ace/post.h"
149 #endif /* STORABLE_FLATFILESTREAM_H */