3 //=============================================================================
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"
20 #include "ace/SString.h"
22 #if !defined (ACE_LACKS_PRAGMA_ONCE)
24 #endif /* ACE_LACKS_PRAGMA_ONCE */
26 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
30 class TAO_Export Storable_Base
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 ()
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
46 static bool retry_on_ebadf_default
;
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.
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,
78 void clear (Storable_State state
= goodbit
);
80 void setstate (Storable_State state
);
82 Storable_State
rdstate () 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;
122 virtual void do_remove () = 0;
124 /// If a backup file exists, remove it.
125 virtual void remove_backup () = 0;
128 bool retry_on_ebadf_
;
131 Storable_State state_
;
134 /// Base class for exceptions thrown when encountering
135 /// errors working with persistent files.
136 class TAO_Export Storable_Exception
139 Storable_Exception (const ACE_CString
& file_name
);
141 virtual ~Storable_Exception ();
143 const ACE_CString
& get_file_name () const;
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
154 Storable_Read_Exception (Storable_Base::Storable_State state
,
155 const ACE_CString
& file_name
);
157 Storable_Base::Storable_State
get_state () const;
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
168 Storable_Write_Exception (Storable_Base::Storable_State state
,
169 const ACE_CString
& file_name
);
171 Storable_Base::Storable_State
get_state () const;
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"