132 # include <iostream.h>
135 #ifdef HAVE_STD_IOSTREAM
149 #include "CosEventComm.hh"
150 #include "CosEventChannelAdmin.hh"
154 static void usage(
int argc,
char **argv);
156 class Supplier_i :
virtual public POA_CosEventComm::PullSupplier {
158 Supplier_i (
long disconnect = 0) : i(0), _disconnect(disconnect), l(0) {};
160 CORBA::Any *try_pull(CORBA::Boolean &has_event);
161 void disconnect_pull_supplier ();
171 cout <<
"Pull Supplier: disconnected by channel." << endl;
176 cout <<
"Pull Supplier: pull() called. Data : ";
177 CORBA::Any *any =
new CORBA::Any();
182 if ((_disconnect > 0) && (i == _disconnect)) {
194 cout <<
"Pull Supplier: try_pull() called. Data : ";
195 CORBA::Any *any =
new CORBA::Any();
201 if ((_disconnect > 0) && (i == _disconnect)) {
214 #if defined(HAVE_OMNIORB4)
215 CORBA::ORB_var
orb =CORBA::ORB_init(argc,argv,
"omniORB4");
217 CORBA::ORB_var
orb =CORBA::ORB_init(argc,argv,
"omniORB3");
222 int sleepInterval =0;
223 const char* channelName =
"EventChannel";
226 while ((c =
getopt(argc,argv,
"d:s:n:h")) != EOF)
230 case 'd': discnum = atoi(
optarg);
233 case 's': sleepInterval = atoi(
optarg);
236 case 'n': channelName =
optarg;
240 default :
usage(argc,argv);
246 #if defined(HAVE_SIGNAL_H) && defined(SIGPIPE)
248 signal(SIGPIPE, SIG_IGN);
252 CosEventChannelAdmin::EventChannel_var channel;
254 const char* action=
"";
256 CORBA::Object_var obj;
258 action=
"resolve initial reference 'RootPOA'";
259 obj=
orb->resolve_initial_references(
"RootPOA");
260 PortableServer::POA_var rootPoa =PortableServer::POA::_narrow(obj);
261 if(CORBA::is_nil(rootPoa))
262 throw CORBA::OBJECT_NOT_EXIST();
264 action=
"activate the RootPOA's POAManager";
265 PortableServer::POAManager_var pman =rootPoa->the_POAManager();
273 action=
"convert URI from command line into object reference";
278 action=
"resolve initial reference 'NameService'";
279 obj=
orb->resolve_initial_references(
"NameService");
280 CosNaming::NamingContext_var rootContext=
281 CosNaming::NamingContext::_narrow(obj);
282 if(CORBA::is_nil(rootContext))
283 throw CORBA::OBJECT_NOT_EXIST();
285 action=
"find EventChannel in NameService";
286 cout << action << endl;
287 obj=rootContext->resolve(
str2name(channelName));
290 action=
"narrow object reference to event channel";
291 channel=CosEventChannelAdmin::EventChannel::_narrow(obj);
292 if(CORBA::is_nil(channel))
294 cerr <<
"Failed to narrow Event Channel reference." << endl;
299 catch(CORBA::ORB::InvalidName& ex) {
300 cerr<<
"Failed to "<<action<<
". ORB::InvalidName"<<endl;
303 catch(CosNaming::NamingContext::InvalidName& ex) {
304 cerr<<
"Failed to "<<action<<
". NamingContext::InvalidName"<<endl;
307 catch(CosNaming::NamingContext::NotFound& ex) {
308 cerr<<
"Failed to "<<action<<
". NamingContext::NotFound"<<endl;
311 catch(CosNaming::NamingContext::CannotProceed& ex) {
312 cerr<<
"Failed to "<<action<<
". NamingContext::CannotProceed"<<endl;
315 catch(CORBA::TRANSIENT& ex) {
316 cerr<<
"Failed to "<<action<<
". TRANSIENT"<<endl;
319 catch(CORBA::OBJECT_NOT_EXIST& ex) {
320 cerr<<
"Failed to "<<action<<
". OBJECT_NOT_EXIST"<<endl;
323 catch(CORBA::SystemException& ex) {
324 cerr<<
"Failed to "<<action<<
".";
325 #if defined(HAVE_OMNIORB4)
326 cerr<<
" "<<ex._name();
327 if(ex.NP_minorString())
328 cerr<<
" ("<<ex.NP_minorString()<<
")";
333 catch(CORBA::Exception& ex) {
334 cerr<<
"Failed to "<<action<<
"."
335 #if defined(HAVE_OMNIORB4)
344 CosEventChannelAdmin::SupplierAdmin_var supplier_admin;
348 supplier_admin = channel->for_suppliers ();
349 if (CORBA::is_nil(supplier_admin))
351 cerr <<
"Event Channel returned nil Supplier Admin!"
357 catch (CORBA::COMM_FAILURE& ex) {
358 cerr <<
"Caught COMM_FAILURE exception "
359 <<
"obtaining Supplier Admin! Retrying..."
364 cout <<
"Obtained SupplierAdmin." << endl;
370 CosEventChannelAdmin::ProxyPullConsumer_var proxy_consumer;
374 proxy_consumer = supplier_admin->obtain_pull_consumer ();
375 if (CORBA::is_nil(proxy_consumer))
377 cerr <<
"Supplier Admin returned nil proxy_consumer!"
383 catch (CORBA::COMM_FAILURE& ex) {
384 cerr <<
"Caught COMM_FAILURE exception "
385 <<
"obtaining Proxy Pull Consumer! Retrying..."
390 cout <<
"Obtained ProxyPullConsumer." << endl;
393 CosEventComm::PullSupplier_var supplierRef =supplier->_this();
397 proxy_consumer->connect_pull_supplier(supplierRef.in());
400 catch (CORBA::BAD_PARAM& ex) {
401 cerr<<
"Caught BAD_PARAM Exception connecting Pull Supplier!"<<endl;
404 catch (CosEventChannelAdmin::AlreadyConnected& ex) {
405 cerr <<
"Pull Supplier already connected!"
409 catch (CORBA::COMM_FAILURE& ex) {
410 cerr <<
"Caught COMM_FAILURE exception "
411 <<
"connecting Pull Supplier! Retrying..."
416 cout <<
"Connected Pull Supplier." << endl;
425 proxy_consumer->disconnect_pull_consumer();
428 catch (CORBA::COMM_FAILURE& ex) {
429 cerr <<
"Caught COMM_FAILURE exception "
430 <<
"disconnecting Pull Supplier! Retrying..."
435 cout <<
"Disconnected Pull Supplier." << endl;
438 cout <<
"Sleeping " << sleepInterval <<
" seconds." << endl;
439 omni_thread::sleep(sleepInterval);
450 "\nCreate a PullSupplier to send events to a channel.\n"
451 "syntax: "<<(argc?argv[0]:
"pullsupp")<<
" OPTIONS [CHANNEL_URI]\n"
453 "CHANNEL_URI: The event channel may be specified as a URI.\n"
454 " This may be an IOR, or a corbaloc::: or corbaname::: URI.\n"
456 "OPTIONS: DEFAULT:\n"
457 " -d NUM disconnect after sending NUM events [0 - never disconnect]\n"
458 " -s SECS sleep SECS seconds after disconnecting [0]\n"
459 " -n NAME channel name (if URI is not specified) [\"EventChannel\"]\n"
460 " -h display this help text\n" << endl;
int getopt(int argc, char *argv[], const char *optionS)
CosNaming::Name str2name(const char *namestr)
Converts stringified name to naming service name.
int main(int argc, char **argv)
The main process entry point.
static void usage(int argc, char **argv)
static omni_semaphore connect_cond(0)
Supplier_i(long disconnect=0)
CORBA::Any * try_pull(CORBA::Boolean &has_event)
void disconnect_pull_supplier()