Event_Map_T.cpp

Go to the documentation of this file.
00001 // Event_Map_T.cpp,v 1.13 2006/03/14 06:14:34 jtc Exp
00002 
00003 #ifndef TAO_Notify_EVENT_MAP_T_CPP
00004 #define TAO_Notify_EVENT_MAP_T_CPP
00005 
00006 #include "orbsvcs/Notify/Event_Map_T.h"
00007 #include "orbsvcs/ESF/ESF_Proxy_Collection.h"
00008 #include "orbsvcs/Notify/Event_Map_Entry_T.h"
00009 #include "orbsvcs/Notify/Properties.h"
00010 #include "orbsvcs/Notify/Factory.h"
00011 
00012 #if ! defined (__ACE_INLINE__)
00013 #include "orbsvcs/Notify/Event_Map_T.inl"
00014 #endif /* __ACE_INLINE__ */
00015 
00016 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00017 
00018 template <class PROXY, class ACE_LOCK>
00019 TAO_Notify_Event_Map_T<PROXY, ACE_LOCK>::TAO_Notify_Event_Map_T (void)
00020   :proxy_count_ (0)
00021 {
00022 
00023 }
00024 
00025 template <class PROXY, class ACE_LOCK>
00026 TAO_Notify_Event_Map_T<PROXY, ACE_LOCK>::~TAO_Notify_Event_Map_T ()
00027 {
00028 }
00029 
00030 template <class PROXY, class ACE_LOCK> void
00031 TAO_Notify_Event_Map_T<PROXY, ACE_LOCK>::init (ACE_ENV_SINGLE_ARG_DECL)
00032 {
00033   this->broadcast_entry_.init (ACE_ENV_SINGLE_ARG_PARAMETER);
00034   ACE_CHECK;
00035 
00036   this->updates_entry_.init (ACE_ENV_SINGLE_ARG_PARAMETER);
00037 }
00038 
00039 template <class PROXY, class ACE_LOCK> void
00040 TAO_Notify_Event_Map_T<PROXY, ACE_LOCK>::connect (PROXY* proxy ACE_ENV_ARG_DECL)
00041 {
00042   this->updates_entry_.connected (proxy ACE_ENV_ARG_PARAMETER);
00043   ACE_CHECK;
00044 
00045   ACE_WRITE_GUARD (ACE_LOCK, ace_mon, this->lock_);
00046   ++this->proxy_count_;
00047 }
00048 
00049 template <class PROXY, class ACE_LOCK> void
00050 TAO_Notify_Event_Map_T<PROXY, ACE_LOCK>::disconnect (PROXY* proxy ACE_ENV_ARG_DECL)
00051 {
00052   this->updates_entry_.disconnected (proxy ACE_ENV_ARG_PARAMETER);
00053   ACE_CHECK;
00054 
00055   ACE_WRITE_GUARD (ACE_LOCK, ace_mon, this->lock_);
00056   --this->proxy_count_;
00057 }
00058 
00059 template <class PROXY, class ACE_LOCK> int
00060 TAO_Notify_Event_Map_T<PROXY, ACE_LOCK>::insert (PROXY* proxy, const TAO_Notify_EventType& event_type ACE_ENV_ARG_DECL)
00061 {
00062   ENTRY* entry;
00063 
00064   int result = -1;
00065 
00066   if (event_type.is_special () == 1)
00067     {
00068       entry = &this->broadcast_entry_;
00069 
00070       result = 0;
00071     }
00072   else
00073     {
00074       ACE_READ_GUARD_RETURN (ACE_LOCK, ace_mon, this->lock_, -1);
00075 
00076       result = this->map_.find (event_type, entry);
00077     }
00078 
00079   if (result == -1) // This type is being seen for the first time.
00080   {
00081     ACE_NEW_THROW_EX (entry,
00082                       ENTRY (),
00083                       CORBA::NO_MEMORY ());
00084     ACE_CHECK_RETURN (-1);
00085 
00086     entry->init (ACE_ENV_SINGLE_ARG_PARAMETER);
00087     ACE_CHECK_RETURN (-1);
00088 
00089     entry->connected (proxy ACE_ENV_ARG_PARAMETER);
00090     ACE_CHECK_RETURN (-1);
00091 
00092     ACE_WRITE_GUARD_RETURN (ACE_LOCK, ace_mon, this->lock_, -1);
00093 
00094     if (map_.bind (event_type, entry) == -1)
00095       ACE_THROW_RETURN (CORBA::NO_MEMORY (), -1);
00096 
00097     if (this->event_types_.insert (event_type) == -1)
00098       return -1;
00099 
00100     return 1;
00101   }
00102   else // Add to existing entry or the broadcast entry.
00103     {
00104       entry->connected (proxy ACE_ENV_ARG_PARAMETER);
00105       ACE_CHECK_RETURN (-1);
00106     }
00107 
00108   return 0;
00109 }
00110 
00111 template <class PROXY, class ACE_LOCK> int
00112 TAO_Notify_Event_Map_T<PROXY, ACE_LOCK>::remove (PROXY* proxy, const TAO_Notify_EventType& event_type ACE_ENV_ARG_DECL)
00113 {
00114   ENTRY* entry = 0;
00115 
00116   if (event_type.is_special () == 1)
00117     {
00118       entry = &this->broadcast_entry_;
00119 
00120       entry->disconnected (proxy ACE_ENV_ARG_PARAMETER);
00121       ACE_CHECK_RETURN (-1);
00122     }
00123   else
00124     {
00125       int result = -1;
00126 
00127       {
00128         ACE_READ_GUARD_RETURN (ACE_LOCK, ace_mon, this->lock_, -1);
00129 
00130         result = this->map_.find (event_type, entry);
00131       }
00132 
00133       if (result == 0)
00134         {
00135           entry->disconnected (proxy ACE_ENV_ARG_PARAMETER);
00136           ACE_CHECK_RETURN (-1);
00137 
00138           if (entry->count () == 0)
00139             {
00140               /// Exec a strategy for removing entries.
00141               /// Strategy 1: remove_immediately
00142               /// Strategy 2: remove a bunch_after crossing a threshold
00143               /// Strategy 3: use cached allocator and 1
00144 
00145               // Strategy 1:
00146               ACE_WRITE_GUARD_RETURN (ACE_LOCK, ace_mon, this->lock_, -1);
00147 
00148               this->map_.unbind (event_type);
00149 
00150               if (entry->_decr_refcnt () == 0)
00151                 delete entry;
00152 
00153               if (this->event_types_.remove (event_type) == -1)
00154                 return -1;
00155 
00156               return 1;
00157             }
00158         }
00159     }
00160 
00161   return 0;
00162 }
00163 
00164 TAO_END_VERSIONED_NAMESPACE_DECL
00165 
00166 #endif /* TAO_Notify_EVENT_MAP_T_CPP */

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