summaryrefslogtreecommitdiff
path: root/TAO/tao/Storable_File_Guard.h
diff options
context:
space:
mode:
Diffstat (limited to 'TAO/tao/Storable_File_Guard.h')
-rw-r--r--TAO/tao/Storable_File_Guard.h93
1 files changed, 93 insertions, 0 deletions
diff --git a/TAO/tao/Storable_File_Guard.h b/TAO/tao/Storable_File_Guard.h
new file mode 100644
index 00000000000..b062f9a8ad9
--- /dev/null
+++ b/TAO/tao/Storable_File_Guard.h
@@ -0,0 +1,93 @@
+// -*- C++ -*-
+
+//=============================================================================
+/**
+ * @file Storable_File_Guard.h
+ *
+ * $Id$
+ *
+ * @author Rich Seibel (seibelr@ociweb.com)
+ * @author Byron Harris (harrisb@ociweb.com)
+ */
+//=============================================================================
+
+#ifndef TAO_STORABLE_FILE_GUARD_H
+#define TAO_STORABLE_FILE_GUARD_H
+
+#include "tao/orbconf.h"
+#include "tao/TAO_Export.h"
+
+TAO_BEGIN_VERSIONED_NAMESPACE_DECL
+
+namespace TAO
+{
+
+ class Storable_Base;
+
+ /**
+ * @class Storable_File_Guard
+ * @brief Bridge abstract class for TAO_Storable_Base that performs locking.
+ *
+ * A guard for Storable_Base that opens a file
+ * for read/write and sets a lock on it. It then checks if the file has
+ * changed and re-reads it if it has.
+ *
+ * The destructor releases the lock.
+ */
+ class TAO_Export Storable_File_Guard
+ {
+ public:
+
+ Storable_File_Guard (bool redundant);
+
+ virtual ~Storable_File_Guard ();
+
+ /// Releases the lock, closes the file, and deletes the I/O stream.
+ void release (void);
+
+ /// Returns the stream to read/write on
+ Storable_Base & peer (void);
+
+ protected:
+
+ /// Should be called by constructors of derived classes
+ /// since can't call virtual functions below in constructor
+ /// of this class.
+ void init (const char * mode);
+
+ virtual void set_parent_last_changed (const time_t & time) = 0;
+
+ virtual time_t get_parent_last_changed () = 0;
+
+ virtual void create_child () = 0;
+
+ virtual bool is_child_created () = 0;
+
+ virtual Storable_Base * create_stream (const char * mode) = 0;
+
+ /// The pointer to the actual file I/O (bridge pattern)
+ Storable_Base *fl_;
+
+ private:
+
+ bool redundant_;
+
+ /// Default constructor
+ Storable_File_Guard ();
+
+ /// A flag to keep us from trying to close things more than once.
+ int closed_;
+
+ /// The flags that we were opened with
+ int rwflags_;
+
+ /// Symbolic values for the flags in the above
+ enum { mode_write = 1, mode_read = 2, mode_create = 4 };
+
+ };
+
+}
+
+TAO_END_VERSIONED_NAMESPACE_DECL
+
+#endif