Method_Request_Dispatch.cpp

Go to the documentation of this file.
00001 // $Id: Method_Request_Dispatch.cpp 79324 2007-08-13 11:20:01Z elliott_c $
00002 
00003 #include "orbsvcs/Notify/Method_Request_Dispatch.h"
00004 
00005 ACE_RCSID(Notify, TAO_Notify_Method_Request_Dispatch, "$Id: Method_Request_Dispatch.cpp 79324 2007-08-13 11:20:01Z elliott_c $")
00006 
00007 #include "orbsvcs/Notify/ProxySupplier.h"
00008 #include "orbsvcs/Notify/Consumer.h"
00009 #include "orbsvcs/Notify/Admin.h"
00010 #include "orbsvcs/Notify/ConsumerAdmin.h"
00011 #include "orbsvcs/Notify/EventChannelFactory.h"
00012 
00013 #include "tao/debug.h"
00014 #include "tao/CDR.h"
00015 
00016 #include "ace/OS_NS_stdio.h"
00017 
00018 #ifndef DEBUG_LEVEL
00019 # define DEBUG_LEVEL TAO_debug_level
00020 #endif //DEBUG_LEVEL
00021 
00022 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00023 
00024 // Constuct from event
00025 TAO_Notify_Method_Request_Dispatch::TAO_Notify_Method_Request_Dispatch (
00026       const TAO_Notify_Event * event,
00027       TAO_Notify_ProxySupplier* proxy_supplier,
00028       bool filtering)
00029   : TAO_Notify_Method_Request_Event (event)
00030   , proxy_supplier_ (proxy_supplier)
00031   , filtering_ (filtering)
00032 {
00033 }
00034 
00035 // Construct from a delivery rquest
00036 TAO_Notify_Method_Request_Dispatch::TAO_Notify_Method_Request_Dispatch (
00037       const TAO_Notify::Delivery_Request_Ptr & delivery,
00038       TAO_Notify_ProxySupplier* proxy_supplier,
00039       bool filtering)
00040   : TAO_Notify_Method_Request_Event (delivery)
00041   , proxy_supplier_ (proxy_supplier)
00042   , filtering_ (filtering)
00043 {
00044 }
00045 
00046 // Constuct construct from another method request+event
00047 // event is passed separately because we may be using a copy
00048 // of the one in the previous method request
00049 TAO_Notify_Method_Request_Dispatch::TAO_Notify_Method_Request_Dispatch (
00050       const TAO_Notify_Method_Request_Event & request,
00051       const TAO_Notify_Event * event,
00052       TAO_Notify_ProxySupplier* proxy_supplier,
00053       bool filtering)
00054   : TAO_Notify_Method_Request_Event (request, event)
00055   , proxy_supplier_ (proxy_supplier)
00056   , filtering_ (filtering)
00057 {
00058 }
00059 
00060 TAO_Notify_Method_Request_Dispatch::~TAO_Notify_Method_Request_Dispatch ()
00061 {
00062 #if 0
00063   ACE_DEBUG ((LM_DEBUG,
00064               ACE_TEXT ("(%P|%t) Destroy TAO_Notify_Method_Request_Dispatch @%@\n"),
00065               this));
00066 #endif
00067 }
00068 
00069 int TAO_Notify_Method_Request_Dispatch::execute_i (void)
00070 {
00071   if (this->proxy_supplier_->has_shutdown ())
00072     return 0; // If we were shutdown while waiting in the queue, return with no action.
00073 
00074   if (this->filtering_ == 1)
00075     {
00076       TAO_Notify_Admin& parent = this->proxy_supplier_->consumer_admin ();
00077       CORBA::Boolean val =  this->proxy_supplier_->check_filters (this->event_,
00078                                                                   parent.filter_admin (),
00079                                                                   parent.filter_operator ());
00080 
00081       if (TAO_debug_level > 1)
00082         ACE_DEBUG ((LM_DEBUG, "Proxysupplier %x filter eval result = %d",&this->proxy_supplier_ , val));
00083 
00084       // Filter failed - do nothing.
00085       if (val == 0)
00086         return 0;
00087     }
00088 
00089   try
00090     {
00091       TAO_Notify_Consumer* consumer = this->proxy_supplier_->consumer ();
00092 
00093       if (consumer != 0)
00094         {
00095           consumer->deliver (this);
00096         }
00097     }
00098   catch (const CORBA::Exception& ex)
00099     {
00100       if (TAO_debug_level > 0)
00101         ex._tao_print_exception (
00102           ACE_TEXT (
00103             "TAO_Notify_Method_Request_Dispatch::: error sending event.\n "));
00104     }
00105 
00106   return 0;
00107 }
00108 
00109 /// Static method used to reconstruct a Method Request Dispatch
00110 TAO_Notify_Method_Request_Dispatch_Queueable *
00111 TAO_Notify_Method_Request_Dispatch::unmarshal (
00112     TAO_Notify::Delivery_Request_Ptr & delivery_request,
00113     TAO_Notify_EventChannelFactory &ecf,
00114     TAO_InputCDR & cdr)
00115 {
00116   bool ok = true;
00117   TAO_Notify_Method_Request_Dispatch_Queueable * result = 0;
00118   ACE_CString textpath;
00119   CORBA::ULong count;
00120   if (cdr.read_ulong (count))
00121   {
00122     TAO_Notify::IdVec id_path (count);
00123     for (size_t nid = 0; ok && nid < count; ++nid)
00124     {
00125       TAO_Notify_Object::ID id = 0;
00126       if ( cdr.read_long (id))
00127       {
00128         id_path.push_back (id);
00129         char idbuf[20];
00130         ACE_OS::snprintf (idbuf, sizeof(idbuf), "/%d", static_cast<int> (id));
00131         textpath += idbuf;
00132       }
00133       else
00134       {
00135         ok = false;
00136       }
00137     }
00138 
00139     if (ok)
00140     {
00141       TAO_Notify_ProxySupplier* proxy_supplier = ecf.find_proxy_supplier (id_path,
00142         0);
00143       if (proxy_supplier != 0)
00144       {
00145         if (DEBUG_LEVEL > 6) ACE_DEBUG ((LM_DEBUG,
00146           ACE_TEXT ("(%P|%t) TAO_Notify_Method_Request_Dispatch reload event for %s\n")
00147           , textpath.c_str()
00148           ));
00149         ACE_NEW_NORETURN (result,
00150           TAO_Notify_Method_Request_Dispatch_Queueable (delivery_request, proxy_supplier, true));
00151       }
00152       else
00153       {
00154         TAO_Notify_ProxyConsumer * proxy_consumer = ecf.find_proxy_consumer (id_path, 0); //@@todo
00155         if (proxy_consumer == 0)
00156         {
00157           ACE_ERROR ((LM_ERROR,
00158             ACE_TEXT ("(%P|%t) TAO_Notify_Method_Request_Dispatch::unmarshal: unknown proxy id %s\n")
00159             , textpath.c_str()
00160             ));
00161         }
00162         else
00163         {
00164           ACE_ERROR ((LM_ERROR,
00165             ACE_TEXT ("(%P|%t) TAO_Notify_Method_Request_Dispatch::unmarshal: wrong type of proxy id %s\n")
00166             , textpath.c_str()
00167             ));
00168         }
00169       }
00170     }
00171     else
00172     {
00173       ACE_ERROR ((LM_ERROR,
00174         ACE_TEXT ("(%P|%t) TAO_Notify_Method_Request_Dispatch::unmarshal: Cant read proxy id path\n")
00175         ));
00176     }
00177   }
00178   return result;
00179 }
00180 
00181 ///////////////////////////////////////////////////////////////////////////////
00182 
00183 
00184 /*******************************************************************/
00185 
00186 // Constuct construct from another method request+event
00187 // event is passed separately because we may be using a copy
00188 // of the one in the previous method request
00189 TAO_Notify_Method_Request_Dispatch_Queueable::TAO_Notify_Method_Request_Dispatch_Queueable (
00190       const TAO_Notify_Method_Request_Event & request,
00191       TAO_Notify_Event::Ptr & event,
00192       TAO_Notify_ProxySupplier* proxy_supplier,
00193       bool filtering)
00194   : TAO_Notify_Method_Request_Dispatch (request, event.get (), proxy_supplier, filtering)
00195   , TAO_Notify_Method_Request_Queueable (event.get ())
00196   , event_var_( event )
00197 {
00198 #if 0
00199   ACE_DEBUG ((LM_DEBUG,
00200     ACE_TEXT ("(%P|%t) Construct Method_Request_Dispatch @%@\n"),
00201     this));
00202 #endif
00203 }
00204 
00205   /// Constuct construct from Delivery Request
00206   /// should ONLY be used by unmarshall
00207 TAO_Notify_Method_Request_Dispatch_Queueable::TAO_Notify_Method_Request_Dispatch_Queueable (
00208         const TAO_Notify::Delivery_Request_Ptr & request,
00209         TAO_Notify_ProxySupplier* proxy_supplier,
00210         bool filtering)
00211   : TAO_Notify_Method_Request_Dispatch (request, request->event ().get (), proxy_supplier, filtering)
00212   , TAO_Notify_Method_Request_Queueable (request->event ().get ())
00213   , event_var_( request->event () )
00214 
00215 {
00216 #if 0
00217   ACE_DEBUG ((LM_DEBUG,
00218     ACE_TEXT ("(%P|%t) Construct unmarshalled Method_Request_Dispatch_Queueable  @%@\n"),
00219     this));
00220 #endif
00221 }
00222 
00223 TAO_Notify_Method_Request_Dispatch_Queueable::~TAO_Notify_Method_Request_Dispatch_Queueable ()
00224 {
00225 #if 0
00226   ACE_DEBUG ((LM_DEBUG,
00227     ACE_TEXT ("(%P|%t) Destroy TAO_Notify_Method_Request_Dispatch_Queueable @%@\n"),
00228     this));
00229 #endif
00230 }
00231 
00232 int
00233 TAO_Notify_Method_Request_Dispatch_Queueable::execute (void)
00234 {
00235   return this->execute_i ();
00236 }
00237 
00238 /*********************************************************************************************************/
00239 
00240   /// Constuct construct from another method request
00241 TAO_Notify_Method_Request_Dispatch_No_Copy::TAO_Notify_Method_Request_Dispatch_No_Copy (
00242       const TAO_Notify_Method_Request_Event & request,
00243       TAO_Notify_ProxySupplier* proxy_supplier,
00244       bool filtering)
00245   : TAO_Notify_Method_Request_Dispatch (request, request.event (), proxy_supplier, filtering)
00246 {
00247 #if 0
00248     ACE_DEBUG ((LM_DEBUG,
00249       ACE_TEXT ("(%P|%t) Construct Method_Request_Dispatch_No_Copy @%@\n"),
00250       this));
00251 #endif
00252 }
00253 
00254 TAO_Notify_Method_Request_Dispatch_No_Copy:: ~TAO_Notify_Method_Request_Dispatch_No_Copy ()
00255 {
00256 #if 0
00257   ACE_DEBUG ((LM_DEBUG,
00258     ACE_TEXT ("(%P|%t) Destroy Method_Request_Dispatch_No_Copy @%@\n"),
00259     this));
00260 #endif
00261 }
00262 
00263 int
00264 TAO_Notify_Method_Request_Dispatch_No_Copy::execute (void)
00265 {
00266   return this->execute_i ();
00267 }
00268 
00269 TAO_Notify_Method_Request_Queueable*
00270 TAO_Notify_Method_Request_Dispatch_No_Copy::copy (void)
00271 {
00272   TAO_Notify_Method_Request_Queueable* request;
00273 
00274   TAO_Notify_Event::Ptr event_var (
00275     this->event_->queueable_copy () );
00276 
00277   ACE_NEW_THROW_EX (request,
00278                     TAO_Notify_Method_Request_Dispatch_Queueable (*this, event_var, this->proxy_supplier_.get(), this->filtering_),
00279                     //TAO_Notify_Method_Request_Dispatch_Queueable (*this, event_var, this->proxy_supplier_, this->filtering_),
00280                     CORBA::INTERNAL ());
00281 
00282   return request;
00283 }
00284 
00285 TAO_END_VERSIONED_NAMESPACE_DECL

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