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

SvTmMain.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 <ServerTime_impl.h>
00026 
00027 CORBA::ORB_ptr orb;
00028 
00029 int main (int argc, char *argv [])
00030 {
00031     JTCInitialize initialize;
00032     try {
00033         CosNaming::Name name;
00034         CosNaming::NamingContext_var inc;
00035         CosNaming::NamingContext_var myinc;
00036         PortableServer::POA_var poa;
00037         PortableServer::POAManager_var mgr;
00038         CORBA::ORB_var orbVar = CORBA::ORB_init(argc, argv);
00039         orb = (CORBA::ORB_ptr) orbVar;
00040         try {
00041             CORBA::Object_var nms = orb->resolve_initial_references ("NameService");
00042             inc = CosNaming::NamingContext::_narrow (nms);
00043             assert (!CORBA::is_nil (inc));
00044             name.length (1);
00045             printf ("Binding %s to 'ServerTime' naming context\n", argv [0]);
00046             name [0].id = CORBA::string_dup ("ServerTime");
00047             name [0].kind = CORBA::string_dup ("");
00048             try {
00049                 myinc = inc->bind_new_context (name);
00050             }
00051             catch (const CosNaming::NamingContext::AlreadyBound &) {
00052                 // fine, context already exists
00053                 CORBA::Object_var ncb = inc->resolve (name);
00054                 myinc = CosNaming::NamingContext::_narrow (ncb);
00055             }
00056             catch (...) {
00057                 cout << "Fatal error: some exception while calling NameService!" << endl;
00058             }
00059         }
00060         catch (...) {
00061             cout << "Fatal error: could not contact NameService!" << endl;
00062             return -1;
00063         }
00064         try {
00065             CORBA::Object_var obj = orb->resolve_initial_references ("RootPOA");
00066             poa = PortableServer::POA::_narrow (obj);
00067             mgr = poa->the_POAManager ();
00068             mgr->activate ();
00069         }
00070         catch (...) {
00071             cout << "Fatal error: could not activate POAManager!" << endl;
00072             return -1;
00073         }
00074         try {
00075             ServerTime::Time_impl *pTime = new ServerTime::Time_impl ();
00076             PortableServer::ObjectId_var iid = poa->activate_object(pTime);
00077             {
00078                 ServerTime::Time_var client = pTime->_this ();
00079                 // CORBA::String_var str = orb->object_to_string (client);
00080                 // cout << str << endl;
00081                 CosNaming::Name name;
00082                 name.length (1);
00083                 name [0].id = CORBA::string_dup ("Time");
00084                 name [0].kind = CORBA::string_dup ("");
00085                 myinc->rebind (name, client);
00086             }
00087             orb->run ();
00088         }
00089         catch (...) {
00090             cout << "Fatal error: could not create client!" << endl;
00091             return -1;
00092         }
00093     }
00094     catch(CORBA::SystemException&) {
00095         cerr << "Caught CORBA::SystemException." << endl;
00096     }
00097     catch(CORBA::Exception&) {
00098         cerr << "Caught CORBA::Exception." << endl;
00099     }
00100     catch(...) {
00101         cerr << "Caught unknown exception." << endl;
00102     }
00103     try {
00104         orb->shutdown (true);
00105         orb->destroy ();
00106     }
00107     catch(...) {
00108         cerr << "Caught unknown exception." << endl;
00109     }
00110     return 0;
00111 }
00112 

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