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
|
<!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>pushsupp.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>pushsupp.cc</h1><a href="a00131.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">// pushsupp.cc Created on: 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 supplier implementation.</font>
00026 <font class="comment">// </font>
00027
00028 <font class="comment">/*</font>
00029 <font class="comment"> $Log: pushsupp.cc,v $</font>
00030 <font class="comment"> Revision 1.10 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.9 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.8 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.7 2004/04/20 16:52:17 alextingle</font>
00041 <font class="comment"> All examples updated for latest version on omniEvents. Server may now be</font>
00042 <font class="comment"> specified as a 'corbaloc' string or IOR, instead of as naming service id/kind.</font>
00043 <font class="comment"></font>
00044 <font class="comment"> Revision 1.6 2004/03/23 19:09:26 alextingle</font>
00045 <font class="comment"> Fixed typos.</font>
00046 <font class="comment"></font>
00047 <font class="comment"> Revision 1.5 2004/02/21 19:07:45 alextingle</font>
00048 <font class="comment"> Corrected servants to use POA instead of BOA.</font>
00049 <font class="comment"></font>
00050 <font class="comment"> Revision 1.4 2004/02/04 22:29:55 alextingle</font>
00051 <font class="comment"> Reworked all C++ examples.</font>
00052 <font class="comment"> Removed catch(...) as it tends to make it harder to see what's going on.</font>
00053 <font class="comment"> Now uses POA instead of BOA.</font>
00054 <font class="comment"> Uses omniORB4's Exception name probing.</font>
00055 <font class="comment"> No longer uses 'naming.h/cc' utility code.</font>
00056 <font class="comment"></font>
00057 <font class="comment"> Revision 1.3 2003/11/03 22:19:25 alextingle</font>
00058 <font class="comment"> Removed all platform specific switches. Now uses autoconf, config.h.</font>
00059 <font class="comment"> Removed stub header in order to allow makefile dependency checking to work</font>
00060 <font class="comment"> correctly.</font>
00061 <font class="comment"> Changed int to bool where appropriate.</font>
00062 <font class="comment"></font>
00063 <font class="comment"> Revision 1.1.1.1.2.1 2002/09/28 22:20:51 shamus13</font>
00064 <font class="comment"> Added ifdefs to enable omniEvents to compile</font>
00065 <font class="comment"> with both omniORB3 and omniORB4. If __OMNIORB4__</font>
00066 <font class="comment"> is defined during compilation, omniORB4 headers</font>
00067 <font class="comment"> and command line option syntax is used, otherwise</font>
00068 <font class="comment"> fall back to omniORB3 style.</font>
00069 <font class="comment"></font>
00070 <font class="comment"> Revision 1.1.1.1 2002/09/25 19:00:26 shamus13</font>
00071 <font class="comment"> Import of OmniEvents source tree from release 2.1.1</font>
00072 <font class="comment"></font>
00073 <font class="comment"> Revision 0.14 2000/10/11 01:16:21 naderp</font>
00074 <font class="comment"> *** empty log message ***</font>
00075 <font class="comment"></font>
00076 <font class="comment"> Revision 0.13 2000/08/30 04:39:48 naderp</font>
00077 <font class="comment"> Port to omniORB 3.0.1.</font>
00078 <font class="comment"></font>
00079 <font class="comment"> Revision 0.12 2000/03/16 05:37:27 naderp</font>
00080 <font class="comment"> Added stdlib.h for getopt.</font>
00081 <font class="comment"></font>
00082 <font class="comment"> Revision 0.11 2000/03/06 13:27:10 naderp</font>
00083 <font class="comment"> Using util getRootNamingContext function.</font>
00084 <font class="comment"> Using stub headers.</font>
00085 <font class="comment"> Fixed error messages.</font>
00086 <font class="comment"></font>
00087 <font class="comment"> Revision 0.10 2000/03/02 03:21:20 naderp</font>
00088 <font class="comment"> Added -r option to connect using nil reference.</font>
00089 <font class="comment"> Added retry resiliency for handling COMM_FAUILURE exceptions.</font>
00090 <font class="comment"></font>
00091 <font class="comment">Revision 0.9 99/11/02 13:39:17 13:39:17 naderp (Paul Nader)</font>
00092 <font class="comment">Added <signal.h></font>
00093 <font class="comment"></font>
00094 <font class="comment"> Revision 0.8 1999/11/02 07:57:18 naderp</font>
00095 <font class="comment"> Updated usage.</font>
00096 <font class="comment"></font>
00097 <font class="comment">Revision 0.7 99/11/01 19:22:43 19:22:43 naderp (Paul Nader)</font>
00098 <font class="comment">Added catch for COMM_FAILURE exception in obtain_push_consumer</font>
00099 <font class="comment">and disconnect_push_consumer calls.</font>
00100 <font class="comment"></font>
00101 <font class="comment">Revision 0.6 99/11/01 16:12:03 16:12:03 naderp (Paul Nader)</font>
00102 <font class="comment">omniEvents 2.0 Release.</font>
00103 <font class="comment"></font>
00104 <font class="comment">Revision 0.5 99/10/27 19:42:31 19:42:31 naderp (Paul Nader)</font>
00105 <font class="comment">Ignoring Unix SIGPIPE signal.</font>
00106 <font class="comment">Reporting sleep beforhand.</font>
00107 <font class="comment"></font>
00108 <font class="comment">Revision 0.4 99/04/23 16:05:47 16:05:47 naderp (Paul Nader)</font>
00109 <font class="comment">gcc port.</font>
00110 <font class="comment"></font>
00111 <font class="comment">Revision 0.3 99/04/23 09:34:04 09:34:04 naderp (Paul Nader)</font>
00112 <font class="comment">Windows Port.</font>
00113 <font class="comment"></font>
00114 <font class="comment">Revision 0.2 99/04/21 18:06:26 18:06:26 naderp (Paul Nader)</font>
00115 <font class="comment">*** empty log message ***</font>
00116 <font class="comment"></font>
00117 <font class="comment">Revision 0.1.1.1 98/11/27 16:59:40 16:59:40 naderp (Paul Nader)</font>
00118 <font class="comment">Added -s option to sleep after disconnecting.</font>
00119 <font class="comment"></font>
00120 <font class="comment">Revision 0.1 98/11/25 14:08:25 14:08:25 naderp (Paul Nader)</font>
00121 <font class="comment">Initial Revision</font>
00122 <font class="comment"></font>
00123 <font class="comment">*/</font>
00124
00125 <font class="preprocessor">#ifdef HAVE_CONFIG_H</font>
00126 <font class="preprocessor"></font><font class="preprocessor"># include "<a class="code" href="a00082.html">config.h</a>"</font>
00127 <font class="preprocessor">#endif</font>
00128 <font class="preprocessor"></font>
00129 <font class="preprocessor">#ifdef HAVE_GETOPT</font>
00130 <font class="preprocessor"></font><font class="preprocessor"># include <unistd.h></font>
00131 <font class="keyword">extern</font> <font class="keywordtype">char</font>* optarg;
00132 <font class="keyword">extern</font> <font class="keywordtype">int</font> optind;
00133 <font class="preprocessor">#else</font>
00134 <font class="preprocessor"></font><font class="preprocessor"># include "<a class="code" href="a00104.html">getopt.h</a>"</font>
00135 <font class="preprocessor">#endif</font>
00136 <font class="preprocessor"></font>
00137 <font class="preprocessor">#ifdef HAVE_IOSTREAM</font>
00138 <font class="preprocessor"></font><font class="preprocessor"># include <iostream></font>
00139 <font class="preprocessor">#else</font>
00140 <font class="preprocessor"></font><font class="preprocessor"># include <iostream.h></font>
00141 <font class="preprocessor">#endif</font>
00142 <font class="preprocessor"></font>
00143 <font class="preprocessor">#ifdef HAVE_STD_IOSTREAM</font>
00144 <font class="preprocessor"></font><font class="keyword">using</font> <font class="keyword">namespace </font>std;
00145 <font class="preprocessor">#endif</font>
00146 <font class="preprocessor"></font>
00147 <font class="preprocessor">#ifdef HAVE_STDLIB_H</font>
00148 <font class="preprocessor"></font><font class="preprocessor"># include <stdlib.h></font>
00149 <font class="preprocessor">#endif</font>
00150 <font class="preprocessor"></font>
00151 <font class="preprocessor">#ifdef HAVE_SIGNAL_H</font>
00152 <font class="preprocessor"></font><font class="preprocessor"># include <signal.h></font>
00153 <font class="preprocessor">#endif</font>
00154 <font class="preprocessor"></font>
00155 <font class="preprocessor">#include "CosEventComm.hh"</font>
00156 <font class="preprocessor">#include "CosEventChannelAdmin.hh"</font>
00157 <font class="preprocessor">#include "<a class="code" href="a00109.html">naming.h</a>"</font>
00158
00159 <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);
00160
00161 <font class="keyword">class </font><a class="code" href="a00075.html">Supplier_i</a> : <font class="keyword">virtual</font> <font class="keyword">public</font> POA_CosEventComm::PushSupplier {
00162 <font class="keyword">public</font>:
<a name="l00163"></a><a class="code" href="a00075.html#a7">00163</a> <a class="code" href="a00075.html#a0">Supplier_i</a> () {};
00164 <font class="keywordtype">void</font> <a class="code" href="a00075.html#a1">disconnect_push_supplier</a> ();
00165 };
00166
00167 <font class="keywordtype">void</font>
00168 <a class="code" href="a00075.html#a1">Supplier_i::disconnect_push_supplier</a> () {
00169 cout << <font class="stringliteral">"Push Supplier: disconnected."</font> << endl;
00170 }
00171
<a name="l00172"></a><a class="code" href="a00131.html#a1">00172</a> <font class="keywordtype">int</font> <a class="code" href="a00131.html#a1">main</a> (<font class="keywordtype">int</font> argc, <font class="keywordtype">char</font>** argv)
00173 {
00174 <font class="keywordtype">long</font> l = 0;
00175 CORBA::ORB_ptr orb = CORBA::ORB_init(argc,argv);
00176
00177 <font class="comment">// Process Options</font>
00178 <font class="keywordtype">int</font> discnum =0;
00179 <font class="keywordtype">bool</font> refnil =<font class="keyword">false</font>;
00180 <font class="keywordtype">int</font> sleepInterval =0;
00181 <font class="keyword">const</font> <font class="keywordtype">char</font>* channelName =<font class="stringliteral">"EventChannel"</font>;
00182
00183 <font class="keywordtype">int</font> c;
00184 <font class="keywordflow">while</font> ((c = <a class="code" href="a00103.html#a5">getopt</a>(argc,argv,<font class="stringliteral">"d:rs:n:h"</font>)) != EOF)
00185 {
00186 <font class="keywordflow">switch</font> (c)
00187 {
00188 <font class="keywordflow">case</font> <font class="charliteral">'d'</font>: discnum = atoi(optarg);
00189 <font class="keywordflow">break</font>;
00190
00191 <font class="keywordflow">case</font> <font class="charliteral">'r'</font>: refnil = <font class="keyword">true</font>;
00192 <font class="keywordflow">break</font>;
00193
00194 <font class="keywordflow">case</font> <font class="charliteral">'s'</font>: sleepInterval = atoi(optarg);
00195 <font class="keywordflow">break</font>;
00196
00197 <font class="keywordflow">case</font> <font class="charliteral">'n'</font>: channelName = optarg;
00198 <font class="keywordflow">break</font>;
00199
00200 <font class="keywordflow">case</font> <font class="charliteral">'h'</font>:
00201 <font class="keywordflow">default</font> : <a class="code" href="a00131.html#a0">usage</a>(argc,argv);
00202 exit(-1);
00203 <font class="keywordflow">break</font>;
00204 }
00205 }
00206
00207 <font class="preprocessor">#if defined(HAVE_SIGNAL_H) && defined(SIGPIPE)</font>
00208 <font class="preprocessor"></font> <font class="comment">// Ignore broken pipes</font>
00209 signal(SIGPIPE, SIG_IGN);
00210 <font class="preprocessor">#endif</font>
00211 <font class="preprocessor"></font>
00212 <a class="code" href="a00075.html">Supplier_i</a>* supplier = NULL;
00213 CosEventChannelAdmin::EventChannel_var channel;
00214
00215 <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>
00216 <font class="keywordflow">try</font> {
00217 CORBA::Object_var obj;
00218
00219 <font class="comment">// A Push Supplier can be implemented as a pure client or as a mixed</font>
00220 <font class="comment">// client-server process, depending on whether it requires and is</font>
00221 <font class="comment">// prepared to service disconnect requests from the channel.</font>
00222 <font class="comment">// If it is then create the servant object and activate the POA.</font>
00223 <font class="keywordflow">if</font>(!refnil)
00224 {
00225 supplier=<font class="keyword">new</font> <a class="code" href="a00075.html">Supplier_i</a>();
00226
00227 action=<font class="stringliteral">"resolve initial reference 'RootPOA'"</font>;
00228 obj=orb->resolve_initial_references(<font class="stringliteral">"RootPOA"</font>);
00229 PortableServer::POA_var rootPoa =PortableServer::POA::_narrow(obj);
00230 <font class="keywordflow">if</font>(CORBA::is_nil(rootPoa))
00231 <font class="keywordflow">throw</font> CORBA::OBJECT_NOT_EXIST();
00232
00233 action=<font class="stringliteral">"activate the RootPOA's POAManager"</font>;
00234 PortableServer::POAManager_var pman =rootPoa->the_POAManager();
00235 pman->activate();
00236 }
00237
00238 <font class="comment">//</font>
00239 <font class="comment">// Obtain object reference to EventChannel</font>
00240 <font class="comment">// (from command-line argument or from the Naming Service).</font>
00241 <font class="keywordflow">if</font>(optind<argc)
00242 {
00243 action=<font class="stringliteral">"convert URI from command line into object reference"</font>;
00244 obj=orb->string_to_object(argv[optind]);
00245 }
00246 <font class="keywordflow">else</font>
00247 {
00248 action=<font class="stringliteral">"resolve initial reference 'NameService'"</font>;
00249 obj=orb->resolve_initial_references(<font class="stringliteral">"NameService"</font>);
00250 CosNaming::NamingContext_var rootContext=
00251 CosNaming::NamingContext::_narrow(obj);
00252 <font class="keywordflow">if</font>(CORBA::is_nil(rootContext))
00253 <font class="keywordflow">throw</font> CORBA::OBJECT_NOT_EXIST();
00254
00255 action=<font class="stringliteral">"find EventChannel in NameService"</font>;
00256 cout << action << endl;
00257 obj=rootContext->resolve(<a class="code" href="a00108.html#a1">str2name</a>(channelName));
00258 }
00259
00260 action=<font class="stringliteral">"narrow object reference to event channel"</font>;
00261 channel=CosEventChannelAdmin::EventChannel::_narrow(obj);
00262 <font class="keywordflow">if</font>(CORBA::is_nil(channel))
00263 {
00264 cerr << <font class="stringliteral">"Failed to narrow Event Channel reference."</font> << endl;
00265 exit(1);
00266 }
00267
00268 }
00269 <font class="keywordflow">catch</font>(CORBA::ORB::InvalidName& ex) { <font class="comment">// resolve_initial_references</font>
00270 cerr<<<font class="stringliteral">"Failed to "</font><<action<<<font class="stringliteral">". ORB::InvalidName"</font><<endl;
00271 exit(1);
00272 }
00273 <font class="keywordflow">catch</font>(CosNaming::NamingContext::InvalidName& ex) { <font class="comment">// resolve</font>
00274 cerr<<<font class="stringliteral">"Failed to "</font><<action<<<font class="stringliteral">". NamingContext::InvalidName"</font><<endl;
00275 exit(1);
00276 }
00277 <font class="keywordflow">catch</font>(CosNaming::NamingContext::NotFound& ex) { <font class="comment">// resolve</font>
00278 cerr<<<font class="stringliteral">"Failed to "</font><<action<<<font class="stringliteral">". NamingContext::NotFound"</font><<endl;
00279 exit(1);
00280 }
00281 <font class="keywordflow">catch</font>(CosNaming::NamingContext::CannotProceed& ex) { <font class="comment">// resolve</font>
00282 cerr<<<font class="stringliteral">"Failed to "</font><<action<<<font class="stringliteral">". NamingContext::CannotProceed"</font><<endl;
00283 exit(1);
00284 }
00285 <font class="keywordflow">catch</font>(CORBA::TRANSIENT& ex) { <font class="comment">// _narrow()</font>
00286 cerr<<<font class="stringliteral">"Failed to "</font><<action<<<font class="stringliteral">". TRANSIENT"</font><<endl;
00287 exit(1);
00288 }
00289 <font class="keywordflow">catch</font>(CORBA::OBJECT_NOT_EXIST& ex) { <font class="comment">// _narrow()</font>
00290 cerr<<<font class="stringliteral">"Failed to "</font><<action<<<font class="stringliteral">". OBJECT_NOT_EXIST"</font><<endl;
00291 exit(1);
00292 }
00293 <font class="keywordflow">catch</font>(CORBA::SystemException& ex) {
00294 cerr<<<font class="stringliteral">"Failed to "</font><<action<<<font class="stringliteral">"."</font>;
00295 <font class="preprocessor">#if defined(HAVE_OMNIORB4)</font>
00296 <font class="preprocessor"></font> cerr<<<font class="stringliteral">" "</font><<ex._name();
00297 <font class="keywordflow">if</font>(ex.NP_minorString())
00298 cerr<<<font class="stringliteral">" ("</font><<ex.NP_minorString()<<<font class="stringliteral">")"</font>;
00299 <font class="preprocessor">#endif</font>
00300 <font class="preprocessor"></font> cerr<<endl;
00301 exit(1);
00302 }
00303 <font class="keywordflow">catch</font>(CORBA::Exception& ex) {
00304 cerr<<<font class="stringliteral">"Failed to "</font><<action<<<font class="stringliteral">"."</font>
00305 <font class="preprocessor">#if defined(HAVE_OMNIORB4)</font>
00306 <font class="preprocessor"></font> <font class="stringliteral">" "</font><<ex._name()
00307 <font class="preprocessor">#endif</font>
00308 <font class="preprocessor"></font> <<endl;
00309 exit(1);
00310 }
00311
00312 <font class="comment">//</font>
00313 <font class="comment">// Get Supplier Admin interface - retrying on Comms Failure.</font>
00314 CosEventChannelAdmin::SupplierAdmin_var supplier_admin;
00315 <font class="keywordflow">while</font> (1)
00316 {
00317 <font class="keywordflow">try</font> {
00318 supplier_admin = channel->for_suppliers ();
00319 <font class="keywordflow">if</font> (CORBA::is_nil(supplier_admin))
00320 {
00321 cerr << <font class="stringliteral">"Event Channel returned nil Supplier Admin!"</font>
00322 << endl;
00323 exit(1);
00324 }
00325 <font class="keywordflow">break</font>;
00326 }
00327 <font class="keywordflow">catch</font> (CORBA::COMM_FAILURE& ex) {
00328 cerr << <font class="stringliteral">"Caught COMM_FAILURE Exception "</font>
00329 << <font class="stringliteral">"obtaining Supplier Admin! Retrying..."</font>
00330 << endl;
00331 <font class="keywordflow">continue</font>;
00332 }
00333 }
00334 cout << <font class="stringliteral">"Obtained SupplierAdmin."</font> << endl;
00335
00336 <font class="keywordflow">while</font> (1)
00337 {
00338 <font class="comment">//</font>
00339 <font class="comment">// Get proxy consumer - retrying on Comms Failure.</font>
00340 CosEventChannelAdmin::ProxyPushConsumer_var proxy_consumer;
00341 <font class="keywordflow">while</font> (1)
00342 {
00343 <font class="keywordflow">try</font> {
00344 proxy_consumer = supplier_admin->obtain_push_consumer ();
00345 <font class="keywordflow">if</font> (CORBA::is_nil(proxy_consumer))
00346 {
00347 cerr << <font class="stringliteral">"Supplier Admin returned nil proxy_consumer!"</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 Proxy Push Consumer! Retrying..."</font>
00355 << endl;
00356 <font class="keywordflow">continue</font>;
00357 }
00358 }
00359 cout << <font class="stringliteral">"Obtained ProxyPushConsumer."</font> << endl;
00360
00361 <font class="comment">//</font>
00362 <font class="comment">// Connect Push Supplier - retrying on Comms Failure.</font>
00363 CosEventComm::PushSupplier_var sptr =CosEventComm::PushSupplier::_nil();
00364 <font class="keywordflow">if</font> (! refnil) {
00365 sptr = supplier->_this();
00366 }
00367
00368 <font class="keywordflow">while</font> (1)
00369 {
00370 <font class="keywordflow">try</font> {
00371 proxy_consumer->connect_push_supplier(sptr.in());
00372 <font class="keywordflow">break</font>;
00373 }
00374 <font class="keywordflow">catch</font> (CORBA::BAD_PARAM& ex) {
00375 cerr << <font class="stringliteral">"Caught BAD_PARAM Exception connecting Push Supplier!"</font>
00376 << endl;
00377 exit (1);
00378 }
00379 <font class="keywordflow">catch</font> (CosEventChannelAdmin::AlreadyConnected& ex) {
00380 cerr << <font class="stringliteral">"Proxy Push Consumer already connected!"</font>
00381 << endl;
00382 <font class="keywordflow">break</font>;
00383 }
00384 <font class="keywordflow">catch</font> (CORBA::COMM_FAILURE& ex) {
00385 cerr << <font class="stringliteral">"Caught COMM_FAILURE Exception "</font>
00386 << <font class="stringliteral">"connecting Push Supplier! Retrying..."</font>
00387 << endl;
00388 <font class="keywordflow">continue</font>;
00389 }
00390 }
00391 cout << <font class="stringliteral">"Connected Push Supplier."</font> << endl;
00392
00393 <font class="comment">// Push data.</font>
00394 <font class="keywordflow">for</font> (<font class="keywordtype">int</font> i=0; (discnum == 0) || (i < discnum); i++)
00395 {
00396 CORBA::Any any;
00397 any <<= (CORBA::ULong) l++;
00398 <font class="keywordflow">try</font> {
00399 cout << <font class="stringliteral">"Push Supplier: push() called. "</font> << flush;
00400 proxy_consumer->push(any);
00401 cout << <font class="stringliteral">"Data : "</font> << l-1 << endl;
00402 }
00403 <font class="keywordflow">catch</font>(CosEventComm::Disconnected&) {
00404 cout << <font class="stringliteral">"Failed. Caught Disconnected Exception!"</font> << endl;
00405 }
00406 <font class="keywordflow">catch</font>(CORBA::COMM_FAILURE&) {
00407 cout << <font class="stringliteral">"Failed. Caught COMM_FAILURE Exception!"</font> << endl;
00408 }
00409 }
00410
00411 <font class="comment">// Disconnect - retrying on Comms Failure.</font>
00412 <font class="keywordflow">while</font> (1)
00413 {
00414 <font class="keywordflow">try</font> {
00415 proxy_consumer->disconnect_push_consumer();
00416 <font class="keywordflow">break</font>;
00417 }
00418 <font class="keywordflow">catch</font> (CORBA::COMM_FAILURE& ex) {
00419 cerr << <font class="stringliteral">"Caught COMM_FAILURE Exception "</font>
00420 << <font class="stringliteral">"disconnecting Push Supplier! Retrying..."</font>
00421 << endl;
00422 <font class="keywordflow">continue</font>;
00423 }
00424 }
00425 cout << <font class="stringliteral">"ProxyPushConsumer disconnected."</font> << endl;
00426
00427 <font class="comment">// Yawn.</font>
00428 cout << <font class="stringliteral">"Sleeping "</font> << sleepInterval << <font class="stringliteral">" seconds."</font> << endl;
00429 omni_thread::sleep(sleepInterval);
00430 }
00431
00432 <font class="comment">// Not Reached</font>
00433 <font class="keywordflow">return</font> 0;
00434 }
00435
00436 <font class="keyword">static</font> <font class="keywordtype">void</font>
<a name="l00437"></a><a class="code" href="a00131.html#a0">00437</a> <a class="code" href="a00131.html#a0">usage</a>(<font class="keywordtype">int</font> argc, <font class="keywordtype">char</font> **argv)
00438 {
00439 cerr<<
00440 <font class="stringliteral">"\nCreate a PushSupplier to send events to a channel.\n"</font>
00441 <font class="stringliteral">"syntax: "</font><<(argc?argv[0]:<font class="stringliteral">"pushsupp"</font>)<<<font class="stringliteral">" OPTIONS [CHANNEL_URI]\n"</font>
00442 <font class="stringliteral">"\n"</font>
00443 <font class="stringliteral">"CHANNEL_URI: The event channel may be specified as a URI.\n"</font>
00444 <font class="stringliteral">" This may be an IOR, or a corbaloc::: or corbaname::: URI.\n"</font>
00445 <font class="stringliteral">"\n"</font>
00446 <font class="stringliteral">"OPTIONS: DEFAULT:\n"</font>
00447 <font class="stringliteral">" -d NUM disconnect after sending NUM events [0 - never disconnect]\n"</font>
00448 <font class="stringliteral">" -r connect using a nil reference\n"</font>
00449 <font class="stringliteral">" -s SECS sleep SECS seconds after disconnecting [0]\n"</font>
00450 <font class="stringliteral">" -n NAME channel name (if URI is not specified) [\"EventChannel\"]\n"</font>
00451 <font class="stringliteral">" -h display this help text\n"</font> << endl;
00452 }
</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>
|