Event_Manager.cpp

Go to the documentation of this file.
00001 // Event_Manager.cpp,v 1.16 2006/03/14 06:14:34 jtc Exp
00002 
00003 #include "orbsvcs/Notify/Event_Manager.h"
00004 
00005 ACE_RCSID(Notify, TAO_Notify_Event_Manager, "Event_Manager.cpp,v 1.16 2006/03/14 06:14:34 jtc Exp")
00006 
00007 #include "orbsvcs/Notify/ProxyConsumer.h"
00008 #include "orbsvcs/Notify/ProxySupplier.h"
00009 #include "orbsvcs/Notify/Consumer_Map.h"
00010 #include "orbsvcs/Notify/Supplier_Map.h"
00011 #include "orbsvcs/Notify/Event_Map_T.h"
00012 
00013 #include "orbsvcs/ESF/ESF_Worker.h"
00014 #include "orbsvcs/ESF/ESF_Proxy_Collection.h"
00015 
00016 #include "tao/debug.h"
00017 
00018 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00019 
00020 /*****************************************************************************/
00021 
00022 /**
00023  * @class TAO_Notify_ProxyConsumer_Update_Worker
00024  *
00025  * @brief Inform ProxyConsumer of updates.
00026  *
00027  */
00028 class TAO_Notify_Serv_Export TAO_Notify_ProxyConsumer_Update_Worker : public TAO_ESF_Worker<TAO_Notify_ProxyConsumer>
00029 {
00030 public:
00031   TAO_Notify_ProxyConsumer_Update_Worker (const TAO_Notify_EventTypeSeq& added, const TAO_Notify_EventTypeSeq& removed);
00032 
00033 protected:
00034   ///= TAO_ESF_Worker method
00035   void work (TAO_Notify_ProxyConsumer* proxy ACE_ENV_ARG_DECL);
00036 
00037   const TAO_Notify_EventTypeSeq& added_;
00038   const TAO_Notify_EventTypeSeq& removed_;
00039 };
00040 
00041 /********************************************************************************/
00042 
00043 /**
00044  * @class TAO_Notify_ProxySupplier_Update_Worker
00045  *
00046  * @brief Inform ProxySupplier of updates.
00047  *
00048  */
00049 class TAO_Notify_Serv_Export TAO_Notify_ProxySupplier_Update_Worker : public TAO_ESF_Worker<TAO_Notify_ProxySupplier>
00050 {
00051 public:
00052   TAO_Notify_ProxySupplier_Update_Worker (const TAO_Notify_EventTypeSeq& added, const TAO_Notify_EventTypeSeq& removed);
00053 
00054 protected:
00055   ///= TAO_ESF_Worker method
00056   void work (TAO_Notify_ProxySupplier* proxy ACE_ENV_ARG_DECL);
00057 
00058   const TAO_Notify_EventTypeSeq& added_;
00059   const TAO_Notify_EventTypeSeq& removed_;
00060 };
00061 
00062 /********************************************************************************/
00063 
00064 TAO_Notify_Event_Manager::TAO_Notify_Event_Manager (void)
00065 {
00066 }
00067 
00068 TAO_Notify_Event_Manager::~TAO_Notify_Event_Manager ()
00069 {
00070   if (TAO_debug_level > 0)
00071     {
00072       ACE_DEBUG ((LM_DEBUG, "destroying consumer/supplier map count = %d/%d, \n",
00073                   this->consumer_map().proxy_count (), this->supplier_map().proxy_count ()));
00074     }
00075 }
00076 
00077 void TAO_Notify_Event_Manager::release()
00078 {
00079   delete this;
00080 }
00081 
00082 void
00083 TAO_Notify_Event_Manager::init (ACE_ENV_SINGLE_ARG_DECL)
00084 {
00085   ACE_ASSERT (this->consumer_map_.get() == 0);
00086 
00087   TAO_Notify_Consumer_Map* consumer_map = 0;
00088   ACE_NEW_THROW_EX (consumer_map,
00089                     TAO_Notify_Consumer_Map (),
00090                     CORBA::NO_MEMORY ());
00091   ACE_CHECK;
00092   this->consumer_map_.reset( consumer_map );
00093 
00094   this->consumer_map().init (ACE_ENV_SINGLE_ARG_PARAMETER);
00095   ACE_CHECK;
00096 
00097   TAO_Notify_Supplier_Map* supplier_map = 0;
00098   ACE_NEW_THROW_EX (supplier_map,
00099                     TAO_Notify_Supplier_Map (),
00100                     CORBA::NO_MEMORY ());
00101   ACE_CHECK;
00102   this->supplier_map_.reset( supplier_map );
00103 
00104   this->supplier_map_->init (ACE_ENV_SINGLE_ARG_PARAMETER);
00105   ACE_CHECK;
00106 }
00107 
00108 void
00109 TAO_Notify_Event_Manager::shutdown (void)
00110 {
00111 }
00112 
00113 void
00114 TAO_Notify_Event_Manager::connect (TAO_Notify_ProxySupplier* proxy_supplier ACE_ENV_ARG_DECL)
00115 {
00116   this->consumer_map().connect (proxy_supplier ACE_ENV_ARG_PARAMETER);
00117   ACE_CHECK;
00118 
00119   // Inform about offered types.
00120   TAO_Notify_EventTypeSeq removed;
00121   proxy_supplier->types_changed (this->offered_types (), removed ACE_ENV_ARG_PARAMETER);
00122   ACE_CHECK;
00123 }
00124 
00125 void
00126 TAO_Notify_Event_Manager::disconnect (TAO_Notify_ProxySupplier* proxy_supplier ACE_ENV_ARG_DECL)
00127 {
00128   this->consumer_map().disconnect (proxy_supplier ACE_ENV_ARG_PARAMETER);
00129 }
00130 
00131 void
00132 TAO_Notify_Event_Manager::connect (TAO_Notify_ProxyConsumer* proxy_consumer ACE_ENV_ARG_DECL)
00133 {
00134   this->supplier_map().connect (proxy_consumer ACE_ENV_ARG_PARAMETER);
00135   ACE_CHECK;
00136   // Inform about subscription types.
00137   TAO_Notify_EventTypeSeq removed;
00138   proxy_consumer->types_changed (this->subscription_types (), removed ACE_ENV_ARG_PARAMETER);
00139 }
00140 
00141 void
00142 TAO_Notify_Event_Manager::disconnect (TAO_Notify_ProxyConsumer* proxy_consumer ACE_ENV_ARG_DECL)
00143 {
00144   this->supplier_map().disconnect (proxy_consumer ACE_ENV_ARG_PARAMETER);
00145 }
00146 
00147 void
00148 TAO_Notify_Event_Manager::offer_change (TAO_Notify_ProxyConsumer* proxy_consumer, const TAO_Notify_EventTypeSeq& added, const TAO_Notify_EventTypeSeq& removed ACE_ENV_ARG_DECL)
00149 {
00150   TAO_Notify_EventTypeSeq new_added, last_removed;
00151 
00152   this->publish (proxy_consumer, added, new_added ACE_ENV_ARG_PARAMETER);
00153   ACE_CHECK;
00154 
00155   this->un_publish (proxy_consumer, removed, last_removed ACE_ENV_ARG_PARAMETER);
00156   ACE_CHECK;
00157 
00158   TAO_Notify_Consumer_Map::ENTRY::COLLECTION* updates_collection = this->consumer_map().updates_collection ();
00159 
00160   TAO_Notify_ProxySupplier_Update_Worker worker (new_added, last_removed);
00161 
00162   if (updates_collection != 0)
00163     updates_collection->for_each (&worker ACE_ENV_ARG_PARAMETER);
00164 }
00165 
00166 void
00167 TAO_Notify_Event_Manager::subscription_change (TAO_Notify_ProxySupplier* proxy_supplier, const TAO_Notify_EventTypeSeq& added, const TAO_Notify_EventTypeSeq& removed ACE_ENV_ARG_DECL)
00168 {
00169   TAO_Notify_EventTypeSeq new_added, last_removed;
00170 
00171   this->subscribe (proxy_supplier, added, new_added ACE_ENV_ARG_PARAMETER);
00172   ACE_CHECK;
00173   this->un_subscribe (proxy_supplier, removed, last_removed ACE_ENV_ARG_PARAMETER);
00174   ACE_CHECK;
00175 
00176   TAO_Notify_Supplier_Map::ENTRY::COLLECTION* updates_collection = this->supplier_map().updates_collection ();
00177 
00178   TAO_Notify_ProxyConsumer_Update_Worker worker (new_added, last_removed);
00179 
00180   if (updates_collection != 0)
00181     {
00182       updates_collection->for_each (&worker ACE_ENV_ARG_PARAMETER);
00183       ACE_CHECK;
00184     }
00185 }
00186 
00187 void
00188 TAO_Notify_Event_Manager::subscribe (TAO_Notify_ProxySupplier* proxy_supplier, const TAO_Notify_EventTypeSeq& seq, TAO_Notify_EventTypeSeq& new_seq ACE_ENV_ARG_DECL)
00189 {
00190   TAO_Notify_EventTypeSeq::CONST_ITERATOR iter (seq);
00191 
00192   TAO_Notify_EventType* event_type;
00193 
00194   for (iter.first (); iter.next (event_type) != 0; iter.advance ())
00195     {
00196       int result = this->consumer_map().insert (proxy_supplier, *event_type ACE_ENV_ARG_PARAMETER);
00197       ACE_CHECK;
00198 
00199       if (result == 1)
00200         new_seq.insert (*event_type);
00201     }
00202 }
00203 
00204 void
00205 TAO_Notify_Event_Manager::un_subscribe (TAO_Notify_ProxySupplier* proxy_supplier, const TAO_Notify_EventTypeSeq& seq, TAO_Notify_EventTypeSeq& last_seq ACE_ENV_ARG_DECL)
00206 {
00207   TAO_Notify_EventTypeSeq::CONST_ITERATOR iter (seq);
00208 
00209   TAO_Notify_EventType* event_type = 0;
00210 
00211   for (iter.first (); iter.next (event_type) != 0; iter.advance ())
00212     {
00213       int result = this->consumer_map().remove (proxy_supplier, *event_type ACE_ENV_ARG_PARAMETER);
00214       ACE_CHECK;
00215 
00216       if (result == 1)
00217         last_seq.insert (*event_type);
00218     }
00219 }
00220 
00221 void
00222 TAO_Notify_Event_Manager::publish (TAO_Notify_ProxyConsumer* proxy_consumer, const TAO_Notify_EventTypeSeq& seq, TAO_Notify_EventTypeSeq& new_seq ACE_ENV_ARG_DECL)
00223 {
00224   TAO_Notify_EventTypeSeq::CONST_ITERATOR iter (seq);
00225 
00226   TAO_Notify_EventType* event_type = 0;
00227 
00228   for (iter.first (); iter.next (event_type) != 0; iter.advance ())
00229     {
00230       int result = supplier_map().insert (proxy_consumer, *event_type ACE_ENV_ARG_PARAMETER);
00231       ACE_CHECK;
00232 
00233       if (result == 1)
00234         new_seq.insert (*event_type);
00235     }
00236 }
00237 
00238 void
00239 TAO_Notify_Event_Manager::un_publish (TAO_Notify_ProxyConsumer* proxy_consumer, const TAO_Notify_EventTypeSeq& seq, TAO_Notify_EventTypeSeq& last_seq ACE_ENV_ARG_DECL)
00240 {
00241   TAO_Notify_EventTypeSeq::CONST_ITERATOR iter (seq);
00242 
00243   TAO_Notify_EventType* event_type = 0;
00244 
00245   for (iter.first (); iter.next (event_type) != 0; iter.advance ())
00246     {
00247       int result = supplier_map().remove (proxy_consumer, *event_type ACE_ENV_ARG_PARAMETER);
00248       ACE_CHECK;
00249 
00250       if (result == 1)
00251         last_seq.insert (*event_type);
00252     }
00253 }
00254 
00255 TAO_Notify_Consumer_Map&
00256 TAO_Notify_Event_Manager::consumer_map (void)
00257 {
00258   ACE_ASSERT( this->consumer_map_.get() != 0 );
00259   return *this->consumer_map_;
00260 }
00261 
00262 TAO_Notify_Supplier_Map&
00263 TAO_Notify_Event_Manager::supplier_map (void)
00264 {
00265   ACE_ASSERT( this->supplier_map_.get() != 0 );
00266   return *this->supplier_map_;
00267 }
00268 
00269 const TAO_Notify_EventTypeSeq&
00270 TAO_Notify_Event_Manager::offered_types (void) const
00271 {
00272   return this->supplier_map_->event_types ();
00273 }
00274 
00275 const TAO_Notify_EventTypeSeq&
00276 TAO_Notify_Event_Manager::subscription_types (void) const
00277 {
00278   return this->consumer_map_->event_types ();
00279 }
00280 
00281 /********************************************************************************/
00282 
00283 TAO_Notify_ProxyConsumer_Update_Worker::TAO_Notify_ProxyConsumer_Update_Worker (const TAO_Notify_EventTypeSeq& added, const TAO_Notify_EventTypeSeq& removed)
00284   :added_ (added), removed_ (removed)
00285 {
00286 }
00287 
00288 void
00289 TAO_Notify_ProxyConsumer_Update_Worker::work (TAO_Notify_ProxyConsumer* proxy ACE_ENV_ARG_DECL)
00290 {
00291   proxy->types_changed (added_, removed_ ACE_ENV_ARG_PARAMETER);
00292 }
00293 
00294 /*****************************************************************************/
00295 
00296 TAO_Notify_ProxySupplier_Update_Worker::TAO_Notify_ProxySupplier_Update_Worker (const TAO_Notify_EventTypeSeq& added, const TAO_Notify_EventTypeSeq& removed)
00297   :added_ (added), removed_ (removed)
00298 {
00299 }
00300 
00301 void
00302 TAO_Notify_ProxySupplier_Update_Worker::work (TAO_Notify_ProxySupplier* proxy ACE_ENV_ARG_DECL)
00303 {
00304   proxy->types_changed (added_, removed_ ACE_ENV_ARG_PARAMETER);
00305 }
00306 
00307 /*****************************************************************************/
00308 
00309 TAO_END_VERSIONED_NAMESPACE_DECL

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