OmniEvents
rmeventc.cc
Go to the documentation of this file.
1// Package : omniEvents
2// rmeventc.cc Created : 2003/12/21
3// Author : Alex Tingle
4//
5// Copyright (C) 2003 Alex Tingle
6//
7// This file is part of the omniEvents application.
8//
9// omniEvents is free software; you can redistribute it and/or
10// modify it under the terms of the GNU Lesser General Public
11// License as published by the Free Software Foundation; either
12// version 2.1 of the License, or (at your option) any later version.
13//
14// omniEvents is distributed in the hope that it will be useful,
15// but WITHOUT ANY WARRANTY; without even the implied warranty of
16// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17// Lesser General Public License for more details.
18//
19// You should have received a copy of the GNU Lesser General Public
20// License along with this library; if not, write to the Free Software
21// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22//
23// Description:
24// Destroys the named EventChannel.
25//
26
27#ifdef HAVE_CONFIG_H
28# include "config.h"
29#endif
30
31#ifdef HAVE_GETOPT
32# include <unistd.h>
33extern char* optarg;
34extern int optind;
35#else
36# include "getopt.h"
37#endif
38
39#ifdef HAVE_STDLIB_H
40# include <stdlib.h> // exit()
41#endif
42
43#ifdef HAVE_IOSTREAM
44# include <iostream>
45#else
46# include <iostream.h>
47#endif
48
49#include <cstdio>
50
51#ifdef HAVE_STD_IOSTREAM
52using namespace std;
53#endif
54
55#include "CosEventChannelAdmin.hh"
56#include "naming.h"
57
58static void usage(int argc, char **argv);
59
60int
61main(int argc, char **argv)
62{
63 int result =1;
64
65 //
66 // Start orb.
67#if defined(HAVE_OMNIORB4)
68 CORBA::ORB_ptr orb = CORBA::ORB_init(argc,argv,"omniORB4");
69#else
70 CORBA::ORB_ptr orb = CORBA::ORB_init(argc,argv,"omniORB3");
71#endif
72
73 // Process Options
74 int c;
75
76 CosNaming::Name ecName =str2name("EventChannel");
77
78 while ((c = getopt(argc,argv,"n:h")) != EOF)
79 {
80 switch (c)
81 {
82 case 'n': ecName=str2name(optarg);
83 break;
84
85 case 'h': usage(argc,argv);
86 exit(0);
87
88 default : usage(argc,argv);
89 exit(-1);
90 }
91 }
92
93 //
94 // Use one big try...catch block.
95 // 'action' variable keeps track of what we're doing.
96 const char* action ="start";
97 try
98 {
99 CORBA::Object_var obj;
100
101 //
102 // Obtain object reference to EventChannel
103 // (from command-line argument or from the Naming Service).
104 if(optind<argc)
105 {
106 action="convert URI from command line into object reference";
107 obj=orb->string_to_object(argv[optind]);
108 }
109 else
110 {
111 //
112 // Get Name Service root context.
113 action="resolve initial reference 'NameService'";
114 obj=orb->resolve_initial_references("NameService");
115 CosNaming::NamingContext_var rootContext=
116 CosNaming::NamingContext::_narrow(obj);
117 if(CORBA::is_nil(rootContext))
118 throw CORBA::OBJECT_NOT_EXIST();
119
120 //
121 // Obtain reference to the Event Channel.
122 action="find Event Channel in naming service";
123 obj=rootContext->resolve(ecName);
124
125 //
126 // Unbind the Channel's reference in the naming service.
127 action="unbind Event Channel from naming service";
128 rootContext->unbind(ecName);
129 }
130
131 action="narrow object reference to event channel";
132 CosEventChannelAdmin::EventChannel_var channel =
133 CosEventChannelAdmin::EventChannel::_narrow(obj);
134 if(CORBA::is_nil(channel))
135 throw CORBA::OBJECT_NOT_EXIST();
136
137 //
138 // Destroy the EventChannel.
139 action="destroy Event Channel";
140 channel->destroy();
141
142 //
143 // Clean up nicely.
144 action="destroy orb";
145 orb->destroy();
146
147 //
148 // If we get here, then everything has worked OK.
149 result=0;
150
151 }
152 catch(CORBA::ORB::InvalidName& ex) { // resolve_initial_references
153 cerr<<"Failed to "<<action<<". ORB::InvalidName"<<endl;
154 }
155 catch(CosNaming::NamingContext::InvalidName& ex) { // resolve
156 cerr<<"Failed to "<<action<<". NamingContext::InvalidName"<<endl;
157 }
158 catch(CosNaming::NamingContext::NotFound& ex) { // resolve
159 cerr<<"Failed to "<<action<<". NamingContext::NotFound"<<endl;
160 }
161 catch(CosNaming::NamingContext::CannotProceed& ex) { // resolve
162 cerr<<"Failed to "<<action<<". NamingContext::CannotProceed"<<endl;
163 }
164 catch(CORBA::TRANSIENT& ex) { // _narrow()
165 cerr<<"Failed to "<<action<<". TRANSIENT"<<endl;
166 }
167 catch(CORBA::OBJECT_NOT_EXIST& ex) { // _narrow()
168 cerr<<"Failed to "<<action<<". OBJECT_NOT_EXIST"<<endl;
169 }
170 catch(CORBA::SystemException& ex) {
171 cerr<<"Failed to "<<action<<".";
172#if defined(HAVE_OMNIORB4)
173 cerr<<" "<<ex._name();
174 if(ex.NP_minorString())
175 cerr<<" ("<<ex.NP_minorString()<<")";
176#endif
177 cerr<<endl;
178 }
179 catch(CORBA::Exception& ex) {
180 cerr<<"Failed to "<<action<<"."
181#if defined(HAVE_OMNIORB4)
182 " "<<ex._name()
183#endif
184 <<endl;
185 }
186
187 return result;
188}
189
190static void
191usage(int argc, char **argv)
192{
193 cerr<<
194"\nDestroy an EventChannel.\n"
195"syntax: "<<(argc?argv[0]:"rmeventc")<<" OPTIONS [CHANNEL_URI]\n"
196"\n"
197"CHANNEL_URI: The event channel may be specified as a URI.\n"
198" This may be an IOR, or a corbaloc::: or corbaname::: URI.\n"
199"\n"
200"OPTIONS: DEFAULT:\n"
201" -n NAME channel name (if URI is not specified) [\"EventChannel\"]\n"
202" -h display this help text\n" << endl;
203}
204
CosNaming::Name str2name(const char *namestr)
Converts stringified name to naming service name.
Definition naming.cc:117
int optind
Definition getopt.cc:82
char * optarg
Definition getopt.cc:83
int getopt(int argc, char *argv[], const char *optionS)
Definition getopt.cc:88
int main(int argc, char **argv)
The main process entry point.
Definition rmeventc.cc:61
static void usage(int argc, char **argv)
Definition rmeventc.cc:191
CORBA::ORB_ptr orb
Definition eventf.cc:60