OpenDDS::DCPS::OfferedDeadlineWatchdog Class Reference

Watchdog responsible calling the DataWriterListener when the deadline period expires. More...

#include <OfferedDeadlineWatchdog.h>

Inheritance diagram for OpenDDS::DCPS::OfferedDeadlineWatchdog:

Inheritance graph
[legend]
Collaboration diagram for OpenDDS::DCPS::OfferedDeadlineWatchdog:

Collaboration graph
[legend]
List of all members.

Public Types

typedef ACE_Recursive_Thread_Mutex lock_type
typedef ACE_Reverse_Lock<
lock_type
reverse_lock_type

Public Member Functions

 OfferedDeadlineWatchdog (lock_type &lock, DDS::DeadlineQosPolicy qos, OpenDDS::DCPS::DataWriterImpl *writer_impl, DDS::DataWriter_ptr writer, DDS::OfferedDeadlineMissedStatus &status, CORBA::Long &last_total_count)
 Constructor.
virtual ~OfferedDeadlineWatchdog ()
 Destructor.
virtual void execute (void const *act, bool timer_called)
 Operation to be executed when the associated timer expires.
void schedule_timer (PublicationInstance *instance)
void cancel_timer (PublicationInstance *instance)
virtual void reschedule_deadline ()
 Re-schedule timer for all instances of the DataWriter.

Private Attributes

lock_typestatus_lock_
 Lock for synchronization of status_ member.
reverse_lock_type reverse_status_lock_
 Reverse lock used for releasing the status_lock_ listener upcall.
OpenDDS::DCPS::DataWriterImpl
*const 
writer_impl_
DDS::DataWriter_var writer_
DDS::OfferedDeadlineMissedStatusstatus_
CORBA::Long & last_total_count_
 Last total_count when status was last checked.

Detailed Description

Watchdog responsible calling the DataWriterListener when the deadline period expires.

This watchdog object calls the on_offered_deadline_missed() listener callback when the configured finite deadline period expires.

Definition at line 37 of file OfferedDeadlineWatchdog.h.


Member Typedef Documentation

typedef ACE_Recursive_Thread_Mutex OpenDDS::DCPS::OfferedDeadlineWatchdog::lock_type

Definition at line 40 of file OfferedDeadlineWatchdog.h.

typedef ACE_Reverse_Lock<lock_type> OpenDDS::DCPS::OfferedDeadlineWatchdog::reverse_lock_type

Definition at line 41 of file OfferedDeadlineWatchdog.h.


Constructor & Destructor Documentation

OpenDDS::DCPS::OfferedDeadlineWatchdog::OfferedDeadlineWatchdog ( lock_type lock,
DDS::DeadlineQosPolicy  qos,
OpenDDS::DCPS::DataWriterImpl writer_impl,
DDS::DataWriter_ptr  writer,
DDS::OfferedDeadlineMissedStatus status,
CORBA::Long &  last_total_count 
)

Constructor.

Definition at line 15 of file OfferedDeadlineWatchdog.cpp.

00022   : Watchdog(duration_to_time_value(qos.period))
00023   , status_lock_(lock)
00024   , reverse_status_lock_(status_lock_)
00025   , writer_impl_(writer_impl)
00026   , writer_(DDS::DataWriter::_duplicate(writer))
00027   , status_(status)
00028   , last_total_count_(last_total_count)
00029 {
00030 }

OpenDDS::DCPS::OfferedDeadlineWatchdog::~OfferedDeadlineWatchdog (  )  [virtual]

Destructor.

Definition at line 32 of file OfferedDeadlineWatchdog.cpp.

00033 {
00034 }


Member Function Documentation

void OpenDDS::DCPS::OfferedDeadlineWatchdog::cancel_timer ( PublicationInstance instance  ) 

Definition at line 45 of file OfferedDeadlineWatchdog.cpp.

References OpenDDS::DCPS::Watchdog::cancel_timer(), and OpenDDS::DCPS::PublicationInstance::deadline_timer_id_.

Referenced by OpenDDS::DCPS::WriteDataContainer::dispose(), execute(), and OpenDDS::DCPS::WriteDataContainer::unregister().

00046 {
00047   if (instance->deadline_timer_id_ != -1) {
00048     Watchdog::cancel_timer(instance->deadline_timer_id_);
00049     instance->deadline_timer_id_ = -1;
00050   }
00051 }

void OpenDDS::DCPS::OfferedDeadlineWatchdog::execute ( void const *  act,
bool  timer_called 
) [virtual]

Operation to be executed when the associated timer expires.

This Watchdog object updates the DDS::OfferedDeadlineMissed structure, and calls DataWriterListener::on_requested_deadline_missed().

Implements OpenDDS::DCPS::Watchdog.

Definition at line 54 of file OfferedDeadlineWatchdog.cpp.

References cancel_timer(), OpenDDS::DCPS::PublicationInstance::cur_sample_tv_, OpenDDS::DCPS::PublicationInstance::deadline_timer_id_, OpenDDS::DCPS::PublicationInstance::instance_handle_, OpenDDS::DCPS::Watchdog::interval_, DDS::OfferedDeadlineMissedStatus::last_instance_handle, OpenDDS::DCPS::PublicationInstance::last_sample_tv_, last_total_count_, OpenDDS::DCPS::DataWriterImpl::listener_for(), OpenDDS::DCPS::EntityImpl::notify_status_condition(), DDS::OFFERED_DEADLINE_MISSED_STATUS, schedule_timer(), OpenDDS::DCPS::EntityImpl::set_status_changed_flag(), status_, DDS::OfferedDeadlineMissedStatus::total_count, DDS::OfferedDeadlineMissedStatus::total_count_change, and writer_impl_.

