File: a00159.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 (459 lines) | stat: -rw-r--r-- 34,246 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
<!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>events.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>events.cc</h1><a href="a00099.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">//   events.cc                Created   : 2004/05/02</font>
00004 <font class="comment">//                            Author    : Alex Tingle</font>
00005 <font class="comment">//</font>
00006 <font class="comment">//    Copyright (C) 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 streamer.</font>
00026 <font class="comment">//      </font>
00027 
00028 <font class="preprocessor">#ifdef HAVE_CONFIG_H</font>
00029 <font class="preprocessor"></font><font class="preprocessor">#  include "<a class="code" href="a00082.html">config.h</a>"</font>
00030 <font class="preprocessor">#endif</font>
00031 <font class="preprocessor"></font>
00032 <font class="preprocessor">#ifdef HAVE_GETOPT</font>
00033 <font class="preprocessor"></font><font class="preprocessor">#  include &lt;unistd.h&gt;</font>
00034 <font class="keyword">extern</font> <font class="keywordtype">char</font>* optarg;
00035 <font class="keyword">extern</font> <font class="keywordtype">int</font> optind;
00036 <font class="preprocessor">#else</font>
00037 <font class="preprocessor"></font><font class="preprocessor">#  include "<a class="code" href="a00104.html">getopt.h</a>"</font>
00038 <font class="preprocessor">#endif</font>
00039 <font class="preprocessor"></font>
00040 <font class="preprocessor">#ifdef HAVE_IOSTREAM</font>
00041 <font class="preprocessor"></font><font class="preprocessor">#  include &lt;iostream&gt;</font>
00042 <font class="preprocessor">#else</font>
00043 <font class="preprocessor"></font><font class="preprocessor">#  include &lt;iostream.h&gt;</font>
00044 <font class="preprocessor">#endif</font>
00045 <font class="preprocessor"></font>
00046 <font class="preprocessor">#ifdef HAVE_STD_IOSTREAM</font>
00047 <font class="preprocessor"></font><font class="keyword">using</font> <font class="keyword">namespace </font>std;
00048 <font class="preprocessor">#endif</font>
00049 <font class="preprocessor"></font>
00050 <font class="preprocessor">#ifdef HAVE_STDLIB_H</font>
00051 <font class="preprocessor"></font><font class="preprocessor">#  include &lt;stdlib.h&gt;</font>
00052 <font class="preprocessor">#endif</font>
00053 <font class="preprocessor"></font>
00054 <font class="preprocessor">#include &lt;stdio.h&gt;</font>
00055 
00056 <font class="preprocessor">#if defined HAVE_UNISTD_H</font>
00057 <font class="preprocessor"></font><font class="preprocessor">#  include &lt;unistd.h&gt;</font> <font class="comment">// read(), write()</font>
00058 <font class="preprocessor">#elif defined __WIN32__</font>
00059 <font class="preprocessor"></font><font class="preprocessor">#  include &lt;io.h&gt;</font>
00060 <font class="preprocessor">#  define write(fd,buf,count) _write(fd,buf,count)</font>
00061 <font class="preprocessor"></font><font class="preprocessor">#  define read(fd,buf,count)  _read(fd,buf,count)</font>
00062 <font class="preprocessor"></font><font class="preprocessor">#  define ssize_t int</font>
00063 <font class="preprocessor"></font><font class="preprocessor">#endif</font>
00064 <font class="preprocessor"></font>
00065 <font class="preprocessor">#ifdef HAVE_SIGNAL_H</font>
00066 <font class="preprocessor"></font><font class="preprocessor">#  include &lt;signal.h&gt;</font>
00067 <font class="preprocessor">#endif</font>
00068 <font class="preprocessor"></font>
00069 <font class="preprocessor">#include "CosEventComm.hh"</font>
00070 <font class="preprocessor">#include "CosEventChannelAdmin.hh"</font>
00071 <font class="preprocessor">#include "<a class="code" href="a00109.html">naming.h</a>"</font>
00072 
00073 <font class="preprocessor">#ifndef STDIN_FILENO</font>
<a name="l00074"></a><a class="code" href="a00099.html#a0">00074</a> <font class="preprocessor"></font><font class="preprocessor"># define STDIN_FILENO 0</font>
<a name="l00075"></a><a class="code" href="a00099.html#a1">00075</a> <font class="preprocessor"></font><font class="preprocessor"># define STDOUT_FILENO 1</font>
00076 <font class="preprocessor"></font><font class="preprocessor">#endif</font>
00077 <font class="preprocessor"></font>
<a name="l00078"></a><a class="code" href="a00099.html#a3">00078</a> CORBA::ORB_ptr <a class="code" href="a00099.html#a3">orb</a>;
00079 
00080 <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);
00081 
00082 <font class="comment">//</font>
00083 <font class="comment">// Time</font>
00084 <font class="comment">//</font>
00085 
<a name="l00086"></a><a class="code" href="a00099.html#a2">00086</a> <font class="preprocessor">#define BILLION 1000000000</font>
00087 <font class="preprocessor"></font>
00088 <font class="keyword">class </font><a class="code" href="a00077.html">Time</a>;
<a name="l00089"></a><a class="code" href="a00077.html">00089</a> <font class="keyword">class </font><a class="code" href="a00077.html">Time</a>
00090 {
00091 <font class="keyword">private</font>:
<a name="l00092"></a><a class="code" href="a00077.html#o0">00092</a>   CORBA::ULong <a class="code" href="a00077.html#o0">_sec</a>;
<a name="l00093"></a><a class="code" href="a00077.html#o1">00093</a>   CORBA::ULong <a class="code" href="a00077.html#o1">_nano</a>;
00094 <font class="keyword">public</font>:
<a name="l00095"></a><a class="code" href="a00077.html#d0">00095</a>   <font class="keyword">static</font> <a class="code" href="a00077.html">Time</a> <a class="code" href="a00077.html#d0">current</a>()
00096   {
00097     <a class="code" href="a00077.html">Time</a> result;
00098     <font class="keywordtype">unsigned</font> <font class="keywordtype">long</font> sec,nano;
00099     omni_thread::get_time(&amp;sec,&amp;nano);
00100     result.<a class="code" href="a00077.html#o0">_sec</a>=sec;
00101     result.<a class="code" href="a00077.html#o1">_nano</a>=nano;
00102     <font class="keywordflow">return</font> result;
00103   }
<a name="l00104"></a><a class="code" href="a00077.html#d1">00104</a>   <font class="keyword">static</font> <font class="keywordtype">void</font> <a class="code" href="a00077.html#d1">sleepUntil</a>(<font class="keyword">const</font> <a class="code" href="a00077.html">Time</a>&amp; futureTime)
00105   {
00106     <a class="code" href="a00077.html">Time</a> now =<a class="code" href="a00077.html#d0">current</a>();
00107     <font class="keywordflow">if</font>(now&lt;futureTime)
00108     {
00109       <a class="code" href="a00077.html">Time</a> offset=futureTime-now;
00110       omni_thread::sleep(offset.<a class="code" href="a00077.html#o0">_sec</a>,offset.<a class="code" href="a00077.html#o1">_nano</a>);
00111     }
00112   }
00113   <font class="comment">//</font>
<a name="l00114"></a><a class="code" href="a00077.html#a0">00114</a>   <a class="code" href="a00077.html#a0">Time</a>():<a class="code" href="a00077.html#o0">_sec</a>(0),<a class="code" href="a00077.html#o1">_nano</a>(0){}
<a name="l00115"></a><a class="code" href="a00077.html#a1">00115</a>   <a class="code" href="a00077.html#a0">Time</a>(CORBA::ULong sec,CORBA::ULong nano):<a class="code" href="a00077.html#o0">_sec</a>(sec),<a class="code" href="a00077.html#o1">_nano</a>(nano){}
<a name="l00116"></a><a class="code" href="a00077.html#a2">00116</a>   <a class="code" href="a00077.html#a0">Time</a>(<font class="keyword">const</font> <a class="code" href="a00077.html">Time</a>&amp; right):<a class="code" href="a00077.html#o0">_sec</a>(right.<a class="code" href="a00077.html#o0">_sec</a>),<a class="code" href="a00077.html#o1">_nano</a>(right.<a class="code" href="a00077.html#o1">_nano</a>){}
<a name="l00117"></a><a class="code" href="a00077.html#a3">00117</a>   <a class="code" href="a00077.html">Time</a>&amp; <a class="code" href="a00077.html#a3">operator=</a>(<font class="keyword">const</font> <a class="code" href="a00077.html">Time</a>&amp; right)
00118   {
00119     <font class="keywordflow">if</font>(<font class="keyword">this</font>!=&amp;right)
00120     {
00121       <a class="code" href="a00077.html#o0">_sec</a> =right.<a class="code" href="a00077.html#o0">_sec</a>;
00122       <a class="code" href="a00077.html#o1">_nano</a>=right.<a class="code" href="a00077.html#o1">_nano</a>;
00123     }
00124     <font class="keywordflow">return</font> *<font class="keyword">this</font>;
00125   }
<a name="l00126"></a><a class="code" href="a00077.html#a4">00126</a>   <font class="keywordtype">bool</font> <a class="code" href="a00077.html#a4">operator&lt;</a>(<font class="keyword">const</font> <a class="code" href="a00077.html">Time</a>&amp; right)<font class="keyword"> const</font>
00127 <font class="keyword">  </font>{
00128     <font class="keywordflow">if</font>(<a class="code" href="a00077.html#o0">_sec</a>==right.<a class="code" href="a00077.html#o0">_sec</a>)
00129         <font class="keywordflow">return</font> <a class="code" href="a00077.html#o1">_nano</a>&lt;right.<a class="code" href="a00077.html#o1">_nano</a>;
00130     <font class="keywordflow">else</font>
00131         <font class="keywordflow">return</font> <a class="code" href="a00077.html#o0">_sec</a>&lt;right.<a class="code" href="a00077.html#o0">_sec</a>;
00132   }
<a name="l00133"></a><a class="code" href="a00077.html#a5">00133</a>   <a class="code" href="a00077.html">Time</a>&amp; <a class="code" href="a00077.html#a5">operator+=</a>(<font class="keyword">const</font> <a class="code" href="a00077.html">Time</a>&amp; right)
00134   {
00135     <a class="code" href="a00077.html#o0">_sec</a> +=right.<a class="code" href="a00077.html#o0">_sec</a>;
00136     <a class="code" href="a00077.html#o1">_nano</a>+=right.<a class="code" href="a00077.html#o1">_nano</a>;
00137     <font class="keywordflow">if</font>(<a class="code" href="a00077.html#o1">_nano</a>&gt;<a class="code" href="a00099.html#a2">BILLION</a>)
00138     {
00139       <a class="code" href="a00077.html#o1">_nano</a>=<a class="code" href="a00077.html#o1">_nano</a>%<a class="code" href="a00099.html#a2">BILLION</a>;
00140       ++<a class="code" href="a00077.html#o0">_sec</a>;
00141     }
00142     <font class="keywordflow">return</font> *<font class="keyword">this</font>;
00143   }
<a name="l00144"></a><a class="code" href="a00077.html#a6">00144</a>   <a class="code" href="a00077.html">Time</a> <a class="code" href="a00077.html#a6">operator+</a>(<font class="keyword">const</font> <a class="code" href="a00077.html">Time</a>&amp; right)<font class="keyword"> const</font>
00145 <font class="keyword">  </font>{
00146     <a class="code" href="a00077.html">Time</a> result(*<font class="keyword">this</font>);
00147     result+=right;
00148     <font class="keywordflow">return</font> result;
00149   }
<a name="l00150"></a><a class="code" href="a00077.html#a7">00150</a>   <a class="code" href="a00077.html">Time</a>&amp; <a class="code" href="a00077.html#a7">operator-=</a>(<font class="keyword">const</font> <a class="code" href="a00077.html">Time</a>&amp; right)
00151   {
00152     <font class="keywordflow">if</font>(<a class="code" href="a00077.html#a4">operator&lt;</a>(right))
00153     {
00154       cerr&lt;&lt;<font class="stringliteral">"Negative time!"</font>&lt;&lt;endl;
00155       <font class="keywordflow">throw</font> CORBA::BAD_PARAM();
00156     }
00157     <a class="code" href="a00077.html#o0">_sec</a>-=right.<a class="code" href="a00077.html#o0">_sec</a>;
00158     <font class="keywordflow">if</font>(<a class="code" href="a00077.html#o1">_nano</a>&lt;right.<a class="code" href="a00077.html#o1">_nano</a>)
00159     {
00160       <a class="code" href="a00077.html#o1">_nano</a>+=<a class="code" href="a00099.html#a2">BILLION</a>;
00161       --<a class="code" href="a00077.html#o0">_sec</a>;
00162     }
00163     <a class="code" href="a00077.html#o1">_nano</a>-=right.<a class="code" href="a00077.html#o1">_nano</a>;
00164     <font class="keywordflow">return</font> *<font class="keyword">this</font>;
00165   }
<a name="l00166"></a><a class="code" href="a00077.html#a8">00166</a>   <a class="code" href="a00077.html">Time</a> <a class="code" href="a00077.html#a8">operator-</a>(<font class="keyword">const</font> <a class="code" href="a00077.html">Time</a>&amp; right)<font class="keyword"> const</font>
00167 <font class="keyword">  </font>{
00168     <a class="code" href="a00077.html">Time</a> result(*<font class="keyword">this</font>);
00169     result-=right;
00170     <font class="keywordflow">return</font> result;
00171   }
<a name="l00172"></a><a class="code" href="a00077.html#a9">00172</a>   <font class="keywordtype">void</font> <a class="code" href="a00077.html#a9">operator&gt;&gt;=</a>(cdrMemoryStream&amp; s)<font class="keyword"> const</font>
00173 <font class="keyword">  </font>{
00174     <a class="code" href="a00077.html#o0">_sec</a>&gt;&gt;=s;
00175     <a class="code" href="a00077.html#o1">_nano</a>&gt;&gt;=s;
00176   }
<a name="l00177"></a><a class="code" href="a00077.html#a10">00177</a>   <font class="keywordtype">void</font> <a class="code" href="a00077.html#a10">operator&lt;&lt;=</a>(cdrMemoryStream&amp; s)
00178   {
00179     <a class="code" href="a00077.html#o0">_sec</a>&lt;&lt;=s;
00180     <a class="code" href="a00077.html#o1">_nano</a>&lt;&lt;=s;
00181   }
<a name="l00182"></a><a class="code" href="a00077.html#a11">00182</a>   <font class="keywordtype">bool</font> <a class="code" href="a00077.html#a11">is_nil</a>()<font class="keyword"> const </font>{ <font class="keywordflow">return</font>(<a class="code" href="a00077.html#o0">_sec</a>==0 &amp;&amp; <a class="code" href="a00077.html#o1">_nano</a>==0); }
00183 }; <font class="comment">// end class Time</font>
00184 
00185 
00186 <font class="comment">//</font>
00187 <font class="comment">// Consumer_i</font>
00188 <font class="comment">//</font>
00189 
<a name="l00190"></a><a class="code" href="a00042.html">00190</a> <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
00191 {
00192 <font class="keyword">public</font>:
<a name="l00193"></a><a class="code" href="a00042.html#a0">00193</a>   <a class="code" href="a00042.html#a4">Consumer_i</a>(<font class="keywordtype">long</font> disconnect=0): <a class="code" href="a00042.html#o0">_memstream</a>() {}
<a name="l00194"></a><a class="code" href="a00042.html#a1">00194</a>   <font class="keywordtype">void</font> <a class="code" href="a00042.html#a1">push</a>(<font class="keyword">const</font> CORBA::Any&amp; data)
00195   {
00196     <font class="comment">// Record the event timestamp.</font>
00197     <a class="code" href="a00077.html">Time</a> now=<a class="code" href="a00077.html#d0">Time::current</a>();
00198     now&gt;&gt;=<a class="code" href="a00042.html#o0">_memstream</a>;
00199     <font class="comment">// stream event data.</font>
00200     data&gt;&gt;=<a class="code" href="a00042.html#o0">_memstream</a>;
00201     <font class="comment">// Write to file.</font>
00202     write(<a class="code" href="a00099.html#a1">STDOUT_FILENO</a>,<a class="code" href="a00042.html#o0">_memstream</a>.bufPtr(),<a class="code" href="a00042.html#o0">_memstream</a>.bufSize());
00203     <font class="comment">// Reset.</font>
00204     <a class="code" href="a00042.html#o0">_memstream</a>.rewindPtrs();
00205   }
<a name="l00206"></a><a class="code" href="a00042.html#a2">00206</a>   <font class="keywordtype">void</font> <a class="code" href="a00042.html#a2">disconnect_push_consumer</a>()
00207   {
00208     cout&lt;&lt;<font class="stringliteral">"disconnected"</font>&lt;&lt;endl;
00209     <a class="code" href="a00099.html#a3">orb</a>-&gt;shutdown(0);
00210   }
<a name="l00211"></a><a class="code" href="a00042.html#a3">00211</a>   <font class="keywordtype">void</font> <a class="code" href="a00042.html#a3">consume</a>(
00212     CosEventChannelAdmin::EventChannel_ptr channel,
00213     <font class="keyword">const</font> <font class="keywordtype">char</font>*&amp; action)
00214   {
00215     action=<font class="stringliteral">"get ConsumerAdmin"</font>;
00216     CosEventChannelAdmin::ConsumerAdmin_var consumer_admin =
00217       channel-&gt;for_consumers();
00218 
00219     action=<font class="stringliteral">"get ProxyPushSupplier"</font>;
00220     CosEventChannelAdmin::ProxyPushSupplier_var proxy_supplier =
00221       consumer_admin-&gt;obtain_push_supplier();
00222 
00223     action=<font class="stringliteral">"connect to ProxyPushSupplier"</font>;
00224     proxy_supplier-&gt;connect_push_consumer(_this());
00225   }
00226 <font class="keyword">private</font>:
<a name="l00227"></a><a class="code" href="a00042.html#o0">00227</a>   cdrMemoryStream <a class="code" href="a00042.html#o0">_memstream</a>;
00228 };
00229 
00230 
00231 <font class="comment">//</font>
00232 <font class="comment">// Supplier_i</font>
00233 <font class="comment">//</font>
00234 
<a name="l00235"></a><a class="code" href="a00075.html">00235</a> <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
00236 {
00237 <font class="keyword">public</font>:
<a name="l00238"></a><a class="code" href="a00075.html#a0">00238</a>   <a class="code" href="a00075.html#a0">Supplier_i</a>(): <a class="code" href="a00075.html#o0">_connected</a>(true) {}
<a name="l00239"></a><a class="code" href="a00075.html#a1">00239</a>   <font class="keywordtype">void</font> <a class="code" href="a00075.html#a1">disconnect_push_supplier</a>()
00240   {
00241     cout&lt;&lt;<font class="stringliteral">"disconnected"</font>&lt;&lt;endl;
00242     <a class="code" href="a00075.html#o0">_connected</a>=<font class="keyword">false</font>;
00243   }
<a name="l00244"></a><a class="code" href="a00075.html#a2">00244</a>   <font class="keywordtype">void</font> <a class="code" href="a00075.html#a2">supply</a>(
00245     CosEventChannelAdmin::EventChannel_ptr channel,
00246     <font class="keyword">const</font> <font class="keywordtype">char</font>*&amp; action)
00247   {
00248     action=<font class="stringliteral">"get SupplierAdmin"</font>;
00249     CosEventChannelAdmin::SupplierAdmin_var supplier_admin =
00250       channel-&gt;for_suppliers();
00251 
00252     action=<font class="stringliteral">"get ProxyPushConsumer"</font>;
00253     CosEventChannelAdmin::ProxyPushConsumer_var proxy_consumer =
00254       supplier_admin-&gt;obtain_push_consumer();
00255 
00256     action=<font class="stringliteral">"connect to ProxyPushConsumer"</font>;
00257     proxy_consumer-&gt;connect_push_supplier(_this());
00258 
00259     <font class="keywordtype">char</font> buf[1024];
00260     ssize_t len;
00261     action=<font class="stringliteral">"read standard input"</font>;
00262     <font class="comment">// Stream start time (seconds,nanoseconds)</font>
00263     <a class="code" href="a00077.html">Time</a> offsetTime;
00264     <font class="keywordflow">while</font>(<a class="code" href="a00075.html#o0">_connected</a> &amp;&amp; (len=read(<a class="code" href="a00099.html#a0">STDIN_FILENO</a>,buf,1024)))
00265     {
00266       CORBA::Any any;
00267       cdrMemoryStream memstr;
00268       action=<font class="stringliteral">"put_octet_array"</font>;
00269       memstr.put_octet_array( (_CORBA_Octet*)buf, (<font class="keywordtype">int</font>)len );
00270       <font class="keywordflow">while</font>(<a class="code" href="a00075.html#o0">_connected</a> &amp;&amp; memstr.currentInputPtr()&lt;memstr.bufSize())
00271       {
00272         action=<font class="stringliteral">"unmarshal"</font>;
00273         <a class="code" href="a00077.html">Time</a> eventTime;
00274         eventTime&lt;&lt;=memstr;
00275         any&lt;&lt;=memstr;
00276 
00277         <font class="keywordflow">if</font>(offsetTime.<a class="code" href="a00077.html#a11">is_nil</a>()) <font class="comment">// first time special.</font>
00278            offsetTime=<a class="code" href="a00077.html#d0">Time::current</a>()-eventTime;
00279         <a class="code" href="a00077.html#d1">Time::sleepUntil</a>(eventTime+offsetTime);
00280 
00281         action=<font class="stringliteral">"push"</font>;
00282         proxy_consumer-&gt;push(any);
00283       }
00284     }
00285   }
00286 <font class="keyword">private</font>:
<a name="l00287"></a><a class="code" href="a00075.html#o0">00287</a>   <font class="keywordtype">bool</font> <a class="code" href="a00075.html#o0">_connected</a>;
00288 };
00289 
00290 
00291 <font class="comment">//</font>
00292 <font class="comment">// main()</font>
00293 <font class="comment">//</font>
00294 
<a name="l00295"></a><a class="code" href="a00099.html#a5">00295</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)
00296 {
00297   <font class="comment">//</font>
00298   <font class="comment">// Start orb.</font>
00299 <font class="preprocessor">#if defined(HAVE_OMNIORB4)</font>
00300 <font class="preprocessor"></font>  <a class="code" href="a00099.html#a3">orb</a>=CORBA::ORB_init(argc,argv,<font class="stringliteral">"omniORB4"</font>);
00301 <font class="preprocessor">#else</font>
00302 <font class="preprocessor"></font>  <a class="code" href="a00099.html#a3">orb</a>=CORBA::ORB_init(argc,argv,<font class="stringliteral">"omniORB3"</font>);
00303 <font class="preprocessor">#endif</font>
00304 <font class="preprocessor"></font>
00305   <font class="comment">// Process Options</font>
00306   <font class="keywordtype">bool</font> supplierMode =<font class="keyword">false</font>;
00307   <font class="keyword">const</font> <font class="keywordtype">char</font>* channelName =<font class="stringliteral">"EventChannel"</font>;
00308 
00309   <font class="keywordtype">int</font> c;
00310   <font class="keywordflow">while</font> ((c = <a class="code" href="a00103.html#a5">getopt</a>(argc,argv,<font class="stringliteral">"shn:"</font>)) != EOF)
00311   {
00312      <font class="keywordflow">switch</font> (c)
00313      {
00314         <font class="keywordflow">case</font> <font class="charliteral">'s'</font>: supplierMode=<font class="keyword">true</font>;
00315                   <font class="keywordflow">break</font>;
00316 
00317         <font class="keywordflow">case</font> <font class="charliteral">'n'</font>: channelName = optarg;
00318                   <font class="keywordflow">break</font>;
00319 
00320         <font class="keywordflow">case</font> <font class="charliteral">'h'</font>: <a class="code" href="a00131.html#a0">usage</a>(argc,argv);
00321                   exit(0);
00322         <font class="keywordflow">default</font> : <a class="code" href="a00131.html#a0">usage</a>(argc,argv);
00323                   exit(-1);
00324      }
00325   }
00326 
00327 <font class="preprocessor">#if defined(HAVE_SIGNAL_H) &amp;&amp; defined(SIGPIPE)</font>
00328 <font class="preprocessor"></font>  <font class="comment">// Ignore broken pipes</font>
00329   signal(SIGPIPE, SIG_IGN);
00330 <font class="preprocessor">#endif</font>
00331 <font class="preprocessor"></font>
00332   <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>
00333   <font class="keywordflow">try</font> {
00334     CORBA::Object_var obj;
00335 
00336     action=<font class="stringliteral">"resolve initial reference 'RootPOA'"</font>;
00337     obj=<a class="code" href="a00099.html#a3">orb</a>-&gt;resolve_initial_references(<font class="stringliteral">"RootPOA"</font>);
00338     PortableServer::POA_var rootPoa =PortableServer::POA::_narrow(obj);
00339     <font class="keywordflow">if</font>(CORBA::is_nil(rootPoa))
00340         <font class="keywordflow">throw</font> CORBA::OBJECT_NOT_EXIST();
00341 
00342     action=<font class="stringliteral">"activate the RootPOA's POAManager"</font>;
00343     PortableServer::POAManager_var pman =rootPoa-&gt;the_POAManager();
00344     pman-&gt;activate();
00345 
00346     <font class="comment">//</font>
00347     <font class="comment">// Obtain object reference to EventChannel</font>
00348     <font class="comment">// (from command-line argument or from the Naming Service).</font>
00349     <font class="keywordflow">if</font>(optind&lt;argc)
00350     {
00351       action=<font class="stringliteral">"convert URI from command line into object reference"</font>;
00352       obj=<a class="code" href="a00099.html#a3">orb</a>-&gt;string_to_object(argv[optind]);
00353     }
00354     <font class="keywordflow">else</font>
00355     {
00356       action=<font class="stringliteral">"resolve initial reference 'NameService'"</font>;
00357       obj=<a class="code" href="a00099.html#a3">orb</a>-&gt;resolve_initial_references(<font class="stringliteral">"NameService"</font>);
00358       CosNaming::NamingContext_var rootContext=
00359         CosNaming::NamingContext::_narrow(obj);
00360       <font class="keywordflow">if</font>(CORBA::is_nil(rootContext))
00361           <font class="keywordflow">throw</font> CORBA::OBJECT_NOT_EXIST();
00362 
00363       action=<font class="stringliteral">"find EventChannel in NameService"</font>;
00364       cout &lt;&lt; action &lt;&lt; endl;
00365       obj=rootContext-&gt;resolve(<a class="code" href="a00108.html#a1">str2name</a>(channelName));
00366     }
00367 
00368     action=<font class="stringliteral">"narrow object reference to event channel"</font>;
00369     CosEventChannelAdmin::EventChannel_var channel =
00370       CosEventChannelAdmin::EventChannel::_narrow(obj);
00371     <font class="keywordflow">if</font>(CORBA::is_nil(channel))
00372     {
00373        cerr &lt;&lt; <font class="stringliteral">"Failed to narrow Event Channel reference."</font> &lt;&lt; endl;
00374        exit(1);
00375     }
00376 
00377     <font class="keywordflow">if</font>(supplierMode)
00378     {
00379       action=<font class="stringliteral">"construct PushSupplier"</font>;
00380       <a class="code" href="a00075.html">Supplier_i</a>* supplier =<font class="keyword">new</font> <a class="code" href="a00075.html">Supplier_i</a>();
00381       supplier-&gt;<a class="code" href="a00075.html#a2">supply</a>(channel,action);
00382     }
00383     <font class="keywordflow">else</font>
00384     {
00385       action=<font class="stringliteral">"construct PushConsumer"</font>;
00386       <a class="code" href="a00042.html">Consumer_i</a>* consumer =<font class="keyword">new</font> <a class="code" href="a00042.html">Consumer_i</a>();
00387       consumer-&gt;<a class="code" href="a00042.html#a3">consume</a>(channel,action);
00388 
00389       action=<font class="stringliteral">"run ORB"</font>;
00390       <a class="code" href="a00099.html#a3">orb</a>-&gt;run();
00391     }
00392 
00393     <font class="keywordflow">return</font> 0;
00394 
00395   }
00396   <font class="keywordflow">catch</font>(CORBA::ORB::InvalidName&amp; ex) { <font class="comment">// resolve_initial_references</font>
00397      cerr&lt;&lt;<font class="stringliteral">"Failed to "</font>&lt;&lt;action&lt;&lt;<font class="stringliteral">". ORB::InvalidName"</font>&lt;&lt;endl;
00398   }
00399   <font class="keywordflow">catch</font>(CosNaming::NamingContext::InvalidName&amp; ex) { <font class="comment">// resolve</font>
00400      cerr&lt;&lt;<font class="stringliteral">"Failed to "</font>&lt;&lt;action&lt;&lt;<font class="stringliteral">". NamingContext::InvalidName"</font>&lt;&lt;endl;
00401   }
00402   <font class="keywordflow">catch</font>(CosNaming::NamingContext::NotFound&amp; ex) { <font class="comment">// resolve</font>
00403      cerr&lt;&lt;<font class="stringliteral">"Failed to "</font>&lt;&lt;action&lt;&lt;<font class="stringliteral">". NamingContext::NotFound"</font>&lt;&lt;endl;
00404   }
00405   <font class="keywordflow">catch</font>(CosNaming::NamingContext::CannotProceed&amp; ex) { <font class="comment">// resolve</font>
00406      cerr&lt;&lt;<font class="stringliteral">"Failed to "</font>&lt;&lt;action&lt;&lt;<font class="stringliteral">". NamingContext::CannotProceed"</font>&lt;&lt;endl;
00407   }
00408   <font class="keywordflow">catch</font>(CORBA::TRANSIENT&amp; ex) { <font class="comment">// _narrow()</font>
00409      cerr&lt;&lt;<font class="stringliteral">"Failed to "</font>&lt;&lt;action&lt;&lt;<font class="stringliteral">". TRANSIENT"</font>&lt;&lt;endl;
00410   }
00411   <font class="keywordflow">catch</font>(CORBA::OBJECT_NOT_EXIST&amp; ex) { <font class="comment">// _narrow()</font>
00412      cerr&lt;&lt;<font class="stringliteral">"Failed to "</font>&lt;&lt;action&lt;&lt;<font class="stringliteral">". OBJECT_NOT_EXIST"</font>&lt;&lt;endl;
00413   }
00414   <font class="keywordflow">catch</font>(CORBA::SystemException&amp; ex) {
00415      cerr&lt;&lt;<font class="stringliteral">"Failed to "</font>&lt;&lt;action&lt;&lt;<font class="stringliteral">"."</font>
00416 <font class="preprocessor">#if defined(HAVE_OMNIORB4)</font>
00417 <font class="preprocessor"></font>       <font class="stringliteral">" "</font>&lt;&lt;ex._name()&lt;&lt;<font class="stringliteral">" ("</font>&lt;&lt;ex.NP_minorString()&lt;&lt;<font class="stringliteral">")"</font>
00418 <font class="preprocessor">#endif</font>
00419 <font class="preprocessor"></font>       &lt;&lt;endl;
00420   }
00421   <font class="keywordflow">catch</font>(CORBA::Exception&amp; ex) {
00422      cerr&lt;&lt;<font class="stringliteral">"Failed to "</font>&lt;&lt;action&lt;&lt;<font class="stringliteral">"."</font>
00423 <font class="preprocessor">#if defined(HAVE_OMNIORB4)</font>
00424 <font class="preprocessor"></font>       <font class="stringliteral">" "</font>&lt;&lt;ex._name()
00425 <font class="preprocessor">#endif</font>
00426 <font class="preprocessor"></font>       &lt;&lt;endl;
00427   }
00428 
00429   <font class="keywordflow">return</font> 1;
00430 }
00431 
<a name="l00432"></a><a class="code" href="a00099.html#a4">00432</a> <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)
00433 {
00434   cerr&lt;&lt;
00435 <font class="stringliteral">"\nStream events from a channel to stdout, or (-s) from stdin to a channel.\n"</font>
00436 <font class="stringliteral">"syntax: "</font>&lt;&lt;(argc?argv[0]:<font class="stringliteral">"events"</font>)&lt;&lt;<font class="stringliteral">" OPTIONS [CHANNEL_URI]\n"</font>
00437 <font class="stringliteral">"\n"</font>
00438 <font class="stringliteral">"CHANNEL_URI: The event channel may be specified as a URI.\n"</font>
00439 <font class="stringliteral">" This may be an IOR, or a corbaloc::: or corbaname::: URI.\n"</font>
00440 <font class="stringliteral">"\n"</font>
00441 <font class="stringliteral">"OPTIONS:                                         DEFAULT:\n"</font>
00442 <font class="stringliteral">" -s       supply mode. Read events from stdin.\n"</font>
00443 <font class="stringliteral">" -n NAME  channel name (if URI is not specified)  [\"EventChannel\"]\n"</font>
00444 <font class="stringliteral">" -h       display this help text\n"</font> &lt;&lt; endl;
00445 }
</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>