File: a00180.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 (269 lines) | stat: -rw-r--r-- 18,098 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
<!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>ProxyPullConsumer.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>ProxyPullConsumer.cc</h1><a href="a00120.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001 <font class="comment">//                            Package   : omniEvents</font>
00002 <font class="comment">// ProxyPullConsumer.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="a00121.html">ProxyPullConsumer.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 
00032 <font class="comment">//</font>
00033 <font class="comment">//  ProxyPullConsumerManager</font>
00034 <font class="comment">//</font>
00035 
00036 PortableServer::Servant
<a name="l00037"></a><a class="code" href="a00064.html#a0">00037</a> ProxyPullConsumerManager::incarnate(
00038   <font class="keyword">const</font> PortableServer::ObjectId&amp; oid,
00039   PortableServer::POA_ptr         poa
00040 )
00041 {
00042   <a class="code" href="a00115.html#a2">DB</a>(20,<font class="stringliteral">"ProxyPullConsumerManager::incarnate()"</font>)
00043   <a class="code" href="a00063.html">ProxyPullConsumer_i</a>* result =<font class="keyword">new</font> <a class="code" href="a00063.html">ProxyPullConsumer_i</a>(<a class="code" href="a00062.html#n1">_managedPoa</a>,<a class="code" href="a00064.html#o0">_queue</a>);
00044   <a class="code" href="a00062.html#n0">_servants</a>.insert(result);
00045   <font class="keywordflow">return</font> result;
00046 }
00047 
<a name="l00048"></a><a class="code" href="a00064.html#a1">00048</a> ProxyPullConsumerManager::ProxyPullConsumerManager(
00049   PortableServer::POA_ptr parentPoa,
00050   list&lt;CORBA::Any*&gt;&amp;      q
00051 )
00052 : <a class="code" href="a00062.html">ProxyManager</a>(parentPoa,"ProxyPullConsumer"),
00053   _queue(q)
00054 {
00055   <font class="comment">// pass</font>
00056 }
00057 
<a name="l00058"></a><a class="code" href="a00064.html#a2">00058</a> ProxyPullConsumerManager::~ProxyPullConsumerManager()
00059 {
00060   <a class="code" href="a00115.html#a2">DB</a>(20,<font class="stringliteral">"~ProxyPullConsumerManager()"</font>)
00061 }
00062 
00063 CosEventChannelAdmin::ProxyPullConsumer_ptr
<a name="l00064"></a><a class="code" href="a00064.html#a3">00064</a> ProxyPullConsumerManager::createObject()
00065 {
00066   <font class="keywordflow">return</font> createNarrowedReference&lt;CosEventChannelAdmin::ProxyPullConsumer&gt;(
00067            <a class="code" href="a00062.html#n1">_managedPoa</a>.in(),
00068            CosEventChannelAdmin::_tc_ProxyPullConsumer-&gt;id()
00069          );
00070 }
00071 
<a name="l00072"></a><a class="code" href="a00064.html#a4">00072</a> <font class="keywordtype">void</font> ProxyPullConsumerManager::trigger()
00073 {
00074   <font class="comment">// Trigger each servant in turn.</font>
00075   <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)
00076   {
00077     <a class="code" href="a00063.html">ProxyPullConsumer_i</a>* proxy=dynamic_cast&lt;ProxyPullConsumer_i*&gt;(*i);
00078     proxy-&gt;<a class="code" href="a00063.html#a4">trigger</a>();
00079   }
00080 }
00081 
<a name="l00082"></a><a class="code" href="a00064.html#a5">00082</a> <font class="keywordtype">void</font> ProxyPullConsumerManager::disconnect()
00083 {
00084   <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)
00085   {
00086     <a class="code" href="a00061.html">Proxy</a>* p =*i; <font class="comment">// Sun's CC requires this temporary.</font>
00087     <a class="code" href="a00063.html">ProxyPullConsumer_i</a>* ppc =static_cast&lt;ProxyPullConsumer_i*&gt;(p);
00088     ppc-&gt;<a class="code" href="a00063.html#a1">disconnect_pull_consumer</a>();
00089   }
00090 }
00091 
00092 
00093 <font class="comment">//</font>
00094 <font class="comment">//  ProxyPullConsumer_i</font>
00095 <font class="comment">//</font>
00096 
00097 <font class="comment">// CORBA interface methods</font>
00098 
<a name="l00099"></a><a class="code" href="a00063.html#a0">00099</a> <font class="keywordtype">void</font> ProxyPullConsumer_i::connect_pull_supplier(
00100   CosEventComm::PullSupplier_ptr pullSupplier
00101 )
00102 {
00103   <font class="keywordflow">if</font>(CORBA::is_nil(pullSupplier))
00104       <font class="keywordflow">throw</font> CORBA::BAD_PARAM();
00105   <font class="keywordflow">if</font>(!CORBA::is_nil(<a class="code" href="a00063.html#o0">_target</a>) || !CORBA::is_nil(<a class="code" href="a00061.html#n0">_req</a>))
00106       <font class="keywordflow">throw</font> CosEventChannelAdmin::AlreadyConnected();
00107   <a class="code" href="a00063.html#o0">_target</a>=CosEventComm::PullSupplier::_duplicate(pullSupplier);
00108 
00109   <a class="code" href="a00063.html#a6">output</a>(<a class="code" href="a00080.html">WriteLock</a>().os);
00110 }
00111 
<a name="l00112"></a><a class="code" href="a00063.html#a1">00112</a> <font class="keywordtype">void</font> ProxyPullConsumer_i::disconnect_pull_consumer()
00113 {
00114   <a class="code" href="a00115.html#a2">DB</a>(5,<font class="stringliteral">"ProxyPullConsumer_i::disconnect_pull_consumer()"</font>);
00115   <a class="code" href="a00061.html#b2">eraseKey</a>(<font class="stringliteral">"SupplierAdmin/ProxyPullConsumer"</font>);
00116   <a class="code" href="a00073.html#b2">deactivateObject</a>();
00117   <font class="keywordflow">if</font>(CORBA::is_nil(<a class="code" href="a00063.html#o0">_target</a>))
00118   {
00119     <font class="keywordflow">throw</font> CORBA::OBJECT_NOT_EXIST(
00120       <a class="code" href="a00115.html#a0">IFELSE_OMNIORB4</a>(omni::OBJECT_NOT_EXIST_NoMatch,0),
00121       CORBA::COMPLETED_NO
00122     );
00123   }
00124   <font class="keywordflow">else</font>
00125   {
00126     CORBA::Request_var req=<a class="code" href="a00063.html#o0">_target</a>-&gt;_request(<font class="stringliteral">"disconnect_pull_supplier"</font>);
00127     req-&gt;send_deferred();
00128     Orb::inst().deferredRequest(req._retn());
00129     <a class="code" href="a00063.html#o0">_target</a>=CosEventComm::PullSupplier::_nil();
00130   }
00131 }
00132 
00133 <font class="comment">//</font>
00134 
<a name="l00135"></a><a class="code" href="a00063.html#a2">00135</a> ProxyPullConsumer_i::ProxyPullConsumer_i(
00136   PortableServer::POA_ptr poa,
00137   list&lt;CORBA::Any*&gt;&amp;      q
00138 )
00139 : <a class="code" href="a00061.html">Proxy</a>(poa),
00140   _target(CosEventComm::PullSupplier::_nil()),
00141   _queue(q)
00142 {
00143   <a class="code" href="a00063.html#o2">_exceptionCount</a>[<a class="code" href="a00063.html#u2u0">Pull</a>]=0;
00144   <a class="code" href="a00063.html#o2">_exceptionCount</a>[<a class="code" href="a00063.html#u2u1">TryPull</a>]=0;
00145 }
00146 
<a name="l00147"></a><a class="code" href="a00063.html#a3">00147</a> ProxyPullConsumer_i::~ProxyPullConsumer_i()
00148 {
00149   <a class="code" href="a00115.html#a2">DB</a>(20,<font class="stringliteral">"~ProxyPullConsumer_i()"</font>)
00150 }
00151 
<a name="l00152"></a><a class="code" href="a00063.html#a4">00152</a> <font class="keywordtype">void</font> ProxyPullConsumer_i::trigger()
00153 {
00154   <font class="comment">// Prefer 'pull' method calls.</font>
00155   CORBA::String_var opname =<font class="stringliteral">"pull"</font>;
00156 
00157   <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()) 
00158   {
00159     opname=CORBA::string_dup(<a class="code" href="a00061.html#n0">_req</a>-&gt;operation());
00160 
00161     CORBA::Environment_ptr env=<a class="code" href="a00061.html#n0">_req</a>-&gt;env(); <font class="comment">// No need to release environment.</font>
00162     <font class="keywordflow">if</font>(!CORBA::is_nil(env) &amp;&amp; env-&gt;exception()) 
00163     {
00164       CORBA::Exception* ex =env-&gt;exception(); <font class="comment">// No need to free exception.</font>
00165       <a class="code" href="a00115.html#a2">DB</a>(10,<font class="stringliteral">"ProxyPullConsumer got exception"</font>
00166            <a class="code" href="a00115.html#a1">IF_OMNIORB4</a>(&lt;&lt;<font class="stringliteral">": "</font>&lt;&lt;ex-&gt;_name())&lt;&lt;<font class="stringliteral">", op:"</font>&lt;&lt;opname);
00167       <font class="keywordflow">if</font>(0==strcmp(<font class="stringliteral">"pull"</font>,opname))
00168       {
00169         ++(<a class="code" href="a00063.html#o2">_exceptionCount</a>[<a class="code" href="a00063.html#u2u0">Pull</a>]);
00170         opname=<font class="stringliteral">"try_pull"</font>; <font class="comment">// Try something else next time.</font>
00171       }
00172       <font class="keywordflow">else</font> <font class="keywordflow">if</font>(0==strcmp(<font class="stringliteral">"try_pull"</font>,opname))
00173       {
00174         ++(<a class="code" href="a00063.html#o2">_exceptionCount</a>[<a class="code" href="a00063.html#u2u1">TryPull</a>]);
00175         opname=<font class="stringliteral">"pull"</font>; <font class="comment">// Try something else next time.</font>
00176       }
00177       <font class="keywordflow">else</font>
00178           <a class="code" href="a00115.html#a2">DB</a>(2,<font class="stringliteral">"Ignoring unrecognised response. operation:"</font>&lt;&lt;opname);
00179       <font class="keywordflow">if</font>(<a class="code" href="a00063.html#o2">_exceptionCount</a>[<a class="code" href="a00063.html#u2u0">Pull</a>]&gt;=2 &amp;&amp; <a class="code" href="a00063.html#o2">_exceptionCount</a>[<a class="code" href="a00063.html#u2u1">TryPull</a>]&gt;=2)
00180       {
00181         Orb::inst().reportObjectFailure(HERE,<a class="code" href="a00063.html#o0">_target</a>.in(),ex);
00182 
00183         <font class="comment">// Try to notify the Supplier that the connection is closing.</font>
00184         CORBA::Request_var req=<a class="code" href="a00063.html#o0">_target</a>-&gt;_request(<font class="stringliteral">"disconnect_pull_supplier"</font>);
00185         req-&gt;send_deferred();
00186         Orb::inst().deferredRequest(req._retn());
00187 
00188         <a class="code" href="a00063.html#o0">_target</a>=CosEventComm::PullSupplier::_nil(); <font class="comment">// disconnected</font>
00189         <a class="code" href="a00061.html#b2">eraseKey</a>(<font class="stringliteral">"SupplierAdmin/ProxyPullConsumer"</font>);
00190         <a class="code" href="a00073.html#b2">deactivateObject</a>();
00191       }
00192     }
00193     <font class="keywordflow">else</font>  
00194     {
00195       <font class="comment">// Do we have an event?</font>
00196       <font class="keywordtype">bool</font> hasEvent=<font class="keyword">false</font>;
00197       <font class="keywordflow">if</font>(0==strcmp(<font class="stringliteral">"pull"</font>,opname))
00198       {
00199         <a class="code" href="a00063.html#o2">_exceptionCount</a>[<a class="code" href="a00063.html#u2u0">Pull</a>]=0;
00200         hasEvent=<font class="keyword">true</font>;
00201       }
00202       <font class="keywordflow">else</font> <font class="keywordflow">if</font>(0==strcmp(<font class="stringliteral">"try_pull"</font>,opname))
00203       {
00204         <a class="code" href="a00063.html#o2">_exceptionCount</a>[<a class="code" href="a00063.html#u2u1">TryPull</a>]=0;
00205         CORBA::NVList_ptr args=<a class="code" href="a00061.html#n0">_req</a>-&gt;arguments(); <font class="comment">// No need to release args.</font>
00206         <font class="keywordflow">if</font>(args-&gt;count()==1)
00207         {
00208           CORBA::NamedValue_var hasEventArg=args-&gt;item(0);
00209           <font class="keywordflow">if</font>(0==strcmp(hasEventArg-&gt;name(),<font class="stringliteral">"has_event"</font>))
00210           {
00211             CORBA::Any* a =hasEventArg-&gt;value();
00212             CORBA::Boolean b;
00213             CORBA::Any::to_boolean tb(b); <font class="comment">//MS VC++6 is on drugs!</font>
00214             hasEvent=(((*a)&gt;&gt;=tb) &amp;&amp; b);
00215           }
00216         }
00217       }
00218       <font class="comment">// Pick up an event, if we have one.</font>
00219       <font class="keywordflow">if</font>(hasEvent)
00220       {
00221         CORBA::Any* event =<font class="keyword">new</font> CORBA::Any();
00222         <a class="code" href="a00061.html#n0">_req</a>-&gt;return_value() &gt;&gt;= (*event);
00223         <a class="code" href="a00063.html#o1">_queue</a>.push_back(event);
00224       }
00225     }
00226     <a class="code" href="a00061.html#n0">_req</a>=CORBA::Request::_nil();
00227   }
00229   <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="a00063.html#o0">_target</a>))
00230   {
00231     <a class="code" href="a00061.html#n0">_req</a>=<a class="code" href="a00063.html#o0">_target</a>-&gt;_request(opname);
00232     <a class="code" href="a00061.html#n0">_req</a>-&gt;set_return_type(CORBA::_tc_any);
00233     <font class="keywordflow">if</font>(0==strcmp(<font class="stringliteral">"try_pull"</font>,opname))
00234         <a class="code" href="a00061.html#n0">_req</a>-&gt;add_out_arg(<font class="stringliteral">"has_event"</font>)&lt;&lt;=CORBA::Any::from_boolean(1);
00235     <a class="code" href="a00061.html#n0">_req</a>-&gt;send_deferred();
00236   }
00237 }
00238 
<a name="l00239"></a><a class="code" href="a00063.html#a5">00239</a> <font class="keywordtype">void</font> ProxyPullConsumer_i::reincarnate(
00240   <font class="keyword">const</font> string&amp;      oid,
00241   <font class="keyword">const</font> <a class="code" href="a00060.html">PersistNode</a>&amp; node
00242 )
00243 {
00244   CosEventComm::PullSupplier_var pullSupplier =
00245     string_to_&lt;CosEventComm::PullSupplier&gt;(node.<a class="code" href="a00060.html#a11">attrString</a>(<font class="stringliteral">"IOR"</font>).c_str());
00246   <font class="comment">// Do not activate until we know that we have read a valid target.</font>
00247   <a class="code" href="a00073.html#b1">activateObjectWithId</a>(oid.c_str());
00248   <a class="code" href="a00063.html#a0">connect_pull_supplier</a>(pullSupplier.in());
00249 }
00250 
<a name="l00251"></a><a class="code" href="a00063.html#a6">00251</a> <font class="keywordtype">void</font> ProxyPullConsumer_i::output(ostream&amp; os)
00252 {
00253   <a class="code" href="a00061.html#b3">basicOutput</a>(os,<font class="stringliteral">"SupplierAdmin/ProxyPullConsumer"</font>,<a class="code" href="a00063.html#o0">_target</a>.in());
00254 }
00255 
00256 }; <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>