3 #include "ace/Get_Opt.h"
4 #include "ace/OS_NS_stdlib.h"
9 namespace CosNotifyCommImpl
{
10 class StructuredPushConsumer
: public virtual POA_CosNotifyComm:: StructuredPushConsumer
13 StructuredPushConsumer () : received_ (false) {};
14 virtual ~ StructuredPushConsumer () {};
16 void push_structured_event(
17 const CosNotification::StructuredEvent
&event
)
20 std::cout
<< "Received an event...," << std::endl
;
21 std::cout
<< "event.header.fixed_header.event_type.domain_name = "
22 << event
.header
.fixed_header
.event_type
.domain_name
24 std::cout
<< "event.header.fixed_header.event_type.type_name = "
25 << event
.header
.fixed_header
.event_type
.type_name
29 void disconnect_structured_push_consumer()
33 const CosNotification::EventTypeSeq
&,
34 const CosNotification::EventTypeSeq
&)
37 bool received_events ()
39 return this->received_
;
47 int parse_args (int argc
, ACE_TCHAR
*argv
[])
49 ACE_Get_Opt
get_opts (argc
, argv
, "t:");
52 while ((x
= get_opts ()) != -1)
56 runtime
= ACE_OS::atoi (get_opts
.optarg
);
60 ACE_ERROR_RETURN ((LM_ERROR
,
61 ACE_TEXT ("usage: %s -t <runtime>\n"),
66 return 0; // successful parse
69 int ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
73 PortableServer::POAManager_var poa_manager
;
75 CORBA::ORB_var orb
= CORBA::ORB_init(argc
, argv
);
77 CORBA::Object_var poa_obj
= orb
->resolve_initial_references("RootPOA");
78 PortableServer::POA_var root_poa
= PortableServer::POA::_narrow(poa_obj
.in());
80 poa_manager
= root_poa
->the_POAManager();
82 if (parse_args (argc
, argv
) != 0)
85 poa_manager
->activate();
88 std::cout
<< "Get event_channel now" << std::endl
;
89 CosNotifyChannelAdmin::EventChannel_var ec
= get_event_channel(orb
.in());
91 //Instanciating the Consumer
92 CosNotifyComm::StructuredPushConsumer_var spc
=
93 CosNotifyComm::StructuredPushConsumer::_nil();
95 CosNotifyCommImpl::StructuredPushConsumer
*pImpl_spc
= new CosNotifyCommImpl::StructuredPushConsumer
;
96 spc
= pImpl_spc
->_this();
98 //Obtain a Consumer Admin
99 CosNotifyChannelAdmin::AdminID adminid
= 0;
100 CosNotifyChannelAdmin::ConsumerAdmin_var ca
=
101 ec
->new_for_consumers (CosNotifyChannelAdmin::AND_OP
, adminid
);
103 if( ca
.in() == CosNotifyChannelAdmin::ConsumerAdmin::_nil() ){
104 std::cerr
<< "ca is nil!" << std::endl
;
108 //Obtain a Proxy Consumer
109 CosNotifyChannelAdmin::ProxyID proxy_id
;
110 CosNotifyChannelAdmin::ClientType ctype
= CosNotifyChannelAdmin::STRUCTURED_EVENT
;
112 CosNotifyChannelAdmin::ProxySupplier_var proxySupplier_obj
;
115 proxySupplier_obj
= ca
->obtain_notification_push_supplier(ctype
, proxy_id
);
117 catch(CosNotifyChannelAdmin::AdminLimitExceeded
& err
)
119 std::cerr
<< "CosNotifyChannelAdmin::AdminLimitExceeded Exception!" << std::endl
;
123 CosNotifyChannelAdmin::StructuredProxyPushSupplier_var pps
=
124 CosNotifyChannelAdmin::StructuredProxyPushSupplier::_narrow(proxySupplier_obj
.in());
127 //Attaching a filter to pps
128 CosNotifyFilter::FilterFactory_var dff
=
129 ec
->default_filter_factory();
131 ACE_ASSERT(!CORBA::is_nil(dff
.in()));
133 CosNotifyFilter::Filter_var filter
= dff
->create_filter("EXTENDED_TCL");
135 CosNotification::EventTypeSeq
event_types(1);
136 event_types
.length(2);
138 event_types
[0].domain_name
= CORBA::string_dup("Test_domain");
139 event_types
[0].type_name
= CORBA::string_dup("Test_type_name");
140 event_types
[1].domain_name
= CORBA::string_dup("DomainB");
141 event_types
[1].type_name
= CORBA::string_dup("TypeB");
143 CosNotifyFilter::ConstraintExpSeq
constraints(1);
144 constraints
.length(1);
146 constraints
[0].event_types
= event_types
;
147 constraints
[0].constraint_expr
= CORBA::string_dup(
148 "$data == 1 or $data == 2 or $data == 4");
150 CosNotifyFilter::ConstraintInfoSeq_var cons_info
= filter
->add_constraints(constraints
);
152 pps
->add_filter(filter
.in());
154 std::cout
<< "Attached a filter to ProxyPushSupplier" << std::endl
;
155 std::cout
<< "The filter's event_types[0].domain_name = " << event_types
[0].domain_name
<< std::endl
;
156 std::cout
<< "The filter's event_types[0].type_name = " << event_types
[0].type_name
<< std::endl
;
157 std::cout
<< "The filter's event_types[1].domain_name = " << event_types
[1].domain_name
<< std::endl
;
158 std::cout
<< "The filter's event_types[1].type_name = " << event_types
[1].type_name
<< std::endl
;
159 std::cout
<< "The filter's constraint_expr=" << constraints
[0].constraint_expr
<< std::endl
;
161 //Connecting a Supplier to a Proxy Consumer
164 pps
->connect_structured_push_consumer(spc
.in());
166 catch (CosEventChannelAdmin::AlreadyConnected
& ac
)
168 std::cerr
<< "CosEventChannelAdmin::AlreadyConnected" << std::endl
;
171 catch (const CORBA::SystemException
& se
)
173 std::cerr
<< "System exception occurred during connect: " <<
179 ACE_Time_Value
tv (runtime
);
181 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("Consumer done.\n")));
183 if (pImpl_spc
->received_events ())
185 //Consumer should not receive any events as the user defined constraint takes
187 std::cerr
<< "Test failed - should not receive test events." << std::endl
;
192 std::cout
<< "Test passed - did not receive test events as expected." << std::endl
;
197 std::cerr
<< "Consumer: Some exceptions was caught!" << std::endl
;