2 #include "ace/OS_NS_unistd.h"
4 namespace CosNotifyCommImpl
{
5 class StructuredPushSupplier
: public virtual POA_CosNotifyComm:: StructuredPushSupplier
8 void disconnect_structured_push_supplier()
11 void subscription_change( const CosNotification::EventTypeSeq
&,
12 const CosNotification::EventTypeSeq
&)
18 int ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
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();
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
;
52 //Obtain a Proxy Consumer
53 CosNotifyChannelAdmin::ProxyID proxy_id
;
54 CosNotifyChannelAdmin::ClientType ctype
= CosNotifyChannelAdmin::STRUCTURED_EVENT
;
56 CosNotifyChannelAdmin::ProxyConsumer_var proxyCon_obj
;
59 proxyCon_obj
= sa
->obtain_notification_push_consumer(ctype
, proxy_id
);
61 catch(const CosNotifyChannelAdmin::AdminLimitExceeded
&)
63 std::cerr
<< "CosNotifyChannelAdmin::AdminLimitExceeded Exception!" << std::endl
;
67 CosNotifyChannelAdmin::StructuredProxyPushConsumer_var ppc
=
68 CosNotifyChannelAdmin::StructuredProxyPushConsumer::_narrow(proxyCon_obj
.in());
70 //Connecting a Supplier to a Proxy Consumer
73 ppc
->connect_structured_push_supplier(sps
.in());
75 catch (const CosEventChannelAdmin::AlreadyConnected
&)
77 std::cerr
<< "CosEventChannelAdmin::AlreadyConnected" << std::endl
;
80 catch (const CORBA::SystemException
& se
)
82 std::cerr
<< "System exception occurred during connect: " <<
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);
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
109 std::cout
<< "event.header.fixed_header.event_type.type_name = "
110 << event
.header
.fixed_header
.event_type
.type_name
112 std::cout
<< "event.filterable_data: data=" << data
<< std::endl
;
116 ppc
->push_structured_event(event
);
118 catch (const CORBA::SystemException
& se
)
120 std::cerr
<< "System exception occurred during push: "
124 catch (const CORBA::Exception
&)
126 std::cerr
<< "Unknown exception occurred during push" << std::endl
;
133 ppc
->disconnect_structured_push_consumer();
135 catch(CORBA::Exception
&)
137 std::cerr
<< "Disconnect fail!" << std::endl
;
141 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("Supplier done.\n")));
145 std::cerr
<< "Supplier: Some exceptions was caught!" << std::endl
;