From 32d0e998682d8d7fd9e39f1a922e5d2cd146facb Mon Sep 17 00:00:00 2001 From: Johnny Willemsen Date: Fri, 4 Mar 2005 10:02:50 +0000 Subject: ChangeLogTag: Fri Mar 4 10:01:12 UTC 2005 Johnny Willemsen --- TAO/tao/PortableServer/Operation_Table.cpp | 540 --------------------- TAO/tao/PortableServer/Operation_Table.h | 315 ------------ .../Operation_Table_Binary_Search.cpp | 94 ++++ .../PortableServer/Operation_Table_Binary_Search.h | 67 +++ .../Operation_Table_Dynamic_Hash.cpp | 164 +++++++ .../PortableServer/Operation_Table_Dynamic_Hash.h | 80 +++ TAO/tao/PortableServer/Operation_Table_Factory.cpp | 26 + TAO/tao/PortableServer/Operation_Table_Factory.h | 55 +++ .../Operation_Table_Linear_Search.cpp | 95 ++++ .../PortableServer/Operation_Table_Linear_Search.h | 63 +++ .../PortableServer/Operation_Table_Parameters.cpp | 58 +++ .../PortableServer/Operation_Table_Parameters.h | 82 ++++ .../Operation_Table_Perfect_Hash.cpp | 105 ++++ .../PortableServer/Operation_Table_Perfect_Hash.h | 73 +++ 14 files changed, 962 insertions(+), 855 deletions(-) create mode 100644 TAO/tao/PortableServer/Operation_Table_Binary_Search.cpp create mode 100644 TAO/tao/PortableServer/Operation_Table_Binary_Search.h create mode 100644 TAO/tao/PortableServer/Operation_Table_Dynamic_Hash.cpp create mode 100644 TAO/tao/PortableServer/Operation_Table_Dynamic_Hash.h create mode 100644 TAO/tao/PortableServer/Operation_Table_Factory.cpp create mode 100644 TAO/tao/PortableServer/Operation_Table_Factory.h create mode 100644 TAO/tao/PortableServer/Operation_Table_Linear_Search.cpp create mode 100644 TAO/tao/PortableServer/Operation_Table_Linear_Search.h create mode 100644 TAO/tao/PortableServer/Operation_Table_Parameters.cpp create mode 100644 TAO/tao/PortableServer/Operation_Table_Parameters.h create mode 100644 TAO/tao/PortableServer/Operation_Table_Perfect_Hash.cpp create mode 100644 TAO/tao/PortableServer/Operation_Table_Perfect_Hash.h diff --git a/TAO/tao/PortableServer/Operation_Table.cpp b/TAO/tao/PortableServer/Operation_Table.cpp index 613d26a39d9..4d8d3308e46 100644 --- a/TAO/tao/PortableServer/Operation_Table.cpp +++ b/TAO/tao/PortableServer/Operation_Table.cpp @@ -1,515 +1,17 @@ // $Id$ #include "Operation_Table.h" -#include "tao/Timeprobe.h" #include "tao/ORB.h" ACE_RCSID(PortableServer, Operation_Table, "$Id$") -#if defined (ACE_ENABLE_TIMEPROBES) - -static const char *TAO_Operation_Table_Timeprobe_Description[] = - { - "TAO_Dynamic_Hash_OpTable::find - start", - "TAO_Dynamic_Hash_OpTable::find - end", - - "TAO_Linear_Search_OpTable::find - start", - "TAO_Linear_Search_OpTable::find - end", - - "TAO_Active_Demux_OpTable::find - start", - "TAO_Active_Demux_OpTable::find - end", - - "TAO_Perfect_Hash_OpTable::find - start", - "TAO_Perfect_Hash_OpTable::find - end", - - "TAO_Binary_Search_OpTable::find - start", - "TAO_Binary_Search_OpTable::find - end" - }; - -enum - { - // Timeprobe description table start key - TAO_DYNAMIC_HASH_OPTABLE_FIND_START = 600, - TAO_DYNAMIC_HASH_OPTABLE_FIND_END, - - TAO_LINEAR_SEARCH_OPTABLE_FIND_START, - TAO_LINEAR_SEARCH_OPTABLE_FIND_END, - - TAO_ACTIVE_DEMUX_OPTABLE_FIND_START, - TAO_ACTIVE_DEMUX_OPTABLE_FIND_END, - - TAO_PERFECT_HASH_OPTABLE_FIND_START, - TAO_PERFECT_HASH_OPTABLE_FIND_END, - - TAO_BINARY_SEARCH_OPTABLE_FIND_START, - TAO_BINARY_SEARCH_OPTABLE_FIND_END - }; - -// Setup Timeprobes -ACE_TIMEPROBE_EVENT_DESCRIPTIONS (TAO_Operation_Table_Timeprobe_Description, - TAO_DYNAMIC_HASH_OPTABLE_FIND_START); - -#endif /* ACE_ENABLE_TIMEPROBES */ - // destructor TAO_Operation_Table::~TAO_Operation_Table (void) { } -// constructor -TAO_Dynamic_Hash_OpTable::TAO_Dynamic_Hash_OpTable ( - TAO_operation_db_entry const * db, - CORBA::ULong dbsize, - CORBA::ULong hashtblsize, - ACE_Allocator *alloc) - : hash_ (hashtblsize, alloc) -{ - // Iterate thru each entry in the database and bind the operation - // name to its corresponding skeleton. - for (CORBA::ULong i = 0; i < dbsize; ++i) - { - TAO::Operation_Skeletons s; - s.skel_ptr = db[i].skel_ptr; - s.thruPOA_skel_ptr = db[i].skel_ptr; - s.direct_skel_ptr = db[i].direct_skel_ptr; - - // @@ (ASG): what happens if bind fails ??? - if (this->bind (db[i].opname, s) == -1) - ACE_ERROR ((LM_ERROR, - ACE_TEXT ("(%P|%t) %p\n"), - ACE_TEXT ("bind failed"))); - } -} - -TAO_Dynamic_Hash_OpTable::~TAO_Dynamic_Hash_OpTable (void) -{ - // Initialize an iterator. We need to go thru each entry and free - // up storage allocated to hold the external ids. In this case, - // these are strings. - OP_MAP_MANAGER::ITERATOR iterator (this->hash_); - - for (OP_MAP_MANAGER::ENTRY *entry = 0; - iterator.next (entry) != 0; - iterator.advance ()) - { - // We had allocated memory and stored the string. So we free the - // memory. - CORBA::string_free ((char *) entry->ext_id_); - entry->ext_id_ = 0; - } -} - -int -TAO_Dynamic_Hash_OpTable::bind (const char *opname, - const TAO::Operation_Skeletons skel_ptr) -{ - return this->hash_.bind (CORBA::string_dup (opname), - skel_ptr); -} - -int -TAO_Dynamic_Hash_OpTable::find (const char *opname, - TAO_Skeleton& skel_ptr, - const unsigned int ) -{ - ACE_FUNCTION_TIMEPROBE (TAO_DYNAMIC_HASH_OPTABLE_FIND_START); - TAO::Operation_Skeletons s; - - int retval = - this->hash_.find ((const char *)opname, - s); - - if (retval != -1) - { - skel_ptr = s.skel_ptr; - } - - return retval; -} - -int -TAO_Dynamic_Hash_OpTable::find (const char *opname, - TAO_Collocated_Skeleton& skel_ptr, - TAO::Collocation_Strategy s, - const unsigned int ) -{ - ACE_FUNCTION_TIMEPROBE (TAO_DYNAMIC_HASH_OPTABLE_FIND_START); - - TAO::Operation_Skeletons skel; - - int retval = - this->hash_.find ((const char *)opname, skel); - - if (retval != -1) - { - switch (s) - { - case TAO::TAO_CS_DIRECT_STRATEGY: - skel_ptr = skel.direct_skel_ptr; - break; - default: - return -1; - } - } - - return retval; -} - -/***************************************************************/ - -TAO_Linear_Search_OpTable::TAO_Linear_Search_OpTable (void) -{ -} - -TAO_Linear_Search_OpTable::~TAO_Linear_Search_OpTable (void) -{ -} - -int -TAO_Linear_Search_OpTable::bind (const char *, - const TAO::Operation_Skeletons ) -{ - return 0; -} - -int -TAO_Linear_Search_OpTable::find (const char *opname, - TAO_Skeleton& skelfunc, - const unsigned int ) -{ - ACE_FUNCTION_TIMEPROBE (TAO_LINEAR_SEARCH_OPTABLE_FIND_START); - - TAO_operation_db_entry const * const entry = lookup (opname); - if (entry == 0) - ACE_ERROR_RETURN ((LM_ERROR, - ACE_TEXT ("TAO_Linear_Search_Table:find failed\n")), - -1); - - // Valid entry. Figure out the skel_ptr. - skelfunc = entry->skel_ptr; - - return 0; -} - - -int -TAO_Linear_Search_OpTable::find (const char *opname, - TAO_Collocated_Skeleton &skelfunc, - TAO::Collocation_Strategy st, - const unsigned int ) -{ - ACE_FUNCTION_TIMEPROBE (TAO_LINEAR_SEARCH_OPTABLE_FIND_START); - - TAO_operation_db_entry const * const entry = lookup (opname); - if (entry == 0) - ACE_ERROR_RETURN ((LM_ERROR, - ACE_TEXT ("TAO_Linear_Search_Table:find failed\n")), - -1); - - switch (st) - { - case TAO::TAO_CS_DIRECT_STRATEGY: - skelfunc = entry->direct_skel_ptr; - break; - default: - return -1; - } - - return 0; -} - -/*********************************************************************/ -TAO_Active_Demux_OpTable::TAO_Active_Demux_OpTable (const - TAO_operation_db_entry *db, - CORBA::ULong dbsize) - : next_ (0), - tablesize_ (dbsize), - tbl_ (0) -{ - ACE_NEW (tbl_, - TAO_Active_Demux_OpTable_Entry[dbsize]); - - // The job of the constructor is to go thru each entry of the - // database and bind the operation name to its corresponding - // skeleton. - for (CORBA::ULong i=0; i < dbsize; i++) - { - TAO::Operation_Skeletons s; - s.skel_ptr = db[i].skel_ptr; - s.thruPOA_skel_ptr = db[i].skel_ptr; - s.direct_skel_ptr = db[i].direct_skel_ptr; - - // @@ (ASG): what happens if bind fails ??? - (void) this->bind (db[i].opname, s); - } -} - -TAO_Active_Demux_OpTable::~TAO_Active_Demux_OpTable (void) -{ - delete [] this->tbl_; -} - -int -TAO_Active_Demux_OpTable::bind (const char * opname, - const TAO::Operation_Skeletons skel_ptr) -{ - CORBA::ULong i = ACE_OS::atoi (opname); - - if (i < this->tablesize_) - { - if (this->tbl_[i].op_skel_ptr_.skel_ptr != 0) - // overwriting previous one - return 1; - else - { - this->tbl_[i].op_skel_ptr_ = skel_ptr; - return 0; - } - } - return -1; // error -} - -int -TAO_Active_Demux_OpTable::find (const char *opname, - TAO_Skeleton& skel_ptr, - const unsigned int ) -{ - ACE_FUNCTION_TIMEPROBE (TAO_ACTIVE_DEMUX_OPTABLE_FIND_START); - - CORBA::ULong i = ACE_OS::atoi (opname); - - ACE_ASSERT (i < this->tablesize_); - skel_ptr = this->tbl_[i].op_skel_ptr_.skel_ptr; - return 0; //success -} - - -int -TAO_Active_Demux_OpTable::find (const char *opname, - TAO_Collocated_Skeleton& skel_ptr, - TAO::Collocation_Strategy st, - const unsigned int ) -{ - ACE_FUNCTION_TIMEPROBE (TAO_ACTIVE_DEMUX_OPTABLE_FIND_START); - - CORBA::ULong i = ACE_OS::atoi (opname); - - ACE_ASSERT (i < this->tablesize_); - - switch (st) - { - case TAO::TAO_CS_DIRECT_STRATEGY: - skel_ptr = this->tbl_[i].op_skel_ptr_.direct_skel_ptr; - break; - default: - return -1; - } - - return 0; //success -} -TAO_Active_Demux_OpTable_Entry::TAO_Active_Demux_OpTable_Entry (void) -{ -} - -TAO_Active_Demux_OpTable_Entry::~TAO_Active_Demux_OpTable_Entry (void) -{ -} - -/**************************************************/ -// Do nothing constructor. -TAO_Perfect_Hash_OpTable::TAO_Perfect_Hash_OpTable (void) -{ -} - -// Do nothing destrctor. -TAO_Perfect_Hash_OpTable::~TAO_Perfect_Hash_OpTable (void) -{ -} - -int -TAO_Perfect_Hash_OpTable::find (const char *opname, - TAO_Skeleton &skelfunc, - const unsigned int length) -{ - ACE_FUNCTION_TIMEPROBE (TAO_PERFECT_HASH_OPTABLE_FIND_START); - - TAO_operation_db_entry const * const entry = lookup (opname, - length); - if (entry == 0) - { - skelfunc = 0; // insure that somebody can't call a wrong function! - ACE_ERROR_RETURN ((LM_ERROR, - ACE_TEXT ("TAO_Perfect_Hash_OpTable:find for ") - ACE_TEXT ("operation '%s' (length=%d) failed\n"), - ACE_TEXT_CHAR_TO_TCHAR (opname ? opname : ""), length), - -1); - } - - // Valid entry. Figure out the skel_ptr. - skelfunc = entry->skel_ptr; - - return 0; -} - -int -TAO_Perfect_Hash_OpTable::find (const char *opname, - TAO_Collocated_Skeleton &skelfunc, - TAO::Collocation_Strategy st, - const unsigned int length) -{ - ACE_FUNCTION_TIMEPROBE (TAO_PERFECT_HASH_OPTABLE_FIND_START); - - TAO_operation_db_entry const * const entry = lookup (opname, - length); - if (entry == 0) - { - skelfunc = 0; // insure that somebody can't call a wrong function! - ACE_ERROR_RETURN ((LM_ERROR, - ACE_TEXT ("TAO_Perfect_Hash_OpTable:find for ") - ACE_TEXT ("operation '%s' (length=%d) failed\n"), - ACE_TEXT_CHAR_TO_TCHAR (opname ? opname : ""), length), - -1); - } - - switch (st) - { - case TAO::TAO_CS_DIRECT_STRATEGY: - skelfunc = entry->direct_skel_ptr; - break; - default: - return -1; - } - - return 0; -} - -int -TAO_Perfect_Hash_OpTable::bind (const char *, - const TAO::Operation_Skeletons) -{ - return 0; -} - -/*****************************************************************/ -TAO_Binary_Search_OpTable::TAO_Binary_Search_OpTable (void) -{ -} - -TAO_Binary_Search_OpTable::~TAO_Binary_Search_OpTable (void) -{ -} - -int -TAO_Binary_Search_OpTable::find (const char *opname, - TAO_Skeleton &skelfunc, - const unsigned int /* length */) -{ - ACE_FUNCTION_TIMEPROBE (TAO_BINARY_SEARCH_OPTABLE_FIND_START); - - TAO_operation_db_entry const * const entry = lookup (opname); - - if (entry == 0) - ACE_ERROR_RETURN ((LM_ERROR, - ACE_TEXT ("TAO_Binary_Search_Table:find failed\n")), - -1); - // Valid entry. Figure out the skel_ptr. - skelfunc = entry->skel_ptr; - - return 0; -} - - -int -TAO_Binary_Search_OpTable::find (const char *opname, - TAO_Collocated_Skeleton &skelfunc, - TAO::Collocation_Strategy st, - const unsigned int /* length */) -{ - ACE_FUNCTION_TIMEPROBE (TAO_BINARY_SEARCH_OPTABLE_FIND_START); - - TAO_operation_db_entry const * const entry = lookup (opname); - - if (entry == 0) - ACE_ERROR_RETURN ((LM_ERROR, - ACE_TEXT ("TAO_Binary_Search_Table:find failed\n")), - -1); - - switch (st) - { - case TAO::TAO_CS_DIRECT_STRATEGY: - skelfunc = entry->direct_skel_ptr; - break; - default: - return -1; - } - - return 0; -} - -int -TAO_Binary_Search_OpTable::bind (const char *, - const TAO::Operation_Skeletons ) -{ - return 0; -} - -/******************************************************************/ -TAO_Operation_Table_Parameters::TAO_Operation_Table_Parameters (void) - : strategy_ (0), - type_ (TAO_Operation_Table_Parameters::TAO_DYNAMIC_HASH) // default -{ -} - -TAO_Operation_Table_Parameters::~TAO_Operation_Table_Parameters (void) -{ -} - -void -TAO_Operation_Table_Parameters::lookup_strategy (TAO_Operation_Table_Parameters::DEMUX_STRATEGY s) -{ - this->type_ = s; -} - -// get the lookup type -TAO_Operation_Table_Parameters::DEMUX_STRATEGY -TAO_Operation_Table_Parameters::lookup_strategy (void) const -{ - return this->type_; -} - -// set the concrete strategy -void -TAO_Operation_Table_Parameters::concrete_strategy (TAO_Operation_Table *ot) -{ - this->strategy_ = ot; -} - -// return the concrete strategy -TAO_Operation_Table* -TAO_Operation_Table_Parameters::concrete_strategy (void) -{ - return this->strategy_; -} - -TAO_Operation_Table_Factory::TAO_Operation_Table_Factory (void) -{ -} - -TAO_Operation_Table_Factory::~TAO_Operation_Table_Factory (void) -{ -} - -TAO_Operation_Table * -TAO_Operation_Table_Factory::opname_lookup_strategy (void) -{ - TAO_Operation_Table_Parameters * const p = - TAO_OP_TABLE_PARAMETERS::instance (); - - return p->concrete_strategy (); -} - /**************************************************************/ TAO::Operation_Skeletons::Operation_Skeletons (void) : skel_ptr (0) @@ -518,45 +20,3 @@ TAO::Operation_Skeletons::Operation_Skeletons (void) { } -#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION) -template class ACE_Hash_Map_Iterator_Base_Ex, - ACE_Equal_To, - ACE_Null_Mutex>; -template class ACE_Hash_Map_Iterator_Ex, - ACE_Equal_To, - ACE_Null_Mutex>; - -template class ACE_Hash_Map_Reverse_Iterator_Ex, - ACE_Equal_To, - ACE_Null_Mutex>; -template class ACE_Hash_Map_Manager_Ex, - ACE_Equal_To, - ACE_Null_Mutex>; -template class ACE_Hash_Map_Entry; - -template class TAO_Singleton; - -#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA) - -#pragma instantiate ACE_Hash_Map_Iterator_Base_Ex, ACE_Equal_To, ACE_Null_Mutex> -#pragma instantiate ACE_Hash_Map_Iterator_Ex, ACE_Equal_To, ACE_Null_Mutex> -#pragma instantiate ACE_Hash_Map_Reverse_Iterator_Ex, ACE_Equal_To, ACE_Null_Mutex> -#pragma instantiate ACE_Hash_Map_Manager_Ex, ACE_Equal_To, ACE_Null_Mutex> -#pragma instantiate ACE_Hash_Map_Entry -#pragma instantiate TAO_Singleton - -#elif defined (ACE_HAS_EXPLICIT_STATIC_TEMPLATE_MEMBER_INSTANTIATION) - -template TAO_Singleton* TAO_Singleton::singleton_; - -#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */ diff --git a/TAO/tao/PortableServer/Operation_Table.h b/TAO/tao/PortableServer/Operation_Table.h index 56873f03604..2301d7929f6 100644 --- a/TAO/tao/PortableServer/Operation_Table.h +++ b/TAO/tao/PortableServer/Operation_Table.h @@ -22,11 +22,7 @@ #endif /* ACE_LACKS_PRAGMA_ONCE */ #include "tao/Object.h" -#include "tao/TAO_Singleton.h" #include "tao/Collocation_Strategy.h" -#include "ace/Synch_Traits.h" -#include "ace/Null_Mutex.h" -#include "ace/Hash_Map_Manager.h" class TAO_ServerRequest; class TAO_Abstract_ServantBase; @@ -98,7 +94,6 @@ namespace TAO }; } - /** * @class TAO_Operation_Table * @@ -135,315 +130,5 @@ public: virtual ~TAO_Operation_Table (void); }; -/** - * @class TAO_Operation_Table_Factory - * - * @brief Factory for producing operation table lookup objects based on - * the enumerated value of strategy held by the parameters. - */ -class TAO_PortableServer_Export TAO_Operation_Table_Factory -{ -public: - /// Return an instance of the specified lookup strategy - TAO_Operation_Table *opname_lookup_strategy (void); - - /// Constructor - TAO_Operation_Table_Factory (void); - - /// Destructor - ~TAO_Operation_Table_Factory (void); -}; - -/** - * @class TAO_Operation_Table_Parameters - * - * @brief Parameters used to create the operation table. - */ -class TAO_PortableServer_Export TAO_Operation_Table_Parameters -{ -public: - /// various lookup strategies - enum DEMUX_STRATEGY - { - TAO_LINEAR_SEARCH, - TAO_DYNAMIC_HASH, - TAO_PERFECT_HASH, - TAO_BINARY_SEARCH, - TAO_ACTIVE_DEMUX, - TAO_USER_DEFINED - }; - - /// Set the lookup strategy from the list of enumerated values - void lookup_strategy (DEMUX_STRATEGY s); - - /// Return the enumerated value for the lookup strategy. Default is - /// Dynamic Hashing. - DEMUX_STRATEGY lookup_strategy (void) const; - - /// Provide a data structure that will do the lookup. This is useful - /// for user-defined lookup strategies. - void concrete_strategy (TAO_Operation_Table *ot); - - /// Return the operation table that is being used to do the lookup. - TAO_Operation_Table *concrete_strategy (void); - - /// Constructor. - TAO_Operation_Table_Parameters (void); - - /// Destructor - ~TAO_Operation_Table_Parameters (void); -private: - /// Pointer to the object that implements a lookup strategy - TAO_Operation_Table *strategy_; - - /// The enumerated value indicating the lookup strategy - DEMUX_STRATEGY type_; -}; - -/** - * @class TAO_Dynamic_Hash_OpTable - * - * @brief Dynamic Hashing scheme for CORBA IDL operation name lookup. - */ -class TAO_PortableServer_Export TAO_Dynamic_Hash_OpTable - : public TAO_Operation_Table -{ -public: - // = Initialization and termination methods. - /** - * Initialize the dynamic hash operation table with a database of - * operation names. The hash table size may be different from the - * size of the database. Hence we use the third argument to specify - * the size of the internal hash table. The argument is - * used to determine where the memory comes from (usually from - * ). - */ - TAO_Dynamic_Hash_OpTable (const TAO_operation_db_entry *db, - CORBA::ULong dbsize, - CORBA::ULong hashtblsize, - ACE_Allocator *alloc); - - /// Destructor - ~TAO_Dynamic_Hash_OpTable (void); - - /// See the documentation in the base class for details. - virtual int bind (const char *opname, - const TAO::Operation_Skeletons skel_ptr); - - virtual int find (const char *opname, - TAO_Skeleton &skelfunc, - const unsigned int length = 0); - - virtual int find (const char *opname, - TAO_Collocated_Skeleton &skelfunc, - TAO::Collocation_Strategy s, - const unsigned int length = 0); -private: - typedef ACE_Hash_Map_Manager_Ex, - ACE_Equal_To, - ACE_Null_Mutex> - OP_MAP_MANAGER; - - /// The hash table data structure. - OP_MAP_MANAGER hash_; -}; - -/** - * @class TAO_Linear_Search_OpTable - * - * @brief Operation table lookup strategy based on - * linear search. Not efficient, but it works. - */ -class TAO_PortableServer_Export TAO_Linear_Search_OpTable - : public TAO_Operation_Table -{ -public: - // = Initialization and termination methods. - /// Default constructor. - TAO_Linear_Search_OpTable (void); - - /// Destructor. - ~TAO_Linear_Search_OpTable (void); - - /// See the documentation in the base class for details. - virtual int find (const char *opname, - TAO_Skeleton &skel_ptr, - const unsigned int length = 0); - - virtual int find (const char *opname, - TAO_Collocated_Skeleton &skelfunc, - TAO::Collocation_Strategy s, - const unsigned int length = 0); - - virtual int bind (const char *opname, - const TAO::Operation_Skeletons skelptr); - -private: - // = Method that should defined by the subclasses. GPERF program - // will generate this routine routines. - virtual const TAO_operation_db_entry* lookup (const char *str) = 0; -}; - -/** - * @class TAO_Active_Demux_OpTable_Entry - * - * @brief Active Demux lookup table entry. - */ -class TAO_PortableServer_Export TAO_Active_Demux_OpTable_Entry -{ -public: - // = Initialization and termination methods. - /// Constructor - TAO_Active_Demux_OpTable_Entry (void); - - /// Destructor - ~TAO_Active_Demux_OpTable_Entry (void); - - /// Skeleton pointer corresponding to the index. - TAO::Operation_Skeletons op_skel_ptr_; -}; - -/** - * @class TAO_Active_Demux_OpTable - * - * @brief Implements the active demultiplexed lookup strategy. The key is - * assumed to provide an index directly into the internal table. - */ -class TAO_PortableServer_Export TAO_Active_Demux_OpTable - : public TAO_Operation_Table -{ -public: - // = Initialization and termination methods. - /// Initializes the internal table with the database of operations - TAO_Active_Demux_OpTable (const TAO_operation_db_entry *db, - CORBA::ULong dbsize); - - /// Destructor. - ~TAO_Active_Demux_OpTable (void); - - /// See the documentation in the base class fopr details. - virtual int find (const char *opname, - TAO_Skeleton &skel_ptr, - const unsigned int length = 0); - - virtual int find (const char *opname, - TAO_Collocated_Skeleton &skelfunc, - TAO::Collocation_Strategy s, - const unsigned int length = 0); - - virtual int bind (const char *opname, - const TAO::Operation_Skeletons skelptr); - -private: - /// The next available free slot - CORBA::ULong next_; - - /// Size of the internal table - CORBA::ULong tablesize_; - - /// Internal lookup table - TAO_Active_Demux_OpTable_Entry *tbl_; -}; - -/** - * @class TAO_Perfect_Hash_OpTable - * - * @brief Helper class for use of perfect hashing operation lookup - * strategy. - * - * This class declares pure virtual methods called 'lookup ()' - * and 'hash ()' which will be generated by the GPERF - * program. These methods are used by 'bind ()' and 'find ()' - * methods. Subclasses will define the lookup and hash - * functions. - */ -class TAO_PortableServer_Export TAO_Perfect_Hash_OpTable - : public TAO_Operation_Table -{ -public: - /// Do nothing constructor. - TAO_Perfect_Hash_OpTable (void); - - /// Do nothing destrctor. - virtual ~TAO_Perfect_Hash_OpTable (void); - - /// See the documentation in the base class for details. - virtual int find (const char *opname, - TAO_Skeleton &skelfunc, - const unsigned int length = 0); - - virtual int find (const char *opname, - TAO_Collocated_Skeleton &skelfunc, - TAO::Collocation_Strategy s, - const unsigned int length = 0); - - virtual int bind (const char *opname, - const TAO::Operation_Skeletons skel_ptr); - -private: - // = Methods that should defined by the subclasses. GPERF program - // will generate these routines. - - virtual unsigned int hash (const char *str, unsigned int len) = 0; - - virtual const TAO_operation_db_entry* lookup (const char *str, - unsigned int len) = 0; -}; - -/** - * @class TAO_Binary_Search_OpTable - * - * @brief Helper class for using binary search operatin lookup strategy - * in the server skeletons. - * - * This class declares pure virtual method called 'lookup ()' - * which will be generated by the GPERF program. This method is - * used by 'bind ()' and 'find ()' methods. Subclasses will - * define the lookup method. - */ -class TAO_PortableServer_Export TAO_Binary_Search_OpTable - : public TAO_Operation_Table -{ -public: - /// Do nothing constructor. - TAO_Binary_Search_OpTable (void); - - /// Do nothing destrctor. - virtual ~TAO_Binary_Search_OpTable (void); - - /// See the documentation in the base class for details. - virtual int find (const char *opname, - TAO_Skeleton &skelfunc, - const unsigned int length = 0); - - virtual int find (const char *opname, - TAO_Collocated_Skeleton &skelfunc, - TAO::Collocation_Strategy s, - const unsigned int length = 0); - - virtual int bind (const char *opname, - const TAO::Operation_Skeletons skel_ptr); - -private: - /// Method that should defined by the subclasses. GPERF program - /// will generate this routine routines. - virtual const TAO_operation_db_entry* lookup (const char *str) = 0; -}; - - -/// Define a singleton instance of operation table parameters. -typedef TAO_Singleton - TAO_OP_TABLE_PARAMETERS; - - -/// Define a singleton instance of the operation table factory. -typedef TAO_Singleton - TAO_OP_TABLE_FACTORY; - - #include /**/ "ace/post.h" #endif /* TAO_OPTABLE_H */ diff --git a/TAO/tao/PortableServer/Operation_Table_Binary_Search.cpp b/TAO/tao/PortableServer/Operation_Table_Binary_Search.cpp new file mode 100644 index 00000000000..12ff4cf608e --- /dev/null +++ b/TAO/tao/PortableServer/Operation_Table_Binary_Search.cpp @@ -0,0 +1,94 @@ +// $Id$ + +#include "Operation_Table_Binary_Search.h" +#include "tao/Timeprobe.h" +#include "ace/Log_Msg.h" + +ACE_RCSID(PortableServer, + Operation_Table_Binary_Search, + "$Id$") + +#if defined (ACE_ENABLE_TIMEPROBES) + +static const char *TAO_Operation_Table_Timeprobe_Description[] = + { + "TAO_Binary_Search_OpTable::find - start", + "TAO_Binary_Search_OpTable::find - end" + }; + +enum + { + // Timeprobe description table start key + TAO_BINARY_SEARCH_OPTABLE_FIND_START = 608, + TAO_BINARY_SEARCH_OPTABLE_FIND_END + }; + +// Setup Timeprobes +ACE_TIMEPROBE_EVENT_DESCRIPTIONS (TAO_Operation_Table_Timeprobe_Description, + TAO_BINARY_SEARCH_OPTABLE_FIND_START); + +#endif /* ACE_ENABLE_TIMEPROBES */ + + +TAO_Binary_Search_OpTable::TAO_Binary_Search_OpTable (void) +{ +} + +TAO_Binary_Search_OpTable::~TAO_Binary_Search_OpTable (void) +{ +} + +int +TAO_Binary_Search_OpTable::find (const char *opname, + TAO_Skeleton &skelfunc, + const unsigned int /* length */) +{ + ACE_FUNCTION_TIMEPROBE (TAO_BINARY_SEARCH_OPTABLE_FIND_START); + + TAO_operation_db_entry const * const entry = lookup (opname); + + if (entry == 0) + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT ("TAO_Binary_Search_Table:find failed\n")), + -1); + // Valid entry. Figure out the skel_ptr. + skelfunc = entry->skel_ptr; + + return 0; +} + + +int +TAO_Binary_Search_OpTable::find (const char *opname, + TAO_Collocated_Skeleton &skelfunc, + TAO::Collocation_Strategy st, + const unsigned int /* length */) +{ + ACE_FUNCTION_TIMEPROBE (TAO_BINARY_SEARCH_OPTABLE_FIND_START); + + TAO_operation_db_entry const * const entry = lookup (opname); + + if (entry == 0) + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT ("TAO_Binary_Search_Table:find failed\n")), + -1); + + switch (st) + { + case TAO::TAO_CS_DIRECT_STRATEGY: + skelfunc = entry->direct_skel_ptr; + break; + default: + return -1; + } + + return 0; +} + +int +TAO_Binary_Search_OpTable::bind (const char *, + const TAO::Operation_Skeletons ) +{ + return 0; +} + diff --git a/TAO/tao/PortableServer/Operation_Table_Binary_Search.h b/TAO/tao/PortableServer/Operation_Table_Binary_Search.h new file mode 100644 index 00000000000..107be238432 --- /dev/null +++ b/TAO/tao/PortableServer/Operation_Table_Binary_Search.h @@ -0,0 +1,67 @@ +// This may look like C, but it's really -*- C++ -*- + +//============================================================================= +/** + * @file Operation_Table_Binary_Search.h + * + * $Id$ + * + * @author Aniruddha Gokhale + */ +//============================================================================= + +#ifndef TAO_OPERATION_TABLE_BINARY_SEARCH_H +#define TAO_OPERATION_TABLE_BINARY_SEARCH_H + +#include /**/ "ace/pre.h" + +#include "portableserver_export.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +#include "Operation_Table.h" + +/** + * @class TAO_Binary_Search_OpTable + * + * @brief Helper class for using binary search operatin lookup strategy + * in the server skeletons. + * + * This class declares pure virtual method called 'lookup ()' + * which will be generated by the GPERF program. This method is + * used by 'bind ()' and 'find ()' methods. Subclasses will + * define the lookup method. + */ +class TAO_PortableServer_Export TAO_Binary_Search_OpTable + : public TAO_Operation_Table +{ +public: + /// Do nothing constructor. + TAO_Binary_Search_OpTable (void); + + /// Do nothing destrctor. + virtual ~TAO_Binary_Search_OpTable (void); + + /// See the documentation in the base class for details. + virtual int find (const char *opname, + TAO_Skeleton &skelfunc, + const unsigned int length = 0); + + virtual int find (const char *opname, + TAO_Collocated_Skeleton &skelfunc, + TAO::Collocation_Strategy s, + const unsigned int length = 0); + + virtual int bind (const char *opname, + const TAO::Operation_Skeletons skel_ptr); + +private: + /// Method that should defined by the subclasses. GPERF program + /// will generate this routine routines. + virtual const TAO_operation_db_entry* lookup (const char *str) = 0; +}; + +#include /**/ "ace/post.h" +#endif /* TAO_OPERATION_TABLE_BINARY_SEARCH_H */ diff --git a/TAO/tao/PortableServer/Operation_Table_Dynamic_Hash.cpp b/TAO/tao/PortableServer/Operation_Table_Dynamic_Hash.cpp new file mode 100644 index 00000000000..dd03dbe1f81 --- /dev/null +++ b/TAO/tao/PortableServer/Operation_Table_Dynamic_Hash.cpp @@ -0,0 +1,164 @@ +// $Id$ + +#include "Operation_Table_Dynamic_Hash.h" +#include "tao/Timeprobe.h" +#include "ace/Log_Msg.h" + +ACE_RCSID(PortableServer, + Operation_Table_Dynamic_Hash, + "$Id$") + +#if defined (ACE_ENABLE_TIMEPROBES) + +static const char *TAO_Operation_Table_Timeprobe_Description[] = + { + "TAO_Dynamic_Hash_OpTable::find - start", + "TAO_Dynamic_Hash_OpTable::find - end", + }; + +enum + { + // Timeprobe description table start key + TAO_DYNAMIC_HASH_OPTABLE_FIND_START = 600, + TAO_DYNAMIC_HASH_OPTABLE_FIND_END, + }; + +// Setup Timeprobes +ACE_TIMEPROBE_EVENT_DESCRIPTIONS (TAO_Operation_Table_Timeprobe_Description, + TAO_DYNAMIC_HASH_OPTABLE_FIND_START); + +#endif /* ACE_ENABLE_TIMEPROBES */ + +// constructor +TAO_Dynamic_Hash_OpTable::TAO_Dynamic_Hash_OpTable ( + TAO_operation_db_entry const * db, + CORBA::ULong dbsize, + CORBA::ULong hashtblsize, + ACE_Allocator *alloc) + : hash_ (hashtblsize, alloc) +{ + // Iterate thru each entry in the database and bind the operation + // name to its corresponding skeleton. + for (CORBA::ULong i = 0; i < dbsize; ++i) + { + TAO::Operation_Skeletons s; + s.skel_ptr = db[i].skel_ptr; + s.thruPOA_skel_ptr = db[i].skel_ptr; + s.direct_skel_ptr = db[i].direct_skel_ptr; + + // @@ (ASG): what happens if bind fails ??? + if (this->bind (db[i].opname, s) == -1) + ACE_ERROR ((LM_ERROR, + ACE_TEXT ("(%P|%t) %p\n"), + ACE_TEXT ("bind failed"))); + } +} + +TAO_Dynamic_Hash_OpTable::~TAO_Dynamic_Hash_OpTable (void) +{ + // Initialize an iterator. We need to go thru each entry and free + // up storage allocated to hold the external ids. In this case, + // these are strings. + OP_MAP_MANAGER::ITERATOR iterator (this->hash_); + + for (OP_MAP_MANAGER::ENTRY *entry = 0; + iterator.next (entry) != 0; + iterator.advance ()) + { + // We had allocated memory and stored the string. So we free the + // memory. + CORBA::string_free ((char *) entry->ext_id_); + entry->ext_id_ = 0; + } +} + +int +TAO_Dynamic_Hash_OpTable::bind (const char *opname, + const TAO::Operation_Skeletons skel_ptr) +{ + return this->hash_.bind (CORBA::string_dup (opname), + skel_ptr); +} + +int +TAO_Dynamic_Hash_OpTable::find (const char *opname, + TAO_Skeleton& skel_ptr, + const unsigned int ) +{ + ACE_FUNCTION_TIMEPROBE (TAO_DYNAMIC_HASH_OPTABLE_FIND_START); + TAO::Operation_Skeletons s; + + int retval = + this->hash_.find ((const char *)opname, + s); + + if (retval != -1) + { + skel_ptr = s.skel_ptr; + } + + return retval; +} + +int +TAO_Dynamic_Hash_OpTable::find (const char *opname, + TAO_Collocated_Skeleton& skel_ptr, + TAO::Collocation_Strategy s, + const unsigned int ) +{ + ACE_FUNCTION_TIMEPROBE (TAO_DYNAMIC_HASH_OPTABLE_FIND_START); + + TAO::Operation_Skeletons skel; + + int retval = + this->hash_.find ((const char *)opname, skel); + + if (retval != -1) + { + switch (s) + { + case TAO::TAO_CS_DIRECT_STRATEGY: + skel_ptr = skel.direct_skel_ptr; + break; + default: + return -1; + } + } + + return retval; +} + +#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION) +template class ACE_Hash_Map_Iterator_Base_Ex, + ACE_Equal_To, + ACE_Null_Mutex>; +template class ACE_Hash_Map_Iterator_Ex, + ACE_Equal_To, + ACE_Null_Mutex>; + +template class ACE_Hash_Map_Reverse_Iterator_Ex, + ACE_Equal_To, + ACE_Null_Mutex>; +template class ACE_Hash_Map_Manager_Ex, + ACE_Equal_To, + ACE_Null_Mutex>; +template class ACE_Hash_Map_Entry; + +#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA) + +#pragma instantiate ACE_Hash_Map_Iterator_Base_Ex, ACE_Equal_To, ACE_Null_Mutex> +#pragma instantiate ACE_Hash_Map_Iterator_Ex, ACE_Equal_To, ACE_Null_Mutex> +#pragma instantiate ACE_Hash_Map_Reverse_Iterator_Ex, ACE_Equal_To, ACE_Null_Mutex> +#pragma instantiate ACE_Hash_Map_Manager_Ex, ACE_Equal_To, ACE_Null_Mutex> +#pragma instantiate ACE_Hash_Map_Entry + +#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */ diff --git a/TAO/tao/PortableServer/Operation_Table_Dynamic_Hash.h b/TAO/tao/PortableServer/Operation_Table_Dynamic_Hash.h new file mode 100644 index 00000000000..a16c3a3acb3 --- /dev/null +++ b/TAO/tao/PortableServer/Operation_Table_Dynamic_Hash.h @@ -0,0 +1,80 @@ +// This may look like C, but it's really -*- C++ -*- + +//============================================================================= +/** + * @file Operation_Table_Dynamic_Hash.h + * + * $Id$ + * + * @author Aniruddha Gokhale + */ +//============================================================================= + +#ifndef TAO_OPERATION_TABLE_DYNAMIC_HASH_H +#define TAO_OPERATION_TABLE_DYNAMIC_HASH_H + +#include /**/ "ace/pre.h" + +#include "portableserver_export.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +#include "Operation_Table.h" +#include "ace/Hash_Map_Manager.h" +#include "ace/Synch_Traits.h" +#include "ace/Null_Mutex.h" + +/** + * @class TAO_Dynamic_Hash_OpTable + * + * @brief Dynamic Hashing scheme for CORBA IDL operation name lookup. + */ +class TAO_PortableServer_Export TAO_Dynamic_Hash_OpTable + : public TAO_Operation_Table +{ +public: + // = Initialization and termination methods. + /** + * Initialize the dynamic hash operation table with a database of + * operation names. The hash table size may be different from the + * size of the database. Hence we use the third argument to specify + * the size of the internal hash table. The argument is + * used to determine where the memory comes from (usually from + * ). + */ + TAO_Dynamic_Hash_OpTable (const TAO_operation_db_entry *db, + CORBA::ULong dbsize, + CORBA::ULong hashtblsize, + ACE_Allocator *alloc); + + /// Destructor + ~TAO_Dynamic_Hash_OpTable (void); + + /// See the documentation in the base class for details. + virtual int bind (const char *opname, + const TAO::Operation_Skeletons skel_ptr); + + virtual int find (const char *opname, + TAO_Skeleton &skelfunc, + const unsigned int length = 0); + + virtual int find (const char *opname, + TAO_Collocated_Skeleton &skelfunc, + TAO::Collocation_Strategy s, + const unsigned int length = 0); +private: + typedef ACE_Hash_Map_Manager_Ex, + ACE_Equal_To, + ACE_Null_Mutex> + OP_MAP_MANAGER; + + /// The hash table data structure. + OP_MAP_MANAGER hash_; +}; + +#include /**/ "ace/post.h" +#endif /* TAO_OPERATION_TABLE_DYNAMIC_HASH_H */ diff --git a/TAO/tao/PortableServer/Operation_Table_Factory.cpp b/TAO/tao/PortableServer/Operation_Table_Factory.cpp new file mode 100644 index 00000000000..458b340e6c8 --- /dev/null +++ b/TAO/tao/PortableServer/Operation_Table_Factory.cpp @@ -0,0 +1,26 @@ +// $Id$ + +#include "Operation_Table_Factory.h" +#include "Operation_Table_Parameters.h" + +ACE_RCSID(PortableServer, + Operation_Table_Factory, + "$Id$") + +TAO_Operation_Table_Factory::TAO_Operation_Table_Factory (void) +{ +} + +TAO_Operation_Table_Factory::~TAO_Operation_Table_Factory (void) +{ +} + +TAO_Operation_Table * +TAO_Operation_Table_Factory::opname_lookup_strategy (void) +{ + TAO_Operation_Table_Parameters * const p = + TAO_OP_TABLE_PARAMETERS::instance (); + + return p->concrete_strategy (); +} + diff --git a/TAO/tao/PortableServer/Operation_Table_Factory.h b/TAO/tao/PortableServer/Operation_Table_Factory.h new file mode 100644 index 00000000000..ea5318fd12c --- /dev/null +++ b/TAO/tao/PortableServer/Operation_Table_Factory.h @@ -0,0 +1,55 @@ +// This may look like C, but it's really -*- C++ -*- + +//============================================================================= +/** + * @file Operation_Table_Factory.h + * + * $Id$ + * + * @author Aniruddha Gokhale + */ +//============================================================================= + +#ifndef TAO_OPERATION_TABLE_FACTORY_H +#define TAO_OPERATION_TABLE_FACTORY_H + +#include /**/ "ace/pre.h" + +#include "portableserver_export.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +#include "tao/TAO_Singleton.h" +#include "ace/Synch_Traits.h" +#include "ace/Null_Mutex.h" + +class TAO_Operation_Table; + +/** + * @class TAO_Operation_Table_Factory + * + * @brief Factory for producing operation table lookup objects based on + * the enumerated value of strategy held by the parameters. + */ +class TAO_PortableServer_Export TAO_Operation_Table_Factory +{ +public: + /// Return an instance of the specified lookup strategy + TAO_Operation_Table *opname_lookup_strategy (void); + + /// Constructor + TAO_Operation_Table_Factory (void); + + /// Destructor + ~TAO_Operation_Table_Factory (void); +}; + +/// Define a singleton instance of the operation table factory. +typedef TAO_Singleton + TAO_OP_TABLE_FACTORY; + +#include /**/ "ace/post.h" +#endif /* TAO_OPERATION_TABLE_FACTORY_H */ diff --git a/TAO/tao/PortableServer/Operation_Table_Linear_Search.cpp b/TAO/tao/PortableServer/Operation_Table_Linear_Search.cpp new file mode 100644 index 00000000000..277f0f35269 --- /dev/null +++ b/TAO/tao/PortableServer/Operation_Table_Linear_Search.cpp @@ -0,0 +1,95 @@ +// $Id$ + +#include "Operation_Table_Linear_Search.h" +#include "tao/Timeprobe.h" +#include "ace/Log_Msg.h" + +ACE_RCSID(PortableServer, + Operation_Table_Linear_Searc, + "$Id$") + +#if defined (ACE_ENABLE_TIMEPROBES) + +static const char *TAO_Operation_Table_Timeprobe_Description[] = + { + "TAO_Linear_Search_OpTable::find - start", + "TAO_Linear_Search_OpTable::find - end", + }; + +enum + { + // Timeprobe description table start key + TAO_LINEAR_SEARCH_OPTABLE_FIND_START = 602, + TAO_LINEAR_SEARCH_OPTABLE_FIND_END, + }; + +// Setup Timeprobes +ACE_TIMEPROBE_EVENT_DESCRIPTIONS (TAO_Operation_Table_Timeprobe_Description, + TAO_LINEAR_SEARCH_OPTABLE_FIND_START); + +#endif /* ACE_ENABLE_TIMEPROBES */ + +/***************************************************************/ + +TAO_Linear_Search_OpTable::TAO_Linear_Search_OpTable (void) +{ +} + +TAO_Linear_Search_OpTable::~TAO_Linear_Search_OpTable (void) +{ +} + +int +TAO_Linear_Search_OpTable::bind (const char *, + const TAO::Operation_Skeletons ) +{ + return 0; +} + +int +TAO_Linear_Search_OpTable::find (const char *opname, + TAO_Skeleton& skelfunc, + const unsigned int ) +{ + ACE_FUNCTION_TIMEPROBE (TAO_LINEAR_SEARCH_OPTABLE_FIND_START); + + TAO_operation_db_entry const * const entry = lookup (opname); + if (entry == 0) + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT ("TAO_Linear_Search_Table:find failed\n")), + -1); + + // Valid entry. Figure out the skel_ptr. + skelfunc = entry->skel_ptr; + + return 0; +} + + +int +TAO_Linear_Search_OpTable::find (const char *opname, + TAO_Collocated_Skeleton &skelfunc, + TAO::Collocation_Strategy st, + const unsigned int ) +{ + ACE_FUNCTION_TIMEPROBE (TAO_LINEAR_SEARCH_OPTABLE_FIND_START); + + TAO_operation_db_entry const * const entry = lookup (opname); + if (entry == 0) + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT ("TAO_Linear_Search_Table:find failed\n")), + -1); + + switch (st) + { + case TAO::TAO_CS_DIRECT_STRATEGY: + skelfunc = entry->direct_skel_ptr; + break; + default: + return -1; + } + + return 0; +} + + diff --git a/TAO/tao/PortableServer/Operation_Table_Linear_Search.h b/TAO/tao/PortableServer/Operation_Table_Linear_Search.h new file mode 100644 index 00000000000..f2055d753d3 --- /dev/null +++ b/TAO/tao/PortableServer/Operation_Table_Linear_Search.h @@ -0,0 +1,63 @@ +// This may look like C, but it's really -*- C++ -*- + +//============================================================================= +/** + * @file Operation_Table_Linear_Search.h + * + * $Id$ + * + * @author Aniruddha Gokhale + */ +//============================================================================= + +#ifndef TAO_OPERATION_TABLE_LINEAR_SEARCH_H +#define TAO_OPERATION_TABLE_LINEAR_SEARCH_H + +#include /**/ "ace/pre.h" + +#include "portableserver_export.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +#include "Operation_Table.h" + +/** + * @class TAO_Linear_Search_OpTable + * + * @brief Operation table lookup strategy based on + * linear search. Not efficient, but it works. + */ +class TAO_PortableServer_Export TAO_Linear_Search_OpTable + : public TAO_Operation_Table +{ +public: + // = Initialization and termination methods. + /// Default constructor. + TAO_Linear_Search_OpTable (void); + + /// Destructor. + ~TAO_Linear_Search_OpTable (void); + + /// See the documentation in the base class for details. + virtual int find (const char *opname, + TAO_Skeleton &skel_ptr, + const unsigned int length = 0); + + virtual int find (const char *opname, + TAO_Collocated_Skeleton &skelfunc, + TAO::Collocation_Strategy s, + const unsigned int length = 0); + + virtual int bind (const char *opname, + const TAO::Operation_Skeletons skelptr); + +private: + // = Method that should defined by the subclasses. GPERF program + // will generate this routine routines. + virtual const TAO_operation_db_entry* lookup (const char *str) = 0; +}; + +#include /**/ "ace/post.h" +#endif /* TAO_OPERATION_TABLE_LINEAR_SEARCH_H */ diff --git a/TAO/tao/PortableServer/Operation_Table_Parameters.cpp b/TAO/tao/PortableServer/Operation_Table_Parameters.cpp new file mode 100644 index 00000000000..e5de37859f6 --- /dev/null +++ b/TAO/tao/PortableServer/Operation_Table_Parameters.cpp @@ -0,0 +1,58 @@ +// $Id$ + +#include "Operation_Table_Parameters.h" + +ACE_RCSID(PortableServer, + Operation_Table_Parameters, + "$Id$") + +TAO_Operation_Table_Parameters::TAO_Operation_Table_Parameters (void) + : strategy_ (0), + type_ (TAO_Operation_Table_Parameters::TAO_DYNAMIC_HASH) // default +{ +} + +TAO_Operation_Table_Parameters::~TAO_Operation_Table_Parameters (void) +{ +} + +void +TAO_Operation_Table_Parameters::lookup_strategy (TAO_Operation_Table_Parameters::DEMUX_STRATEGY s) +{ + this->type_ = s; +} + +// get the lookup type +TAO_Operation_Table_Parameters::DEMUX_STRATEGY +TAO_Operation_Table_Parameters::lookup_strategy (void) const +{ + return this->type_; +} + +// set the concrete strategy +void +TAO_Operation_Table_Parameters::concrete_strategy (TAO_Operation_Table *ot) +{ + this->strategy_ = ot; +} + +// return the concrete strategy +TAO_Operation_Table* +TAO_Operation_Table_Parameters::concrete_strategy (void) +{ + return this->strategy_; +} + +#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION) +template class TAO_Singleton; + +#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA) + +#pragma instantiate TAO_Singleton + +#elif defined (ACE_HAS_EXPLICIT_STATIC_TEMPLATE_MEMBER_INSTANTIATION) + +template TAO_Singleton* TAO_Singleton::singleton_; + +#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */ diff --git a/TAO/tao/PortableServer/Operation_Table_Parameters.h b/TAO/tao/PortableServer/Operation_Table_Parameters.h new file mode 100644 index 00000000000..f575ea2f18f --- /dev/null +++ b/TAO/tao/PortableServer/Operation_Table_Parameters.h @@ -0,0 +1,82 @@ +// This may look like C, but it's really -*- C++ -*- + +//============================================================================= +/** + * @file Operation_Table_Parameters.h + * + * $Id$ + * + * @author Aniruddha Gokhale + */ +//============================================================================= + +#ifndef TAO_OPERATION_TABLE_PARAMETERS_H +#define TAO_OPERATION_TABLE_PARAMETERS_H + +#include /**/ "ace/pre.h" + +#include "portableserver_export.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +class TAO_Operation_Table; + +#include "tao/TAO_Singleton.h" +#include "ace/Synch_Traits.h" +#include "ace/Null_Mutex.h" + +/** + * @class TAO_Operation_Table_Parameters + * + * @brief Parameters used to create the operation table. + */ +class TAO_PortableServer_Export TAO_Operation_Table_Parameters +{ +public: + /// various lookup strategies + enum DEMUX_STRATEGY + { + TAO_LINEAR_SEARCH, + TAO_DYNAMIC_HASH, + TAO_PERFECT_HASH, + TAO_BINARY_SEARCH, + TAO_ACTIVE_DEMUX, + TAO_USER_DEFINED + }; + + /// Set the lookup strategy from the list of enumerated values + void lookup_strategy (DEMUX_STRATEGY s); + + /// Return the enumerated value for the lookup strategy. Default is + /// Dynamic Hashing. + DEMUX_STRATEGY lookup_strategy (void) const; + + /// Provide a data structure that will do the lookup. This is useful + /// for user-defined lookup strategies. + void concrete_strategy (TAO_Operation_Table *ot); + + /// Return the operation table that is being used to do the lookup. + TAO_Operation_Table *concrete_strategy (void); + + /// Constructor. + TAO_Operation_Table_Parameters (void); + + /// Destructor + ~TAO_Operation_Table_Parameters (void); +private: + /// Pointer to the object that implements a lookup strategy + TAO_Operation_Table *strategy_; + + /// The enumerated value indicating the lookup strategy + DEMUX_STRATEGY type_; +}; + +/// Define a singleton instance of operation table parameters. +typedef TAO_Singleton + TAO_OP_TABLE_PARAMETERS; + +#include /**/ "ace/post.h" +#endif /* TAO_OPERATION_TABLE_PARAMETERS_H */ diff --git a/TAO/tao/PortableServer/Operation_Table_Perfect_Hash.cpp b/TAO/tao/PortableServer/Operation_Table_Perfect_Hash.cpp new file mode 100644 index 00000000000..ae294a0297a --- /dev/null +++ b/TAO/tao/PortableServer/Operation_Table_Perfect_Hash.cpp @@ -0,0 +1,105 @@ +// $Id$ + +#include "Operation_Table_Perfect_Hash.h" +#include "tao/Timeprobe.h" +#include "ace/Log_Msg.h" + +ACE_RCSID(PortableServer, + Operation_Table_Perfect_Hash, + "$Id$") + +#if defined (ACE_ENABLE_TIMEPROBES) + +static const char *TAO_Operation_Table_Timeprobe_Description[] = + { + "TAO_Perfect_Hash_OpTable::find - start", + "TAO_Perfect_Hash_OpTable::find - end", + }; + +enum + { + // Timeprobe description table start key + TAO_PERFECT_HASH_OPTABLE_FIND_START = 606, + TAO_PERFECT_HASH_OPTABLE_FIND_END, + }; + +// Setup Timeprobes +ACE_TIMEPROBE_EVENT_DESCRIPTIONS (TAO_Operation_Table_Timeprobe_Description, + TAO_PERFECT_HASH_OPTABLE_FIND_START); + +#endif /* ACE_ENABLE_TIMEPROBES */ + +// Do nothing constructor. +TAO_Perfect_Hash_OpTable::TAO_Perfect_Hash_OpTable (void) +{ +} + +// Do nothing destrctor. +TAO_Perfect_Hash_OpTable::~TAO_Perfect_Hash_OpTable (void) +{ +} + +int +TAO_Perfect_Hash_OpTable::find (const char *opname, + TAO_Skeleton &skelfunc, + const unsigned int length) +{ + ACE_FUNCTION_TIMEPROBE (TAO_PERFECT_HASH_OPTABLE_FIND_START); + + TAO_operation_db_entry const * const entry = lookup (opname, + length); + if (entry == 0) + { + skelfunc = 0; // insure that somebody can't call a wrong function! + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT ("TAO_Perfect_Hash_OpTable:find for ") + ACE_TEXT ("operation '%s' (length=%d) failed\n"), + ACE_TEXT_CHAR_TO_TCHAR (opname ? opname : ""), length), + -1); + } + + // Valid entry. Figure out the skel_ptr. + skelfunc = entry->skel_ptr; + + return 0; +} + +int +TAO_Perfect_Hash_OpTable::find (const char *opname, + TAO_Collocated_Skeleton &skelfunc, + TAO::Collocation_Strategy st, + const unsigned int length) +{ + ACE_FUNCTION_TIMEPROBE (TAO_PERFECT_HASH_OPTABLE_FIND_START); + + TAO_operation_db_entry const * const entry = lookup (opname, + length); + if (entry == 0) + { + skelfunc = 0; // insure that somebody can't call a wrong function! + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT ("TAO_Perfect_Hash_OpTable:find for ") + ACE_TEXT ("operation '%s' (length=%d) failed\n"), + ACE_TEXT_CHAR_TO_TCHAR (opname ? opname : ""), length), + -1); + } + + switch (st) + { + case TAO::TAO_CS_DIRECT_STRATEGY: + skelfunc = entry->direct_skel_ptr; + break; + default: + return -1; + } + + return 0; +} + +int +TAO_Perfect_Hash_OpTable::bind (const char *, + const TAO::Operation_Skeletons) +{ + return 0; +} + diff --git a/TAO/tao/PortableServer/Operation_Table_Perfect_Hash.h b/TAO/tao/PortableServer/Operation_Table_Perfect_Hash.h new file mode 100644 index 00000000000..5c60c7ad69f --- /dev/null +++ b/TAO/tao/PortableServer/Operation_Table_Perfect_Hash.h @@ -0,0 +1,73 @@ +// This may look like C, but it's really -*- C++ -*- + +//============================================================================= +/** + * @file Operation_Table_Perfect_Hash.h + * + * $Id$ + * + * @author Aniruddha Gokhale + */ +//============================================================================= + +#ifndef TAO_OPERATION_TABLE_PERFECT_HASH_H +#define TAO_OPERATION_TABLE_PERFECT_HASH_H + +#include /**/ "ace/pre.h" + +#include "portableserver_export.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +#include "Operation_Table.h" + +/** + * @class TAO_Perfect_Hash_OpTable + * + * @brief Helper class for use of perfect hashing operation lookup + * strategy. + * + * This class declares pure virtual methods called 'lookup ()' + * and 'hash ()' which will be generated by the GPERF + * program. These methods are used by 'bind ()' and 'find ()' + * methods. Subclasses will define the lookup and hash + * functions. + */ +class TAO_PortableServer_Export TAO_Perfect_Hash_OpTable + : public TAO_Operation_Table +{ +public: + /// Do nothing constructor. + TAO_Perfect_Hash_OpTable (void); + + /// Do nothing destrctor. + virtual ~TAO_Perfect_Hash_OpTable (void); + + /// See the documentation in the base class for details. + virtual int find (const char *opname, + TAO_Skeleton &skelfunc, + const unsigned int length = 0); + + virtual int find (const char *opname, + TAO_Collocated_Skeleton &skelfunc, + TAO::Collocation_Strategy s, + const unsigned int length = 0); + + virtual int bind (const char *opname, + const TAO::Operation_Skeletons skel_ptr); + +private: + // = Methods that should defined by the subclasses. GPERF program + // will generate these routines. + + virtual unsigned int hash (const char *str, unsigned int len) = 0; + + virtual const TAO_operation_db_entry* lookup (const char *str, + unsigned int len) = 0; +}; + + +#include /**/ "ace/post.h" +#endif /* TAO_OPERATION_TABLE_PERFECT_HASH_H */ -- cgit v1.2.1