File: a00151.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 (479 lines) | stat: -rw-r--r-- 32,585 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
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
474
475
476
477
478
479
<!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>eventc.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>eventc.cc</h1><a href="a00091.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">// eventc.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.</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">//    Client to the event channel factory. Requests creation of an event</font>
00026 <font class="comment">//    channel and registers it with the Naming service.</font>
00027 <font class="comment">//      </font>
00028 
00029 <font class="comment">/*</font>
00030 <font class="comment">  $Log: eventc.cc,v $</font>
00031 <font class="comment">  Revision 1.4.2.1  2004/11/01 12:27:12  alextingle</font>
00032 <font class="comment">  New EventChannel parameter `PullRetryPeriod_ms' supercedes `PullRetryPeriod'.</font>
00033 <font class="comment">  The new parameter is set by `eventc -R'. The old parameter and its `-r'</font>
00034 <font class="comment">  option still work as before, for backwards compatibility.</font>
00035 <font class="comment"></font>
00036 <font class="comment">  Revision 1.4  2004/10/08 09:06:19  alextingle</font>
00037 <font class="comment">  More robust exception minor code handling.</font>
00038 <font class="comment"></font>
00039 <font class="comment">  Revision 1.3  2004/08/06 16:16:40  alextingle</font>
00040 <font class="comment">  Simplified call to ORB_init().</font>
00041 <font class="comment"></font>
00042 <font class="comment">  Revision 1.2  2004/08/04 21:52:52  alextingle</font>
00043 <font class="comment">  'n' &amp; 'N' options now take a full name path. No more 'k' or 'K' options.</font>
00044 <font class="comment"></font>
00045 <font class="comment">  Revision 1.1  2004/05/31 10:29:37  alextingle</font>
00046 <font class="comment">  New 'tools' directory. Contains useful command line tools that previously lived in the 'examples' directory.</font>
00047 <font class="comment"></font>
00048 <font class="comment">  Revision 1.14  2004/05/28 10:38:23  alextingle</font>
00049 <font class="comment">  Now uses new omniEvents.idl header. Properly this time!</font>
00050 <font class="comment"></font>
00051 <font class="comment">  Revision 1.13  2004/05/28 10:16:54  alextingle</font>
00052 <font class="comment">  Now uses new omniEvents.idl header.</font>
00053 <font class="comment"></font>
00054 <font class="comment">  Revision 1.12  2004/04/30 17:48:02  alextingle</font>
00055 <font class="comment">  New 'real time push' feature: -t option.</font>
00056 <font class="comment"></font>
00057 <font class="comment">  Revision 1.11  2004/04/21 10:23:46  alextingle</font>
00058 <font class="comment">  If there is no Naming Service, eventc only issues a warning unless it is needed to find the factory, or options -n or -k are set.</font>
00059 <font class="comment"></font>
00060 <font class="comment">  Revision 1.10  2004/04/20 16:51:59  alextingle</font>
00061 <font class="comment">  All examples updated for latest version on omniEvents. Server may now be</font>
00062 <font class="comment">  specified as a 'corbaloc' string or IOR, instead of as naming service id/kind.</font>
00063 <font class="comment"></font>
00064 <font class="comment">  Revision 1.9  2004/03/28 00:58:05  alextingle</font>
00065 <font class="comment">  New options. -c sets CyclePeriod_ns. -i sets the Channel's InsName.</font>
00066 <font class="comment"></font>
00067 <font class="comment">  Revision 1.8  2004/03/26 16:06:30  alextingle</font>
00068 <font class="comment">  Added verbose (-v) option that prints the new channel's IOR to standard out.</font>
00069 <font class="comment"></font>
00070 <font class="comment">  Revision 1.7  2004/02/20 17:41:40  alextingle</font>
00071 <font class="comment">  Moved 'endl;' to the actual end!!</font>
00072 <font class="comment"></font>
00073 <font class="comment">  Revision 1.6  2004/02/20 14:01:54  alextingle</font>
00074 <font class="comment">  New param: -p sets MaxNumProxies for omniEvents 2.5+.</font>
00075 <font class="comment">  No longer sends parameters that are not explicitly set on</font>
00076 <font class="comment">  the command line. This leaves the server to decide upon</font>
00077 <font class="comment">  default values.</font>
00078 <font class="comment"></font>
00079 <font class="comment">  Revision 1.5  2004/02/04 22:29:55  alextingle</font>
00080 <font class="comment">  Reworked all C++ examples.</font>
00081 <font class="comment">  Removed catch(...) as it tends to make it harder to see what's going on.</font>
00082 <font class="comment">  Now uses POA instead of BOA.</font>
00083 <font class="comment">  Uses omniORB4's Exception name probing.</font>
00084 <font class="comment">  No longer uses 'naming.h/cc' utility code.</font>
00085 <font class="comment"></font>
00086 <font class="comment">  Revision 1.4  2003/12/21 11:12:01  alextingle</font>
00087 <font class="comment">  Most exceptions are now caught by a unified catch block.</font>
00088 <font class="comment"></font>
00089 <font class="comment">  Revision 1.3  2003/11/03 22:21:21  alextingle</font>
00090 <font class="comment">  Removed all platform specific switches. Now uses autoconf, config.h.</font>
00091 <font class="comment">  Removed stub header in order to allow makefile dependency checking to work</font>
00092 <font class="comment">  correctly.</font>
00093 <font class="comment"></font>
00094 <font class="comment">  Revision 1.1.1.1.2.1  2002/09/28 22:20:51  shamus13</font>
00095 <font class="comment">  Added ifdefs to enable omniEvents to compile</font>
00096 <font class="comment">  with both omniORB3 and omniORB4. If __OMNIORB4__</font>
00097 <font class="comment">  is defined during compilation, omniORB4 headers</font>
00098 <font class="comment">  and command line option syntax is used, otherwise</font>
00099 <font class="comment">  fall back to omniORB3 style.</font>
00100 <font class="comment"></font>
00101 <font class="comment">  Revision 1.1.1.1  2002/09/25 19:00:25  shamus13</font>
00102 <font class="comment">  Import of OmniEvents source tree from release 2.1.1</font>
00103 <font class="comment"></font>
00104 <font class="comment">  Revision 1.6  2000/09/05 01:05:38  naderp</font>
00105 <font class="comment">  Added MaxQueueLength QOS.</font>
00106 <font class="comment"></font>
00107 <font class="comment">  Revision 1.5  2000/08/30 04:39:20  naderp</font>
00108 <font class="comment">  Port to omniORB 3.0.1.</font>
00109 <font class="comment"></font>
00110 <font class="comment">  Revision 1.4  2000/03/16 05:34:30  naderp</font>
00111 <font class="comment">  Added stdlib.h for solaris getopt()</font>
00112 <font class="comment"></font>
00113 <font class="comment">  Revision 1.3  2000/03/16 02:44:13  naderp</font>
00114 <font class="comment">  Added iostream and signal headers.</font>
00115 <font class="comment"></font>
00116 <font class="comment">  Revision 1.2  2000/03/06 13:23:50  naderp</font>
00117 <font class="comment">  Using util getRootNamingContext function.</font>
00118 <font class="comment">  Using stub headers.</font>
00119 <font class="comment"></font>
00120 <font class="comment">  Revision 1.1  1999/11/01 20:37:42  naderp</font>
00121 <font class="comment">  Updated usage statement.</font>
00122 <font class="comment"></font>
00123 <font class="comment">Revision 1.0  99/11/01  17:05:13  17:05:13  naderp (Paul Nader)</font>
00124 <font class="comment">omniEvents 2.0.</font>
00125 <font class="comment">Added -m switch to support MaxEventsPerConsumer criteria.</font>
00126 <font class="comment"></font>
00127 <font class="comment">Revision 0.6  99/08/27  11:48:22  11:48:22  naderp (Paul Nader)</font>
00128 <font class="comment">Partitioned EventChannelFactory_i from CosEvent_i.</font>
00129 <font class="comment"></font>
00130 <font class="comment">Revision 0.5  99/05/10  11:27:50  11:27:50  naderp (Paul Nader)</font>
00131 <font class="comment">Initialised rootContext.</font>
00132 <font class="comment"></font>
00133 <font class="comment">Revision 0.4  99/04/23  16:02:22  16:02:22  naderp (Paul Nader)</font>
00134 <font class="comment">gcc port.</font>
00135 <font class="comment"></font>
00136 <font class="comment">Revision 0.3  99/04/23  09:32:58  09:32:58  naderp (Paul Nader)</font>
00137 <font class="comment">Windows Port.</font>
00138 <font class="comment"></font>
00139 <font class="comment">Revision 0.2  99/04/21  18:06:23  18:06:23  naderp (Paul Nader)</font>
00140 <font class="comment">*** empty log message ***</font>
00141 <font class="comment"></font>
00142 <font class="comment">Revision 0.1.1.1  98/11/27  17:01:51  17:01:51  naderp (Paul Nader)</font>
00143 <font class="comment">Enclosed supports call in try block to avoid core dump.</font>
00144 <font class="comment">Added information messages for exceptions.</font>
00145 <font class="comment"></font>
00146 <font class="comment">Revision 0.1  98/11/25  14:07:22  14:07:22  naderp (Paul Nader)</font>
00147 <font class="comment">Initial Revision</font>
00148 <font class="comment"></font>
00149 <font class="comment">*/</font>
00150 
00151 <font class="comment">//</font>
00152 <font class="comment">//</font>
00153 
00154 <font class="preprocessor">#ifdef HAVE_CONFIG_H</font>
00155 <font class="preprocessor"></font><font class="preprocessor">#  include "<a class="code" href="a00082.html">config.h</a>"</font>
00156 <font class="preprocessor">#endif</font>
00157 <font class="preprocessor"></font>
00158 <font class="preprocessor">#ifdef HAVE_GETOPT</font>
00159 <font class="preprocessor"></font><font class="preprocessor">#  include &lt;unistd.h&gt;</font>
00160 <font class="keyword">extern</font> <font class="keywordtype">char</font>* optarg;
00161 <font class="keyword">extern</font> <font class="keywordtype">int</font> optind;
00162 <font class="preprocessor">#else</font>
00163 <font class="preprocessor"></font><font class="preprocessor">#  include "<a class="code" href="a00104.html">getopt.h</a>"</font>
00164 <font class="preprocessor">#endif</font>
00165 <font class="preprocessor"></font>
00166 <font class="preprocessor">#ifdef HAVE_IOSTREAM</font>
00167 <font class="preprocessor"></font><font class="preprocessor">#  include &lt;iostream&gt;</font>
00168 <font class="preprocessor">#else</font>
00169 <font class="preprocessor"></font><font class="preprocessor">#  include &lt;iostream.h&gt;</font>
00170 <font class="preprocessor">#endif</font>
00171 <font class="preprocessor"></font>
00172 <font class="preprocessor">#ifdef HAVE_STD_IOSTREAM</font>
00173 <font class="preprocessor"></font><font class="keyword">using</font> <font class="keyword">namespace </font>std;
00174 <font class="preprocessor">#endif</font>
00175 <font class="preprocessor"></font>
00176 <font class="preprocessor">#ifdef HAVE_STDLIB_H</font>
00177 <font class="preprocessor"></font><font class="preprocessor">#  include &lt;stdlib.h&gt;</font>
00178 <font class="preprocessor">#endif</font>
00179 <font class="preprocessor"></font>
00180 <font class="preprocessor">#ifdef HAVE_SIGNAL_H</font>
00181 <font class="preprocessor"></font><font class="preprocessor">#  include &lt;signal.h&gt;</font>
00182 <font class="preprocessor">#endif</font>
00183 <font class="preprocessor"></font>
00184 <font class="preprocessor">#include "omniEvents.hh"</font>
00185 <font class="preprocessor">#include "<a class="code" href="a00109.html">naming.h</a>"</font>
00186 
00187 <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);
00188 <font class="keyword">static</font> <font class="keywordtype">void</font> <a class="code" href="a00091.html#a1">appendCriterion</a>(   CosLifeCycle::Criteria&amp;,<font class="keyword">const</font> <font class="keywordtype">char</font>*,<font class="keyword">const</font> <font class="keywordtype">char</font>*);
00189 <font class="keyword">static</font> <font class="keywordtype">void</font> <a class="code" href="a00091.html#a2">appendCriterionStr</a>(CosLifeCycle::Criteria&amp;,<font class="keyword">const</font> <font class="keywordtype">char</font>*,<font class="keyword">const</font> <font class="keywordtype">char</font>*);
00190 
00191 <font class="keywordtype">int</font>
<a name="l00192"></a><a class="code" href="a00091.html#a3">00192</a> <a class="code" href="a00131.html#a1">main</a>(<font class="keywordtype">int</font> argc, <font class="keywordtype">char</font> **argv)
00193 {
00194   <font class="keywordtype">int</font> result =1;
00195 
00196   <font class="comment">//</font>
00197   <font class="comment">// Start orb.</font>
00198   CORBA::ORB_ptr orb = CORBA::ORB_init(argc,argv);
00199 
00200   <font class="comment">// Process Options</font>
00201   <font class="keywordtype">bool</font> verbose =<font class="keyword">false</font>;
00202   <font class="keywordtype">bool</font> needNameService =<font class="keyword">false</font>;
00203   <font class="keyword">const</font> <font class="keywordtype">char</font>* channelName =<font class="stringliteral">"EventChannel"</font>;
00204   <font class="keyword">const</font> <font class="keywordtype">char</font>* factoryName =<font class="stringliteral">"EventChannelFactory"</font>;
00205   CosLifeCycle::Criteria criteria;
00206 
00207   <font class="keywordtype">int</font> c;
00208   <font class="keywordflow">while</font> ((c = <a class="code" href="a00103.html#a5">getopt</a>(argc,argv,<font class="stringliteral">"n:N:m:c:i:p:q:R:r:t:vh"</font>)) != EOF)
00209   {
00210      <font class="keywordflow">switch</font> (c)
00211      {
00212      <font class="keywordflow">case</font> <font class="charliteral">'n'</font>:
00213        channelName=optarg;
00214        needNameService=<font class="keyword">true</font>;       
00215        <font class="keywordflow">break</font>;
00216 
00217      <font class="keywordflow">case</font> <font class="charliteral">'N'</font>:
00218        factoryName=optarg;
00219        <font class="keywordflow">break</font>;
00220 
00221      <font class="keywordflow">case</font> <font class="charliteral">'m'</font>: <font class="comment">// OLD OPTION</font>
00222        <a class="code" href="a00091.html#a1">appendCriterion</a>(criteria,<font class="stringliteral">"MaxEventsPerConsumer"</font>,optarg);
00223        <font class="keywordflow">break</font>;
00224 
00225      <font class="keywordflow">case</font> <font class="charliteral">'c'</font>:
00226        <a class="code" href="a00091.html#a1">appendCriterion</a>(criteria,<font class="stringliteral">"CyclePeriod_ns"</font>,optarg);
00227        <font class="keywordflow">break</font>;
00228 
00229      <font class="keywordflow">case</font> <font class="charliteral">'i'</font>:
00230        <a class="code" href="a00091.html#a2">appendCriterionStr</a>(criteria,<font class="stringliteral">"InsName"</font>,optarg);
00231        <font class="keywordflow">break</font>;
00232 
00233      <font class="keywordflow">case</font> <font class="charliteral">'p'</font>:
00234        <a class="code" href="a00091.html#a1">appendCriterion</a>(criteria,<font class="stringliteral">"MaxNumProxies"</font>,optarg);
00235        <font class="keywordflow">break</font>;
00236 
00237      <font class="keywordflow">case</font> <font class="charliteral">'q'</font>:
00238        <a class="code" href="a00091.html#a1">appendCriterion</a>(criteria,<font class="stringliteral">"MaxQueueLength"</font>,optarg);
00239        <font class="keywordflow">break</font>;
00240 
00241      <font class="keywordflow">case</font> <font class="charliteral">'R'</font>:
00242        <a class="code" href="a00091.html#a1">appendCriterion</a>(criteria,<font class="stringliteral">"PullRetryPeriod_ms"</font>,optarg);
00243        <font class="keywordflow">break</font>;
00244 
00245      <font class="keywordflow">case</font> <font class="charliteral">'r'</font>: <font class="comment">// This option is deprecated in favour of -R:</font>
00246        <a class="code" href="a00091.html#a1">appendCriterion</a>(criteria,<font class="stringliteral">"PullRetryPeriod"</font>,optarg);
00247        <font class="keywordflow">break</font>;
00248 
00249      <font class="keywordflow">case</font> <font class="charliteral">'t'</font>:
00250        <a class="code" href="a00091.html#a2">appendCriterionStr</a>(criteria,<font class="stringliteral">"FilterId"</font>,optarg);
00251        <font class="keywordflow">break</font>;
00252 
00253      <font class="keywordflow">case</font> <font class="charliteral">'v'</font>:
00254        verbose=<font class="keyword">true</font>;
00255        <font class="keywordflow">break</font>;
00256 
00257      <font class="keywordflow">case</font> <font class="charliteral">'h'</font>:
00258        <a class="code" href="a00131.html#a0">usage</a>(argc,argv);
00259        exit(0);
00260 
00261      <font class="keywordflow">default</font> :
00262        <a class="code" href="a00131.html#a0">usage</a>(argc,argv);
00263        exit(-1);
00264      }
00265   }
00266   <font class="comment">// Need the naming service to find the factory if there is no URI argument.</font>
00267   needNameService=(needNameService || optind&gt;=argc);
00268 
00269   <font class="comment">//</font>
00270   <font class="comment">// Use one big try...catch block.</font>
00271   <font class="comment">// 'action' variable keeps track of what we're doing.</font>
00272   <font class="keyword">const</font> <font class="keywordtype">char</font>* action =<font class="stringliteral">"start"</font>;
00273   <font class="keywordflow">try</font>
00274   {
00275     CORBA::Object_var obj;
00276 
00277     <font class="comment">//</font>
00278     <font class="comment">// Get Name Service root context.(we can carry on without it though)</font>
00279     CosNaming::NamingContext_var rootContext=CosNaming::NamingContext::_nil();
00280     <font class="keywordflow">try</font> {
00281       action=<font class="stringliteral">"resolve initial reference 'NameService'"</font>;
00282       obj=orb-&gt;resolve_initial_references(<font class="stringliteral">"NameService"</font>);
00283       rootContext=CosNaming::NamingContext::_narrow(obj);
00284       <font class="keywordflow">if</font>(CORBA::is_nil(rootContext))
00285           <font class="keywordflow">throw</font> CORBA::OBJECT_NOT_EXIST();
00286     }
00287     <font class="keywordflow">catch</font> (CORBA::Exception&amp; ex) {
00288        <font class="keywordflow">if</font>(needNameService)
00289            <font class="keywordflow">throw</font>;
00290        <font class="keywordflow">else</font>
00291            cerr&lt;&lt;<font class="stringliteral">"Warning - failed to "</font>&lt;&lt;action&lt;&lt;<font class="stringliteral">"."</font>&lt;&lt;endl;
00292     }
00293 
00294     <font class="comment">//</font>
00295     <font class="comment">// Obtain reference to the Event Channel Factory implementation.</font>
00296     <font class="comment">// (from command-line argument or from the Naming Service).</font>
00297     <font class="keywordflow">if</font>(optind&lt;argc)
00298     {
00299       action=<font class="stringliteral">"convert URI from command line into object reference"</font>;
00300       obj=orb-&gt;string_to_object(argv[optind]);
00301     }
00302     <font class="keywordflow">else</font>
00303     {
00304       action=<font class="stringliteral">"find Event Channel Factory in naming service"</font>;
00305       obj=rootContext-&gt;resolve(<a class="code" href="a00108.html#a1">str2name</a>(factoryName));
00306     }
00307 
00308     action=<font class="stringliteral">"narrow object reference to event channel factory"</font>;
00309     omniEvents::EventChannelFactory_var factory =
00310       omniEvents::EventChannelFactory::_narrow(obj);
00311     <font class="keywordflow">if</font>(CORBA::is_nil(factory))
00312     {
00313        cerr &lt;&lt; <font class="stringliteral">"Failed to narrow Event Channel Factory reference."</font> &lt;&lt; endl;
00314        exit(1);
00315     }
00316 
00317     <font class="comment">// Check that the factory is of the right type</font>
00318     action=<font class="stringliteral">"check factory supports EventChannel object interface"</font>;
00319     CosLifeCycle::Key key;
00320     key.length (1);
00321     key[0].id = CORBA::string_dup(<font class="stringliteral">"EventChannel"</font>);
00322     key[0].kind = CORBA::string_dup(<font class="stringliteral">"object interface"</font>);
00323 
00324     <font class="keywordflow">if</font>(!factory-&gt;supports(key))
00325     {
00326       cerr &lt;&lt; <font class="stringliteral">"Factory does not support Event Channel Interface! [\""</font>
00327            &lt;&lt; factoryName &lt;&lt; <font class="stringliteral">"\"]"</font> &lt;&lt; endl;
00328       exit(1);
00329     }
00330 
00331     <font class="comment">//</font>
00332     <font class="comment">// Create Event Channel Object.</font>
00333     action=<font class="stringliteral">"create EventChannel object"</font>;
00334     CORBA::Object_var channelObj =factory-&gt;create_object(key, criteria);
00335     <font class="keywordflow">if</font> (CORBA::is_nil(channelObj))
00336     {
00337        cerr &lt;&lt; <font class="stringliteral">"Channel Factory returned nil reference! [\""</font>
00338             &lt;&lt; channelName &lt;&lt; <font class="stringliteral">"\"]"</font> &lt;&lt; endl;
00339        exit(1);
00340     }
00341 
00342     <font class="comment">// Narrow object returned to an Event Channel</font>
00343     CosEventChannelAdmin::EventChannel_var channel =
00344       CosEventChannelAdmin::EventChannel::_narrow(channelObj);
00345     <font class="keywordflow">if</font> (CORBA::is_nil(channel))
00346     {
00347        cerr &lt;&lt; <font class="stringliteral">"Failed to narrow Event Channel! [\""</font>
00348             &lt;&lt; channelName &lt;&lt; <font class="stringliteral">"\"]"</font> &lt;&lt; endl;
00349        exit(1);
00350     }
00351     
00352     <font class="comment">// Print the new EventChannel's IOR to standard output.</font>
00353     <font class="keywordflow">if</font>(verbose)
00354     {
00355       CORBA::String_var sior =orb-&gt;object_to_string(channel);
00356       cout&lt;&lt;sior.in()&lt;&lt;endl;
00357     }
00358 
00359     <font class="comment">//</font>
00360     <font class="comment">// Register event channel with naming service</font>
00361     <font class="keywordflow">if</font>(!CORBA::is_nil(rootContext))
00362     {
00363       CosNaming::Name name =<a class="code" href="a00108.html#a1">str2name</a>(channelName);
00364       <font class="keywordflow">try</font>{
00365         action=<font class="stringliteral">"register (bind) EventChannel with the naming service"</font>;
00366         rootContext-&gt;bind(name,channel.in());
00367       }
00368       <font class="keywordflow">catch</font>(CosNaming::NamingContext::AlreadyBound&amp; ex) {
00369         action=<font class="stringliteral">"register (rebind) EventChannel with the naming service"</font>;
00370         rootContext-&gt;rebind(name,channel.in());
00371       }
00372     }
00373     
00374     <font class="comment">//</font>
00375     <font class="comment">// If we get here, then everything has worked OK.</font>
00376     result=0;
00377 
00378   }
00379   <font class="keywordflow">catch</font> (CosLifeCycle::NoFactory&amp; ex) <font class="comment">/* create_object() */</font> {
00380      cerr&lt;&lt;<font class="stringliteral">"Failed to create Event Channel: NoFactory"</font>
00381        <font class="stringliteral">" (interface not supported) "</font>&lt;&lt;endl;
00382   }
00383   <font class="keywordflow">catch</font> (CosLifeCycle::CannotMeetCriteria&amp; ex) <font class="comment">/* create_object() */</font> {
00384      cerr&lt;&lt;<font class="stringliteral">"Failed to create Event Channel: CannotMeetCriteria "</font>&lt;&lt;endl;
00385   }
00386   <font class="keywordflow">catch</font> (CosLifeCycle::InvalidCriteria&amp; ex) <font class="comment">/* create_object() */</font> {
00387      cerr&lt;&lt;<font class="stringliteral">"Failed to create Event Channel: InvalidCriteria "</font>&lt;&lt;endl;
00388   }
00389   <font class="keywordflow">catch</font> (CORBA::COMM_FAILURE&amp; ex) {
00390      cerr&lt;&lt;<font class="stringliteral">"System exception, unable to "</font>&lt;&lt;action&lt;&lt;<font class="stringliteral">": COMM_FAILURE"</font>&lt;&lt;endl;
00391   }
00392   <font class="keywordflow">catch</font> (CORBA::SystemException&amp; ex) {
00393      cerr&lt;&lt;<font class="stringliteral">"System exception, unable to "</font>&lt;&lt;action;
00394 <font class="preprocessor">#if defined(HAVE_OMNIORB4)</font>
00395 <font class="preprocessor"></font>     cerr&lt;&lt;<font class="stringliteral">" "</font>&lt;&lt;ex._name();
00396      <font class="keywordflow">if</font>(ex.NP_minorString())
00397          cerr&lt;&lt;<font class="stringliteral">" ("</font>&lt;&lt;ex.NP_minorString()&lt;&lt;<font class="stringliteral">")"</font>;
00398 <font class="preprocessor">#endif</font>
00399 <font class="preprocessor"></font>     cerr&lt;&lt;endl;
00400   }
00401   <font class="keywordflow">catch</font> (CORBA::Exception&amp; ex) {
00402      cerr&lt;&lt;<font class="stringliteral">"CORBA exception, unable to "</font>&lt;&lt;action
00403 <font class="preprocessor">#ifdef HAVE_OMNIORB4</font>
00404 <font class="preprocessor"></font>         &lt;&lt;<font class="stringliteral">": "</font>&lt;&lt;ex._name()
00405 <font class="preprocessor">#endif</font>
00406 <font class="preprocessor"></font>         &lt;&lt; endl;
00407   }
00408   <font class="keywordflow">catch</font> (omniORB::fatalException&amp; ex) {
00409      cerr&lt;&lt;<font class="stringliteral">"Fatal Exception, unable to "</font>&lt;&lt;action&lt;&lt;endl;
00410   }
00411 
00412   <font class="keywordflow">return</font> result;
00413 }
00414 
00415 <font class="keyword">static</font> <font class="keywordtype">void</font>
<a name="l00416"></a><a class="code" href="a00091.html#a0">00416</a> <a class="code" href="a00131.html#a0">usage</a>(<font class="keywordtype">int</font> argc, <font class="keywordtype">char</font> **argv)
00417 {
00418   cerr&lt;&lt;
00419 <font class="stringliteral">"\nCreate an EventChannel and register it in the naming service.\n"</font>
00420 <font class="stringliteral">"syntax: "</font>&lt;&lt;(argc?argv[0]:<font class="stringliteral">"eventc"</font>)&lt;&lt;<font class="stringliteral">" OPTIONS [FACTORY_URI]\n"</font>
00421 <font class="stringliteral">"\n"</font>
00422 <font class="stringliteral">"FACTORY_URI: The factory may be specified as a URI.\n"</font>
00423 <font class="stringliteral">" This may be an IOR, or a corbaloc::: or corbaname::: URI.\n"</font>
00424 <font class="stringliteral">" For example: corbaloc::localhost:11169/omniEvents\n"</font>
00425 <font class="stringliteral">"\n"</font>
00426 <font class="stringliteral">"OPTIONS:                                         DEFAULT:\n"</font>
00427 <font class="stringliteral">" -n channel name                                  [\"EventChannel\"]\n"</font>
00428 <font class="stringliteral">" -N factory name (if URI is not specified)        [\"EventChannelFactory\"]\n"</font>
00429 <font class="stringliteral">" -c override default CyclePeriod_ns of new channel (nanoseconds)\n"</font>
00430 <font class="stringliteral">" -i set the InsName of new channel, to enable access via corbaloc\n"</font>
00431 <font class="stringliteral">" -p override default MaxNumProxies of new channel\n"</font>
00432 <font class="stringliteral">" -q override default MaxQueueLength of new channel\n"</font>
00433 <font class="stringliteral">" -R override default PullRetryPeriod_ms for new channel (milliseconds)\n"</font>
00434 <font class="stringliteral">" -t set an event type filter, FilterId=&lt;RepositoryId&gt;\n"</font>
00435 <font class="stringliteral">" -v print the IOR of the new EventChannel to standard output.\n"</font>
00436 <font class="stringliteral">" -h display this help text\n"</font>
00437 <font class="stringliteral">"OLD OPTIONS: (only used by omniEvents v2.4 and earlier)\n"</font>
00438 <font class="stringliteral">" -m override default MaxEventsPerConsumer for new channel\n"</font> &lt;&lt; endl;
00439 }
00440 
<a name="l00441"></a><a class="code" href="a00091.html#a1">00441</a> <font class="keyword">static</font> <font class="keywordtype">void</font> <a class="code" href="a00091.html#a1">appendCriterion</a>(
00442   CosLifeCycle::Criteria&amp; criteria,
00443   <font class="keyword">const</font> <font class="keywordtype">char</font>* name,
00444   <font class="keyword">const</font> <font class="keywordtype">char</font>* value
00445 )
00446 {
00447   CORBA::ULong criteriaLen =criteria.length();
00448   ++criteriaLen;
00449   criteria.length(criteriaLen);
00450   criteria[criteriaLen-1].name=CORBA::string_dup(name);
00451   criteria[criteriaLen-1].value&lt;&lt;=CORBA::ULong(atol(value));
00452 }
00453 
<a name="l00454"></a><a class="code" href="a00091.html#a2">00454</a> <font class="keyword">static</font> <font class="keywordtype">void</font> <a class="code" href="a00091.html#a2">appendCriterionStr</a>(
00455   CosLifeCycle::Criteria&amp; criteria,
00456   <font class="keyword">const</font> <font class="keywordtype">char</font>* name,
00457   <font class="keyword">const</font> <font class="keywordtype">char</font>* value
00458 )
00459 {
00460   CORBA::ULong criteriaLen =criteria.length();
00461   ++criteriaLen;
00462   criteria.length(criteriaLen);
00463   criteria[criteriaLen-1].name=CORBA::string_dup(name);
00464   criteria[criteriaLen-1].value&lt;&lt;=value;
00465 }
</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>