00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef OMNIEVENTS__ORB_H
00025 #define OMNIEVENTS__ORB_H
00026
00027 #ifdef HAVE_CONFIG_H
00028 # include "config.h"
00029 #endif
00030
00031 #include <list>
00032
00033 #ifdef HAVE_OMNIORB3
00034 # include <omniORB3/CORBA.h>
00035 #endif
00036
00037 #ifdef HAVE_OMNIORB4
00038 # include <omniORB4/CORBA.h>
00039 #endif
00040
00041 #ifdef HAVE_OMNIORB4
00042 # define IFELSE_OMNIORB4(omniORB4_code,default_code) omniORB4_code
00043 # define IF_OMNIORB4(omniORB4_code) omniORB4_code
00044 #else
00045 # define IFELSE_OMNIORB4(omniORB4_code,default_code) default_code
00046 # define IF_OMNIORB4(omniORB4_code)
00047 #endif
00048
00049 #define DB(l,x) \
00050 {if(omniORB::trace(l)){omniORB::logger log("omniEvents: ");log<<x<<"\n";}}
00051
00052 #define NP_MINORSTRING(systemException) \
00053 ((systemException).NP_minorString()?(systemException).NP_minorString():"??")
00054
00055 #define AS_STR_2(x) #x
00056 #define AS_STR_1(x) AS_STR_2(x)
00057
00058 #define HERE __FILE__ ":" AS_STR_1(__LINE__)
00059
00060 #ifdef HAVE_STD_STL
00061 using namespace std;
00062 #endif
00063
00064 namespace OmniEvents {
00065
00066 class Callback;
00067
00069 class Orb
00070 {
00071 private:
00072 static Orb _inst;
00073 typedef pair<CORBA::Request_ptr,Callback*> RequestCallback_t;
00074 list<RequestCallback_t> _deferredRequests;
00075 omni_mutex _deferredRequestsLock;
00076 bool _shutdownRequested;
00077 Orb():_shutdownRequested(false){}
00078 friend void OmniEvents_Orb_shutdown(int);
00079
00080 public:
00081 inline static Orb& inst()
00082 {
00083 return _inst;
00084 }
00086 ~Orb();
00087
00088 CORBA::ORB_var _orb;
00089 PortableServer::POA_var _RootPOA;
00090 PortableServer::POA_var _omniINSPOA;
00091 CosNaming::NamingContext_var _NameService;
00092 #ifdef HAVE_OMNIORB4
00093 PortableServer::Current_ptr _POACurrent;
00094 #endif
00095
00097 void resolveInitialReferences();
00098
00103 void run();
00104
00109 void deferredRequest(CORBA::Request_ptr req, Callback* callback=NULL);
00110
00112 void cancelCallback(const Callback* callback);
00113
00117 void reportObjectFailure(
00118 const char* here,
00119 CORBA::Object_ptr obj,
00120 CORBA::Exception* ex
00121 );
00122
00126 void shutdown(int) { _shutdownRequested=true; }
00127 };
00128
00129
00131 template<class T>
00132 typename T::_ptr_type string_to_(const char* oidStr)
00133 {
00134 CORBA::Object_var obj =Orb::inst()._orb->string_to_object(oidStr);
00135 if(CORBA::is_nil(obj.in()))
00136 throw CORBA::BAD_PARAM();
00137
00138 #ifdef HAVE_OMNIORB4
00139 typename T::_var_type result =T::_unchecked_narrow(obj);
00140 #else
00141 typename T::_var_type result =T::_narrow(obj);
00142 #endif
00143 if(CORBA::is_nil(result.in()))
00144 throw CORBA::BAD_PARAM();
00145
00146 return result._retn();
00147 }
00148
00149 };
00150
00151 #endif // OMNIEVENTS__ORB_H