Referenced by OpenDDS::DCPS::WriteDataContainer::enqueue().

00055 {
00056   OpenDDS::DCPS::PublicationInstance * instance = (OpenDDS::DCPS::PublicationInstance *)act;
00057 
00058   if (instance->deadline_timer_id_ != -1) {
00059     bool missed = false;
00060 
00061     if (instance->cur_sample_tv_  == ACE_Time_Value::zero) { // not write any sample.
00062       missed = true;
00063 
00064     } else if (timer_called) { // handle_timeout is called
00065       ACE_Time_Value diff = ACE_OS::gettimeofday() - instance->cur_sample_tv_;
00066       missed = diff >= this->interval_;
00067 
00068     } else if (instance->last_sample_tv_ != ACE_Time_Value::zero) { // upon writing sample.
00069       ACE_Time_Value diff = instance->cur_sample_tv_ - instance->last_sample_tv_;
00070       missed = diff > this->interval_;
00071     }
00072 
00073     if (missed) {
00074       ACE_GUARD(ACE_Recursive_Thread_Mutex, monitor, this->status_lock_);
00075 
00076       if (timer_called) {
00077         ++this->status_.total_count;
00078         this->status_.total_count_change =
00079           this->status_.total_count - this->last_total_count_;
00080         this->status_.last_instance_handle = instance->instance_handle_;
00081 
00082         this->writer_impl_->set_status_changed_flag(
00083           DDS::OFFERED_DEADLINE_MISSED_STATUS, true);
00084 
00085         DDS::DataWriterListener_var listener =
00086           this->writer_impl_->listener_for(
00087             DDS::OFFERED_DEADLINE_MISSED_STATUS);
00088 
00089         if (! CORBA::is_nil(listener.in())) {
00090           // Copy before releasing the lock.
00091           DDS::OfferedDeadlineMissedStatus const status = this->status_;
00092 
00093           // Release the lock during the upcall.
00094           ACE_GUARD(reverse_lock_type, reverse_monitor, this->reverse_status_lock_);
00095 
00096           // @todo Will this operation ever throw?  If so we may want to
00097           //       catch all exceptions, and act accordingly.
00098           listener->on_offered_deadline_missed(this->writer_.in(),
00099                                               status);
00100         }
00101 
00102         this->writer_impl_->notify_status_condition();
00103       }
00104     }
00105 
00106     // This next part is without status_lock_ held to avoid reactor deadlock.
00107     if (!timer_called) {
00108       this->cancel_timer(instance);
00109       this->schedule_timer(instance);
00110     }
00111 
00112   } else {
00113     // not an error - timer is scheduled asynchronously so we can get here
00114     // via WriteDataContainer::enqueue() before schedule_timer() is done
00115   }
00116 }

void OpenDDS::DCPS::OfferedDeadlineWatchdog::reschedule_deadline (  )  [virtual]

Re-schedule timer for all instances of the DataWriter.

Implements OpenDDS::DCPS::Watchdog.

Definition at line 119 of file OfferedDeadlineWatchdog.cpp.

References OpenDDS::DCPS::DataWriterImpl::reschedule_deadline(), and writer_impl_.

00120 {
00121   this->writer_impl_->reschedule_deadline();
00122 }

void OpenDDS::DCPS::OfferedDeadlineWatchdog::schedule_timer ( PublicationInstance instance  ) 

Definition at line 37 of file OfferedDeadlineWatchdog.cpp.

References OpenDDS::DCPS::PublicationInstance::deadline_timer_id_, and OpenDDS::DCPS::Watchdog::schedule_timer().

Referenced by execute(), and OpenDDS::DCPS::WriteDataContainer::register_instance().

00038 {
00039   if (instance->deadline_timer_id_ == -1) {
00040     instance->deadline_timer_id_ = Watchdog::schedule_timer((void*)instance, this->interval_);
00041   }
00042 }


Member Data Documentation

CORBA::Long& OpenDDS::DCPS::OfferedDeadlineWatchdog::last_total_count_ [private]

Last total_count when status was last checked.

Definition at line 92 of file OfferedDeadlineWatchdog.h.

Referenced by execute().

reverse_lock_type OpenDDS::DCPS::OfferedDeadlineWatchdog::reverse_status_lock_ [private]

Reverse lock used for releasing the status_lock_ listener upcall.

Definition at line 77 of file OfferedDeadlineWatchdog.h.

DDS::OfferedDeadlineMissedStatus& OpenDDS::DCPS::OfferedDeadlineWatchdog::status_ [private]

Reference to the missed requested deadline status structure.

Definition at line 89 of file OfferedDeadlineWatchdog.h.

Referenced by execute().

lock_type& OpenDDS::DCPS::OfferedDeadlineWatchdog::status_lock_ [private]

Lock for synchronization of status_ member.

Definition at line 75 of file OfferedDeadlineWatchdog.h.

DDS::DataWriter_var OpenDDS::DCPS::OfferedDeadlineWatchdog::writer_ [private]

Reference to DataWriter passed to listener when the deadline expires.

Definition at line 85 of file OfferedDeadlineWatchdog.h.

OpenDDS::DCPS::DataWriterImpl* const OpenDDS::DCPS::OfferedDeadlineWatchdog::writer_impl_ [private]

Pointer to the DataWriterImpl object from which the DataWriterListener is obtained.

Definition at line 81 of file OfferedDeadlineWatchdog.h.

Referenced by execute(), and reschedule_deadline().


The documentation for this class was generated from the following files:
Generated on Fri Feb 12 20:06:20 2016 for OpenDDS by  doxygen 1.4.7