File: a00156.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 (206 lines) | stat: -rw-r--r-- 13,726 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
<!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>eventf.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>eventf.cc</h1><a href="a00096.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001 <font class="comment">//                            Package   : omniEvents</font>
00002 <font class="comment">// eventf.cc                  Created   : 2004-05-30</font>
00003 <font class="comment">//                            Author    : Alex Tingle</font>
00004 <font class="comment">//</font>
00005 <font class="comment">//    Copyright (C) 2004 Alex Tingle</font>
00006 <font class="comment">//</font>
00007 <font class="comment">//    This file is part of the omniEvents application.</font>
00008 <font class="comment">//</font>
00009 <font class="comment">//    omniEvents is free software; you can redistribute it and/or</font>
00010 <font class="comment">//    modify it under the terms of the GNU Lesser General Public</font>
00011 <font class="comment">//    License as published by the Free Software Foundation; either</font>
00012 <font class="comment">//    version 2.1 of the License, or (at your option) any later version.</font>
00013 <font class="comment">//</font>
00014 <font class="comment">//    omniEvents is distributed in the hope that it will be useful,</font>
00015 <font class="comment">//    but WITHOUT ANY WARRANTY; without even the implied warranty of</font>
00016 <font class="comment">//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU</font>
00017 <font class="comment">//    Lesser General Public License for more details.</font>
00018 <font class="comment">//</font>
00019 <font class="comment">//    You should have received a copy of the GNU Lesser General Public</font>
00020 <font class="comment">//    License along with this library; if not, write to the Free Software</font>
00021 <font class="comment">//    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</font>
00022 <font class="comment">//</font>
00023 <font class="comment">// Description:</font>
00024 <font class="comment">//    Destroys the named EventChannel.</font>
00025 <font class="comment">//      </font>
00026 
00027 <font class="preprocessor">#ifdef HAVE_CONFIG_H</font>
00028 <font class="preprocessor"></font><font class="preprocessor">#  include "<a class="code" href="a00082.html">config.h</a>"</font>
00029 <font class="preprocessor">#endif</font>
00030 <font class="preprocessor"></font>
00031 <font class="preprocessor">#ifdef HAVE_GETOPT</font>
00032 <font class="preprocessor"></font><font class="preprocessor">#  include &lt;unistd.h&gt;</font>
00033 <font class="keyword">extern</font> <font class="keywordtype">char</font>* optarg;
00034 <font class="keyword">extern</font> <font class="keywordtype">int</font> optind;
00035 <font class="preprocessor">#else</font>
00036 <font class="preprocessor"></font><font class="preprocessor">#  include "<a class="code" href="a00104.html">getopt.h</a>"</font>
00037 <font class="preprocessor">#endif</font>
00038 <font class="preprocessor"></font>
00039 <font class="preprocessor">#ifdef HAVE_STDLIB_H</font>
00040 <font class="preprocessor"></font><font class="preprocessor">#  include &lt;stdlib.h&gt;</font> <font class="comment">// exit()</font>
00041 <font class="preprocessor">#endif</font>
00042 <font class="preprocessor"></font>
00043 <font class="preprocessor">#ifdef HAVE_IOSTREAM</font>
00044 <font class="preprocessor"></font><font class="preprocessor">#  include &lt;iostream&gt;</font>
00045 <font class="preprocessor">#else</font>
00046 <font class="preprocessor"></font><font class="preprocessor">#  include &lt;iostream.h&gt;</font>
00047 <font class="preprocessor">#endif</font>
00048 <font class="preprocessor"></font>
00049 <font class="preprocessor">#ifdef HAVE_STD_IOSTREAM</font>
00050 <font class="preprocessor"></font><font class="keyword">using</font> <font class="keyword">namespace </font>std;
00051 <font class="preprocessor">#endif</font>
00052 <font class="preprocessor"></font>
00053 <font class="preprocessor">#include "CosEventChannelAdmin.hh"</font>
00054 
00055 <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);
00056 <font class="keyword">static</font> CosEventChannelAdmin::EventChannel_ptr <a class="code" href="a00096.html#a2">getChannel</a>(<font class="keyword">const</font> <font class="keywordtype">char</font>* sior);
00057 
<a name="l00058"></a><a class="code" href="a00096.html#a0">00058</a> CORBA::ORB_ptr <a class="code" href="a00096.html#a0">orb</a>;
00059 
00060 <font class="keywordtype">int</font>
<a name="l00061"></a><a class="code" href="a00096.html#a3">00061</a> <a class="code" href="a00131.html#a1">main</a>(<font class="keywordtype">int</font> argc, <font class="keywordtype">char</font> **argv)
00062 {
00063   <font class="keywordtype">int</font> result =1;
00064 
00065   <font class="comment">//</font>
00066   <font class="comment">// Start orb.</font>
00067 <font class="preprocessor">#if defined(HAVE_OMNIORB4)</font>
00068 <font class="preprocessor"></font>  <a class="code" href="a00096.html#a0">orb</a>=CORBA::ORB_init(argc,argv,<font class="stringliteral">"omniORB4"</font>);
00069 <font class="preprocessor">#else</font>
00070 <font class="preprocessor"></font>  <a class="code" href="a00096.html#a0">orb</a>=CORBA::ORB_init(argc,argv,<font class="stringliteral">"omniORB3"</font>);
00071 <font class="preprocessor">#endif</font>
00072 <font class="preprocessor"></font>
00073   <font class="comment">// Process Options</font>
00074   <font class="keywordtype">int</font> c;
00075 
00076   <font class="keywordflow">while</font>((c = <a class="code" href="a00103.html#a5">getopt</a>(argc,argv,<font class="stringliteral">"h"</font>)) != EOF)
00077   {
00078     <font class="keywordflow">switch</font> (c)
00079     {
00080       <font class="keywordflow">case</font> <font class="charliteral">'h'</font>: <a class="code" href="a00131.html#a0">usage</a>(argc,argv);
00081                 exit(0);
00082 
00083       <font class="keywordflow">default</font> : <a class="code" href="a00131.html#a0">usage</a>(argc,argv);
00084                 exit(-1);
00085     }
00086   }
00087 
00088   <font class="keywordflow">if</font>(optind!=argc-2)
00089   {
00090     <a class="code" href="a00131.html#a0">usage</a>(argc,argv);
00091     exit(-1);
00092   }
00093 
00094   <font class="comment">//</font>
00095   <font class="comment">// Use one big try...catch block.</font>
00096   <font class="comment">// 'action' variable keeps track of what we're doing.</font>
00097   <font class="keyword">const</font> <font class="keywordtype">char</font>* action =<font class="stringliteral">"start"</font>;
00098   <font class="keywordflow">try</font>
00099   {
00100     <font class="keyword">using</font> <font class="keyword">namespace </font>CosEventChannelAdmin;
00101 
00102     action=<font class="stringliteral">"convert URI into reference to source channel"</font>;
00103     EventChannel_var from_channel =<a class="code" href="a00096.html#a2">getChannel</a>(argv[optind]);
00104 
00105     action=<font class="stringliteral">"convert URI into reference to destination channel"</font>;
00106     EventChannel_var to_channel   =<a class="code" href="a00096.html#a2">getChannel</a>(argv[optind+1]);
00107 
00108     action=<font class="stringliteral">"obtain ConsumerAdmin"</font>;
00109     ConsumerAdmin_var cadmin =from_channel-&gt;for_consumers();
00110 
00111     action=<font class="stringliteral">"obtain ProxyPushSupplier"</font>;
00112     ProxyPushSupplier_var supplier =cadmin-&gt;obtain_push_supplier();
00113 
00114     action=<font class="stringliteral">"obtain SupplierAdmin"</font>;
00115     SupplierAdmin_var sadmin =to_channel-&gt;for_suppliers();
00116 
00117     action=<font class="stringliteral">"obtain ProxyPushConsumer"</font>;
00118     ProxyPushConsumer_var consumer =sadmin-&gt;obtain_push_consumer();
00119 
00120     action=<font class="stringliteral">"connect PushConsumer"</font>;
00121     consumer-&gt;connect_push_supplier(supplier.in());
00122 
00123     action=<font class="stringliteral">"connect PushSupplier"</font>;
00124     supplier-&gt;connect_push_consumer(consumer.in());
00125 
00126     <font class="comment">//</font>
00127     <font class="comment">// Clean up.</font>
00128     <a class="code" href="a00096.html#a0">orb</a>-&gt;destroy();
00129     
00130     <font class="comment">//</font>
00131     <font class="comment">// If we get here, then everything has worked OK.</font>
00132     result=0;
00133 
00134   }
00135   <font class="keywordflow">catch</font>(CORBA::TRANSIENT&amp; ex) { <font class="comment">// _narrow()</font>
00136      cerr&lt;&lt;<font class="stringliteral">"Failed to "</font>&lt;&lt;action&lt;&lt;<font class="stringliteral">". TRANSIENT"</font>&lt;&lt;endl;
00137   }
00138   <font class="keywordflow">catch</font>(CORBA::OBJECT_NOT_EXIST&amp; ex) { <font class="comment">// _narrow()</font>
00139      cerr&lt;&lt;<font class="stringliteral">"Failed to "</font>&lt;&lt;action&lt;&lt;<font class="stringliteral">". OBJECT_NOT_EXIST"</font>&lt;&lt;endl;
00140   }
00141   <font class="keywordflow">catch</font>(CORBA::SystemException&amp; ex) {
00142      cerr&lt;&lt;<font class="stringliteral">"Failed to "</font>&lt;&lt;action&lt;&lt;<font class="stringliteral">"."</font>;
00143 <font class="preprocessor">#if defined(HAVE_OMNIORB4)</font>
00144 <font class="preprocessor"></font>     cerr&lt;&lt;<font class="stringliteral">" "</font>&lt;&lt;ex._name();
00145      <font class="keywordflow">if</font>(ex.NP_minorString())
00146          cerr&lt;&lt;<font class="stringliteral">" ("</font>&lt;&lt;ex.NP_minorString()&lt;&lt;<font class="stringliteral">")"</font>;
00147 <font class="preprocessor">#endif</font>
00148 <font class="preprocessor"></font>     cerr&lt;&lt;endl;
00149   }
00150   <font class="keywordflow">catch</font>(CORBA::Exception&amp; ex) {
00151      cerr&lt;&lt;<font class="stringliteral">"Failed to "</font>&lt;&lt;action&lt;&lt;<font class="stringliteral">"."</font>
00152 <font class="preprocessor">#if defined(HAVE_OMNIORB4)</font>
00153 <font class="preprocessor"></font>       <font class="stringliteral">" "</font>&lt;&lt;ex._name()
00154 <font class="preprocessor">#endif</font>
00155 <font class="preprocessor"></font>       &lt;&lt;endl;
00156   }
00157 
00158   <font class="keywordflow">return</font> result;
00159 }
00160 
00161 
00162 <font class="keyword">static</font> <font class="keywordtype">void</font>
<a name="l00163"></a><a class="code" href="a00096.html#a1">00163</a> <a class="code" href="a00131.html#a0">usage</a>(<font class="keywordtype">int</font> argc, <font class="keywordtype">char</font> **argv)
00164 {
00165   cerr&lt;&lt;
00166 <font class="stringliteral">"\nConnect (federate) two event channels.\n"</font>
00167 <font class="stringliteral">"syntax: "</font>&lt;&lt;(argc?argv[0]:<font class="stringliteral">"eventf"</font>)&lt;&lt;<font class="stringliteral">" OPTIONS [FROM_CHANNEL] [TO_CHANNEL]\n"</font>
00168 <font class="stringliteral">"\n"</font>
00169 <font class="stringliteral">"FROM/TO_CHANNEL: The event channels must be specified as a URI.\n"</font>
00170 <font class="stringliteral">" This may be an IOR, or a corbaloc::: or corbaname::: URI.\n"</font>
00171 <font class="stringliteral">"\n"</font>
00172 <font class="stringliteral">"OPTIONS:\n"</font>
00173 <font class="stringliteral">" -h  display this help text\n"</font> &lt;&lt; endl;
00174 }
00175 
00176 
00177 <font class="comment">//</font>
00178 <font class="comment">// Obtain object reference to EventChannel</font>
00179 <font class="keyword">static</font> CosEventChannelAdmin::EventChannel_ptr
<a name="l00180"></a><a class="code" href="a00096.html#a2">00180</a> <a class="code" href="a00096.html#a2">getChannel</a>(<font class="keyword">const</font> <font class="keywordtype">char</font>* sior)
00181 {
00182   <font class="comment">// convert URI from command line into object reference";</font>
00183   CORBA::Object_var obj =<a class="code" href="a00096.html#a0">orb</a>-&gt;string_to_object(sior);
00184 
00185   <font class="comment">// narrow object reference to event channel";</font>
00186   CosEventChannelAdmin::EventChannel_var channel =
00187     CosEventChannelAdmin::EventChannel::_narrow(obj);
00188   <font class="keywordflow">if</font>(CORBA::is_nil(channel))
00189       <font class="keywordflow">throw</font> CORBA::OBJECT_NOT_EXIST();
00190   
00191   <font class="keywordflow">return</font> channel._retn();
00192 }
</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>