Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes

TAO_Codeset_Manager_i Class Reference

#include <Codeset_Manager_i.h>

Inheritance diagram for TAO_Codeset_Manager_i:
Inheritance graph
[legend]
Collaboration diagram for TAO_Codeset_Manager_i:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 TAO_Codeset_Manager_i (void)
 ~TAO_Codeset_Manager_i (void)
void set_codeset (TAO_Tagged_Components &) const
void set_tcs (TAO_Profile &theProfile, TAO_Transport &)
void process_service_context (TAO_ServerRequest &)
void generate_service_context (TAO_Operation_Details &, TAO_Transport &)
void open (TAO_ORB_Core &core)
virtual
TAO_Codeset_Descriptor_Base
char_codeset_descriptor (void)
virtual
TAO_Codeset_Descriptor_Base
wchar_codeset_descriptor (void)

Static Public Attributes

static CONV_FRAME::CodeSetId default_char_codeset = TAO_DEFAULT_CHAR_CODESET_ID
 NCS for char is defaulted to ISO 8859-1:1987; Latin Alphabet No. 1.
static CONV_FRAME::CodeSetId default_wchar_codeset = TAO_DEFAULT_WCHAR_CODESET_ID

Private Member Functions

CONV_FRAME::CodeSetId computeTCS (CONV_FRAME::CodeSetComponent &, CONV_FRAME::CodeSetComponent &)
 returns the TCS for Char / Wchar
int isElementOf (CONV_FRAME::CodeSetId, CONV_FRAME::CodeSetComponent &)
 Checks whether the NCS is a part of CCS.
CONV_FRAME::CodeSetId intersectionOf (CONV_FRAME::CodeSetComponent &, CONV_FRAME::CodeSetComponent &)
 Find the Intersection of Client and Server CCS's.
int isCompatible (CONV_FRAME::CodeSetId, CONV_FRAME::CodeSetId)
int init_ccs (TAO_Codeset_Descriptor &, CONV_FRAME::CodeSetComponent &)
TAO_Codeset_Translator_Baseget_char_trans (CONV_FRAME::CodeSetId)
TAO_Codeset_Translator_Baseget_wchar_trans (CONV_FRAME::CodeSetId)
TAO_Codeset_Translator_Baseget_translator_i (TAO_Codeset_Descriptor &, CONV_FRAME::CodeSetId)
void get_ncs (CONV_FRAME::CodeSetId &ncsc, CONV_FRAME::CodeSetId &ncsw)

Private Attributes

CONV_FRAME::CodeSetComponentInfo codeset_info_
TAO_Codeset_Descriptor char_descriptor_
TAO_Codeset_Descriptor wchar_descriptor_

Detailed Description

Definition at line 61 of file Codeset_Manager_i.h.


Constructor & Destructor Documentation

TAO_Codeset_Manager_i::TAO_Codeset_Manager_i ( void   ) 
TAO_Codeset_Manager_i::~TAO_Codeset_Manager_i ( void   ) 

Definition at line 80 of file Codeset_Manager_i.cpp.

{
}


Member Function Documentation

TAO_Codeset_Descriptor_Base * TAO_Codeset_Manager_i::char_codeset_descriptor ( void   )  [virtual]

Implements TAO_Codeset_Manager.

Definition at line 85 of file Codeset_Manager_i.cpp.

{
  return &this->char_descriptor_;
}

CONV_FRAME::CodeSetId TAO_Codeset_Manager_i::computeTCS ( CONV_FRAME::CodeSetComponent &  remote,
CONV_FRAME::CodeSetComponent &  local 
) [private]

returns the TCS for Char / Wchar

Definition at line 315 of file Codeset_Manager_i.cpp.

{
  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
        {
          throw ::CORBA::CODESET_INCOMPATIBLE ();
        }
    }

  return tcs;
}

