00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051 #include "naming.h"
00052
00053 #include <stdio.h>
00054
00055 #ifdef HAVE_IOMANIP
00056 # include <iomanip>
00057 #else
00058 # include <iomanip.h>
00059 #endif
00060
00061 #ifdef HAVE_STDLIB_H
00062 # include <stdlib.h>
00063 #endif
00064
00065 CosNaming::NamingContext_ptr
00066 getRootNamingContext(CORBA::ORB_ptr orb)
00067 {
00068 CosNaming::NamingContext_ptr rootContext;
00069 try {
00070
00071
00072 CORBA::Object_var initServ;
00073 initServ = orb->resolve_initial_references("NameService");
00074
00075
00076
00077 rootContext = CosNaming::NamingContext::_narrow(initServ);
00078 if (CORBA::is_nil(rootContext))
00079 {
00080 cerr << "Failed to narrow naming context." << endl;
00081 exit(1);
00082 }
00083 }
00084 catch(CORBA::ORB::InvalidName& ex) {
00085 cerr << "Service required is invalid [does not exist]." << endl;
00086 exit(1);
00087 }
00088 catch (CORBA::COMM_FAILURE& ex)
00089 {
00090 cerr << "Caught system exception COMM_FAILURE, unable to find the "
00091 << "naming service." << endl;
00092 exit(1);
00093 }
00094 catch (omniORB::fatalException& ex) {
00095 cerr << "Caught omniORB fatal exception" << endl;
00096 throw;
00097 }
00098 catch (CORBA::SystemException& ex) {
00099 cerr<<"System exception while resolving the naming service"
00100 #ifdef HAVE_OMNIORB4
00101 <<": "<<ex._name()<<" ("<<ex.NP_minorString()<<")"
00102 #endif
00103 << endl;
00104 exit(1);
00105 }
00106 catch (CORBA::Exception& ex) {
00107 cerr<<"CORBA exception while resolving the naming service"
00108 #ifdef HAVE_OMNIORB4
00109 <<": "<<ex._name()
00110 #endif
00111 << endl;
00112 exit(1);
00113 }
00114
00115 return rootContext;
00116 }
00117
00118 ostream& operator<<(ostream& os, const CosNaming::Name &n)
00119 {
00120 long length = n.length();
00121 for (long l=0; l<length; l++)
00122 {
00123 os << "\"" << (const char *) n[l].id << "\"/\"" << (const char *) n[l].kind << "\" ";
00124 }
00125 return os;
00126 }
00127
00128 void
00129 bindName2Object(CosNaming::NamingContext_ptr c,
00130 const CosNaming::Name & n,
00131 CORBA::Object_ptr obj)
00132 {
00133
00134 try {
00135 c->bind(n, obj);
00136 }
00137 catch(CosNaming::NamingContext::AlreadyBound& ex)
00138 {
00139
00140 c->rebind(n, obj);
00141 }
00142 catch (CORBA::COMM_FAILURE& ex)
00143 {
00144 cerr << "Caught system exception COMM_FAILURE, unable to contact the "
00145 << "naming service." << endl;
00146 exit(1);
00147 }
00148 catch (omniORB::fatalException& ex) {
00149 cerr << "Caught omniORB fatal exception binding " << n << endl;
00150 throw;
00151 }
00152 catch (CORBA::SystemException& ex) {
00153 cerr<<"System exception binding "<<n
00154 #ifdef HAVE_OMNIORB4
00155 <<": "<<ex._name()<<" ("<<ex.NP_minorString()<<")"
00156 #endif
00157 << endl;
00158 exit(1);
00159 }
00160 catch (CORBA::Exception& ex) {
00161 cerr<<"CORBA exception binding "<<n
00162 #ifdef HAVE_OMNIORB4
00163 <<": "<<ex._name()
00164 #endif
00165 << endl;
00166 exit(1);
00167 }
00168
00169
00170 }
00171 ostream& operator<<(ostream& os, const omniORB::objectKey &k)
00172 {
00173 omniORB::seqOctets* ostr = omniORB::keyToOctetSequence(k);
00174
00175
00176 os << hex;
00177 for (unsigned int i = 0; i < ostr->length(); i++) {
00178 os << setfill('0') << setw(2) << (int)(*ostr)[i];
00179 }
00180 os << dec;
00181 delete ostr;
00182 return os;
00183 }
00184
00185
00186 void
00187 str2key(omniORB::objectKey& k, char *str)
00188 {
00189 int l = strlen(str) / 2;
00190 omniORB::seqOctets os(l);
00191 os.length(l);
00192 char* p = str;
00193 for (int i = 0; i < l; i++) {
00194 int n;
00195 sscanf(p,"%02x",&n);
00196 os[i] = n;
00197 p += 2;
00198 }
00199 k = omniORB::octetSequenceToKey(os);
00200 delete [] str;
00201 }
00202
00203