Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / orbsvcs / tests / Bug_3387_Regression / MessengerConsumer.cpp
bloba6575d05a1e73091837571b65f6e96009109c29e
1 #include "orbsvcs/CosNotifyChannelAdminC.h"
2 #include "orbsvcs/CosNotifyCommC.h"
3 #include "orbsvcs/CosNamingC.h"
5 #include "StructuredEventConsumer_i.h"
6 #include <iostream>
8 #include "tao/ORB_Core.h"
9 #include "ace/Get_Opt.h"
11 static CORBA::ORB_ptr orb;
12 static CosNotifyChannelAdmin::StructuredProxyPushSupplier_ptr supplier_proxy;
13 static int pass;
15 int
16 parse_args (int argc, ACE_TCHAR *argv[])
18 ACE_Get_Opt get_opts (argc, argv, "p:");
19 int c;
21 while ((c = get_opts ()) != -1) switch (c)
23 case 'p':
24 pass = ACE_OS::atoi(get_opts.opt_arg ());
25 break;
26 case '?':
27 default:
28 ACE_ERROR_RETURN ((LM_ERROR,
29 "usage: %s "
30 "-p <pass> "
31 "\n",
32 argv [0]),
33 -1);
35 // Indicates successful parsing of the command line
36 return 0;
40 int
41 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
43 try
45 orb = CORBA::ORB_init(argc, argv);
47 if (parse_args (argc, argv) != 0)
48 return 1;
50 CORBA::Object_var naming_obj =
51 orb->resolve_initial_references ("NameService");
53 CosNaming::NamingContext_var naming_context =
54 CosNaming::NamingContext::_narrow(naming_obj.in());
56 CosNaming::Name name;
57 name.length (1);
58 name[0].id = CORBA::string_dup("MyEventChannel");
59 CORBA::Object_var ecObj = naming_context->resolve(name);
61 CosNotifyChannelAdmin::EventChannel_var ec =
62 CosNotifyChannelAdmin::EventChannel::_narrow(ecObj.in());
64 CosNotifyChannelAdmin::AdminID adminid;
65 CosNotifyChannelAdmin::InterFilterGroupOperator ifgop =
66 CosNotifyChannelAdmin::OR_OP;
68 CosNotifyChannelAdmin::ConsumerAdmin_var consumer_admin =
69 ec->new_for_consumers(ifgop,
70 adminid);
72 CORBA::Object_var poa_object =
73 orb->resolve_initial_references("RootPOA");
75 PortableServer::POA_var poa =
76 PortableServer::POA::_narrow (poa_object.in());
78 StructuredEventConsumer_i servant (orb);
80 PortableServer::ObjectId_var objectId = poa->activate_object (&servant);
82 CORBA::Object_var consumer_obj = poa->id_to_reference (objectId.in ());
84 CosNotifyComm::StructuredPushConsumer_var consumer =
85 CosNotifyComm::StructuredPushConsumer::_narrow (consumer_obj.in ());
87 CosNotifyChannelAdmin::ProxyID consumeradmin_proxy_id;
89 CosNotifyChannelAdmin::ProxySupplier_var proxy_supplier =
90 consumer_admin->obtain_notification_push_supplier(
91 CosNotifyChannelAdmin::STRUCTURED_EVENT,
92 consumeradmin_proxy_id);
94 supplier_proxy = CosNotifyChannelAdmin::StructuredProxyPushSupplier::
95 _narrow(proxy_supplier.in());
97 supplier_proxy->connect_structured_push_consumer(consumer.in());
102 CosNotification::EventTypeSeq added (1);
103 CosNotification::EventTypeSeq removed (1);
104 added.length (1);
105 removed.length (1);
107 added[0].domain_name = CORBA::string_dup ("OCI_TAO");
108 added[0].type_name = CORBA::string_dup ("examples");
110 removed[0].domain_name = CORBA::string_dup ("*");
111 removed[0].type_name = CORBA::string_dup ("*");
113 supplier_proxy->subscription_change(added, removed);
119 PortableServer::POAManager_var poa_manager = poa->the_POAManager();
121 poa_manager->activate();
123 ACE_Time_Value run_time(12);
124 orb->run(&run_time);
126 if ( servant.nummsgs() > 0 )
128 std::cout << "Success pass " << pass << ": events received " << std::endl;
130 else
132 std::cout << "ERROR pass " << pass << ": no events received " << std::endl;
136 catch(const CORBA::Exception& ex)
138 std::cerr << "Caught exception: " << ex << std::endl;
139 return 1;
142 return 0;
146 // VxWorks shutdown hook
147 int consumerStop()
149 printf("in consumerStop\n");
152 supplier_proxy->disconnect_structured_push_supplier();
155 catch(const CORBA::Exception& ex)
157 std::cerr << "Caught exception: " << ex << std::endl;
158 return 1;
161 orb->shutdown(0);
162 return 0;