/* * FBFS Distributed Object Repository * Copyright (C) 2001 Francesco V. Bassi * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include <iostream.h> #include "../../idl/NameServer.hh" #include "../../idl/Object.hh" #include "../../idl/Security.hh" #include "../../utils/NameServer.h" using namespace fbfs; static void resolv(NameServer_ptr e, string name) { if( CORBA::is_nil(e) ) { cerr << "hello: The object reference is nil!\n" << endl; return; } Obj_id id; Security sec; id.name = CORBA::string_dup( name.c_str() ); try { CORBA::String_var dest = e->lookup(sec, id); cerr << "The NameServer object replied: \"" << (char*)dest <<"\"." << endl; } catch(NotFound) { cout << "Not Found\n"; } catch(SecurityException) { cout << "Security Exception\n"; } catch(InternalError) { cout << "NameServer Internal Error\n"; } catch(...) { cout << "very, very unusual. Check code.\n"; }; } int main (int argc, char **argv) { try { CORBA::ORB_var orb = CORBA::ORB_init(argc, argv, "omniORB3"); if(argc != 3) { cerr << "Usage: " << argv[0] << "<NameServer URI> <Name>\n"; return 0; }; utils::URI uri = utils::URI(argv[1]); cout << "NameServer URI: " << uri.toString() << "\n"; CORBA::Object_var obj = utils::NameServer::get_object(orb, uri); NameServer_var nameserver = NameServer::_narrow(obj); resolv(nameserver, argv[2]); orb->destroy(); } catch(CORBA::COMM_FAILURE& ex) { cerr << "Caught system exception COMM_FAILURE -- unable to contact the " << "object." << endl; } catch(CORBA::SystemException&) { cerr << "Caught 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; }