Updated logging to include the class/method so that it is more obvious where these...
[ACE_TAO.git] / TAO / tao / Storable_File_Guard.h
blob7f33ba7c681104b3340c233d849834d4e5bf9724
1 // -*- C++ -*-
3 //=============================================================================
4 /**
5 * @file Storable_File_Guard.h
7 * @author Rich Seibel (seibelr@ociweb.com)
8 * @author Byron Harris (harrisb@ociweb.com)
9 */
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
19 namespace TAO
21 /**
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
33 public:
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.
42 void release (void);
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.
53 enum Method_Type
56 /// Construction with persistent file already existing
57 CREATE_WITH_FILE,
59 /// Construction with persistent file not existing
60 CREATE_WITHOUT_FILE,
62 /// Getting object state
63 ACCESSOR,
65 /// Setting object state
66 MUTATOR
69 protected:
70 /// Should be called by constructors of derived classes
71 /// since can't call the virtual functions below in constructor
72 /// of this class.
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
83 void reload (void);
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)
103 Storable_Base *fl_;
105 private:
106 // Return 0 if successful.
107 int load ();
109 bool redundant_;
111 /// A flag to keep us from trying to close things more than once.
112 int closed_;
114 /// The flags that we were opened with
115 int rwflags_;
117 /// A flag indicating if backup/restore should be performed
118 bool use_backup_;
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
127 #endif