3 //=============================================================================
5 * @file Storable_File_Guard.h
7 * @author Rich Seibel (seibelr@ociweb.com)
8 * @author Byron Harris (harrisb@ociweb.com)
10 //=============================================================================
12 #ifndef TAO_STORABLE_FILE_GUARD_H
13 #define TAO_STORABLE_FILE_GUARD_H
15 #include "tao/Storable_Base.h"
17 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
22 * @class Storable_File_Guard
23 * @brief Base class to use with TAO_Storable_Base to synch object state
24 * with a storable base.
26 * A guard for Storable_Base that opens a file
27 * for read/write and sets a lock on it. It then checks if the file has
28 * changed and re-reads it if it has.
31 class TAO_Export Storable_File_Guard
34 Storable_File_Guard (bool redundant
,
35 bool use_backup
= Storable_Base::use_backup_default
);
37 virtual ~Storable_File_Guard () noexcept(false);
39 /// Releases the lock, closes the file, and deletes the I/O stream.
40 /// Destructors of derived classes should call this this will
41 /// virtual functions are available.
44 /// Return when the object in memory has last changed
45 virtual time_t get_object_last_changed () = 0;
47 /// Get the underlying stream being used.
48 TAO::Storable_Base
& peer ();
50 /// Indicate how the state of the object is being used.
51 /// This is used for determine the mode for accessing
52 /// the persistent store.
56 /// Construction with persistent file already existing
59 /// Construction with persistent file not existing
62 /// Getting object state
65 /// Setting object state
70 /// Should be called by constructors of derived classes
71 /// since can't call the virtual functions below in constructor
73 void init (Method_Type method_type
);
75 /// Initializes the backing store file object but does not
76 /// actually load the data. This can be called without locks,
77 /// allowing the caller to decide whether or not to then lock
78 /// and complete the load.
79 void init_no_load (Method_Type method_type
);
81 /// Complete the initialization of the containing object, should
82 /// be called with lock held after calling init_no_load
85 /// Check if the object is current with the last update.
86 virtual bool object_obsolete (void);
88 /// Mark the object as up to date
89 virtual void mark_object_current (void);
91 /// Indicate when the object in memory has last changed
92 virtual void set_object_last_changed (const time_t & time
) = 0;
94 /// Load object from file to memory. Return 0 on success.
95 virtual int load_from_stream () = 0;
97 /// Answer if object has been loaded from file
98 virtual bool is_loaded_from_stream () = 0;
100 virtual Storable_Base
* create_stream (const char * mode
) = 0;
102 /// The pointer to the actual file I/O (bridge pattern)
106 // Return 0 if successful.
111 /// A flag to keep us from trying to close things more than once.
114 /// The flags that we were opened with
117 /// A flag indicating if backup/restore should be performed
120 /// Symbolic values for the flags in the above
121 enum { mode_write
= 1, mode_read
= 2, mode_create
= 4 };
125 TAO_END_VERSIONED_NAMESPACE_DECL