📄 cdrstream.cc
字号:
// -*- Mode: C++; -*-// Package : omniORB// cdrStream.cc Created on: 09/11/2000// Author : Sai Lai Lo (sll)//// Copyright (C) 2000 AT&T Laboratories Cambrige//// This file is part of the omniORB library//// The omniORB library is free software; you can redistribute it and/or// modify it under the terms of the GNU Library General Public// License as published by the Free Software Foundation; either// version 2 of the License, or (at your option) any later version.//// This library is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU// Library General Public License for more details.//// You should have received a copy of the GNU Library General Public// License along with this library; if not, write to the Free// Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA // 02111-1307, USA////// Description:// *** PROPRIETORY INTERFACE ***// /* $Log: cdrStream.cc,v $ Revision 1.1.2.19 2006/01/10 10:24:01 dgrisby Minor log message reformatting. Revision 1.1.2.18 2005/03/03 12:55:55 dgrisby Minor log output clean-up. Thanks Peter Klotz. Revision 1.1.2.17 2005/01/13 16:48:29 dgrisby Typo in log message. Thanks Dirk Siebnich. Revision 1.1.2.16 2003/07/26 22:52:22 dgrisby Avoid spurious gcc warnings when sizeof pointer > sizeof int. Revision 1.1.2.15 2003/02/03 16:53:14 dgrisby Force type in constructor argument to help confused compilers. Revision 1.1.2.14 2002/11/26 14:51:50 dgrisby Implement missing interceptors. Revision 1.1.2.13 2002/05/07 12:55:47 dgrisby Minor tweak to log message format. Revision 1.1.2.12 2002/04/25 23:13:30 dgrisby Minor tweak to codeset setting interceptors for GIOP 1.0. Revision 1.1.2.11 2001/11/14 17:13:43 dpg1 Long double support. Revision 1.1.2.10 2001/10/17 16:33:28 dpg1 New downcast mechanism for cdrStreams. Revision 1.1.2.9 2001/08/21 11:02:12 sll orbOptions handlers are now told where an option comes from. This is necessary to process DefaultInitRef and InitRef correctly. Revision 1.1.2.8 2001/08/17 17:12:35 sll Modularise ORB configuration parameters. Revision 1.1.2.7 2001/08/03 17:41:18 sll System exception minor code overhaul. When a system exeception is raised, a meaning minor code is provided. Revision 1.1.2.6 2001/07/31 17:42:11 sll Cleanup String_var usage. Revision 1.1.2.5 2001/07/31 16:32:02 sll Added virtual function is_giopStream to check if a cdrStream is a giopStream. That is, a poor man's substitute for dynamic_cast. Revision 1.1.2.4 2001/04/18 18:18:11 sll Big checkin with the brand new internal APIs. Revision 1.1.2.3 2000/11/20 11:59:43 dpg1 API to configure code sets. Revision 1.1.2.2 2000/11/15 19:16:06 sll Changed default native wchar from UCS-4 to UTF-16. Revision 1.1.2.1 2000/11/15 17:17:20 sll *** empty log message ****/#include <omniORB4/CORBA.h>#include <omniORB4/omniInterceptors.h>#include <giopStream.h>#include <giopStrand.h>#include <GIOP_S.h>#include <initialiser.h>#include <giopStreamImpl.h>#include <exceptiondefs.h>#include <orbOptions.h>#include <orbParameters.h>#include <stdio.h>OMNI_USING_NAMESPACE(omni)////////////////////////////////////////////////////////////////////////////// Configuration options //////////////////////////////////////////////////////////////////////////////omniCodeSet::NCS_C* orbParameters::nativeCharCodeSet = 0;// set the native code set for char and string//omniCodeSet::NCS_W* orbParameters::nativeWCharCodeSet = 0;// set the native code set for wchar and wstring//omniCodeSet::TCS_C* orbParameters::anyCharCodeSet = 0;// set the preferred code set for char data inside anys//omniCodeSet::TCS_W* orbParameters::anyWCharCodeSet = 0;// set the preferred code set for wchar data inside anys/////////////////////////////////////////////////////////////////////////////cdrStream::cdrStream() : pd_unmarshal_byte_swap(0), pd_marshal_byte_swap(0), pd_inb_end(0), pd_inb_mkr(0), pd_outb_end(0), pd_outb_mkr(0), pd_tcs_c(0), pd_tcs_w(0), pd_ncs_c(orbParameters::nativeCharCodeSet), pd_ncs_w(orbParameters::nativeWCharCodeSet) {}/////////////////////////////////////////////////////////////////////////////void*cdrStream::ptrToClass(int* cptr){ if (cptr == &cdrStream::_classid) return (cdrStream*)this; return 0;}int cdrStream::_classid;/////////////////////////////////////////////////////////////////////////////CORBA::ULong cdrStream::completion() { return CORBA::COMPLETED_NO;}/////////////////////////////////////////////////////////////////////////////voidcdrStream::copy_to(cdrStream& s,int size,omni::alignment_t align) { try { alignInput(align); if (s.maybeReserveOutputSpace(align,size)) { omni::ptr_arith_t p1 = omni::align_to((omni::ptr_arith_t)s.pd_outb_mkr, align); get_octet_array((CORBA::Octet*)p1,size,align); s.pd_outb_mkr = (void*)(p1 + size); } else { skipInput(size); } } catch (const CORBA::BAD_PARAM&) { // Use a bounce buffer if the destination stream cannot satisfy // maybeReserveOutputSpace(). cdrMemoryStream mbuf(size,0); mbuf.maybeReserveOutputSpace(align,size); omni::ptr_arith_t p1 = omni::align_to((omni::ptr_arith_t)mbuf.pd_outb_mkr, align); get_octet_array((CORBA::Octet*)p1,size,align); s.put_octet_array((const CORBA::Octet*)p1,size,align); }}/////////////////////////////////////////////////////////////////////////////#ifdef HAS_LongDouble# if SIZEOF_LONG_DOUBLE == 12# ifndef __x86__# error "12-byte long double only supported for x86"# endif// Intel x86 extended double is odd. Firstly, it's 80 bits, not 96, so// the two most significant bytes are always zero. Secondly, the// significand _includes_ the most significant bit. IEEE floating// point always missed out the msb, as do the other floating point// formats on x86. This means we have to do lots of bit shifting.//// This isn't the most efficient code in the world, but it's designed// to be easy to understand.voidoperator>>=(_CORBA_LongDouble a, cdrStream& s){ _CORBA_Octet mbuf[16]; _CORBA_Octet* dbuf = (_CORBA_Octet*)&a; memset(mbuf, 0, 16); if (s.pd_marshal_byte_swap) { // big endian // Sign and exponent mbuf[0] = dbuf[9]; mbuf[1] = dbuf[8]; // significand mbuf[2] = (dbuf[7] << 1) | (dbuf[6] >> 7); mbuf[3] = (dbuf[6] << 1) | (dbuf[5] >> 7); mbuf[4] = (dbuf[5] << 1) | (dbuf[4] >> 7); mbuf[5] = (dbuf[4] << 1) | (dbuf[3] >> 7); mbuf[6] = (dbuf[3] << 1) | (dbuf[2] >> 7); mbuf[7] = (dbuf[2] << 1) | (dbuf[1] >> 7); mbuf[8] = (dbuf[1] << 1) | (dbuf[0] >> 7); mbuf[9] = (dbuf[0] << 1); } else { // little endian // Sign and exponent mbuf[15] = dbuf[9]; mbuf[14] = dbuf[8]; // significand mbuf[13] = (dbuf[7] << 1) | (dbuf[6] >> 7); mbuf[12] = (dbuf[6] << 1) | (dbuf[5] >> 7); mbuf[11] = (dbuf[5] << 1) | (dbuf[4] >> 7); mbuf[10] = (dbuf[4] << 1) | (dbuf[3] >> 7); mbuf[ 9] = (dbuf[3] << 1) | (dbuf[2] >> 7); mbuf[ 8] = (dbuf[2] << 1) | (dbuf[1] >> 7); mbuf[ 7] = (dbuf[1] << 1) | (dbuf[0] >> 7); mbuf[ 6] = (dbuf[0] << 1); } s.put_octet_array((_CORBA_Octet*)mbuf, 16, omni::ALIGN_8);}voidoperator<<=(_CORBA_LongDouble& a, cdrStream& s){ _CORBA_Octet mbuf[16]; _CORBA_Octet* dbuf = (_CORBA_Octet*)&a; s.get_octet_array((_CORBA_Octet*)mbuf, 16, omni::ALIGN_8); dbuf[11] = dbuf[10] = 0; if (s.pd_unmarshal_byte_swap) { // big endian // Sign and exponent dbuf[9] = mbuf[0]; dbuf[8] = mbuf[1]; // significand dbuf[7] = (mbuf[0] == 0 && mbuf[1] == 0) ? 0 : 0x80 | (mbuf[2] >> 1); dbuf[6] = (mbuf[2] << 7) | (mbuf[3] >> 1); dbuf[5] = (mbuf[3] << 7) | (mbuf[4] >> 1); dbuf[4] = (mbuf[4] << 7) | (mbuf[5] >> 1); dbuf[3] = (mbuf[5] << 7) | (mbuf[6] >> 1); dbuf[2] = (mbuf[6] << 7) | (mbuf[7] >> 1); dbuf[1] = (mbuf[7] << 7) | (mbuf[8] >> 1); dbuf[0] = (mbuf[8] << 7) | (mbuf[9] >> 1); } else { // little endian // Sign and exponent dbuf[9] = mbuf[15]; dbuf[8] = mbuf[14]; // significand dbuf[7] = (mbuf[15] == 0 && mbuf[14] == 0) ? 0 : 0x80 | (mbuf[13] >> 1); dbuf[6] = (mbuf[13] << 7) | (mbuf[12] >> 1); dbuf[5] = (mbuf[12] << 7) | (mbuf[11] >> 1); dbuf[4] = (mbuf[11] << 7) | (mbuf[10] >> 1); dbuf[3] = (mbuf[10] << 7) | (mbuf[ 9] >> 1); dbuf[2] = (mbuf[ 9] << 7) | (mbuf[ 8] >> 1); dbuf[1] = (mbuf[ 8] << 7) | (mbuf[ 7] >> 1); dbuf[0] = (mbuf[ 7] << 7) | (mbuf[ 6] >> 1); }}# endif // SIZEOF_LONG_DOUBLE == 12#endif // HAS_LongDouble//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////OMNI_USING_NAMESPACE(omni)/////////////////////////////////////////////////////////////////////////////// Deal with insert and extract codeset component in IOR ///////////////////////////////////////////////////////////////////////////////staticvoid initialise_my_code_set(){ CONV_FRAME::CodeSetComponentInfo info; // Could put more conversion_code_sets but our default is sufficent for // most cases. info.ForCharData.native_code_set = orbParameters::nativeCharCodeSet->id(); info.ForCharData.conversion_code_sets.length(1); info.ForCharData.conversion_code_sets[0] = omniCodeSet::ID_UTF_8; info.ForWcharData.native_code_set = orbParameters::nativeWCharCodeSet->id(); info.ForWcharData.conversion_code_sets.length(1); info.ForWcharData.conversion_code_sets[0] = omniCodeSet::ID_UTF_16; omniIOR::add_TAG_CODE_SETS(info);}voidomniIOR::unmarshal_TAG_CODE_SETS(const IOP::TaggedComponent& c, omniIOR& ior){ OMNIORB_ASSERT(c.tag == IOP::TAG_CODE_SETS); cdrEncapsulationStream e(c.component_data.get_buffer(), c.component_data.length(),1); CONV_FRAME::CodeSetComponentInfo info; info <<= e; // Pick a char code set convertor omniCodeSet::TCS_C* tcs_c = 0; if (info.ForCharData.native_code_set) { tcs_c = omniCodeSet::getTCS_C(info.ForCharData.native_code_set, ior.getIORInfo()->version()); } if (!tcs_c) { CORBA::ULong total = info.ForCharData.conversion_code_sets.length(); for (CORBA::ULong index=0; index < total; index++) { tcs_c = omniCodeSet::getTCS_C( info.ForCharData.conversion_code_sets[index], ior.getIORInfo()->version()); if (tcs_c) break; } } if (!tcs_c && (info.ForCharData.native_code_set || info.ForCharData.conversion_code_sets.length())) { // The server has specified its native code set or at least one // conversion code set. But we cannot a TCS_C for any of these // code set. In this case, we use the fallback code set. tcs_c = omniCodeSet::getTCS_C(omniCodeSet::ID_UTF_8, ior.getIORInfo()->version()); } ior.getIORInfo()->TCS_C(tcs_c); // Pick a wchar code set convertor omniCodeSet::TCS_W* tcs_w = 0; if (info.ForWcharData.native_code_set) { tcs_w = omniCodeSet::getTCS_W(info.ForWcharData.native_code_set, ior.getIORInfo()->version()); } if (!tcs_w) { CORBA::ULong total = info.ForWcharData.conversion_code_sets.length(); for (CORBA::ULong index=0; index < total; index++) { tcs_w = omniCodeSet::getTCS_W( info.ForWcharData.conversion_code_sets[index], ior.getIORInfo()->version()); if (tcs_w) break; } } if (!tcs_w && (info.ForWcharData.native_code_set || info.ForWcharData.conversion_code_sets.length())) { // The server has specified its native code set or at least one // conversion code set. But we cannot a TCS_W for any of these // code set. In this case, we use the fallback code set. tcs_w = omniCodeSet::getTCS_W(omniCodeSet::ID_UTF_16, ior.getIORInfo()->version()); } ior.getIORInfo()->TCS_W(tcs_w);}static const char* not_specified = "not specified";static const char* not_supported = "0xXXXXXXXX";static void write_codeset_name(char* buf, const char* cname, CONV_FRAME::CodeSetId id){ if (strcmp(cname,not_supported)) strcat(buf,cname); else { char* p = buf + strlen(buf); sprintf(p,"0x%08lx",(unsigned long)id); }}char*omniIOR::dump_TAG_CODE_SETS(const IOP::TaggedComponent& c){ OMNIORB_ASSERT(c.tag == IOP::TAG_CODE_SETS); cdrEncapsulationStream e(c.component_data.get_buffer(), c.component_data.length(),1); CONV_FRAME::CodeSetComponentInfo info; info <<= e; CORBA::ULong bufsize = 0; const char* ncs_c; const char* ncs_w; {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -