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