1 #include "orbsvcs/CosNotifyChannelAdminC.h"
2 #include "orbsvcs/CosNotifyCommC.h"
3 #include "orbsvcs/CosNamingC.h"
4 #include "ace/OS_NS_stdio.h"
6 #include "Messenger_i.h"
7 #include "StructuredEventSupplier_i.h"
10 Messenger_i::Messenger_i (CORBA::ORB_ptr orb
)
11 : orb_ (CORBA::ORB::_duplicate (orb
))
14 CORBA::Object_var naming_obj
=
15 orb_
->resolve_initial_references ("NameService");
17 CosNaming::NamingContext_var naming_context
=
18 CosNaming::NamingContext::_narrow (naming_obj
.in());
22 name
[0].id
= CORBA::string_dup ("NotifyEventChannelFactory");
24 CORBA::Object_var obj
= naming_context
->resolve (name
);
26 CosNotifyChannelAdmin::EventChannelFactory_var notify_factory
=
27 CosNotifyChannelAdmin::EventChannelFactory::_narrow (obj
.in ());
29 CosNotifyChannelAdmin::ChannelID id
;
30 CosNotification::QoSProperties initial_qos
;
31 CosNotification::AdminProperties initial_admin
;
33 CosNotifyChannelAdmin::EventChannel_var ec
=
34 notify_factory
->create_channel (initial_qos
,
38 name
[0].id
= CORBA::string_dup ("MyEventChannel");
40 naming_context
->rebind (name
, ec
.in());
42 CosNotifyChannelAdmin::AdminID adminid
;
43 CosNotifyChannelAdmin::InterFilterGroupOperator ifgop
=
44 CosNotifyChannelAdmin::OR_OP
;
46 CosNotifyChannelAdmin::SupplierAdmin_var supplier_admin
=
47 ec
->new_for_suppliers (ifgop
, adminid
);
49 CosNotifyChannelAdmin::ProxyID supplieradmin_proxy_id
;
51 CosNotifyChannelAdmin::ProxyConsumer_var proxy_consumer
=
52 supplier_admin
->obtain_notification_push_consumer(
53 CosNotifyChannelAdmin::STRUCTURED_EVENT
,
54 supplieradmin_proxy_id
);
56 StructuredEventSupplier_i
*servant
=
57 new StructuredEventSupplier_i(orb_
.in());
59 CORBA::Object_var poa_obj
= orb_
->resolve_initial_references ("RootPOA");
60 PortableServer::POA_var poa
= PortableServer::POA::_narrow (poa_obj
.in ());
61 PortableServer::POAManager_var mgr
= poa
->the_POAManager ();
64 PortableServer::ObjectId_var objectId
= poa
->activate_object (servant
);
66 CORBA::Object_var supplier_obj
= poa
->id_to_reference (objectId
.in ());
68 CosNotifyComm::StructuredPushSupplier_var supplier
=
69 CosNotifyComm::StructuredPushSupplier::_narrow (supplier_obj
.in ());
72 CosNotifyChannelAdmin::StructuredProxyPushConsumer::_narrow (proxy_consumer
.in());
75 connect_structured_push_supplier (supplier
.in());
79 Messenger_i::~Messenger_i (void)
83 CORBA::Boolean
Messenger_i::send_message (
84 const char * user_name
,
89 ACE_OS::printf("Message from: %s\nSubject: %s\nMessage: %s\n",
90 user_name
, subject
, message
);
91 //cout << "Message from: " << user_name << endl;
92 //cout << "Subject: " << subject << endl;
93 //cout << "Message: " << message << endl;
97 CosNotification::StructuredEvent event
;
99 event
.header
.fixed_header
.event_type
.domain_name
=
100 CORBA::string_dup("OCI_TAO");
102 event
.header
.fixed_header
.event_type
.type_name
=
103 CORBA::string_dup("examples");
105 event
.header
.fixed_header
.event_name
=
106 CORBA::string_dup("myevent");
108 // OptionalHeaderFields
111 // sequence<Property>: string name, any value
112 event
.filterable_data
.length (3);
113 event
.filterable_data
[0].name
= CORBA::string_dup("Message from:");
114 event
.filterable_data
[0].value
<<= (const char *)user_name
;
115 event
.filterable_data
[1].name
= CORBA::string_dup("Subject:");
116 event
.filterable_data
[1].value
<<= (const char *)subject
;
117 event
.filterable_data
[2].name
= CORBA::string_dup("Message:");
118 event
.filterable_data
[2].value
<<= (const char *)message
;
120 std::cout
<< "pushing " << std::endl
;
121 consumer_proxy_
->push_structured_event(event
);