Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / TAO / tao / CodecFactory / CodecFactory_impl.cpp
blobb4c843e436b9268b9e0bf65a69960e0f4036924d
1 // -*- C++ -*-
2 #include "tao/CodecFactory/CodecFactory_impl.h"
3 #include "tao/CodecFactory/CDR_Encaps_Codec.h"
4 #include "tao/SystemException.h"
5 #include "tao/ORB_Constants.h"
6 #include "tao/ORB_Core.h"
7 #include "tao/Codeset_Manager.h"
8 #include "ace/Codeset_Symbols.h"
9 #include "ace/CORBA_macros.h"
11 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
13 TAO_CodecFactory::TAO_CodecFactory (TAO_ORB_Core * orb_core)
14 : orb_core_ (orb_core)
18 IOP::Codec_ptr
19 TAO_CodecFactory::create_codec_with_codesets (const IOP::Encoding_1_2 & enc)
21 TAO_Codeset_Translator_Base *char_trans = 0;
22 TAO_Codeset_Translator_Base *wchar_trans = 0;
23 CONV_FRAME::CodeSetId ncsc;
24 CONV_FRAME::CodeSetId ncsw;
26 TAO_Codeset_Manager *csm = this->orb_core_->codeset_manager ();
28 if (csm)
30 char_trans = csm->get_char_trans (enc.char_codeset);
31 wchar_trans = csm->get_wchar_trans (enc.wchar_codeset);
32 csm->get_ncs (ncsc,ncsw); // pass by reference
34 else
36 // No codeset manager, so also raise an unsupported codeset
37 throw IOP::CodecFactory::UnsupportedCodeset (enc.wchar_codeset);
40 if (wchar_trans == 0 &&
41 enc.wchar_codeset != ACE_CODESET_ID_ISO_UTF_16 &&
42 enc.wchar_codeset != ncsw)
44 throw IOP::CodecFactory::UnsupportedCodeset (enc.wchar_codeset);
47 if (char_trans == 0 &&
48 enc.char_codeset != ncsc)
50 throw IOP::CodecFactory::UnsupportedCodeset (enc.char_codeset);
53 return this->create_codec_i (enc.major_version,
54 enc.minor_version,
55 enc.format,
56 char_trans,
57 wchar_trans);
60 IOP::Codec_ptr
61 TAO_CodecFactory::create_codec (const IOP::Encoding & enc)
63 return this->create_codec_i (enc.major_version,
64 enc.minor_version,
65 enc.format,
67 0);
70 IOP::Codec_ptr
71 TAO_CodecFactory::create_codec_i (CORBA::Octet major,
72 CORBA::Octet minor,
73 IOP::EncodingFormat encoding_format,
74 TAO_Codeset_Translator_Base * char_trans,
75 TAO_Codeset_Translator_Base * wchar_trans)
77 // @todo: Ideally we should have some sort of CodecFactory
78 // registry to make it possible to add factories
79 // dynamically. However, there currently isn't a need to
80 // support anything other than CDR encapsulations yet so we
81 // hardcode its Codec. This may change once TAO starts to
82 // support messaging formats other than GIOP.
84 IOP::Codec_ptr codec = IOP::Codec::_nil ();
86 switch (encoding_format)
88 // @@ MSVC 6 gets confused and thinks that
89 // IOP::ENCODING_CDR_ENCAPS is not a constant, so its actual
90 // value (0) is used instead.
91 case 0 /* IOP::ENCODING_CDR_ENCAPS */:
92 if (major < 1)
94 // There is no such thing as a "0.x" CDR encapsulation.
95 throw ::CORBA::BAD_PARAM (
96 CORBA::SystemException::_tao_minor_code (
98 EINVAL),
99 CORBA::COMPLETED_NO);
102 ACE_NEW_THROW_EX (codec,
103 TAO_CDR_Encaps_Codec (major,
104 minor,
105 this->orb_core_,
106 char_trans,
107 wchar_trans),
108 CORBA::NO_MEMORY (
109 CORBA::SystemException::_tao_minor_code (
111 ENOMEM),
112 CORBA::COMPLETED_MAYBE));
113 break;
115 default:
116 throw IOP::CodecFactory::UnknownEncoding ();
119 return codec;
122 TAO_END_VERSIONED_NAMESPACE_DECL