InstanceState.h

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 #ifndef OPENDDS_DCPS_INSTANCESTATE_H
00009 #define OPENDDS_DCPS_INSTANCESTATE_H
00010 
00011 #include "dcps_export.h"
00012 #include "ace/Time_Value.h"
00013 #include "dds/DdsDcpsInfrastructureC.h"
00014 #include "dds/DCPS/Definitions.h"
00015 #include "dds/DCPS/GuidUtils.h"
00016 #include "dds/DCPS/PoolAllocator.h"
00017 
00018 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00019 #pragma once
00020 #endif /* ACE_LACKS_PRAGMA_ONCE */
00021 
00022 namespace OpenDDS {
00023 namespace DCPS {
00024 
00025 class DataReaderImpl;
00026 class ReceivedDataElement;
00027 
00028 /**
00029  * @class InstanceState
00030  *
00031  * @brief manage the states of a received data instance.
00032  *
00033  * Provide a mechanism to manage the view state and instance
00034  * state values for an instance contained within a DataReader.
00035  * The instance_state and view_state are managed by this class.
00036  * Accessors are provided to query the current value of each of
00037  * these states.
00038  */
00039 class OpenDDS_Dcps_Export InstanceState : public ACE_Event_Handler {
00040 public:
00041   /// Constructor.
00042   InstanceState(DataReaderImpl* reader,
00043                 ACE_Recursive_Thread_Mutex& lock,
00044                 DDS::InstanceHandle_t handle);
00045 
00046   /// Destructor
00047   virtual ~InstanceState();
00048 
00049   /// Populate the SampleInfo structure
00050   void sample_info(DDS::SampleInfo& si,
00051                    const ReceivedDataElement* de);
00052 
00053   /// Access instance state.
00054   DDS::InstanceStateKind instance_state() const;
00055 
00056   /// Access view state.
00057   DDS::ViewStateKind view_state() const;
00058 
00059   /// Access disposed generation count
00060   size_t disposed_generation_count() const;
00061 
00062   /// Access no writers generation count
00063   size_t no_writers_generation_count() const;
00064 
00065   /// DISPOSE message received for this instance.
00066   /// Return flag indicates whether the instance state was changed.
00067   /// This flag is used by concreate DataReader to determine whether
00068   /// it should notify listener. If state is not changed, the dispose
00069   /// message is ignored.
00070   bool dispose_was_received(const PublicationId& writer_id);
00071 
00072   /// UNREGISTER message received for this instance.
00073   /// Return flag indicates whether the instance state was changed.
00074   /// This flag is used by concreate DataReader to determine whether
00075   /// it should notify listener. If state is not changed, the unregister
00076   /// message is ignored.
00077   bool unregister_was_received(const PublicationId& writer_id);
00078 
00079   /// Data sample received for this instance.
00080   void data_was_received(const PublicationId& writer_id);
00081 
00082   /// LIVELINESS message received for this DataWriter.
00083   void lively(const PublicationId& writer_id);
00084 
00085   /// A read or take operation has been performed on this instance.
00086   void accessed();
00087 
00088   bool most_recent_generation(ReceivedDataElement* item) const;
00089 
00090   /// DataReader has become empty.  Returns true if the instance was released.
00091   bool empty(bool value);
00092 
00093   /// Schedule a pending release of resources.
00094   void schedule_pending();
00095 
00096   /// Schedule an immediate release of resources.
00097   void schedule_release();
00098 
00099   /// Cancel a scheduled or pending release of resources.
00100   void cancel_release();
00101 
00102   /// Remove the instance if it's instance has no samples
00103   /// and no writers.
00104   /// Returns true if the instance was released.
00105   bool release_if_empty();
00106 
00107   /// Remove the instance immediately.
00108   void release();
00109 
00110   /// tell this instance when a DataWriter transitions to NOT_ALIVE
00111   void writer_became_dead(const PublicationId& writer_id,
00112                           int num_alive_writers,
00113                           const ACE_Time_Value& when);
00114 
00115   DataReaderImpl* data_reader() const;
00116 
00117   virtual int handle_timeout(const ACE_Time_Value& current_time,
00118                              const void* arg);
00119 
00120   void set_owner (const PublicationId& owner);
00121   PublicationId& get_owner ();
00122   bool is_exclusive () const;
00123   bool registered();
00124   void registered (bool flag);
00125   bool is_last (const PublicationId& pub);
00126 
00127   bool no_writer () const;
00128 
00129   void reset_ownership (::DDS::InstanceHandle_t instance);
00130 
00131   DDS::InstanceHandle_t instance_handle() const { return handle_; }
00132 
00133 private:
00134   ACE_Recursive_Thread_Mutex& lock_;
00135 
00136   /**
00137    * Current instance state.
00138    *
00139    * Can have values defined as:
00140    *
00141    *   DDS::ALIVE_INSTANCE_STATE
00142    *   DDS::NOT_ALIVE_DISPOSED_INSTANCE_STATE
00143    *   DDS::NOT_ALIVE_NO_WRITERS_INSTANCE_STATE
00144    *
00145    * and can be checked with the masks:
00146    *
00147    *   DDS::ANY_INSTANCE_STATE
00148    *   DDS::NOT_ALIVE_INSTANCE_STATE
00149    */
00150   DDS::InstanceStateKind instance_state_;
00151 
00152   /**
00153    * Current instance view state.
00154    *
00155    * Can have values defined as:
00156    *
00157    *   DDS::NEW_VIEW_STATE
00158    *   DDS::NOT_NEW_VIEW_STATE
00159    *
00160    * and can be checked with the mask:
00161    *
00162    *   DDS::ANY_VIEW_STATE
00163    */
00164   DDS::ViewStateKind view_state_;
00165 
00166   /// Number of times the instance state changes
00167   /// from NOT_ALIVE_DISPOSED to ALIVE.
00168   size_t disposed_generation_count_;
00169 
00170   /// Number of times the instance state changes
00171   /// from NOT_ALIVE_NO_WRITERS to ALIVE.
00172   size_t no_writers_generation_count_;
00173 
00174   /**
00175    * Keep track of whether the DataReader is empty or not.
00176    */
00177   bool empty_;
00178 
00179   /**
00180    * Keep track of whether the instance is waiting to be released.
00181    */
00182   bool release_pending_;
00183 
00184   /**
00185    * Keep track of a scheduled release timer.
00186    */
00187   long release_timer_id_;
00188 
00189   /**
00190    * Reference to our containing reader.  This is used to call back
00191    * and notify the reader that liveliness has been lost on this
00192    * instance.  It is also queried to determine if the DataReader is
00193    * empty -- that it contains no more sample data.
00194    */
00195   DataReaderImpl* reader_;
00196   DDS::InstanceHandle_t handle_;
00197 
00198   RepoIdSet writers_;
00199   PublicationId owner_;
00200   bool exclusive_;
00201   /// registered with participant so it can be calledback as
00202   /// the owner is updated.
00203   bool registered_;
00204 };
00205 
00206 } // namespace DCPS
00207 } // namespace OpenDDS
00208 
00209 #if defined (__ACE_INLINE__)
00210 # include "InstanceState.inl"
00211 #endif  /* __ACE_INLINE__ */
00212 
00213 #endif /* OPENDDS_DCPS_INSTANCESTATE_H */

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