diff options
author | Phil Mesnier <mesnier_p@ociweb.com> | 2005-07-13 22:15:31 +0000 |
---|---|---|
committer | Phil Mesnier <mesnier_p@ociweb.com> | 2005-07-13 22:15:31 +0000 |
commit | b75199c59154ceafdbf3d5e2b1279d73783c05bb (patch) | |
tree | 0180a382b2de6c08a2ce533295772efc03876222 /TAO/tao | |
parent | d902bd85103074e3fa0e37f91a1b4a12f3c47840 (diff) | |
download | ATCD-b75199c59154ceafdbf3d5e2b1279d73783c05bb.tar.gz |
ChangeLog tag: Wed Jul 13 16:37:41 2005 Phil Mesnier <mesnier_p@ociweb.com>
Diffstat (limited to 'TAO/tao')
40 files changed, 2002 insertions, 1003 deletions
diff --git a/TAO/tao/Codeset.mpc b/TAO/tao/Codeset.mpc new file mode 100644 index 00000000000..76a03c004e0 --- /dev/null +++ b/TAO/tao/Codeset.mpc @@ -0,0 +1,23 @@ +//$Id$ +project : taolib, core { + sharedname = TAO_Codeset + dynamicflags = TAO_CODESET_BUILD_DLL + pch_header = + pch_source = + + Source_Files { + Codeset + } + + Header_Files { + Codeset + } + + Inline_Files { + Codeset + } + + Template_Files { + Codeset + } +} diff --git a/TAO/tao/Codeset/Codeset_Manager_i.cpp b/TAO/tao/Codeset/Codeset_Manager_i.cpp new file mode 100644 index 00000000000..cbae78d9245 --- /dev/null +++ b/TAO/tao/Codeset/Codeset_Manager_i.cpp @@ -0,0 +1,646 @@ +// $Id$ + +#include "tao/TAO_Server_Request.h" +#include "tao/operation_details.h" +#include "tao/Transport.h" +#include "tao/Profile.h" +#include "tao/SystemException.h" +#include "tao/debug.h" +#include "tao/CDR.h" +#include "tao/ORB_Core.h" +#include "tao/Resource_Factory.h" + +#include "Codeset_Manager_i.h" +#include "Codeset_Translator_Factory.h" + +#include "ace/Dynamic_Service.h" +#include "ace/Codeset_Registry.h" +#include "ace/OS_NS_string.h" +#include "ace/Service_Config.h" + +ACE_RCSID (tao, + Codeset_Manager_i, + "$Id$") + + +// These numbers are assigned by the OpenGroup, a database is +// available at +// +// ftp://ftp.opengroup.org/pub/code_set_registry/ +// +#define TAO_CODESET_ID_ISO8859_1 0x00010001U +#define TAO_CODESET_ID_UNICODE 0x00010109U +#define TAO_CODESET_ID_XOPEN_UTF_8 0x05010001U + +// These are the default codesets that TAO declares, of course they +// will be different on each platform, once the complete support for +// character sets is implemented + +#if (defined TAO_DEFAULT_CHAR_CODESET_ID) +# undef TAO_DEFAULT_CHAR_CODESET_ID +#endif /* defined TAO_DEFAULT_CHAR_CODESET_ID */ + +#if (defined TAO_DEFAULT_WCHAR_CODESET_ID) +# undef TAO_DEFAULT_WCHAR_CODESET_ID +#endif /* defined TAO_DEFAULT_WCHAR_CODESET_ID */ + +//#define TAO_DEFAULT_CHAR_CODESET_ID TAO_CODESET_ID_XOPEN_UTF_8 +#define TAO_DEFAULT_CHAR_CODESET_ID TAO_CODESET_ID_ISO8859_1 +#define TAO_DEFAULT_WCHAR_CODESET_ID TAO_CODESET_ID_UNICODE + +// **************************************************************** + +/// NCS for char is defaulted to ISO 8859-1:1987; Latin Alphabet No. 1 +CONV_FRAME::CodeSetId +TAO_Codeset_Manager_i::default_char_codeset = TAO_DEFAULT_CHAR_CODESET_ID; +/// NCS for wchar is not defaulted by the CORBA specification, but a default +/// may be set here if desired +CONV_FRAME::CodeSetId +TAO_Codeset_Manager_i::default_wchar_codeset = TAO_DEFAULT_WCHAR_CODESET_ID; + +TAO_Codeset_Manager_i::TAO_Codeset_Manager_i () + : codeset_info_ (), + char_factories_ (), + wchar_factories_ () +{ + this->codeset_info_.ForCharData.native_code_set = + TAO_Codeset_Manager_i::default_char_codeset; + this->codeset_info_.ForWcharData.native_code_set = + TAO_Codeset_Manager_i::default_wchar_codeset; + + this->add_char_translator ("UTF8_Latin1_Factory"); + this->add_wchar_translator ("UTF16_BOM_Factory"); +} + +TAO_Codeset_Manager_i::~TAO_Codeset_Manager_i () +{ + // Cleanup the character map + TAO_CodesetFactorySetItor cf_end = this->char_factories_.end (); + TAO_CodesetFactorySetItor cf_iter = this->char_factories_.begin (); + + for (; cf_iter != cf_end; ++cf_iter) + { + delete *cf_iter; + } + + this->char_factories_.reset (); + + // Cleanup the wide character map + cf_end = this->wchar_factories_.end (); + cf_iter = this->wchar_factories_.begin (); + + for (;cf_iter != cf_end; ++cf_iter) + { + delete *cf_iter; + } + + this->wchar_factories_.reset (); +} + +void +TAO_Codeset_Manager_i::set_codeset (TAO_Tagged_Components& tc) const +{ + tc.set_code_sets (this->codeset_info_); +} + +void +TAO_Codeset_Manager_i::set_tcs (TAO_Profile &theProfile, + TAO_Transport &trans) +{ + /// If tcs is already set on the transport then donot process, + /// use existing transport as CDR have translators set. + TAO_Tagged_Components& theTaggedComp = theProfile.tagged_components (); + + CONV_FRAME::CodeSetComponentInfo remote; + + /// Get the codeset component + if (theTaggedComp.get_code_sets(remote) == 0 ) + { + if (trans.is_tcs_set ()) + { + if(TAO_debug_level > 2) + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("TAO (%P|%t) - Codeset_Manager_i::set_tcs, ") + ACE_TEXT ("transport already set\n"))); + return; + } + if (TAO_debug_level > 2) + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("TAO (%P|%t) - Codeset_Manager_i::set_tcs, ") + ACE_TEXT ("No codeset component in profile\n"))); + + // These are the "fallback" codeset ids for use if no context is + // available + remote.ForCharData.native_code_set = + TAO_CODESET_ID_XOPEN_UTF_8; + remote.ForWcharData.native_code_set = + TAO_CODESET_ID_UNICODE; + + trans.char_translator + (this->get_char_trans + (TAO_Codeset_Manager_i::default_char_codeset)); + trans.wchar_translator + (this->get_wchar_trans + (TAO_Codeset_Manager_i::default_wchar_codeset)); + } + else + { + CONV_FRAME::CodeSetId tcs = + computeTCS (remote.ForCharData, + this->codeset_info_.ForCharData); + if (TAO_debug_level > 2) + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT("TAO (%P|%t) - Codeset_Manager_i::set_tcs, ") + ACE_TEXT("setting char translator (%08x)\n"), + tcs)); + trans.char_translator(this->get_char_trans (tcs)); + + tcs = computeTCS (remote.ForWcharData, + this->codeset_info_.ForWcharData); + + if (TAO_debug_level > 2) + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT("TAO (%P|%t) - Codeset_Manager_i::set_tcs, ") + ACE_TEXT("setting wchar translator (%08x)\n"), + tcs)); + trans.wchar_translator(this->get_wchar_trans (tcs)); + } +} + +void +TAO_Codeset_Manager_i::process_service_context (TAO_ServerRequest &request) +{ + // Get the service Context from an object of TAO_ServerRequest + // and set the TCS values on the Transport + TAO_Service_Context &service_cntx = request.request_service_context (); + IOP::ServiceContext context; + context.context_id = IOP::CodeSets; + + // These are the "fallback" codeset ids for use if no context is + // available + CONV_FRAME::CodeSetId tcs_c = TAO_CODESET_ID_XOPEN_UTF_8; + CONV_FRAME::CodeSetId tcs_w = TAO_CODESET_ID_UNICODE; + + if (service_cntx.get_context(context)) + { + // Convert the Service Context to Codeset Context + const char *buffer = + reinterpret_cast<const char*> (context.context_data.get_buffer ()); + + TAO_InputCDR cdr (buffer,context.context_data.length ()); + CORBA::Boolean byte_order; + + if (cdr >> TAO_InputCDR::to_boolean (byte_order)) + { + cdr.reset_byte_order (static_cast<int> (byte_order)); + cdr >> tcs_c; + cdr >> tcs_w; + } + } + else + { + if (request.transport()->is_tcs_set()) + return; + if (TAO_debug_level > 0) + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT("TAO (%P|%t) - Codeset_Manager_i::process_service_context ") + ACE_TEXT("no codeset context in request, inferring TAO backwards compatibility\n"))); + } + if (TAO_debug_level > 2) + { + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("TAO (%P|%t) - Codeset_Manager_i::") + ACE_TEXT ("process_service_context, ") + ACE_TEXT ("using tcsc = %08x, tcsw = %08x\n"), + tcs_c,tcs_w)); + } + + request.transport()->char_translator(this->get_char_trans (tcs_c)); + request.transport()->wchar_translator(this->get_wchar_trans (tcs_w)); +} + +void +TAO_Codeset_Manager_i::generate_service_context (TAO_Operation_Details &opd, + TAO_Transport &trans) +{ + TAO_Service_Context &service_cntx = opd.request_service_context (); + CONV_FRAME::CodeSetContext codeset_cntx; + + // Generating codeset context + // Assuming the TCS values from Transport will be defaulted + TAO_Codeset_Translator_Factory *tf = + ACE_dynamic_cast(TAO_Codeset_Translator_Factory*, + trans.char_translator ()); + + codeset_cntx.char_data = + tf ? tf->tcs () : this->codeset_info_.ForCharData.native_code_set; + + tf = ACE_dynamic_cast(TAO_Codeset_Translator_Factory*, + trans.wchar_translator ()); + + codeset_cntx.wchar_data = + tf ? tf->tcs () : this->codeset_info_.ForWcharData.native_code_set; + + if (TAO_debug_level > 2) + { + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("TAO (%P|%t) - Codeset_Manager_i::") + ACE_TEXT ("generate_service_context, ") + ACE_TEXT ("using tcs_c = %08x, tcs_w = %08x\n"), + codeset_cntx.char_data, + codeset_cntx.wchar_data)); + } + + TAO_OutputCDR codeset_cdr; + codeset_cdr << TAO_OutputCDR::from_boolean (TAO_ENCAP_BYTE_ORDER); + codeset_cdr << codeset_cntx; + + service_cntx.set_context (IOP::CodeSets,codeset_cdr); +} + +/// Checks whether the NCS is a part of CCS +int +TAO_Codeset_Manager_i::isElementOf (CONV_FRAME::CodeSetId id, + CONV_FRAME::CodeSetComponent &cs_comp) +{ + for (CORBA::ULong i = 0L; + i < cs_comp.conversion_code_sets.length (); + ++i ) + { + if (id == cs_comp.conversion_code_sets[i]) + return 1; + } + + return 0; +} + +/// Find the Intersection of Client and Server CCS's +CONV_FRAME::CodeSetId +TAO_Codeset_Manager_i::intersectionOf (CONV_FRAME::CodeSetComponent &cs_comp1, + CONV_FRAME::CodeSetComponent &cs_comp2) +{ + for(CORBA::ULong index = 0L; + index < cs_comp1.conversion_code_sets.length(); + ++index ) + { + if (this->isElementOf(cs_comp1.conversion_code_sets[index], cs_comp2)) + { + return cs_comp1.conversion_code_sets[index]; + } + } + + return 0; +} + +int +TAO_Codeset_Manager_i::isCompatible(CONV_FRAME::CodeSetId cs1, + CONV_FRAME::CodeSetId cs2 ) +{ + // Call the is_compatible method of ACE_Codeset_Registry + return ACE_Codeset_Registry::is_compatible(cs1,cs2); +} + +/// returns the TCS for Char / Wchar +CONV_FRAME::CodeSetId +TAO_Codeset_Manager_i::computeTCS (CONV_FRAME::CodeSetComponent &remote, + CONV_FRAME::CodeSetComponent &local ) +{ + if (remote.native_code_set == local.native_code_set) + { + return local.native_code_set; + } + + if (this->isElementOf (remote.native_code_set, local)) + { + return remote.native_code_set; + } + + if (this->isElementOf (local.native_code_set, remote)) + { + return local.native_code_set; + } + + CONV_FRAME::CodeSetId tcs; + + if ((tcs = this->intersectionOf (remote, local)) == 0) + { + if (isCompatible (local.native_code_set, remote.native_code_set)) + { + return remote.native_code_set; + } + else + { + ACE_DECLARE_NEW_CORBA_ENV; + ACE_THROW_RETURN(CORBA::CODESET_INCOMPATIBLE (), 0); + } + } + + return tcs; +} + +void +TAO_Codeset_Manager_i::set_ncs_c (CONV_FRAME::CodeSetId ncs) +{ + this->codeset_info_.ForCharData.native_code_set = ncs; +} + +void +TAO_Codeset_Manager_i::set_ncs_w (CONV_FRAME::CodeSetId ncs,int mb) +{ + this->codeset_info_.ForWcharData.native_code_set = ncs; + ACE_OutputCDR::wchar_maxbytes(mb); +} + +int +TAO_Codeset_Manager_i::add_char_translator (const char *name) +{ + TAO_Codeset_Item *item = 0; + ACE_NEW_RETURN (item, TAO_Codeset_Item (name), -1); + + if (this->char_factories_.insert (item) == -1) + { + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT ("TAO (%P|%t) - Codeset_Manager_i::") + ACE_TEXT ("add_char_translator, ") + ACE_TEXT ("Unable to add Codeset ") + ACE_TEXT ("factories for %s: %m\n"), + ACE_TEXT_CHAR_TO_TCHAR (name)), + -1); + } + + return 0; +} + +int +TAO_Codeset_Manager_i::add_wchar_translator (const char *name) +{ + TAO_Codeset_Item *item = 0; + ACE_NEW_RETURN (item, TAO_Codeset_Item (name), -1); + + if (this->wchar_factories_.insert (item) == -1) + { + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT ("TAO (%P|%t) - Codeset_Manager_i::") + ACE_TEXT ("add_wchar_translator, ") + ACE_TEXT ("Unable to add Codeset ") + ACE_TEXT ("factories for %s: %m\n"), + ACE_TEXT_CHAR_TO_TCHAR (name)), + -1); + } + + return 0; +} + +void +TAO_Codeset_Manager_i::open(void) +{ + // These translators help comply with the CORBA 3.0.2 specifcation + TAO_Codeset_Translator_Factory *fact = + ACE_Dynamic_Service<TAO_Codeset_Translator_Factory>:: + instance ("UTF8_Latin1_Factory"); + if (fact == 0) + ACE_Service_Config::process_directive + (ACE_DYNAMIC_SERVICE_DIRECTIVE ("UTF8_Latin1_Factory", + "TAO_Codeset", + "_make_TAO_UTF8_Latin1_Factory", + "")); + else + { + if (TAO_debug_level > 2) + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT("TAO (%P|%t) - Codeset_Manager_i::open skipping ") + ACE_TEXT("redundant load of UTF8_Latin1_Factory\n") + )); + } + + fact = ACE_Dynamic_Service<TAO_Codeset_Translator_Factory>:: + instance ("UTF16_BOM_Factory"); + if (fact == 0) + ACE_Service_Config::process_directive + (ACE_DYNAMIC_SERVICE_DIRECTIVE ("UTF16_BOM_Factory", + "TAO_Codeset", + "_make_TAO_UTF16_BOM_Factory", + "")); + else + { + if (TAO_debug_level > 2) + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT("TAO (%P|%t) - Codeset_Manager_i::open skipping ") + ACE_TEXT("redundant load of UTF16_BOM_Factory\n") + )); + } + + if (init_codeset_factories_i (this->char_factories_, + this->codeset_info_.ForCharData) == -1) + { + if (TAO_debug_level) + ACE_ERROR ((LM_ERROR, + ACE_TEXT ("TAO (%P|%t) - Codeset_Manager_i::") + ACE_TEXT ("configure_codeset_factories, failed to init ") + ACE_TEXT ("char codeset factories\n"))); + } + + if (init_codeset_factories_i (this->wchar_factories_, + this->codeset_info_.ForWcharData) == -1) + { + if (TAO_debug_level) + ACE_ERROR ((LM_ERROR, + ACE_TEXT ("TAO (%P|%t) - Codeset_Manager_i::") + ACE_TEXT ("configure_codeset_factories, failed to init ") + ACE_TEXT ("wchar codeset factories\n"))); + } + + if (this->codeset_info_.ForWcharData.native_code_set == 0) + { + ACE_OutputCDR::wchar_maxbytes(0); // disallow wchar when no ncs_w set + } +} + +/// Initialise the specific type codeset factories +int +TAO_Codeset_Manager_i::init_codeset_factories_i ( + TAO_CodesetFactorySet& factset, + CONV_FRAME::CodeSetComponent& cs_comp + ) +{ + TAO_CodesetFactorySetItor end = factset.end (); + TAO_CodesetFactorySetItor iter = factset.begin (); + + CONV_FRAME::CodeSetId ncs = cs_comp.native_code_set; + cs_comp.conversion_code_sets.length ( + static_cast<CORBA::ULong> (factset.size())); + CORBA::ULong index; + + for (index = 0; iter != end; ++iter) + { + const char *name = (*iter)->codeset_name (); + TAO_Codeset_Translator_Factory *fact = + ACE_Dynamic_Service<TAO_Codeset_Translator_Factory>::instance (name); + + if (fact == 0) + { + if (TAO_debug_level) + ACE_ERROR ((LM_ERROR, + ACE_TEXT ("TAO (%P|%t) - Codeset_Manager_i::") + ACE_TEXT ("init_codeset_factories_i, Unable to load ") + ACE_TEXT ("CodeSet <%s>, %m\n"), + ACE_TEXT_CHAR_TO_TCHAR(name))); + continue; + } + + if (fact->ncs() == ncs) + { + (*iter)->factory (fact); + cs_comp.conversion_code_sets[index++] = fact->tcs(); + + if (TAO_debug_level > 2) + { + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("TAO (%P|%t) - Codeset_Manager_i::") + ACE_TEXT ("init_codeset_factories_i, Loaded Codeset ") + ACE_TEXT ("<%s>, ncs = %08x tcs = %08x\n"), + ACE_TEXT_CHAR_TO_TCHAR(name), + fact->ncs(),fact->tcs())); + } + } + } + + cs_comp.conversion_code_sets.length(index); + return 0; +} + + +TAO_Codeset_Translator_Base * +TAO_Codeset_Manager_i::get_char_trans (CONV_FRAME::CodeSetId tcs) +{ + if (this->codeset_info_.ForCharData.native_code_set == tcs) + return 0; + return this->get_translator_i (this->char_factories_,tcs); +} + +TAO_Codeset_Translator_Base * +TAO_Codeset_Manager_i::get_wchar_trans (CONV_FRAME::CodeSetId tcs) +{ + if (tcs == this->codeset_info_.ForWcharData.native_code_set && + tcs != ACE_CODESET_ID_ISO_UTF_16) + return 0; + return this->get_translator_i (this->wchar_factories_,tcs); +} + +TAO_Codeset_Translator_Base * +TAO_Codeset_Manager_i::get_translator_i (TAO_CodesetFactorySet& factset, + CONV_FRAME::CodeSetId tcs) +{ + const TAO_CodesetFactorySetItor end = factset.end (); + + for (TAO_CodesetFactorySetItor iter = factset.begin (); iter != end; ++iter) + { + TAO_Codeset_Translator_Factory *fact = (*iter)->factory (); + + if (fact && tcs == fact->tcs ()) + { + return fact; + } + } + + return 0; +} + + +//--------------------------------------------------------------------- +// Codeset Item +TAO_Codeset_Item::TAO_Codeset_Item (const char *name) + : name_ (0), + factory_ (0) +{ + if (name) + { + name_ = ACE_OS::strdup(name); + } +} + +TAO_Codeset_Item::~TAO_Codeset_Item (void) +{ + ACE_OS::free (this->name_); +} + +const char * +TAO_Codeset_Item::codeset_name (void) +{ + return this->name_; +} + +TAO_Codeset_Translator_Factory * +TAO_Codeset_Item::factory (void) +{ + return this->factory_; +} + +void +TAO_Codeset_Item::factory (TAO_Codeset_Translator_Factory *factory) +{ + this->factory_ = factory; +} + +// End of Codeset Item Class + +TAO_Codeset_Manager_Factory::~TAO_Codeset_Manager_Factory () +{ +} + +TAO_Codeset_Manager * +TAO_Codeset_Manager_Factory::create (TAO_ORB_Core *oc) +{ + TAO_Codeset_Manager_i *csm = 0; + ACE_NEW_RETURN (csm, TAO_Codeset_Manager_i, 0); + + const TAO_Codeset_Descriptor *cd = + oc->resource_factory()->get_codeset_descriptor(0); // char + if (cd->ncs_set()) + csm->set_ncs_c(cd->ncs()); + const TAO_Codeset_Descriptor::Translator_Node *tlist = + cd->translators(); + while (tlist != 0) + { + csm->add_char_translator (tlist->name_); + tlist = tlist->next_; + } + + cd = oc->resource_factory()->get_codeset_descriptor(1); // wchar + if (cd->ncs_set()) + csm->set_ncs_w(cd->ncs(), cd->max_bytes()); + tlist = cd->translators(); + while (tlist != 0) + { + csm->add_wchar_translator (tlist->name_); + tlist = tlist->next_; + } + + return csm; +} + +ACE_FACTORY_DEFINE (TAO_Codeset, TAO_Codeset_Manager_Factory) +ACE_STATIC_SVC_DEFINE (TAO_Table_Adapter_Factory, + ACE_TEXT ("TAO_Codeset"), + ACE_SVC_OBJ_T, + &ACE_SVC_NAME (TAO_Codeset_Manager_Factory), + ACE_Service_Type::DELETE_THIS | ACE_Service_Type::DELETE_OBJ, + 0) + +#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION) + +template class ACE_Dynamic_Service<TAO_Codeset_Translator_Factory>; + +template class ACE_Node<TAO_Codeset_Item*>; +template class ACE_Unbounded_Set<TAO_Codeset_Item*>; +template class ACE_Unbounded_Set_Iterator<TAO_Codeset_Item*>; + +#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA) + +#pragma instantiate ACE_Dynamic_Service<TAO_Codeset_Translator_Factory> +#pragma instantiate ACE_Node<TAO_Codeset_Item*> +/// +#pragma instantiate ACE_Unbounded_Set<TAO_Codeset_Item*> +#pragma instantiate ACE_Unbounded_Set_Iterator<TAO_Codeset_Item*> + +# endif diff --git a/TAO/tao/Codeset/Codeset_Manager_i.h b/TAO/tao/Codeset/Codeset_Manager_i.h new file mode 100644 index 00000000000..1c74dff4552 --- /dev/null +++ b/TAO/tao/Codeset/Codeset_Manager_i.h @@ -0,0 +1,240 @@ +// This may look like C, but it's really -*- C++ -*- + +//====================================================================== +/* + * @file Codeset_Manager_i.h + * + * $Id$ + * + * Interface for the TAO CodeSet Manager. + * + * @author Phil Mesnier + */ +//====================================================================== + +#ifndef TAO_CODESET_MANAGER_I_H +#define TAO_CODESET_MANAGER_I_H + +#include /**/ "ace/pre.h" + +#include "tao/CONV_FRAMEC.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +#include "ace/Unbounded_Set.h" +#include "codeset_export.h" +#include "tao/Codeset_Manager.h" + +class ACE_WChar_Codeset_Translator; + +class TAO_Profile; +class TAO_Transport; +class TAO_Operation_Details; + +class TAO_ServerRequest; +class TAO_Tagged_Components; +class TAO_Codeset_Translator_Factory; +class TAO_Codeset_Manager; + +// **************************************************************** + +/** + * @class TAO_Codeset_Item + * + * @brief A single element in the list of Codeset Translator Factories + * + * This class is used by the Codeset_Manager to store references to + * individual codeset factories. Only those translators that match the + * char or wchar native codeset will be kept in the list. + * + */ + +class TAO_Codeset_Item +{ +public: + friend class TAO_Codeset_Manager; + /// creator method, the codeset name can only be set when the + /// object is created. + TAO_Codeset_Item (const char *name); + + /// destructor that deallocates the factory object if the + /// CodeSet_Item retains ownership. + ~TAO_Codeset_Item (void); + + /// return a reference to the character representation of the codeset + /// factories name. + const char *codeset_name (void); + + /// return a pointer to the codeset factory. + TAO_Codeset_Translator_Factory *factory (void); + + /// set the factory pointer's value. + void factory (TAO_Codeset_Translator_Factory *factory); + +private: + // Prohibited + ACE_UNIMPLEMENTED_FUNC (TAO_Codeset_Item (const TAO_Codeset_Item&)) + ACE_UNIMPLEMENTED_FUNC (void operator= (const TAO_Codeset_Item&)) + +private: + /// factory name. + char *name_; + + /// pointer to factory object. + TAO_Codeset_Translator_Factory *factory_; +}; + +// **************************************************************** + +/** + * @class TAO_Codeset_Manager + * + * @brief The encapsulation of logic for codeset negotiation + * + * The Codeset Manager is owned by the ORB_Core, initialized through Resource + * Factory configuration options. The codeset manager participates in profile + * creation by servers and connection establishment by clients. The involvement + * is necessary to supply a codeset component to the profile including for both + * chars and wide chars the native code set and any conversion code sets for + * which translators are available. The codeset manager is also responsible for + * determining the transmission codesets based an the local and remote codeset + * information. The transmission codesets are communicated via a service + * context attached to the first request sent on the new connection. + * + */ + +class TAO_Codeset_Export TAO_Codeset_Manager_i : + public TAO_Codeset_Manager +{ + +public: + /// NCS for char is defaulted to ISO 8859-1:1987; Latin Alphabet + /// No. 1 + static CONV_FRAME::CodeSetId default_char_codeset; + /// NCS for wchar is defaulted to 0 (not used), but people wishing + /// to provide a non-compliant default wchar codeset may do so. + static CONV_FRAME::CodeSetId default_wchar_codeset; + + TAO_Codeset_Manager_i (); + ~TAO_Codeset_Manager_i (); + + /// Called by an object of TAO_Acceptor to set NCS and CCS values + /// for Char/Wchar in to the Object Reference. + void set_codeset (TAO_Tagged_Components& ) const; + /// + /// Called from an object of "TAO_GIOP_Invocation" to set TCS on the + /// Transport + void set_tcs (TAO_Profile &theProfile, TAO_Transport &); + + /// Called from an Object of TAO_Messaging for every request at + /// server side to process service context and set TCS for + /// Char/WChar + void process_service_context (TAO_ServerRequest &); + + /// Called by a client object to generate service context + /// at this time Transport has the TCS for Char and WChar + void generate_service_context (TAO_Operation_Details&, TAO_Transport & ); + + + /// Called by the resource factory to set the native char codeset id + void set_ncs_c (CONV_FRAME::CodeSetId ncs); + + /// Called by the resource factory to set the native wchar codeset + /// id. The maxbytes value is used to communicate the width of + /// untranslated wide characters on the stream. This size may be + /// smaller than the size of a wchar_t. + void set_ncs_w (CONV_FRAME::CodeSetId ncs, int maxbytes = 0); + + /// Called by the resource factory to add a potential codeset + /// translator for char data. The actual factory will be added to + /// the list later, if its ncs matches that of the codeset manager. + int add_char_translator (const char *name); + + /// Called by the resource factory to add a potential codeset + /// translator for wchar data. The actual factory will be added to + /// the list later, if its ncs matches that of the codeset manager. + int add_wchar_translator (const char *name); + + /// Called by the resource factory to signify the end of + /// initialization. This will traverse the list of named codeset + /// translator factories and add any of those that have a native + /// codeset id matching the manager's native codeset id. + void open(void); + +private: + // typedefs for containers containing the list of codesets + // factories for character and wide character. + typedef ACE_Unbounded_Set<TAO_Codeset_Item*> + TAO_CodesetFactorySet; + + // Iterators + typedef ACE_Unbounded_Set_Iterator<TAO_Codeset_Item*> + TAO_CodesetFactorySetItor; + + // Compute the TCS for Char/WChar asper the CORBA Specification + CONV_FRAME::CodeSetId computeTCS (CONV_FRAME::CodeSetComponent &, + CONV_FRAME::CodeSetComponent &); + + // Find CodesetId in the codeset component + int isElementOf (CONV_FRAME::CodeSetId, + CONV_FRAME::CodeSetComponent & ); + + // find the intersection of CodesetIds between Client and Server CCS + CONV_FRAME::CodeSetId intersectionOf (CONV_FRAME::CodeSetComponent &, + CONV_FRAME::CodeSetComponent &); + + // determine compatibility between two codesets via the codeset + // registry + int isCompatible (CONV_FRAME::CodeSetId, CONV_FRAME::CodeSetId); + + // traverse the list of codeset factories, populating the list of + // conversion codeset values with the translated codeset id from + // each factory that has a matching native codeset. Those factories + // that do not have a matching codeset are not retained in the list. + int init_codeset_factories_i (TAO_CodesetFactorySet&, + CONV_FRAME::CodeSetComponent&); + + // get the translator between our ncs_c and the supplied tcs_c + TAO_Codeset_Translator_Base * get_char_trans (CONV_FRAME::CodeSetId); + + // get the translator between our ncs_w and the supplied tcs_w + TAO_Codeset_Translator_Base * get_wchar_trans (CONV_FRAME::CodeSetId); + + TAO_Codeset_Translator_Base * + get_translator_i (TAO_CodesetFactorySet&, + CONV_FRAME::CodeSetId); + + // The CodeSetComponentInfo struct contains all of the information + // regarding the code sets this application recognizes. This is + // where the native code set for both char and wchar are stored. + CONV_FRAME::CodeSetComponentInfo codeset_info_; + + // The lists of available translators for both chars and wchars. + TAO_CodesetFactorySet char_factories_; + TAO_CodesetFactorySet wchar_factories_; +}; + + +// **************************************************************** + +/** + * @class TAO_Codeset_Manager_Factory_Base + * + * @brief Abstract Base class for creating instances of the codeset manager. + */ + +class TAO_Codeset_Export TAO_Codeset_Manager_Factory : + public TAO_Codeset_Factory +{ +public: + virtual ~TAO_Codeset_Manager_Factory (); + virtual TAO_Codeset_Manager *create(TAO_ORB_Core *orb_core); +}; + + + +#include /**/ "ace/post.h" + +#endif /* TAO_CODESET_MANAGER_I_H */ diff --git a/TAO/tao/Codeset_Translator_Factory.cpp b/TAO/tao/Codeset/Codeset_Translator_Factory.cpp index 58ee5fb5ada..5abceffc601 100644 --- a/TAO/tao/Codeset_Translator_Factory.cpp +++ b/TAO/tao/Codeset/Codeset_Translator_Factory.cpp @@ -17,7 +17,7 @@ // // ============================================================================ -#include "tao/Codeset_Translator_Factory.h" +#include "Codeset_Translator_Factory.h" #include "tao/CDR.h" ACE_RCSID (tao, diff --git a/TAO/tao/Codeset/Codeset_Translator_Factory.h b/TAO/tao/Codeset/Codeset_Translator_Factory.h new file mode 100644 index 00000000000..105afa3dc65 --- /dev/null +++ b/TAO/tao/Codeset/Codeset_Translator_Factory.h @@ -0,0 +1,86 @@ +// -*- C++ -*- + +// =================================================================== +/** + * @file Codeset_Translator_Factory.h + * + * $Id$ + * + * @author Phil Mesnier <mesnier_p@ociweb.com> + */ +// ========================= + +#ifndef TAO_CODESET_TRANSLATOR_FACTORY_H +#define TAO_CODESET_TRANSLATOR_FACTORY_H + +#include /**/ "ace/pre.h" +#include "ace/Service_Object.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +#include "tao/CONV_FRAMEC.h" +#include "tao/Codeset_Translator_Base.h" +#include "codeset_export.h" + +class TAO_InputCDR; +class TAO_OutputCDR; + +class ACE_Char_Codeset_Translator; +class ACE_WChar_Codeset_Translator; + + +// **************************************************************** + +/** + * @class TAO_Codeset_Translator_Factory + * + * @brief Abstract base class for factories providing codeset translators + * + * The codeset translator factory is a loadable service object. It is used to + * supply the actual translator used in converting between two codesets. The + * intent of using a factory is to avoid requiring codeset translators to be + * multiply inherited both from the translator base class and the service + * object base. The translator factory is also responsible for assigning + * translators to CDR streams. Since there is no common base class between + * input and output CDRs, the assingment code must be duplicated. + */ + +class TAO_Codeset_Export TAO_Codeset_Translator_Factory : + public TAO_Codeset_Translator_Base, + public ACE_Service_Object +{ +public: + TAO_Codeset_Translator_Factory (); + virtual ~TAO_Codeset_Translator_Factory (); + virtual int init (int argc, ACE_TCHAR *argv[]); + +protected: + /// Assign the translator to the supplied input CDR. The template instance + /// will have a translator that is based on either the Char or Wchar + /// translator, so the compiler will select the appropriate call from + /// assign(). + void assign_i (TAO_InputCDR *, ACE_Char_Codeset_Translator* ) const; + /// Assign the translator to the supplied input CDR. The template instance + /// will have a translator that is based on either the Char or Wchar + /// translator, so the compiler will select the appropriate call from + /// assign(). + void assign_i (TAO_InputCDR *, ACE_WChar_Codeset_Translator* ) const; + /// Assign the translator to the supplied output CDR. The template instance + /// will have a translator that is based on either the Char or Wchar + /// translator, so the compiler will select the appropriate call from + /// assign(). + void assign_i (TAO_OutputCDR *, ACE_Char_Codeset_Translator* ) const; + /// Assign the translator to the supplied output CDR. The template instance + /// will have a translator that is based on either the Char or Wchar + /// translator, so the compiler will select the appropriate call from + /// assign(). + void assign_i (TAO_OutputCDR *, ACE_WChar_Codeset_Translator* ) const; +}; + +// Get the template includes last +#include "tao/Codeset/Codeset_Translator_Factory_T.h" + +#include /**/ "ace/post.h" +#endif /* TAO_Codeset_Translator_Factory */ diff --git a/TAO/tao/Codeset_Translator_Factory_T.cpp b/TAO/tao/Codeset/Codeset_Translator_Factory_T.cpp index 8dcd9262635..37d327ea80e 100644 --- a/TAO/tao/Codeset_Translator_Factory_T.cpp +++ b/TAO/tao/Codeset/Codeset_Translator_Factory_T.cpp @@ -19,7 +19,7 @@ #ifndef TAO_CODESET_TRANSLATOR_FACTORY_T_CPP #define TAO_CODESET_TRANSLATOR_FACTORY_T_CPP -#include "tao/Codeset_Translator_Factory_T.h" +#include "Codeset_Translator_Factory_T.h" #include "tao/debug.h" #include "tao/CDR.h" @@ -87,14 +87,3 @@ TAO_Codeset_Translator_Factory_T<NCS_TO_TCS>::assign (TAO_OutputCDR *cdr) const } #endif /* TAO_CODESET_TRANSLATOR_FACTORY_T_CPP */ - - - - - - - - - - - diff --git a/TAO/tao/Codeset_Translator_Factory_T.h b/TAO/tao/Codeset/Codeset_Translator_Factory_T.h index b523a863e78..07408db8717 100644 --- a/TAO/tao/Codeset_Translator_Factory_T.h +++ b/TAO/tao/Codeset/Codeset_Translator_Factory_T.h @@ -14,7 +14,7 @@ #include /**/ "ace/pre.h" -#include "tao/Codeset_Translator_Factory.h" +#include "Codeset_Translator_Factory.h" #if !defined (ACE_LACKS_PRAGMA_ONCE) # pragma once @@ -40,7 +40,7 @@ public: TAO_Codeset_Translator_Factory_T (); virtual ~TAO_Codeset_Translator_Factory_T (); - /// Initialize the factory service object. Instantiates the translator. + /// initialize the factory service object. Instantiates the translator. int init( int argc, ACE_TCHAR* argv[]); /// ncs returns the translator's native codeset ID. @@ -68,7 +68,7 @@ private: #endif /* ACE_LACKS_PRAGMA_ONCE */ #if defined (ACE_TEMPLATES_REQUIRE_SOURCE) -#include "tao/Codeset_Translator_Factory_T.cpp" +#include "Codeset_Translator_Factory_T.cpp" #endif /* ACE_TEMPLATES_REQUIRE_SOURCE */ #if defined (ACE_TEMPLATES_REQUIRE_PRAGMA) diff --git a/TAO/tao/UTF16_BOM_Factory.cpp b/TAO/tao/Codeset/UTF16_BOM_Factory.cpp index 9bf0443682a..99ce120b05f 100644 --- a/TAO/tao/UTF16_BOM_Factory.cpp +++ b/TAO/tao/Codeset/UTF16_BOM_Factory.cpp @@ -26,37 +26,37 @@ // via the Service Manager. #if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION) -template class ACE_Dynamic_Service<UTF16_BOM_Factory>; +template class ACE_Dynamic_Service<TAO_UTF16_BOM_Factory>; #elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA) -#pragma instantiate ACE_Dynamic_Service<UTF16_BOM_Factory> +#pragma instantiate ACE_Dynamic_Service<TAO_UTF16_BOM_Factory> #endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */ -ACE_STATIC_SVC_DEFINE (UTF16_BOM_Factory, - ACE_TEXT ("UTF16_BOM_Factory"), +ACE_STATIC_SVC_DEFINE (TAO_UTF16_BOM_Factory, + ACE_TEXT ("TAO_UTF16_BOM_Factory"), ACE_SVC_OBJ_T, - &ACE_SVC_NAME (UTF16_BOM_Factory), + &ACE_SVC_NAME (TAO_UTF16_BOM_Factory), ACE_Service_Type::DELETE_THIS | ACE_Service_Type::DELETE_OBJ, 0) -ACE_FACTORY_DEFINE (TAO, UTF16_BOM_Factory) -ACE_STATIC_SVC_REQUIRE (UTF16_BOM_Factory) +ACE_FACTORY_DEFINE (TAO_Codeset, TAO_UTF16_BOM_Factory) +ACE_STATIC_SVC_REQUIRE (TAO_UTF16_BOM_Factory) -UTF16_BOM_Factory::UTF16_BOM_Factory () +TAO_UTF16_BOM_Factory::TAO_UTF16_BOM_Factory () : translator_ (0) , forceBE_ (false) { } -UTF16_BOM_Factory::~UTF16_BOM_Factory () +TAO_UTF16_BOM_Factory::~TAO_UTF16_BOM_Factory () { delete this->translator_; } int -UTF16_BOM_Factory::init (int argc, ACE_TCHAR *argv[]) +TAO_UTF16_BOM_Factory::init (int argc, ACE_TCHAR *argv[]) { TAO_Codeset_Translator_Factory::init (argc, argv); @@ -70,8 +70,8 @@ UTF16_BOM_Factory::init (int argc, ACE_TCHAR *argv[]) else { ACE_ERROR ((LM_ERROR, - ACE_TEXT ("(%P|%t)UTF16_BOM_Factory parameter error: %s\n") - ACE_TEXT ("Usage: UTF16_BOM_Factory \"-forceBE\"\n") + ACE_TEXT ("(%P|%t)TAO_UTF16_BOM_Factory parameter error: %s\n") + ACE_TEXT ("Usage: TAO_UTF16_BOM_Factory \"-forceBE\"\n") , argv[narg] )); return -1; @@ -81,10 +81,10 @@ UTF16_BOM_Factory::init (int argc, ACE_TCHAR *argv[]) } int -UTF16_BOM_Factory::parse_one_arg (int argc, ACE_TCHAR *argv[]) +TAO_UTF16_BOM_Factory::parse_one_arg (int argc, ACE_TCHAR *argv[]) { int consumed = 0; - if ((argc > 0) && (ACE_OS::strcasecmp (argv[0], ACE_TEXT ("-forcebe")) == 0)) + if ((argc > 0) && (ACE_OS::strcasecmp (argv[0], ACE_TEXT("-forcebe")) == 0)) { this->forceBE_ = true; consumed = 1; @@ -93,14 +93,14 @@ UTF16_BOM_Factory::parse_one_arg (int argc, ACE_TCHAR *argv[]) } CONV_FRAME::CodeSetId -UTF16_BOM_Factory::ncs () const +TAO_UTF16_BOM_Factory::ncs () const { create_translator(); return this->translator_->ncs(); } CONV_FRAME::CodeSetId -UTF16_BOM_Factory::tcs () const +TAO_UTF16_BOM_Factory::tcs () const { create_translator(); return this->translator_->tcs(); @@ -109,7 +109,7 @@ UTF16_BOM_Factory::tcs () const // Assign either a reference to the existing translator or a new translator // for input CDR streams void -UTF16_BOM_Factory::assign (TAO_InputCDR *cdr) const +TAO_UTF16_BOM_Factory::assign (TAO_InputCDR *cdr) const { if (cdr) { @@ -121,7 +121,7 @@ UTF16_BOM_Factory::assign (TAO_InputCDR *cdr) const // Assign either a reference to the existing translator or a new translator // for output CDR streams void -UTF16_BOM_Factory::assign (TAO_OutputCDR *cdr) const +TAO_UTF16_BOM_Factory::assign (TAO_OutputCDR *cdr) const { if (cdr) { @@ -131,16 +131,16 @@ UTF16_BOM_Factory::assign (TAO_OutputCDR *cdr) const } void -UTF16_BOM_Factory::create_translator () const +TAO_UTF16_BOM_Factory::create_translator () const { if (this->translator_ == 0) { - UTF16_BOM_Factory * pthis = const_cast<UTF16_BOM_Factory *> (this); - ACE_NEW (pthis->translator_, UTF16_BOM_Translator (this->forceBE_)); + TAO_UTF16_BOM_Factory * pthis = const_cast<TAO_UTF16_BOM_Factory *> (this); + ACE_NEW (pthis->translator_, TAO_UTF16_BOM_Translator (this->forceBE_)); if (this->translator_ == 0) { ACE_ERROR ((LM_ERROR, - ACE_TEXT ("(%P|%t) UTF16_BOM_Factory cannot create UTF16_BOM_Translator\n") + ACE_TEXT ("(%P|%t) TAO_UTF16_BOM_Factory cannot create Translator\n") )); } } diff --git a/TAO/tao/UTF16_BOM_Factory.h b/TAO/tao/Codeset/UTF16_BOM_Factory.h index 98261fe35cc..64bc891198b 100644 --- a/TAO/tao/UTF16_BOM_Factory.h +++ b/TAO/tao/Codeset/UTF16_BOM_Factory.h @@ -22,15 +22,17 @@ #include /**/ "ace/pre.h" #include "ace/Service_Config.h" -#include "tao/Codeset_Translator_Factory.h" +#include "Codeset_Translator_Factory.h" #include "UTF16_BOM_Translator.h" +#include "codeset_export.h" -class TAO_Export UTF16_BOM_Factory : public TAO_Codeset_Translator_Factory +class TAO_Codeset_Export TAO_UTF16_BOM_Factory + : public TAO_Codeset_Translator_Factory { public: - UTF16_BOM_Factory (); - virtual ~UTF16_BOM_Factory (); + TAO_UTF16_BOM_Factory (); + virtual ~TAO_UTF16_BOM_Factory (); virtual int init (int argc, ACE_TCHAR *argv[]); /// ncs returns the translator's native codeset ID. @@ -54,12 +56,12 @@ private: int parse_one_arg (int argc, ACE_TCHAR *argv[]); private: - UTF16_BOM_Translator *translator_; + TAO_UTF16_BOM_Translator *translator_; bool forceBE_; // force big endian wchar, warray, & wstring }; -ACE_STATIC_SVC_DECLARE_EXPORT (TAO, UTF16_BOM_Factory) -ACE_FACTORY_DECLARE (TAO, UTF16_BOM_Factory) +ACE_STATIC_SVC_DECLARE_EXPORT (TAO_Codeset, TAO_UTF16_BOM_Factory) +ACE_FACTORY_DECLARE (TAO_Codeset, TAO_UTF16_BOM_Factory) #include /**/ "ace/post.h" #endif /* UTF16_BOM_FACTORY_H */ diff --git a/TAO/tao/UTF16_BOM_Translator.cpp b/TAO/tao/Codeset/UTF16_BOM_Translator.cpp index 287430f5c06..fdc20ecc76a 100644 --- a/TAO/tao/UTF16_BOM_Translator.cpp +++ b/TAO/tao/Codeset/UTF16_BOM_Translator.cpp @@ -18,11 +18,11 @@ #include "ace/Log_Msg.h" ACE_RCSID (tao, - UTF16_BOM_Translator, + TAO_UTF16_BOM_Translator, "$Id$") -// **************************************************************** + // **************************************************************** typedef ACE_CDR::UShort ACE_UTF16_T; @@ -31,24 +31,24 @@ static const unsigned short ACE_UNICODE_BOM_CORRECT = 0xFEFFU; static const unsigned short ACE_UNICODE_BOM_SWAPPED = 0xFFFEU; ///////////////////////////// -// UTF16_BOM_Translator implementation +// TAO_UTF16_BOM_Translator implementation -UTF16_BOM_Translator::UTF16_BOM_Translator (bool forceBE) +TAO_UTF16_BOM_Translator::TAO_UTF16_BOM_Translator (bool forceBE) : forceBE_(forceBE) { if (TAO_debug_level > 1) ACE_DEBUG((LM_DEBUG, - ACE_TEXT ("TAO (%P|%t) - UTF16_BOM_Translator:forceBE %d\n"), - this->forceBE_?1:0 )); + ACE_TEXT ("(%P|%t)TAO_UTF16_BOM_Translator") + ACE_TEXT("forceBE %d\n"), this->forceBE_?1:0 )); } -UTF16_BOM_Translator::~UTF16_BOM_Translator (void) +TAO_UTF16_BOM_Translator::~TAO_UTF16_BOM_Translator (void) { } // = Documented in $ACE_ROOT/ace/CDR_Stream.h ACE_CDR::Boolean -UTF16_BOM_Translator::read_wchar (ACE_InputCDR &cdr, ACE_CDR::WChar &x) +TAO_UTF16_BOM_Translator::read_wchar (ACE_InputCDR &cdr, ACE_CDR::WChar &x) { if (static_cast<ACE_CDR::Short> (this->major_version (cdr)) == 1 && static_cast<ACE_CDR::Short> (this->minor_version (cdr)) == 2) @@ -113,8 +113,8 @@ UTF16_BOM_Translator::read_wchar (ACE_InputCDR &cdr, ACE_CDR::WChar &x) } ACE_CDR::Boolean -UTF16_BOM_Translator::read_wstring (ACE_InputCDR &cdr, - ACE_CDR::WChar *&x) +TAO_UTF16_BOM_Translator::read_wstring (ACE_InputCDR &cdr, + ACE_CDR::WChar *&x) { ACE_CDR::ULong len; if (!this->read_4 (cdr, &len)) @@ -169,10 +169,10 @@ UTF16_BOM_Translator::read_wstring (ACE_InputCDR &cdr, } ACE_CDR::Boolean -UTF16_BOM_Translator::read_wchar_array_i (ACE_InputCDR & cdr, - ACE_CDR::WChar *x, - ACE_CDR::ULong &length, - int adjust_len) +TAO_UTF16_BOM_Translator::read_wchar_array_i (ACE_InputCDR & cdr, + ACE_CDR::WChar *x, + ACE_CDR::ULong &length, + int adjust_len) { int has_bom = 0; int must_swap = 0; @@ -229,9 +229,9 @@ UTF16_BOM_Translator::read_wchar_array_i (ACE_InputCDR & cdr, } ACE_CDR::Boolean -UTF16_BOM_Translator::read_wchar_array (ACE_InputCDR & cdr, - ACE_CDR::WChar *x, - ACE_CDR::ULong length) +TAO_UTF16_BOM_Translator::read_wchar_array (ACE_InputCDR & cdr, + ACE_CDR::WChar *x, + ACE_CDR::ULong length) { if (length == 0) return 1; @@ -250,16 +250,16 @@ UTF16_BOM_Translator::read_wchar_array (ACE_InputCDR & cdr, } ACE_CDR::Boolean -UTF16_BOM_Translator::write_wchar (ACE_OutputCDR &cdr, - ACE_CDR::WChar x) +TAO_UTF16_BOM_Translator::write_wchar (ACE_OutputCDR &cdr, + ACE_CDR::WChar x) { return this->write_wchar_i (cdr, x, true); } ACE_CDR::Boolean -UTF16_BOM_Translator::write_wchar_i (ACE_OutputCDR &cdr, - ACE_CDR::WChar x, - bool allow_BOM) +TAO_UTF16_BOM_Translator::write_wchar_i (ACE_OutputCDR &cdr, + ACE_CDR::WChar x, + bool allow_BOM) { if (static_cast<ACE_CDR::Short> (this->major_version (cdr)) == 1 && static_cast<ACE_CDR::Short> (this->minor_version (cdr)) > 1) @@ -276,7 +276,7 @@ UTF16_BOM_Translator::write_wchar_i (ACE_OutputCDR &cdr, // force both the byte order mark and the data to Big Endian order buffer[0] = ACE_UNICODE_BOM_SWAPPED; ACE_CDR::swap_2 (reinterpret_cast<const char *> (&x), - reinterpret_cast<char *> (&buffer[1])); + reinterpret_cast<char *> (&buffer[1])); } else #endif @@ -320,9 +320,9 @@ UTF16_BOM_Translator::write_wchar_i (ACE_OutputCDR &cdr, } ACE_CDR::Boolean -UTF16_BOM_Translator::write_wstring (ACE_OutputCDR & cdr, - ACE_CDR::ULong len, - const ACE_CDR::WChar *x) +TAO_UTF16_BOM_Translator::write_wstring (ACE_OutputCDR & cdr, + ACE_CDR::ULong len, + const ACE_CDR::WChar *x) { // we'll accept a null pointer but only for an empty string ACE_ASSERT (x != 0 || len == 0); @@ -368,9 +368,9 @@ UTF16_BOM_Translator::write_wstring (ACE_OutputCDR & cdr, } ACE_CDR::Boolean -UTF16_BOM_Translator::write_wchar_array (ACE_OutputCDR & cdr, - const ACE_CDR::WChar *x, - ACE_CDR::ULong length) +TAO_UTF16_BOM_Translator::write_wchar_array (ACE_OutputCDR & cdr, + const ACE_CDR::WChar *x, + ACE_CDR::ULong length) { if (static_cast<ACE_CDR::Short> (this->major_version (cdr)) == 1 && static_cast<ACE_CDR::Short> (this->minor_version (cdr)) > 1) @@ -385,22 +385,10 @@ UTF16_BOM_Translator::write_wchar_array (ACE_OutputCDR & cdr, return this->write_wchar_array_i (cdr, x, length); } -ACE_CDR::ULong -UTF16_BOM_Translator::ncs (void) -{ - return 0x00010109; -} - -ACE_CDR::ULong -UTF16_BOM_Translator::tcs (void) -{ - return 0x00010109; -} - ACE_CDR::Boolean -UTF16_BOM_Translator::write_wchar_array_i (ACE_OutputCDR & cdr, - const ACE_CDR::WChar *x, - ACE_CDR::ULong length) +TAO_UTF16_BOM_Translator::write_wchar_array_i (ACE_OutputCDR & cdr, + const ACE_CDR::WChar *x, + ACE_CDR::ULong length) { if (length == 0) return 1; @@ -423,9 +411,9 @@ UTF16_BOM_Translator::write_wchar_array_i (ACE_OutputCDR & cdr, } ACE_CDR::Boolean -UTF16_BOM_Translator::write_swapped_wchar_array_i (ACE_OutputCDR & cdr, - const ACE_CDR::WChar *x, - ACE_CDR::ULong length) +TAO_UTF16_BOM_Translator::write_swapped_wchar_array_i (ACE_OutputCDR & cdr, + const ACE_CDR::WChar *x, + ACE_CDR::ULong length) { if (length == 0) return 1; diff --git a/TAO/tao/UTF16_BOM_Translator.h b/TAO/tao/Codeset/UTF16_BOM_Translator.h index 11338846dae..6f8e5d6bc7c 100644 --- a/TAO/tao/UTF16_BOM_Translator.h +++ b/TAO/tao/Codeset/UTF16_BOM_Translator.h @@ -23,12 +23,12 @@ #endif /* ACE_LACKS_PRAGMA_ONCE */ #include "ace/CDR_Stream.h" -#include "TAO_Export.h" +#include "codeset_export.h" // **************************************************************** /** - * @class UTF16_BOM_Translator + * @class TAO_UTF16_BOM_Translator * * @brief Codeset translation specialization - Manages Byte Order Marker * @@ -36,15 +36,16 @@ * - Native: UTF16 (i.e. Unicode) * - Stream: UTF16 with Byte Order Marker */ -class TAO_Export UTF16_BOM_Translator : public ACE_WChar_Codeset_Translator +class TAO_Codeset_Export TAO_UTF16_BOM_Translator + : public ACE_WChar_Codeset_Translator { public: /// constructor /// @param forceBE: true forces all wchar, warray, and wstrings to big-endian byte order - UTF16_BOM_Translator (bool forceBE); + TAO_UTF16_BOM_Translator (bool forceBE); /// Virtual destruction - virtual ~UTF16_BOM_Translator (void); + virtual ~TAO_UTF16_BOM_Translator (void); // = Documented in $ACE_ROOT/ace/CDR_Stream.h virtual ACE_CDR::Boolean read_wchar (ACE_InputCDR &, @@ -62,8 +63,8 @@ public: virtual ACE_CDR::Boolean write_wchar_array (ACE_OutputCDR &, const ACE_CDR::WChar *, ACE_CDR::ULong); - virtual ACE_CDR::ULong ncs (void); - virtual ACE_CDR::ULong tcs (void); + virtual ACE_CDR::ULong ncs () {return 0x00010109;} + virtual ACE_CDR::ULong tcs () {return 0x00010109;} private: ACE_CDR::Boolean read_wchar_array_i (ACE_InputCDR &, diff --git a/TAO/tao/Codeset/UTF8_Latin1_Factory.cpp b/TAO/tao/Codeset/UTF8_Latin1_Factory.cpp new file mode 100644 index 00000000000..39c75153e69 --- /dev/null +++ b/TAO/tao/Codeset/UTF8_Latin1_Factory.cpp @@ -0,0 +1,97 @@ +// -*- C++ -*- +// $Id$ +#include "ace/Dynamic_Service.h" +#include "UTF8_Latin1_Factory.h" + +// Instantiate templates that allow discovery of this factory +// in the Service Manager. +#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION) + +template class ACE_Dynamic_Service<TAO_UTF8_Latin1_Factory>; + +#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA) + +#pragma instantiate ACE_Dynamic_Service<TAO_UTF8_Latin1_Factory> + +#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */ + +ACE_STATIC_SVC_DEFINE (TAO_UTF8_Latin1_Factory, + ACE_TEXT ("UTF8_Latin1_Factory"), + ACE_SVC_OBJ_T, + &ACE_SVC_NAME (TAO_UTF8_Latin1_Factory), + ACE_Service_Type::DELETE_THIS + | ACE_Service_Type::DELETE_OBJ, + 0) +ACE_FACTORY_DEFINE (TAO_Codeset, TAO_UTF8_Latin1_Factory) +ACE_STATIC_SVC_REQUIRE (TAO_UTF8_Latin1_Factory) + +TAO_UTF8_Latin1_Factory::TAO_UTF8_Latin1_Factory() + : translator_ (0) +{ +} + +TAO_UTF8_Latin1_Factory::~TAO_UTF8_Latin1_Factory () +{ + delete this->translator_; +} +int +TAO_UTF8_Latin1_Factory::init (int argc, ACE_TCHAR *argv[]) +{ + TAO_Codeset_Translator_Factory::init (argc, argv); + return 0; +} + +CONV_FRAME::CodeSetId +TAO_UTF8_Latin1_Factory::ncs () const +{ + create_translator(); + return this->translator_->ncs(); +} + +CONV_FRAME::CodeSetId +TAO_UTF8_Latin1_Factory::tcs () const +{ + create_translator(); + return this->translator_->tcs(); +} + +// Assign either a reference to the existing translator or a new translator +// for input CDR streams +void +TAO_UTF8_Latin1_Factory::assign (TAO_InputCDR *cdr) const +{ + if (cdr) + { + create_translator(); + this->assign_i(cdr,this->translator_); + } +} + +// Assign either a reference to the existing translator or a new translator +// for output CDR streams +void +TAO_UTF8_Latin1_Factory::assign (TAO_OutputCDR *cdr) const +{ + if (cdr) + { + create_translator(); + this->assign_i(cdr,this->translator_); + } +} + +void +TAO_UTF8_Latin1_Factory::create_translator () const +{ + if (this->translator_ == 0) + { + TAO_UTF8_Latin1_Factory * pthis = ACE_const_cast (TAO_UTF8_Latin1_Factory *, this); + ACE_NEW (pthis->translator_, TAO_UTF8_Latin1_Translator); + if (this->translator_ == 0) + { + ACE_ERROR ((LM_ERROR, + ACE_TEXT ("(%P|%t) TAO_UTF8_Latin1_Factory cannot ") + ACE_TEXT("create TAO_UTF8_Latin1_Translator\n") + )); + } + } +} diff --git a/TAO/tao/Codeset/UTF8_Latin1_Factory.h b/TAO/tao/Codeset/UTF8_Latin1_Factory.h new file mode 100644 index 00000000000..81bfdf71f08 --- /dev/null +++ b/TAO/tao/Codeset/UTF8_Latin1_Factory.h @@ -0,0 +1,49 @@ +// -*- C++ -*- +// $Id$ + +#ifndef UTF8_LATIN1_FACTORY_H +#define UTF8_LATIN1_FACTORY_H + +#include /**/ "ace/pre.h" +#include "codeset_export.h" +#include "ace/Service_Config.h" +#include "Codeset_Translator_Factory.h" + +#include "UTF8_Latin1_Translator.h" + +class TAO_Codeset_Export TAO_UTF8_Latin1_Factory + : public TAO_Codeset_Translator_Factory +{ +public: + TAO_UTF8_Latin1_Factory (); + virtual ~TAO_UTF8_Latin1_Factory (); + virtual int init (int argc, ACE_TCHAR *argv[]); + + /// ncs returns the translator's native codeset ID. + CONV_FRAME::CodeSetId ncs () const; + /// tcs returns the translator's transmission codeset ID. + CONV_FRAME::CodeSetId tcs () const; + + /// Assign the translator to the input CDR. The inherited assign_i is used + /// to assign either a char or wchar translator, depending on the base type + /// of NCS_TO_TCS. A null input CDR is permitted, in which case assign is a + /// no-op. + virtual void assign (TAO_InputCDR *) const; + /// Assign the translator to the output CDR. The inherited assign_i is used + /// to assign either a char or wchar translator, depending on the base type + /// of NCS_TO_TCS. A null output CDR is permitted, in which case assign is a + /// no-op. + virtual void assign (TAO_OutputCDR *) const; + +private: + void create_translator () const; + +private: + TAO_UTF8_Latin1_Translator *translator_; +}; + +ACE_STATIC_SVC_DECLARE_EXPORT (TAO_Codeset, TAO_UTF8_Latin1_Factory) +ACE_FACTORY_DECLARE (TAO_Codeset, TAO_UTF8_Latin1_Factory) + +#include /**/ "ace/post.h" +#endif /* UTF8_LATIN1_FACTORY_H */ diff --git a/TAO/tao/Codeset/UTF8_Latin1_Translator.cpp b/TAO/tao/Codeset/UTF8_Latin1_Translator.cpp new file mode 100644 index 00000000000..11eca3f5c99 --- /dev/null +++ b/TAO/tao/Codeset/UTF8_Latin1_Translator.cpp @@ -0,0 +1,227 @@ +// -*- C++ -*- +// $Id$ + +// ============================================================================ +// +// = LIBRARY +// ace +// +// = FILENAME +// UTF8_Latin1_Translator.cpp +// +// = DESCRIPTION +// Defines the methods required to convert UTF-8 based unicode strings +// to the Latin-1 codeset. +// +// = AUTHOR +// Phil Mesnier <mesnier_p@ociweb.com> +// +// ============================================================================ +#include "UTF8_Latin1_Translator.h" +#include "tao/debug.h" +#include "ace/OS_Memory.h" + +// **************************************************************** + + +///////////////////////////// +// UTF8_Latin1_Translator implementation + +TAO_UTF8_Latin1_Translator::TAO_UTF8_Latin1_Translator () +{ +} + +TAO_UTF8_Latin1_Translator::~TAO_UTF8_Latin1_Translator (void) +{ +} + +// = Documented in $ACE_ROOT/ace/CDR_Stream.h +ACE_CDR::Boolean +TAO_UTF8_Latin1_Translator::read_char (ACE_InputCDR &cdr, ACE_CDR::Char &x) +{ + // We cannot have a codepoint > 0xBF at this point, since we are expecting + // only one single char. + ACE_CDR::Octet ox; + if (this->read_1 (cdr, &ox)) + { + if (ox < 0xC0) + { + x = ox; + return 1; + } + } + return 0; +} + +ACE_CDR::ULong +TAO_UTF8_Latin1_Translator::read_char_i (ACE_InputCDR &cdr, ACE_CDR::Char &x) +{ + // This will read up to 2 octets and combine them into one char if possible + ACE_CDR::Octet upper; + if (this->read_1 (cdr, &upper)) + { + if ( upper >= 0xC4) // Anything with a leading char > 110001xx converts + // to a codepoint value > 0x00FF, thus won't fit in + // a single char. + return 0; + if ( upper < 0xC0 ) + { + x = ACE_static_cast(ACE_CDR::Char, upper); + return 1; + } + ACE_CDR::Octet lower; + if (this->read_1 (cdr, &lower)) + { + ACE_CDR::Octet final = ((upper & 0xBF) << 6) + (lower & 0xC0); + x = ACE_static_cast (ACE_CDR::Char, final); + return 2; + }; + } + return 0; +} + +ACE_CDR::Boolean +TAO_UTF8_Latin1_Translator::read_string (ACE_InputCDR &cdr, + ACE_CDR::Char *&x) +{ + ACE_CDR::ULong len; + if (!cdr.read_ulong (len)) + return 0; + if (ACE_static_cast (ACE_CDR::Short, this->major_version(cdr)) == 1 + && ACE_static_cast (ACE_CDR::Short, this->minor_version(cdr)) == 2) + len--; + + // A check for the length being too great is done later in the + // call to read_char_array but we want to have it done before + // the memory is allocated. + if (len > 0 && len <= cdr.length()) + { + ACE_NEW_RETURN (x, + ACE_CDR::Char [len+1], + 0); + // pos keeps track of the character position, it will never be + // greater than len + size_t pos = 0; + ACE_CDR::ULong incr = 1; + for (ACE_CDR::ULong i = 0; incr > 0 && i < len; i += incr) + { + incr = this->read_char_i(cdr,x[pos++]); + } + if (incr > 0) + { + x[pos] = '\x00'; + return 1; + } + delete [] x; + } + else if (len == 0) + { + // Convert any null strings to empty strings since empty + // strings can cause crashes. (See bug 58.) + ACE_NEW_RETURN (x, + ACE_CDR::Char[1], + 0); + x[0] = '\x00'; + return 1; + } + x = 0; + return 0; +} + +ACE_CDR::Boolean +TAO_UTF8_Latin1_Translator::read_char_array (ACE_InputCDR & cdr, + ACE_CDR::Char *x, + ACE_CDR::ULong length) +{ + if (length == 0) + return 1; + + for (size_t i = 0; i < length; ++i) + if (!this->read_char(cdr,x[i])) + return 0; + + return 1; +} + +ACE_CDR::Boolean +TAO_UTF8_Latin1_Translator::write_char (ACE_OutputCDR &cdr, + ACE_CDR::Char x) +{ + ACE_CDR::Octet ox = x; + if (ox < 0xC0) + return this->write_1 (cdr,&ox); + else + { // character cannot be represented in a single octet + errno = EINVAL; + return 0; + } +} + +ACE_CDR::Boolean +TAO_UTF8_Latin1_Translator::write_char_i (ACE_OutputCDR &cdr, + ACE_CDR::Char x) +{ + // @@@ Strictly speaking, we should test for 7F < x < C0 and do + // something else in that case, but for now we will just let it + // pass. + + ACE_CDR::Octet ox = x; + if (ox < 0xC0) + return this->write_1 (cdr,&ox); + else + { // character cannot be represented in a single octet + // Since the source will never be > 0xFF, we don't have to worry about + // using a third octet. + ACE_CDR::Octet upper = 0xC0 + ox >> 6; + ACE_CDR::Octet lower = 0x80 + (ox & 0x3F); + if (this->write_1(cdr, &upper)) + return this->write_1(cdr, &lower); + } + return 0; +} + +ACE_CDR::Boolean +TAO_UTF8_Latin1_Translator::write_string (ACE_OutputCDR & cdr, + ACE_CDR::ULong len, + const ACE_CDR::Char *x) +{ + // we'll accept a null pointer but only for an empty string + if (x == 0 && len != 0) + return 0; + + ACE_CDR::ULong l = len; + // Compute the real buffer size by adding in multi-byte codepoints. + for (ACE_CDR::ULong i = 0; i < len; i++) + if (ACE_static_cast(ACE_CDR::Octet,x[i]) > 0xbf) l++; + + // Always add one for the nul + l++; + if (cdr.write_ulong (l)) + { + for (ACE_CDR::ULong i = 0; i < len; ++i) + { + if (this->write_char_i (cdr,x[i]) == 0) + return 0; + } + ACE_CDR::Octet s = 0; + return this->write_1 (cdr, &s); + } + return 0; +} + +ACE_CDR::Boolean +TAO_UTF8_Latin1_Translator::write_char_array (ACE_OutputCDR & cdr, + const ACE_CDR::Char *x, + ACE_CDR::ULong length) +{ + if (length == 0) + return 1; + + for (size_t i = 0; i < length; ++i) + // We still have to write each char individually, as any translated + // value may fail to fit in a single octet. + if (this->write_char (cdr, x[i]) == 0) + return 0; + + return 1; +} diff --git a/TAO/tao/Codeset/UTF8_Latin1_Translator.h b/TAO/tao/Codeset/UTF8_Latin1_Translator.h new file mode 100644 index 00000000000..bcf40d115a9 --- /dev/null +++ b/TAO/tao/Codeset/UTF8_Latin1_Translator.h @@ -0,0 +1,86 @@ +// -*- C++ -*- + +//============================================================================= +/** + * @file UTF8_Latin1_Translator.h + * + * $Id$ + * + * + * + * @author Phil Mesnier <mesnier_p@ociweb.com> + */ +//============================================================================= + +#ifndef UTF8_LATIN1_TRANSLATOR_H +#define UTF8_LATIN1_TRANSLATOR_H +#include /**/ "ace/pre.h" + +#include "ace/config-all.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +#include "ace/CDR_Stream.h" +#include "codeset_export.h" + +// **************************************************************** + +/** + * @class UTF8_Latin1_Translator + * + * @brief Codeset translation specialization - Manages Byte Order Marker + * + * This class performs the codeset translation: + * - Native: ISO-8859-1 (i.e. Latin 1) + * - Stream: UTF-8 (8 bit unicode mapping) + * + * When writing chars, it is possible to raise a DATA_CONVERSION exception + * because some valid Latin codepoints map to 2-byte utf-8 codepoints. + * + * When reading strings, it is possible to raise a DATA_CONVERSION exception + * because the string may include utf-8 unicode codepoints > 0x00FF. + */ +class TAO_Codeset_Export TAO_UTF8_Latin1_Translator + : public ACE_Char_Codeset_Translator +{ +public: + /// constructor + TAO_UTF8_Latin1_Translator (); + + /// Virtual destruction + virtual ~TAO_UTF8_Latin1_Translator (void); + + // = Documented in $ACE_ROOT/ace/CDR_Stream.h + virtual ACE_CDR::Boolean read_char (ACE_InputCDR &, + ACE_CDR::Char &); + virtual ACE_CDR::Boolean read_string (ACE_InputCDR &, + ACE_CDR::Char *&); + virtual ACE_CDR::Boolean read_char_array (ACE_InputCDR &, + ACE_CDR::Char *, + ACE_CDR::ULong); + virtual ACE_CDR::Boolean write_char (ACE_OutputCDR &, + ACE_CDR::Char); + virtual ACE_CDR::Boolean write_string (ACE_OutputCDR &, + ACE_CDR::ULong, + const ACE_CDR::Char *); + virtual ACE_CDR::Boolean write_char_array (ACE_OutputCDR &, + const ACE_CDR::Char *, + ACE_CDR::ULong); + virtual ACE_CDR::ULong ncs () {return 0x00010001U;} + virtual ACE_CDR::ULong tcs () {return 0x05010001U;} + +private: + ACE_CDR::ULong read_char_i (ACE_InputCDR &, + ACE_CDR::Char &); + + ACE_CDR::Boolean write_char_i (ACE_OutputCDR &, + ACE_CDR::Char); + +private: + +}; + +#include /**/ "ace/post.h" +#endif /* UTF8_LATIN1_TRANSLATOR_H */ diff --git a/TAO/tao/Codeset/codeset_export.h b/TAO/tao/Codeset/codeset_export.h new file mode 100644 index 00000000000..10f5440fdeb --- /dev/null +++ b/TAO/tao/Codeset/codeset_export.h @@ -0,0 +1,40 @@ + +// -*- C++ -*- +// $Id$ +// Definition for Win32 Export directives. +// This file is generated automatically by generate_export_file.pl +// ------------------------------ +#ifndef TAO_CODESET_EXPORT_H +#define TAO_CODESET_EXPORT_H + +#include "ace/config-all.h" + +#if defined (TAO_AS_STATIC_LIBS) +# if !defined (TAO_HAS_DLL) +# define TAO_HAS_DLL 0 +# endif /* ! TAO_HAS_DLL */ +#else +# if !defined (TAO_HAS_DLL) +# define TAO_HAS_DLL 1 +# endif /* ! TAO_HAS_DLL */ +#endif + +#if defined (TAO_HAS_DLL) && (TAO_HAS_DLL == 1) +# if defined (TAO_BUILD_DLL) +# define TAO_Codeset_Export ACE_Proper_Export_Flag +# define TAO_SINGLETON_DECLARATION(T) ACE_EXPORT_SINGLETON_DECLARATION (T) +# define TAO_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) ACE_EXPORT_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) +# else /* TAO_BUILD_DLL */ +# define TAO_Codeset_Export ACE_Proper_Import_Flag +# define TAO_SINGLETON_DECLARATION(T) ACE_IMPORT_SINGLETON_DECLARATION (T) +# define TAO_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) ACE_IMPORT_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) +# endif /* TAO_BUILD_DLL */ +#else /* TAO_HAS_DLL == 1 */ +# define TAO_Codeset_Export +# define TAO_SINGLETON_DECLARATION(T) +# define TAO_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) +#endif /* TAO_HAS_DLL == 1 */ + +#endif /* TAO_CODESET_EXPORT_H */ + +// End of auto generated file. diff --git a/TAO/tao/Codeset_Manager.cpp b/TAO/tao/Codeset_Manager.cpp index b4ee793e3cf..75206adfcaf 100644 --- a/TAO/tao/Codeset_Manager.cpp +++ b/TAO/tao/Codeset_Manager.cpp @@ -1,16 +1,15 @@ // $Id$ -#include "tao/Codeset_Manager.h" #include "tao/TAO_Server_Request.h" #include "tao/operation_details.h" #include "tao/Transport.h" #include "tao/Profile.h" -#include "tao/Codeset_Translator_Factory.h" #include "tao/SystemException.h" -#include "tao/UTF16_BOM_Factory.h" #include "tao/debug.h" #include "tao/CDR.h" +#include "Codeset_Manager.h" + #include "ace/Dynamic_Service.h" #include "ace/Codeset_Registry.h" #include "ace/OS_NS_string.h" @@ -21,548 +20,10 @@ ACE_RCSID (tao, "$Id$") -// These numbers are assigned by the OpenGroup, a database is -// available at -// -// ftp://ftp.opengroup.org/pub/code_set_registry/ -// -#define TAO_CODESET_ID_ISO8859_1 0x00010001U -#define TAO_CODESET_ID_UNICODE 0x00010109U -#define TAO_CODESET_ID_XOPEN_UTF_8 0x05010001U - -// These are the default codesets that TAO declares, of course they -// will be different on each platform, once the complete support for -// character sets is implemented - -//#define TAO_DEFAULT_CHAR_CODESET_ID TAO_CODESET_ID_XOPEN_UTF_8 -#define TAO_DEFAULT_CHAR_CODESET_ID TAO_CODESET_ID_ISO8859_1 -#define TAO_DEFAULT_WCHAR_CODESET_ID TAO_CODESET_ID_UNICODE - -// **************************************************************** - -/// NCS for char is defaulted to ISO 8859-1:1987; Latin Alphabet No. 1 -CONV_FRAME::CodeSetId -TAO_Codeset_Manager::default_char_codeset = TAO_DEFAULT_CHAR_CODESET_ID; -/// NCS for wchar is not defaulted by the CORBA specification, but a default -/// may be set here if desired -CONV_FRAME::CodeSetId -TAO_Codeset_Manager::default_wchar_codeset = TAO_DEFAULT_WCHAR_CODESET_ID; - -TAO_Codeset_Manager::TAO_Codeset_Manager () - : codeset_info_ (), - char_factories_ (), - wchar_factories_ (), - utf16_bom_translator_ (0) -{ - this->codeset_info_.ForCharData.native_code_set = - TAO_Codeset_Manager::default_char_codeset; - this->codeset_info_.ForWcharData.native_code_set = - TAO_Codeset_Manager::default_wchar_codeset; -} - TAO_Codeset_Manager::~TAO_Codeset_Manager () { - // Cleanup the character map - TAO_CodesetFactorySetItor cf_end = this->char_factories_.end (); - TAO_CodesetFactorySetItor cf_iter = this->char_factories_.begin (); - - for (; cf_iter != cf_end; ++cf_iter) - { - delete *cf_iter; - } - - this->char_factories_.reset (); - - // Cleanup the wide character map - cf_end = this->wchar_factories_.end (); - cf_iter = this->wchar_factories_.begin (); - - for (;cf_iter != cf_end; ++cf_iter) - { - delete *cf_iter; - } - - this->wchar_factories_.reset (); - - // Note: do not delete utf16_bom_translator_ The service manager owns it -} - -void -TAO_Codeset_Manager::set_codeset (TAO_Tagged_Components& tc) const -{ - tc.set_code_sets (this->codeset_info_); -} - -void -TAO_Codeset_Manager::set_tcs (TAO_Profile &theProfile, - TAO_Transport &trans) -{ - /// If tcs is already set on the transport then donot process, - /// use existing transport as CDR have translators set. - if (trans.is_tcs_set ()) - { - if(TAO_debug_level > 2) - { - ACE_DEBUG ((LM_DEBUG, - ACE_TEXT ("TAO (%P|%t) - Codeset_Manager::set_tcs, ") - ACE_TEXT ("transport already set\n"))); - } - - return; - } - - TAO_Tagged_Components& theTaggedComp = theProfile.tagged_components (); - - CONV_FRAME::CodeSetComponentInfo remote; - - /// Get the codeset component - if (theTaggedComp.get_code_sets(remote) == 0 ) - { - if (TAO_debug_level > 2) - { - ACE_DEBUG ((LM_DEBUG, - ACE_TEXT ("TAO (%P|%t) - Codeset_Manager::set_tcs, ") - ACE_TEXT ("No codeset component in profile\n"))); - } - - remote.ForCharData.native_code_set = - TAO_Codeset_Manager::default_char_codeset; - remote.ForWcharData.native_code_set = - TAO_Codeset_Manager::default_wchar_codeset; - } - else - { - CONV_FRAME::CodeSetId tcs = - computeTCS (remote.ForCharData, - this->codeset_info_.ForCharData); - if (TAO_debug_level > 2) - ACE_DEBUG ((LM_DEBUG, - ACE_TEXT("TAO (%P|%t) - Codeset_Manager::set_tcs, ") - ACE_TEXT("setting char translator (%08x)\n"), - tcs)); - trans.char_translator(this->get_char_trans (tcs)); - - tcs = computeTCS (remote.ForWcharData, - this->codeset_info_.ForWcharData); - - if (TAO_debug_level > 2) - ACE_DEBUG ((LM_DEBUG, - ACE_TEXT("TAO (%P|%t) - Codeset_Manager::set_tcs, ") - ACE_TEXT("setting wchar translator (%08x)\n"), - tcs)); - trans.wchar_translator(this->get_wchar_trans (tcs)); - } -} - -void -TAO_Codeset_Manager::process_service_context (TAO_ServerRequest &request) -{ - if (request.transport()->is_tcs_set ()) - { - return; - } - - // Get the service Context from an object of TAO_ServerRequest - // and set the TCS values on the Transport - TAO_Service_Context &service_cntx = request.request_service_context (); - IOP::ServiceContext context; - context.context_id = IOP::CodeSets; - - CONV_FRAME::CodeSetId tcs_c = TAO_Codeset_Manager::default_char_codeset; - CONV_FRAME::CodeSetId tcs_w = TAO_Codeset_Manager::default_wchar_codeset; - if (service_cntx.get_context(context)) - { - // Convert the Service Context to Codeset Context - const char *buffer = - reinterpret_cast<const char*> (context.context_data.get_buffer ()); - - TAO_InputCDR cdr (buffer,context.context_data.length ()); - CORBA::Boolean byte_order; - - if (cdr >> TAO_InputCDR::to_boolean (byte_order)) - { - cdr.reset_byte_order (static_cast<int> (byte_order)); - cdr >> tcs_c; - cdr >> tcs_w; - } - } - else - { - if (TAO_debug_level > 0) - ACE_DEBUG ((LM_DEBUG, - ACE_TEXT("TAO (%P|%t) - Codeset_Manager::process_service_context ") - ACE_TEXT("no codeset context in request, inferring TAO backwards compatibility\n"))); - } - if (TAO_debug_level > 2) - { - ACE_DEBUG ((LM_DEBUG, - ACE_TEXT ("TAO (%P|%t) - Codeset_Manager::") - ACE_TEXT ("process_service_context, ") - ACE_TEXT ("using tcsc = %08x, tcsw = %08x\n"), - tcs_c,tcs_w)); - } - - request.transport()->char_translator(this->get_char_trans (tcs_c)); - request.transport()->wchar_translator(this->get_wchar_trans (tcs_w)); -} - -void -TAO_Codeset_Manager::generate_service_context (TAO_Operation_Details &opd, - TAO_Transport &trans) -{ - TAO_Service_Context &service_cntx = opd.request_service_context (); - CONV_FRAME::CodeSetContext codeset_cntx; - - // Generating codeset context - // Assuming the TCS values from Transport will be defaulted - TAO_Codeset_Translator_Factory *tf = trans.char_translator (); - - codeset_cntx.char_data = - tf ? tf->tcs () : this->codeset_info_.ForCharData.native_code_set; - - tf = trans.wchar_translator (); - - codeset_cntx.wchar_data = - tf ? tf->tcs () : this->codeset_info_.ForWcharData.native_code_set; - - if (TAO_debug_level > 2) - { - ACE_DEBUG ((LM_DEBUG, - ACE_TEXT ("TAO (%P|%t) - Codeset_Manager::") - ACE_TEXT ("generate_service_context, ") - ACE_TEXT ("using tcs_c = %08x, tcs_w = %08x\n"), - codeset_cntx.char_data, - codeset_cntx.wchar_data)); - } - - TAO_OutputCDR codeset_cdr; - codeset_cdr << TAO_OutputCDR::from_boolean (TAO_ENCAP_BYTE_ORDER); - codeset_cdr << codeset_cntx; - - service_cntx.set_context (IOP::CodeSets,codeset_cdr); -} - -/// Checks whether the NCS is a part of CCS -int -TAO_Codeset_Manager::isElementOf (CONV_FRAME::CodeSetId id, - CONV_FRAME::CodeSetComponent &cs_comp) -{ - for (CORBA::ULong i = 0L; - i < cs_comp.conversion_code_sets.length (); - ++i ) - { - if (id == cs_comp.conversion_code_sets[i]) - return 1; - } - - return 0; -} - -/// Find the Intersection of Client and Server CCS's -CONV_FRAME::CodeSetId -TAO_Codeset_Manager::intersectionOf (CONV_FRAME::CodeSetComponent &cs_comp1, - CONV_FRAME::CodeSetComponent &cs_comp2) -{ - for(CORBA::ULong index = 0L; - index < cs_comp1.conversion_code_sets.length(); - ++index ) - { - if (this->isElementOf(cs_comp1.conversion_code_sets[index], cs_comp2)) - { - return cs_comp1.conversion_code_sets[index]; - } - } - - return 0; -} - -int -TAO_Codeset_Manager::isCompatible(CONV_FRAME::CodeSetId cs1, - CONV_FRAME::CodeSetId cs2 ) -{ - // Call the is_compatible method of ACE_Codeset_Registry - return ACE_Codeset_Registry::is_compatible(cs1,cs2); -} - -/// returns the TCS for Char / Wchar -CONV_FRAME::CodeSetId -TAO_Codeset_Manager::computeTCS (CONV_FRAME::CodeSetComponent &remote, - CONV_FRAME::CodeSetComponent &local ) -{ - if (remote.native_code_set == local.native_code_set) - { - return local.native_code_set; - } - - if (this->isElementOf (remote.native_code_set, local)) - { - return remote.native_code_set; - } - - if (this->isElementOf (local.native_code_set, remote)) - { - return local.native_code_set; - } - - CONV_FRAME::CodeSetId tcs; - - if ((tcs = this->intersectionOf (remote, local)) == 0) - { - if (isCompatible (local.native_code_set, remote.native_code_set)) - { - return remote.native_code_set; - } - else - { - ACE_DECLARE_NEW_CORBA_ENV; - ACE_THROW_RETURN(CORBA::CODESET_INCOMPATIBLE (), 0); - } - } - - return tcs; -} - -void -TAO_Codeset_Manager::set_ncs_c (CONV_FRAME::CodeSetId ncs) -{ - this->codeset_info_.ForCharData.native_code_set = ncs; -} - -void -TAO_Codeset_Manager::set_ncs_w (CONV_FRAME::CodeSetId ncs,int mb) -{ - this->codeset_info_.ForWcharData.native_code_set = ncs; - ACE_OutputCDR::wchar_maxbytes(mb); -} - -int -TAO_Codeset_Manager::add_char_translator (const char *name) -{ - TAO_Codeset_Item *item = 0; - ACE_NEW_RETURN (item, TAO_Codeset_Item (name), -1); - - if (this->char_factories_.insert (item) == -1) - { - ACE_ERROR_RETURN ((LM_ERROR, - ACE_TEXT ("TAO (%P|%t) - Codeset_Manager::") - ACE_TEXT ("add_char_translator, ") - ACE_TEXT ("Unable to add Codeset ") - ACE_TEXT ("factories for %s: %m\n"), - ACE_TEXT_CHAR_TO_TCHAR (name)), - -1); - } - - return 0; -} - -int -TAO_Codeset_Manager::add_wchar_translator (const char *name) -{ - TAO_Codeset_Item *item = 0; - ACE_NEW_RETURN (item, TAO_Codeset_Item (name), -1); - - if (this->wchar_factories_.insert (item) == -1) - { - ACE_ERROR_RETURN ((LM_ERROR, - ACE_TEXT ("TAO (%P|%t) - Codeset_Manager::") - ACE_TEXT ("add_wchar_translator, ") - ACE_TEXT ("Unable to add Codeset ") - ACE_TEXT ("factories for %s: %m\n"), - ACE_TEXT_CHAR_TO_TCHAR (name)), - -1); - } - - return 0; -} - -void -TAO_Codeset_Manager::configure_codeset_factories() -{ - if (init_codeset_factories_i (this->char_factories_, - this->codeset_info_.ForCharData) == -1) - { - ACE_ERROR ((LM_ERROR, - ACE_TEXT ("TAO (%P|%t) - Codeset_Manager::") - ACE_TEXT ("configure_codeset_factories, failed to init ") - ACE_TEXT ("char codeset factories\n"))); - } - - if (init_codeset_factories_i (this->wchar_factories_, - this->codeset_info_.ForWcharData) == -1) - { - ACE_ERROR ((LM_ERROR, - ACE_TEXT ("TAO (%P|%t) - Codeset_Manager::") - ACE_TEXT ("configure_codeset_factories, failed to init ") - ACE_TEXT ("wchar codeset factories\n"))); - } - - if (this->codeset_info_.ForWcharData.native_code_set == 0) - { - ACE_OutputCDR::wchar_maxbytes(0); // disallow wchar when no ncs_w set - } -} - -/// Initialise the specific type codeset factories -int -TAO_Codeset_Manager::init_codeset_factories_i ( - TAO_CodesetFactorySet& factset, - CONV_FRAME::CodeSetComponent& cs_comp - ) -{ - TAO_CodesetFactorySetItor end = factset.end (); - TAO_CodesetFactorySetItor iter = factset.begin (); - - CONV_FRAME::CodeSetId ncs = cs_comp.native_code_set; - cs_comp.conversion_code_sets.length ( - static_cast<CORBA::ULong> (factset.size())); - CORBA::ULong index; - - for (index = 0; iter != end; ++iter) - { - const char *name = (*iter)->codeset_name (); - TAO_Codeset_Translator_Factory *trans = - ACE_Dynamic_Service<TAO_Codeset_Translator_Factory>::instance (name); - - if (trans == 0) - { - ACE_ERROR ((LM_ERROR, - ACE_TEXT ("TAO (%P|%t) - Codeset_Manager::") - ACE_TEXT ("init_codeset_factories_i, Unable to load ") - ACE_TEXT ("CodeSet <%s>, %m\n"), - ACE_TEXT_CHAR_TO_TCHAR(name))); - continue; - } - - if (trans->ncs() == ncs) - { - (*iter)->factory (trans); - cs_comp.conversion_code_sets[index++] = trans->tcs(); - - if (TAO_debug_level > 2) - { - ACE_DEBUG ((LM_DEBUG, - ACE_TEXT ("TAO (%P|%t) - Codeset_Manager::") - ACE_TEXT ("init_codeset_factories_i, Loaded CodeSet ") - ACE_TEXT ("<%s>, ncs = %08x tcs = %08x\n"), - ACE_TEXT_CHAR_TO_TCHAR(name), - trans->ncs(),trans->tcs())); - } - } - } - - cs_comp.conversion_code_sets.length(index); - return 0; -} - - -TAO_Codeset_Translator_Factory * -TAO_Codeset_Manager::get_char_trans (CONV_FRAME::CodeSetId tcs) -{ - if (this->codeset_info_.ForCharData.native_code_set == tcs) - return 0; - return this->get_translator_i (this->char_factories_,tcs); } -TAO_Codeset_Translator_Factory * -TAO_Codeset_Manager::get_wchar_trans (CONV_FRAME::CodeSetId tcs) +TAO_Codeset_Factory::~TAO_Codeset_Factory () { - if (this->codeset_info_.ForWcharData.native_code_set == tcs) - { - if (tcs != ACE_CODESET_ID_ISO_UTF_16) - return 0; - else - { - if (TAO_debug_level > 9) - ACE_DEBUG ((LM_DEBUG, - ACE_TEXT ("TAO (%P|%t) - Codeset_Manager::") - ACE_TEXT ("get_wchar_trans, ") - ACE_TEXT ("Using utf16 BOM translator\n"))); - if (this->utf16_bom_translator_ == 0) - { - this->utf16_bom_translator_ = - ACE_Dynamic_Service <UTF16_BOM_Factory>::instance ("UTF16_BOM_Factory"); - } - return this->utf16_bom_translator_; - } - } - return this->get_translator_i (this->wchar_factories_,tcs); } - - - -TAO_Codeset_Translator_Factory * -TAO_Codeset_Manager::get_translator_i (TAO_CodesetFactorySet& factset, - CONV_FRAME::CodeSetId tcs) -{ - const TAO_CodesetFactorySetItor end = factset.end (); - - for (TAO_CodesetFactorySetItor iter = factset.begin (); iter != end; ++iter) - { - TAO_Codeset_Translator_Factory *fact = (*iter)->factory (); - - if (fact && tcs == fact->tcs ()) - { - return fact; - } - } - - return 0; -} - - -//--------------------------------------------------------------------- -// Codeset Item -TAO_Codeset_Item::TAO_Codeset_Item (const char *name) - : name_ (0), - factory_ (0) -{ - if (name) - { - name_ = ACE_OS::strdup(name); - } -} - -TAO_Codeset_Item::~TAO_Codeset_Item (void) -{ - ACE_OS::free (this->name_); -} - -const char * -TAO_Codeset_Item::codeset_name (void) -{ - return this->name_; -} - -TAO_Codeset_Translator_Factory * -TAO_Codeset_Item::factory (void) -{ - return this->factory_; -} - -void -TAO_Codeset_Item::factory (TAO_Codeset_Translator_Factory *factory) -{ - this->factory_ = factory; -} - -// End of Codeset Item Class - - - -#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION) - -template class ACE_Dynamic_Service<TAO_Codeset_Translator_Factory>; - -template class ACE_Node<TAO_Codeset_Item*>; -template class ACE_Unbounded_Set<TAO_Codeset_Item*>; -template class ACE_Unbounded_Set_Iterator<TAO_Codeset_Item*>; - -#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA) - -#pragma instantiate ACE_Dynamic_Service<TAO_Codeset_Translator_Factory> -#pragma instantiate ACE_Node<TAO_Codeset_Item*> -/// -#pragma instantiate ACE_Unbounded_Set<TAO_Codeset_Item*> -#pragma instantiate ACE_Unbounded_Set_Iterator<TAO_Codeset_Item*> - -# endif diff --git a/TAO/tao/Codeset_Manager.h b/TAO/tao/Codeset_Manager.h index 273948d39bd..083be9500fa 100644 --- a/TAO/tao/Codeset_Manager.h +++ b/TAO/tao/Codeset_Manager.h @@ -23,7 +23,8 @@ # pragma once #endif /* ACE_LACKS_PRAGMA_ONCE */ -#include "ace/Unbounded_Set.h" +#include "ace/Service_Object.h" +#include "TAO_Export.h" class ACE_WChar_Codeset_Translator; @@ -33,61 +34,12 @@ class TAO_Operation_Details; class TAO_ServerRequest; class TAO_Tagged_Components; -class TAO_Codeset_Translator_Factory; +class TAO_Codeset_Translator_Base; class TAO_Codeset_Manager; // **************************************************************** /** - * @class TAO_Codeset_Item - * - * @brief A single element in the list of Codeset Translator Factories - * - * This class is used by the Codeset_Manager to store references to - * individual codeset factories. Only those translators that match the - * char or wchar native codeset will be kept in the list. - * - */ - -class TAO_Codeset_Item -{ -public: - friend class TAO_Codeset_Manager; - - /// Creator method, the codeset name can only be set when the - /// object is created. - TAO_Codeset_Item (const char *name); - - /// Destructor that deallocates the factory object if the - /// CodeSet_Item retains ownership. - ~TAO_Codeset_Item (void); - - /// Return a reference to the character representation of the codeset - /// factories name. - const char *codeset_name (void); - - /// Return a pointer to the codeset factory. - TAO_Codeset_Translator_Factory *factory (void); - - /// Set the factory pointer's value. - void factory (TAO_Codeset_Translator_Factory *factory); - -private: - // Prohibited - ACE_UNIMPLEMENTED_FUNC (TAO_Codeset_Item (const TAO_Codeset_Item&)) - ACE_UNIMPLEMENTED_FUNC (void operator= (const TAO_Codeset_Item&)) - -private: - /// Factory name. - char *name_; - - /// Pointer to factory object. - TAO_Codeset_Translator_Factory *factory_; -}; - -// **************************************************************** - -/** * @class TAO_Codeset_Manager * * @brief The encapsulation of logic for codeset negotiation @@ -108,112 +60,45 @@ class TAO_Export TAO_Codeset_Manager { public: - /// NCS for char is defaulted to ISO 8859-1:1987; Latin Alphabet No. 1 - static CONV_FRAME::CodeSetId default_char_codeset; - /// NCS for wchar is defaulted to 0 (not used), but people wishing to - /// provide a non-compliant default wchar codeset may do so. - static CONV_FRAME::CodeSetId default_wchar_codeset; - - TAO_Codeset_Manager (); - ~TAO_Codeset_Manager(); + virtual ~TAO_Codeset_Manager(); /// Called by an object of TAO_Acceptor to set NCS and CCS values for /// Char/Wchar in to the Object Reference. - void set_codeset (TAO_Tagged_Components& ) const; - - /// Called from an object of TAO::Invocation_Base to set TCS on the + virtual void set_codeset (TAO_Tagged_Components& ) const = 0; + /// + /// Called from an object of "TAO_GIOP_Invocation" to set TCS on the /// Transport - void set_tcs (TAO_Profile &theProfile, TAO_Transport &); + virtual void set_tcs (TAO_Profile &theProfile, TAO_Transport &) = 0; /// Called from an Object of TAO_Messaging for every request at server side /// to process service context and set TCS for Char/WChar - void process_service_context (TAO_ServerRequest &); + virtual void process_service_context (TAO_ServerRequest &) = 0; /// Called by a client object to generate service context /// at this time Transport has the TCS for Char and WChar - void generate_service_context (TAO_Operation_Details&, TAO_Transport & ); - - /// Called by the resource factory to set the native char codeset id - void set_ncs_c (CONV_FRAME::CodeSetId ncs); - - /// Called by the resource factory to set the native wchar codeset id. The - /// maxbytes value is used to communicate the width of untranslated wide - /// characters on the stream. This size may be smaller than the size of a - /// wchar_t. - void set_ncs_w (CONV_FRAME::CodeSetId ncs, int maxbytes = 0); - - /// Called by the resource factory to add a potential codeset translator - /// for char data. The actual factory will be added to the list later, if its - /// ncs matches that of the codeset manager. - int add_char_translator (const char *name); - - /// Called by the resource factory to add a potential codeset translator - /// for wchar data. The actual factory will be added to the list later, if - /// its ncs matches that of the codeset manager. - int add_wchar_translator (const char *name); - - /// Called by the resource factory to signify the end of initialization. - /// This will traverse the list of named codeset translator factories and add - /// any of those that have a native codeset id matching the manager's native - /// codeset id. - void configure_codeset_factories(); - -private: - /// Typedefs for containers containing the list of codesets - /// factories for character and wide character. - typedef ACE_Unbounded_Set<TAO_Codeset_Item*> - TAO_CodesetFactorySet; - - /// Iterators - typedef ACE_Unbounded_Set_Iterator<TAO_Codeset_Item*> - TAO_CodesetFactorySetItor; - - /// Compute the TCS for Char/WChar asper the CORBA Specification - CONV_FRAME::CodeSetId computeTCS (CONV_FRAME::CodeSetComponent &, - CONV_FRAME::CodeSetComponent &); - - /// Find CodesetId in the codeset component - int isElementOf (CONV_FRAME::CodeSetId, - CONV_FRAME::CodeSetComponent & ); - - /// Find the intersection of CodesetIds between Client and Server CCS - CONV_FRAME::CodeSetId intersectionOf (CONV_FRAME::CodeSetComponent &, - CONV_FRAME::CodeSetComponent &); - - /// Determine compatibility between two codesets via the codeset registry - int isCompatible (CONV_FRAME::CodeSetId, CONV_FRAME::CodeSetId); - - /// Traverse the list of codeset factories, populating the list of conversion - /// codeset values with the translated codeset id from each factory that has - /// a matching native codeset. Those factories that do not have a matching - /// codeset are not retained in the list. - int init_codeset_factories_i (TAO_CodesetFactorySet&, - CONV_FRAME::CodeSetComponent&); - - /// Get the translator between our ncs_c and the supplied tcs_c - TAO_Codeset_Translator_Factory * get_char_trans (CONV_FRAME::CodeSetId); - - /// Get the translator between our ncs_w and the supplied tcs_w - TAO_Codeset_Translator_Factory * get_wchar_trans (CONV_FRAME::CodeSetId); - - TAO_Codeset_Translator_Factory * get_translator_i (TAO_CodesetFactorySet&, - CONV_FRAME::CodeSetId); - - /// The CodeSetComponentInfo struct contains all of the information regarding - /// the code sets this application recognizes. This is where the native code - /// set for both char and wchar are stored. - CONV_FRAME::CodeSetComponentInfo codeset_info_; - - /// The lists of available translators for both chars and wchars. - TAO_CodesetFactorySet char_factories_; - TAO_CodesetFactorySet wchar_factories_; - - /// The UTF16 BOM (Byte Order Marker) translator is unique in that it is - /// required when UTF16 is used as both the native and transmitted codeset. - /// It exists to insert or extract the BOM preceeding Wchar data in the - /// stream. - TAO_Codeset_Translator_Factory *utf16_bom_translator_; + virtual void generate_service_context (TAO_Operation_Details&, TAO_Transport & ) = 0; + + virtual TAO_Codeset_Translator_Base * get_char_trans (CONV_FRAME::CodeSetId tcs) = 0; + + virtual TAO_Codeset_Translator_Base * get_wchar_trans (CONV_FRAME::CodeSetId tcs) = 0; + + virtual void open (void) = 0; + +}; +// **************************************************************** + +/** + * @class TAO_Codeset_Manager_Factory_Base + * + * @brief Abstract Base class for creating instances of the codeset manager. + */ + +class TAO_Export TAO_Codeset_Factory : public ACE_Service_Object +{ +public: + virtual ~TAO_Codeset_Factory (); + virtual TAO_Codeset_Manager *create(TAO_ORB_Core *orb_core) = 0; }; #include /**/ "ace/post.h" diff --git a/TAO/tao/Codeset_Translator_Base.cpp b/TAO/tao/Codeset_Translator_Base.cpp new file mode 100644 index 00000000000..c5d222373b2 --- /dev/null +++ b/TAO/tao/Codeset_Translator_Base.cpp @@ -0,0 +1,29 @@ +// -*- C++ -*- + +// ===================================================================== +// +// = LIBRARY +// TAO/tao +// +// = FILENAME +// Codeset_Translator_Base.cpp +// +// = DESCRIPTION The base for all the translator factories. Translator +// factories are responsible for supplying the proper translator on +// demand. +// +// = AUTHORS +// Phil Mesnier <mesnier_p@ociweb.com> +// +// ===================================================================== + +#include "Codeset_Translator_Base.h" + +ACE_RCSID (tao, + Codeset_Translator_Base, + "$Id$") + +TAO_Codeset_Translator_Base::~TAO_Codeset_Translator_Base () +{ + +} diff --git a/TAO/tao/Codeset_Translator_Base.h b/TAO/tao/Codeset_Translator_Base.h new file mode 100644 index 00000000000..cb87201e9ce --- /dev/null +++ b/TAO/tao/Codeset_Translator_Base.h @@ -0,0 +1,72 @@ +// -*- C++ -*- + +// =================================================================== +/** + * @file Codeset_Translator_Base.h + * + * $Id$ + * + * @author Phil Mesnier <mesnier_p@ociweb.com> + */ +// ========================= + +#ifndef TAO_CODESET_TRANSLATOR_BASE_H +#define TAO_CODESET_TRANSLATOR_BASE_H + +#include /**/ "ace/pre.h" +#include "ace/Service_Object.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +#include "tao/CONV_FRAMEC.h" +#include "tao/Codeset_Translator_Base.h" +#include "TAO_Export.h" + +class TAO_InputCDR; +class TAO_OutputCDR; + +class ACE_Char_Codeset_Translator; +class ACE_WChar_Codeset_Translator; + + +// **************************************************************** + +/** + * @class TAO_Codeset_Translator_Base + * + * @brief Abstract base Translator component for interaction with TAO + * + * Certain elements of TAO need an interface defined in the TAO module + * Through which the actual codeset translator instance may be assigned + * to CDR streams. + */ + +class TAO_Export TAO_Codeset_Translator_Base +{ +public: + virtual ~TAO_Codeset_Translator_Base (); + virtual int init (int argc, ACE_TCHAR *argv[]) = 0; + + /// Get the native codeset ID from the base. There is no reasonable + /// default for this method, so it is left abstract. + virtual CONV_FRAME::CodeSetId ncs () const = 0; + + /// Get the translated codeset ID from the base. There is no reasonable + /// default for this method, so it is left abstract. + virtual CONV_FRAME::CodeSetId tcs () const = 0; + + /// Assign the translator to the supplied input CDR. This is left abstract + /// since the base base does not have a reference to the actual translator + /// instance. The template instance provides this implementation. + virtual void assign (TAO_InputCDR *) const = 0; + + /// Assign the translator to the supplied output CDR. This is left abstract + /// since the base base does not have a reference to the actual translator + /// instance. The template instance provides this implementation. + virtual void assign (TAO_OutputCDR *) const = 0; +}; + +#include /**/ "ace/post.h" +#endif /* TAO_Codeset_Translator_Base */ diff --git a/TAO/tao/Codeset_Translator_Factory.h b/TAO/tao/Codeset_Translator_Factory.h index 8c3cd1d8aae..98ad65a0a8b 100644 --- a/TAO/tao/Codeset_Translator_Factory.h +++ b/TAO/tao/Codeset_Translator_Factory.h @@ -10,93 +10,20 @@ */ // ========================= -#ifndef TAO_CODESET_TRANSLATOR_FACTORY_H -#define TAO_CODESET_TRANSLATOR_FACTORY_H +#ifndef TAO_CODESET_TRANSLATOR_FACTORY_DEPRECATED_H +#define TAO_CODESET_TRANSLATOR_FACTORY_DEPRECATED_H #include /**/ "ace/pre.h" -#include "ace/Service_Object.h" -#if !defined (ACE_LACKS_PRAGMA_ONCE) -# pragma once -#endif /* ACE_LACKS_PRAGMA_ONCE */ +// TAO_Codeset_Translator_Factroy is now part of the TAO_Codeset +// library. Since it is possible that people have supplied their +// own codeset translator classes, this header is included as a +// migration aid. +// +// Anyone with their own translator should also add the new +// codeset.mpb to their MPC project's list of dependencies. -#include "tao/CONV_FRAMEC.h" - -class TAO_InputCDR; -class TAO_OutputCDR; - -class ACE_Char_Codeset_Translator; -class ACE_WChar_Codeset_Translator; - - -// **************************************************************** - -/** - * @class TAO_Codeset_Translator_Factory - * - * @brief Abstract base class for factories providing codeset translators - * - * The codeset translator factory is a loadable service object. It is used to - * supply the actual translator used in converting between two codesets. The - * intent of using a factory is to avoid requiring codeset translators to be - * multiply inherited both from the translator base class and the service - * object base. The translator factory is also responsible for assigning - * translators to CDR streams. Since there is no common base class between - * input and output CDRs, the assingment code must be duplicated. - */ - -class TAO_Export TAO_Codeset_Translator_Factory : - public ACE_Service_Object -{ -public: - TAO_Codeset_Translator_Factory (); - virtual ~TAO_Codeset_Translator_Factory (); - virtual int init (int argc, ACE_TCHAR *argv[]); - - /// Get the native codeset ID from the factory. There is no reasonable - /// default for this method, so it is left abstract. - virtual CONV_FRAME::CodeSetId ncs () const = 0; - - /// Get the translated codeset ID from the factory. There is no reasonable - /// default for this method, so it is left abstract. - virtual CONV_FRAME::CodeSetId tcs () const = 0; - - /// Assign the translator to the supplied input CDR. This is left abstract - /// since the factory base does not have a reference to the actual translator - /// instance. The template instance provides this implementation. - virtual void assign (TAO_InputCDR *) const = 0; - - /// Assign the translator to the supplied output CDR. This is left abstract - /// since the factory base does not have a reference to the actual translator - /// instance. The template instance provides this implementation. - virtual void assign (TAO_OutputCDR *) const = 0; - -protected: - - /// Assign the translator to the supplied input CDR. The template instance - /// will have a translator that is based on either the Char or Wchar - /// translator, so the compiler will select the appropriate call from - /// assign(). - void assign_i (TAO_InputCDR *, ACE_Char_Codeset_Translator* ) const; - /// Assign the translator to the supplied input CDR. The template instance - /// will have a translator that is based on either the Char or Wchar - /// translator, so the compiler will select the appropriate call from - /// assign(). - void assign_i (TAO_InputCDR *, ACE_WChar_Codeset_Translator* ) const; - /// Assign the translator to the supplied output CDR. The template instance - /// will have a translator that is based on either the Char or Wchar - /// translator, so the compiler will select the appropriate call from - /// assign(). - void assign_i (TAO_OutputCDR *, ACE_Char_Codeset_Translator* ) const; - /// Assign the translator to the supplied output CDR. The template instance - /// will have a translator that is based on either the Char or Wchar - /// translator, so the compiler will select the appropriate call from - /// assign(). - void assign_i (TAO_OutputCDR *, ACE_WChar_Codeset_Translator* ) const; -}; - -// Get the template includes last -#include "tao/Codeset_Translator_Factory_T.h" +#include "tao/Codeset/Codeset_Translator_Factory.h" #include /**/ "ace/post.h" #endif /* TAO_Codeset_Translator_Factory */ diff --git a/TAO/tao/GIOP_Message_Base.cpp b/TAO/tao/GIOP_Message_Base.cpp index 0095a74a692..3aeca12a984 100644 --- a/TAO/tao/GIOP_Message_Base.cpp +++ b/TAO/tao/GIOP_Message_Base.cpp @@ -807,8 +807,12 @@ TAO_GIOP_Message_Base::process_request (TAO_Transport *transport, parse_error = parser->parse_request_header (request); - request.orb_core()->codeset_manager()->process_service_context(request); - transport->assign_translators(&cdr,&output); + TAO_Codeset_Manager *csm = request.orb_core()->codeset_manager(); + if (csm) + { + csm->process_service_context(request); + transport->assign_translators(&cdr,&output); + } // Throw an exception if the if (parse_error != 0) diff --git a/TAO/tao/GIOP_Message_Lite.cpp b/TAO/tao/GIOP_Message_Lite.cpp index d56e5a5dee0..b64d83e6940 100644 --- a/TAO/tao/GIOP_Message_Lite.cpp +++ b/TAO/tao/GIOP_Message_Lite.cpp @@ -711,8 +711,12 @@ TAO_GIOP_Message_Lite::process_request (TAO_Transport *transport, parse_error = this->parse_request_header (request); - request.orb_core()->codeset_manager()->process_service_context(request); - transport->assign_translators(&cdr,&output); + TAO_Codeset_Manager *csm = request.orb_core()->codeset_manager(); + if (csm) + { + csm->process_service_context(request); + transport->assign_translators(&cdr,&output); + } // Throw an exception if the if (parse_error != 0) diff --git a/TAO/tao/IIOP_Acceptor.cpp b/TAO/tao/IIOP_Acceptor.cpp index 761977d8cda..4e4e0cf7fa9 100644 --- a/TAO/tao/IIOP_Acceptor.cpp +++ b/TAO/tao/IIOP_Acceptor.cpp @@ -156,8 +156,9 @@ TAO_IIOP_Acceptor::create_new_profile (const TAO::ObjectKey &object_key, pfile->tagged_components ().set_orb_type (TAO_ORB_TYPE); - this->orb_core_->codeset_manager()-> - set_codeset(pfile->tagged_components()); + TAO_Codeset_Manager *csm = this->orb_core_->codeset_manager(); + if (csm) + csm->set_codeset(pfile->tagged_components()); } return 0; @@ -212,8 +213,9 @@ TAO_IIOP_Acceptor::create_shared_profile (const TAO::ObjectKey &object_key, && (this->version_.major >= 1 && this->version_.minor >= 1)) { iiop_profile->tagged_components ().set_orb_type (TAO_ORB_TYPE); - this->orb_core_->codeset_manager()-> - set_codeset(iiop_profile->tagged_components()); + TAO_Codeset_Manager *csm = this->orb_core_->codeset_manager(); + if (csm) + csm->set_codeset(iiop_profile->tagged_components()); } index = 1; diff --git a/TAO/tao/ORB_Core.cpp b/TAO/tao/ORB_Core.cpp index be48e5cb124..010f9fb4f9a 100644 --- a/TAO/tao/ORB_Core.cpp +++ b/TAO/tao/ORB_Core.cpp @@ -35,6 +35,7 @@ #include "PolicyFactory_Registry_Adapter.h" #include "PolicyFactory_Registry_Factory.h" #include "ORBInitializer_Registry_Adapter.h" +#include "Codeset_Manager.h" #if (TAO_HAS_CORBA_MESSAGING == 1) #include "Policy_Manager.h" @@ -269,6 +270,8 @@ TAO_ORB_Core::~TAO_ORB_Core (void) // Don't delete, is a process wide singleton shared by all orbs orbinitializer_registry_ = 0; + delete this->codeset_manager_; + CORBA::release (this->orb_); } @@ -349,6 +352,12 @@ TAO_ORB_Core::init (int &argc, char *argv[] ACE_ENV_ARG_DECL) this->lock_, -1); +#if defined (TAO_NEGOTIATE_CODESETS) && (TAO_NEGOTIATE_CODESETS == 1) + int negotiate_codesets = 1; +#else + int negotiate_codesets = 0; +#endif /* TAO_NEGOTIATE_CODESETS */ + // Pick up the value of the use_implrepo_ flag from an environment variable // called "TAO_USE_IMR". Do it here so that it can be overridden by // the "-ORBUseIMR" command line argument. @@ -881,6 +890,14 @@ TAO_ORB_Core::init (int &argc, char *argv[] ACE_ENV_ARG_DECL) arg_shifter.consume_arg (); } + else if ((current_arg = arg_shifter.get_the_parameter + (ACE_LIB_TEXT("-ORBNegotiateCodesets")))) + { + negotiate_codesets = + (ACE_OS::atoi (current_arg)); + + arg_shifter.consume_arg (); + } else if ((current_arg = arg_shifter.get_the_parameter (ACE_TEXT("-ORBSingleReadOptimization")))) { @@ -1004,7 +1021,7 @@ TAO_ORB_Core::init (int &argc, char *argv[] ACE_ENV_ARG_DECL) CORBA::COMPLETED_NO), -1); } - +#if 0 // @@Phil: Could we add a -ORB option to prevent creation of codeset // manager. This adds to our runtime footprint. It would be awesome // if we can do away with this if the user doesnt want to. Does that @@ -1023,6 +1040,7 @@ TAO_ORB_Core::init (int &argc, char *argv[] ACE_ENV_ARG_DECL) CORBA::COMPLETED_NO), -1); } +#endif // @@ ???? // Make sure the reactor is initialized... @@ -1135,9 +1153,9 @@ TAO_ORB_Core::init (int &argc, char *argv[] ACE_ENV_ARG_DECL) this->orb_params ()->service_port (IMPLREPOSERVICE, ir_port); this->orb_params ()->use_dotted_decimal_addresses (dotted_decimal_addresses); - // When caching incoming transports don't use the host name if + // When caching incoming transports don't use the host name if // -ORBDottedDecimalAddresses or -ORBNoServerSideNameLookups is true. - this->orb_params ()->cache_incoming_by_dotted_decimal_address + this->orb_params ()->cache_incoming_by_dotted_decimal_address (no_server_side_name_lookups || dotted_decimal_addresses); this->orb_params ()->linger (linger); @@ -1151,6 +1169,8 @@ TAO_ORB_Core::init (int &argc, char *argv[] ACE_ENV_ARG_DECL) this->orb_params ()->std_profile_components (std_profile_components); + this->orb_params ()->negotiate_codesets (negotiate_codesets); + // Set up the pluggable protocol infrastructure. First get a // pointer to the protocol factories set, then obtain pointers to // all factories loaded by the service configurator. @@ -2366,6 +2386,39 @@ TAO_ORB_Core::resolve_ior_table_i (ACE_ENV_SINGLE_ARG_DECL) } } +void +TAO_ORB_Core::load_codeset_manager () +{ + if (this->orb_params()->negotiate_codesets() == 0) + return; + + TAO_Codeset_Factory *factory = + ACE_Dynamic_Service<TAO_Codeset_Factory>::instance ("TAO_Codeset"); + if (factory == 0) + { + ACE_Service_Config::process_directive + (ACE_DYNAMIC_SERVICE_DIRECTIVE("TAO_Codeset", + "TAO_Codeset", + "_make_TAO_Codeset_Manager_Factory", + "")); + factory = + ACE_Dynamic_Service<TAO_Codeset_Factory>::instance ("TAO_Codeset"); + } + if (factory == 0) + { + if (TAO_debug_level > 0) + ACE_ERROR ((LM_ERROR, + ACE_TEXT("(%P|%t) ORB_Core: ") + ACE_TEXT("Unable to initialize Codeset Manager\n"))); + return; + } + + this->codeset_manager_ = factory->create (this); + if (this->codeset_manager_) + this->codeset_manager_->open(); + +} + int TAO_ORB_Core::set_endpoint_helper (const ACE_CString &lane, const ACE_CString &endpoints diff --git a/TAO/tao/ORB_Core.h b/TAO/tao/ORB_Core.h index dc0e27f4203..36f35066888 100644 --- a/TAO/tao/ORB_Core.h +++ b/TAO/tao/ORB_Core.h @@ -250,52 +250,6 @@ public: ACE_ENV_ARG_DECL); //@} - /** - * @name Default Code Set Translators - * - * Get the default codeset translators. - * - * @par - * In most configurations these are just <nil> objects, but they can - * be set to something different if the native character sets are - * not ISO8869 (aka Latin/1, UTF-8) and UNICODE (aka UTF-16). - * - * @note - * This is just note on how the translator database coule be - * implemented: use the Service Configurator to load the translator, - * and then use the CodesetId (an unsigned long) to translate the - * character set code into the Service Object name. - * @par - * The default resource factory could parse command line options - * like: - * - -ORBcharcodeset 0x00010001=ISO8859 - * - -ORBcharcodeset 0x10020417=IBM1047 - * - -ORBwcharcodeset 0x00010106=ISOIEC10646 - * that would let the user experiment with different translators - * and plug them in on demand. - *@par - * - * We should also think about how translators will report conversion - * failures and how to simplify the implementation of char - * translators (it would seem like just a couple of arrays are - * needed, maybe the arrays should be dynamically loaded and the - * implementation would remain constant? Just a thought. - * - */ - //@{ - /// Convert from ISO8859 to the native character set - ACE_Char_Codeset_Translator *from_iso8859 (void) const; - - /// Convert from the native character set to ISO8859 - ACE_Char_Codeset_Translator *to_iso8859 (void) const; - - /// Convert from UNICODE to the native wide character set - ACE_WChar_Codeset_Translator *from_unicode (void) const; - - /// Convert from the native wide character set to UNICODE - ACE_WChar_Codeset_Translator *to_unicode (void) const; - //@} - /// Set/get the collocation flags //@{ void optimize_collocation_objects (CORBA::Boolean opt); @@ -908,8 +862,9 @@ public: */ TAO_Flushing_Strategy *flushing_strategy (void); - /// Get Code Set Manager + /// Get/Set Code Set Manager TAO_Codeset_Manager *codeset_manager (void); + void codeset_manager (TAO_Codeset_Manager *); typedef ACE_Array_Map<ACE_CString, ACE_CString> InitRefMap; @@ -1013,6 +968,10 @@ private: CORBA::Boolean is_collocation_enabled (TAO_ORB_Core *other_orb, const TAO_MProfile &mp); + /// Load the codeset manager, if the option is set and the library + /// is available. + void load_codeset_manager (ACE_ENV_SINGLE_ARG_DECL_WITH_DEFAULTS); + protected: /// Synchronize internal state... diff --git a/TAO/tao/ORB_Core.i b/TAO/tao/ORB_Core.i index f02c798655c..abfba4e9896 100644 --- a/TAO/tao/ORB_Core.i +++ b/TAO/tao/ORB_Core.i @@ -256,6 +256,29 @@ TAO_ORB_Core::orb_params(void) return &(this->orb_params_); } + +ACE_INLINE TAO_Codeset_Manager * +TAO_ORB_Core::codeset_manager() +{ + if (this->orb_params()->negotiate_codesets() == 0) + return 0; + if (this->codeset_manager_ == 0) + { + // This causes a factory to be loaded which will call + // the codeset_manager setter in this thread. + this->load_codeset_manager(); + if (this->codeset_manager_ == 0) + this->orb_params()->negotiate_codesets(false); + } + return this->codeset_manager_; +} + +ACE_INLINE void +TAO_ORB_Core::codeset_manager (TAO_Codeset_Manager *tcm) +{ + this->codeset_manager_ = tcm; +}; + #define TAO_OC_RETRIEVE(member) \ ((this->member##_ == 0) \ ? (this->member##_ = this->resource_factory ()->get_##member ()) \ @@ -273,12 +296,6 @@ TAO_ORB_Core::parser_registry (void) return &this->parser_registry_; } -ACE_INLINE TAO_Codeset_Manager * -TAO_ORB_Core::codeset_manager() -{ - return this->codeset_manager_; -} - #undef TAO_OC_RETRIEVE #if (TAO_HAS_CORBA_MESSAGING == 1) diff --git a/TAO/tao/Profile_Transport_Resolver.cpp b/TAO/tao/Profile_Transport_Resolver.cpp index 0fab758b90c..8c88d2a7db0 100644 --- a/TAO/tao/Profile_Transport_Resolver.cpp +++ b/TAO/tao/Profile_Transport_Resolver.cpp @@ -109,7 +109,8 @@ namespace TAO { TAO_Codeset_Manager *tcm = this->stub_->orb_core ()->codeset_manager (); - tcm->set_tcs (*this->profile_, *this->transport_); + if (tcm) + tcm->set_tcs (*this->profile_, *this->transport_); } } diff --git a/TAO/tao/Resource_Factory.cpp b/TAO/tao/Resource_Factory.cpp index 23e714452b3..d5aeebf9f4e 100644 --- a/TAO/tao/Resource_Factory.cpp +++ b/TAO/tao/Resource_Factory.cpp @@ -48,6 +48,82 @@ TAO_Protocol_Item::factory (TAO_Protocol_Factory *factory, this->factory_owner_ = owner; } +// ********************************************************************** + +TAO_Codeset_Descriptor::TAO_Codeset_Descriptor () + :ncs_ (0), + max_bytes_ (1), + ncs_set_ (0), + trans_base_(0) +{ +} + +TAO_Codeset_Descriptor::~TAO_Codeset_Descriptor () +{ + Translator_Node *temp = trans_base_; + while (temp) + { + temp = trans_base_->next_; + delete [] trans_base_->name_; + delete trans_base_; + trans_base_ = temp; + } +} + +void +TAO_Codeset_Descriptor::ncs (ACE_CDR::ULong ncs, int mb) +{ + this->ncs_ = ncs; + this->max_bytes_ = mb; + this->ncs_set_ = 1; +} + +ACE_CDR::ULong +TAO_Codeset_Descriptor::ncs (void) const +{ + return this->ncs_; +} + +int +TAO_Codeset_Descriptor::max_bytes (void) const +{ + return this->max_bytes_; +} + +int +TAO_Codeset_Descriptor::ncs_set (void) const +{ + return this->ncs_set_; +} + +void +TAO_Codeset_Descriptor::add_translator (const char *name) +{ + Translator_Node *temp = trans_base_; + if (this->trans_base_ == 0) + { + this->trans_base_ = new Translator_Node; + temp = trans_base_; + } + else + { + while (temp->next_ != 0) + temp = temp->next_; + temp->next_ = new Translator_Node; + temp = temp->next_; + } + temp->name_ = new char[ACE_OS::strlen (name) + 1]; + ACE_OS::strcpy (temp->name_,name); + temp->next_ = 0; +} + +const TAO_Codeset_Descriptor::Translator_Node * +TAO_Codeset_Descriptor::translators (void) const +{ + return this->trans_base_; +} + +// ******************************************************************** TAO_Resource_Factory::TAO_Resource_Factory (void) { @@ -156,8 +232,8 @@ TAO_Resource_Factory::get_protocol_factories (void) return 0; } -TAO_Codeset_Manager * -TAO_Resource_Factory::get_codeset_manager (void) +const TAO_Codeset_Descriptor * +TAO_Resource_Factory::get_codeset_descriptor (int) const { return 0; } diff --git a/TAO/tao/Resource_Factory.h b/TAO/tao/Resource_Factory.h index d78937a555c..52f29c06cb1 100644 --- a/TAO/tao/Resource_Factory.h +++ b/TAO/tao/Resource_Factory.h @@ -23,6 +23,7 @@ #include "ace/Unbounded_Set.h" #include "ace/SString.h" +#include "ace/CDR_Base.h" #include "tao/TAO_Export.h" @@ -34,7 +35,6 @@ class TAO_Flushing_Strategy; class TAO_Connection_Purging_Strategy; class TAO_LF_Strategy; -class TAO_Codeset_Manager; class ACE_Lock; // **************************************************************** @@ -86,6 +86,34 @@ typedef ACE_Unbounded_Set_Iterator<TAO_Protocol_Item*> // **************************************************************** +class TAO_Export TAO_Codeset_Descriptor +{ +public: + TAO_Codeset_Descriptor (); + ~TAO_Codeset_Descriptor (); + struct Translator_Node + { + char *name_; + Translator_Node *next_; + }; + void ncs (ACE_CDR::ULong ncs, int mb = 0); + ACE_CDR::ULong ncs (void) const; + int max_bytes (void) const; + + int ncs_set (void) const; + + void add_translator (const char *name); + const Translator_Node *translators (void) const; + +private: + ACE_CDR::ULong ncs_; + int max_bytes_; + int ncs_set_; + Translator_Node *trans_base_; +}; + +// **************************************************************** + /** * @class TAO_Resource_Factory * @@ -175,7 +203,8 @@ public: */ virtual TAO_ProtocolFactorySet *get_protocol_factories (void); - virtual TAO_Codeset_Manager *get_codeset_manager(void); + // Returns either the char or wchar codeset descriptor object. + virtual const TAO_Codeset_Descriptor *get_codeset_descriptor(int for_wchar=0) const; /** * This method will loop through the protocol list and diff --git a/TAO/tao/Transport.cpp b/TAO/tao/Transport.cpp index cf91bf779bc..17b7e2cad92 100644 --- a/TAO/tao/Transport.cpp +++ b/TAO/tao/Transport.cpp @@ -17,7 +17,7 @@ #include "Thread_Lane_Resources.h" #include "Resume_Handle.h" #include "Codeset_Manager.h" -#include "Codeset_Translator_Factory.h" +#include "Codeset_Translator_Base.h" #include "debug.h" #include "CDR.h" #include "ORB_Core.h" @@ -291,10 +291,9 @@ TAO_Transport::generate_request_header ( // on a particular connection. if (this->first_request_) { - this->orb_core ()->codeset_manager ()->generate_service_context ( - opdetails, - *this - ); + TAO_Codeset_Manager *csm = this->orb_core ()->codeset_manager (); + if (csm) + csm->generate_service_context (opdetails,*this); } if (this->messaging_object ()->generate_request_header (opdetails, diff --git a/TAO/tao/Transport.h b/TAO/tao/Transport.h index aaabf5aebdd..be7b5573629 100644 --- a/TAO/tao/Transport.h +++ b/TAO/tao/Transport.h @@ -35,7 +35,7 @@ class TAO_Transport_Mux_Strategy; class TAO_Wait_Strategy; class TAO_Connection_Handler; class TAO_Pluggable_Messaging; -class TAO_Codeset_Translator_Factory; +class TAO_Codeset_Translator_Base; class TAO_Queued_Message; class TAO_Synch_Queued_Message; @@ -744,16 +744,16 @@ public: size_t sent_byte_count (void); /// CodeSet Negotiation - Get the char codeset translator factory - TAO_Codeset_Translator_Factory *char_translator (void) const; + TAO_Codeset_Translator_Base *char_translator (void) const; /// CodeSet Negotiation - Get the wchar codeset translator factory - TAO_Codeset_Translator_Factory *wchar_translator (void) const; + TAO_Codeset_Translator_Base *wchar_translator (void) const; /// CodeSet negotiation - Set the char codeset translator factory - void char_translator (TAO_Codeset_Translator_Factory *); + void char_translator (TAO_Codeset_Translator_Base *); /// CodeSet negotiation - Set the wchar codeset translator factory - void wchar_translator (TAO_Codeset_Translator_Factory *); + void wchar_translator (TAO_Codeset_Translator_Base *); /// Use the Transport's codeset factories to set the translator for input /// and output CDRs. @@ -1007,8 +1007,8 @@ private: /// with the DSCP stuff around there. Do you agree? /// Additional member values required to support codeset translation - TAO_Codeset_Translator_Factory *char_translator_; - TAO_Codeset_Translator_Factory *wchar_translator_; + TAO_Codeset_Translator_Base *char_translator_; + TAO_Codeset_Translator_Base *wchar_translator_; /// The tcs_set_ flag indicates that negotiation has occured and so the /// translators are correct, since a null translator is valid if both ends diff --git a/TAO/tao/Transport.inl b/TAO/tao/Transport.inl index 7eeacf34ca7..c476cf5ed4a 100644 --- a/TAO/tao/Transport.inl +++ b/TAO/tao/Transport.inl @@ -118,27 +118,27 @@ TAO_Transport::reset_flush_timer (void) // codeset related methods -ACE_INLINE TAO_Codeset_Translator_Factory * +ACE_INLINE TAO_Codeset_Translator_Base * TAO_Transport::char_translator (void) const { return this->char_translator_; } -ACE_INLINE TAO_Codeset_Translator_Factory * +ACE_INLINE TAO_Codeset_Translator_Base * TAO_Transport::wchar_translator (void) const { return this->wchar_translator_; } ACE_INLINE void -TAO_Transport::char_translator (TAO_Codeset_Translator_Factory *tf) +TAO_Transport::char_translator (TAO_Codeset_Translator_Base *tf) { this->char_translator_ = tf; this->tcs_set_ = 1; } ACE_INLINE void -TAO_Transport::wchar_translator (TAO_Codeset_Translator_Factory *tf) +TAO_Transport::wchar_translator (TAO_Codeset_Translator_Base *tf) { this->wchar_translator_ = tf; this->tcs_set_ = 1; diff --git a/TAO/tao/default_resource.cpp b/TAO/tao/default_resource.cpp index 38acaa51995..4acaa884008 100644 --- a/TAO/tao/default_resource.cpp +++ b/TAO/tao/default_resource.cpp @@ -11,7 +11,6 @@ #include "tao/Leader_Follower_Flushing_Strategy.h" #include "tao/LRU_Connection_Purging_Strategy.h" #include "tao/LF_Strategy_Complete.h" -#include "tao/Codeset_Manager.h" #include "ace/TP_Reactor.h" #include "ace/Dynamic_Service.h" @@ -43,7 +42,8 @@ TAO_Default_Resource_Factory::TAO_Default_Resource_Factory (void) , object_key_table_lock_type_ (TAO_THREAD_LOCK) , corba_object_lock_type_ (TAO_THREAD_LOCK) , flushing_strategy_type_ (TAO_LEADER_FOLLOWER_FLUSHING) - , codeset_manager_ (0) + , char_codeset_descriptor_ () + , wchar_codeset_descriptor_ () , resource_usage_strategy_ (TAO_Resource_Factory::TAO_EAGER) , drop_replies_ (true) { @@ -71,8 +71,6 @@ TAO_Default_Resource_Factory::~TAO_Default_Resource_Factory (void) CORBA::string_free (this->parser_names_[i]); delete [] this->parser_names_; - - delete this->codeset_manager_; } int @@ -164,7 +162,7 @@ TAO_Default_Resource_Factory::init (int argc, ACE_TCHAR *argv[]) ACE_TEXT("-ORBNativeCharCodeSet")) == 0) { ++curarg; - CONV_FRAME::CodeSetId ncs; + ACE_CDR::ULong ncs; if (ACE_Codeset_Registry::locale_to_registry (ACE_TEXT_ALWAYS_CHAR(argv[curarg]), ncs) == 0) { @@ -172,7 +170,6 @@ TAO_Default_Resource_Factory::init (int argc, ACE_TCHAR *argv[]) ncs = ACE_OS::strtoul(ACE_TEXT_ALWAYS_CHAR(argv[curarg]), endPtr, 0); } - // Validate the CodesetId if (ACE_Codeset_Registry::get_max_bytes(ncs) == 0) { @@ -182,26 +179,24 @@ TAO_Default_Resource_Factory::init (int argc, ACE_TCHAR *argv[]) ncs)); return -1; } - TAO_Codeset_Manager *csm = this->get_codeset_manager(); - if (csm) - csm->set_ncs_c(ncs); + this->char_codeset_descriptor_.ncs (ncs); } else if (ACE_OS::strcasecmp (argv[curarg], ACE_TEXT("-ORBNativeWCharCodeSet")) == 0) { ++curarg; - CONV_FRAME::CodeSetId ncs; - if (ACE_Codeset_Registry::locale_to_registry (ACE_TEXT_ALWAYS_CHAR (argv[curarg]), + ACE_CDR::ULong ncs; + if (ACE_Codeset_Registry::locale_to_registry(ACE_TEXT_ALWAYS_CHAR(argv[curarg]), ncs) == 0) { char **endPtr = 0; - ncs = ACE_OS::strtoul (ACE_TEXT_ALWAYS_CHAR(argv[curarg]), + ncs = ACE_OS::strtoul(ACE_TEXT_ALWAYS_CHAR(argv[curarg]), endPtr, 0); } // Validate the CodesetId int mb = ACE_Codeset_Registry::get_max_bytes(ncs); - if (mb == 0 || static_cast<size_t> (mb) > sizeof (ACE_CDR::WChar)) + if (mb == 0 || static_cast<size_t>(mb) > sizeof (ACE_CDR::WChar)) { if (TAO_debug_level > 0) ACE_ERROR((LM_ERROR, @@ -209,9 +204,7 @@ TAO_Default_Resource_Factory::init (int argc, ACE_TCHAR *argv[]) ncs)); return -1; } - TAO_Codeset_Manager *csm = this->get_codeset_manager(); - if (csm) - csm->set_ncs_w(ncs,mb); + this->wchar_codeset_descriptor_.ncs (ncs, mb); } else if (ACE_OS::strcasecmp (argv[curarg], @@ -220,10 +213,7 @@ TAO_Default_Resource_Factory::init (int argc, ACE_TCHAR *argv[]) ++curarg; if (curarg < argc) { - TAO_Codeset_Manager *csm = this->get_codeset_manager(); - if (csm) - if (csm->add_char_translator(ACE_TEXT_ALWAYS_CHAR (argv[curarg])) == -1) - return -1; + this->char_codeset_descriptor_.add_translator (ACE_TEXT_ALWAYS_CHAR(argv[curarg])); } } @@ -234,10 +224,7 @@ TAO_Default_Resource_Factory::init (int argc, ACE_TCHAR *argv[]) ++curarg; if (curarg < argc) { - TAO_Codeset_Manager *csm = this->get_codeset_manager(); - if (csm) - if (csm->add_wchar_translator(ACE_TEXT_ALWAYS_CHAR(argv[curarg])) == -1) - return -1; + this->wchar_codeset_descriptor_.add_translator (ACE_TEXT_ALWAYS_CHAR(argv[curarg])); } } @@ -495,10 +482,6 @@ TAO_Default_Resource_Factory::init (int argc, ACE_TCHAR *argv[]) } } - TAO_Codeset_Manager *csm = this->get_codeset_manager(); - if (csm) - csm->configure_codeset_factories(); - return 0; } @@ -1032,15 +1015,12 @@ TAO_Default_Resource_Factory::disable_factory (void) } } -TAO_Codeset_Manager * -TAO_Default_Resource_Factory::get_codeset_manager (void) +const TAO_Codeset_Descriptor * +TAO_Default_Resource_Factory::get_codeset_descriptor(int for_wchar) const { - if (this->codeset_manager_ == 0) - { - ACE_NEW_RETURN (this->codeset_manager_, TAO_Codeset_Manager, 0); - } - - return this->codeset_manager_; + if (for_wchar) + return &this->wchar_codeset_descriptor_; + return &this->char_codeset_descriptor_; } TAO_Resource_Factory::Resource_Usage diff --git a/TAO/tao/default_resource.h b/TAO/tao/default_resource.h index 417554b818f..c1721f78f23 100644 --- a/TAO/tao/default_resource.h +++ b/TAO/tao/default_resource.h @@ -121,7 +121,7 @@ public: virtual ACE_Allocator* ami_response_handler_allocator (void); virtual TAO_ProtocolFactorySet *get_protocol_factories (void); - virtual TAO_Codeset_Manager *get_codeset_manager (); + virtual const TAO_Codeset_Descriptor *get_codeset_descriptor(int wchar=0) const; virtual int init_protocol_factories (void); @@ -240,7 +240,8 @@ private: /// Type of flushing strategy configured Flushing_Strategy_Type flushing_strategy_type_; - TAO_Codeset_Manager *codeset_manager_; + TAO_Codeset_Descriptor char_codeset_descriptor_; + TAO_Codeset_Descriptor wchar_codeset_descriptor_; /// Resource usage strategy Resource_Usage resource_usage_strategy_; diff --git a/TAO/tao/orbconf.h b/TAO/tao/orbconf.h index aa28ab7f1bd..7fadcd77817 100644 --- a/TAO/tao/orbconf.h +++ b/TAO/tao/orbconf.h @@ -76,6 +76,14 @@ # define TAO_USE_DOTTED_DECIMAL_ADDRESSES 0 #endif /* TAO_USE_DOTTED_DECIMAL_ADDRESSES */ +// If set the ORB will use codeset negotiation. This means adding a +// Codeset component to each profile in an IOR, and a codeset context +// to the first request. The use of codeset negotiation also causes +// libTAO_Codeset to be linked in. +#if !defined (TAO_NEGOTIATE_CODESETS) +# define TAO_NEGOTIATE_CODESETS 1 +#endif /*TAO_NEGOTIATE_CODESETS*/ + // The default size of TAO's ORB table, i.e. the one used as the // underlying implementation for the CORBA::ORB_init() function. #if !defined (TAO_DEFAULT_ORB_TABLE_SIZE) diff --git a/TAO/tao/params.cpp b/TAO/tao/params.cpp index 09f61540912..1102cc428fd 100644 --- a/TAO/tao/params.cpp +++ b/TAO/tao/params.cpp @@ -36,6 +36,7 @@ TAO_ORB_Parameters::TAO_ORB_Parameters (void) , pref_network_ () , disable_rt_collocation_resolver_ (false) , enforce_preferred_interfaces_ (false) + , negotiate_codesets_ (true) { for (int i = 0; i != TAO_NO_OF_MCAST_SERVICES; ++i) { diff --git a/TAO/tao/params.h b/TAO/tao/params.h index fe49568f478..eeea266a3a0 100644 --- a/TAO/tao/params.h +++ b/TAO/tao/params.h @@ -109,7 +109,7 @@ public: /// decimal form of the peer's address int cache_incoming_by_dotted_decimal_address (void) const; void cache_incoming_by_dotted_decimal_address (int); - + /// The ORB will turn off SO_LINGER if this is zero. int linger (void) const; void linger (int); @@ -179,6 +179,10 @@ public: void enforce_pref_interfaces (bool p); bool enforce_pref_interfaces (void) const; + + void negotiate_codesets (bool c); + bool negotiate_codesets (void) const; + private: // Each "endpoint" is of the form: // @@ -233,8 +237,8 @@ private: /// For selecting a address notation int use_dotted_decimal_addresses_; - - /// If incoming connections should be cached against IP (true) or + + /// If incoming connections should be cached against IP (true) or /// hostname (false). int cache_incoming_by_dotted_decimal_address_; @@ -295,6 +299,9 @@ private: bool disable_rt_collocation_resolver_; bool enforce_preferred_interfaces_; + + /// Enable the use of codeset negotiation + bool negotiate_codesets_; }; #if defined (__ACE_INLINE__) diff --git a/TAO/tao/params.i b/TAO/tao/params.i index 617c94e7f61..a7a6a424d65 100644 --- a/TAO/tao/params.i +++ b/TAO/tao/params.i @@ -215,3 +215,16 @@ TAO_ORB_Parameters::disable_rt_collocation_resolver (bool x) { this->disable_rt_collocation_resolver_ = x; } + + +ACE_INLINE bool +TAO_ORB_Parameters::negotiate_codesets (void) const +{ + return this->negotiate_codesets_; +} + +ACE_INLINE void +TAO_ORB_Parameters::negotiate_codesets (bool x) +{ + this->negotiate_codesets_ = x; +} diff --git a/TAO/tao/tao.mpc b/TAO/tao/tao.mpc index bafcc39c965..0abd7810345 100644 --- a/TAO/tao/tao.mpc +++ b/TAO/tao/tao.mpc @@ -43,7 +43,7 @@ project(TAO) : acelib, core, tao_output, taodefaults, pidl, extra_core { ClientRequestInterceptor_Adapter.cpp ClientRequestInterceptor_Adapter_Factory.cpp Codeset_Manager.cpp - Codeset_Translator_Factory.cpp + Codeset_Translator_Base.cpp Collocated_Invocation.cpp Collocation_Proxy_Broker.cpp Collocation_Resolver.cpp @@ -282,8 +282,6 @@ project(TAO) : acelib, core, tao_output, taodefaults, pidl, extra_core { UserException.cpp UShortSeqA.cpp UShortSeqC.cpp - UTF16_BOM_Factory.cpp - UTF16_BOM_Translator.cpp Value_TypeCode_Static.cpp Valuetype_Adapter.cpp ValueModifierC.cpp @@ -354,8 +352,9 @@ project(TAO) : acelib, core, tao_output, taodefaults, pidl, extra_core { ClientRequestInterceptor_Adapter.h Client_Strategy_Factory.h Codeset_Manager.h - Codeset_Translator_Factory.h - Codeset_Translator_Factory_T.h + Codeset_Translator_Base.h +// Codeset_Translator_Factory.h *** file is for backwardscompatibility only +// *** there should be no dependencies on it Collocated_Invocation.h Collocation_Proxy_Broker.h Collocation_Resolver.h @@ -634,8 +633,6 @@ project(TAO) : acelib, core, tao_output, taodefaults, pidl, extra_core { UserException.h UShortSeqC.h UShortSeqS.h - UTF16_BOM_Factory.h - UTF16_BOM_Translator.h Value_TypeCode.h Value_TypeCode_Static.h Valuetype_Adapter.h |