Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / TAO / orbsvcs / tests / Notify / Bug_3688_Regression / supplier.cpp
blobad34e9cfa75066e7caf6137a48e4a706146a1fcd
1 #include "common.h"
2 #include "ace/OS_NS_unistd.h"
4 namespace CosNotifyCommImpl{
5 class StructuredPushSupplier: public virtual POA_CosNotifyComm:: StructuredPushSupplier
7 public:
8 void disconnect_structured_push_supplier()
11 void subscription_change( const CosNotification::EventTypeSeq&,
12 const CosNotification::EventTypeSeq&)
13 {};
18 int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
20 try
22 PortableServer::POAManager_var poa_manager;
24 CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
26 CORBA::Object_var poa_obj = orb->resolve_initial_references("RootPOA");
27 PortableServer::POA_var root_poa = PortableServer::POA::_narrow(poa_obj.in());
29 poa_manager = root_poa->the_POAManager();
31 poa_manager->activate();
33 /*Get event_channel*/
34 std::cout << "Create event_channel now" << std::endl;
35 CosNotifyChannelAdmin::EventChannel_var ec = get_event_channel(orb.in());
37 //Instanciating the Supplier
38 CosNotifyComm::StructuredPushSupplier_var sps =
39 CosNotifyComm::StructuredPushSupplier::_nil();
42 CosNotifyCommImpl::StructuredPushSupplier *pImpl_sps = new CosNotifyCommImpl::StructuredPushSupplier;
43 sps = pImpl_sps->_this();
45 //Obtain a Supplier Admin
46 CosNotifyChannelAdmin::SupplierAdmin_var sa = ec->default_supplier_admin();
47 if( sa.in() == CosNotifyChannelAdmin::SupplierAdmin::_nil() ){
48 std::cerr << "sa is nil!" << std::endl;
49 return 1;
52 //Obtain a Proxy Consumer
53 CosNotifyChannelAdmin::ProxyID proxy_id;
54 CosNotifyChannelAdmin::ClientType ctype = CosNotifyChannelAdmin::STRUCTURED_EVENT;
56 CosNotifyChannelAdmin::ProxyConsumer_var proxyCon_obj;
57 try
59 proxyCon_obj = sa->obtain_notification_push_consumer(ctype, proxy_id);
61 catch(const CosNotifyChannelAdmin::AdminLimitExceeded&)
63 std::cerr << "CosNotifyChannelAdmin::AdminLimitExceeded Exception!" << std::endl;
64 throw;
67 CosNotifyChannelAdmin::StructuredProxyPushConsumer_var ppc =
68 CosNotifyChannelAdmin::StructuredProxyPushConsumer::_narrow(proxyCon_obj.in());
70 //Connecting a Supplier to a Proxy Consumer
71 try
73 ppc->connect_structured_push_supplier(sps.in());
75 catch (const CosEventChannelAdmin::AlreadyConnected&)
77 std::cerr << "CosEventChannelAdmin::AlreadyConnected" << std::endl;
78 throw;
80 catch (const CORBA::SystemException& se)
82 std::cerr << "System exception occurred during connect: " <<
83 se << std::endl;
84 throw;
88 //Demo::demo_send_heart_beat(ppc);
89 //Send a Demo Notification
91 CosNotification::StructuredEvent event;
93 event.header.fixed_header.event_type.domain_name =
94 CORBA::string_dup("Test_domain");
95 event.header.fixed_header.event_type.type_name =
96 CORBA::string_dup("Test_type_name");
97 event.header.variable_header.length(0);
99 int data = 5;
100 event.filterable_data.length(1);
101 event.filterable_data[0].name = CORBA::string_dup ("data");
102 event.filterable_data[0].value <<= data;
103 event.remainder_of_body <<= data;
105 std::cout << "Sending a demo event...," << std::endl;
106 std::cout << "event.header.fixed_header.event_type.domain_name = "
107 << event.header.fixed_header.event_type.domain_name
108 << std::endl;
109 std::cout << "event.header.fixed_header.event_type.type_name = "
110 << event.header.fixed_header.event_type.type_name
111 << std::endl;
112 std::cout << "event.filterable_data: data=" << data << std::endl;
115 try{
116 ppc->push_structured_event(event);
118 catch (const CORBA::SystemException& se)
120 std::cerr << "System exception occurred during push: "
121 << se << std::endl;
122 throw;
124 catch (const CORBA::Exception&)
126 std::cerr << "Unknown exception occurred during push" << std::endl;
127 throw;
130 ACE_OS::sleep (5);
132 try{
133 ppc->disconnect_structured_push_consumer();
135 catch(CORBA::Exception&)
137 std::cerr << "Disconnect fail!" << std::endl;
140 orb->shutdown();
141 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Supplier done.\n")));
143 catch(...)
145 std::cerr << "Supplier: Some exceptions was caught!" << std::endl;
146 return 1;
150 return 0;