00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
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();
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 };