client/protocol/corba/CompatibleCorba.cpp

Go to the documentation of this file.
00001 /*----------------------------------------------------------------------------
00002 Name:      CompatibleCorba.cpp
00003 Project:   xmlBlaster.org
00004 Copyright: xmlBlaster.org, see xmlBlaster-LICENSE file
00005 Comment:   functions to encapsulate corba-implementor specific stuff
00006 Version:   $Id: CompatibleCorba.cpp 16474 2007-09-06 22:34:23Z laghi $
00007 Author:    <Michele Laghi> michele@laghi.eu
00008 ----------------------------------------------------------------------------*/
00009 #ifdef _WINDOWS
00010 #pragma warning(disable:4786)
00011 #pragma warning(disable:4251)
00012 #endif
00013 
00014 #include <client/protocol/corba/CompatibleCorba.h>
00015 #include <util/lexical_cast.h>
00016 
00017 using namespace std;
00018 
00019 /*
00020  * Further implementor specific macros which must be called after having
00021  * included the CORBA header files 
00022  */
00023 
00024 
00025 # ifdef XBL_IDL_WITH_WSTRING
00026 void string2wstring(std::wstring &dest,const std::string &src)
00027 {
00028     dest.resize(src.size());
00029     for (uint32_t i=0; i<src.size(); i++)
00030         dest[i] = static_cast<unsigned char>(src[i]);
00031 /*
00032    int xlen = src.size()+1;
00033    wchar_t *x = new wchar_t[xlen]; // Temp buffer
00034    mbstowcs(x, src.c_str(), xlen);
00035    dest = x;
00036    delete [] x; // Clean up temp buffer
00037 
00038    mbstate_t ps;
00039    int xlen = src.size()+1;
00040    wchar_t *cdest = new wchar_t[xlen]; // Temp buffer
00041    mbsrtowcs(cdest, &src.c_str(), xlen, &ps);
00042    dest = cdest;
00043    delete [] cdest; // Clean up temp buffer
00044 */
00045 }
00046 
00047 void wstring2string(std::string &dest,const std::wstring &src)
00048 {
00049     dest.resize(src.size());
00050     for (uint32_t i=0; i<src.size(); i++)
00051         dest[i] = src[i] < 256 ? src[i] : ' ';
00052 }
00053 
00054 std::wstring toWstring(const std::string &src)
00055 {
00056    std::wstring dest;
00057    string2wstring(dest,src);
00058    return dest;
00059 }
00060 
00061 
00062 std::string toString(const std::wstring &src)
00063 {
00064    string dest;
00065    wstring2string(dest,src);
00066    return dest;
00067 }
00068 
00069 std::string corbaWStringToString(const CORBA::WString_var &src)
00070 {
00071    std::string dest;
00072    wstring2string(dest,wstring(src));
00073    return dest;
00074 }
00075 
00076 CORBA::WString_var toCorbaWString(const std::string &src)
00077 {
00078    setlocale(LC_ALL, ""); // set the locale
00079    std::wstring dest = toWstring(src);
00080    //wcout << L"CompatibleCorba: Sending now: " << dest << endl;
00081    CORBA::WString_var var = CORBA::wstring_dup(dest.c_str());
00082    //cout << "CompatibleCorba: Sending now CORBA: " << corbaWStringToString(var) << endl;
00083    return var;
00084    // Who does CORBA::wstring_free() ??
00085 }
00086 # else // XBL_IDL_WITH_WSTRING
00087 std::string corbaWStringToString(const char *src)
00088 {
00089    std::string dest(src);
00090    return dest;
00091 }
00092 
00093 const char *toCorbaWString(const std::string &src)
00094 {
00095    return src.c_str();
00096 }
00097 # endif // XBL_IDL_WITH_WSTRING
00098 
00099 
00100 /******************************************************************
00101  *                      OMNIORB (4.1.1)
00102  ******************************************************************/
00103 #ifdef  XMLBLASTER_OMNIORB
00104 
00105 string to_string(const CORBA::Exception &ex) {
00106    string name(ex._name());
00107    string repId(ex._rep_id());
00108 
00109    string ret = "CORBA::Exception name=" + name
00110           + " repId=" + repId;
00111    return ret;
00112 }
00113 
00114 #endif  // XMLBLASTER_OMNIORB
00115 
00116 /******************************************************************
00117  *                      ORBACUS (OB-4.03)
00118  ******************************************************************/
00119 #ifdef  XMLBLASTER_ORBACUS
00120 
00121 string to_string(const CORBA::Exception &ex) {
00122    string name(ex._name());
00123    string repId(ex._rep_id());
00124 
00125    string ret = "CORBA::Exception name=" + name
00126           + " repId=" + repId;
00127    return ret;
00128 }
00129 
00130 #endif  // XMLBLASTER_ORBACUS
00131 
00132 /*****************************************************************
00133  *                     MICO (ver. 2.3.1)
00134  *****************************************************************/
00135 #ifdef  XMLBLASTER_MICO
00136 
00137 string to_string(const CORBA::Exception &ex) {
00138    return ex._repoid();
00139 }
00140 
00141 #endif  // XMLBLASTER_MICO
00142 
00143 /*****************************************************************
00144  *                    ORBIX 2000 (ver 2.0) 
00145  *****************************************************************/
00146 #ifdef XMLBLASTER_ORBIX
00147 
00148 string to_string(const CORBA::Exception &ex ) {
00149   return ex._rep_id();
00150 }
00151 
00152 #endif //XMLBLASTER_ORBIX
00153 
00154 #ifdef  XMLBLASTER_TAO
00155 
00156 string to_string(const CORBA::Exception &ex) {
00157    string name(ex._name());
00158    string repId(ex._rep_id());
00159    //string typeCode(ex._type());
00160    //string info(ex._info()); // info is not portable
00161 
00162    string ret = "CORBA::Exception name=" + name
00163           + " repId=" + repId
00164           //+ " typeCode=" + typeCode
00165           //+ " info=" + info
00166           ;
00167    return ret.c_str();
00168 }
00169 
00170 #endif  // XMLBLASTER_TAO
00171