void TAO_Codeset_Manager_i::generate_service_context ( TAO_Operation_Details opd,
TAO_Transport trans 
) [virtual]

Called by a client object to generate service context at this time Transport has the TCS for Char and WChar

Implements TAO_Codeset_Manager.

Definition at line 227 of file Codeset_Manager_i.cpp.

{
  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 =
    dynamic_cast<TAO_Codeset_Translator_Factory*>(trans.char_translator());

  codeset_cntx.char_data =
    tf ? tf->tcs () : this->codeset_info_.ForCharData.native_code_set;

  tf =
    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_CString tcs_c_locale;
      ACE_CString tcs_w_locale;
      ACE_Codeset_Registry::registry_to_locale (codeset_cntx.char_data, tcs_c_locale, 0, 0);
      ACE_Codeset_Registry::registry_to_locale (codeset_cntx.wchar_data, tcs_w_locale, 0, 0);
      ACE_DEBUG ((LM_DEBUG,
                  ACE_TEXT ("TAO (%P|%t) - Codeset_Manager_i::")
                  ACE_TEXT ("generate_service_context, ")
                  ACE_TEXT ("using tcs_c <%C> (%08x), tcs_w <%C> (%08x)\n"),
                  tcs_c_locale.c_str (),
                  codeset_cntx.char_data,
                  tcs_w_locale.c_str (),
                  codeset_cntx.wchar_data));
    }

  TAO_OutputCDR codeset_cdr;
  if ((codeset_cdr << TAO_OutputCDR::from_boolean (TAO_ENCAP_BYTE_ORDER)) &&
      (codeset_cdr << codeset_cntx))
    {
      service_cntx.set_context (IOP::CodeSets,codeset_cdr);
    }
}

TAO_Codeset_Translator_Base * TAO_Codeset_Manager_i::get_char_trans ( CONV_FRAME::CodeSetId  tcs  )  [private, virtual]

Implements TAO_Codeset_Manager.

Definition at line 489 of file Codeset_Manager_i.cpp.

{
  if (this->codeset_info_.ForCharData.native_code_set == tcs)
    return 0;
  return this->get_translator_i (this->char_descriptor_,tcs);
}

void TAO_Codeset_Manager_i::get_ncs ( CONV_FRAME::CodeSetId &  ncsc,
CONV_FRAME::CodeSetId &  ncsw 
) [private, virtual]

Implements TAO_Codeset_Manager.

Definition at line 520 of file Codeset_Manager_i.cpp.

{
   ncsc = this->char_descriptor_.ncs();
   ncsw = this->wchar_descriptor_.ncs();
}

TAO_Codeset_Translator_Base * TAO_Codeset_Manager_i::get_translator_i ( TAO_Codeset_Descriptor cd,
CONV_FRAME::CodeSetId  tcs 
) [private]

Definition at line 506 of file Codeset_Manager_i.cpp.

{
  for (TAO_Codeset_Descriptor::Translator_Node *tlist = cd.translators();
       tlist; tlist = tlist->next_)
    {
      TAO_Codeset_Translator_Factory *fact = tlist->translator_factory_;
      if (fact && tcs == fact->tcs ())
        return fact;
    }
  return 0;
}

TAO_Codeset_Translator_Base * TAO_Codeset_Manager_i::get_wchar_trans ( CONV_FRAME::CodeSetId  tcs  )  [private, virtual]

Implements TAO_Codeset_Manager.

Definition at line 497 of file Codeset_Manager_i.cpp.

{
  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_descriptor_,tcs);
}

int TAO_Codeset_Manager_i::init_ccs ( TAO_Codeset_Descriptor cd,
CONV_FRAME::CodeSetComponent &  cs_comp 
) [private]

Definition at line 426 of file Codeset_Manager_i.cpp.

{
  cs_comp.conversion_code_sets.length
    (static_cast<CORBA::ULong> (cd.num_translators()));

  CORBA::ULong index;
  TAO_Codeset_Descriptor::Translator_Node *tlist = cd.translators();

  for (index = 0; tlist; tlist = tlist->next_)
    {
      tlist->translator_factory_ =
        ACE_Dynamic_Service<TAO_Codeset_Translator_Factory>::instance
        (tlist->name_);

      if (tlist->translator_factory_ == 0)
        {
          if (TAO_debug_level)
            ACE_ERROR ((LM_ERROR,
                        ACE_TEXT ("TAO (%P|%t) - Codeset_Manager_i::")
                        ACE_TEXT ("init_ccs, Unable to load ")
                        ACE_TEXT ("code set translator <%s>, %m\n"),
                        tlist->name_));
          continue;
        }

      if (tlist->translator_factory_->ncs() != cs_comp.native_code_set)
        {
          if (TAO_debug_level)
            ACE_ERROR ((LM_ERROR,
                        ACE_TEXT ("TAO (%P|%t) - Codeset_Manager_i::")
                        ACE_TEXT ("init_ccs, codeset translator <%s> ")
                        ACE_TEXT ("has wrong ncs (%d), %m\n"),
                        tlist->name_,
                        tlist->translator_factory_->ncs()));
          tlist->translator_factory_ = 0;
          continue;
        }

      // this is a special case for the utf16 bom translator.
      if (tlist->translator_factory_->tcs() ==  cs_comp.native_code_set)
        continue;

      cs_comp.conversion_code_sets[index++] =
        tlist->translator_factory_->tcs();
      if (TAO_debug_level > 2)
        {
          ACE_DEBUG ((LM_DEBUG,
                      ACE_TEXT ("TAO (%P|%t) - Codeset_Manager_i::")
                      ACE_TEXT ("init_ccs, Loaded Codeset translator ")
                      ACE_TEXT ("<%s>, ncs = %08x tcs = %08x\n"),
                      tlist->name_,
                      tlist->translator_factory_->ncs(),
                      tlist->translator_factory_->tcs()
                      ));
        }
    }

  cs_comp.conversion_code_sets.length(index);
  return 0;
}

CONV_FRAME::CodeSetId TAO_Codeset_Manager_i::intersectionOf ( CONV_FRAME::CodeSetComponent &  cs_comp1,
CONV_FRAME::CodeSetComponent &  cs_comp2 
) [private]

Find the Intersection of Client and Server CCS's.

Definition at line 289 of file Codeset_Manager_i.cpp.

{
  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 
) [private]

Definition at line 306 of file Codeset_Manager_i.cpp.

{
  // Call the is_compatible method of ACE_Codeset_Registry
  return ACE_Codeset_Registry::is_compatible(cs1,cs2);
}

int TAO_Codeset_Manager_i::isElementOf ( CONV_FRAME::CodeSetId  id,
CONV_FRAME::CodeSetComponent &  cs_comp 
) [private]

Checks whether the NCS is a part of CCS.

Definition at line 273 of file Codeset_Manager_i.cpp.

{
  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;
}

void TAO_Codeset_Manager_i::open ( TAO_ORB_Core core  )  [virtual]

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.

Implements TAO_Codeset_Manager.

Definition at line 351 of file Codeset_Manager_i.cpp.

{
#if 0
  // 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")
                    ));
    }
