Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

Orb.cc

Go to the documentation of this file.
00001 //                            Package   : omniEvents
00002 // Orb.cc                     Created   : 2003/12/04
00003 //                            Author    : Alex Tingle
00004 //
00005 //    Copyright (C) 2003 Alex Tingle.
00006 //
00007 //    This file is part of the omniEvents application.
00008 //
00009 //    omniEvents is free software; you can redistribute it and/or
00010 //    modify it under the terms of the GNU Lesser General Public
00011 //    License as published by the Free Software Foundation; either
00012 //    version 2.1 of the License, or (at your option) any later version.
00013 //
00014 //    omniEvents 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 GNU
00017 //    Lesser General Public License for more details.
00018 //
00019 //    You should have received a copy of the GNU Lesser General Public
00020 //    License along with this library; if not, write to the Free Software
00021 //    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00022 //
00023 
00024 #include "Orb.h"
00025 
00026 #ifdef HAVE_IOSTREAM
00027 #  include <iostream>
00028 #else
00029 #  include <iostream.h>
00030 #endif
00031 
00032 #include <stdlib.h>
00033 
00034 #define DB(l,x) ((omniORB::traceLevel >= l) && (cerr << x << endl))
00035 
00036 namespace OmniEvents {
00037 
00038 Orb Orb::_inst;
00039 
00040 void Orb::init(int argc, char** argv)
00041 {
00042   _orb=CORBA::ORB_init(argc,argv,"omniORB4");
00043   
00044   CORBA::Object_var obj;
00045 
00046   obj=_orb->resolve_initial_references("RootPOA");
00047   _RootPOA=PortableServer::POA::_narrow(obj);
00048   if(CORBA::is_nil(_RootPOA))
00049   {
00050     cerr<<"Failed to resolve initial reference: RootPOA."<<endl;
00051     exit(1);
00052   }
00053 
00054   obj=_orb->resolve_initial_references("omniINSPOA");
00055   _omniINSPOA=PortableServer::POA::_narrow(obj);
00056   if(CORBA::is_nil(_omniINSPOA))
00057   {
00058     cerr<<"Failed to resolve initial reference: omniINSPOA."<<endl;
00059     exit(1);
00060   }
00061   
00062   obj=_orb->resolve_initial_references("POACurrent");
00063   _POACurrent=PortableServer::Current::_narrow(obj);
00064   if(CORBA::is_nil(_POACurrent))
00065   {
00066     cerr<<"Failed to resolve initial reference: POACurrent."<<endl;
00067     exit(1);
00068   }
00069   
00070   obj=_orb->resolve_initial_references("NameService");
00071   _NameService=CosNaming::NamingContext::_narrow(obj);
00072   if(CORBA::is_nil(_NameService))
00073   {
00074     cerr<<"Failed to resolve initial reference: NameService."<<endl;
00075     exit(1);
00076   }
00077 }
00078 
00079 
00080 void Orb::run()
00081 {
00082   while(true)
00083   {
00084     omni_thread::sleep(5);
00085     list<CORBA::Request_var>::iterator curr, next=_orphans.begin();
00086     while(next!=_orphans.end())
00087     {
00088       curr=next++;
00089       if((*curr)->poll_response())
00090       {
00091         CORBA::Environment_var env=(*curr)->env();
00092         if(!CORBA::is_nil(env) && env->exception())
00093         {
00094           CORBA::Exception* ex =env->exception(); // No need to free exception.
00095           DB(1,"Orphan call to "<<(*curr)->operation()<<"() got exception: "
00096               <<ex->_name()<<endl);
00097         }
00098         else
00099             DB(15,"Orphan call to "<<(*curr)->operation()<<"() returned.");
00100         _orphans.erase(curr);
00101       }
00102     }
00103   }
00104 }
00105 
00106 
00107 void Orb::orphanRequest(CORBA::Request* req)
00108 {
00109   _orphans.push_back(req);
00110 }
00111 
00112 
00113 }; // end namespace OmniEvents

Generated on Fri Dec 12 10:53:02 2003 for OmniEvents by doxygen1.2.15