1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>Orb.cc Source File</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.2.15 -->
<center>
<a class="qindex" href="main.html">Main Page</a> <a class="qindex" href="namespaces.html">Namespace List</a> <a class="qindex" href="hierarchy.html">Class Hierarchy</a> <a class="qindex" href="annotated.html">Compound List</a> <a class="qindex" href="files.html">File List</a> <a class="qindex" href="namespacemembers.html">Namespace Members</a> <a class="qindex" href="functions.html">Compound Members</a> <a class="qindex" href="globals.html">File Members</a> </center>
<hr><h1>Orb.cc</h1><a href="a00114.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001 <font class="comment">// Package : omniEvents</font>
00002 <font class="comment">// Orb.cc Created : 2003/12/04</font>
00003 <font class="comment">// Author : Alex Tingle</font>
00004 <font class="comment">//</font>
00005 <font class="comment">// Copyright (C) 2003 Alex Tingle.</font>
00006 <font class="comment">//</font>
00007 <font class="comment">// This file is part of the omniEvents application.</font>
00008 <font class="comment">//</font>
00009 <font class="comment">// omniEvents is free software; you can redistribute it and/or</font>
00010 <font class="comment">// modify it under the terms of the GNU Lesser General Public</font>
00011 <font class="comment">// License as published by the Free Software Foundation; either</font>
00012 <font class="comment">// version 2.1 of the License, or (at your option) any later version.</font>
00013 <font class="comment">//</font>
00014 <font class="comment">// omniEvents is distributed in the hope that it will be useful,</font>
00015 <font class="comment">// but WITHOUT ANY WARRANTY; without even the implied warranty of</font>
00016 <font class="comment">// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU</font>
00017 <font class="comment">// Lesser General Public License for more details.</font>
00018 <font class="comment">//</font>
00019 <font class="comment">// You should have received a copy of the GNU Lesser General Public</font>
00020 <font class="comment">// License along with this library; if not, write to the Free Software</font>
00021 <font class="comment">// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA</font>
00022 <font class="comment">//</font>
00023
00024 <font class="preprocessor">#include "<a class="code" href="a00115.html">Orb.h</a>"</font>
00025
00026 <font class="preprocessor">#ifdef HAVE_IOSTREAM</font>
00027 <font class="preprocessor"></font><font class="preprocessor"># include <iostream></font>
00028 <font class="preprocessor">#else</font>
00029 <font class="preprocessor"></font><font class="preprocessor"># include <iostream.h></font>
00030 <font class="preprocessor">#endif</font>
00031 <font class="preprocessor"></font>
00032 <font class="preprocessor">#include <stdlib.h></font>
00033 <font class="preprocessor">#include <assert.h></font>
00034
00035 <font class="preprocessor">#include "<a class="code" href="a00081.html">Callback.h</a>"</font>
00036
00037 <font class="keyword">namespace </font>OmniEvents {
00038
<a name="l00039"></a><a class="code" href="a00059.html#r0">00039</a> <a class="code" href="a00059.html">Orb</a> Orb::_inst;
00040
00041
<a name="l00042"></a><a class="code" href="a00059.html#a0">00042</a> Orb::~Orb()
00043 {
00044 omni_mutex_lock l(<a class="code" href="a00059.html#o1">_deferredRequestsLock</a>);
00045 list<RequestCallback_t>::iterator curr, next=<a class="code" href="a00059.html#o0">_deferredRequests</a>.begin();
00046 <font class="keywordflow">while</font>(next!=<a class="code" href="a00059.html#o0">_deferredRequests</a>.end())
00047 {
00048 curr=next++;
00049 CORBA::release(curr->first);
00050 <a class="code" href="a00059.html#o0">_deferredRequests</a>.erase(curr);
00051 }
00052 }
00053
00054
<a name="l00055"></a><a class="code" href="a00059.html#a1">00055</a> <font class="keywordtype">void</font> Orb::resolveInitialReferences()
00056 {
00057 assert(!CORBA::is_nil(<a class="code" href="a00059.html#m0">_orb</a>));
00058
00059 <font class="keyword">const</font> <font class="keywordtype">char</font>* action=<font class="stringliteral">""</font>; <font class="comment">// Use this variable to help report errors.</font>
00060 <font class="keywordflow">try</font>
00061 {
00062 CORBA::Object_var obj;
00063
00064 action=<font class="stringliteral">"resolve initial reference 'RootPOA'"</font>;
00065 obj=<a class="code" href="a00059.html#m0">_orb</a>->resolve_initial_references(<font class="stringliteral">"RootPOA"</font>);
00066 <a class="code" href="a00059.html#m1">_RootPOA</a>=PortableServer::POA::_narrow(obj);
00067 <font class="keywordflow">if</font>(CORBA::is_nil(<a class="code" href="a00059.html#m1">_RootPOA</a>))
00068 <font class="keywordflow">throw</font> CORBA::OBJECT_NOT_EXIST();
00069
00070 action=<font class="stringliteral">"resolve initial reference 'omniINSPOA'"</font>;
00071 obj=<a class="code" href="a00059.html#m0">_orb</a>->resolve_initial_references(<font class="stringliteral">"omniINSPOA"</font>);
00072 <a class="code" href="a00059.html#m2">_omniINSPOA</a>=PortableServer::POA::_narrow(obj);
00073 <font class="keywordflow">if</font>(CORBA::is_nil(<a class="code" href="a00059.html#m2">_omniINSPOA</a>))
00074 <font class="keywordflow">throw</font> CORBA::OBJECT_NOT_EXIST();
00075
00076 <font class="comment">// The naming service is optional.</font>
00077 <font class="keywordflow">try</font>
00078 {
00079 action=<font class="stringliteral">"resolve initial reference 'NameService'"</font>;
00080 obj=<a class="code" href="a00059.html#m0">_orb</a>->resolve_initial_references(<font class="stringliteral">"NameService"</font>);
00081 <a class="code" href="a00059.html#m3">_NameService</a>=CosNaming::NamingContext::_narrow(obj);
00082 }
00083 <font class="keywordflow">catch</font>(CORBA::Exception& ex)
00084 {
00085 <a class="code" href="a00115.html#a2">DB</a>(1,<font class="stringliteral">"Warning - failed to "</font><<action<<
00086 <a class="code" href="a00115.html#a0">IFELSE_OMNIORB4</a>(<font class="stringliteral">". Exception: "</font><<ex._name(),<font class="stringliteral">"."</font>))
00087 }
00088
00089 <font class="preprocessor">#ifdef HAVE_OMNIORB4</font>
00090 <font class="preprocessor"></font> action=<font class="stringliteral">"resolve initial reference 'POACurrent'"</font>;
00091 obj=<a class="code" href="a00059.html#m0">_orb</a>->resolve_initial_references(<font class="stringliteral">"POACurrent"</font>);
00092 _POACurrent=PortableServer::Current::_narrow(obj);
00093 <font class="keywordflow">if</font>(CORBA::is_nil(_POACurrent))
00094 <font class="keywordflow">throw</font> CORBA::OBJECT_NOT_EXIST();
00095 <font class="preprocessor">#endif</font>
00096 <font class="preprocessor"></font>
00097 <font class="keywordflow">return</font>;
00098 }
00099 <font class="keywordflow">catch</font>(CORBA::ORB::InvalidName& ex) <font class="comment">// resolve_initial_references</font>
00100 {
00101 <a class="code" href="a00115.html#a2">DB</a>(0,<font class="stringliteral">"Failed to "</font><<action<<<font class="stringliteral">". InvalidName"</font>)
00102 }
00103 <font class="keywordflow">catch</font>(CORBA::TRANSIENT& ex) <font class="comment">// _narrow()</font>
00104 {
00105 <a class="code" href="a00115.html#a2">DB</a>(0,<font class="stringliteral">"Failed to "</font><<action<<<font class="stringliteral">". TRANSIENT"</font>)
00106 }
00107 <font class="keywordflow">catch</font>(CORBA::OBJECT_NOT_EXIST& ex) <font class="comment">// _narrow()</font>
00108 {
00109 <a class="code" href="a00115.html#a2">DB</a>(0,<font class="stringliteral">"Failed to "</font><<action<<<font class="stringliteral">". OBJECT_NOT_EXIST"</font>)
00110 }
00111 <font class="keywordflow">catch</font>(CORBA::SystemException& ex)
00112 {
00113 <a class="code" href="a00115.html#a2">DB</a>(0,<font class="stringliteral">"Failed to "</font><<action<<<font class="stringliteral">"."</font>
00114 <a class="code" href="a00115.html#a1">IF_OMNIORB4</a>(<font class="stringliteral">" "</font><<ex._name()<<<font class="stringliteral">" ("</font><<<a class="code" href="a00115.html#a3">NP_MINORSTRING</a>(ex)<<<font class="stringliteral">")"</font>) )
00115 }
00116 <font class="keywordflow">catch</font>(CORBA::Exception& ex)
00117 {
00118 <a class="code" href="a00115.html#a2">DB</a>(0,<font class="stringliteral">"Failed to "</font><<action<<<font class="stringliteral">"."</font> <a class="code" href="a00115.html#a1">IF_OMNIORB4</a>(<font class="stringliteral">" "</font><<ex._name()) )
00119 }
00120 exit(1);
00121 }
00122
00123
<a name="l00124"></a><a class="code" href="a00059.html#a2">00124</a> <font class="keywordtype">void</font> Orb::run()
00125 {
00126 <font class="keywordflow">while</font>(!<a class="code" href="a00059.html#o2">_shutdownRequested</a>)
00127 {
00128 omni_thread::sleep(5);
00129 omni_mutex_lock l(<a class="code" href="a00059.html#o1">_deferredRequestsLock</a>);
00130 <a class="code" href="a00115.html#a2">DB</a>(20,<font class="stringliteral">"Polling "</font><<<a class="code" href="a00059.html#o0">_deferredRequests</a>.size()<<<font class="stringliteral">" deferred requests."</font>)
00131 list<RequestCallback_t>::iterator curr, next=<a class="code" href="a00059.html#o0">_deferredRequests</a>.begin();
00132 <font class="keywordflow">while</font>(next!=<a class="code" href="a00059.html#o0">_deferredRequests</a>.end())
00133 {
00134 curr=next++;
00135 <font class="keywordflow">if</font>(curr->first->poll_response())
00136 {
00137 CORBA::Environment_ptr env=curr->first->env();<font class="comment">// No need to release env.</font>
00138 <font class="keywordflow">if</font>(!CORBA::is_nil(env) && env->exception())
00139 {
00140 CORBA::Exception* ex =env->exception(); <font class="comment">// No need to free exception.</font>
00141 <a class="code" href="a00115.html#a2">DB</a>(10,<font class="stringliteral">"Deferred call to "</font><<curr->first->operation()
00142 <<<font class="stringliteral">"() got exception"</font> <a class="code" href="a00115.html#a1">IF_OMNIORB4</a>(<<<font class="stringliteral">": "</font><<ex->_name()))
00143 }
00144 <font class="keywordflow">else</font> <font class="keywordflow">if</font>(curr->second && curr->second->isValid())
00145 {
00146 <a class="code" href="a00115.html#a2">DB</a>(15,<font class="stringliteral">"Deferred call to "</font><<curr->first->operation()<<<font class="stringliteral">"() returned."</font>)
00147 curr->second->callback(curr->first);
00148 }
00149 <font class="keywordflow">else</font>
00150 {
00151 <a class="code" href="a00115.html#a2">DB</a>(15,<font class="stringliteral">"Orphan call to "</font><<curr->first->operation()<<<font class="stringliteral">"() returned."</font>)
00152 }
00153 CORBA::release(curr->first);
00154 <a class="code" href="a00059.html#o0">_deferredRequests</a>.erase(curr);
00155 }
00156 }
00157 }
00158 }
00159
00160
<a name="l00161"></a><a class="code" href="a00059.html#a3">00161</a> <font class="keywordtype">void</font> Orb::deferredRequest(CORBA::Request_ptr req, <a class="code" href="a00041.html">Callback</a>* callback)
00162 {
00163 omni_mutex_lock l(<a class="code" href="a00059.html#o1">_deferredRequestsLock</a>);
00164 <font class="keywordflow">if</font>(callback)
00165 <a class="code" href="a00059.html#o0">_deferredRequests</a>.push_front(<a class="code" href="a00059.html#u0">RequestCallback_t</a>(req,callback));
00166 <font class="keywordflow">else</font>
00167 <a class="code" href="a00059.html#o0">_deferredRequests</a>.push_back(<a class="code" href="a00059.html#u0">RequestCallback_t</a>(req,NULL));
00168 }
00169
00170
<a name="l00171"></a><a class="code" href="a00059.html#a4">00171</a> <font class="keywordtype">void</font> Orb::cancelCallback(<font class="keyword">const</font> <a class="code" href="a00041.html">Callback</a>* callback)
00172 {
00173 omni_mutex_lock l(<a class="code" href="a00059.html#o1">_deferredRequestsLock</a>);
00174 list<RequestCallback_t>::iterator i=<a class="code" href="a00059.html#o0">_deferredRequests</a>.begin();
00175 <font class="comment">// All the callback are at the front, so we can stop when i->second==NULL.</font>
00176 <font class="keywordflow">while</font>(i!=<a class="code" href="a00059.html#o0">_deferredRequests</a>.end() && i->second)
00177 {
00178 <font class="keywordflow">if</font>(i->second==callback)
00179 i->second=NULL;
00180 ++i;
00181 }
00182 }
00183
00184
<a name="l00185"></a><a class="code" href="a00059.html#a5">00185</a> <font class="keywordtype">void</font> Orb::reportObjectFailure(
00186 <font class="keyword">const</font> <font class="keywordtype">char</font>* here,
00187 CORBA::Object_ptr obj,
00188 CORBA::Exception* ex
00189 )
00190 {
00191 assert(!CORBA::is_nil(obj));
00192 <font class="preprocessor">#ifdef HAVE_OMNIORB4</font>
00193 <font class="preprocessor"></font> {
00194 <font class="comment">// Hack! The '!' signals object failure.</font>
00195 <font class="comment">// See DaemonImpl::log() in daemon_unix.cc.</font>
00196 omniORB::logger log(<font class="stringliteral">"omniEvents! Object failure: "</font>);
00197 omniIOR* ior =obj->_PR_getobj()->_getIOR();
00198 <font class="comment">// Log Repository ID.</font>
00199 log<<ior->repositoryID();
00200 <font class="comment">// Log Object ID. (Limitation: only display the first TAG_INTERNET_IOP)</font>
00201 <font class="keywordflow">for</font>(CORBA::ULong i=0; i<ior->iopProfiles().length(); i++)
00202 {
00203 <font class="keywordflow">if</font> (ior->iopProfiles()[i].tag == IOP::TAG_INTERNET_IOP)
00204 {
00205 IIOP::ProfileBody pBody;
00206 IIOP::unmarshalProfile(ior->iopProfiles()[i],pBody);
00207 log<<<font class="stringliteral">" \""</font>;
00208 <font class="keywordflow">for</font>(CORBA::ULong j=0; j<pBody.object_key.length(); ++j)
00209 {
00210 <font class="keywordtype">char</font> c=(char)pBody.object_key[j];
00211 log<<( (c>=<font class="charliteral">' '</font>&&c<=<font class="charliteral">'~'</font>)? c: <font class="charliteral">'.'</font> ); <font class="comment">// Log object key as text</font>
00212 }
00213 log<<<font class="stringliteral">"\" at "</font><<(<font class="keyword">const</font> <font class="keywordtype">char</font>*)pBody.address.host<<<font class="stringliteral">":"</font><<pBody.address.port;
00214 <font class="keywordflow">break</font>; <font class="comment">// ONLY DISPLAY FIRST!</font>
00215 }
00216 }
00217 <font class="comment">// Log exception.</font>
00218 <font class="keywordflow">if</font>(!ex)
00219 {
00220 log<<<font class="stringliteral">" threw unknown exception\n"</font>;
00221 }
00222 <font class="keywordflow">else</font>
00223 {
00224 log<<<font class="stringliteral">" threw "</font><<ex->_name();
00225 CORBA::SystemException* sysex =CORBA::SystemException::_downcast(ex);
00226 <font class="keywordflow">if</font>(sysex)
00227 log<<<font class="stringliteral">" ("</font><<<a class="code" href="a00115.html#a3">NP_MINORSTRING</a>(*sysex)<<<font class="stringliteral">")"</font>;
00228 log<<<font class="stringliteral">"\n"</font>;
00229 }
00230 }
00231 <font class="preprocessor">#endif</font>
00232 <font class="preprocessor"></font> {
00233 omniORB::logger log(<font class="stringliteral">"omniEvents! Object failure detail: "</font>);
00234 CORBA::String_var sior( Orb::inst().<a class="code" href="a00059.html#m0">_orb</a>->object_to_string(obj) );
00235 log<<sior<<<font class="stringliteral">" at "</font><<here<<<font class="stringliteral">"\n"</font>;
00236 }
00237 }
00238
00239
00240 <font class="comment">//</font>
00241 <font class="comment">// Callback</font>
00242 <font class="comment">//</font>
00243
<a name="l00244"></a><a class="code" href="a00041.html#r0">00244</a> <font class="keyword">const</font> <font class="keywordtype">long</font> Callback::_goodMagic =0xCa11ab1e;
00245
<a name="l00246"></a><a class="code" href="a00041.html#a3">00246</a> Callback::~Callback()
00247 {
00248 <a class="code" href="a00041.html#o0">_magic</a>=0;
00249 <font class="comment">// This call can be blocked waiting for a mutex. In the meantime, Orb::run()</font>
00250 <font class="comment">// might come along and try to call callback(). If that happens.. BANG!</font>
00251 <font class="comment">// This objects virtual call table has already been destroyed, so</font>
00252 <font class="comment">// any attempt to call a virtual function will cause a core dump.</font>
00253
00254 <font class="comment">// To prevent this, here we set _magic=0 BEFORE calling cancelCallback(),</font>
00255 <font class="comment">// and in Orb::run() we check the value of _magic (by calling isValid())</font>
00256 <font class="comment">// BEFORE we try to call callback().</font>
00257 Orb::inst().cancelCallback(<font class="keyword">this</font>);
00258 }
00259
00260
00261 }; <font class="comment">// end namespace OmniEvents</font>
</pre></div><hr><address align="right"><small>Generated on Fri Nov 19 17:42:20 2004 for OmniEvents by
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border=0
width=110 height=53></a>1.2.15 </small></address>
</body>
</html>
|