Revert "Minor modernization of DynamicAny code"
[ACE_TAO.git] / TAO / tao / Storable_Base.h
blobbc1e1d351c8a5085868999ab0a661bc17a52d6d3
1 // -*- C++ -*-
3 //=============================================================================
4 /**
5 * @file Storable_Base.h
7 * @author Bruce Trask <trask_b@ociweb.com>
8 * @author Chanaka Liyanaarachchi <chanaka@ociweb.com>
9 * @author Byron Harris <harrisb@ociweb.com>
11 //=============================================================================
13 #ifndef TAO_STORABLE_BASE_H
14 #define TAO_STORABLE_BASE_H
16 #include "tao/TAO_Export.h"
17 #include "tao/orbconf.h"
18 #include "tao/CDR.h"
20 #include "ace/SString.h"
22 #if !defined (ACE_LACKS_PRAGMA_ONCE)
23 #pragma once
24 #endif /* ACE_LACKS_PRAGMA_ONCE */
26 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
28 namespace TAO
30 class TAO_Export Storable_Base
32 public:
33 Storable_Base (bool use_backup, bool retry_ebadf);
35 virtual ~Storable_Base ();
37 /// The process-wide default policy for doing a backup when close ()
38 /// is called.
39 /// The backup can then be restored if restore_backup () is called.
40 /// The initial value for the default is false.
41 static bool use_backup_default;
43 /// The process-wide default policy for retiring certain flock operations
44 /// if an ebadf is returned. This can happen spuriously on nfs mounted
45 /// file.
46 static bool retry_on_ebadf_default;
48 bool use_backup ();
50 bool retry_on_ebadf ();
52 /// Remove the file that is assumed to not be open.
53 /// If backup are used, the backup will also be removed.
54 void remove();
56 virtual int create_backup () = 0;
58 virtual int exists() = 0;
60 virtual int open () = 0;
62 virtual int close () = 0;
64 virtual int flock (int whence, int start, int len) = 0;
66 virtual int funlock (int whence, int start, int len) = 0;
68 virtual time_t last_changed() = 0;
70 // Mimic a portion of the std::ios interface. We need to be able
71 // to indicate error states from the extraction operators below.
72 enum Storable_State { goodbit = 0,
73 badbit = 1,
74 eofbit = 2,
75 failbit = 4
78 void clear (Storable_State state = goodbit);
80 void setstate (Storable_State state);
82 Storable_State rdstate () const;
84 bool good () const;
86 bool bad () const;
88 bool eof () const;
90 bool fail () const;
92 static ACE_CString state_as_string (Storable_State state);
94 virtual void rewind () = 0;
96 virtual bool flush () = 0;
98 /// Force write of storable data to storage.
99 /// Returns 0 on success, otherwise EOF
100 virtual int sync () = 0;
102 virtual Storable_Base& operator << (const ACE_CString&) = 0;
103 virtual Storable_Base& operator >> (ACE_CString&) = 0;
104 virtual Storable_Base& operator << (ACE_UINT32 ) = 0;
105 virtual Storable_Base& operator >> (ACE_UINT32 &) = 0;
106 virtual Storable_Base& operator << (ACE_UINT64 ) = 0;
107 virtual Storable_Base& operator >> (ACE_UINT64 &) = 0;
108 virtual Storable_Base& operator << (ACE_INT32 ) = 0;
109 virtual Storable_Base& operator >> (ACE_INT32 &) = 0;
110 virtual Storable_Base& operator << (ACE_INT64 ) = 0;
111 virtual Storable_Base& operator >> (ACE_INT64 &) = 0;
113 virtual Storable_Base& operator << (const TAO_OutputCDR & cdr) = 0;
115 virtual size_t write (size_t size, const char * bytes) = 0;
117 virtual size_t read (size_t size, char * bytes) = 0;
119 virtual int restore_backup () = 0;
121 protected:
122 virtual void do_remove () = 0;
124 /// If a backup file exists, remove it.
125 virtual void remove_backup () = 0;
127 bool use_backup_;
128 bool retry_on_ebadf_;
130 private:
131 Storable_State state_;
134 /// Base class for exceptions thrown when encountering
135 /// errors working with persistent files.
136 class TAO_Export Storable_Exception
138 public:
139 Storable_Exception (const ACE_CString & file_name);
141 virtual ~Storable_Exception ();
143 const ACE_CString & get_file_name () const;
145 private:
146 ACE_CString file_name_;
149 /// Exception thrown when an error is encountered
150 /// during reading of the persistent store.
151 class TAO_Export Storable_Read_Exception : public Storable_Exception
153 public:
154 Storable_Read_Exception (Storable_Base::Storable_State state,
155 const ACE_CString & file_name);
157 Storable_Base::Storable_State get_state () const;
159 private:
160 TAO::Storable_Base::Storable_State storable_state_;
163 /// Exception thrown when an error is encountered
164 /// during writing to the persistent store.
165 class TAO_Export Storable_Write_Exception : public Storable_Exception
167 public:
168 Storable_Write_Exception (Storable_Base::Storable_State state,
169 const ACE_CString & file_name);
171 Storable_Base::Storable_State get_state () const;
173 private:
174 TAO::Storable_Base::Storable_State storable_state_;
178 TAO_END_VERSIONED_NAMESPACE_DECL
180 #if defined (__ACE_INLINE__)
181 #include "tao/Storable_Base.inl"
182 #endif
185 #endif