Hash_Naming_Context.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 //=============================================================================
00004 /**
00005  *  @file   Hash_Naming_Context.h
00006  *
00007  *  $Id: Hash_Naming_Context.h 76589 2007-01-25 18:04:11Z elliott_c $
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 
00157   /**
00158    * This is similar to <bind> operation above, except for when the
00159    * binding for the specified name already exists in the specified
00160    * context.  In that case, the existing binding is replaced with the
00161    * new one.
00162    */
00163   virtual void rebind (const CosNaming::Name &n,
00164                        CORBA::Object_ptr obj);
00165 
00166   /**
00167    * This is the version of <bind> specifically for binding naming
00168    * contexts, so that they will participate in name resolution when
00169    * compound names are passed to be resolved.
00170    */
00171   virtual void bind_context (const CosNaming::Name &n,
00172                              CosNaming::NamingContext_ptr nc);
00173 
00174   /**
00175    * This is a version of <rebind> specifically for naming contexts,
00176    * so that they can participate in name resolution when compound
00177    * names are passed.
00178    */
00179    virtual void rebind_context (const CosNaming::Name &n,
00180                                CosNaming::NamingContext_ptr nc);
00181 
00182   /**
00183    * Return object reference that is bound to the name.  Compound name
00184    * resolve is defined as follows: ctx->resolve (<c1; c2; cn>) =
00185    * ctx->resolve (<c1; c2 cn-1>)->resolve (<cn>) The naming service
00186    * does not return the type of the object.  Clients are responsible
00187    * for "narrowing" the object to the appropriate type.
00188    */
00189   virtual CORBA::Object_ptr resolve (const CosNaming::Name &n);
00190 
00191   /**
00192    * Remove the name binding from the context.  When compound names
00193    * are used, unbind is defined as follows: ctx->unbind (<c1; c2;
00194    * cn>) = (ctx->resolve (<c1; c2; cn-1>))->unbind (<cn>)
00195    */
00196   virtual void unbind (const CosNaming::Name &n);
00197 
00198   /**
00199    * This operation creates a new context and binds it to the name
00200    * supplied as an argument.  The newly-created context is
00201    * implemented by the same server as the context in which it was
00202    * bound (the name argument excluding the last component).
00203    */
00204   virtual CosNaming::NamingContext_ptr bind_new_context (const CosNaming::Name &n);
00205 
00206   /**
00207    * Delete the naming context.  The user should take care to <unbind> any
00208    * bindings in which the given context is bound to some names, to
00209    * avoid dangling references when invoking <destroy> operation.
00210    * NOTE: <destory> is a no-op on the root context.
00211    * NOTE: after <destroy> is invoked on a Naming Context, all
00212    * BindingIterators associated with that Naming Context are also destroyed.
00213    */
00214   virtual void destroy (void);
00215 
00216   /// Returns the Default POA of this Servant object
00217   virtual PortableServer::POA_ptr _default_POA (void);
00218 
00219 protected:
00220   // = Helper method used by other methods.
00221 
00222   /**
00223    * <get_context> is used by methods that need to resolve a compound
00224    * name before performing the actual operation (e.g., bind, unbind,
00225    * etc.)  <get_context> takes a full name (including the last
00226    * component that doesn't need to be resolved), and returns a
00227    * pointer to the target context.
00228    */
00229   CosNaming::NamingContext_ptr get_context (const CosNaming::Name &name);
00230 
00231   /**
00232    * Pointer to the data structure used to store this Naming Context's
00233    * bindings.  <context_> is initialized with a concrete data
00234    * structure by subclasses, which know which data structure to use.
00235    */
00236   TAO_Bindings_Map *context_;
00237 
00238   /**
00239    * Pointer to the <interface> object for which we serve as a
00240    * <concrete implementation>, i.e., the object that delegates to us
00241    * all client CosNaming::NamingContext CORBA calls.
00242    * We need this pointer for reference counting.
00243    */
00244   TAO_Naming_Context *interface_;
00245 
00246   /// Lock used to serialize access to the underlying data structure.
00247   TAO_SYNCH_RECURSIVE_MUTEX lock_;
00248 
00249   /**
00250    * Flag indicating whether this Naming Context is no longer valid.
00251    * This flag is necessary because immediate destruction
00252    * might not be possible if there are pending requests on this servant
00253    * in the POA.
00254    */
00255   int destroyed_;
00256 
00257   /// POA we are registered with.
00258   PortableServer::POA_var poa_;
00259 
00260   /**
00261    * ID with which we are registered with <poa_>.
00262    * Note, if <poa_id_> is equivalent to TAO_ROOT_NAMING_CONTEXT, then this Naming Context
00263    * is the root Naming Context for the server, i.e., it is un<destroy>able.
00264    */
00265   ACE_CString poa_id_;
00266 };
00267 
00268 TAO_END_VERSIONED_NAMESPACE_DECL
00269 
00270 #include /**/ "ace/post.h"
00271 
00272 #endif /* TAO_HASH_NAMING_CONTEXT_H */

Generated on Sun Jan 27 16:15:29 2008 for TAO_CosNaming by doxygen 1.3.6