OmniEvents
Orb.h
Go to the documentation of this file.
1 // Package : omniEvents
2 // Orb.h Created : 2003/12/04
3 // Author : Alex Tingle
4 //
5 // Copyright (C) 2003-2005 Alex Tingle.
6 //
7 // This file is part of the omniEvents application.
8 //
9 // omniEvents is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU Lesser General Public
11 // License as published by the Free Software Foundation; either
12 // version 2.1 of the License, or (at your option) any later version.
13 //
14 // omniEvents is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 // Lesser General Public License for more details.
18 //
19 // You should have received a copy of the GNU Lesser General Public
20 // License along with this library; if not, write to the Free Software
21 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 //
23 
24 #ifndef OMNIEVENTS__ORB_H
25 #define OMNIEVENTS__ORB_H
26 
27 #ifdef HAVE_CONFIG_H
28 # include "config.h"
29 #endif
30 
31 #include <list>
32 
33 #ifdef HAVE_OMNIORB3
34 # include <omniORB3/CORBA.h>
35 #endif
36 
37 #ifdef HAVE_OMNIORB4
38 # include <omniORB4/CORBA.h>
39 #endif
40 
41 #ifdef HAVE_OMNIORB4
42 # define IFELSE_OMNIORB4(omniORB4_code,default_code) omniORB4_code
43 # define IF_OMNIORB4(omniORB4_code) omniORB4_code
44 #else
45 # define IFELSE_OMNIORB4(omniORB4_code,default_code) default_code
46 # define IF_OMNIORB4(omniORB4_code)
47 #endif
48 
49 #define DB(l,x) \
50  {if(omniORB::trace(l)){omniORB::logger log("omniEvents: ");log<<x<<"\n";}}
51 
52 #define NP_MINORSTRING(systemException) \
53  ((systemException).NP_minorString()?(systemException).NP_minorString():"??")
54 
55 #define AS_STR_2(x) #x
56 #define AS_STR_1(x) AS_STR_2(x)
58 #define HERE __FILE__ ":" AS_STR_1(__LINE__)
59 
60 #ifdef HAVE_STD_STL
61 using namespace std;
62 #endif
63 
64 namespace OmniEvents {
65 
66 class Callback;
67 
69 class Orb
70 {
71 private:
72  static Orb _inst;
73  typedef pair<CORBA::Request_ptr,Callback*> RequestCallback_t;
74  list<RequestCallback_t> _deferredRequests;
77  Orb():_shutdownRequested(false){}
78  friend void OmniEvents_Orb_shutdown(int);
79 
80 public:
81  inline static Orb& inst()
82  {
83  return _inst;
84  }
86  ~Orb();
87 
88  CORBA::ORB_var _orb;
89  PortableServer::POA_var _RootPOA;
90  PortableServer::POA_var _omniINSPOA;
91  CosNaming::NamingContext_var _NameService;
92 #ifdef HAVE_OMNIORB4
93  PortableServer::Current_ptr _POACurrent;
94 #endif
95 
97  void resolveInitialReferences();
98 
103  void run();
104 
109  void deferredRequest(CORBA::Request_ptr req, Callback* callback=NULL);
110 
112  void cancelCallback(const Callback* callback);
113 
117  void reportObjectFailure(
118  const char* here,
119  CORBA::Object_ptr obj,
120  CORBA::Exception* ex
121  );
122 
126  void shutdown(int) { _shutdownRequested=true; }
127 }; // end class Orb
128 
129 
131 template<class T>
132 typename T::_ptr_type string_to_(const char* oidStr)
133 {
134  CORBA::Object_var obj =Orb::inst()._orb->string_to_object(oidStr);
135  if(CORBA::is_nil(obj.in()))
136  throw CORBA::BAD_PARAM();
137 
138 #ifdef HAVE_OMNIORB4
139  typename T::_var_type result =T::_unchecked_narrow(obj);
140 #else
141  typename T::_var_type result =T::_narrow(obj);
142 #endif
143  if(CORBA::is_nil(result.in()))
144  throw CORBA::BAD_PARAM();
145 
146  return result._retn();
147 }
148 
149 }; // end namespace OmniEvents
150 
151 #endif // OMNIEVENTS__ORB_H
void OmniEvents_Orb_shutdown(int signum)
Signal handler, sets Orb::_shutdownRequested.
Definition: main.cc:312
T::_ptr_type string_to_(const char *oidStr)
Converts a string to a narrowed reference.
Definition: Orb.h:132
Interface for classes that wish to receive callbacks from deferred requests.
Definition: Callback.h:46
Singleton class that owns the ORB and various initial references.
Definition: Orb.h:70
PortableServer::POA_var _RootPOA
Definition: Orb.h:89
pair< CORBA::Request_ptr, Callback * > RequestCallback_t
Definition: Orb.h:73
list< RequestCallback_t > _deferredRequests
Definition: Orb.h:74
CORBA::ORB_var _orb
Definition: Orb.h:88
void cancelCallback(const Callback *callback)
Called by Callback objects when they are destroyed.
static Orb _inst
Definition: Orb.h:72
bool _shutdownRequested
Definition: Orb.h:76
void shutdown(int)
Sets _shutdownRequested.
Definition: Orb.h:126
CosNaming::NamingContext_var _NameService
Definition: Orb.h:91
static Orb & inst()
Definition: Orb.h:81
omni_mutex _deferredRequestsLock
Definition: Orb.h:75
PortableServer::POA_var _omniINSPOA
Definition: Orb.h:90