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
|
<!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>rmeventc.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>rmeventc.cc</h1><a href="a00132.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001 <font class="comment">// Package : omniEvents</font>
00002 <font class="comment">// rmeventc.cc Created : 2003/12/21</font>
00003 <font class="comment">// Author : Alex Tingle</font>
00004 <font class="comment">//</font>
00005 <font class="comment">// Copyright (C) 2003 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 <unistd.h></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 <stdlib.h></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 <iostream></font>
00045 <font class="preprocessor">#else</font>
00046 <font class="preprocessor"></font><font class="preprocessor"># include <iostream.h></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 <font class="preprocessor">#include "<a class="code" href="a00109.html">naming.h</a>"</font>
00055
00056 <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);
00057
00058 <font class="keywordtype">int</font>
<a name="l00059"></a><a class="code" href="a00132.html#a1">00059</a> <a class="code" href="a00131.html#a1">main</a>(<font class="keywordtype">int</font> argc, <font class="keywordtype">char</font> **argv)
00060 {
00061 <font class="keywordtype">int</font> result =1;
00062
00063 <font class="comment">//</font>
00064 <font class="comment">// Start orb.</font>
00065 <font class="preprocessor">#if defined(HAVE_OMNIORB4)</font>
00066 <font class="preprocessor"></font> CORBA::ORB_ptr orb = CORBA::ORB_init(argc,argv,<font class="stringliteral">"omniORB4"</font>);
00067 <font class="preprocessor">#else</font>
00068 <font class="preprocessor"></font> CORBA::ORB_ptr orb = CORBA::ORB_init(argc,argv,<font class="stringliteral">"omniORB3"</font>);
00069 <font class="preprocessor">#endif</font>
00070 <font class="preprocessor"></font>
00071 <font class="comment">// Process Options</font>
00072 <font class="keywordtype">int</font> c;
00073
00074 CosNaming::Name ecName =<a class="code" href="a00108.html#a1">str2name</a>(<font class="stringliteral">"EventChannel"</font>);
00075
00076 <font class="keywordflow">while</font> ((c = <a class="code" href="a00103.html#a5">getopt</a>(argc,argv,<font class="stringliteral">"n:h"</font>)) != EOF)
00077 {
00078 <font class="keywordflow">switch</font> (c)
00079 {
00080 <font class="keywordflow">case</font> <font class="charliteral">'n'</font>: ecName=<a class="code" href="a00108.html#a1">str2name</a>(optarg);
00081 <font class="keywordflow">break</font>;
00082
00083 <font class="keywordflow">case</font> <font class="charliteral">'h'</font>: <a class="code" href="a00131.html#a0">usage</a>(argc,argv);
00084 exit(0);
00085
00086 <font class="keywordflow">default</font> : <a class="code" href="a00131.html#a0">usage</a>(argc,argv);
00087 exit(-1);
00088 }
00089 }
00090
00091 <font class="comment">//</font>
00092 <font class="comment">// Use one big try...catch block.</font>
00093 <font class="comment">// 'action' variable keeps track of what we're doing.</font>
00094 <font class="keyword">const</font> <font class="keywordtype">char</font>* action =<font class="stringliteral">"start"</font>;
00095 <font class="keywordflow">try</font>
00096 {
00097 CORBA::Object_var obj;
00098
00099 <font class="comment">//</font>
00100 <font class="comment">// Obtain object reference to EventChannel</font>
00101 <font class="comment">// (from command-line argument or from the Naming Service).</font>
00102 <font class="keywordflow">if</font>(optind<argc)
00103 {
00104 action=<font class="stringliteral">"convert URI from command line into object reference"</font>;
00105 obj=orb->string_to_object(argv[optind]);
00106 }
00107 <font class="keywordflow">else</font>
00108 {
00109 <font class="comment">//</font>
00110 <font class="comment">// Get Name Service root context.</font>
00111 action=<font class="stringliteral">"resolve initial reference 'NameService'"</font>;
00112 obj=orb->resolve_initial_references(<font class="stringliteral">"NameService"</font>);
00113 CosNaming::NamingContext_var rootContext=
00114 CosNaming::NamingContext::_narrow(obj);
00115 <font class="keywordflow">if</font>(CORBA::is_nil(rootContext))
00116 <font class="keywordflow">throw</font> CORBA::OBJECT_NOT_EXIST();
00117
00118 <font class="comment">//</font>
00119 <font class="comment">// Obtain reference to the Event Channel.</font>
00120 action=<font class="stringliteral">"find Event Channel in naming service"</font>;
00121 obj=rootContext->resolve(ecName);
00122
00123 <font class="comment">//</font>
00124 <font class="comment">// Unbind the Channel's reference in the naming service.</font>
00125 action=<font class="stringliteral">"unbind Event Channel from naming service"</font>;
00126 rootContext->unbind(ecName);
00127 }
00128
00129 action=<font class="stringliteral">"narrow object reference to event channel"</font>;
00130 CosEventChannelAdmin::EventChannel_var channel =
00131 CosEventChannelAdmin::EventChannel::_narrow(obj);
00132 <font class="keywordflow">if</font>(CORBA::is_nil(channel))
00133 <font class="keywordflow">throw</font> CORBA::OBJECT_NOT_EXIST();
00134
00135 <font class="comment">//</font>
00136 <font class="comment">// Destroy the EventChannel.</font>
00137 action=<font class="stringliteral">"destroy Event Channel"</font>;
00138 channel->destroy();
00139
00140 <font class="comment">//</font>
00141 <font class="comment">// If we get here, then everything has worked OK.</font>
00142 result=0;
00143
00144 }
00145 <font class="keywordflow">catch</font>(CORBA::ORB::InvalidName& ex) { <font class="comment">// resolve_initial_references</font>
00146 cerr<<<font class="stringliteral">"Failed to "</font><<action<<<font class="stringliteral">". ORB::InvalidName"</font><<endl;
00147 }
00148 <font class="keywordflow">catch</font>(CosNaming::NamingContext::InvalidName& ex) { <font class="comment">// resolve</font>
00149 cerr<<<font class="stringliteral">"Failed to "</font><<action<<<font class="stringliteral">". NamingContext::InvalidName"</font><<endl;
00150 }
00151 <font class="keywordflow">catch</font>(CosNaming::NamingContext::NotFound& ex) { <font class="comment">// resolve</font>
00152 cerr<<<font class="stringliteral">"Failed to "</font><<action<<<font class="stringliteral">". NamingContext::NotFound"</font><<endl;
00153 }
00154 <font class="keywordflow">catch</font>(CosNaming::NamingContext::CannotProceed& ex) { <font class="comment">// resolve</font>
00155 cerr<<<font class="stringliteral">"Failed to "</font><<action<<<font class="stringliteral">". NamingContext::CannotProceed"</font><<endl;
00156 }
00157 <font class="keywordflow">catch</font>(CORBA::TRANSIENT& ex) { <font class="comment">// _narrow()</font>
00158 cerr<<<font class="stringliteral">"Failed to "</font><<action<<<font class="stringliteral">". TRANSIENT"</font><<endl;
00159 }
00160 <font class="keywordflow">catch</font>(CORBA::OBJECT_NOT_EXIST& ex) { <font class="comment">// _narrow()</font>
00161 cerr<<<font class="stringliteral">"Failed to "</font><<action<<<font class="stringliteral">". OBJECT_NOT_EXIST"</font><<endl;
00162 }
00163 <font class="keywordflow">catch</font>(CORBA::SystemException& ex) {
00164 cerr<<<font class="stringliteral">"Failed to "</font><<action<<<font class="stringliteral">"."</font>;
00165 <font class="preprocessor">#if defined(HAVE_OMNIORB4)</font>
00166 <font class="preprocessor"></font> cerr<<<font class="stringliteral">" "</font><<ex._name();
00167 <font class="keywordflow">if</font>(ex.NP_minorString())
00168 cerr<<<font class="stringliteral">" ("</font><<ex.NP_minorString()<<<font class="stringliteral">")"</font>;
00169 <font class="preprocessor">#endif</font>
00170 <font class="preprocessor"></font> cerr<<endl;
00171 }
00172 <font class="keywordflow">catch</font>(CORBA::Exception& ex) {
00173 cerr<<<font class="stringliteral">"Failed to "</font><<action<<<font class="stringliteral">"."</font>
00174 <font class="preprocessor">#if defined(HAVE_OMNIORB4)</font>
00175 <font class="preprocessor"></font> <font class="stringliteral">" "</font><<ex._name()
00176 <font class="preprocessor">#endif</font>
00177 <font class="preprocessor"></font> <<endl;
00178 }
00179
00180 <font class="keywordflow">return</font> result;
00181 }
00182
00183 <font class="keyword">static</font> <font class="keywordtype">void</font>
<a name="l00184"></a><a class="code" href="a00132.html#a0">00184</a> <a class="code" href="a00131.html#a0">usage</a>(<font class="keywordtype">int</font> argc, <font class="keywordtype">char</font> **argv)
00185 {
00186 cerr<<
00187 <font class="stringliteral">"\nDestroy an EventChannel.\n"</font>
00188 <font class="stringliteral">"syntax: "</font><<(argc?argv[0]:<font class="stringliteral">"rmeventc"</font>)<<<font class="stringliteral">" OPTIONS [CHANNEL_URI]\n"</font>
00189 <font class="stringliteral">"\n"</font>
00190 <font class="stringliteral">"CHANNEL_URI: The event channel may be specified as a URI.\n"</font>
00191 <font class="stringliteral">" This may be an IOR, or a corbaloc::: or corbaname::: URI.\n"</font>
00192 <font class="stringliteral">"\n"</font>
00193 <font class="stringliteral">"OPTIONS: DEFAULT:\n"</font>
00194 <font class="stringliteral">" -n NAME channel name (if URI is not specified) [\"EventChannel\"]\n"</font>
00195 <font class="stringliteral">" -h display this help text\n"</font> << endl;
00196 }
00197
</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>
|