00001 // -*- C++ -*- 00002 00003 //============================================================================= 00004 /** 00005 * @file ObjectKey_Table.h 00006 * 00007 * $Id: ObjectKey_Table.h 76687 2007-01-29 19:18:13Z johnnyw $ 00008 * 00009 * @author Balachandran Natarajan <bala@dre.vanderbilt.edu> 00010 */ 00011 //============================================================================= 00012 00013 #ifndef TAO_OBJECTKEY_TABLE_H 00014 #define TAO_OBJECTKEY_TABLE_H 00015 00016 #include /**/ "ace/pre.h" 00017 #include "ace/RB_Tree.h" 00018 00019 #if !defined (ACE_LACKS_PRAGMA_ONCE) 00020 # pragma once 00021 #endif /* ACE_LACKS_PRAGMA_ONCE */ 00022 00023 #include "ace/Null_Mutex.h" 00024 00025 #include "tao/Object_KeyC.h" 00026 #include /**/ "tao/Versioned_Namespace.h" 00027 00028 TAO_BEGIN_VERSIONED_NAMESPACE_DECL 00029 00030 // Forward declarations 00031 class TAO_ORB_Core; 00032 00033 namespace TAO 00034 { 00035 00036 // Forward declarations within the namespace.. 00037 class Refcounted_ObjectKey; 00038 class ObjectKey; 00039 00040 /** 00041 * @class Less_Than_ObjectKey 00042 * 00043 * @brief Compares the length and then the contents of ObjectKeys. 00044 * 00045 * Should have been a specialization of the functor 00046 * ACE_Less_Than<sequence<CORBA::Octet>>. But that will not work 00047 * so easily across bunch of stuff. Hence let us put up with this 00048 * for the time being. 00049 */ 00050 class TAO_Export Less_Than_ObjectKey 00051 { 00052 public: 00053 bool operator () (const TAO::ObjectKey &lhs, 00054 const TAO::ObjectKey &rhs) const; 00055 }; 00056 00057 /** 00058 * @class ObjectKey_Table 00059 * 00060 * @brief Table that maintains the set of ObjectKey's seen by the 00061 * ORB. 00062 * 00063 * The ORB maintains one table for the whole ORB. ObjectKeys 00064 * generated by the ORB or the ones seen by the ORB from remote 00065 * ORB's are stored here. The ObjectKeys are stored through a 00066 * wrapper which encapsulates the refcount on them. This class 00067 * actually provides the synchronization mechanism for manipulating 00068 * the reference counts on the object keys provided by the wrapper 00069 * class. 00070 * 00071 * This class does not offer a find () call with a reason. The call 00072 * to bind () will return a pointer which is expected to be cached 00073 * by the client/caller and use the pointer in every invocation. 00074 * 00075 * @note This class uses the ACE_RB_Tree to maintain the table of 00076 * ObjectKeys. The RB_Tree has good insertion and lookup 00077 * properties. Its Iteration properties are not that good, but we 00078 * dont need to do much iteration unless we are closing down the 00079 * table. 00080 * 00081 * @note The reasons to use RB_Tree are its good dynamic 00082 * properties. We should try to strategize the class to use either a 00083 * Hash_Map or a RB_Tree based on some runtime option. For that we 00084 * need an adapter class in ACE, like an ACE_Lock_Adapter class. We 00085 * will do that if our instrumentation shows the need for it. 00086 * 00087 */ 00088 class TAO_Export ObjectKey_Table 00089 { 00090 public: 00091 /// Default Constructor and destructor.. 00092 ObjectKey_Table (void); 00093 00094 ~ObjectKey_Table (void); 00095 00096 /// Initialize method that sets up the underlying lock and other 00097 /// related stuff. 00098 int init (TAO_ORB_Core *orb); 00099 00100 /// Iterates and unbinds the contents of the table. 00101 int destroy (void); 00102 00103 /// Bind the ObjectKey in the table. 00104 /** 00105 * Bind an ObjectKey in the table and return a pointer to the 00106 * Refcounted_ObjectKey which the client can use. If the ObjectKey 00107 * is already available in the table, this operation just 00108 * increments the refcount on the ObjectKey. If the ObjectKey is 00109 * new it is bounded to the table. Returns a 0 on success and a -1 00110 * on failure. 00111 */ 00112 int bind (const ObjectKey &key, Refcounted_ObjectKey *&key_new); 00113 00114 /// Unbind an ObjectKey from the table. 00115 int unbind (TAO::Refcounted_ObjectKey *&key); 00116 00117 protected: 00118 /// Implementation for bind (). 00119 int bind_i (const ObjectKey &key, Refcounted_ObjectKey *&key_new); 00120 00121 /// Implementation for unbind (). 00122 int unbind_i (Refcounted_ObjectKey *&key); 00123 00124 private: 00125 00126 // Some useful typedefs. 00127 typedef ACE_RB_Tree<TAO::ObjectKey, 00128 TAO::Refcounted_ObjectKey *, 00129 TAO::Less_Than_ObjectKey, 00130 ACE_Null_Mutex> TABLE; 00131 00132 /// Lock for the table. 00133 ACE_Lock *lock_; 00134 00135 /// Table that contains the data 00136 TABLE table_; 00137 }; 00138 } 00139 00140 TAO_END_VERSIONED_NAMESPACE_DECL 00141 00142 #include /**/ "ace/post.h" 00143 00144 #endif /*TAO_OBJECT_KEY_TABLE_H*/