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 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473
|
<!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>pushcons.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>pushcons.cc</h1><a href="a00130.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001 <font class="comment">// -*- Mode: C++; -*-</font>
00002 <font class="comment">// Package : omniEvents</font>
00003 <font class="comment">// pushcons.cc Created : 1/4/98</font>
00004 <font class="comment">// Author : Paul Nader (pwn)</font>
00005 <font class="comment">//</font>
00006 <font class="comment">// Copyright (C) 1998 Paul Nader, 2003-2004 Alex Tingle</font>
00007 <font class="comment">//</font>
00008 <font class="comment">// This file is part of the omniEvents application.</font>
00009 <font class="comment">//</font>
00010 <font class="comment">// omniEvents is free software; you can redistribute it and/or</font>
00011 <font class="comment">// modify it under the terms of the GNU Lesser General Public</font>
00012 <font class="comment">// License as published by the Free Software Foundation; either</font>
00013 <font class="comment">// version 2.1 of the License, or (at your option) any later version.</font>
00014 <font class="comment">//</font>
00015 <font class="comment">// omniEvents is distributed in the hope that it will be useful,</font>
00016 <font class="comment">// but WITHOUT ANY WARRANTY; without even the implied warranty of</font>
00017 <font class="comment">// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU</font>
00018 <font class="comment">// Lesser General Public License for more details.</font>
00019 <font class="comment">//</font>
00020 <font class="comment">// You should have received a copy of the GNU Lesser General Public</font>
00021 <font class="comment">// License along with this library; if not, write to the Free Software</font>
00022 <font class="comment">// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA</font>
00023 <font class="comment">//</font>
00024 <font class="comment">// Description:</font>
00025 <font class="comment">// Push Model consumer implementation</font>
00026 <font class="comment">// </font>
00027
00028 <font class="comment">/*</font>
00029 <font class="comment"> $Log: pushcons.cc,v $</font>
00030 <font class="comment"> Revision 1.12 2004/10/08 09:06:08 alextingle</font>
00031 <font class="comment"> More robust exception minor code handling.</font>
00032 <font class="comment"></font>
00033 <font class="comment"> Revision 1.11 2004/08/18 17:49:45 alextingle</font>
00034 <font class="comment"> Added check for SIGPIPE before trying to use it.</font>
00035 <font class="comment"></font>
00036 <font class="comment"> Revision 1.10 2004/08/06 16:19:23 alextingle</font>
00037 <font class="comment"> -k & -K options removed.</font>
00038 <font class="comment"> Naming service names may now be as complex as you like.</font>
00039 <font class="comment"></font>
00040 <font class="comment"> Revision 1.9 2004/04/30 17:54:47 alextingle</font>
00041 <font class="comment"> Corrected handling of CORBA::Any.</font>
00042 <font class="comment"></font>
00043 <font class="comment"> Revision 1.8 2004/04/20 16:52:17 alextingle</font>
00044 <font class="comment"> All examples updated for latest version on omniEvents. Server may now be</font>
00045 <font class="comment"> specified as a 'corbaloc' string or IOR, instead of as naming service id/kind.</font>
00046 <font class="comment"></font>
00047 <font class="comment"> Revision 1.7 2004/04/01 22:28:36 alextingle</font>
00048 <font class="comment"> Corrected usage message.</font>
00049 <font class="comment"></font>
00050 <font class="comment"> Revision 1.6 2004/03/23 19:09:26 alextingle</font>
00051 <font class="comment"> Fixed typos.</font>
00052 <font class="comment"></font>
00053 <font class="comment"> Revision 1.5 2004/02/21 19:07:45 alextingle</font>
00054 <font class="comment"> Corrected servants to use POA instead of BOA.</font>
00055 <font class="comment"></font>
00056 <font class="comment"> Revision 1.4 2004/02/04 22:29:55 alextingle</font>
00057 <font class="comment"> Reworked all C++ examples.</font>
00058 <font class="comment"> Removed catch(...) as it tends to make it harder to see what's going on.</font>
00059 <font class="comment"> Now uses POA instead of BOA.</font>
00060 <font class="comment"> Uses omniORB4's Exception name probing.</font>
00061 <font class="comment"> No longer uses 'naming.h/cc' utility code.</font>
00062 <font class="comment"></font>
00063 <font class="comment"> Revision 1.3 2003/11/03 22:19:56 alextingle</font>
00064 <font class="comment"> Removed all platform specific switches. Now uses autoconf, config.h.</font>
00065 <font class="comment"> Removed stub header in order to allow makefile dependency checking to work</font>
00066 <font class="comment"> correctly.</font>
00067 <font class="comment"> Corrected usage of omni_condition/omni_mutex. Mutexes are now always unlocked by</font>
00068 <font class="comment"> the same thread that locked them.</font>
00069 <font class="comment"></font>
00070 <font class="comment"> Revision 1.1.1.1.2.1 2002/09/28 22:20:51 shamus13</font>
00071 <font class="comment"> Added ifdefs to enable omniEvents to compile</font>
00072 <font class="comment"> with both omniORB3 and omniORB4. If __OMNIORB4__</font>
00073 <font class="comment"> is defined during compilation, omniORB4 headers</font>
00074 <font class="comment"> and command line option syntax is used, otherwise</font>
00075 <font class="comment"> fall back to omniORB3 style.</font>
00076 <font class="comment"></font>
00077 <font class="comment"> Revision 1.1.1.1 2002/09/25 19:00:26 shamus13</font>
00078 <font class="comment"> Import of OmniEvents source tree from release 2.1.1</font>
00079 <font class="comment"></font>
00080 <font class="comment"> Revision 0.13 2000/08/30 04:39:48 naderp</font>
00081 <font class="comment"> Port to omniORB 3.0.1.</font>
00082 <font class="comment"></font>
00083 <font class="comment"> Revision 0.12 2000/03/16 05:37:27 naderp</font>
00084 <font class="comment"> Added stdlib.h for getopt.</font>
00085 <font class="comment"></font>
00086 <font class="comment"> Revision 0.11 2000/03/06 13:27:02 naderp</font>
00087 <font class="comment"> Using util getRootNamingContext function.</font>
00088 <font class="comment"> Using stub headers.</font>
00089 <font class="comment"> Fixed error messages.</font>
00090 <font class="comment"></font>
00091 <font class="comment"> Revision 0.10 2000/03/02 03:20:24 naderp</font>
00092 <font class="comment"> Added retry resiliency for handling COMM_FAUILURE exceptions.</font>
00093 <font class="comment"></font>
00094 <font class="comment"> Revision 0.9 1999/11/02 13:39:15 naderp</font>
00095 <font class="comment"> Added <signal.h></font>
00096 <font class="comment"></font>
00097 <font class="comment"> Revision 0.8 1999/11/02 07:57:04 naderp</font>
00098 <font class="comment"> Updated usage.</font>
00099 <font class="comment"></font>
00100 <font class="comment">Revision 0.7 99/11/01 18:10:29 18:10:29 naderp (Paul Nader)</font>
00101 <font class="comment">Added ahndling of COMM_FAILURE exception for connect_push_consumer.</font>
00102 <font class="comment"></font>
00103 <font class="comment">Revision 0.6 99/11/01 16:11:03 16:11:03 naderp (Paul Nader)</font>
00104 <font class="comment">omniEvents 2.0 Release.</font>
00105 <font class="comment"></font>
00106 <font class="comment">Revision 0.5 99/10/27 19:46:01 19:46:01 naderp (Paul Nader)</font>
00107 <font class="comment">Ignoring Unix SIGPIPE signal.</font>
00108 <font class="comment">Catching COMM_FAILURE exception for obtain_push_supplier.</font>
00109 <font class="comment">Continuing if it fails to obtain Proxy Supplier.</font>
00110 <font class="comment">Try/Catch block for disconnect_push_supplier.</font>
00111 <font class="comment"></font>
00112 <font class="comment">Revision 0.4 99/04/23 16:05:46 16:05:46 naderp (Paul Nader)</font>
00113 <font class="comment">gcc port.</font>
00114 <font class="comment"></font>
00115 <font class="comment">Revision 0.3 99/04/23 09:34:03 09:34:03 naderp (Paul Nader)</font>
00116 <font class="comment">Windows Port.</font>
00117 <font class="comment"></font>
00118 <font class="comment">Revision 0.2 99/04/21 18:06:26 18:06:26 naderp (Paul Nader)</font>
00119 <font class="comment">*** empty log message ***</font>
00120 <font class="comment"></font>
00121 <font class="comment">Revision 0.1.1.1 98/11/27 16:59:37 16:59:37 naderp (Paul Nader)</font>
00122 <font class="comment">Added -s option to sleep after disconnecting.</font>
00123 <font class="comment"></font>
00124 <font class="comment">Revision 0.1 98/11/25 14:08:21 14:08:21 naderp (Paul Nader)</font>
00125 <font class="comment">Initial Revision</font>
00126 <font class="comment"></font>
00127 <font class="comment">*/</font>
00128
00129 <font class="preprocessor">#ifdef HAVE_CONFIG_H</font>
00130 <font class="preprocessor"></font><font class="preprocessor"># include "<a class="code" href="a00082.html">config.h</a>"</font>
00131 <font class="preprocessor">#endif</font>
00132 <font class="preprocessor"></font>
00133 <font class="preprocessor">#ifdef HAVE_GETOPT</font>
00134 <font class="preprocessor"></font><font class="preprocessor"># include <unistd.h></font>
00135 <font class="keyword">extern</font> <font class="keywordtype">char</font>* optarg;
00136 <font class="keyword">extern</font> <font class="keywordtype">int</font> optind;
00137 <font class="preprocessor">#else</font>
00138 <font class="preprocessor"></font><font class="preprocessor"># include "<a class="code" href="a00104.html">getopt.h</a>"</font>
00139 <font class="preprocessor">#endif</font>
00140 <font class="preprocessor"></font>
00141 <font class="preprocessor">#ifdef HAVE_IOSTREAM</font>
00142 <font class="preprocessor"></font><font class="preprocessor"># include <iostream></font>
00143 <font class="preprocessor">#else</font>
00144 <font class="preprocessor"></font><font class="preprocessor"># include <iostream.h></font>
00145 <font class="preprocessor">#endif</font>
00146 <font class="preprocessor"></font>
00147 <font class="preprocessor">#ifdef HAVE_STD_IOSTREAM</font>
00148 <font class="preprocessor"></font><font class="keyword">using</font> <font class="keyword">namespace </font>std;
00149 <font class="preprocessor">#endif</font>
00150 <font class="preprocessor"></font>
00151 <font class="preprocessor">#ifdef HAVE_STDLIB_H</font>
00152 <font class="preprocessor"></font><font class="preprocessor"># include <stdlib.h></font>
00153 <font class="preprocessor">#endif</font>
00154 <font class="preprocessor"></font>
00155 <font class="preprocessor">#ifdef HAVE_SIGNAL_H</font>
00156 <font class="preprocessor"></font><font class="preprocessor"># include <signal.h></font>
00157 <font class="preprocessor">#endif</font>
00158 <font class="preprocessor"></font>
00159 <font class="preprocessor">#include "CosEventComm.hh"</font>
00160 <font class="preprocessor">#include "CosEventChannelAdmin.hh"</font>
00161 <font class="preprocessor">#include "<a class="code" href="a00109.html">naming.h</a>"</font>
00162
<a name="l00163"></a><a class="code" href="a00130.html#a0">00163</a> <font class="keyword">static</font> omni_mutex <a class="code" href="a00130.html#a0">mutex</a>;
00164 <font class="keyword">static</font> omni_condition <a class="code" href="a00130.html#a1">connect_cond</a>(&<a class="code" href="a00130.html#a0">mutex</a>);
00165 <font class="keyword">static</font> <font class="keywordtype">void</font> <a class="code" href="a00131.html#a0">usage</a>(<font class="keywordtype">int</font> argc, <font class="keywordtype">char</font> **argv);
00166
00167 <font class="keyword">class </font><a class="code" href="a00042.html">Consumer_i</a> : <font class="keyword">virtual</font> <font class="keyword">public</font> POA_CosEventComm::PushConsumer {
00168 <font class="keyword">public</font>:
<a name="l00169"></a><a class="code" href="a00042.html#a6">00169</a> <a class="code" href="a00042.html#a4">Consumer_i</a>(<font class="keywordtype">long</font> disconnect=0): <a class="code" href="a00042.html#o1">_disconnect</a>(disconnect) {}
00170
00171 <font class="keywordtype">void</font> <a class="code" href="a00042.html#a1">push</a>(<font class="keyword">const</font> CORBA::Any& data);
00172 <font class="keywordtype">void</font> <a class="code" href="a00042.html#a2">disconnect_push_consumer</a> ();
00173
00174 <font class="keyword">private</font>:
<a name="l00175"></a><a class="code" href="a00042.html#o1">00175</a> <font class="keywordtype">long</font> <a class="code" href="a00042.html#o1">_disconnect</a>;
00176 };
00177
00178 <font class="keywordtype">void</font> <a class="code" href="a00042.html#a1">Consumer_i::push</a>(<font class="keyword">const</font> CORBA::Any& data) {
00179 CORBA::ULong l;
00180 <font class="keyword">static</font> <font class="keywordtype">int</font> i = 0;
00181
00182 i++;
00183 <font class="keywordflow">if</font>( data>>=l )
00184 {
00185 cout<<<font class="stringliteral">"Push Consumer: push() called. Data : "</font><< l <<endl;
00186
00187 <font class="comment">// Exercise Disconnect</font>
00188 <font class="keywordflow">if</font> (i == <a class="code" href="a00042.html#o1">_disconnect</a>)
00189 {
00190 i = 0;
00191 <font class="comment">// NOTE : The proxy_supplier object is disposed at the server</font>
00192 <font class="comment">// during the disconnect_push_supplier call. Do NOT</font>
00193 <font class="comment">// use the proxy_supplier reference after disconnecting.</font>
00194
00195 <font class="comment">// Signal main thread to disconnect and re-connect.</font>
00196 <a class="code" href="a00130.html#a1">connect_cond</a>.signal();
00197 }
00198 }
00199 <font class="keywordflow">else</font>
00200 {
00201 cerr<<<font class="stringliteral">"Push Consumer: push() called. UNEXPECTED TYPE"</font><<endl;
00202 }
00203 }
00204
00205 <font class="keywordtype">void</font> <a class="code" href="a00042.html#a2">Consumer_i::disconnect_push_consumer</a> () {
00206 cout << <font class="stringliteral">"Push Consumer: disconnected."</font> << endl;
00207 }
00208
00209 <font class="keywordtype">int</font>
<a name="l00210"></a><a class="code" href="a00130.html#a3">00210</a> <a class="code" href="a00131.html#a1">main</a>(<font class="keywordtype">int</font> argc, <font class="keywordtype">char</font> **argv)
00211 {
00212 <font class="comment">//</font>
00213 <font class="comment">// Start orb.</font>
00214 CORBA::ORB_ptr orb = CORBA::ORB_init(argc,argv);
00215
00216 <font class="comment">// Process Options</font>
00217 <font class="keywordtype">int</font> discnum =0;
00218 <font class="keywordtype">int</font> sleepInterval =0;
00219 <font class="keyword">const</font> <font class="keywordtype">char</font>* channelName =<font class="stringliteral">"EventChannel"</font>;
00220
00221 <font class="keywordtype">int</font> c;
00222 <font class="keywordflow">while</font> ((c = <a class="code" href="a00103.html#a5">getopt</a>(argc,argv,<font class="stringliteral">"hd:s:n:"</font>)) != EOF)
00223 {
00224 <font class="keywordflow">switch</font> (c)
00225 {
00226 <font class="keywordflow">case</font> <font class="charliteral">'d'</font>: discnum = atoi(optarg);
00227 <font class="keywordflow">break</font>;
00228
00229 <font class="keywordflow">case</font> <font class="charliteral">'s'</font>: sleepInterval = atoi(optarg);
00230 <font class="keywordflow">break</font>;
00231
00232 <font class="keywordflow">case</font> <font class="charliteral">'n'</font>: channelName = optarg;
00233 <font class="keywordflow">break</font>;
00234
00235 <font class="keywordflow">case</font> <font class="charliteral">'h'</font>: <a class="code" href="a00131.html#a0">usage</a>(argc,argv);
00236 exit(0);
00237 <font class="keywordflow">default</font> : <a class="code" href="a00131.html#a0">usage</a>(argc,argv);
00238 exit(-1);
00239 }
00240 }
00241
00242 <font class="preprocessor">#if defined(HAVE_SIGNAL_H) && defined(SIGPIPE)</font>
00243 <font class="preprocessor"></font> <font class="comment">// Ignore broken pipes</font>
00244 signal(SIGPIPE, SIG_IGN);
00245 <font class="preprocessor">#endif</font>
00246 <font class="preprocessor"></font>
00247 <a class="code" href="a00042.html">Consumer_i</a>* consumer = <font class="keyword">new</font> <a class="code" href="a00042.html">Consumer_i</a> (discnum);
00248 CosEventChannelAdmin::EventChannel_var channel;
00249
00250 <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>
00251 <font class="keywordflow">try</font> {
00252 CORBA::Object_var obj;
00253
00254 action=<font class="stringliteral">"resolve initial reference 'RootPOA'"</font>;
00255 obj=orb->resolve_initial_references(<font class="stringliteral">"RootPOA"</font>);
00256 PortableServer::POA_var rootPoa =PortableServer::POA::_narrow(obj);
00257 <font class="keywordflow">if</font>(CORBA::is_nil(rootPoa))
00258 <font class="keywordflow">throw</font> CORBA::OBJECT_NOT_EXIST();
00259
00260 action=<font class="stringliteral">"activate the RootPOA's POAManager"</font>;
00261 PortableServer::POAManager_var pman =rootPoa->the_POAManager();
00262 pman->activate();
00263
00264 <font class="comment">//</font>
00265 <font class="comment">// Obtain object reference to EventChannel</font>
00266 <font class="comment">// (from command-line argument or from the Naming Service).</font>
00267 <font class="keywordflow">if</font>(optind<argc)
00268 {
00269 action=<font class="stringliteral">"convert URI from command line into object reference"</font>;
00270 obj=orb->string_to_object(argv[optind]);
00271 }
00272 <font class="keywordflow">else</font>
00273 {
00274 action=<font class="stringliteral">"resolve initial reference 'NameService'"</font>;
00275 obj=orb->resolve_initial_references(<font class="stringliteral">"NameService"</font>);
00276 CosNaming::NamingContext_var rootContext=
00277 CosNaming::NamingContext::_narrow(obj);
00278 <font class="keywordflow">if</font>(CORBA::is_nil(rootContext))
00279 <font class="keywordflow">throw</font> CORBA::OBJECT_NOT_EXIST();
00280
00281 action=<font class="stringliteral">"find EventChannel in NameService"</font>;
00282 cout << action << endl;
00283 obj=rootContext->resolve(<a class="code" href="a00108.html#a1">str2name</a>(channelName));
00284 }
00285
00286 action=<font class="stringliteral">"narrow object reference to event channel"</font>;
00287 channel=CosEventChannelAdmin::EventChannel::_narrow(obj);
00288 <font class="keywordflow">if</font>(CORBA::is_nil(channel))
00289 {
00290 cerr << <font class="stringliteral">"Failed to narrow Event Channel reference."</font> << endl;
00291 exit(1);
00292 }
00293
00294 }
00295 <font class="keywordflow">catch</font>(CORBA::ORB::InvalidName& ex) { <font class="comment">// resolve_initial_references</font>
00296 cerr<<<font class="stringliteral">"Failed to "</font><<action<<<font class="stringliteral">". ORB::InvalidName"</font><<endl;
00297 exit(1);
00298 }
00299 <font class="keywordflow">catch</font>(CosNaming::NamingContext::InvalidName& ex) { <font class="comment">// resolve</font>
00300 cerr<<<font class="stringliteral">"Failed to "</font><<action<<<font class="stringliteral">". NamingContext::InvalidName"</font><<endl;
00301 exit(1);
00302 }
00303 <font class="keywordflow">catch</font>(CosNaming::NamingContext::NotFound& ex) { <font class="comment">// resolve</font>
00304 cerr<<<font class="stringliteral">"Failed to "</font><<action<<<font class="stringliteral">". NamingContext::NotFound"</font><<endl;
00305 exit(1);
00306 }
00307 <font class="keywordflow">catch</font>(CosNaming::NamingContext::CannotProceed& ex) { <font class="comment">// resolve</font>
00308 cerr<<<font class="stringliteral">"Failed to "</font><<action<<<font class="stringliteral">". NamingContext::CannotProceed"</font><<endl;
00309 exit(1);
00310 }
00311 <font class="keywordflow">catch</font>(CORBA::TRANSIENT& ex) { <font class="comment">// _narrow()</font>
00312 cerr<<<font class="stringliteral">"Failed to "</font><<action<<<font class="stringliteral">". TRANSIENT"</font><<endl;
00313 exit(1);
00314 }
00315 <font class="keywordflow">catch</font>(CORBA::OBJECT_NOT_EXIST& ex) { <font class="comment">// _narrow()</font>
00316 cerr<<<font class="stringliteral">"Failed to "</font><<action<<<font class="stringliteral">". OBJECT_NOT_EXIST"</font><<endl;
00317 exit(1);
00318 }
00319 <font class="keywordflow">catch</font>(CORBA::SystemException& ex) {
00320 cerr<<<font class="stringliteral">"Failed to "</font><<action<<<font class="stringliteral">"."</font>;
00321 <font class="preprocessor">#if defined(HAVE_OMNIORB4)</font>
00322 <font class="preprocessor"></font> cerr<<<font class="stringliteral">" "</font><<ex._name();
00323 <font class="keywordflow">if</font>(ex.NP_minorString())
00324 cerr<<<font class="stringliteral">" ("</font><<ex.NP_minorString()<<<font class="stringliteral">")"</font>;
00325 <font class="preprocessor">#endif</font>
00326 <font class="preprocessor"></font> cerr<<endl;
00327 exit(1);
00328 }
00329 <font class="keywordflow">catch</font>(CORBA::Exception& ex) {
00330 cerr<<<font class="stringliteral">"Failed to "</font><<action<<<font class="stringliteral">"."</font>
00331 <font class="preprocessor">#if defined(HAVE_OMNIORB4)</font>
00332 <font class="preprocessor"></font> <font class="stringliteral">" "</font><<ex._name()
00333 <font class="preprocessor">#endif</font>
00334 <font class="preprocessor"></font> <<endl;
00335 exit(1);
00336 }
00337
00338 <font class="comment">//</font>
00339 <font class="comment">// Get Consumer admin interface - retrying on Comms Failure.</font>
00340 CosEventChannelAdmin::ConsumerAdmin_var consumer_admin;
00341 <font class="keywordflow">while</font> (1)
00342 {
00343 <font class="keywordflow">try</font> {
00344 consumer_admin = channel->for_consumers ();
00345 <font class="keywordflow">if</font> (CORBA::is_nil (consumer_admin))
00346 {
00347 cerr << <font class="stringliteral">"Event Channel returned nil Consumer Admin!"</font> << endl;
00348 exit(1);
00349 }
00350 <font class="keywordflow">break</font>;
00351 }
00352 <font class="keywordflow">catch</font> (CORBA::COMM_FAILURE& ex) {
00353 cerr << <font class="stringliteral">"Caught COMM_FAILURE exception "</font>
00354 << <font class="stringliteral">"obtaining Consumer Admin! Retrying..."</font>
00355 << endl;
00356 <font class="keywordflow">continue</font>;
00357 }
00358 }
00359 cout << <font class="stringliteral">"Obtained ConsumerAdmin."</font> << endl;
00360
00361 <font class="keywordflow">while</font> (1) {
00362 <font class="comment">//</font>
00363 <font class="comment">// Get proxy supplier - retrying on Comms Failure.</font>
00364 CosEventChannelAdmin::ProxyPushSupplier_var proxy_supplier;
00365 <font class="keywordflow">while</font> (1)
00366 {
00367 <font class="keywordflow">try</font> {
00368 proxy_supplier = consumer_admin->obtain_push_supplier ();
00369 <font class="keywordflow">if</font> (CORBA::is_nil (proxy_supplier))
00370 {
00371 cerr << <font class="stringliteral">"Consumer Admin returned nil proxy_supplier!"</font>
00372 << endl;
00373 exit (1);
00374 }
00375 <font class="keywordflow">break</font>;
00376 }
00377 <font class="keywordflow">catch</font> (CORBA::COMM_FAILURE& ex) {
00378 cerr << <font class="stringliteral">"Caught COMM_FAILURE Exception "</font>
00379 << <font class="stringliteral">"obtaining Push Supplier! Retrying..."</font>
00380 << endl;
00381 <font class="keywordflow">continue</font>;
00382 }
00383 }
00384 cout << <font class="stringliteral">"Obtained ProxyPushSupplier."</font> << endl;
00385
00386 <font class="comment">//</font>
00387 <font class="comment">// Connect Push Consumer - retrying on Comms Failure.</font>
00388 <font class="keywordflow">while</font> (1)
00389 {
00390 <font class="keywordflow">try</font> {
00391 proxy_supplier->connect_push_consumer(consumer->_this());
00392 <font class="keywordflow">break</font>;
00393 }
00394 <font class="keywordflow">catch</font> (CORBA::BAD_PARAM& ex) {
00395 cerr << <font class="stringliteral">"Caught BAD_PARAM Exception connecting Push Consumer!"</font>
00396 << endl;
00397 exit (1);
00398 }
00399 <font class="keywordflow">catch</font> (CosEventChannelAdmin::AlreadyConnected& ex) {
00400 cerr << <font class="stringliteral">"Proxy Push Supplier already connected!"</font>
00401 << endl;
00402 <font class="keywordflow">break</font>;
00403 }
00404 <font class="keywordflow">catch</font> (CORBA::COMM_FAILURE& ex) {
00405 cerr << <font class="stringliteral">"Caught COMM_FAILURE exception "</font>
00406 << <font class="stringliteral">"connecting Push Consumer! Retrying..."</font>
00407 << endl;
00408 <font class="keywordflow">continue</font>;
00409 }
00410 }
00411 cout << <font class="stringliteral">"Connected Push Consumer."</font> << endl;
00412
00413 <font class="comment">// Wait for indication to disconnect before re-connecting.</font>
00414 {
00415 omni_mutex_lock condition_lock(<a class="code" href="a00130.html#a0">mutex</a>);
00416 <a class="code" href="a00130.html#a1">connect_cond</a>.wait();
00417 }
00418
00419 <font class="comment">// Disconnect - retrying on Comms Failure.</font>
00420 <font class="keywordflow">while</font> (1)
00421 {
00422 <font class="keywordflow">try</font> {
00423 proxy_supplier->disconnect_push_supplier();
00424 <font class="keywordflow">break</font>;
00425 }
00426 <font class="keywordflow">catch</font> (CORBA::COMM_FAILURE& ex) {
00427 cerr << <font class="stringliteral">"Caught COMM_FAILURE Exception "</font>
00428 << <font class="stringliteral">"disconnecting Push Consumer! Retrying..."</font>
00429 << endl;
00430 <font class="keywordflow">continue</font>;
00431 }
00432 }
00433 cout << <font class="stringliteral">"Disconnected Push Consumer."</font> << endl;
00434
00435 <font class="comment">// Yawn</font>
00436 cout << <font class="stringliteral">"Sleeping "</font> << sleepInterval << <font class="stringliteral">" seconds."</font> << endl;
00437 omni_thread::sleep(sleepInterval);
00438 }
00439
00440 <font class="comment">// NEVER GET HERE</font>
00441 <font class="keywordflow">return</font> 0;
00442 }
00443
00444 <font class="keyword">static</font> <font class="keywordtype">void</font>
<a name="l00445"></a><a class="code" href="a00130.html#a2">00445</a> <a class="code" href="a00131.html#a0">usage</a>(<font class="keywordtype">int</font> argc, <font class="keywordtype">char</font> **argv)
00446 {
00447 cerr<<
00448 <font class="stringliteral">"\nCreate a PushConsumer to receive events from a channel.\n"</font>
00449 <font class="stringliteral">"syntax: "</font><<(argc?argv[0]:<font class="stringliteral">"pushcons"</font>)<<<font class="stringliteral">" OPTIONS [CHANNEL_URI]\n"</font>
00450 <font class="stringliteral">"\n"</font>
00451 <font class="stringliteral">"CHANNEL_URI: The event channel may be specified as a URI.\n"</font>
00452 <font class="stringliteral">" This may be an IOR, or a corbaloc::: or corbaname::: URI.\n"</font>
00453 <font class="stringliteral">"\n"</font>
00454 <font class="stringliteral">"OPTIONS: DEFAULT:\n"</font>
00455 <font class="stringliteral">" -d NUM disconnect after receiving NUM events [0 - never disconnect]\n"</font>
00456 <font class="stringliteral">" -s SECS sleep SECS seconds after disconnecting [0]\n"</font>
00457 <font class="stringliteral">" -n NAME channel name (if URI is not specified) [\"EventChannel\"]\n"</font>
00458 <font class="stringliteral">" -h display this help text\n"</font> << endl;
00459 }
</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>
|