43 # include <iostream.h>
46 #ifdef HAVE_STD_IOSTREAM
56 #if defined HAVE_UNISTD_H
58 #elif defined __WIN32__
60 # define write(fd,buf,count) _write(fd,buf,count)
61 # define read(fd,buf,count) _read(fd,buf,count)
69 #include "CosEventComm.hh"
70 #include "CosEventChannelAdmin.hh"
74 # define STDIN_FILENO 0
75 # define STDOUT_FILENO 1
80 static void usage(
int argc,
char **argv);
86 #define BILLION 1000000000
98 unsigned long sec,nano;
99 omni_thread::get_time(&sec,&nano);
109 Time offset=futureTime-now;
110 omni_thread::sleep(offset.
_sec,offset.
_nano);
115 Time(CORBA::ULong sec,CORBA::ULong nano):_sec(sec),_nano(nano){}
116 Time(
const Time& right):_sec(right._sec),_nano(right._nano){}
129 return _nano<right.
_nano;
131 return _sec<right.
_sec;
154 cerr<<
"Negative time!"<<endl;
155 throw CORBA::BAD_PARAM();
158 if(_nano<right.
_nano)
182 bool is_nil()
const {
return(_sec==0 && _nano==0); }
190 class Consumer_i :
virtual public POA_CosEventComm::PushConsumer
194 void push(
const CORBA::Any& data)
202 write(
STDOUT_FILENO,_memstream.bufPtr(),_memstream.bufSize());
204 _memstream.rewindPtrs();
208 cout<<
"disconnected"<<endl;
212 CosEventChannelAdmin::EventChannel_ptr channel,
215 action=
"get ConsumerAdmin";
216 CosEventChannelAdmin::ConsumerAdmin_var consumer_admin =
217 channel->for_consumers();
219 action=
"get ProxyPushSupplier";
220 CosEventChannelAdmin::ProxyPushSupplier_var proxy_supplier =
221 consumer_admin->obtain_push_supplier();
223 action=
"connect to ProxyPushSupplier";
224 proxy_supplier->connect_push_consumer(_this());
235 class Supplier_i :
virtual public POA_CosEventComm::PushSupplier
241 cout<<
"disconnected"<<endl;
245 CosEventChannelAdmin::EventChannel_ptr channel,
248 action=
"get SupplierAdmin";
249 CosEventChannelAdmin::SupplierAdmin_var supplier_admin =
250 channel->for_suppliers();
252 action=
"get ProxyPushConsumer";
253 CosEventChannelAdmin::ProxyPushConsumer_var proxy_consumer =
254 supplier_admin->obtain_push_consumer();
256 action=
"connect to ProxyPushConsumer";
257 proxy_consumer->connect_push_supplier(_this());
261 action=
"read standard input";
267 cdrMemoryStream memstr;
268 action=
"put_octet_array";
269 memstr.put_octet_array( (_CORBA_Octet*)buf, (
int)len );
270 while(_connected && memstr.currentInputPtr()<memstr.bufSize())
282 proxy_consumer->push(any);
295 int main(
int argc,
char **argv)
299 #if defined(HAVE_OMNIORB4)
300 orb=CORBA::ORB_init(argc,argv,
"omniORB4");
302 orb=CORBA::ORB_init(argc,argv,
"omniORB3");
306 bool supplierMode =
false;
307 const char* channelName =
"EventChannel";
310 while ((c =
getopt(argc,argv,
"shn:")) != EOF)
314 case 's': supplierMode=
true;
317 case 'n': channelName =
optarg;
320 case 'h':
usage(argc,argv);
322 default :
usage(argc,argv);
327 #if defined(HAVE_SIGNAL_H) && defined(SIGPIPE)
329 signal(SIGPIPE, SIG_IGN);
332 const char* action=
"";
334 CORBA::Object_var obj;
336 action=
"resolve initial reference 'RootPOA'";
337 obj=
orb->resolve_initial_references(
"RootPOA");
338 PortableServer::POA_var rootPoa =PortableServer::POA::_narrow(obj);
339 if(CORBA::is_nil(rootPoa))
340 throw CORBA::OBJECT_NOT_EXIST();
342 action=
"activate the RootPOA's POAManager";
343 PortableServer::POAManager_var pman =rootPoa->the_POAManager();
351 action=
"convert URI from command line into object reference";
356 action=
"resolve initial reference 'NameService'";
357 obj=
orb->resolve_initial_references(
"NameService");
358 CosNaming::NamingContext_var rootContext=
359 CosNaming::NamingContext::_narrow(obj);
360 if(CORBA::is_nil(rootContext))
361 throw CORBA::OBJECT_NOT_EXIST();
363 action=
"find EventChannel in NameService";
364 cout << action << endl;
365 obj=rootContext->resolve(
str2name(channelName));
368 action=
"narrow object reference to event channel";
369 CosEventChannelAdmin::EventChannel_var channel =
370 CosEventChannelAdmin::EventChannel::_narrow(obj);
371 if(CORBA::is_nil(channel))
373 cerr <<
"Failed to narrow Event Channel reference." << endl;
379 action=
"construct PushSupplier";
381 supplier->
supply(channel,action);
385 action=
"construct PushConsumer";
387 consumer->
consume(channel,action);
396 catch(CORBA::ORB::InvalidName& ex) {
397 cerr<<
"Failed to "<<action<<
". ORB::InvalidName"<<endl;
399 catch(CosNaming::NamingContext::InvalidName& ex) {
400 cerr<<
"Failed to "<<action<<
". NamingContext::InvalidName"<<endl;
402 catch(CosNaming::NamingContext::NotFound& ex) {
403 cerr<<
"Failed to "<<action<<
". NamingContext::NotFound"<<endl;
405 catch(CosNaming::NamingContext::CannotProceed& ex) {
406 cerr<<
"Failed to "<<action<<
". NamingContext::CannotProceed"<<endl;
408 catch(CORBA::TRANSIENT& ex) {
409 cerr<<
"Failed to "<<action<<
". TRANSIENT"<<endl;
411 catch(CORBA::OBJECT_NOT_EXIST& ex) {
412 cerr<<
"Failed to "<<action<<
". OBJECT_NOT_EXIST"<<endl;
414 catch(CORBA::SystemException& ex) {
415 cerr<<
"Failed to "<<action<<
"."
416 #if defined(HAVE_OMNIORB4)
417 " "<<ex._name()<<
" ("<<ex.NP_minorString()<<
")"
421 catch(CORBA::Exception& ex) {
422 cerr<<
"Failed to "<<action<<
"."
423 #if defined(HAVE_OMNIORB4)
432 static void usage(
int argc,
char **argv)
435 "\nStream events from a channel to stdout, or (-s) from stdin to a channel.\n"
436 "syntax: "<<(argc?argv[0]:
"events")<<
" OPTIONS [CHANNEL_URI]\n"
438 "CHANNEL_URI: The event channel may be specified as a URI.\n"
439 " This may be an IOR, or a corbaloc::: or corbaname::: URI.\n"
441 "OPTIONS: DEFAULT:\n"
442 " -s supply mode. Read events from stdin.\n"
443 " -n NAME channel name (if URI is not specified) [\"EventChannel\"]\n"
444 " -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)
bool operator<(const Time &right) const
Time operator+(const Time &right) const
Time(CORBA::ULong sec, CORBA::ULong nano)
static void sleepUntil(const Time &futureTime)
Time & operator-=(const Time &right)
Time operator-(const Time &right) const
Time & operator=(const Time &right)
void operator>>=(cdrMemoryStream &s) const
Time & operator+=(const Time &right)
void operator<<=(cdrMemoryStream &s)
void consume(CosEventChannelAdmin::EventChannel_ptr channel, const char *&action)
void push(const CORBA::Any &data)
cdrMemoryStream _memstream
void disconnect_push_consumer()
Consumer_i(long disconnect=0)
void disconnect_push_supplier()
void supply(CosEventChannelAdmin::EventChannel_ptr channel, const char *&action)