⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cdrstream.cc

📁 编译工具
💻 CC
📖 第 1 页 / 共 2 页
字号:
    omniCodeSet::NCS_C* n;    n = omniCodeSet::getNCS_C(info.ForCharData.native_code_set);    if (n)      ncs_c = n->name();    else if (info.ForCharData.native_code_set == 0)      ncs_c = not_specified;    else      ncs_c = not_supported;    bufsize += strlen(ncs_c) + 1;  }  {    omniCodeSet::NCS_W* n;    n = omniCodeSet::getNCS_W(info.ForWcharData.native_code_set);    if (n)      ncs_w = n->name();    else if (info.ForWcharData.native_code_set == 0)      ncs_w = not_specified;    else      ncs_w = not_supported;    bufsize += strlen(ncs_w) + 1;  }  CORBA::ULong total,index;  const char** tcs_c;  const char** tcs_w;  total = info.ForCharData.conversion_code_sets.length();  tcs_c = new const char*[total+1];  for (index = 0; index < total; index++) {    omniCodeSet::TCS_C* t;    t = omniCodeSet::getTCS_C(info.ForCharData.conversion_code_sets[index],			      giopStreamImpl::maxVersion()->version());    if (t)      tcs_c[index] = t->name();    else if (info.ForCharData.conversion_code_sets[index] == 0)      tcs_c[index] = not_specified;    else      tcs_c[index] = not_supported;    bufsize += strlen(tcs_c[index]) + 3;  }  tcs_c[index] = 0;  total = info.ForWcharData.conversion_code_sets.length();  tcs_w = new const char*[total+1];  for (index = 0; index < total; index++) {    omniCodeSet::TCS_W* t;    t = omniCodeSet::getTCS_W(info.ForWcharData.conversion_code_sets[index],			      giopStreamImpl::maxVersion()->version());    if (t)      tcs_w[index] = t->name();    else if (info.ForWcharData.conversion_code_sets[index] == 0)      tcs_w[index] = not_specified;    else      tcs_w[index] = not_supported;    bufsize += strlen(tcs_w[index]) + 3;  }  tcs_w[index] = 0;  CORBA::String_var strbuf(CORBA::string_alloc(bufsize+256));  const char** p;  strcpy(strbuf,"TAG_CODE_SETS char native code set: ");  write_codeset_name(strbuf,ncs_c,info.ForCharData.native_code_set);  strcat(strbuf,"\n");  strcat(strbuf,"              char conversion code set: ");  p = tcs_c;  index = 0;  while (*p) {    if (index)       strcat(strbuf,", ");    write_codeset_name(strbuf,*p,info.ForCharData.conversion_code_sets[index]);    p++; index++;  }  strcat(strbuf,"\n");  strcat(strbuf,"              wchar native code set: ");  write_codeset_name(strbuf,ncs_w,info.ForWcharData.native_code_set);  strcat(strbuf,"\n");  strcat(strbuf,"              wchar conversion code set: ");  p = tcs_w;  index = 0;  while (*p) {    if (index)       strcat(strbuf,", ");    write_codeset_name(strbuf,*p,		       info.ForWcharData.conversion_code_sets[index]);    p++; index++;  }  strcat(strbuf,"\n");  delete [] tcs_c;  delete [] tcs_w;  return strbuf._retn();}///////////////////////////////////////////////////////////////////////////////            Client side interceptor for code set service context         ///////////////////////////////////////////////////////////////////////////////staticCORBA::BooleansetCodeSetServiceContext(omniInterceptors::clientSendRequest_T::info_T& info) {  omniCodeSet::TCS_C* tcs_c;  omniCodeSet::TCS_W* tcs_w;  CORBA::Boolean sendcontext = 0;  giopStrand& d = (giopStrand&)(info.giopstream);  GIOP::Version ver = info.giopstream.version();  if (ver.minor < 1) {    // Code set service context is only defined from GIOP 1.1 onwards,    // so here we do not attempt to set a codeset service context.    if (!d.tcs_selected) {      d.tcs_c = omniCodeSet::getTCS_C(omniCodeSet::ID_8859_1,ver);      d.tcs_w = 0;    }    info.giopstream.TCS_C(d.tcs_c);    info.giopstream.TCS_W(d.tcs_w);    return 1;  }  if (d.tcs_selected) {    // giopStream::acquireClient never gives out the same strand    // to run 2 different GIOP versions.    OMNIORB_ASSERT(d.version.major == ver.major && 		   d.version.minor == ver.minor);    tcs_c = d.tcs_c;    tcs_w = d.tcs_w;        // Notice that we do not check the chosen convertors against the IOR    // of the object. In fact, the IOR of the object may specify a set    // of codesets that does not contain the ones we have just selected!    // This is possible because our selection might be based on the IOR    // of another object in the same server and a perverse server may put    // into the 2 IORs a different set of codesets.  }  else {    tcs_c = info.ior.getIORInfo()->TCS_C();    tcs_w = info.ior.getIORInfo()->TCS_W();    if (tcs_c || tcs_w) {      sendcontext = 1;      d.tcs_c = tcs_c;      d.tcs_w = tcs_w;      d.version = ver;      d.tcs_selected = 1;    }    else {      // The server has not supplied any code set information.      // Use the default code set.      tcs_c = omniCodeSet::getTCS_C(omniCodeSet::ID_8859_1,ver);    }  }  info.giopstream.TCS_C(tcs_c);  info.giopstream.TCS_W(tcs_w);    if (sendcontext) {    cdrEncapsulationStream s(CORBA::ULong(0),CORBA::Boolean(1));    tcs_c->id() >>= s;    if (tcs_w) {      tcs_w->id() >>= s;    }    else {      operator>>=(CORBA::ULong(0),s);    }    CORBA::Octet* data;    CORBA::ULong max,datalen;    s.getOctetStream(data,max,datalen);    CORBA::ULong len = info.service_contexts.length() + 1;    info.service_contexts.length(len);    info.service_contexts[len-1].context_id = IOP::CodeSets;    info.service_contexts[len-1].context_data.replace(max,datalen,data,1);    if (omniORB::trace(25)) {      omniORB::logger log;      log << "Send codeset service context: ("	  << tcs_c->name() << "," << ((tcs_w) ? tcs_w->name() : "none")	  << ")\n";    }  }  return 1;}///////////////////////////////////////////////////////////////////////////////            Server side interceptor for code set service context         ///////////////////////////////////////////////////////////////////////////////staticCORBA::BooleangetCodeSetServiceContext(omniInterceptors::serverReceiveRequest_T::info_T& info) {  giopStrand& d = (giopStrand&)(info.giop_s);  GIOP::Version ver = info.giop_s.version();  if (ver.minor < 1) {    // Code set service context is only defined from  GIOP 1.1 onwards    if (!d.tcs_selected) {      d.tcs_c = omniCodeSet::getTCS_C(omniCodeSet::ID_8859_1,ver);      d.tcs_w = 0;    }    info.giop_s.TCS_C(d.tcs_c);    info.giop_s.TCS_W(d.tcs_w);    return 1;  }  omniCodeSet::TCS_C* tcs_c = d.tcs_c;  omniCodeSet::TCS_W* tcs_w = d.tcs_w;  IOP::ServiceContextList& svclist = info.giop_s.service_contexts();  CORBA::ULong total = svclist.length();  for (CORBA::ULong index = 0; index < total; index++) {    if (svclist[index].context_id == IOP::CodeSets) {      cdrEncapsulationStream e(svclist[index].context_data.get_buffer(),			       svclist[index].context_data.length(),1);      CONV_FRAME::CodeSetId tcs_cid, tcs_wid;      tcs_cid <<= e;      tcs_wid <<= e;      if (tcs_cid) {	tcs_c = omniCodeSet::getTCS_C(tcs_cid,ver);      }      else {	// Client do not specify char TCS. Use default.	tcs_c =  omniCodeSet::getTCS_C(omniCodeSet::ID_8859_1,ver);      }      if (tcs_wid) {	tcs_w = omniCodeSet::getTCS_W(tcs_wid,ver);      }      else {	// Client do not specify wchar TCS.	tcs_w = 0;      }      d.version = ver;      d.tcs_c = tcs_c;      d.tcs_w = tcs_w;      d.tcs_selected = 1;      if (omniORB::trace(25)) {	omniORB::logger log;	log << "Receive codeset service context and set TCS to ("	    << ((tcs_c) ? tcs_c->name() : "none") << "," 	    << ((tcs_w) ? tcs_w->name() : "none") << ")\n";      }      break;    }  }  if (!d.tcs_selected) {    // In the absence of any codeset negotiation, we choose     // ISO-8859-1 as the transmission code set for char    d.version.major = ver.major; d.version.minor = ver.minor;    tcs_c = d.tcs_c = omniCodeSet::getTCS_C(omniCodeSet::ID_8859_1,ver);    tcs_w = d.tcs_w = 0;    d.tcs_selected = 1;  }  if (d.version.major != ver.major || d.version.minor != ver.minor) {    // We are in murky water here. The strand has previously been used    // for one GIOP version and now a request of another GIOP version    // is coming in. Does the codeset negotiation established for    // the previous request also apply to this one?    //    // Our interpretation is that the previous codeset negotiation only    // applies to the GIOP version it negotiates for. For the current    // request, we treat the situation as if no negotiation has taken place    // at all.    tcs_c = omniCodeSet::getTCS_C(omniCodeSet::ID_8859_1,ver);    tcs_w = 0;  }  info.giop_s.TCS_C(tcs_c);  info.giop_s.TCS_W(tcs_w);  return 1;}/////////////////////////////////////////////////////////////////////////////static const char* unknown_code_set_msg = "Unknown code set name";/////////////////////////////////////////////////////////////////////////////class nativeCharCodeSetHandler : public orbOptions::Handler {public:  nativeCharCodeSetHandler() :     orbOptions::Handler("nativeCharCodeSet",			"nativeCharCodeSet = <code set name, e.g. ISO-8859-1>",			1,			"-ORBnativeCharCodeSet <code set name, e.g. ISO-8859-1>") {}  void visit(const char* value,orbOptions::Source) throw (orbOptions::BadParam) {        omniCodeSet::NCS_C* v = omniCodeSet::getNCS_C(value);    if (!v) {      throw orbOptions::BadParam(key(),value,unknown_code_set_msg);    }    orbParameters::nativeCharCodeSet = v;  }  void dump(orbOptions::sequenceString& result) {    const char* v;    if (orbParameters::nativeCharCodeSet)      v = orbParameters::nativeCharCodeSet->name();    else      v = "nil";    orbOptions::addKVString(key(),v,result);  }};static nativeCharCodeSetHandler nativeCharCodeSetHandler_;/////////////////////////////////////////////////////////////////////////////class nativeWCharCodeSetHandler : public orbOptions::Handler {public:  nativeWCharCodeSetHandler() :     orbOptions::Handler("nativeWCharCodeSet",			"nativeWCharCodeSet = <code set name, e.g. UTF-16>",			1,			"-ORBnativeWCharCodeSet <code set name, e.g. UTF-16>") {}  void visit(const char* value,orbOptions::Source) throw (orbOptions::BadParam) {        omniCodeSet::NCS_W* v = omniCodeSet::getNCS_W(value);    if (!v) {      throw orbOptions::BadParam(key(),value,unknown_code_set_msg);    }    orbParameters::nativeWCharCodeSet = v;  }  void dump(orbOptions::sequenceString& result) {    const char* v;    if (orbParameters::nativeWCharCodeSet)      v = orbParameters::nativeWCharCodeSet->name();    else      v = "nil";    orbOptions::addKVString(key(),v,result);  }};static nativeWCharCodeSetHandler nativeWCharCodeSetHandler_;///////////////////////////////////////////////////////////////////////////////            Module initialiser                                           ///////////////////////////////////////////////////////////////////////////////OMNI_NAMESPACE_BEGIN(omni)class omni_cdrStream_initialiser : public omniInitialiser {public:  omni_cdrStream_initialiser() {    orbOptions::singleton().registerHandler(nativeCharCodeSetHandler_);    orbOptions::singleton().registerHandler(nativeWCharCodeSetHandler_);  }  void attach() {    if (!orbParameters::nativeCharCodeSet)      orbParameters::nativeCharCodeSet = omniCodeSet::getNCS_C(omniCodeSet::ID_8859_1);    if (!orbParameters::nativeWCharCodeSet)      orbParameters::nativeWCharCodeSet = omniCodeSet::getNCS_W(omniCodeSet::ID_UTF_16);    GIOP::Version ver = giopStreamImpl::maxVersion()->version();    if (!orbParameters::anyCharCodeSet)      orbParameters::anyCharCodeSet =	omniCodeSet::getTCS_C(orbParameters::nativeCharCodeSet->id(), ver);    if (!orbParameters::anyWCharCodeSet)      orbParameters::anyWCharCodeSet =	omniCodeSet::getTCS_W(orbParameters::nativeWCharCodeSet->id(), ver);    // Create the tagged component for all IORs created by this ORB.    initialise_my_code_set();    // install interceptors    omniInterceptors* interceptors = omniORB::getInterceptors();    interceptors->clientSendRequest.add(setCodeSetServiceContext);    interceptors->serverReceiveRequest.add(getCodeSetServiceContext);  }  void detach() {  }};static omni_cdrStream_initialiser initialiser;omniInitialiser& omni_cdrStream_initialiser_ = initialiser;OMNI_NAMESPACE_END(omni)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -