// eg2_clt.cc - This is the source code of example 2 used in Chapter 2 // "The Basics" of the omniORB user guide. // // This is the client. The object reference is given as a // stringified IOR on the command line. // // Usage: eg2_clt [message] // #include #include static void hello(Echo_ptr e, const char* src) { CORBA::String_var dest = e->echoString(src); cerr << "I said, \"" << (char*)src << "\"." << endl << "The Echo object replied, \"" << (char*)dest <<"\"." << endl; } ////////////////////////////////////////////////////////////////////// int main(int argc, char** argv) { try { CORBA::ORB_var orb = CORBA::ORB_init(argc, argv, "omniORB3"); if( argc < 2 || argc > 3 ) { cerr << "usage: eg2_clt [message]" << endl; return 1; } CORBA::Object_var obj = orb->string_to_object(argv[1]); Echo_var echoref = Echo::_narrow(obj); if( CORBA::is_nil(echoref) ) { cerr << "Can't narrow reference to type Echo (or it was nil)." << endl; return 1; } const char* message = (argc == 3) ? argv[2] : "Hello!"; hello(echoref, message); orb->destroy(); } catch(CORBA::COMM_FAILURE& ex) { cerr << "Caught system exception COMM_FAILURE -- unable to contact the " << "object." << endl; } catch(CORBA::SystemException&) { cerr << "Caught a CORBA::SystemException." << endl; } catch(CORBA::Exception&) { cerr << "Caught CORBA::Exception." << endl; } catch(omniORB::fatalException& fe) { cerr << "Caught omniORB::fatalException:" << endl; cerr << " file: " << fe.file() << endl; cerr << " line: " << fe.line() << endl; cerr << " mesg: " << fe.errmsg() << endl; } catch(...) { cerr << "Caught unknown exception." << endl; } return 0; }