Line data Source code
1 : /* 2 : * 3 : * 4 : * Distributed under the OpenDDS License. 5 : * See: http://www.opendds.org/license.html 6 : */ 7 : 8 : #include "ReceivedDataElementList.h" 9 : #include "ace/OS_NS_sys_time.h" 10 : 11 : OPENDDS_BEGIN_VERSIONED_NAMESPACE_DECL 12 : 13 : ACE_INLINE 14 : OpenDDS::DCPS::WeakRcHandle<OpenDDS::DCPS::DataReaderImpl> 15 0 : OpenDDS::DCPS::InstanceState::data_reader() const 16 : { 17 0 : return reader_; 18 : } 19 : 20 : ACE_INLINE 21 : void 22 0 : OpenDDS::DCPS::InstanceState::accessed() 23 : { 24 0 : ACE_GUARD(ACE_Recursive_Thread_Mutex, guard, lock_); 25 : // 26 : // Manage the view state due to data access here. 27 : // 28 0 : if (view_state_ & DDS::ANY_VIEW_STATE) { 29 0 : const bool updated = (view_state_ != DDS::NOT_NEW_VIEW_STATE); 30 0 : view_state_ = DDS::NOT_NEW_VIEW_STATE; 31 0 : if (updated) { 32 0 : state_updated(); 33 : } 34 : } 35 0 : } 36 : 37 : ACE_INLINE 38 : DDS::InstanceStateKind 39 0 : OpenDDS::DCPS::InstanceState::instance_state() const 40 : { 41 0 : return instance_state_; 42 : } 43 : 44 : ACE_INLINE 45 : DDS::ViewStateKind 46 0 : OpenDDS::DCPS::InstanceState::view_state() const 47 : { 48 0 : return view_state_; 49 : } 50 : 51 : ACE_INLINE 52 0 : bool OpenDDS::DCPS::InstanceState::match(DDS::ViewStateMask view, DDS::InstanceStateMask inst) const 53 : { 54 0 : return (view_state_ & view) && (instance_state_ & inst); 55 : } 56 : 57 : ACE_INLINE 58 0 : size_t OpenDDS::DCPS::InstanceState::disposed_generation_count() const 59 : { 60 0 : return disposed_generation_count_; 61 : } 62 : 63 : ACE_INLINE 64 0 : size_t OpenDDS::DCPS::InstanceState::no_writers_generation_count() const 65 : { 66 0 : return no_writers_generation_count_; 67 : } 68 : 69 : ACE_INLINE 70 : void 71 0 : OpenDDS::DCPS::InstanceState::data_was_received(const GUID_t& writer_id) 72 : { 73 0 : ACE_GUARD(ACE_Recursive_Thread_Mutex, guard, lock_); 74 0 : cancel_release(); 75 : 76 : // 77 : // Update the view state here, since only sample data received affects 78 : // this state value. Then manage the data sample only transitions 79 : // here. Let the lively() method manage the other transitions. 80 : // 81 0 : writers_.insert(writer_id); 82 : 83 0 : const CORBA::ULong old_view_state = view_state_; 84 0 : const CORBA::ULong old_instance_state = instance_state_; 85 : 86 0 : switch (view_state_) { 87 0 : case DDS::NEW_VIEW_STATE: 88 0 : break; 89 : 90 0 : case DDS::NOT_NEW_VIEW_STATE: 91 0 : if (instance_state_ & DDS::NOT_ALIVE_INSTANCE_STATE) { 92 0 : view_state_ = DDS::NEW_VIEW_STATE; 93 : } 94 0 : break; 95 : 96 0 : default: 97 0 : view_state_ = DDS::NEW_VIEW_STATE; 98 0 : break; 99 : } 100 : 101 0 : switch (instance_state_) { 102 0 : case DDS::NOT_ALIVE_DISPOSED_INSTANCE_STATE: 103 0 : ++disposed_generation_count_; 104 0 : break; 105 : 106 0 : case DDS::NOT_ALIVE_NO_WRITERS_INSTANCE_STATE: 107 0 : ++no_writers_generation_count_; 108 0 : break; 109 : 110 0 : default: 111 0 : break; 112 : } 113 : 114 0 : instance_state_ = DDS::ALIVE_INSTANCE_STATE; 115 : 116 0 : if (view_state_ != old_view_state || instance_state_ != old_instance_state) { 117 0 : state_updated(); 118 : } 119 0 : } 120 : 121 : ACE_INLINE 122 : void 123 0 : OpenDDS::DCPS::InstanceState::lively(const GUID_t& writer_id) 124 : { 125 0 : ACE_GUARD(ACE_Recursive_Thread_Mutex, guard, lock_); 126 : 127 : // 128 : // Manage transisitions in the instance state that do not require a 129 : // data sample, but merely the notion of liveliness. 130 : // 131 0 : writers_.insert(writer_id); 132 : 133 0 : if (instance_state_ == DDS::NOT_ALIVE_NO_WRITERS_INSTANCE_STATE) { 134 0 : cancel_release(); // cancel unregister 135 : 136 0 : ++no_writers_generation_count_; 137 0 : const bool updated = (instance_state_ != DDS::ALIVE_INSTANCE_STATE); 138 0 : instance_state_ = DDS::ALIVE_INSTANCE_STATE; 139 0 : if (updated) { 140 0 : state_updated(); 141 : } 142 : } 143 0 : } 144 : 145 : ACE_INLINE 146 : bool 147 0 : OpenDDS::DCPS::InstanceState::empty(bool value) 148 : { 149 : // 150 : // Manage the instance state due to the DataReader becoming empty 151 : // here. 152 : // 153 0 : if ((empty_ = value) && release_pending_) { 154 0 : return release_if_empty(); 155 : } else { 156 0 : return false; 157 : } 158 : } 159 : 160 : 161 : ACE_INLINE 162 : bool 163 0 : OpenDDS::DCPS::InstanceState::is_last (const GUID_t& pub) 164 : { 165 0 : ACE_GUARD_RETURN(ACE_Recursive_Thread_Mutex, guard, lock_, false); 166 : 167 0 : return writers_.size() == 1 && *writers_.begin() == pub; 168 0 : } 169 : 170 : ACE_INLINE 171 : bool 172 : OpenDDS::DCPS::InstanceState::no_writer () const 173 : { 174 : ACE_GUARD_RETURN(ACE_Recursive_Thread_Mutex, guard, lock_, true); 175 : 176 : return writers_.empty(); 177 : } 178 : 179 : ACE_INLINE 180 0 : const char* OpenDDS::DCPS::InstanceState::instance_state_string() const 181 : { 182 0 : return instance_state_string(instance_state_); 183 : } 184 : 185 : OPENDDS_END_VERSIONED_NAMESPACE_DECL