PushConsumer.cpp

Go to the documentation of this file.
00001 // $Id: PushConsumer.cpp 76626 2007-01-26 13:50:03Z elliott_c $
00002 
00003 #include "orbsvcs/Notify/Any/PushConsumer.h"
00004 
00005 ACE_RCSID (Notify,
00006            TAO_Notify_PushConsumer,
00007            "$Id: PushConsumer.cpp 76626 2007-01-26 13:50:03Z elliott_c $")
00008 
00009 #include "ace/Bound_Ptr.h"
00010 #include "tao/Stub.h" // For debug messages printing out ORBid.
00011 #include "tao/ORB_Core.h"
00012 #include "orbsvcs/CosEventCommC.h"
00013 #include "orbsvcs/Notify/Event.h"
00014 #include "orbsvcs/Notify/Properties.h"
00015 
00016 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00017 
00018 TAO_Notify_PushConsumer::TAO_Notify_PushConsumer (TAO_Notify_ProxySupplier* proxy)
00019   :TAO_Notify_Consumer (proxy)
00020 {
00021 }
00022 
00023 TAO_Notify_PushConsumer::~TAO_Notify_PushConsumer ()
00024 {
00025 }
00026 
00027 void
00028 TAO_Notify_PushConsumer::init (CosEventComm::PushConsumer_ptr push_consumer)
00029 {
00030   // Initialize only once
00031   ACE_ASSERT( CORBA::is_nil (this->push_consumer_.in()) );
00032 
00033   // push_consumer not optional
00034   if (CORBA::is_nil (push_consumer))
00035   {
00036     throw CORBA::BAD_PARAM();
00037   }
00038 
00039   try
00040   {
00041     if (!TAO_Notify_PROPERTIES::instance()->separate_dispatching_orb ())
00042       {
00043         this->push_consumer_ = CosEventComm::PushConsumer::_duplicate (push_consumer);
00044 
00045         this->publish_ =
00046           CosNotifyComm::NotifyPublish::_narrow (push_consumer);
00047       }
00048     else
00049       {
00050         // "Port" consumer's object reference from receiving ORB to dispatching ORB.
00051         CORBA::String_var temp =
00052           TAO_Notify_PROPERTIES::instance()->orb()->object_to_string(push_consumer);
00053 
00054         CORBA::Object_var obj =
00055           TAO_Notify_PROPERTIES::instance()->dispatching_orb()->string_to_object(temp.in());
00056 
00057         CosEventComm::PushConsumer_var new_cos_comm_pc =
00058           CosEventComm::PushConsumer::_unchecked_narrow(obj.in());
00059 
00060         this->push_consumer_ =
00061           CosEventComm::PushConsumer::_duplicate (new_cos_comm_pc.in());
00062 
00063         //
00064         // Note that here we do an _unchecked_narrow() in order to avoid
00065         // making a call on the consumer b/c the consumer may not have activated
00066         // its POA just yet.  That means that before we use this reference the first
00067         // time, we'll actually need to call _is_a() on it, i.e., the equivalent
00068         // of an _narrow().  At the time of this writing, the only use of
00069         // this->publish_ is in TAO_NS_Consumer::dispatch_updates_i (the superclass).
00070         // If any other use is made of this data member, then the code to validate
00071         // the actual type of the target object must be refactored.
00072         this->publish_ =
00073           CosNotifyComm::NotifyPublish::_unchecked_narrow (obj.in());
00074 
00075 
00076         //--cj verify dispatching ORB
00077         if (TAO_debug_level >= 10)
00078           {
00079             ACE_DEBUG ((LM_DEBUG, "(%P|%t) Any push init dispatching ORB id is %s.\n",
00080                         obj->_stubobj()->orb_core()->orbid()));
00081           }
00082         //--cj end
00083       }
00084   }
00085   catch (const CORBA::TRANSIENT& ex)
00086     {
00087       ex._tao_print_exception ("Got a TRANSIENT in NS_PushConsumer::init");
00088       ACE_DEBUG ((LM_DEBUG, "(%P|%t) got it for NS_PushConsumer %@\n", this));
00089     }
00090   catch (const CORBA::Exception&)
00091     {
00092       // _narrow failed which probably means the interface is CosEventComm type.
00093     }
00094 }
00095 
00096 void
00097 TAO_Notify_PushConsumer::release (void)
00098 {
00099   delete this;
00100   //@@ inform factory
00101 }
00102 
00103 void
00104 TAO_Notify_PushConsumer::push (const CORBA::Any& payload)
00105 {
00106   //--cj verify dispatching ORB
00107   if (TAO_debug_level >= 10) {
00108     ACE_DEBUG ((LM_DEBUG, "(%P|%t) Any push dispatching ORB id is %s.\n",
00109                 this->push_consumer_->_stubobj()->orb_core()->orbid()));
00110   }
00111   //--cj end
00112 
00113   this->push_consumer_->push (payload);
00114 }
00115 
00116 void
00117 TAO_Notify_PushConsumer::push (const CosNotification::StructuredEvent& event)
00118 {
00119   CORBA::Any any;
00120 
00121   TAO_Notify_Event::translate (event, any);
00122 
00123   this->push_consumer_->push (any);
00124 }
00125 
00126 /// Push a batch of events to this consumer.
00127 void
00128 TAO_Notify_PushConsumer::push (const CosNotification::EventBatch& event)
00129 {
00130   ACE_ASSERT(false);
00131   ACE_UNUSED_ARG (event);
00132   // TODO exception?
00133 }
00134 
00135 ACE_CString
00136 TAO_Notify_PushConsumer::get_ior (void) const
00137 {
00138   ACE_CString result;
00139   CORBA::ORB_var orb = TAO_Notify_PROPERTIES::instance()->orb();
00140   try
00141     {
00142       CORBA::String_var ior = orb->object_to_string(this->push_consumer_.in());
00143       result = static_cast<const char*> (ior.in ());
00144     }
00145   catch (const CORBA::Exception&)
00146     {
00147       result.fast_clear();
00148     }
00149   return result;
00150 }
00151 
00152 void
00153 TAO_Notify_PushConsumer::reconnect_from_consumer (TAO_Notify_Consumer* old_consumer)
00154 {
00155   TAO_Notify_PushConsumer* tmp =
00156     dynamic_cast<TAO_Notify_PushConsumer*> (old_consumer);
00157   ACE_ASSERT(tmp != 0);
00158   this->init(tmp->push_consumer_.in());
00159   this->schedule_timer(false);
00160 }
00161 
00162 TAO_END_VERSIONED_NAMESPACE_DECL

Generated on Tue Feb 2 17:45:29 2010 for TAO_CosNotification by  doxygen 1.4.7