Hash_Naming_Context.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 //=============================================================================
00004 /**
00005  *  @file   Hash_Naming_Context.h
00006  *
00007  *  Hash_Naming_Context.h,v 1.23 2006/03/14 06:14:33 jtc Exp
00008  *
00009  *  @author Marina Spivak <marina@cs.wustl.edu>
00010  */
00011 //=============================================================================
00012 
00013 
00014 #ifndef TAO_HASH_NAMING_CONTEXT_H
00015 #define TAO_HASH_NAMING_CONTEXT_H
00016 
00017 #include /**/ "ace/pre.h"
00018 
00019 #include "orbsvcs/Naming/Naming_Context_Interface.h"
00020 #include "orbsvcs/Naming/naming_serv_export.h"
00021 
00022 #include "ace/Recursive_Thread_Mutex.h"
00023 #include "ace/SString.h"
00024 
00025 // This is to remove "inherits via dominance" warnings from MSVC.
00026 #if defined (_MSC_VER)
00027 # pragma warning (disable : 4250)
00028 #endif /* _MSC_VER */
00029 
00030 // Note: 'interface' has been defined as struct on WinCE platform and
00031 //       gives a compiler error.  This undef has been found harmless on
00032 //       Windows and solaris platforms; however, if this generates
00033 //       error, then proper ifdef must be added around following block.
00034 #if defined (interface)
00035 #undef interface
00036 #endif  // interface
00037 
00038 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00039 
00040 /**
00041  * @class TAO_Bindings_Map
00042  *
00043  * @brief This abstract base class defines an interface for hash-based
00044  * data structures used in implementations of NamingContext
00045  * (i.e., TAO_Transient_Naming_Context and TAO_Persistent_Naming_Context)
00046  *
00047  * Define an interface for several hash-based data structures, so
00048  * that we can write some code that would work with any of them,
00049  * i.e., TAO_Hash_Naming_Context.
00050  */
00051 class TAO_Naming_Serv_Export TAO_Bindings_Map
00052 {
00053 
00054 public:
00055 
00056   /// Destructor.
00057   virtual ~TAO_Bindings_Map (void);
00058 
00059   /// Return current number of entries (name bindings) in the
00060   /// underlying hash map.
00061   virtual size_t current_size (void) = 0;
00062 
00063   /**
00064    * Add a binding with the specified parameters to the table.
00065    * Return 0 on success and -1 on failure, 1 if there already is a
00066    * binding with <id> and <kind>.
00067    */
00068   virtual int bind (const char *id,
00069                     const char *kind,
00070                     CORBA::Object_ptr obj,
00071                     CosNaming::BindingType type) = 0;
00072 
00073   /**
00074    * Overwrite a binding containing <id> and <kind> (or create a new
00075    * one if one doesn't exist) with the specified parameters.  Returns
00076    * -1 on failure.
00077    */
00078   virtual int rebind (const char *id,
00079                       const char *kind,
00080                       CORBA::Object_ptr obj,
00081                       CosNaming::BindingType type) = 0;
00082 
00083   /// Remove a binding containing <id> and <kind> from the table.
00084   /// Return 0 on success and -1 on failure.
00085   virtual int unbind (const char * id,
00086                       const char * kind) = 0;
00087 
00088   /**
00089    * Find the binding containing <id> and <kind> in the table, and
00090    * pass binding's type and object back to the caller by reference.
00091    * Return 0 on success and -1 on failure.   Note: a 'duplicated' object
00092    * reference is assigned to <obj>, so the caller is responsible for
00093    * its deallocation.
00094    */
00095   virtual int find (const char * id,
00096                     const char * kind,
00097                     CORBA::Object_ptr & obj,
00098                     CosNaming::BindingType &type) = 0;
00099 
00100 };
00101 
00102 /**
00103  * @class TAO_Hash_Naming_Context
00104  *
00105  * @brief This class factors out common code for two 'ConcreteImplementors'
00106  * in the Bridge pattern architecture of the CosNaming::NamingContext
00107  * implementation.
00108  *
00109  * This class contains 'algorithm' code that is common to two
00110  * hash-table-based implementations of the NamingContext:
00111  * TAO_Transient_Naming_Context and TAO_Persistent_Naming_Context.
00112  * To help achieve this 'templatization', we use the abstract base
00113  * class TAO_Bindings_Map, which provides a common interface to the data structures
00114  * used in TAO_Persistent_Namng_Context and TAO_Transient_Naming_Context.
00115  */
00116 class TAO_Naming_Serv_Export TAO_Hash_Naming_Context :public TAO_Naming_Context_Impl
00117 {
00118 public:
00119   // = Initialization and termination methods.
00120   /// Constructor.
00121   TAO_Hash_Naming_Context (PortableServer::POA_ptr poa,
00122                            const char *poa_id);
00123 
00124   /// Set our <interface_> pointer.
00125   void interface (TAO_Naming_Context *i);
00126 
00127   /// Destructor.
00128   virtual ~TAO_Hash_Naming_Context (void);
00129 
00130   // = Accessors.
00131 
00132   /// Get the pointer to our <interface>.
00133   TAO_Naming_Context *interface (void);
00134 
00135   /// Returns true if this Naming Context is a root Naming Context for
00136   /// the server, and false otherwise.
00137   int root (void);
00138 
00139   /// Returns true if this context had <destroy> operation invoked on
00140   /// it, and false otherwise.
00141   int destroyed (void);
00142 
00143   // = CosNaming::NamingContext idl interface methods.
00144 
00145   /**
00146    * Create a binding for name <n> and object <obj> in the naming
00147    * context.  Compound names are treated as follows: ctx->bind (<c1;
00148    * c2; c3; cn>, obj) = (ctx->resolve (<c1; c2; cn-1>))->bind (<cn>,
00149    * obj) if the there already exists a binding for the specified
00150    * name, <AlreadyBound> exception is thrown.  Naming contexts should
00151    * be bound using <bind_context> and <rebind_context> in order to
00152    * participate in name resolution later.
00153    */
00154   virtual void bind (const CosNaming::Name &n,
00155                      CORBA::Object_ptr obj
00156                      ACE_ENV_ARG_DECL);
00157 
00158   /**
00159    * This is similar to <bind> operation above, except for when the
00160    * binding for the specified name already exists in the specified
00161    * context.  In that case, the existing binding is replaced with the
00162    * new one.
00163    */
00164   virtual void rebind (const CosNaming::Name &n,
00165                        CORBA::Object_ptr obj
00166                        ACE_ENV_ARG_DECL);
00167 
00168   /**
00169    * This is the version of <bind> specifically for binding naming
00170    * contexts, so that they will participate in name resolution when
00171    * compound names are passed to be resolved.
00172    */
00173   virtual void bind_context (const CosNaming::Name &n,
00174                              CosNaming::NamingContext_ptr nc
00175                              ACE_ENV_ARG_DECL);
00176 
00177   /**
00178    * This is a version of <rebind> specifically for naming contexts,
00179    * so that they can participate in name resolution when compound
00180    * names are passed.
00181    */
00182    virtual void rebind_context (const CosNaming::Name &n,
00183                                CosNaming::NamingContext_ptr nc
00184                                ACE_ENV_ARG_DECL);
00185 
00186   /**
00187    * Return object reference that is bound to the name.  Compound name
00188    * resolve is defined as follows: ctx->resolve (<c1; c2; cn>) =
00189    * ctx->resolve (<c1; c2 cn-1>)->resolve (<cn>) The naming service
00190    * does not return the type of the object.  Clients are responsible
00191    * for "narrowing" the object to the appropriate type.
00192    */
00193   virtual CORBA::Object_ptr resolve (const CosNaming::Name &n
00194                                      ACE_ENV_ARG_DECL);
00195 
00196   /**
00197    * Remove the name binding from the context.  When compound names
00198    * are used, unbind is defined as follows: ctx->unbind (<c1; c2;
00199    * cn>) = (ctx->resolve (<c1; c2; cn-1>))->unbind (<cn>)
00200    */
00201   virtual void unbind (const CosNaming::Name &n
00202                        ACE_ENV_ARG_DECL);
00203 
00204   /**
00205    * This operation creates a new context and binds it to the name
00206    * supplied as an argument.  The newly-created context is
00207    * implemented by the same server as the context in which it was
00208    * bound (the name argument excluding the last component).
00209    */
00210   virtual CosNaming::NamingContext_ptr bind_new_context (const CosNaming::Name &n
00211                                                          ACE_ENV_ARG_DECL);
00212 
00213   /**
00214    * Delete the naming context.  The user should take care to <unbind> any
00215    * bindings in which the given context is bound to some names, to
00216    * avoid dangling references when invoking <destroy> operation.
00217    * NOTE: <destory> is a no-op on the root context.
00218    * NOTE: after <destroy> is invoked on a Naming Context, all
00219    * BindingIterators associated with that Naming Context are also destroyed.
00220    */
00221   virtual void destroy (ACE_ENV_SINGLE_ARG_DECL);
00222 
00223   /// Returns the Default POA of this Servant object
00224   virtual PortableServer::POA_ptr _default_POA (void);
00225 
00226 protected:
00227   // = Helper method used by other methods.
00228 
00229   /**
00230    * <get_context> is used by methods that need to resolve a compound
00231    * name before performing the actual operation (e.g., bind, unbind,
00232    * etc.)  <get_context> takes a full name (including the last
00233    * component that doesn't need to be resolved), and returns a
00234    * pointer to the target context.
00235    */
00236   CosNaming::NamingContext_ptr get_context (const CosNaming::Name &name
00237                                             ACE_ENV_ARG_DECL);
00238 
00239   /**
00240    * Pointer to the data structure used to store this Naming Context's
00241    * bindings.  <context_> is initialized with a concrete data
00242    * structure by subclasses, which know which data structure to use.
00243    */
00244   TAO_Bindings_Map *context_;
00245 
00246   /**
00247    * Pointer to the <interface> object for which we serve as a
00248    * <concrete implementation>, i.e., the object that delegates to us
00249    * all client CosNaming::NamingContext CORBA calls.
00250    * We need this pointer for reference counting.
00251    */
00252   TAO_Naming_Context *interface_;
00253 
00254   /// Lock used to serialize access to the underlying data structure.
00255   TAO_SYNCH_RECURSIVE_MUTEX lock_;
00256 
00257   /**
00258    * Flag indicating whether this Naming Context is no longer valid.
00259    * This flag is necessary because immediate destruction
00260    * might not be possible if there are pending requests on this servant
00261    * in the POA.
00262    */
00263   int destroyed_;
00264 
00265   /// POA we are registered with.
00266   PortableServer::POA_var poa_;
00267 
00268   /**
00269    * ID with which we are registered with <poa_>.
00270    * Note, if <poa_id_> is equivalent to TAO_ROOT_NAMING_CONTEXT, then this Naming Context
00271    * is the root Naming Context for the server, i.e., it is un<destroy>able.
00272    */
00273   ACE_CString poa_id_;
00274 };
00275 
00276 TAO_END_VERSIONED_NAMESPACE_DECL
00277 
00278 #include /**/ "ace/post.h"
00279 
00280 #endif /* TAO_HASH_NAMING_CONTEXT_H */

Generated on Thu Nov 9 13:57:02 2006 for TAO_CosNaming by doxygen 1.3.6