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

main.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 <iostream.h>
00024 #include <OB/CORBA.h>
00025 #include <OB/CosNaming.h>
00026 #include "BridgeStub.h"
00027 #include "Parser.h"
00028 #include "StdAfx.h"
00029 #include "SoapCorba.h"
00030 #include "DbObjects.h"
00031 #include "ReadIR.h"
00032 #include "SoapBridge.h"
00033 #include "SoapBridge_skel.h"
00034 #include <sys/timeb.h>
00035 #include "sbimpl.h"
00036 
00038 CORBA::ORB_ptr orb;
00039 
00041 DynamicAny::DynAnyFactory_var dynFact;
00042 
00044 IRPLUS_H irplusHandle;
00045 
00047 CORBA::String_var ObjCtxMan_SIOR;
00048 
00054 JTCMonitor *p_struct_tm_monitor;
00055 
00057 int main (int argn, char *argv [])
00058 {
00059     ANYCFG_H cfgHdl = sbInitialize (argn, argv);
00060     p_struct_tm_monitor = new JTCMonitor;
00061     CORBA_H corbaHdl = initCorba (argn, argv);
00062     orb = (CORBA::ORB_ptr) corbaHdl;
00063     {
00064         CORBA::Object_var factObj = orb->resolve_initial_references ("DynAnyFactory");
00065         dynFact = DynamicAny::DynAnyFactory::_narrow (factObj);
00066     }
00067     irplusHandle = initIRPlus (corbaHdl, cfgHdl);
00068     try {
00069         CosNaming::Name name;
00070         CosNaming::NamingContext_var inc;
00071         CosNaming::NamingContext_var myinc;
00072         PortableServer::POA_var poa;
00073         PortableServer::POAManager_var mgr;
00074         try {
00075             CORBA::Object_var nms = orb->resolve_initial_references ("NameService");
00076             inc = CosNaming::NamingContext::_narrow (nms);
00077             assert (!CORBA::is_nil (inc));
00078             name.length (1);
00079             printf ("Binding %s to 'SOAPBridge' naming context\n", argv [0]);
00080             name [0].id = CORBA::string_dup ("SOAPBridge");
00081             name [0].kind = CORBA::string_dup ("");
00082             try {
00083                 myinc = inc->bind_new_context (name);
00084             }
00085             catch (const CosNaming::NamingContext::AlreadyBound &) {
00086                 // fine, context already exists
00087                 CORBA::Object_var ncb = inc->resolve (name);
00088                 myinc = CosNaming::NamingContext::_narrow (ncb);
00089             }
00090             catch (...) {
00091                 cout << "Fatal error: some exception while calling NameService!" << endl;
00092             }
00093         }
00094         catch (...) {
00095             cout << "Fatal error: could not contact NameService!" << endl;
00096             return -1;
00097         }
00098         try {
00099             CORBA::Object_var obj;
00100             CosNaming::Name name;
00101             name.length (1);
00102             name [0].id = CORBA::string_dup ("ObjectContextManager");
00103             name [0].kind = CORBA::string_dup ("");
00104             obj = myinc->resolve (name);
00105             ObjCtxMan_SIOR = orb->object_to_string (obj);
00106         }
00107         catch (...) {
00108             cout << "Fatal error: could not resolve 'SOAPBridge/ObjectContextManager'!" << endl;
00109             return -1;
00110         }
00111         try {
00112             CORBA::Object_var obj = orb->resolve_initial_references ("RootPOA");
00113             poa = PortableServer::POA::_narrow (obj);
00114             mgr = poa->the_POAManager ();
00115             mgr->activate ();
00116         }
00117         catch (...) {
00118             cout << "Fatal error: could not activate POAManager!" << endl;
00119             return -1;
00120         }
00121         try {
00122             SOAPBridge_SOAPCall_i *pCall = new SOAPBridge_SOAPCall_i(inc);
00123             PortableServer::ObjectId_var mySOAPBridge_SOAPCall_iid = poa->activate_object(pCall);
00124             // Obtain a reference to the object and store it in the NamingService
00125             {
00126                 // IDL interface: SOAPBridge::ContextManager
00127                 CORBA::Object_var ref = pCall->_this();
00128                 CosNaming::Name name;
00129                 name.length (1);
00130                 name [0].id = CORBA::string_dup ("SOAPCall");
00131                 name [0].kind = CORBA::string_dup ("");
00132                 myinc->rebind (name, ref);
00133             }
00134         }
00135         catch (...) {
00136             cout << "Fatal error: could not create SOAPCall service!" << endl;
00137             return -1;
00138         }
00139         try {
00140             SOAPBridge_TypeConversions_impl *pConv = new SOAPBridge_TypeConversions_impl (poa);
00141             PortableServer::ObjectId_var mySOAPBridge_TypeConversions_iid = poa->activate_object(pConv);
00142             // Obtain a reference to the object and store it in the NamingService
00143             {
00144                 CORBA::Object_var ref = pConv->_this();
00145                 CosNaming::Name name;
00146                 name.length (1);
00147                 name [0].id = CORBA::string_dup ("TypeConversions");
00148                 name [0].kind = CORBA::string_dup ("");
00149                 myinc->rebind (name, ref);
00150             }
00151         }
00152         catch (...) {
00153             cout << "Fatal error: could not create SOAPCall service!" << endl;
00154             return -1;
00155         }
00156         try {
00157             SOAPBridge::CORBACall_impl *pi = new SOAPBridge::CORBACall_impl (poa);
00158             PortableServer::ObjectId_var id = poa -> activate_object(pi);
00159             // Obtain a reference to the object and store it in the NamingService
00160             {
00161                 CORBA::Object_var ref = pi->_this();
00162                 CosNaming::Name name;
00163                 name.length (1);
00164                 name [0].id = CORBA::string_dup ("CORBACall");
00165                 name [0].kind = CORBA::string_dup ("");
00166                 myinc->rebind (name, ref);
00167             }
00168         }
00169         catch (...) {
00170             cout << "Fatal error: could not create CORBACall service!" << endl;
00171             return -1;
00172         }
00173         //
00174         // Create implementation objects
00175         //
00176     
00177         orb->run ();
00178     }
00179     catch(CORBA::SystemException&) {
00180         cerr << "Caught CORBA::SystemException." << endl;
00181     }
00182     catch(CORBA::Exception&) {
00183         cerr << "Caught CORBA::Exception." << endl;
00184     }
00185     catch(...) {
00186         cerr << "Caught unknown exception." << endl;
00187     }
00188     try {
00189         orb->shutdown (true);
00190         orb->destroy ();
00191     }
00192     catch(...) {
00193         cerr << "Caught unknown exception." << endl;
00194     }
00195     termCorba (corbaHdl);
00196     sbTerminate (cfgHdl);
00197     return 0;
00198 }
00199 
00200 

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