File: a00186.html

package info (click to toggle)
omnievents 2.6.1-4
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 5,228 kB
  • ctags: 2,538
  • sloc: cpp: 7,346; sh: 2,568; python: 2,171; xml: 2,057; java: 1,407; makefile: 304; ansic: 9
file content (407 lines) | stat: -rw-r--r-- 28,755 bytes parent folder | download
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
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
<!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>ProxyPushSupplier.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> &nbsp; <a class="qindex" href="namespaces.html">Namespace List</a> &nbsp; <a class="qindex" href="hierarchy.html">Class Hierarchy</a> &nbsp; <a class="qindex" href="annotated.html">Compound List</a> &nbsp; <a class="qindex" href="files.html">File List</a> &nbsp; <a class="qindex" href="namespacemembers.html">Namespace Members</a> &nbsp; <a class="qindex" href="functions.html">Compound Members</a> &nbsp; <a class="qindex" href="globals.html">File Members</a> &nbsp; </center>
<hr><h1>ProxyPushSupplier.cc</h1><a href="a00126.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001 <font class="comment">//                            Package   : omniEvents</font>
00002 <font class="comment">// ProxyPushSupplier.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="a00127.html">ProxyPushSupplier.h</a>"</font>
00025 <font class="preprocessor">#include "<a class="code" href="a00115.html">Orb.h</a>"</font>
00026 <font class="preprocessor">#include "<a class="code" href="a00113.html">omniEventsLog.h</a>"</font>
00027 <font class="preprocessor">#include "<a class="code" href="a00117.html">PersistNode.h</a>"</font>
00028 <font class="preprocessor">#include &lt;assert.h&gt;</font>
00029 
00030 <font class="keyword">namespace </font>OmniEvents {
00031 
<a name="l00035"></a><a class="code" href="a00055.html">00035</a> <font class="keyword">class </font><a class="code" href="a00055.html">omni_mutex_kcol</a> {
<a name="l00036"></a><a class="code" href="a00055.html#o0">00036</a>     omni_mutex&amp; <a class="code" href="a00055.html#o0">mutex</a>;
00037 <font class="keyword">public</font>:
<a name="l00038"></a><a class="code" href="a00055.html#a0">00038</a>     <a class="code" href="a00055.html#a0">omni_mutex_kcol</a>(omni_mutex&amp; m) : <a class="code" href="a00055.html#o0">mutex</a>(m) { <a class="code" href="a00055.html#o0">mutex</a>.unlock(); }
<a name="l00039"></a><a class="code" href="a00055.html#a1">00039</a>     <a class="code" href="a00055.html#a1">~omni_mutex_kcol</a>(<font class="keywordtype">void</font>) { <a class="code" href="a00055.html#o0">mutex</a>.lock(); }
00040 <font class="keyword">private</font>:
00041     <font class="comment">// dummy copy constructor and operator= to prevent copying</font>
00042     <a class="code" href="a00055.html#a0">omni_mutex_kcol</a>(<font class="keyword">const</font> <a class="code" href="a00055.html#a0">omni_mutex_kcol</a>&amp;);
00043     <a class="code" href="a00055.html#a0">omni_mutex_kcol</a>&amp; <a class="code" href="a00055.html#c1">operator=</a>(<font class="keyword">const</font> <a class="code" href="a00055.html#a0">omni_mutex_kcol</a>&amp;);
00044 };
00045 
00046 
00047 <font class="comment">//</font>
00048 <font class="comment">//  ProxyPushSupplierManager</font>
00049 <font class="comment">//</font>
00050 
00051 PortableServer::Servant
<a name="l00052"></a><a class="code" href="a00070.html#a0">00052</a> ProxyPushSupplierManager::incarnate(
00053   <font class="keyword">const</font> PortableServer::ObjectId&amp; oid,
00054   PortableServer::POA_ptr         poa
00055 )
00056 {
00057   <a class="code" href="a00069.html">ProxyPushSupplier_i</a>* result =<font class="keyword">new</font> <a class="code" href="a00069.html">ProxyPushSupplier_i</a>(<a class="code" href="a00062.html#n1">_managedPoa</a>,<a class="code" href="a00070.html#o0">_queue</a>);
00058   <a class="code" href="a00071.html">PauseThenWake</a> p(<font class="keyword">this</font>);
00059   <a class="code" href="a00062.html#n0">_servants</a>.insert(result);
00060   <font class="keywordflow">return</font> result;
00061 }
00062 
00063 <font class="keywordtype">void</font>
<a name="l00064"></a><a class="code" href="a00070.html#a1">00064</a> ProxyPushSupplierManager::etherealize(
00065   <font class="keyword">const</font> PortableServer::ObjectId&amp; oid,
00066   PortableServer::POA_ptr         adapter,
00067   PortableServer::Servant         serv,
00068   CORBA::Boolean                  cleanup_in_progress,
00069   CORBA::Boolean                  remaining_activations
00070 )
00071 {
00072   omni_mutex_lock pause(<a class="code" href="a00070.html#m0">_lock</a>);
00073   ProxyManager::etherealize(oid,adapter,serv,
00074     cleanup_in_progress,remaining_activations);
00075 }
00076 
<a name="l00077"></a><a class="code" href="a00070.html#a2">00077</a> ProxyPushSupplierManager::ProxyPushSupplierManager(
00078   PortableServer::POA_ptr parentPoa,
00079   <a class="code" href="a00049.html">EventQueue</a>&amp; q
00080 )
00081 : <a class="code" href="a00062.html">ProxyManager</a>(parentPoa,"ProxyPushSupplier"),
00082   omni_thread(NULL,PRIORITY_HIGH),
00083   _queue(q),
00084   _lock(),_condition(&amp;_lock),
00085   _refCount(1)
00086 {
00087   start();
00088 }
00089 
<a name="l00090"></a><a class="code" href="a00070.html#a3">00090</a> ProxyPushSupplierManager::~ProxyPushSupplierManager()
00091 {
00092   <a class="code" href="a00115.html#a2">DB</a>(20,<font class="stringliteral">"~ProxyPushSupplierManager()"</font>)
00093 }
00094 
00095 CosEventChannelAdmin::ProxyPushSupplier_ptr
<a name="l00096"></a><a class="code" href="a00070.html#a4">00096</a> ProxyPushSupplierManager::createObject()
00097 {  
00098   <font class="keywordflow">return</font> createNarrowedReference&lt;CosEventChannelAdmin::ProxyPushSupplier&gt;(
00099            <a class="code" href="a00062.html#n1">_managedPoa</a>.in(),
00100            CosEventChannelAdmin::_tc_ProxyPushSupplier-&gt;id()
00101          );
00102 }
00103 
<a name="l00104"></a><a class="code" href="a00070.html#a5">00104</a> <font class="keywordtype">void</font> ProxyPushSupplierManager::disconnect()
00105 {
00106   <font class="keywordflow">for</font>(set&lt;Proxy*&gt;::iterator i =<a class="code" href="a00062.html#n0">_servants</a>.begin(); i!=<a class="code" href="a00062.html#n0">_servants</a>.end(); ++i)
00107   {
00108     <a class="code" href="a00061.html">Proxy</a>* p =*i; <font class="comment">// Sun's CC requires this temporary.</font>
00109     <a class="code" href="a00069.html">ProxyPushSupplier_i</a>* pps =static_cast&lt;ProxyPushSupplier_i*&gt;(p);
00110     pps-&gt;<a class="code" href="a00069.html#a1">disconnect_push_supplier</a>();
00111   }
00112 }
00113 
00114 <font class="keywordtype">void</font>
<a name="l00115"></a><a class="code" href="a00070.html#a6">00115</a> ProxyPushSupplierManager::run(<font class="keywordtype">void</font>*)
00116 {
00117   <font class="comment">// This loop repeatedly triggers all of the servants in turn. As long as</font>
00118   <font class="comment">// something happens each time, then we loop as fast as we can.</font>
00119   <font class="comment">// As soon as activity dries up, we start to wait longer and longer between</font>
00120   <font class="comment">// loops (up to a maximum). When there is no work to do, just block until</font>
00121   <font class="comment">// a new event arrives.</font>
00122   <font class="comment">//</font>
00123   <font class="comment">// Rationale: The faster we loop the more events we can deliver to each</font>
00124   <font class="comment">// consumer per second. However, when nothing is happening, this busy loop</font>
00125   <font class="comment">// just soaks up CPU and kills performance. The optimum sleep time varies</font>
00126   <font class="comment">// wildly from platform to platform, and also depends upon the typical ping</font>
00127   <font class="comment">// time to the consumers.</font>
00128   <font class="comment">//</font>
00129   <font class="comment">// This dynamic approach should deliver reasonable performance when things</font>
00130   <font class="comment">// are hectic, but not soak up too much CPU when not much is happening.</font>
00131   <font class="comment">//</font>
00132   <font class="keyword">const</font> <font class="keywordtype">unsigned</font> <font class="keywordtype">long</font> sleepTimeNanosec0 =0x8000;   <font class="comment">// 33us (doubled before use)</font>
00133   <font class="keyword">const</font> <font class="keywordtype">unsigned</font> <font class="keywordtype">long</font> maxSleepNanosec   =0x800000; <font class="comment">// 8.4ms</font>
00134   <font class="keywordtype">unsigned</font> <font class="keywordtype">long</font> sleepTimeNanosec =sleepTimeNanosec0;
00135 
00136   omni_mutex_lock conditionLock(<a class="code" href="a00070.html#m0">_lock</a>);
00137   <font class="keywordflow">while</font>(true)
00138   {
00139     <font class="keywordflow">try</font> {
00140       <font class="keywordflow">if</font>(<a class="code" href="a00070.html#o1">_refCount</a>&lt;1)
00141           <font class="keywordflow">break</font>;
00142 
00143       <font class="keywordtype">bool</font> busy=<font class="keyword">false</font>;
00144       <font class="keywordtype">bool</font> waiting=<font class="keyword">false</font>;
00145 
00146       <font class="comment">// Trigger each servant in turn.</font>
00147       <font class="keywordflow">for</font>(set&lt;Proxy*&gt;::iterator i =<a class="code" href="a00062.html#n0">_servants</a>.begin(); i!=<a class="code" href="a00062.html#n0">_servants</a>.end(); ++i)
00148       {
00149         <a class="code" href="a00061.html">Proxy</a>* p =*i; <font class="comment">// Sun's CC requires this temporary.</font>
00150         <a class="code" href="a00069.html">ProxyPushSupplier_i</a>* pps =static_cast&lt;ProxyPushSupplier_i*&gt;(p);
00151         pps-&gt;<a class="code" href="a00069.html#a4">trigger</a>(busy,waiting);
00152       }
00153 
00154       <font class="keywordflow">if</font>(busy)
00155       {
00156         <font class="comment">// Something happened last time round. So we'll be optimistic and</font>
00157         <font class="comment">// immediately go round for another go. Yield first, just to let the</font>
00158         <font class="comment">// other kids get in if they need to.</font>
00159         <a class="code" href="a00055.html">omni_mutex_kcol</a> l(<a class="code" href="a00070.html#m0">_lock</a>); <font class="comment">// 'lock' reversed!</font>
00160         omni_thread::yield();
00161         <font class="comment">// Reset the sleep time.</font>
00162         sleepTimeNanosec=sleepTimeNanosec0;
00163       }
00164       <font class="keywordflow">else</font> <font class="keywordflow">if</font>(waiting)
00165       {
00166         <font class="comment">// Nothing happened, so we'll wait for a bit and then give it another</font>
00167         <font class="comment">// go. Each time we wait for twice as long, up to the maximum.</font>
00168         <font class="keywordflow">if</font>(sleepTimeNanosec&lt;maxSleepNanosec)
00169             sleepTimeNanosec&lt;&lt;=1; <font class="comment">// (multiply by 2)</font>
00170         <font class="keywordtype">unsigned</font> <font class="keywordtype">long</font> sec,nsec;
00171         omni_thread::get_time(&amp;sec,&amp;nsec,0,sleepTimeNanosec);
00172         <a class="code" href="a00070.html#m1">_condition</a>.timedwait(sec,nsec);
00173       }
00174       <font class="keywordflow">else</font>
00175       {
00176         <font class="comment">// There is nothing to do, so block until a new event arrives.</font>
00177         <a class="code" href="a00070.html#m1">_condition</a>.wait();
00178       }
00179 
00180     }
00181     <font class="keywordflow">catch</font> (CORBA::SystemException&amp; ex) {
00182       <a class="code" href="a00115.html#a2">DB</a>(2,<font class="stringliteral">"ProxyPushSupplierManager ignoring CORBA system exception"</font>
00183          <a class="code" href="a00115.html#a1">IF_OMNIORB4</a>(<font class="stringliteral">": "</font>&lt;&lt;ex._name()&lt;&lt;<font class="stringliteral">" ("</font>&lt;&lt;<a class="code" href="a00115.html#a3">NP_MINORSTRING</a>(ex)&lt;&lt;<font class="stringliteral">")"</font>) <font class="stringliteral">"."</font>)
00184     }
00185     <font class="keywordflow">catch</font> (CORBA::Exception&amp; ex) {
00186       <a class="code" href="a00115.html#a2">DB</a>(2,<font class="stringliteral">"ProxyPushSupplierManager ignoring CORBA exception"</font>
00187          <a class="code" href="a00115.html#a1">IF_OMNIORB4</a>(<font class="stringliteral">": "</font>&lt;&lt;ex._name()&lt;&lt;) <font class="stringliteral">"."</font>)
00188     }
00189     <font class="keywordflow">catch</font>(...) {
00190       <a class="code" href="a00115.html#a2">DB</a>(2,<font class="stringliteral">"ProxyPushSupplierManager thread killed by unknown exception."</font>)
00191       <font class="keywordflow">break</font>;
00192     }
00193   }
00194 }
00195 
<a name="l00196"></a><a class="code" href="a00070.html#a7">00196</a> <font class="keywordtype">void</font> ProxyPushSupplierManager::_add_ref()
00197 {
00198   omni_mutex_lock pause(<a class="code" href="a00070.html#m0">_lock</a>);
00199   ++<a class="code" href="a00070.html#o1">_refCount</a>;
00200 }
00201 
<a name="l00202"></a><a class="code" href="a00070.html#a8">00202</a> <font class="keywordtype">void</font> ProxyPushSupplierManager::_remove_ref()
00203 {
00204   <font class="keywordtype">int</font> myref;
00205   {
00206     <a class="code" href="a00071.html">PauseThenWake</a> p(<font class="keyword">this</font>);
00207     myref = --<a class="code" href="a00070.html#o1">_refCount</a>;
00208   }
00209   <font class="keywordflow">if</font>(myref&lt;0)
00210       <a class="code" href="a00115.html#a2">DB</a>(2,<font class="stringliteral">"ProxyPushSupplierManager has negative ref count! "</font>&lt;&lt;myref)
00211   <font class="keywordflow">else</font> <font class="keywordflow">if</font>(myref==0)
00212       <a class="code" href="a00115.html#a2">DB</a>(15,<font class="stringliteral">"ProxyPushSupplierManager has zero ref count -- shutdown."</font>)
00213 }
00214 
00215 
00216 <font class="comment">//</font>
00217 <font class="comment">//  ProxyPushSupplier_i</font>
00218 <font class="comment">//</font>
00219 
<a name="l00220"></a><a class="code" href="a00069.html#a0">00220</a> <font class="keywordtype">void</font> ProxyPushSupplier_i::connect_push_consumer(
00221   CosEventComm::PushConsumer_ptr pushConsumer)
00222 {
00223   <font class="keywordflow">if</font>(CORBA::is_nil(pushConsumer))
00224       <font class="keywordflow">throw</font> CORBA::BAD_PARAM();
00225   <font class="keywordflow">if</font>(!CORBA::is_nil(<a class="code" href="a00069.html#o0">_target</a>) || !CORBA::is_nil(<a class="code" href="a00061.html#n0">_req</a>))
00226       <font class="keywordflow">throw</font> CosEventChannelAdmin::AlreadyConnected();
00227   <a class="code" href="a00069.html#o0">_target</a>=CosEventComm::PushConsumer::_duplicate(pushConsumer);
00228 
00229   <font class="comment">// Test to see whether pushSupplier is a ProxyPushSupplier.</font>
00230   <font class="comment">// If so, then we will aggressively try to reconnect, when we are reincarnated</font>
00231   CORBA::Request_var req =<a class="code" href="a00069.html#o0">_target</a>-&gt;_request(<font class="stringliteral">"_is_a"</font>);
00232   req-&gt;add_in_arg() &lt;&lt;= CosEventChannelAdmin::_tc_ProxyPushConsumer-&gt;id();
00233   req-&gt;set_return_type(CORBA::_tc_boolean);
00234   req-&gt;send_deferred();
00235   Orb::inst().deferredRequest(req._retn(),<font class="keyword">this</font>); <font class="comment">// Register for callback</font>
00236 
00237   <a class="code" href="a00069.html#a7">output</a>(<a class="code" href="a00080.html">WriteLock</a>().os);
00238 }
00239 
00240 
<a name="l00241"></a><a class="code" href="a00069.html#a1">00241</a> <font class="keywordtype">void</font> ProxyPushSupplier_i::disconnect_push_supplier()
00242 {
00243   <a class="code" href="a00115.html#a2">DB</a>(5,<font class="stringliteral">"ProxyPushSupplier_i::disconnect_push_supplier()"</font>);
00244   <a class="code" href="a00061.html#b2">eraseKey</a>(<font class="stringliteral">"ConsumerAdmin/ProxyPushSupplier"</font>);
00245   <a class="code" href="a00073.html#b2">deactivateObject</a>();
00246   <font class="keywordflow">if</font>(CORBA::is_nil(<a class="code" href="a00069.html#o0">_target</a>))
00247   {
00248     <font class="keywordflow">throw</font> CORBA::OBJECT_NOT_EXIST(
00249       <a class="code" href="a00115.html#a0">IFELSE_OMNIORB4</a>(omni::OBJECT_NOT_EXIST_NoMatch,0),
00250       CORBA::COMPLETED_NO
00251     );
00252   }
00253   <font class="keywordflow">else</font>
00254   {
00255     CORBA::Request_var req=<a class="code" href="a00069.html#o0">_target</a>-&gt;_request(<font class="stringliteral">"disconnect_push_consumer"</font>);
00256     req-&gt;send_deferred();
00257     Orb::inst().deferredRequest(req._retn());
00258     <a class="code" href="a00069.html#o0">_target</a>=CosEventComm::PushConsumer::_nil();
00259   }
00260 }
00261 
00262 
<a name="l00263"></a><a class="code" href="a00069.html#a2">00263</a> ProxyPushSupplier_i::ProxyPushSupplier_i(
00264   PortableServer::POA_ptr poa,
00265   <a class="code" href="a00049.html">EventQueue</a>&amp;             q
00266 )
00267 : <a class="code" href="a00061.html">Proxy</a>(poa),
00268   <a class="code" href="a00049.html">EventQueue</a>::Reader(q),
00269   _target(CosEventComm::PushConsumer::_nil()),
00270   _targetIsProxy(false)
00271 {
00272   <font class="comment">// pass</font>
00273 }
00274 
<a name="l00275"></a><a class="code" href="a00069.html#a3">00275</a> ProxyPushSupplier_i::~ProxyPushSupplier_i()
00276 {
00277   <a class="code" href="a00115.html#a2">DB</a>(20,<font class="stringliteral">"~ProxyPushSupplier_i()"</font>)
00278 }
00279 
<a name="l00280"></a><a class="code" href="a00069.html#a4">00280</a> <font class="keyword">inline</font> <font class="keywordtype">void</font> ProxyPushSupplier_i::trigger(<font class="keywordtype">bool</font>&amp; busy, <font class="keywordtype">bool</font>&amp; waiting)
00281 {
00282   <font class="keywordflow">if</font>(!CORBA::is_nil(<a class="code" href="a00061.html#n0">_req</a>) &amp;&amp; <a class="code" href="a00061.html#n0">_req</a>-&gt;poll_response()) <font class="comment">// response has arrived</font>
00283   {
00284     CORBA::Environment_ptr env=<a class="code" href="a00061.html#n0">_req</a>-&gt;env(); <font class="comment">// No need to free environment.</font>
00285     <font class="keywordflow">if</font>(!CORBA::is_nil(env) &amp;&amp; env-&gt;exception())
00286     {
00287       <font class="comment">// Shut down the connection</font>
00288       CORBA::Exception* ex =env-&gt;exception(); <font class="comment">// No need to free exception.</font>
00289       <a class="code" href="a00115.html#a2">DB</a>(10,<font class="stringliteral">"ProxyPushSupplier got exception"</font> <a class="code" href="a00115.html#a1">IF_OMNIORB4</a>(<font class="stringliteral">": "</font>&lt;&lt;ex-&gt;_name()) );
00290       Orb::inst().reportObjectFailure(HERE,<a class="code" href="a00069.html#o0">_target</a>.in(),ex);
00291       <a class="code" href="a00061.html#n0">_req</a>=CORBA::Request::_nil();
00292 
00293       <font class="comment">// Try to notify the Consumer that the connection is closing.</font>
00294       CORBA::Request_var req=<a class="code" href="a00069.html#o0">_target</a>-&gt;_request(<font class="stringliteral">"disconnect_push_consumer"</font>);
00295       req-&gt;send_deferred();
00296       Orb::inst().deferredRequest(req._retn());
00297 
00298       <a class="code" href="a00069.html#o0">_target</a>=CosEventComm::PushConsumer::_nil(); <font class="comment">// disconnected.</font>
00299       <a class="code" href="a00061.html#b2">eraseKey</a>(<font class="stringliteral">"ConsumerAdmin/ProxyPushSupplier"</font>);
00300       <a class="code" href="a00073.html#b2">deactivateObject</a>();
00301       <font class="keywordflow">return</font>; <font class="comment">// No more work to do</font>
00302     }
00303     <a class="code" href="a00061.html#n0">_req</a>=CORBA::Request::_nil();
00304     busy=<font class="keyword">true</font>;
00305   }
00306   <font class="keywordflow">if</font>(CORBA::is_nil(<a class="code" href="a00061.html#n0">_req</a>) &amp;&amp; !CORBA::is_nil(<a class="code" href="a00069.html#o0">_target</a>) &amp;&amp; <a class="code" href="a00050.html#a1">moreEvents</a>())
00307   {
00308     <a class="code" href="a00061.html#n0">_req</a>=<a class="code" href="a00069.html#o0">_target</a>-&gt;_request(<font class="stringliteral">"push"</font>);
00309     <a class="code" href="a00061.html#n0">_req</a>-&gt;add_in_arg() &lt;&lt;= *(<a class="code" href="a00050.html#a2">nextEvent</a>());
00310     <a class="code" href="a00061.html#n0">_req</a>-&gt;send_deferred();
00311     busy=<font class="keyword">true</font>;
00312   }
00313   <font class="keywordflow">if</font>(!CORBA::is_nil(<a class="code" href="a00061.html#n0">_req</a>)) <font class="comment">// More work to do, if _req NOT nil.</font>
00314       waiting=<font class="keyword">true</font>;
00315 }
00316 
00317 
<a name="l00318"></a><a class="code" href="a00069.html#a5">00318</a> <font class="keywordtype">void</font> ProxyPushSupplier_i::callback(CORBA::Request_ptr req)
00319 {
00320   <font class="keywordflow">if</font>(_targetIsProxy)
00321   {
00322     <font class="comment">// There should only ever be one of these callbacks per proxy,</font>
00323     <font class="comment">// because each proxy should only be connected once.</font>
00324     <a class="code" href="a00115.html#a2">DB</a>(2,<font class="stringliteral">"WARNING: Multiple connections to ProxyPushSupplier."</font>);
00325   }
00326   <font class="keywordflow">else</font> <font class="keywordflow">if</font>(req-&gt;return_value()&gt;&gt;=CORBA::Any::to_boolean(<a class="code" href="a00069.html#o1">_targetIsProxy</a>))
00327   {
00328     <font class="keywordflow">if</font>(_targetIsProxy)
00329     {
00330       <a class="code" href="a00069.html#a7">output</a>(<a class="code" href="a00080.html">WriteLock</a>().os);
00331       <a class="code" href="a00115.html#a2">DB</a>(15,<font class="stringliteral">"ProxyPushSupplier is federated."</font>);
00332     }
00333   }
00334   <font class="keywordflow">else</font>
00335   {
00336     <a class="code" href="a00115.html#a2">DB</a>(2,<font class="stringliteral">"ProxyPushSupplier got unexpected callback."</font>);
00337     <a class="code" href="a00069.html#o1">_targetIsProxy</a>=<font class="keyword">false</font>; <font class="comment">// Reset it just to be sure.</font>
00338   }
00339 }
00340 
00341 
<a name="l00342"></a><a class="code" href="a00069.html#a6">00342</a> <font class="keywordtype">void</font> ProxyPushSupplier_i::reincarnate(
00343   <font class="keyword">const</font> string&amp;      oid,
00344   <font class="keyword">const</font> <a class="code" href="a00060.html">PersistNode</a>&amp; node
00345 )
00346 {
00347   <font class="keywordflow">try</font>
00348   {
00349     <font class="keyword">using</font> <font class="keyword">namespace </font>CosEventChannelAdmin;
00350 
00351     string ior( node.<a class="code" href="a00060.html#a11">attrString</a>(<font class="stringliteral">"IOR"</font>).c_str() );
00352     CosEventComm::PushConsumer_var pushConsumer =
00353       string_to_&lt;CosEventComm::PushConsumer&gt;(ior.c_str());
00354     <font class="comment">// Do not activate until we know that we have read a valid target.</font>
00355     <a class="code" href="a00073.html#b1">activateObjectWithId</a>(oid.c_str());
00356     <a class="code" href="a00069.html#o0">_target</a>=pushConsumer._retn();
00357     <a class="code" href="a00069.html#o1">_targetIsProxy</a>=bool(node.<a class="code" href="a00060.html#a12">attrLong</a>(<font class="stringliteral">"proxy"</font>));
00358 
00359     <font class="comment">// If pushConsumer is a proxy, then try to reconnect.</font>
00360     <font class="keywordflow">if</font>(_targetIsProxy)
00361     {
00362       <a class="code" href="a00115.html#a2">DB</a>(15,<font class="stringliteral">"Attempting to reconnect ProxyPushSupplier: "</font>&lt;&lt;oid.c_str())
00363       <font class="comment">// This will only work if the proxy is implemented in the same way as</font>
00364       <font class="comment">// omniEvents, so connect_() automatically creates a proxy.</font>
00365       ProxyPushConsumer_var proxyCons =
00366         string_to_&lt;ProxyPushConsumer&gt;(ior.c_str());
00367       CosEventComm::PushSupplier_var thisSupp =_this();
00368       proxyCons-&gt;connect_push_supplier(thisSupp);
00369       <a class="code" href="a00115.html#a2">DB</a>(7,<font class="stringliteral">"Reconnected ProxyPushSupplier: "</font>&lt;&lt;oid.c_str())
00370     }
00371   }
00372   <font class="keywordflow">catch</font>(CosEventChannelAdmin::AlreadyConnected&amp;){ <font class="comment">// connect_push_supplier()</font>
00373     <font class="comment">// The supplier doesn't need to be reconnected.</font>
00374     <a class="code" href="a00115.html#a2">DB</a>(7,<font class="stringliteral">"Remote ProxyPushConsumer already connected: "</font>&lt;&lt;oid.c_str())
00375   }
00376   <font class="keywordflow">catch</font>(CosEventChannelAdmin::TypeError&amp;){ <font class="comment">// connect_push_supplier()</font>
00377     <font class="comment">// Don't know what to make of this...</font>
00378     <a class="code" href="a00115.html#a2">DB</a>(2,<font class="stringliteral">"Remote ProxyPushConsumer threw TypeError: "</font>&lt;&lt;oid.c_str())
00379   }
00380   <font class="keywordflow">catch</font>(CORBA::OBJECT_NOT_EXIST&amp;) {} <font class="comment">// object 'pushConsumer' not responding.</font>
00381   <font class="keywordflow">catch</font>(CORBA::TRANSIENT&amp;       ) {} <font class="comment">// object 'pushConsumer' not responding.</font>
00382   <font class="keywordflow">catch</font>(CORBA::COMM_FAILURE&amp;    ) {} <font class="comment">// object 'pushConsumer' not responding.</font>
00383 }
00384 
00385 
<a name="l00386"></a><a class="code" href="a00069.html#a7">00386</a> <font class="keywordtype">void</font> ProxyPushSupplier_i::output(ostream &amp;os)
00387 {
00388   <a class="code" href="a00061.html#b3">basicOutput</a>(
00389     os,<font class="stringliteral">"ConsumerAdmin/ProxyPushSupplier"</font>,
00390     <a class="code" href="a00069.html#o0">_target</a>.in(),
00391     <a class="code" href="a00069.html#o1">_targetIsProxy</a>? <font class="stringliteral">" proxy=1"</font>: NULL
00392   );
00393 }
00394 
00395 
00396 }; <font class="comment">// end namespace OmniEvents</font>
</pre></div><hr><address align="right"><small>Generated on Fri Nov 19 17:42:21 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>