Method_Request_Dispatch.cpp

Go to the documentation of this file.
00001 // Method_Request_Dispatch.cpp,v 1.19 2006/03/14 06:14:34 jtc Exp
00002 
00003 #include "orbsvcs/Notify/Method_Request_Dispatch.h"
00004 
00005 ACE_RCSID(Notify, TAO_Notify_Method_Request_Dispatch, "Method_Request_Dispatch.cpp,v 1.19 2006/03/14 06:14:34 jtc Exp")
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 (ACE_ENV_SINGLE_ARG_DECL)
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                                                                   ACE_ENV_ARG_PARAMETER);
00081       ACE_CHECK_RETURN (-1);
00082 
00083       if (TAO_debug_level > 1)
00084         ACE_DEBUG ((LM_DEBUG, "Proxysupplier %x filter eval result = %d",&this->proxy_supplier_ , val));
00085 
00086       // Filter failed - do nothing.
00087       if (val == 0)
00088         return 0;
00089     }
00090 
00091   ACE_TRY
00092     {
00093       TAO_Notify_Consumer* consumer = this->proxy_supplier_->consumer ();
00094 
00095       if (consumer != 0)
00096         {
00097           consumer->deliver (this ACE_ENV_ARG_PARAMETER);
00098           ACE_TRY_CHECK;
00099         }
00100     }
00101   ACE_CATCHANY
00102     {
00103       if (TAO_debug_level > 0)
00104         ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION,
00105         ACE_TEXT ("TAO_Notify_Method_Request_Dispatch::: error sending event.\n ")
00106         );
00107     }
00108   ACE_ENDTRY;
00109 
00110   return 0;
00111 }
00112 
00113 /// Static method used to reconstruct a Method Request Dispatch
00114 TAO_Notify_Method_Request_Dispatch_Queueable *
00115 TAO_Notify_Method_Request_Dispatch::unmarshal (
00116     TAO_Notify::Delivery_Request_Ptr & delivery_request,
00117     TAO_Notify_EventChannelFactory &ecf,
00118     TAO_InputCDR & cdr
00119     ACE_ENV_ARG_DECL)
00120 {
00121   bool ok = true;
00122   TAO_Notify_Method_Request_Dispatch_Queueable * result = 0;
00123   ACE_CString textpath;
00124   CORBA::ULong count;
00125   if (cdr.read_ulong (count))
00126   {
00127     TAO_Notify::IdVec id_path (count);
00128     for (size_t nid = 0; ok && nid < count; ++nid)
00129     {
00130       TAO_Notify_Object::ID id = 0;
00131       if ( cdr.read_long (id))
00132       {
00133         id_path.push_back (id);
00134         char idbuf[20];
00135         ACE_OS::snprintf (idbuf, sizeof(idbuf)-1, "/%d", static_cast<int> (id));
00136         textpath += idbuf;
00137       }
00138       else
00139       {
00140         ok = false;
00141       }
00142     }
00143 
00144     if (ok)
00145     {
00146       TAO_Notify_ProxySupplier* proxy_supplier = ecf.find_proxy_supplier (id_path,
00147         0 ACE_ENV_ARG_PARAMETER);
00148       ACE_CHECK_RETURN(0);
00149       if (proxy_supplier != 0)
00150       {
00151         if (DEBUG_LEVEL > 6) ACE_DEBUG ((LM_DEBUG,
00152           ACE_TEXT ("(%P|%t) TAO_Notify_Method_Request_Dispatch reload event for %s\n")
00153           , textpath.c_str()
00154           ));
00155         ACE_NEW_NORETURN (result,
00156           TAO_Notify_Method_Request_Dispatch_Queueable (delivery_request, proxy_supplier, true));
00157       }
00158       else
00159       {
00160         TAO_Notify_ProxyConsumer * proxy_consumer = ecf.find_proxy_consumer (id_path, 0 ACE_ENV_ARG_PARAMETER); //@@todo
00161         if (proxy_consumer == 0)
00162         {
00163           ACE_ERROR ((LM_ERROR,
00164             ACE_TEXT ("(%P|%t) TAO_Notify_Method_Request_Dispatch::unmarshal: unknown proxy id %s\n")
00165             , textpath.c_str()
00166             ));
00167         }
00168         else
00169         {
00170           ACE_ERROR ((LM_ERROR,
00171             ACE_TEXT ("(%P|%t) TAO_Notify_Method_Request_Dispatch::unmarshal: wrong type of proxy id %s\n")
00172             , textpath.c_str()
00173             ));
00174         }
00175       }
00176     }
00177     else
00178     {
00179       ACE_ERROR ((LM_ERROR,
00180         ACE_TEXT ("(%P|%t) TAO_Notify_Method_Request_Dispatch::unmarshal: Cant read proxy id path\n")
00181         ));
00182     }
00183   }
00184   return result;
00185 }
00186 
00187 ///////////////////////////////////////////////////////////////////////////////
00188 
00189 
00190 /*******************************************************************/
00191 
00192 // Constuct construct from another method request+event
00193 // event is passed separately because we may be using a copy
00194 // of the one in the previous method request
00195 TAO_Notify_Method_Request_Dispatch_Queueable::TAO_Notify_Method_Request_Dispatch_Queueable (
00196       const TAO_Notify_Method_Request_Event & request,
00197       TAO_Notify_Event::Ptr & event,
00198       TAO_Notify_ProxySupplier* proxy_supplier,
00199       bool filtering)
00200   : TAO_Notify_Method_Request_Dispatch (request, event.get (), proxy_supplier, filtering)
00201   , TAO_Notify_Method_Request_Queueable (event.get ())
00202   , event_var_( event )
00203 {
00204 #if 0
00205   ACE_DEBUG ((LM_DEBUG,
00206     ACE_TEXT ("(%P|%t) Construct Method_Request_Dispatch @%@\n"),
00207     this));
00208 #endif
00209 }
00210 
00211   /// Constuct construct from Delivery Request
00212   /// should ONLY be used by unmarshall
00213 TAO_Notify_Method_Request_Dispatch_Queueable::TAO_Notify_Method_Request_Dispatch_Queueable (
00214         const TAO_Notify::Delivery_Request_Ptr & request,
00215         TAO_Notify_ProxySupplier* proxy_supplier,
00216         bool filtering)
00217   : TAO_Notify_Method_Request_Dispatch (request, request->event ().get (), proxy_supplier, filtering)
00218   , TAO_Notify_Method_Request_Queueable (request->event ().get ())
00219   , event_var_( request->event () )
00220 
00221 {
00222 #if 0
00223   ACE_DEBUG ((LM_DEBUG,
00224     ACE_TEXT ("(%P|%t) Construct unmarshalled Method_Request_Dispatch_Queueable  @%@\n"),
00225     this));
00226 #endif
00227 }
00228 
00229 TAO_Notify_Method_Request_Dispatch_Queueable::~TAO_Notify_Method_Request_Dispatch_Queueable ()
00230 {
00231 #if 0
00232   ACE_DEBUG ((LM_DEBUG,
00233     ACE_TEXT ("(%P|%t) Destroy TAO_Notify_Method_Request_Dispatch_Queueable @%@\n"),
00234     this));
00235 #endif
00236 }
00237 
00238 int
00239 TAO_Notify_Method_Request_Dispatch_Queueable::execute (ACE_ENV_SINGLE_ARG_DECL)
00240 {
00241   return this->execute_i (ACE_ENV_SINGLE_ARG_PARAMETER);
00242 }
00243 
00244 /*********************************************************************************************************/
00245 
00246 TAO_Notify_Method_Request_Dispatch_No_Copy::TAO_Notify_Method_Request_Dispatch_No_Copy (
00247       const TAO_Notify_Event* event,
00248       TAO_Notify_ProxySupplier* proxy_supplier,
00249       bool filtering)
00250   : TAO_Notify_Method_Request_Dispatch (event, proxy_supplier, filtering)
00251 {
00252 #if 0
00253     ACE_DEBUG ((LM_DEBUG,
00254       ACE_TEXT ("(%P|%t) Construct Method_Request_Dispatch_No_Copy @%@\n"),
00255       this));
00256 #endif
00257 }
00258   /// Constuct construct from another method request
00259 TAO_Notify_Method_Request_Dispatch_No_Copy::TAO_Notify_Method_Request_Dispatch_No_Copy (
00260       const TAO_Notify_Method_Request_Event & request,
00261       TAO_Notify_ProxySupplier* proxy_supplier,
00262       bool filtering)
00263   : TAO_Notify_Method_Request_Dispatch (request, request.event (), proxy_supplier, filtering)
00264 {
00265 #if 0
00266     ACE_DEBUG ((LM_DEBUG,
00267       ACE_TEXT ("(%P|%t) Construct Method_Request_Dispatch_No_Copy @%@\n"),
00268       this));
00269 #endif
00270 }
00271 
00272 TAO_Notify_Method_Request_Dispatch_No_Copy:: ~TAO_Notify_Method_Request_Dispatch_No_Copy ()
00273 {
00274 #if 0
00275   ACE_DEBUG ((LM_DEBUG,
00276     ACE_TEXT ("(%P|%t) Destroy Method_Request_Dispatch_No_Copy @%@\n"),
00277     this));
00278 #endif
00279 }
00280 
00281 int
00282 TAO_Notify_Method_Request_Dispatch_No_Copy::execute (ACE_ENV_SINGLE_ARG_DECL)
00283 {
00284   return this->execute_i (ACE_ENV_SINGLE_ARG_PARAMETER);
00285 }
00286 
00287 TAO_Notify_Method_Request_Queueable*
00288 TAO_Notify_Method_Request_Dispatch_No_Copy::copy (ACE_ENV_SINGLE_ARG_DECL)
00289 {
00290   TAO_Notify_Method_Request_Queueable* request;
00291 
00292   TAO_Notify_Event::Ptr event_var (
00293     this->event_->queueable_copy (ACE_ENV_SINGLE_ARG_PARAMETER) );
00294   ACE_CHECK_RETURN (0);
00295 
00296   ACE_NEW_THROW_EX (request,
00297                     TAO_Notify_Method_Request_Dispatch_Queueable (*this, event_var, this->proxy_supplier_.get(), this->filtering_),
00298                     //TAO_Notify_Method_Request_Dispatch_Queueable (*this, event_var, this->proxy_supplier_, this->filtering_),
00299                     CORBA::INTERNAL ());
00300 
00301   return request;
00302 }
00303 
00304 TAO_END_VERSIONED_NAMESPACE_DECL

Generated on Thu Nov 9 13:24:12 2006 for TAO_CosNotification by doxygen 1.3.6