PSDL_Datastore.h

Go to the documentation of this file.
00001 /* -*- C++ -*- */
00002 
00003 //=============================================================================
00004 /**
00005  *  @file    PSDL_Datastore.h
00006  *
00007  *  PSDL_Datastore.h,v 1.3 2003/08/02 18:10:48 bala Exp
00008  *
00009  *  @author Priyanka Gontla <gontla_p@ociweb.com>
00010  */
00011 //=============================================================================
00012 
00013 
00014 #ifndef TAO_PSDL_DATASTORE_H
00015 #define TAO_PSDL_DATASTORE_H
00016 #include /**/ "ace/pre.h"
00017 
00018 #include "PSDL_Code_Gen.h"
00019 
00020 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00021 # pragma once
00022 #endif /* ACE_LACKS_PRAGMA_ONCE */
00023 
00024 // The name under which the index of naming contexts is stored in
00025 // persistent naming service.
00026 #if !defined (TAO_PERSISTENT_NAME_OBJ_MAP)
00027 #  define TAO_PERSISTENT_NAME_OBJ_MAP "Persistent_Name_Obj_Map"
00028 #endif /* ! TAO_PERSISTENT_NAME_OBJ_MAP */
00029 
00030 #include "ace/Malloc.h"
00031 #include "ace/Hash_Map_With_Allocator_T.h"
00032 
00033 /**
00034  * @class TAO_PSDL_Datastore
00035  *
00036  * @brief This class facilitates implementation of Persistent
00037  * Service. Helps perform the bind and find to the hash_map
00038  **/
00039 
00040 // Forward declarations.
00041 class TAO_PSDL_OctetSeq;
00042 class TAO_PSDL_String;
00043 
00044 class TAO_PSDL_Export TAO_PSDL_Datastore
00045 {
00046 public:
00047   // = Some typedefs for convenience.
00048 
00049   /// Hash map used by Persistent Naming Context to keep its state.
00050   typedef ACE_Hash_Map_With_Allocator<TAO_PSDL_String, TAO_PSDL_OctetSeq> NAME_OBJ_REF_MAP;
00051 
00052   typedef ACE_Hash_Map_Entry <TAO_PSDL_String, TAO_PSDL_OctetSeq> NAME_OBJ_REF_ENTRY;
00053 
00054   /// Allocator we will be using to make the Naming Service persistent.
00055   typedef ACE_Allocator_Adapter <ACE_Malloc <ACE_MMAP_MEMORY_POOL, TAO_SYNCH_MUTEX>
00056   > ALLOCATOR;
00057 
00058   // = Initialization and termination methods.
00059 
00060   /// Constructor.
00061   TAO_PSDL_Datastore ();
00062 
00063   /**
00064    * Create ACE_Allocator, open/create memory-mapped file with the
00065    * specified file name/base address.  Find or allocate <index_>.
00066    * Return 0 on success or -1 on failure.
00067    */
00068   int open (const ACE_TCHAR *file_name,
00069             void * base_address = ACE_DEFAULT_BASE_ADDR);
00070 
00071   /**
00072    * If <index_> contains no entries (i.e., was just created), create
00073    * a root Persistent servant with table of size
00074    * <context_size>, and make an entry for it
00075    * in the <index_>.  If <index_> contains entries, create a
00076    * Persistent servant for each entry.  Return 0 on
00077    * success and -1 on failure.
00078    */
00079   int init (size_t context_size);
00080 
00081   /**
00082    * Destructor.  The memory mapped file that was opened/created is
00083    * not deleted, since we want it to keep the state of the Database
00084    * until the next run.
00085    */
00086   ~TAO_PSDL_Datastore (void);
00087 
00088   // = Accessors.
00089   int bind (const char *name,
00090             const CORBA::OctetSeq &octetseq);
00091 
00092   int unbind (const char *name);
00093 
00094   int find (const char *name,
00095             CORBA::OctetSeq &octet_seq);
00096 
00097   /// Return allocator.
00098   ACE_Allocator *allocator (void);
00099 
00100 private:
00101 
00102   /// Helper for the <init> method.  Iterates over <index_>, and
00103   /// creates a servant for each entry.
00104   int recreate_all (void);
00105 
00106   /// Helper for the <open> method.
00107   int create_index (void);
00108 
00109   /// Helper for <create_index> method: places hash table into an
00110   /// allocated space.
00111   int create_index_helper (void *buffer);
00112 
00113   /// Lock to prevent multiple threads from modifying entries in the
00114   /// <index_> simultanneously.
00115   TAO_SYNCH_MUTEX lock_;
00116 
00117   /**
00118    * Allocator that deals out memory from a memory-mapped file.  We
00119    * use it whenever we
00120    * deal with data that should be kept in persistent store.
00121    */
00122   ALLOCATOR *allocator_;
00123 
00124   /// Hash map where we keep entries for all Persistent entries
00125   NAME_OBJ_REF_MAP *obj_ref_map_;
00126 
00127   /// Name of the memory-mapped file used by <allocator_>.
00128   const ACE_TCHAR *index_file_;
00129 
00130   /// Base address for the memory-mapped file.
00131   void *base_address_;
00132 };
00133 
00134 #include /**/ "ace/post.h"
00135 #endif /* TAO_PSDL_DATASTORE_H */

Generated on Thu Nov 9 14:07:02 2006 for TAO_PSS by doxygen 1.3.6