#endif
  //
  TAO_Codeset_Service_Context_Handler* h = 0;
  ACE_NEW (h,
           TAO_Codeset_Service_Context_Handler());
  core.service_context_registry ().bind (IOP::CodeSets, h);

  // add in from the service configurator
  this->codeset_info_.ForCharData.native_code_set =
    this->char_descriptor_.ncs();
  this->codeset_info_.ForWcharData.native_code_set =
    this->wchar_descriptor_.ncs();
  ACE_OutputCDR::wchar_maxbytes(this->wchar_descriptor_.max_bytes());

  if (init_ccs (this->char_descriptor_,
                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_ccs (this->wchar_descriptor_,
                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")));
    }
}

void TAO_Codeset_Manager_i::process_service_context ( TAO_ServerRequest request  )  [virtual]

Called from an Object of TAO_Messaging for every request at server side to process service context and set TCS for Char/WChar

Implements TAO_Codeset_Manager.

Definition at line 167 of file Codeset_Manager_i.cpp.

{
  // 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 other codeset
  // can be computed based on our local set and those in the context
  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) - ")
                    ACE_TEXT("Codeset_Manager_i::process_service_context ")
                    ACE_TEXT("no codeset context in request, using defaults\n")
                    ));
      tcs_c = TAO_Codeset_Manager_i::default_char_codeset;
      tcs_w = TAO_Codeset_Manager_i::default_wchar_codeset;
    }
  if (TAO_debug_level > 2)
    {
      ACE_CString tcs_c_locale;
      ACE_CString tcs_w_locale;
      ACE_Codeset_Registry::registry_to_locale (tcs_c, tcs_c_locale, 0, 0);
      ACE_Codeset_Registry::registry_to_locale (tcs_w, tcs_w_locale, 0, 0);
      ACE_DEBUG ((LM_DEBUG,
                  ACE_TEXT ("TAO (%P|%t) - Codeset_Manager_i::")
                  ACE_TEXT ("process_service_context, ")
                  ACE_TEXT ("using tcsc <%C> (%08x), tcsw <%C> (%08x)\n"),
                  tcs_c_locale.c_str (), tcs_c, tcs_w_locale.c_str (), 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::set_codeset ( TAO_Tagged_Components tc  )  const [virtual]

Called by an object of TAO_Acceptor to set NCS and CCS values for Char/Wchar in to the Object Reference.

Implements TAO_Codeset_Manager.

Definition at line 97 of file Codeset_Manager_i.cpp.

{
  tc.set_code_sets (this->codeset_info_);
}

void TAO_Codeset_Manager_i::set_tcs ( TAO_Profile theProfile,
TAO_Transport trans 
) [virtual]

Called from an object of "TAO_GIOP_Invocation" to set TCS on the Transport

If tcs is already set on the transport then do not process, use existing transport as CDR have translators set.

Get the codeset component

Implements TAO_Codeset_Manager.

Definition at line 103 of file Codeset_Manager_i.cpp.

{
  /// If tcs is already set on the transport then do not 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));
     }
}

TAO_Codeset_Descriptor_Base * TAO_Codeset_Manager_i::wchar_codeset_descriptor ( void   )  [virtual]

Implements TAO_Codeset_Manager.

Definition at line 91 of file Codeset_Manager_i.cpp.

{
  return &this->wchar_descriptor_;
}


Member Data Documentation

Definition at line 142 of file Codeset_Manager_i.h.

CONV_FRAME::CodeSetComponentInfo TAO_Codeset_Manager_i::codeset_info_ [private]

Definition at line 140 of file Codeset_Manager_i.h.

CONV_FRAME::CodeSetId TAO_Codeset_Manager_i::default_char_codeset = TAO_DEFAULT_CHAR_CODESET_ID [static]

NCS for char is defaulted to ISO 8859-1:1987; Latin Alphabet No. 1.

NCS for char is defaulted to ISO 8859-1:1987; Latin Alphabet No. 1

Definition at line 68 of file Codeset_Manager_i.h.

CONV_FRAME::CodeSetId TAO_Codeset_Manager_i::default_wchar_codeset = TAO_DEFAULT_WCHAR_CODESET_ID [static]

NCS for wchar is defaulted to 0 (not used), but people wishing to provide a non-compliant default wchar codeset may do so.

NCS for wchar is not defaulted by the CORBA specification, but a default may be set here if desired

Definition at line 71 of file Codeset_Manager_i.h.

Definition at line 143 of file Codeset_Manager_i.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines