1 #include "orbsvcs/CosNotifyChannelAdminC.h"
2 #include "orbsvcs/CosNotifyCommC.h"
3 #include "orbsvcs/CosNamingC.h"
5 #include "Messenger_i.h"
6 #include "StructuredEventSupplier_i.h"
9 Messenger_i::Messenger_i (CORBA::ORB_ptr orb
)
10 : orb_(CORBA::ORB::_duplicate(orb
))
12 CORBA::Object_var poa_object
=
13 orb_
->resolve_initial_references("RootPOA");
15 if (CORBA::is_nil (poa_object
.in())) {
16 std::cerr
<< "Unable to initialize the POA." << std::endl
;
19 CORBA::Object_var naming_obj
=
20 orb_
->resolve_initial_references ("NameService");
22 if (CORBA::is_nil(naming_obj
.in())) {
23 std::cerr
<< "Unable to find naming service" << std::endl
;
26 CosNaming::NamingContext_var naming_context
=
27 CosNaming::NamingContext::_narrow(naming_obj
.in());
31 name
[0].id
= CORBA::string_dup("NotifyEventChannelFactory");
33 CORBA::Object_var obj
= naming_context
->resolve(name
);
35 CosNotifyChannelAdmin::EventChannelFactory_var notify_factory
=
36 CosNotifyChannelAdmin::EventChannelFactory::_narrow(obj
.in());
38 if (CORBA::is_nil(notify_factory
.in())) {
39 std::cerr
<< "Unable to find notify factory" << std::endl
;
42 CosNotifyChannelAdmin::ChannelID id
;
43 CosNotification::QoSProperties initial_qos
;
44 CosNotification::AdminProperties initial_admin
;
46 CosNotifyChannelAdmin::EventChannel_var ec
=
47 notify_factory
->create_channel (initial_qos
,
51 if (CORBA::is_nil (ec
.in())) {
52 std::cerr
<< "Unable to crete event channel" << std::endl
;
56 name
[0].id
= CORBA::string_dup("MyEventChannel");
58 naming_context
->rebind(name
, ec
.in());
60 CosNotifyChannelAdmin::AdminID adminid
;
61 CosNotifyChannelAdmin::InterFilterGroupOperator ifgop
=
62 CosNotifyChannelAdmin::AND_OP
;
64 CosNotifyChannelAdmin::SupplierAdmin_var supplier_admin
=
65 ec
->new_for_suppliers (ifgop
, adminid
);
67 if (CORBA::is_nil (supplier_admin
.in())) {
68 std::cerr
<< "Unable to find supplier admin" << std::endl
;
71 CosNotifyChannelAdmin::ProxyID supplieradmin_proxy_id
;
73 CosNotifyChannelAdmin::ProxyConsumer_var proxy_consumer
=
74 supplier_admin
->obtain_notification_push_consumer(
75 CosNotifyChannelAdmin::STRUCTURED_EVENT
,
76 supplieradmin_proxy_id
);
78 StructuredEventSupplier_i
*servant
=
79 new StructuredEventSupplier_i(orb_
.in());
81 CosNotifyComm::StructuredPushSupplier_var supplier
=
85 CosNotifyChannelAdmin::StructuredProxyPushConsumer::
86 _narrow(proxy_consumer
.in());
88 if (CORBA::is_nil (s_proxy_consumer_
.in())) {
89 std::cerr
<< "Unable to find structured proxy push consumer" << std::endl
;
93 connect_structured_push_supplier(supplier
.in());
96 CosNotification::EventTypeSeq
added (1);
97 CosNotification::EventTypeSeq
removed (1);
100 added
[0].domain_name
= CORBA::string_dup ("OCI_TAO");
101 added
[0].type_name
= CORBA::string_dup ("examples");
103 removed
[0].domain_name
= CORBA::string_dup ("*");
104 removed
[0].type_name
= CORBA::string_dup ("*");
106 s_proxy_consumer_
->offer_change(added
, removed
);
109 Messenger_i::~Messenger_i (void)
113 CORBA::Boolean
Messenger_i::send_message (
114 const char * user_name
,
115 const char * subject
,
119 std::cout
<< "Message from: " << user_name
<< std::endl
;
120 std::cout
<< "Subject: " << subject
<< std::endl
;
121 std::cout
<< "Message: " << message
<< std::endl
;
125 CosNotification::StructuredEvent event
;
127 event
.header
.fixed_header
.event_type
.domain_name
=
128 CORBA::string_dup("OCI_TAO");
130 event
.header
.fixed_header
.event_type
.type_name
=
131 CORBA::string_dup("examples");
133 event
.header
.fixed_header
.event_name
=
134 CORBA::string_dup("myevent");
136 // OptionalHeaderFields
139 // sequence<Property>: string name, any value
140 event
.filterable_data
.length (1);
141 event
.filterable_data
[0].name
= CORBA::string_dup("Message from:");
142 event
.filterable_data
[0].value
<<= (const char *)user_name
;
143 event
.filterable_data
.length (2);
144 event
.filterable_data
[1].name
= CORBA::string_dup("Subject:");
145 event
.filterable_data
[1].value
<<= (const char *)subject
;
146 event
.filterable_data
.length (3);
147 event
.filterable_data
[2].name
= CORBA::string_dup("Message:");
148 event
.filterable_data
[2].value
<<= (const char *)message
;
150 s_proxy_consumer_
->push_structured_event(event
);