InstanceState.inl

Go to the documentation of this file.
00001 /*
00002  *
00003  *
00004  * Distributed under the OpenDDS License.
00005  * See: http://www.opendds.org/license.html
00006  */
00007 
00008 #include "ReceivedDataElementList.h"
00009 #include "ace/OS_NS_sys_time.h"
00010 
00011 ACE_INLINE
00012 OpenDDS::DCPS::DataReaderImpl*
00013 OpenDDS::DCPS::InstanceState::data_reader() const
00014 {
00015   return reader_;
00016 }
00017 
00018 ACE_INLINE
00019 void
00020 OpenDDS::DCPS::InstanceState::accessed()
00021 {
00022   ACE_GUARD(ACE_Recursive_Thread_Mutex,
00023             guard, this->lock_);
00024   //
00025   // Manage the view state due to data access here.
00026   //
00027   if (this->view_state_ & DDS::ANY_VIEW_STATE) {
00028     this->view_state_ = DDS::NOT_NEW_VIEW_STATE ;
00029   }
00030 }
00031 
00032 ACE_INLINE
00033 bool
00034 OpenDDS::DCPS::InstanceState::most_recent_generation(ReceivedDataElement* item) const
00035 {
00036   return item->disposed_generation_count_ == disposed_generation_count_
00037          && item->no_writers_generation_count_ == no_writers_generation_count_;
00038 }
00039 
00040 ACE_INLINE
00041 DDS::InstanceStateKind
00042 OpenDDS::DCPS::InstanceState::instance_state() const
00043 {
00044   return this->instance_state_ ;
00045 }
00046 
00047 ACE_INLINE
00048 DDS::ViewStateKind
00049 OpenDDS::DCPS::InstanceState::view_state() const
00050 {
00051   return this->view_state_ ;
00052 }
00053 
00054 ACE_INLINE
00055 size_t OpenDDS::DCPS::InstanceState::disposed_generation_count() const
00056 {
00057   return disposed_generation_count_ ;
00058 }
00059 
00060 ACE_INLINE
00061 size_t OpenDDS::DCPS::InstanceState::no_writers_generation_count() const
00062 {
00063   return no_writers_generation_count_ ;
00064 }
00065 
00066 ACE_INLINE
00067 void
00068 OpenDDS::DCPS::InstanceState::data_was_received(const PublicationId& writer_id)
00069 {
00070   ACE_GUARD(ACE_Recursive_Thread_Mutex,
00071             guard, this->lock_);
00072   cancel_release();
00073 
00074   //
00075   // Update the view state here, since only sample data received affects
00076   // this state value.  Then manage the data sample only transistions
00077   // here.  Let the lively() method manage the other transitions.
00078   //
00079   writers_.insert(writer_id);
00080 
00081   switch (this->view_state_) {
00082   case DDS::NEW_VIEW_STATE:
00083     break ; // No action.
00084 
00085   case DDS::NOT_NEW_VIEW_STATE:
00086 
00087     if (this->instance_state_ & DDS::NOT_ALIVE_INSTANCE_STATE) {
00088       this->view_state_ = DDS::NEW_VIEW_STATE ;
00089     }
00090 
00091     break ;
00092 
00093   default:
00094     this->view_state_ = DDS::NEW_VIEW_STATE ;
00095     break ;
00096   }
00097 
00098   switch (this->instance_state_) {
00099   case DDS::NOT_ALIVE_DISPOSED_INSTANCE_STATE:
00100     ++this->disposed_generation_count_;
00101     break ;
00102 
00103   case DDS::NOT_ALIVE_NO_WRITERS_INSTANCE_STATE:
00104     ++this->no_writers_generation_count_;
00105     break ;
00106 
00107   default:
00108     break ;
00109   }
00110 
00111   this->instance_state_ = DDS::ALIVE_INSTANCE_STATE ;
00112 }
00113 
00114 ACE_INLINE
00115 void
00116 OpenDDS::DCPS::InstanceState::lively(const PublicationId& writer_id)
00117 {
00118   ACE_GUARD(ACE_Recursive_Thread_Mutex,
00119             guard, this->lock_);
00120 
00121   //
00122   // Manage transisitions in the instance state that do not require a
00123   // data sample, but merely the notion of liveliness.
00124   //
00125   writers_.insert(writer_id);
00126 
00127   if (this->instance_state_ == DDS::NOT_ALIVE_NO_WRITERS_INSTANCE_STATE) {
00128     cancel_release(); // cancel unregister
00129 
00130     this->no_writers_generation_count_++ ;
00131     this->instance_state_ = DDS::ALIVE_INSTANCE_STATE ;
00132   }
00133 }
00134 
00135 ACE_INLINE
00136 bool
00137 OpenDDS::DCPS::InstanceState::empty(bool value)
00138 {
00139   //
00140   // Manage the instance state due to the DataReader becoming empty
00141   // here.
00142   //
00143   if ((this->empty_ = value) && this->release_pending_) {
00144     return release_if_empty();
00145   } else {
00146     return false;
00147   }
00148 }
00149 
00150 
00151 ACE_INLINE
00152 bool
00153 OpenDDS::DCPS::InstanceState::is_last (const PublicationId& pub)
00154 {
00155   ACE_GUARD_RETURN(ACE_Recursive_Thread_Mutex,
00156                    guard, this->lock_, false);
00157 
00158   return (this->writers_.size () == 1) && *(this->writers_.begin ()) == pub;
00159 }
00160 
00161 ACE_INLINE
00162 bool
00163 OpenDDS::DCPS::InstanceState::no_writer () const
00164 {
00165   ACE_GUARD_RETURN(ACE_Recursive_Thread_Mutex,
00166                    guard, this->lock_, true);
00167 
00168   return this->writers_.size () == 0;
00169 }
00170 

Generated on Fri Feb 12 20:05:23 2016 for OpenDDS by  doxygen 1.4.7