Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

NamingClient.cpp

Go to the documentation of this file.
00001 
00005 /* --------------------------------------------------------------
00006 Copyright (C) 2001 LifeLine Networks BV <soap2corba@lifeline.nl>
00007 
00008 This program is free software; you can redistribute it and/or
00009 modify it under the terms of the GNU General Public License
00010 as published by the Free Software Foundation; either
00011 version 2 of the License, or (at your option) any later
00012 version.
00013 
00014 This program is distributed in the hope that it will be useful,
00015 but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017 GNU General Public License for more details.
00018 
00019 You should have received a copy of the GNU General Public License
00020 along with this program; if not, write to the Free Software
00021 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00022 -------------------------------------------------------------- */
00023 #include <OB/CORBA.h>
00024 #include <OB/CosNaming.h>
00025 #include "NameClient_impl.h"
00026 
00033 int main(int argc, char* argv[])
00034 {
00035     CORBA::ORB_var orb;
00036 
00037     try {
00038         CosNaming::Name name;
00039         CosNaming::NamingContext_var inc;
00040         CosNaming::NamingContext_var myinc;
00041         PortableServer::POA_var poa;
00042         PortableServer::POAManager_var mgr;
00043         orb = CORBA::ORB_init(argc, argv);
00044         try {
00045             CORBA::Object_var nms = orb->resolve_initial_references ("NameService");
00046             inc = CosNaming::NamingContext::_narrow (nms);
00047             assert (!CORBA::is_nil (inc));
00048             name.length (1);
00049             printf ("Binding %s to 'SimpleNameServer' naming context\n", argv [0]);
00050             name [0].id = CORBA::string_dup ("SimpleNameServer");
00051             name [0].kind = CORBA::string_dup ("");
00052             try {
00053                 myinc = inc->bind_new_context (name);
00054             }
00055             catch (const CosNaming::NamingContext::AlreadyBound &) {
00056                 // fine, context already exists
00057                 CORBA::Object_var ncb = inc->resolve (name);
00058                 myinc = CosNaming::NamingContext::_narrow (ncb);
00059             }
00060             catch (...) {
00061                 cout << "Fatal error: some exception while calling NameService!" << endl;
00062             }
00063         }
00064         catch (...) {
00065             cout << "Fatal error: could not contact NameService!" << endl;
00066             return -1;
00067         }
00068         try {
00069             CORBA::Object_var obj = orb->resolve_initial_references ("RootPOA");
00070             poa = PortableServer::POA::_narrow (obj);
00071             mgr = poa->the_POAManager ();
00072             mgr->activate ();
00073         }
00074         catch (...) {
00075             cout << "Fatal error: could not activate POAManager!" << endl;
00076             return -1;
00077         }
00078         try {
00079             SimpleNameServer::SimpleNamingClient_impl *pSimNamClient = 
00080                 new SimpleNameServer::SimpleNamingClient_impl (inc);
00081             {
00082                 SimpleNameServer::SimpleNamingClient_var client = pSimNamClient->_this ();
00083                 // CORBA::String_var str = orb->object_to_string (client);
00084                 // cout << str << endl;
00085                 CosNaming::Name name;
00086                 name.length (1);
00087                 name [0].id = CORBA::string_dup ("SimpleNamingClient");
00088                 name [0].kind = CORBA::string_dup ("");
00089                 myinc->rebind (name, client);
00090             }
00091             orb->run ();
00092             // delete pSimNamClient; 
00093         }
00094         catch (...) {
00095             cout << "Fatal error: could not create client!" << endl;
00096             return -1;
00097         }
00098     }
00099     catch(CORBA::SystemException&) {
00100         cerr << "Caught CORBA::SystemException." << endl;
00101     }
00102     catch(CORBA::Exception&) {
00103         cerr << "Caught CORBA::Exception." << endl;
00104     }
00105     catch(...) {
00106         cerr << "Caught unknown exception." << endl;
00107     }
00108     try {
00109         orb->shutdown (true);
00110         orb->destroy ();
00111     }
00112     catch(...) {
00113         cerr << "Caught unknown exception." << endl;
00114     }
00115     return 0;
00116 }
00117 
00118 

This documentation is part of the "SOAP to CORBA bridge" project
Copyright © 2000 by Lifeline Networks bv.
All rights are reserved.