Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

Orb.h

Go to the documentation of this file.
00001 //                            Package   : omniEvents
00002 // Orb.h                      Created   : 2003/12/04
00003 //                            Author    : Alex Tingle
00004 //
00005 //    Copyright (C) 2003-2005 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 #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 }; // end class Orb
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 }; // end namespace OmniEvents
00150 
00151 #endif // OMNIEVENTS__ORB_H

Generated on Fri Aug 26 20:56:14 2005 for OmniEvents by  doxygen 1.4.3-20050530