1 #include "orbsvcs/CosNotifyChannelAdminC.h"
2 #include "orbsvcs/CosNotifyCommC.h"
3 #include "orbsvcs/CosNamingC.h"
5 #include "StructuredEventConsumer_i.h"
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
;
16 parse_args (int argc
, ACE_TCHAR
*argv
[])
18 ACE_Get_Opt
get_opts (argc
, argv
, "p:");
21 while ((c
= get_opts ()) != -1) switch (c
)
24 pass
= ACE_OS::atoi(get_opts
.opt_arg ());
28 ACE_ERROR_RETURN ((LM_ERROR
,
35 // Indicates successful parsing of the command line
41 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
45 orb
= CORBA::ORB_init(argc
, argv
);
47 if (parse_args (argc
, argv
) != 0)
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());
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
,
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);
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);
126 if ( servant
.nummsgs() > 0 )
128 std::cout
<< "Success pass " << pass
<< ": events received " << std::endl
;
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
;
146 // VxWorks shutdown hook
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
;