summaryrefslogtreecommitdiff
path: root/TAO/tao/Codeset_Manager.cpp
diff options
context:
space:
mode:
authorPhil Mesnier <mesnier_p@ociweb.com>2003-03-26 03:02:54 +0000
committerPhil Mesnier <mesnier_p@ociweb.com>2003-03-26 03:02:54 +0000
commitc3f3cb5fa54ab1d0f2786a89b3ae866ab6d0965b (patch)
tree9ce689d1ba94060e84c3ffef7353eb629835f649 /TAO/tao/Codeset_Manager.cpp
parent4497e54f06482f7227e462e46c584f345fd77cde (diff)
downloadATCD-c3f3cb5fa54ab1d0f2786a89b3ae866ab6d0965b.tar.gz
ChangeLog tag: Tue Mar 25 20:55:15 2003 Phil Mesnier <mesnier_p@ociweb.com>
Diffstat (limited to 'TAO/tao/Codeset_Manager.cpp')
-rw-r--r--TAO/tao/Codeset_Manager.cpp253
1 files changed, 226 insertions, 27 deletions
diff --git a/TAO/tao/Codeset_Manager.cpp b/TAO/tao/Codeset_Manager.cpp
index dd1af55a241..c4f3e559554 100644
--- a/TAO/tao/Codeset_Manager.cpp
+++ b/TAO/tao/Codeset_Manager.cpp
@@ -4,13 +4,13 @@
#include "tao/CDR.h"
#include "tao/TAO_Server_Request.h"
#include "tao/operation_details.h"
-#include "tao/ORB_Core.h"
#include "tao/Exception.h"
#include "tao/corbafwd.h"
#include "tao/Codeset_Translator_Factory.h"
#include "tao/TAO_Server_Request.h"
#include "tao/Tagged_Components.h"
+#include "ace/Dynamic_Service.h"
#include "ace/Codeset_Registry.h"
ACE_RCSID(tao, Codeset_Manager, "$Id$")
@@ -22,23 +22,38 @@ CONV_FRAME::CodeSetId TAO_Codeset_Manager::default_char_codeset = 0x00010001;
CONV_FRAME::CodeSetId TAO_Codeset_Manager::default_wchar_codeset = 0;
-TAO_Codeset_Manager::TAO_Codeset_Manager(CONV_FRAME::CodeSetComponentInfo *csi)
- :codeset_info_ (csi)
+TAO_Codeset_Manager::TAO_Codeset_Manager()
+ :codeset_info_ (),
+ char_factories_ (),
+ wchar_factories_ ()
{
}
TAO_Codeset_Manager::~TAO_Codeset_Manager()
{
- delete codeset_info_;
+ // 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::set_codeset (TAO_Tagged_Components& tc) const
{
- tc.set_code_sets (*this->codeset_info_);
+ tc.set_code_sets (this->codeset_info_);
}
-
void
TAO_Codeset_Manager::set_tcs(TAO_Profile &theProfile,
TAO_Transport &trans)
@@ -71,28 +86,26 @@ TAO_Codeset_Manager::set_tcs(TAO_Profile &theProfile,
}
CONV_FRAME::CodeSetId ncs =
- this->codeset_info_->ForCharData.native_code_set;
+ this->codeset_info_.ForCharData.native_code_set;
CONV_FRAME::CodeSetId tcs = computeTCS (remote.ForCharData,
- this->codeset_info_->ForCharData);
- TAO_Resource_Factory *rf = trans.orb_core()->resource_factory();
+ this->codeset_info_.ForCharData);
if (TAO_debug_level > 2)
ACE_DEBUG ((LM_DEBUG,
ACE_LIB_TEXT("(%P|%t) Codeset_Manager::set_tcs ")
ACE_LIB_TEXT("setting char translator(%08x, %08x)\n"),
ncs,tcs));
- trans.char_translator(rf->get_char_translator (ncs,tcs));
+ trans.char_translator(this->get_char_trans (ncs,tcs));
- ncs = this->codeset_info_->ForWcharData.native_code_set;
+ ncs = this->codeset_info_.ForWcharData.native_code_set;
tcs = computeTCS (remote.ForWcharData,
- this->codeset_info_->ForWcharData);
+ this->codeset_info_.ForWcharData);
if (TAO_debug_level > 2)
ACE_DEBUG ((LM_DEBUG,
ACE_LIB_TEXT("(%P|%t) Codeset_Manager::set_tcs ")
ACE_LIB_TEXT("setting wchar translator (%08x, %08x)\n"),
ncs,tcs));
- trans.wchar_translator(rf->get_wchar_translator (ncs,tcs));
- trans.wchar_allowed (ncs != 0 || tcs != 0);
+ trans.wchar_translator(this->get_wchar_trans (ncs,tcs));
}
void
@@ -118,10 +131,14 @@ TAO_Codeset_Manager::process_service_context (TAO_ServerRequest &request)
const char *buffer =
ACE_reinterpret_cast(const char*,context.context_data.get_buffer ());
- TAO_InputCDR cdr (buffer,context.context_data.length (),
- request.incoming().byte_order());
- cdr >> tcs_c;
- cdr >> tcs_w;
+ TAO_InputCDR cdr (buffer,context.context_data.length ());
+ CORBA::Boolean byte_order;
+ if (cdr >> TAO_InputCDR::to_boolean (byte_order))
+ {
+ cdr.reset_byte_order (ACE_static_cast (int, byte_order));
+ cdr >> tcs_c;
+ cdr >> tcs_w;
+ }
}
if (TAO_debug_level > 2)
@@ -131,15 +148,12 @@ TAO_Codeset_Manager::process_service_context (TAO_ServerRequest &request)
tcs_c,tcs_w));
CONV_FRAME::CodeSetId ncs =
- this->codeset_info_->ForCharData.native_code_set;
+ this->codeset_info_.ForCharData.native_code_set;
- TAO_Resource_Factory *rf =
- request.transport()->orb_core()->resource_factory();
- request.transport()->char_translator(rf->get_char_translator (ncs,tcs_c));
+ request.transport()->char_translator(this->get_char_trans (ncs,tcs_c));
- ncs = this->codeset_info_->ForWcharData.native_code_set;
- request.transport()->wchar_translator(rf->get_wchar_translator (ncs,tcs_w));
- request.transport()->wchar_allowed (ncs != 0 || tcs_w != 0);
+ ncs = this->codeset_info_.ForWcharData.native_code_set;
+ request.transport()->wchar_translator(this->get_wchar_trans (ncs,tcs_w));
}
void
@@ -155,10 +169,10 @@ TAO_Codeset_Manager::generate_service_context (TAO_Operation_Details &opd,
// 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;
+ 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;
+ this->codeset_info_.ForWcharData.native_code_set;
if (TAO_debug_level > 2)
ACE_DEBUG ((LM_DEBUG,
ACE_LIB_TEXT("(%P|%t) Codeset_Manager::generate_service_context ")
@@ -167,6 +181,7 @@ TAO_Codeset_Manager::generate_service_context (TAO_Operation_Details &opd,
codeset_cntx.wchar_data));
TAO_OutputCDR codeset_cdr;
+ codeset_cdr << TAO_OutputCDR::from_boolean (TAO_ENCAP_BYTE_ORDER);
codeset_cdr << codeset_cntx;
// Convert the codeset_cntx to servicecontext and insert into the List
@@ -258,3 +273,187 @@ TAO_Codeset_Manager::computeTCS (CONV_FRAME::CodeSetComponent &remote,
}
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_LIB_TEXT ("(%P|%t) Unable to add Codeset ")
+ ACE_LIB_TEXT ("factories for %s: %p\n"),
+ 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_LIB_TEXT ("(%P|%t) Unable to add Codeset ")
+ ACE_LIB_TEXT ("factories for %s: %p\n"),
+ 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_LIB_TEXT ("TAO (%P|%t) failed to init char ")
+ ACE_LIB_TEXT ("codeset factories\n")));
+ if (init_codeset_factories_i (this->wchar_factories_,
+ this->codeset_info_.ForWcharData) == -1)
+ ACE_ERROR ((LM_ERROR,
+ ACE_LIB_TEXT ("TAO (%P|%t) failed to init wchar ")
+ ACE_LIB_TEXT ("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(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_LIB_TEXT ("TAO (%P|%t) Unable to load ")
+ ACE_LIB_TEXT ("CodeSet <%s>, %p\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_LIB_TEXT ("TAO (%P|%t) Loaded CodeSet <%s>, ")
+ ACE_LIB_TEXT ("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 ncs,
+ CONV_FRAME::CodeSetId tcs)
+{
+ return this->get_translator_i (this->char_factories_,ncs,tcs);
+}
+
+TAO_Codeset_Translator_Factory *
+TAO_Codeset_Manager::get_wchar_trans (CONV_FRAME::CodeSetId ncs,
+ CONV_FRAME::CodeSetId tcs)
+{
+ return this->get_translator_i (this->wchar_factories_,ncs,tcs);
+}
+
+TAO_Codeset_Translator_Factory *
+TAO_Codeset_Manager::get_translator_i (TAO_CodesetFactorySet& factset,
+ CONV_FRAME::CodeSetId ncs,
+ CONV_FRAME::CodeSetId tcs)
+{
+ TAO_CodesetFactorySetItor end = factset.end ();
+ TAO_CodesetFactorySetItor iter = factset.begin ();
+
+ for (; iter != end; iter++)
+ {
+ TAO_Codeset_Translator_Factory *fact = (*iter)->factory ();
+ if( fact && ncs == fact->ncs() && 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)
+{
+ delete [] 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