00001
00002
00003 #include "orbsvcs/Notify/Event_Manager.h"
00004
00005 ACE_RCSID(Notify, TAO_Notify_Event_Manager, "$Id: Event_Manager.cpp 84563 2009-02-23 08:13:54Z johnnyw $")
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
00024
00025
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
00035 void work (TAO_Notify_ProxyConsumer* proxy);
00036
00037 const TAO_Notify_EventTypeSeq& added_;
00038 const TAO_Notify_EventTypeSeq& removed_;
00039 };
00040
00041
00042
00043
00044
00045
00046
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
00056 void work (TAO_Notify_ProxySupplier* proxy);
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 (void)
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 this->consumer_map_.reset( consumer_map );
00092
00093 this->consumer_map().init ();
00094
00095 TAO_Notify_Supplier_Map* supplier_map = 0;
00096 ACE_NEW_THROW_EX (supplier_map,
00097 TAO_Notify_Supplier_Map (),
00098 CORBA::NO_MEMORY ());
00099 this->supplier_map_.reset( supplier_map );
00100
00101 this->supplier_map_->init ();
00102 }
00103
00104 void
00105 TAO_Notify_Event_Manager::shutdown (void)
00106 {
00107 }
00108
00109 void
00110 TAO_Notify_Event_Manager::connect (TAO_Notify_ProxySupplier* proxy_supplier)
00111 {
00112 this->consumer_map().connect (proxy_supplier);
00113
00114
00115 TAO_Notify_EventTypeSeq removed;
00116 proxy_supplier->types_changed (this->offered_types (), removed);
00117 }
00118
00119 void
00120 TAO_Notify_Event_Manager::disconnect (TAO_Notify_ProxySupplier* proxy_supplier)
00121 {
00122 this->consumer_map().disconnect (proxy_supplier);
00123 }
00124
00125 void
00126 TAO_Notify_Event_Manager::connect (TAO_Notify_ProxyConsumer* proxy_consumer)
00127 {
00128 this->supplier_map().connect (proxy_consumer);
00129
00130 TAO_Notify_EventTypeSeq removed;
00131 proxy_consumer->types_changed (this->subscription_types (), removed);
00132 }
00133
00134 void
00135 TAO_Notify_Event_Manager::disconnect (TAO_Notify_ProxyConsumer* proxy_consumer)
00136 {
00137 this->supplier_map().disconnect (proxy_consumer);
00138 }
00139
00140 void
00141 TAO_Notify_Event_Manager::offer_change (TAO_Notify_ProxyConsumer* proxy_consumer, const TAO_Notify_EventTypeSeq& added, const TAO_Notify_EventTypeSeq& removed)
00142 {
00143 TAO_Notify_EventTypeSeq new_added, last_removed;
00144
00145 this->publish (proxy_consumer, added, new_added);
00146
00147 this->un_publish (proxy_consumer, removed, last_removed);
00148
00149 TAO_Notify_Consumer_Map::ENTRY::COLLECTION* updates_collection = this->consumer_map().updates_collection ();
00150
00151 TAO_Notify_ProxySupplier_Update_Worker worker (new_added, last_removed);
00152
00153 if (updates_collection != 0)
00154 updates_collection->for_each (&worker);
00155 }
00156
00157 void
00158 TAO_Notify_Event_Manager::subscription_change (TAO_Notify_ProxySupplier* proxy_supplier, const TAO_Notify_EventTypeSeq& added, const TAO_Notify_EventTypeSeq& removed)
00159 {
00160 TAO_Notify_EventTypeSeq new_added, last_removed;
00161
00162 this->subscribe (proxy_supplier, added, new_added);
00163 this->un_subscribe (proxy_supplier, removed, last_removed);
00164
00165 TAO_Notify_Supplier_Map::ENTRY::COLLECTION* updates_collection = this->supplier_map().updates_collection ();
00166
00167 TAO_Notify_ProxyConsumer_Update_Worker worker (new_added, last_removed);
00168
00169 if (updates_collection != 0)
00170 {
00171 updates_collection->for_each (&worker);
00172 }
00173 }
00174
00175 void
00176 TAO_Notify_Event_Manager::subscribe (TAO_Notify_ProxySupplier* proxy_supplier, const TAO_Notify_EventTypeSeq& seq, TAO_Notify_EventTypeSeq& new_seq)
00177 {
00178 TAO_Notify_EventTypeSeq::CONST_ITERATOR iter (seq);
00179
00180 TAO_Notify_EventType* event_type;
00181
00182 for (iter.first (); iter.next (event_type) != 0; iter.advance ())
00183 {
00184 int result = this->consumer_map().insert (proxy_supplier, *event_type);
00185
00186 if (result == 1)
00187 new_seq.insert (*event_type);
00188 }
00189 }
00190
00191 void
00192 TAO_Notify_Event_Manager::un_subscribe (TAO_Notify_ProxySupplier* proxy_supplier, const TAO_Notify_EventTypeSeq& seq, TAO_Notify_EventTypeSeq& last_seq)
00193 {
00194 TAO_Notify_EventTypeSeq::CONST_ITERATOR iter (seq);
00195
00196 TAO_Notify_EventType* event_type = 0;
00197
00198 for (iter.first (); iter.next (event_type) != 0; iter.advance ())
00199 {
00200 int result = this->consumer_map().remove (proxy_supplier, *event_type);
00201
00202 if (result == 1)
00203 last_seq.insert (*event_type);
00204 }
00205 }
00206
00207 void
00208 TAO_Notify_Event_Manager::publish (TAO_Notify_ProxyConsumer* proxy_consumer, const TAO_Notify_EventTypeSeq& seq, TAO_Notify_EventTypeSeq& new_seq)
00209 {
00210 TAO_Notify_EventTypeSeq::CONST_ITERATOR iter (seq);
00211
00212 TAO_Notify_EventType* event_type = 0;
00213
00214 for (iter.first (); iter.next (event_type) != 0; iter.advance ())
00215 {
00216 int result = supplier_map().insert (proxy_consumer, *event_type);
00217
00218 if (result == 1)
00219 new_seq.insert (*event_type);
00220 }
00221 }
00222
00223 void
00224 TAO_Notify_Event_Manager::un_publish (TAO_Notify_ProxyConsumer* proxy_consumer, const TAO_Notify_EventTypeSeq& seq, TAO_Notify_EventTypeSeq& last_seq)
00225 {
00226 TAO_Notify_EventTypeSeq::CONST_ITERATOR iter (seq);
00227
00228 TAO_Notify_EventType* event_type = 0;
00229
00230 for (iter.first (); iter.next (event_type) != 0; iter.advance ())
00231 {
00232 int result = supplier_map().remove (proxy_consumer, *event_type);
00233
00234 if (result == 1)
00235 last_seq.insert (*event_type);
00236 }
00237 }
00238
00239 TAO_Notify_Consumer_Map&
00240 TAO_Notify_Event_Manager::consumer_map (void)
00241 {
00242 ACE_ASSERT( this->consumer_map_.get() != 0 );
00243 return *this->consumer_map_;
00244 }
00245
00246 TAO_Notify_Supplier_Map&
00247 TAO_Notify_Event_Manager::supplier_map (void)
00248 {
00249 ACE_ASSERT( this->supplier_map_.get() != 0 );
00250 return *this->supplier_map_;
00251 }
00252
00253 const TAO_Notify_EventTypeSeq&
00254 TAO_Notify_Event_Manager::offered_types (void) const
00255 {
00256 return this->supplier_map_->event_types ();
00257 }
00258
00259 const TAO_Notify_EventTypeSeq&
00260 TAO_Notify_Event_Manager::subscription_types (void) const
00261 {
00262 return this->consumer_map_->event_types ();
00263 }
00264
00265
00266
00267 TAO_Notify_ProxyConsumer_Update_Worker::TAO_Notify_ProxyConsumer_Update_Worker (const TAO_Notify_EventTypeSeq& added, const TAO_Notify_EventTypeSeq& removed)
00268 :added_ (added), removed_ (removed)
00269 {
00270 }
00271
00272 void
00273 TAO_Notify_ProxyConsumer_Update_Worker::work (TAO_Notify_ProxyConsumer* proxy)
00274 {
00275 proxy->types_changed (added_, removed_);
00276 }
00277
00278
00279
00280 TAO_Notify_ProxySupplier_Update_Worker::TAO_Notify_ProxySupplier_Update_Worker (const TAO_Notify_EventTypeSeq& added, const TAO_Notify_EventTypeSeq& removed)
00281 :added_ (added), removed_ (removed)
00282 {
00283 }
00284
00285 void
00286 TAO_Notify_ProxySupplier_Update_Worker::work (TAO_Notify_ProxySupplier* proxy)
00287 {
00288 proxy->types_changed (added_, removed_);
00289 }
00290
00291
00292
00293 TAO_END_VERSIONED_NAMESPACE_DECL