00001
00002
00003 #ifndef TAO_ESF_COPY_ON_READ_CPP
00004 #define TAO_ESF_COPY_ON_READ_CPP
00005
00006 #include "orbsvcs/ESF/ESF_Copy_On_Read.h"
00007 #include "orbsvcs/ESF/ESF_Worker.h"
00008
00009 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00010
00011 template<class PROXY, class COLLECTION, class ITERATOR, class ACE_LOCK>
00012 TAO_ESF_Copy_On_Read<PROXY,COLLECTION,ITERATOR,ACE_LOCK>::
00013 TAO_ESF_Copy_On_Read (void)
00014 {
00015 }
00016
00017 template<class PROXY, class COLLECTION, class ITERATOR, class ACE_LOCK>
00018 TAO_ESF_Copy_On_Read<PROXY,COLLECTION,ITERATOR,ACE_LOCK>::
00019 TAO_ESF_Copy_On_Read (const COLLECTION &collection)
00020 : collection_ (collection)
00021 {
00022 }
00023
00024 template<class PROXY, class COLLECTION, class ITERATOR, class ACE_LOCK> void
00025 TAO_ESF_Copy_On_Read<PROXY,COLLECTION,ITERATOR,ACE_LOCK>::
00026 for_each (TAO_ESF_Worker<PROXY> *worker)
00027 {
00028
00029 PROXY **proxies = 0;
00030 size_t size = 0;
00031 try
00032 {
00033 {
00034 ACE_GUARD (ACE_LOCK, ace_mon, this->lock_);
00035
00036 size = this->collection_.size ();
00037 ACE_NEW (proxies, PROXY*[size]);
00038 PROXY **j = proxies;
00039
00040 for (; j != proxies + size; ++j)
00041 *j = 0;
00042
00043 j = proxies;
00044
00045 ITERATOR end = this->collection_.end ();
00046 for (ITERATOR i = this->collection_.begin (); i != end; ++i)
00047 {
00048 *j = *i;
00049 (*j)->_incr_refcnt ();
00050 ++j;
00051 }
00052 }
00053 worker->set_size(size);
00054 for (PROXY **j = proxies; j != proxies + size; ++j)
00055 {
00056 worker->work (*j);
00057 (*j)->_decr_refcnt ();
00058 }
00059 delete[] proxies;
00060 }
00061 catch (const CORBA::Exception&)
00062 {
00063 for (PROXY **j = proxies; j != proxies + size; ++j)
00064 {
00065 if (*j != 0)
00066 (*j)->_decr_refcnt ();
00067 }
00068 delete[] proxies;
00069
00070 throw;
00071 }
00072 }
00073
00074 template<class PROXY, class COLLECTION, class ITERATOR, class ACE_LOCK> void
00075 TAO_ESF_Copy_On_Read<PROXY,COLLECTION,ITERATOR,ACE_LOCK>::
00076 connected (PROXY *proxy)
00077 {
00078 ACE_GUARD (ACE_LOCK, ace_mon, this->lock_);
00079
00080 proxy->_incr_refcnt ();
00081 this->collection_.connected (proxy);
00082 }
00083
00084 template<class PROXY, class COLLECTION, class ITERATOR, class ACE_LOCK> void
00085 TAO_ESF_Copy_On_Read<PROXY,COLLECTION,ITERATOR,ACE_LOCK>::
00086 reconnected (PROXY *proxy)
00087 {
00088 ACE_GUARD (ACE_LOCK, ace_mon, this->lock_);
00089
00090 proxy->_incr_refcnt ();
00091 this->collection_.reconnected (proxy);
00092 }
00093
00094 template<class PROXY, class COLLECTION, class ITERATOR, class ACE_LOCK> void
00095 TAO_ESF_Copy_On_Read<PROXY,COLLECTION,ITERATOR,ACE_LOCK>::
00096 disconnected (PROXY *proxy)
00097 {
00098 ACE_GUARD (ACE_LOCK, ace_mon, this->lock_);
00099
00100 this->collection_.disconnected (proxy);
00101 }
00102
00103 template<class PROXY, class COLLECTION, class ITERATOR, class ACE_LOCK> void
00104 TAO_ESF_Copy_On_Read<PROXY,COLLECTION,ITERATOR,ACE_LOCK>::shutdown (void)
00105 {
00106 ACE_GUARD (ACE_LOCK, ace_mon, this->lock_);
00107
00108 this->collection_.shutdown ();
00109 }
00110
00111 TAO_END_VERSIONED_NAMESPACE_DECL
00112
00113 #endif