Proxy.cpp

Go to the documentation of this file.
00001 // $Id: Proxy.cpp 77001 2007-02-12 07:54:49Z johnnyw $
00002 
00003 #include "orbsvcs/Notify/Proxy.h"
00004 
00005 #if ! defined (__ACE_INLINE__)
00006 #include "orbsvcs/Notify/Proxy.inl"
00007 #endif /* __ACE_INLINE__ */
00008 
00009 ACE_RCSID(Notify, TAO_Notify_Proxy, "$Id: Proxy.cpp 77001 2007-02-12 07:54:49Z johnnyw $")
00010 
00011 #include "orbsvcs/Notify/Peer.h"
00012 #include "orbsvcs/Notify/Proxy.h"
00013 #include "orbsvcs/Notify/Method_Request_Updates.h"
00014 #include "orbsvcs/Notify/Worker_Task.h"
00015 #include "orbsvcs/Notify/Properties.h"
00016 #include "orbsvcs/Notify/POA_Helper.h"
00017 #include "orbsvcs/Notify/Topology_Saver.h"
00018 
00019 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00020 
00021 TAO_Notify_Proxy::TAO_Notify_Proxy (void)
00022   : updates_off_ (0)
00023 {
00024 }
00025 
00026 TAO_Notify_Proxy::~TAO_Notify_Proxy ()
00027 {
00028 }
00029 
00030 CORBA::Object_ptr
00031 TAO_Notify_Proxy::activate (PortableServer::Servant servant)
00032 {
00033   // Set the POA that we use to return our <ref>
00034   this->set_primary_as_proxy_poa();
00035   return TAO_Notify_Object::activate (servant);
00036 }
00037 
00038 CORBA::Object_ptr
00039 TAO_Notify_Proxy::activate (PortableServer::Servant servant,
00040                             CORBA::Long id)
00041 {
00042   // Set the POA that we use to return our <ref>
00043   this->set_primary_as_proxy_poa();
00044   return TAO_Notify_Object::activate (servant, id);
00045 }
00046 
00047 void
00048 TAO_Notify_Proxy::deactivate (void)
00049 {
00050   ACE_ASSERT (this->proxy_poa() != 0 );
00051   this->proxy_poa()->deactivate (this->id());
00052 }
00053 
00054 void
00055 TAO_Notify_Proxy::subscribed_types (TAO_Notify_EventTypeSeq& subscribed_types)
00056 {
00057   ACE_GUARD_THROW_EX (TAO_SYNCH_MUTEX, ace_mon, this->lock_,
00058                         CORBA::INTERNAL ());
00059 
00060   // copy
00061   subscribed_types = this->subscribed_types_;
00062 }
00063 
00064 void
00065 TAO_Notify_Proxy::types_changed (const TAO_Notify_EventTypeSeq& added, const TAO_Notify_EventTypeSeq& removed)
00066 {
00067   // return if the updates for this proxy are turned off or
00068   // if all the updates in the channel are switched off.
00069   if (this->updates_off_ == 1 || TAO_Notify_PROPERTIES::instance()->updates () == 0)
00070     return;
00071 
00072   TAO_Notify_Method_Request_Updates_No_Copy request (added, removed, this);
00073 
00074   if (TAO_Notify_PROPERTIES::instance()->asynch_updates () == 1) // if we should send the updates synchronously.
00075     {
00076       this->execute_task (request);
00077     }
00078   else // execute in the current thread context.
00079     {
00080       request.execute ();
00081     }
00082 }
00083 
00084 CosNotification::EventTypeSeq*
00085 TAO_Notify_Proxy::obtain_types (CosNotifyChannelAdmin::ObtainInfoMode mode, const TAO_Notify_EventTypeSeq& types)
00086 {
00087   CosNotification::EventTypeSeq_var event_type_seq;
00088 
00089   ACE_NEW_THROW_EX (event_type_seq,
00090                     CosNotification::EventTypeSeq (),
00091                     CORBA::NO_MEMORY ());
00092 
00093   ACE_GUARD_THROW_EX (TAO_SYNCH_MUTEX, ace_mon, this->lock_, CORBA::INTERNAL ());
00094 
00095   if (mode == CosNotifyChannelAdmin::ALL_NOW_UPDATES_OFF ||
00096       mode == CosNotifyChannelAdmin::ALL_NOW_UPDATES_ON)
00097     {
00098       types.populate (event_type_seq);
00099     }
00100 
00101   if (mode == CosNotifyChannelAdmin::NONE_NOW_UPDATES_ON ||
00102       mode == CosNotifyChannelAdmin::ALL_NOW_UPDATES_ON)
00103     {
00104       this->updates_off_ = 0;
00105     }
00106   else
00107     {
00108       this->updates_off_ = 1;
00109     }
00110 
00111   return event_type_seq._retn ();
00112 }
00113 
00114 void
00115 TAO_Notify_Proxy::qos_changed (const TAO_Notify_QoSProperties& qos_properties)
00116 {
00117   //Inform Peers of qos changes.
00118   TAO_Notify_Peer* peer = this->peer ();
00119 
00120   if (peer != 0)
00121     peer->qos_changed (qos_properties);
00122 }
00123 
00124 void
00125 TAO_Notify_Proxy::save_persistent (TAO_Notify::Topology_Saver& saver)
00126 {
00127   bool changed = this->children_changed_;
00128   this->children_changed_ = false;
00129   this->self_changed_ = false;
00130 
00131   if (is_persistent ())
00132   {
00133     TAO_Notify::NVPList attrs;
00134     this->save_attrs(attrs);
00135 
00136     const char * type_name = this->get_proxy_type_name ();
00137     bool want_all_children = saver.begin_object(this->id(), type_name, attrs, changed);
00138 
00139     if (want_all_children || this->filter_admin_.is_changed ())
00140     {
00141       this->filter_admin_.save_persistent(saver);
00142     }
00143 
00144     if (want_all_children || this->subscribed_types_.is_changed ())
00145     {
00146       this->subscribed_types_.save_persistent(saver);
00147     }
00148 
00149     // todo: handle removed children
00150 
00151     saver.end_object(this->id(), type_name);
00152   }
00153 }
00154 
00155 void
00156 TAO_Notify_Proxy::save_attrs (TAO_Notify::NVPList& attrs)
00157 {
00158   TAO_Notify_Object::save_attrs(attrs);
00159   TAO_Notify_Peer * peer = this->peer();
00160   if (peer != 0)
00161   {
00162     attrs.push_back (TAO_Notify::NVP("PeerIOR", peer->get_ior()));
00163   }
00164 }
00165 
00166 TAO_Notify::Topology_Object*
00167 TAO_Notify_Proxy::load_child (const ACE_CString &type, CORBA::Long id,
00168   const TAO_Notify::NVPList& attrs)
00169 {
00170   ACE_UNUSED_ARG (id);
00171   ACE_UNUSED_ARG (attrs);
00172   TAO_Notify::Topology_Object* result = this;
00173   if (type == "subscriptions")
00174   {
00175     // since we initialized our subscribed types to everything
00176     // in the constructor. we have to clear it out first.
00177     this->subscribed_types_.reset();
00178     result = &this->subscribed_types_;
00179   }
00180   else if (type == "filter_admin")
00181   {
00182     result = & this->filter_admin_;
00183   }
00184   return result;
00185 }
00186 
00187 TAO_END_VERSIONED_NAMESPACE_DECL

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