Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / orbsvcs / DevGuideExamples / NotifyService / RTNotify / Messenger_i.cpp
blobd269451a068bf1980ad4a387ccfd6d6aad5c8924
1 #include "orbsvcs/CosNotifyChannelAdminC.h"
2 #include "orbsvcs/CosNotifyCommC.h"
3 #include "orbsvcs/CosNamingC.h"
4 #include "orbsvcs/NotifyExtC.h"
5 #include "ace/OS_NS_stdio.h"
7 #include "Messenger_i.h"
8 #include "StructuredEventSupplier_i.h"
9 #include "Priorities.h"
10 #include <iostream>
12 Messenger_i::Messenger_i (CORBA::ORB_ptr orb)
13 : orb_ (CORBA::ORB::_duplicate (orb))
15 CORBA::Object_var naming_obj =
16 orb_->resolve_initial_references ("NameService");
18 CosNaming::NamingContext_var naming_context =
19 CosNaming::NamingContext::_narrow (naming_obj.in());
21 CosNaming::Name name;
22 name.length (1);
23 name[0].id = CORBA::string_dup ("NotifyEventChannelFactory");
25 CORBA::Object_var obj = naming_context->resolve (name);
27 CosNotifyChannelAdmin::EventChannelFactory_var notify_factory =
28 CosNotifyChannelAdmin::EventChannelFactory::_narrow (obj.in ());
30 CosNotifyChannelAdmin::ChannelID id;
31 CosNotification::QoSProperties initial_qos;
32 CosNotification::AdminProperties initial_admin;
34 CosNotifyChannelAdmin::EventChannel_var ec =
35 notify_factory->create_channel (initial_qos,
36 initial_admin,
37 id);
39 name[0].id = CORBA::string_dup ("MyEventChannel");
41 naming_context->rebind (name, ec.in());
43 CosNotifyChannelAdmin::AdminID adminid;
44 CosNotifyChannelAdmin::InterFilterGroupOperator ifgop =
45 CosNotifyChannelAdmin::AND_OP;
47 CosNotifyChannelAdmin::SupplierAdmin_var supplier_admin =
48 ec->new_for_suppliers (ifgop, adminid);
50 NotifyExt::ThreadPoolLanesParams tpl_params;
52 tpl_params.priority_model = NotifyExt::CLIENT_PROPAGATED;
53 tpl_params.server_priority = DEFAULT_PRIORITY;
54 tpl_params.stacksize = 0;
55 tpl_params.allow_borrowing = 0;
56 tpl_params.allow_request_buffering = 0;
57 tpl_params.max_buffered_requests = 0;
58 tpl_params.max_request_buffer_size = 0;
59 tpl_params.lanes.length (2);
60 tpl_params.lanes[0].lane_priority = LOW_PRIORITY;
61 tpl_params.lanes[0].static_threads = 2;
62 tpl_params.lanes[0].dynamic_threads = 0;
63 tpl_params.lanes[1].lane_priority = HIGH_PRIORITY;
64 tpl_params.lanes[1].static_threads = 2;
65 tpl_params.lanes[1].dynamic_threads = 0;
66 CosNotification::QoSProperties qos;
67 qos.length(1);
68 qos[0].name = CORBA::string_dup (NotifyExt::ThreadPoolLanes);
69 qos[0].value <<= tpl_params;
71 supplier_admin->set_qos(qos);
72 CORBA::Object_var current_obj =
73 this->orb_->resolve_initial_references ("RTCurrent");
75 current_ = RTCORBA::Current::_narrow (current_obj.in ());
76 current_->the_priority(HIGH_PRIORITY);
78 CosNotifyChannelAdmin::ProxyID supplieradmin_proxy_id;
80 CosNotifyChannelAdmin::ProxyConsumer_var proxy_consumer =
81 supplier_admin->obtain_notification_push_consumer(
82 CosNotifyChannelAdmin::STRUCTURED_EVENT,
83 supplieradmin_proxy_id);
85 StructuredEventSupplier_i *servant =
86 new StructuredEventSupplier_i(orb_.in());
88 CORBA::Object_var poa_obj = orb_->resolve_initial_references ("RootPOA");
89 PortableServer::POA_var poa = PortableServer::POA::_narrow (poa_obj.in ());
90 PortableServer::POAManager_var mgr = poa->the_POAManager ();
92 mgr->activate ();
93 PortableServer::ObjectId_var objectId = poa->activate_object (servant);
95 CORBA::Object_var supplier_obj = poa->id_to_reference (objectId.in ());
97 CosNotifyComm::StructuredPushSupplier_var supplier =
98 CosNotifyComm::StructuredPushSupplier::_narrow (supplier_obj.in ());
100 consumer_proxy_ =
101 CosNotifyChannelAdmin::StructuredProxyPushConsumer::_narrow (proxy_consumer.in());
103 consumer_proxy_->
104 connect_structured_push_supplier (supplier.in());
108 Messenger_i::~Messenger_i (void)
112 CORBA::Boolean Messenger_i::send_message (
113 const char * user_name,
114 const char * subject,
115 char *& message)
117 ACE_OS::printf("Message from: %s\nSubject: %s\nMessage: %s\n",
118 user_name, subject, message);
119 //cout << "Message from: " << user_name << endl;
120 //cout << "Subject: " << subject << endl;
121 //cout << "Message: " << message << endl;
123 // Event Definition
124 CosNotification::StructuredEvent event;
126 event.header.fixed_header.event_type.domain_name =
127 CORBA::string_dup("OCI_TAO");
128 // string
129 event.header.fixed_header.event_type.type_name =
130 CORBA::string_dup("examples");
131 // string
132 event.header.fixed_header.event_name =
133 CORBA::string_dup("myevent");
135 // OptionalHeaderFields
136 // PropertySeq
138 // sequence<Property>: string name, any value
139 event.filterable_data.length (3);
140 event.filterable_data[0].name = CORBA::string_dup("Message from:");
141 event.filterable_data[0].value <<= (const char *)user_name;
142 event.filterable_data[1].name = CORBA::string_dup("Subject:");
143 event.filterable_data[1].value <<= (const char *)subject;
144 event.filterable_data[2].name = CORBA::string_dup("Message:");
145 event.filterable_data[2].value <<= (const char *)message;
147 std::cout << "pushing " << std::endl;
148 current_->the_priority(HIGH_PRIORITY);
149 consumer_proxy_->push_structured_event(event);
151 return 1;