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
)
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 ();
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
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
,
61 TAO_CodecFactory::create_codec (const IOP::Encoding
& enc
)
63 return this->create_codec_i (enc
.major_version
,
71 TAO_CodecFactory::create_codec_i (CORBA::Octet major
,
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 */:
94 // There is no such thing as a "0.x" CDR encapsulation.
95 throw ::CORBA::BAD_PARAM (
96 CORBA::SystemException::_tao_minor_code (
102 ACE_NEW_THROW_EX (codec
,
103 TAO_CDR_Encaps_Codec (major
,
109 CORBA::SystemException::_tao_minor_code (
112 CORBA::COMPLETED_MAYBE
));
116 throw IOP::CodecFactory::UnknownEncoding ();
122 TAO_END_VERSIONED_NAMESPACE_DECL