summaryrefslogtreecommitdiff
path: root/TAO/tao/Codeset_Manager.cpp
diff options
context:
space:
mode:
authorbala <balanatarajan@users.noreply.github.com>2003-10-28 18:31:01 +0000
committerbala <balanatarajan@users.noreply.github.com>2003-10-28 18:31:01 +0000
commitc20c95d4d526d887c9782960a3ff73f63c3c1c85 (patch)
treefd6ae8c3db752254802dfaafd1543974a4741e47 /TAO/tao/Codeset_Manager.cpp
parent3d20d6aedf2b56b86fe2a386777c7afbf1c19c93 (diff)
downloadATCD-c20c95d4d526d887c9782960a3ff73f63c3c1c85.tar.gz
ChangeLogTag:Tue Oct 28 12:02:47 2003 Balachandran Natarajan <bala@dre.vanderbilt.edu>
Diffstat (limited to 'TAO/tao/Codeset_Manager.cpp')
-rw-r--r--TAO/tao/Codeset_Manager.cpp328
1 files changed, 213 insertions, 115 deletions
diff --git a/TAO/tao/Codeset_Manager.cpp b/TAO/tao/Codeset_Manager.cpp
index 13005448634..48767ed0b30 100644
--- a/TAO/tao/Codeset_Manager.cpp
+++ b/TAO/tao/Codeset_Manager.cpp
@@ -1,21 +1,34 @@
// $Id$
+
#include "tao/Codeset_Manager.h"
-#include "tao/debug.h"
-#include "tao/CDR.h"
#include "tao/TAO_Server_Request.h"
#include "tao/operation_details.h"
#include "tao/Transport.h"
#include "tao/Profile.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$")
+ACE_RCSID (tao,
+ Codeset_Manager,
+ "$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
+
+// 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_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
@@ -25,10 +38,10 @@ TAO_Codeset_Manager::default_char_codeset = TAO_DEFAULT_CHAR_CODESET_ID;
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_ ()
+TAO_Codeset_Manager::TAO_Codeset_Manager ()
+ : codeset_info_ (),
+ char_factories_ (),
+ wchar_factories_ ()
{
this->codeset_info_.ForCharData.native_code_set =
TAO_Codeset_Manager::default_char_codeset;
@@ -36,21 +49,27 @@ TAO_Codeset_Manager::TAO_Codeset_Manager()
TAO_Codeset_Manager::default_wchar_codeset;
}
-TAO_Codeset_Manager::~TAO_Codeset_Manager()
+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;
+
+ 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;
+ {
+ delete *cf_iter;
+ }
this->wchar_factories_.reset ();
}
@@ -62,61 +81,74 @@ TAO_Codeset_Manager::set_codeset (TAO_Tagged_Components& tc) const
}
void
-TAO_Codeset_Manager::set_tcs(TAO_Profile &theProfile,
- TAO_Transport &trans)
+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_LIB_TEXT("(%P|%t) Codeset_Manager::set_tcs ")
- ACE_LIB_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_LIB_TEXT("(%P|%t) Codeset_Manager::set_tcs ")
- ACE_LIB_TEXT("No codeset componnet 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;
- }
-
- CONV_FRAME::CodeSetId tcs = computeTCS (remote.ForCharData,
- 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)\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_LIB_TEXT("(%P|%t) Codeset_Manager::set_tcs ")
- ACE_LIB_TEXT("setting wchar translator (%08x)\n"),
- tcs));
- trans.wchar_translator(this->get_wchar_trans (tcs));
+ /// 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_LIB_TEXT ("(%P|%t) Codeset_Manager::set_tcs ")
+ ACE_LIB_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_LIB_TEXT ("(%P|%t) Codeset_Manager::set_tcs ")
+ ACE_LIB_TEXT ("No codeset componnet 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;
+ }
+
+ CONV_FRAME::CodeSetId tcs = computeTCS (remote.ForCharData,
+ 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)\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_LIB_TEXT ("(%P|%t) Codeset_Manager::set_tcs ")
+ ACE_LIB_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;
+ 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
@@ -130,10 +162,11 @@ TAO_Codeset_Manager::process_service_context (TAO_ServerRequest &request)
{
// Convert the Service Context to Codeset Context
const char *buffer =
- ACE_reinterpret_cast(const char*,context.context_data.get_buffer ());
+ ACE_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 (ACE_static_cast (int, byte_order));
@@ -143,10 +176,13 @@ TAO_Codeset_Manager::process_service_context (TAO_ServerRequest &request)
}
if (TAO_debug_level > 2)
- ACE_DEBUG ((LM_DEBUG,
- ACE_LIB_TEXT("(%P|%t) Codeset_Manager::process_service_context ")
- ACE_LIB_TEXT("using tcsc = %08x, tcsw = %08x\n"),
- tcs_c,tcs_w));
+ {
+ ACE_DEBUG ((LM_DEBUG,
+ ACE_LIB_TEXT ("(%P|%t) Codeset_Manager::")
+ ACE_LIB_TEXT ("process_service_context ")
+ ACE_LIB_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));
@@ -161,18 +197,25 @@ TAO_Codeset_Manager::generate_service_context (TAO_Operation_Details &opd,
// 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;
+ 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_LIB_TEXT("(%P|%t) Codeset_Manager::generate_service_context ")
- ACE_LIB_TEXT("using tcs_c = %08x, tcs_w = %08x\n"),
- codeset_cntx.char_data,
- codeset_cntx.wchar_data));
+ {
+ ACE_DEBUG ((LM_DEBUG,
+ ACE_LIB_TEXT ("(%P|%t) Codeset_Manager::")
+ ACE_LIB_TEXT ("generate_service_context ")
+ ACE_LIB_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);
@@ -186,13 +229,14 @@ 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();
+ 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;
}
@@ -201,11 +245,16 @@ CONV_FRAME::CodeSetId
TAO_Codeset_Manager::intersectionOf (CONV_FRAME::CodeSetComponent &cs_comp1,
CONV_FRAME::CodeSetComponent &cs_comp2)
{
- for(CORBA::ULong index=0L;
+ 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];
+ {
+ if (this->isElementOf(cs_comp1.conversion_code_sets[index], cs_comp2))
+ {
+ return cs_comp1.conversion_code_sets[index];
+ }
+ }
+
return 0;
}
@@ -223,23 +272,35 @@ 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;
+ {
+ return local.native_code_set;
+ }
if (this->isElementOf (remote.native_code_set, local))
- return remote.native_code_set;
+ {
+ return remote.native_code_set;
+ }
if (this->isElementOf (local.native_code_set, remote))
- return local.native_code_set;
+ {
+ 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);
- }
+ {
+ 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;
}
@@ -261,11 +322,16 @@ 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);
+ {
+ 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;
}
@@ -274,11 +340,16 @@ 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);
+ {
+ 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;
}
@@ -287,22 +358,32 @@ 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
+ {
+ 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_Codeset_Manager::init_codeset_factories_i (
+ TAO_CodesetFactorySet& factset,
+ CONV_FRAME::CodeSetComponent& cs_comp
+ )
{
TAO_CodesetFactorySetItor end = factset.end ();
TAO_CodesetFactorySetItor iter = factset.begin ();
@@ -312,11 +393,12 @@ TAO_Codeset_Manager::init_codeset_factories_i (TAO_CodesetFactorySet& factset,
factset.size()));
CORBA::ULong index;
- for (index=0; iter != end; iter++)
+ 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,
@@ -325,18 +407,23 @@ TAO_Codeset_Manager::init_codeset_factories_i (TAO_CodesetFactorySet& factset,
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()));
+ {
+ 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;
}
@@ -345,7 +432,10 @@ 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 0;
+ }
+
return this->get_translator_i (this->char_factories_,tcs);
}
@@ -353,7 +443,10 @@ TAO_Codeset_Translator_Factory *
TAO_Codeset_Manager::get_wchar_trans (CONV_FRAME::CodeSetId tcs)
{
if (this->codeset_info_.ForWcharData.native_code_set == tcs)
- return 0;
+ {
+ return 0;
+ }
+
return this->get_translator_i (this->wchar_factories_,tcs);
}
@@ -367,8 +460,11 @@ TAO_Codeset_Manager::get_translator_i (TAO_CodesetFactorySet& factset,
for (; iter != end; iter++)
{
TAO_Codeset_Translator_Factory *fact = (*iter)->factory ();
+
if (fact && tcs == fact->tcs())
+ {
return fact;
+ }
}
return 0;
@@ -382,7 +478,9 @@ TAO_Codeset_Item::TAO_Codeset_Item (const char *name)
factory_ (0)
{
if (name)
- name_ = ACE_OS::strdup(name);
+ {
+ name_ = ACE_OS::strdup(name);
+ }
}
TAO_Codeset_Item::~TAO_Codeset_Item (void)