Merge pull request #1551 from DOCGroup/plm_jira_333
[ACE_TAO.git] / TAO / orbsvcs / examples / Notify / Lanes / Consumer.cpp
blob1b5f39bdc88927901bd19ee7cb5219ef9d35a0a4
1 #include "Consumer.h"
3 TAO_Notify_Lanes_Consumer::TAO_Notify_Lanes_Consumer (TAO_Notify_ORB_Objects& orb_objects)
4 : orb_objects_ (orb_objects)
8 TAO_Notify_Lanes_Consumer::~TAO_Notify_Lanes_Consumer (void)
12 void
13 TAO_Notify_Lanes_Consumer::init (PortableServer::POA_var& poa, CosNotifyChannelAdmin::ConsumerAdmin_var& admin, ACE_CString& event_type)
15 this->default_POA_ = poa;
16 this->admin_ = admin;
17 this->event_type_ = event_type;
19 this->connect ();
22 PortableServer::POA_ptr
23 TAO_Notify_Lanes_Consumer::_default_POA (void)
25 return PortableServer::POA::_duplicate (this->default_POA_.in ());
28 void
29 TAO_Notify_Lanes_Consumer::run (void)
31 // Nothing to do.
34 void
35 TAO_Notify_Lanes_Consumer::connect (void)
37 // Activate the consumer with the default_POA_
38 CosNotifyComm::StructuredPushConsumer_var objref = this->_this ();
40 CosNotifyChannelAdmin::ProxySupplier_var proxysupplier =
41 this->admin_->obtain_notification_push_supplier (CosNotifyChannelAdmin::STRUCTURED_EVENT
42 , proxy_supplier_id_);
44 ACE_ASSERT (!CORBA::is_nil (proxysupplier.in ()));
46 // narrow
47 this->proxy_supplier_ =
48 CosNotifyChannelAdmin::StructuredProxyPushSupplier::_narrow (proxysupplier.in ());
50 ACE_ASSERT (!CORBA::is_nil (proxy_supplier_.in ()));
52 this->proxy_supplier_->connect_structured_push_consumer (objref.in ());
54 // Call subscription_change to inform the supplier that this consumer is available.
55 CosNotification::EventTypeSeq added (1);
56 CosNotification::EventTypeSeq removed;
58 added.length (1);
59 added[0].domain_name = CORBA::string_dup ("TEST_DOMAIN");
60 added[0].type_name = CORBA::string_dup (this->event_type_.c_str ());
62 this->proxy_supplier_->subscription_change (added, removed);
65 void
66 TAO_Notify_Lanes_Consumer::disconnect (void)
68 this->proxy_supplier_->disconnect_structured_push_supplier();
71 void
72 TAO_Notify_Lanes_Consumer::offer_change (const CosNotification::EventTypeSeq & /*added*/,
73 const CosNotification::EventTypeSeq & /*removed*/)
75 // No-Op.
78 void
79 TAO_Notify_Lanes_Consumer::push_structured_event (const CosNotification::StructuredEvent & notification)
81 try
83 // Check the current threads priority.
84 RTCORBA::Priority thread_priority =
85 this->orb_objects_.current_->the_priority ();
87 const CosNotification::PropertySeq& prop_seq = notification.header.variable_header;
89 // Extract the priority at which the supplier send it.
90 RTCORBA::Priority event_priority = 0;
92 for (CORBA::ULong i = 0; i < prop_seq.length (); ++i)
94 if (ACE_OS::strcmp (prop_seq[i].name.in (), CosNotification::Priority) == 0)
95 prop_seq[i].value >>= event_priority;
98 ACE_DEBUG ((LM_DEBUG, "(%P, %t) Consumer received event with priority = %d and thread priority = %d\n",
99 event_priority, thread_priority));
101 // The current thread priority and the event priority must match.
102 if (event_priority != thread_priority)
103 ACE_DEBUG ((LM_DEBUG, "(%P, %t) Error: Event priority and thread priority are different.\n"));
105 // Disconnect from the EC
106 this->disconnect ();
108 // Deactivate this object.
109 this->deactivate ();
111 // We received the event, shutdown the ORB.
112 this->orb_objects_.orb_->shutdown (1);
114 catch (const CORBA::Exception& ex)
116 ex._tao_print_exception (ACE_TEXT ("Consumer error "));
118 return;
122 void
123 TAO_Notify_Lanes_Consumer::deactivate (void)
125 PortableServer::POA_var poa (this->_default_POA ());
127 PortableServer::ObjectId_var id (poa->servant_to_id (this));
129 poa->deactivate_object (id.in());
132 void
133 TAO_Notify_Lanes_Consumer::disconnect_structured_push_consumer (void)
135 this->deactivate ();