00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096 #ifdef HAVE_CONFIG_H
00097 # include "config.h"
00098 #endif
00099
00100 #ifdef HAVE_GETOPT
00101 # include <unistd.h>
00102 extern char* optarg;
00103 extern int optind;
00104 #else
00105 # include "getopt.h"
00106 #endif
00107
00108 #ifdef HAVE_IOSTREAM
00109 # include <iostream>
00110 #else
00111 # include <iostream.h>
00112 #endif
00113
00114 #ifdef HAVE_STD_IOSTREAM
00115 using namespace std;
00116 #endif
00117
00118 #ifdef HAVE_STDLIB_H
00119 # include <stdlib.h>
00120 #endif
00121
00122 #ifdef HAVE_SIGNAL_H
00123 # include <signal.h>
00124 #endif
00125
00126 #include "naming.h"
00127
00128 #include "CosEventChannelAdmin.hh"
00129 #include "EventChannelAdmin.hh"
00130
00131 static void usage();
00132
00133 int
00134 main(int argc, char **argv)
00135 {
00136 int result =1;
00137
00138
00139
00140 #if defined(HAVE_OMNIORB4)
00141 CORBA::ORB_ptr orb = CORBA::ORB_init(argc,argv,"omniORB4");
00142 CORBA::BOA_ptr boa = orb->BOA_init(argc,argv,"omniORB4_BOA");
00143 #else
00144 CORBA::ORB_ptr orb = CORBA::ORB_init(argc,argv,"omniORB3");
00145 CORBA::BOA_ptr boa = orb->BOA_init(argc,argv,"omniORB3_BOA");
00146 #endif
00147
00148
00149 int c;
00150 const char* channelName ="EventChannel";
00151 const char* channelKind ="EventChannel";
00152 const char* factoryName ="EventChannelFactory";
00153 const char* factoryKind ="EventChannelFactory";
00154 CORBA::ULong pullRetryPeriod =1;
00155 CORBA::ULong maxQueueLength =0;
00156 CORBA::ULong maxEventsPerConsumer =0;
00157
00158 while ((c = getopt(argc,argv,"n:k:N:K:r:m:q:h")) != EOF)
00159 {
00160 switch (c)
00161 {
00162 case 'n': channelName = optarg;
00163 break;
00164
00165 case 'k': channelKind = optarg;
00166 break;
00167
00168 case 'N': factoryName = optarg;
00169 break;
00170
00171 case 'K': factoryKind = optarg;
00172 break;
00173
00174 case 'r': pullRetryPeriod = atol(optarg);
00175 break;
00176
00177 case 'm': maxEventsPerConsumer = atol(optarg);
00178 break;
00179
00180 case 'q': maxQueueLength = atol(optarg);
00181 break;
00182
00183 case 'h':
00184 default : usage();
00185 exit(-1);
00186 break;
00187 }
00188 }
00189
00190
00191
00192
00193 const char* action ="start";
00194 try
00195 {
00196
00197
00198
00199 action="get NameService initial reference";
00200 CosNaming::NamingContext_ptr rootContext;
00201 rootContext = getRootNamingContext(orb);
00202
00203
00204
00205 action="find Event Channel Factory in naming service";
00206 CosNaming::Name name;
00207 name.length (1);
00208 name[0].id = CORBA::string_dup(factoryName);
00209 name[0].kind = CORBA::string_dup(factoryKind);
00210
00211 CORBA::Object_var obj = rootContext->resolve(name);
00212 EventChannelAdmin::EventChannelFactory_var factory =
00213 EventChannelAdmin::EventChannelFactory::_narrow(obj);
00214 if(CORBA::is_nil(factory))
00215 {
00216 cerr << "Failed to narrow Event Channel Factory reference." << endl;
00217 exit(1);
00218 }
00219
00220
00221 action="check factory supports EventChannel object interface";
00222 CosLifeCycle::Key key;
00223 key.length (1);
00224 key[0].id = CORBA::string_dup("EventChannel");
00225 key[0].kind = CORBA::string_dup("object interface");
00226
00227 if(!factory->supports(key))
00228 {
00229 cerr << "Factory does not support Event Channel Interface ! [\""
00230 << factoryName << "\", \"" << factoryKind << "\"]"
00231 << endl;
00232 exit (1);
00233 }
00234
00235
00236
00237 action="create EventChannel object";
00238
00239
00240 CosLifeCycle::Criteria criteria;
00241 criteria.length(3);
00242 criteria[0].name = CORBA::string_dup ("PullRetryPeriod");
00243 criteria[0].value <<= (CORBA::ULong) pullRetryPeriod;
00244 criteria[1].name = CORBA::string_dup ("MaxEventsPerConsumer");
00245 criteria[1].value <<= (CORBA::ULong) maxEventsPerConsumer;
00246 criteria[2].name = CORBA::string_dup ("MaxQueueLength");
00247 criteria[2].value <<= (CORBA::ULong) maxQueueLength;
00248
00249 CORBA::Object_var channelObj =factory->create_object(key, criteria);
00250 if (CORBA::is_nil(channelObj))
00251 {
00252 cerr << "Channel Factory returned nil reference! [\""
00253 << channelName << "\", \"" << channelKind << "\"]" << endl;
00254 exit(1);
00255 }
00256
00257
00258 CosEventChannelAdmin::EventChannel_var channel =
00259 CosEventChannelAdmin::EventChannel::_narrow(channelObj);
00260 if (CORBA::is_nil(channel))
00261 {
00262 cerr << "Failed to narrow Event Channel ! [\""
00263 << channelName << "\", \"" << channelKind << "\"]"
00264 << endl;
00265 exit(1);
00266 }
00267
00268
00269
00270 name.length(1);
00271 name[0].id = CORBA::string_dup (channelName);
00272 name[0].kind = CORBA::string_dup (channelKind);
00273
00274 try{
00275 action="register (bind) EventChannel with the naming service";
00276 rootContext->bind(name,channel.in());
00277 }
00278 catch(CosNaming::NamingContext::AlreadyBound& ex) {
00279 action="register (rebind) EventChannel with the naming service";
00280 rootContext->rebind(name,channel.in());
00281 }
00282
00283
00284
00285 result=0;
00286
00287 }
00288 catch (CosLifeCycle::NoFactory& ex) {
00289 cerr<<"Failed to create Event Channel: NoFactory"
00290 " (interface not supported) "<<endl;
00291 }
00292 catch (CosLifeCycle::CannotMeetCriteria& ex) {
00293 cerr<<"Failed to create Event Channel: CannotMeetCriteria "<<endl;
00294 }
00295 catch (CosLifeCycle::InvalidCriteria& ex) {
00296 cerr<<"Failed to create Event Channel: InvalidCriteria "<<endl;
00297 }
00298 catch (CORBA::COMM_FAILURE& ex) {
00299 cerr<<"System exception, unable to "<<action<<": COMM_FAILURE"<<endl;
00300 }
00301 catch (CORBA::SystemException& ex) {
00302 cerr<<"System exception, unable to "<<action
00303 #ifdef HAVE_OMNIORB4
00304 <<": "<<ex._name()<<" ("<<ex.NP_minorString()<<")"
00305 #endif
00306 << endl;
00307 }
00308 catch (CORBA::Exception& ex) {
00309 cerr<<"CORBA exception, unable to "<<action
00310 #ifdef HAVE_OMNIORB4
00311 <<": "<<ex._name()
00312 #endif
00313 << endl;
00314 }
00315 catch (omniORB::fatalException& ex) {
00316 cerr<<"Fatal Exception, unable to "<<action<<endl;
00317 }
00318
00319 return result;
00320 }
00321
00322 static void
00323 usage()
00324 {
00325 cerr << "\nusage: eventc [-n name] [-k kind] [-N name] [-K kind] [-r sec] [-m events] [-q events] [-h]\n" << endl;
00326 cerr << " -n name specify channel name [\"EventChannel\"]" << endl;
00327 cerr << " -k kind specify channel kind [\"EventChannel\"]" << endl;
00328 cerr << " -N name specify factory name [\"EventChannelFactory\"]" << endl;
00329 cerr << " -K kind specify factory kind [\"EventChannelFactory\"]" << endl;
00330 cerr << " -r Pull retry Period (in seconds) [1 sec]" << endl;
00331 cerr << " -m Maximum Number of Events queued per Consumer [0 = unlimited]" << endl;
00332 cerr << " -q Maximum Number of Events queued by the channel [0 = unlimited]" << endl;
00333 cerr << " -h display usage" << endl;
00334 cerr << endl;
00335 }
00336