Admin.cpp

Go to the documentation of this file.
00001 // $Id: Admin.cpp 81418 2008-04-24 11:11:22Z johnnyw $
00002 #include "orbsvcs/Notify/Admin.h"
00003 
00004 #if ! defined (__ACE_INLINE__)
00005 #include "orbsvcs/Notify/Admin.inl"
00006 #endif /* __ACE_INLINE__ */
00007 
00008 ACE_RCSID (Notify,
00009            TAO_Notify_Admin,
00010            "$Id: Admin.cpp 81418 2008-04-24 11:11:22Z johnnyw $")
00011 
00012 #include "orbsvcs/CosNotifyChannelAdminC.h"
00013 
00014 #include "orbsvcs/Notify/Container_T.h"
00015 #include "orbsvcs/Notify/Proxy.h"
00016 #include "orbsvcs/Notify/EventChannel.h"
00017 #include "orbsvcs/Notify/Topology_Saver.h"
00018 #include "orbsvcs/Notify/Save_Persist_Worker_T.h"
00019 #include "orbsvcs/Notify/Reconnect_Worker_T.h"
00020 #include "orbsvcs/Notify/Consumer_Map.h"
00021 #include "orbsvcs/Notify/Supplier_Map.h"
00022 #include "orbsvcs/Notify/ConsumerAdmin.h"
00023 #include "orbsvcs/Notify/SupplierAdmin.h"
00024 
00025 #include "tao/debug.h"
00026 
00027 //#define DEBUG_LEVEL 9
00028 #ifndef DEBUG_LEVEL
00029 # define DEBUG_LEVEL TAO_debug_level
00030 #endif //DEBUG_LEVEL
00031 
00032 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00033 
00034 TAO_Notify_Admin::TAO_Notify_Admin ()
00035   : ec_ (0)
00036   , filter_operator_ (CosNotifyChannelAdmin::OR_OP)
00037   , is_default_ (false)
00038 {
00039   // Initialize all Admin objects to initially be subscribed for all
00040   // events.  This is a reasonable default and is required to allow
00041   // Cos Event consumers/suppliers to send/receive events,
00042   this->subscribed_types_.insert (TAO_Notify_EventType::special ());
00043 }
00044 
00045 TAO_Notify_Admin::~TAO_Notify_Admin ()
00046 {
00047 }
00048 
00049 void
00050 TAO_Notify_Admin::init (TAO_Notify::Topology_Parent* parent)
00051 {
00052   ACE_ASSERT (this->ec_.get() == 0);
00053 
00054   this->ec_.reset (dynamic_cast<TAO_Notify_EventChannel *>(parent));
00055   ACE_ASSERT (this->ec_.get() != 0);
00056 
00057   // this-> on the following line confuses VC6
00058   initialize (parent);
00059 
00060   TAO_Notify_Proxy_Container* proxy_container = 0;
00061   ACE_NEW_THROW_EX (proxy_container,
00062                     TAO_Notify_Proxy_Container (),
00063                     CORBA::INTERNAL ());
00064   this->proxy_container_.reset (proxy_container);
00065 
00066   this->proxy_container().init ();
00067 
00068 }
00069 
00070 void
00071 TAO_Notify_Admin::cleanup_proxy (TAO_Notify_Proxy *proxy
00072                                  , bool is_supplier)
00073 {
00074   // We must clean up the proxy before calling remove.  Doing it in the
00075   // opposite order causes us to use invalid memory (through the call of
00076   // id() into the proxy).
00077   ec_->cleanup_proxy (proxy->id(), is_supplier);
00078 
00079   this->remove (proxy);
00080 }
00081 
00082 void
00083 TAO_Notify_Admin::remove (TAO_Notify_Proxy* proxy)
00084 {
00085   this->proxy_container().remove (proxy);
00086 }
00087 
00088 void
00089 TAO_Notify_Admin::subscribed_types (TAO_Notify_EventTypeSeq& subscribed_types)
00090 {
00091   ACE_GUARD_THROW_EX (TAO_SYNCH_MUTEX, ace_mon, this->lock_,
00092                       CORBA::INTERNAL ());
00093 
00094   // Adopt the Admin's subscription.
00095   TAO_Notify_EventTypeSeq added (this->subscribed_types_), removed;
00096 
00097   added.add_and_remove (subscribed_types, removed);
00098 
00099   subscribed_types = added;
00100 }
00101 
00102 int
00103 TAO_Notify_Admin::shutdown (void)
00104 {
00105   if (TAO_Notify_Object::shutdown () == 1)
00106     return 1;
00107 
00108   this->proxy_container().shutdown ();
00109 
00110   return 0;
00111 }
00112 
00113 void
00114 TAO_Notify_Admin::insert (TAO_Notify_Proxy* proxy)
00115 {
00116   this->proxy_container().insert (proxy);
00117 }
00118 
00119 void
00120 TAO_Notify_Admin::save_persistent (TAO_Notify::Topology_Saver& saver)
00121 {
00122   bool changed = this->children_changed_;
00123   this->children_changed_ = false;
00124   this->self_changed_ = false;
00125 
00126   if (is_persistent ())
00127     {
00128       TAO_Notify::NVPList attrs;
00129       this->save_attrs(attrs);
00130 
00131       const char* type = this->get_admin_type_name();
00132 
00133       bool want_all_children =
00134         saver.begin_object(this->id(), type, attrs, changed);
00135 
00136       if (want_all_children || this->filter_admin_.is_changed ())
00137         {
00138           this->filter_admin_.save_persistent(saver);
00139         }
00140       if (want_all_children || this->subscribed_types_.is_changed ())
00141         {
00142           this->subscribed_types_.save_persistent(saver);
00143         }
00144 
00145       TAO_Notify::Save_Persist_Worker<TAO_Notify_Proxy>
00146         wrk(saver, want_all_children);
00147       this->proxy_container().collection()->for_each(&wrk);
00148 
00149       saver.end_object(this->id(), type);
00150     }
00151 }
00152 
00153 void
00154 TAO_Notify_Admin::save_attrs (TAO_Notify::NVPList& attrs)
00155 {
00156   TAO_Notify_Object::save_attrs(attrs);
00157   attrs.push_back(TAO_Notify::NVP("InterFilterGroupOperator",
00158                                   this->filter_operator_));
00159   if (this->is_default_)
00160     {
00161       attrs.push_back (TAO_Notify::NVP ("default", "yes"));
00162     }
00163 }
00164 
00165 void
00166 TAO_Notify_Admin::load_attrs(const TAO_Notify::NVPList& attrs)
00167 {
00168   TAO_Notify_Object::load_attrs (attrs);
00169   const char* value = 0;
00170   if (attrs.find ("InterFilterGroupOperator", value))
00171     {
00172       this->filter_operator_ = static_cast <CosNotifyChannelAdmin::InterFilterGroupOperator> (ACE_OS::atoi (value));
00173     }
00174 
00175   if (attrs.find ("default", value))
00176     {
00177       this->is_default_ = (ACE_OS::strcmp (value, "yes") == 0);
00178     }
00179 }
00180 
00181 TAO_Notify::Topology_Object*
00182 TAO_Notify_Admin::load_child (const ACE_CString &type,
00183                               CORBA::Long id,
00184                               const TAO_Notify::NVPList& attrs)
00185 {
00186   ACE_UNUSED_ARG (attrs);
00187   TAO_Notify::Topology_Object* result = this;
00188   if (type == "subscriptions")
00189     {
00190       if (DEBUG_LEVEL)
00191         ACE_DEBUG ((LM_DEBUG,
00192                     ACE_TEXT ("(%P|%t) Admin reload subscription %d\n"),
00193                     static_cast<int> (id)
00194                     ));
00195       // since we initialized our subscribed types to everything
00196       // in the constructor. we have to clear it out first.
00197       this->subscribed_types_.reset();
00198       result = &this->subscribed_types_;
00199     }
00200   else if (type == "filter_admin")
00201     {
00202       if (DEBUG_LEVEL)
00203         ACE_DEBUG ((LM_DEBUG,
00204                     ACE_TEXT ("(%P|%t) Admin reload filter_admin %d\n"),
00205                     static_cast<int> (id)
00206                     ));
00207       result = & this->filter_admin_;
00208     }
00209   return result;
00210 }
00211 
00212 void
00213 TAO_Notify_Admin::reconnect (void)
00214 {
00215   TAO_Notify::Reconnect_Worker<TAO_Notify_Proxy> wrk;
00216   this->proxy_container().collection()->for_each(&wrk);
00217 }
00218 
00219 TAO_END_VERSIONED_NAMESPACE_DECL

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