1 /*----------------------------------------------------------------------------
  2 Name:      CompatibleCorba.cpp
  3 Project:   xmlBlaster.org
  4 Copyright: xmlBlaster.org, see xmlBlaster-LICENSE file
  5 Comment:   functions to encapsulate corba-implementor specific stuff
  6 Version:   $Id: CompatibleCorba.cpp 16474 2007-09-06 22:34:23Z laghi $
  7 Author:    <Michele Laghi> michele@laghi.eu
  8 ----------------------------------------------------------------------------*/
  9 #ifdef _WINDOWS
 10 #pragma warning(disable:4786)
 11 #pragma warning(disable:4251)
 12 #endif
 13 
 14 #include <client/protocol/corba/CompatibleCorba.h>
 15 #include <util/lexical_cast.h>
 16 
 17 using namespace std;
 18 
 19 /*
 20  * Further implementor specific macros which must be called after having
 21  * included the CORBA header files 
 22  */
 23 
 24 
 25 # ifdef XBL_IDL_WITH_WSTRING
 26 void string2wstring(std::wstring &dest,const std::string &src)
 27 {
 28     dest.resize(src.size());
 29     for (uint32_t i=0; i<src.size(); i++)
 30         dest[i] = static_cast<unsigned char>(src[i]);
 31 /*
 32    int xlen = src.size()+1;
 33    wchar_t *x = new wchar_t[xlen]; // Temp buffer
 34    mbstowcs(x, src.c_str(), xlen);
 35    dest = x;
 36    delete [] x; // Clean up temp buffer
 37 
 38    mbstate_t ps;
 39    int xlen = src.size()+1;
 40    wchar_t *cdest = new wchar_t[xlen]; // Temp buffer
 41    mbsrtowcs(cdest, &src.c_str(), xlen, &ps);
 42    dest = cdest;
 43    delete [] cdest; // Clean up temp buffer
 44 */
 45 }
 46 
 47 void wstring2string(std::string &dest,const std::wstring &src)
 48 {
 49     dest.resize(src.size());
 50     for (uint32_t i=0; i<src.size(); i++)
 51         dest[i] = src[i] < 256 ? src[i] : ' ';
 52 }
 53 
 54 std::wstring toWstring(const std::string &src)
 55 {
 56    std::wstring dest;
 57    string2wstring(dest,src);
 58    return dest;
 59 }
 60 
 61 
 62 std::string toString(const std::wstring &src)
 63 {
 64    string dest;
 65    wstring2string(dest,src);
 66    return dest;
 67 }
 68 
 69 std::string corbaWStringToString(const CORBA::WString_var &src)
 70 {
 71    std::string dest;
 72    wstring2string(dest,wstring(src));
 73    return dest;
 74 }
 75 
 76 CORBA::WString_var toCorbaWString(const std::string &src)
 77 {
 78    setlocale(LC_ALL, ""); // set the locale
 79    std::wstring dest = toWstring(src);
 80    //wcout << L"CompatibleCorba: Sending now: " << dest << endl;
 81    CORBA::WString_var var = CORBA::wstring_dup(dest.c_str());
 82    //cout << "CompatibleCorba: Sending now CORBA: " << corbaWStringToString(var) << endl;
 83    return var;
 84    // Who does CORBA::wstring_free() ??
 85 }
 86 # else // XBL_IDL_WITH_WSTRING
 87 std::string corbaWStringToString(const char *src)
 88 {
 89    std::string dest(src);
 90    return dest;
 91 }
 92 
 93 const char *toCorbaWString(const std::string &src)
 94 {
 95    return src.c_str();
 96 }
 97 # endif // XBL_IDL_WITH_WSTRING
 98 
 99 
100 /******************************************************************
101  *                      OMNIORB (4.1.1)
102  ******************************************************************/
103 #ifdef  XMLBLASTER_OMNIORB
104 
105 string to_string(const CORBA::Exception &ex) {
106    string name(ex._name());
107    string repId(ex._rep_id());
108 
109    string ret = "CORBA::Exception name=" + name
110           + " repId=" + repId;
111    return ret;
112 }
113 
114 #endif  // XMLBLASTER_OMNIORB
115 
116 /******************************************************************
117  *                      ORBACUS (OB-4.03)
118  ******************************************************************/
119 #ifdef  XMLBLASTER_ORBACUS
120 
121 string to_string(const CORBA::Exception &ex) {
122    string name(ex._name());
123    string repId(ex._rep_id());
124 
125    string ret = "CORBA::Exception name=" + name
126           + " repId=" + repId;
127    return ret;
128 }
129 
130 #endif  // XMLBLASTER_ORBACUS
131 
132 /*****************************************************************
133  *                     MICO (ver. 2.3.1)
134  *****************************************************************/
135 #ifdef  XMLBLASTER_MICO
136 
137 string to_string(const CORBA::Exception &ex) {
138    return ex._repoid();
139 }
140 
141 #endif  // XMLBLASTER_MICO
142 
143 /*****************************************************************
144  *                    ORBIX 2000 (ver 2.0) 
145  *****************************************************************/
146 #ifdef XMLBLASTER_ORBIX
147 
148 string to_string(const CORBA::Exception &ex ) {
149   return ex._rep_id();
150 }
151 
152 #endif //XMLBLASTER_ORBIX
153 
154 #ifdef  XMLBLASTER_TAO
155 
156 string to_string(const CORBA::Exception &ex) {
157    string name(ex._name());
158    string repId(ex._rep_id());
159    //string typeCode(ex._type());
160    //string info(ex._info()); // info is not portable
161 
162    string ret = "CORBA::Exception name=" + name
163           + " repId=" + repId
164           //+ " typeCode=" + typeCode
165           //+ " info=" + info
166           ;
167    return ret.c_str();
168 }
169 
170 #endif  // XMLBLASTER_TAO


syntax highlighted by Code2HTML, v. 0.9.1