diff options
author | William R. Otte <wotte@dre.vanderbilt.edu> | 2006-07-24 15:50:21 +0000 |
---|---|---|
committer | William R. Otte <wotte@dre.vanderbilt.edu> | 2006-07-24 15:50:21 +0000 |
commit | 3aff90f4a822fcf5d902bbfbcc9fa931d6191a8c (patch) | |
tree | 197c810e5f5bce17b1233a7cb8d7b50c0bcd25e2 /TAO/orbsvcs/orbsvcs/Time | |
parent | 6b846cf03c0bcbd8c276cb0af61a181e5f98eaae (diff) | |
download | ATCD-3aff90f4a822fcf5d902bbfbcc9fa931d6191a8c.tar.gz |
Repo restructuring
Diffstat (limited to 'TAO/orbsvcs/orbsvcs/Time')
-rw-r--r-- | TAO/orbsvcs/orbsvcs/Time/TAO_TIO.cpp | 288 | ||||
-rw-r--r-- | TAO/orbsvcs/orbsvcs/Time/TAO_TIO.h | 95 | ||||
-rw-r--r-- | TAO/orbsvcs/orbsvcs/Time/TAO_Time_Service_Clerk.cpp | 181 | ||||
-rw-r--r-- | TAO/orbsvcs/orbsvcs/Time/TAO_Time_Service_Clerk.h | 141 | ||||
-rw-r--r-- | TAO/orbsvcs/orbsvcs/Time/TAO_Time_Service_Server.cpp | 127 | ||||
-rw-r--r-- | TAO/orbsvcs/orbsvcs/Time/TAO_Time_Service_Server.h | 87 | ||||
-rw-r--r-- | TAO/orbsvcs/orbsvcs/Time/TAO_UTO.cpp | 246 | ||||
-rw-r--r-- | TAO/orbsvcs/orbsvcs/Time/TAO_UTO.h | 119 | ||||
-rw-r--r-- | TAO/orbsvcs/orbsvcs/Time/Timer_Helper.cpp | 156 | ||||
-rw-r--r-- | TAO/orbsvcs/orbsvcs/Time/Timer_Helper.h | 80 | ||||
-rw-r--r-- | TAO/orbsvcs/orbsvcs/Time/time_export.h | 40 |
11 files changed, 1560 insertions, 0 deletions
diff --git a/TAO/orbsvcs/orbsvcs/Time/TAO_TIO.cpp b/TAO/orbsvcs/orbsvcs/Time/TAO_TIO.cpp new file mode 100644 index 00000000000..55708a8dc13 --- /dev/null +++ b/TAO/orbsvcs/orbsvcs/Time/TAO_TIO.cpp @@ -0,0 +1,288 @@ +// $Id$ + +#include "orbsvcs/Time/TAO_TIO.h" + +TAO_BEGIN_VERSIONED_NAMESPACE_DECL + +// Constructor. +TAO_TIO::TAO_TIO (TimeBase::TimeT lower, + TimeBase::TimeT upper) +{ + this->attr_time_interval.lower_bound = lower; + this->attr_time_interval.upper_bound = upper; +} + +// Destructor. +TAO_TIO::~TAO_TIO (void) +{ +} + +// This is the get method for the attribute time interval. + +TimeBase::IntervalT +TAO_TIO::time_interval (ACE_ENV_SINGLE_ARG_DECL_NOT_USED) + ACE_THROW_SPEC ((CORBA::SystemException)) +{ + return attr_time_interval; +} + +// This operation returns a value of type OverlapType depending on how +// the interval in the object and the time range represented by the +// parameter UTO overlap. If OverlapType is not OTNoOverlap, then the +// out parameter overlap contains the overlap interval, otherwise the +// out parameter contains the gap between the two intervals. + +CosTime::OverlapType +TAO_TIO::spans (CosTime::UTO_ptr uto, + CosTime::TIO_out overlap + ACE_ENV_ARG_DECL) + ACE_THROW_SPEC ((CORBA::SystemException)) +{ + TAO_TIO *tio = 0; + + ACE_TRY + { + TimeBase::TimeT lb1 = + this->time_interval ().lower_bound; + + TimeBase::TimeT up1 = + this->time_interval ().upper_bound; + + TimeBase::TimeT tmp1 = uto->time (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + + TimeBase::TimeT tmp2 = uto->inaccuracy (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + + TimeBase::TimeT lb2 = tmp1 - tmp2; + + + tmp1 = uto->time (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + + tmp2 = uto->inaccuracy (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + + TimeBase::TimeT up2 = tmp1 + tmp2; + + if (lb1 == lb2 && up1 == up2) + { + ACE_NEW_RETURN (tio, + TAO_TIO (lb1, up1), + CosTime::OTNoOverlap); + overlap = tio->_this (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK_RETURN (CosTime::OTNoOverlap); + + return CosTime::OTOverlap; + } + else if (lb1 > lb2 && up1 < up2) + { + ACE_NEW_RETURN (tio, + TAO_TIO (lb1, up1), + CosTime::OTNoOverlap); + + overlap = tio->_this (); + ACE_CHECK_RETURN (CosTime::OTNoOverlap); + + return CosTime::OTContained; + } + else if (lb1 < lb2 && up1 > up2) + { + ACE_NEW_RETURN (tio, + TAO_TIO (lb2, up2), + CosTime::OTNoOverlap); + + overlap = tio->_this (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK_RETURN (CosTime::OTNoOverlap); + + return CosTime::OTContained; + } + else if (lb1 < lb2) + { + if (up1 < lb2) + { + ACE_NEW_RETURN (tio, + TAO_TIO (0, 0), + CosTime::OTNoOverlap); + + overlap = tio->_this (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK_RETURN (CosTime::OTNoOverlap); + + return CosTime::OTNoOverlap; + } + else + { + ACE_NEW_RETURN (tio, + TAO_TIO (lb2, up1), + CosTime::OTNoOverlap); + overlap = tio->_this (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK_RETURN (CosTime::OTNoOverlap); + + return CosTime::OTOverlap; + } + } + else if (up2 < lb1) + { + + ACE_NEW_RETURN (tio, + TAO_TIO (0, 0), + CosTime::OTNoOverlap); + + overlap = tio->_this (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK_RETURN (CosTime::OTNoOverlap); + + return CosTime::OTNoOverlap; + } + else + { + ACE_NEW_RETURN (tio, + TAO_TIO (lb1, up2), + CosTime::OTNoOverlap); + + overlap = tio->_this (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK_RETURN (CosTime::OTNoOverlap); + } + } + ACE_CATCHANY + { + ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, "Exception:"); + } + ACE_ENDTRY; + ACE_CHECK_RETURN (CosTime::OTNoOverlap); + + return CosTime::OTNoOverlap; +} + +// This operation returns a value of type OverlapType depending on how +// the interval in the object and interval in the parameter TIO +// overlap. If OverlapType is not OTNoOverlap, then the out parameter +// overlap contains the overlap interval, otherwise the out parameter +// contains the gap between the two intervals. + +CosTime::OverlapType +TAO_TIO::overlaps (CosTime::TIO_ptr tio, + CosTime::TIO_out overlap + ACE_ENV_ARG_DECL) + ACE_THROW_SPEC ((CORBA::SystemException)) +{ + TAO_TIO *tio_i = 0; + + TimeBase::TimeT lb1 = + this->time_interval ().lower_bound; + + TimeBase::TimeT up1 = + this->time_interval ().upper_bound; + + TimeBase::TimeT lb2 = + tio->time_interval ().lower_bound; + + TimeBase::TimeT up2 = + tio->time_interval ().upper_bound; + + if (lb1 == lb2 && up1 == up2) + { + ACE_NEW_THROW_EX (tio_i, + TAO_TIO (lb1, up1), + CORBA::NO_MEMORY ()); + + ACE_CHECK_RETURN (CosTime::OTNoOverlap); + + overlap = tio_i->_this (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK_RETURN (CosTime::OTNoOverlap); + + return CosTime::OTOverlap; + } + else if (lb1 > lb2 && up1 < up2) + { + ACE_NEW_THROW_EX (tio_i, + TAO_TIO (lb1, up1), + CORBA::NO_MEMORY ()); + ACE_CHECK_RETURN (CosTime::OTNoOverlap); + + overlap = tio_i->_this (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK_RETURN (CosTime::OTNoOverlap); + + return CosTime::OTContained; + } + else if (lb1 < lb2 && up1 > up2) + { + ACE_NEW_THROW_EX (tio_i, + TAO_TIO (lb2, up2), + CORBA::NO_MEMORY ()); + ACE_CHECK_RETURN (CosTime::OTNoOverlap); + + overlap = tio_i->_this (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK_RETURN (CosTime::OTNoOverlap); + + return CosTime::OTContained; + } + else if (lb1 < lb2) + { + if (up1 < lb2) + { + ACE_NEW_THROW_EX (tio_i, + TAO_TIO (0, 0), + CORBA::NO_MEMORY ()); + ACE_CHECK_RETURN (CosTime::OTNoOverlap); + overlap = tio_i->_this (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK_RETURN (CosTime::OTNoOverlap); + + return CosTime::OTNoOverlap; + } + else + { + ACE_NEW_THROW_EX (tio_i, + TAO_TIO (lb2, up1), + CORBA::NO_MEMORY ()); + ACE_CHECK_RETURN (CosTime::OTNoOverlap); + + overlap = tio_i->_this (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK_RETURN (CosTime::OTNoOverlap); + + return CosTime::OTOverlap; + } + } + else if (up2 < lb1) + { + ACE_NEW_THROW_EX (tio_i, + TAO_TIO (0, 0), + CORBA::NO_MEMORY ()); + ACE_CHECK_RETURN (CosTime::OTNoOverlap); + + overlap = tio_i->_this (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK_RETURN (CosTime::OTNoOverlap); + + return CosTime::OTNoOverlap; + } + else + { + ACE_NEW_THROW_EX (tio_i, + TAO_TIO (lb1, up2), + CORBA::NO_MEMORY ()); + ACE_CHECK_RETURN (CosTime::OTNoOverlap); + overlap = tio_i->_this (); + } + + return CosTime::OTNoOverlap; +} + +CosTime::UTO_ptr +TAO_TIO::time (ACE_ENV_SINGLE_ARG_DECL) + ACE_THROW_SPEC ((CORBA::SystemException)) +{ + TAO_UTO *uto = 0; + + ACE_NEW_THROW_EX (uto, + TAO_UTO ((this->time_interval ().upper_bound - + this->time_interval ().lower_bound) / 2, + this->time_interval ().upper_bound - + this->time_interval ().lower_bound, + 0), + CORBA::NO_MEMORY ()); + + ACE_CHECK_RETURN (CosTime::UTO::_nil ()); + + return uto->_this (ACE_ENV_SINGLE_ARG_PARAMETER); +} + +TAO_END_VERSIONED_NAMESPACE_DECL diff --git a/TAO/orbsvcs/orbsvcs/Time/TAO_TIO.h b/TAO/orbsvcs/orbsvcs/Time/TAO_TIO.h new file mode 100644 index 00000000000..ff4f0e8ab36 --- /dev/null +++ b/TAO/orbsvcs/orbsvcs/Time/TAO_TIO.h @@ -0,0 +1,95 @@ +// -*- C++ -*- + +//============================================================================= +/** + * @file TAO_TIO.h + * + * $Id$ + * + * This class implements the CosTime::TIO IDL interface. + * + * + * @author Vishal Kachroo <vishal@cs.wustl.edu> + */ +//============================================================================= + + +#ifndef TAO_TIO_H +#define TAO_TIO_H +#include /**/ "ace/pre.h" + +#include "orbsvcs/TimeServiceS.h" +#include "orbsvcs/Time/TAO_UTO.h" +#include "orbsvcs/Time/time_export.h" + +TAO_BEGIN_VERSIONED_NAMESPACE_DECL + +/** + * @class TAO_TIO + * + * @brief Time Interval Object Implementation. + * + * The TIO represents a time interval and has operations to + * compare itself with a UTO or another TIO. It also has an + * operation to create a UTO from the value of it's time + * interval. + */ +class TAO_Time_Export TAO_TIO : public POA_CosTime::TIO +{ +public: + // = Initialization and termination methods. + /// Constructor. + TAO_TIO (TimeBase::TimeT lower, + TimeBase::TimeT upper); + + /// Destructor. + ~TAO_TIO (void); + + /// This is the get method for the attribute time interval. + virtual TimeBase::IntervalT time_interval ( + ACE_ENV_SINGLE_ARG_DECL_WITH_DEFAULTS) + ACE_THROW_SPEC ((CORBA::SystemException)); + + /** + * This operation returns a value of type OverlapType depending on + * how the interval in the object and the time range represented by + * the parameter UTO overlap. If OverlapType is not OTNoOverlap, + * then the out parameter overlap contains the overlap interval, + * otherwise the out parameter contains the gap between the two + * intervals. + */ + virtual CosTime::OverlapType spans (CosTime::UTO_ptr time, + CosTime::TIO_out overlap + ACE_ENV_ARG_DECL) + ACE_THROW_SPEC ((CORBA::SystemException)); + + /** + * This operation returns a value of type OverlapType depending on + * how the interval in the object and interval in the parameter TIO + * overlap. If OverlapType is not OTNoOverlap, then the out + * parameter overlap contains the overlap interval, otherwise the + * out parameter contains the gap between the two intervals. + */ + virtual CosTime::OverlapType overlaps (CosTime::TIO_ptr interval, + CosTime::TIO_out overlap + ACE_ENV_ARG_DECL) + ACE_THROW_SPEC ((CORBA::SystemException)); + + /** + * Returns a UTO in which the inaccuracy interval is equal to the + * time interval in the TIO and time value is the midpoint of the + * interval. + */ + virtual CosTime::UTO_ptr time (ACE_ENV_SINGLE_ARG_DECL) + ACE_THROW_SPEC ((CORBA::SystemException)); + +private: + /// This attribute returns an IntervalT structure with the values of + /// its fields filled in with the corresponding values from the TIO. + TimeBase::IntervalT attr_time_interval; +}; + +TAO_END_VERSIONED_NAMESPACE_DECL + +#include /**/ "ace/post.h" +#endif /* TAO_TIO_H */ diff --git a/TAO/orbsvcs/orbsvcs/Time/TAO_Time_Service_Clerk.cpp b/TAO/orbsvcs/orbsvcs/Time/TAO_Time_Service_Clerk.cpp new file mode 100644 index 00000000000..710c8fad7ee --- /dev/null +++ b/TAO/orbsvcs/orbsvcs/Time/TAO_Time_Service_Clerk.cpp @@ -0,0 +1,181 @@ +// -*- C++ -*- +// $Id$ + +#include "orbsvcs/Time/TAO_Time_Service_Clerk.h" +#include "orbsvcs/Time/TAO_TIO.h" +#include "orbsvcs/Time/TAO_UTO.h" + +#include "tao/ORB_Core.h" +#include "ace/OS_NS_sys_time.h" + +TAO_BEGIN_VERSIONED_NAMESPACE_DECL + +// Constructor. +TAO_Time_Service_Clerk::TAO_Time_Service_Clerk (int timer_value, + int timer_value_usecs, + const IORS& servers) + : server_ (servers), + helper_ (this) +{ + // Schedule the helper to be invoked by the reactor + // periodically. + + if (TAO_ORB_Core_instance ()->reactor ()->schedule_timer + (&helper_, + 0, + ACE_Time_Value::zero, + ACE_Time_Value(timer_value,timer_value_usecs)) == -1) + ACE_ERROR ((LM_ERROR, + "%p\n", + "schedule_timer ()")); +} + +// Destructor. + +TAO_Time_Service_Clerk::~TAO_Time_Service_Clerk (void) +{ +} + +// This method returns the global time and an estimate of inaccuracy +// in a UTO. + +CosTime::UTO_ptr +TAO_Time_Service_Clerk::universal_time (ACE_ENV_SINGLE_ARG_DECL) + ACE_THROW_SPEC ((CORBA::SystemException, + CosTime::TimeUnavailable)) +{ + TAO_UTO *uto = 0; + + ACE_NEW_THROW_EX (uto, + TAO_UTO (this->get_time (), + this->inaccuracy (), + this->time_displacement_factor ()), + CORBA::NO_MEMORY ()); + ACE_CHECK_RETURN (CosTime::UTO::_nil ()); + // Return the global time as a UTO. + + return uto->_this (ACE_ENV_SINGLE_ARG_PARAMETER); +} + +// This method returns the global time in a UTO only if the time can +// be guaranteed to have been obtained securely. This method is not +// implemented currently. + +CosTime::UTO_ptr +TAO_Time_Service_Clerk::secure_universal_time (ACE_ENV_SINGLE_ARG_DECL) + ACE_THROW_SPEC ((CORBA::SystemException, + CosTime::TimeUnavailable)) +{ + ACE_THROW_RETURN (CORBA::NO_IMPLEMENT (), + CosTime::UTO::_nil ()); +} + +// This creates a new UTO based on the given parameters. + +CosTime::UTO_ptr +TAO_Time_Service_Clerk::new_universal_time (TimeBase::TimeT time, + TimeBase::InaccuracyT inaccuracy, + TimeBase::TdfT tdf + ACE_ENV_ARG_DECL) + ACE_THROW_SPEC ((CORBA::SystemException)) +{ + TAO_UTO *uto = 0; + + ACE_NEW_THROW_EX (uto, + TAO_UTO (time, + inaccuracy, + tdf), + CORBA::NO_MEMORY ()); + ACE_CHECK_RETURN (CosTime::UTO::_nil ()); + + return uto->_this (ACE_ENV_SINGLE_ARG_PARAMETER); +} + +// This creates a new UTO given a time in the UtcT form. + +CosTime::UTO_ptr +TAO_Time_Service_Clerk::uto_from_utc (const TimeBase::UtcT &utc + ACE_ENV_ARG_DECL) + ACE_THROW_SPEC ((CORBA::SystemException)) +{ + TAO_UTO *uto = 0; + + // Use the low and high values of inaccuracy + // to calculate the total inaccuracy. + + TimeBase::InaccuracyT inaccuracy = utc.inacchi; + inaccuracy <<= 32; + inaccuracy |= utc.inacclo; + + ACE_NEW_THROW_EX (uto, + TAO_UTO (utc.time, + inaccuracy, + utc.tdf), + CORBA::NO_MEMORY ()); + ACE_CHECK_RETURN (CosTime::UTO::_nil ()); + return uto->_this (ACE_ENV_SINGLE_ARG_PARAMETER); +} + +// This creates a new TIO with the given parameters. + +CosTime::TIO_ptr +TAO_Time_Service_Clerk::new_interval (TimeBase::TimeT lower, + TimeBase::TimeT upper + ACE_ENV_ARG_DECL) + ACE_THROW_SPEC ((CORBA::SystemException)) +{ + TAO_TIO *tio = 0; + + ACE_NEW_THROW_EX (tio, + TAO_TIO (lower, + upper), + CORBA::NO_MEMORY ()); + ACE_CHECK_RETURN (CosTime::TIO::_nil ()); + return tio->_this (ACE_ENV_SINGLE_ARG_PARAMETER); +} + +CORBA::ULongLong +TAO_Time_Service_Clerk::get_time (void) +{ + // Globally sync. time is the latest global time plus the time + // elapsed since last updation was done. + + const ACE_Time_Value timeofday = ACE_OS::gettimeofday (); + + return (CORBA::ULongLong) (static_cast<CORBA::ULongLong> (timeofday.sec ()) * + static_cast<ACE_UINT32> (10000000) + + static_cast<CORBA::ULongLong> (timeofday.usec () * 10)) + - this->update_timestamp_ + + this->time_; +} + +// Returns the time displacement factor in minutes. +// This is displacement from the GMT. +CORBA::Short +TAO_Time_Service_Clerk::time_displacement_factor (void) +{ + return time_displacement_factor_; +} + +// Sets the TDF. +void +TAO_Time_Service_Clerk::time_displacement_factor (CORBA::Short tdf) +{ + this->time_displacement_factor_ = tdf; +} + +// GET method for inaccuracy. +TimeBase::InaccuracyT +TAO_Time_Service_Clerk::inaccuracy (void) +{ + return this->inaccuracy_; +} + +// SET method for inaccuracy. +void +TAO_Time_Service_Clerk::inaccuracy (TimeBase::InaccuracyT inaccuracy) +{ + this->inaccuracy_ = inaccuracy; +} + +TAO_END_VERSIONED_NAMESPACE_DECL diff --git a/TAO/orbsvcs/orbsvcs/Time/TAO_Time_Service_Clerk.h b/TAO/orbsvcs/orbsvcs/Time/TAO_Time_Service_Clerk.h new file mode 100644 index 00000000000..ef8d5a9a3dd --- /dev/null +++ b/TAO/orbsvcs/orbsvcs/Time/TAO_Time_Service_Clerk.h @@ -0,0 +1,141 @@ +// -*- C++ -*- + +//============================================================================= +/** + * @file TAO_Time_Service_Clerk.h + * + * $Id$ + * + * This class implements the CosTime::TimeService IDL interface. + * + * + * @author Vishal Kachroo <vishal@cs.wustl.edu> + */ +//============================================================================= + + +#ifndef TAO_TIME_SERVICE_CLERK_H +#define TAO_TIME_SERVICE_CLERK_H +#include /**/ "ace/pre.h" + +#include "ace/Reactor.h" + +#include "orbsvcs/TimeServiceS.h" +#include "orbsvcs/Time/Timer_Helper.h" +#include "orbsvcs/Time/time_export.h" + + +TAO_BEGIN_VERSIONED_NAMESPACE_DECL + +/** + * @class TAO_Time_Service_Clerk + * + * @brief TimeService Object Implementation. + * + * The Object implementation implements methods to retrieve + * GLOBAL time as well as secure GLOBAL time. The times are + * retrieved as UTOs. The object also allows creation of a TIO + * for a given time interval. In general, the TimeService clerk + * manages the UTOs and the TIOs. The notion of time returned + * here is the globally synchronized time. + */ +class TAO_Time_Export TAO_Time_Service_Clerk : public POA_CosTime::TimeService +{ +public: + + /// Helper class to help in the updation of time. + friend class Timer_Helper; + + /// Unbounded set of IORs. + typedef ACE_Array_Base<CosTime::TimeService_var> IORS; + + // = Initialization and termination methods. + /// Constructor. + TAO_Time_Service_Clerk (int timer_value, + int timer_value_usecs, + const IORS& server); + + /// Destructor. + ~TAO_Time_Service_Clerk (void); + + /// This operation returns the global time and an estimate of + /// inaccuracy in a UTO. + virtual CosTime::UTO_ptr universal_time (ACE_ENV_SINGLE_ARG_DECL) + ACE_THROW_SPEC ((CORBA::SystemException, + CosTime::TimeUnavailable)); + + /** + * This operation returns the global time in a UTO only if the time + * can be guaranteed to have been obtained securely. Currently this + * operation is not implemented and throws a CORBA::NO_IMPLEMENT + * exception, if called. + */ + virtual CosTime::UTO_ptr secure_universal_time (ACE_ENV_SINGLE_ARG_DECL) + ACE_THROW_SPEC ((CORBA::SystemException, + CosTime::TimeUnavailable)); + + /// This creates a new UTO based on the given parameters. + virtual CosTime::UTO_ptr new_universal_time (TimeBase::TimeT time, + TimeBase::InaccuracyT inaccuracy, + TimeBase::TdfT tdf + ACE_ENV_ARG_DECL) + ACE_THROW_SPEC ((CORBA::SystemException)); + + /// This creates a new UTO given a time in the UtcT form. + virtual CosTime::UTO_ptr uto_from_utc (const TimeBase::UtcT &utc + ACE_ENV_ARG_DECL) + ACE_THROW_SPEC ((CORBA::SystemException)); + + /// This creates a new TIO with the given parameters. + virtual CosTime::TIO_ptr new_interval (TimeBase::TimeT lower, + TimeBase::TimeT upper + ACE_ENV_ARG_DECL) + ACE_THROW_SPEC ((CORBA::SystemException)); + + /// Return the globally synchronized time. + virtual CORBA::ULongLong get_time (void); + + /// Returns the time displacement factor. + CORBA::Short time_displacement_factor (void); + + /// Set the TDF. + void time_displacement_factor (CORBA::Short); + + /// Get method for inaccuracy. + TimeBase::InaccuracyT inaccuracy (void); + + /// Set method for inaccuracy. + void inaccuracy (TimeBase::InaccuracyT inaccuracy); + + /// Clerk's notion of time. + CORBA::ULongLong time_; + +private: + + /// Time displacement factor in minutes. + CORBA::Short time_displacement_factor_; + + /// Inaccuracy in the time. + TimeBase::InaccuracyT inaccuracy_; + + /// Set of server Time Server IORs. + IORS server_; + + /// Time when last global synchronization was done. + CORBA::ULongLong update_timestamp_; + + /** + * This is a friend class that inherits from the Event Handler + * class. The handle_timeout method of this class is scheduled for + * periodic invocation by the reactor. This method, in turn, updates + * the clerks notion of time. Using this class obviates the need for + * the clerk to multiple inherit from the servant base as well as + * the event handler. + */ + Timer_Helper helper_; +}; + +TAO_END_VERSIONED_NAMESPACE_DECL + +#include /**/ "ace/post.h" +#endif /* TIME_SERVICE_CLERK_H */ diff --git a/TAO/orbsvcs/orbsvcs/Time/TAO_Time_Service_Server.cpp b/TAO/orbsvcs/orbsvcs/Time/TAO_Time_Service_Server.cpp new file mode 100644 index 00000000000..6fc4cf2b98e --- /dev/null +++ b/TAO/orbsvcs/orbsvcs/Time/TAO_Time_Service_Server.cpp @@ -0,0 +1,127 @@ +#include "orbsvcs/Time/TAO_UTO.h" +#include "orbsvcs/Time/TAO_TIO.h" +#include "orbsvcs/Time/TAO_Time_Service_Server.h" +#include "ace/OS_NS_sys_time.h" +#include "orbsvcs/Time_Utilities.h" + +#include "tao/debug.h" + + +ACE_RCSID (Time, + TAO_Time_Service_Server, + "$Id$") + +TAO_BEGIN_VERSIONED_NAMESPACE_DECL + +// Constructor. +TAO_Time_Service_Server::TAO_Time_Service_Server (void) +{ +} + +// Destructor. +TAO_Time_Service_Server::~TAO_Time_Service_Server (void) +{ +} + +// This method returns the current system time and an estimate of +// inaccuracy in a UTO. + +CosTime::UTO_ptr +TAO_Time_Service_Server::universal_time (ACE_ENV_SINGLE_ARG_DECL) + ACE_THROW_SPEC ((CORBA::SystemException, + CosTime::TimeUnavailable)) +{ + TAO_UTO *uto = 0; + + TimeBase::TimeT timestamp; + ORBSVCS_Time::Absolute_Time_Value_to_TimeT(timestamp, ACE_OS::gettimeofday()); + + // Return the local time of the system as a UTO. + ACE_NEW_THROW_EX (uto, + TAO_UTO (timestamp, + 0, + 0), + CORBA::NO_MEMORY ()); + + ACE_CHECK_RETURN (CosTime::UTO::_nil ()); + + if (TAO_debug_level > 0) + ACE_DEBUG ((LM_DEBUG, + "Returning a UTO\n")); + + return uto->_this (ACE_ENV_SINGLE_ARG_PARAMETER); +} + +// This method returns the current time in a UTO only if the time can +// be guaranteed to have been obtained securely. This method is not +// implemented currently. + +CosTime::UTO_ptr +TAO_Time_Service_Server::secure_universal_time (ACE_ENV_SINGLE_ARG_DECL) + ACE_THROW_SPEC ((CORBA::SystemException, + CosTime::TimeUnavailable)) +{ + ACE_THROW_RETURN (CORBA::NO_IMPLEMENT (), + CosTime::UTO::_nil ()); +} + +// This creates a new UTO based on the given parameters. + +CosTime::UTO_ptr +TAO_Time_Service_Server::new_universal_time (TimeBase::TimeT time, + TimeBase::InaccuracyT inaccuracy, + TimeBase::TdfT tdf + ACE_ENV_ARG_DECL) + ACE_THROW_SPEC ((CORBA::SystemException)) +{ + TAO_UTO *uto = 0; + + ACE_NEW_THROW_EX (uto, + TAO_UTO (time, + inaccuracy, + tdf), + CORBA::NO_MEMORY ()); + ACE_CHECK_RETURN (CosTime::UTO::_nil ()); + + return uto->_this (ACE_ENV_SINGLE_ARG_PARAMETER); +} + +// This creates a new UTO given a time in the UtcT form. + +CosTime::UTO_ptr +TAO_Time_Service_Server::uto_from_utc (const TimeBase::UtcT &utc + ACE_ENV_ARG_DECL) + ACE_THROW_SPEC ((CORBA::SystemException)) +{ + TAO_UTO *uto = 0; + + ACE_NEW_THROW_EX (uto, + TAO_UTO (utc.time, + utc.inacclo + utc.inacchi, + utc.tdf), + CORBA::NO_MEMORY ()); + ACE_CHECK_RETURN (CosTime::UTO::_nil ()); + + return uto->_this (ACE_ENV_SINGLE_ARG_PARAMETER); +} + +// This creates a new TIO with the given parameters. + +CosTime::TIO_ptr +TAO_Time_Service_Server::new_interval (TimeBase::TimeT lower, + TimeBase::TimeT upper + ACE_ENV_ARG_DECL) + ACE_THROW_SPEC ((CORBA::SystemException)) +{ + TAO_TIO *tio = 0; + + ACE_NEW_THROW_EX (tio, + TAO_TIO (lower, + upper), + CORBA::NO_MEMORY ()); + ACE_CHECK_RETURN (CosTime::TIO::_nil ()); + + return tio->_this (ACE_ENV_SINGLE_ARG_PARAMETER); +} + +TAO_END_VERSIONED_NAMESPACE_DECL diff --git a/TAO/orbsvcs/orbsvcs/Time/TAO_Time_Service_Server.h b/TAO/orbsvcs/orbsvcs/Time/TAO_Time_Service_Server.h new file mode 100644 index 00000000000..c87d563935a --- /dev/null +++ b/TAO/orbsvcs/orbsvcs/Time/TAO_Time_Service_Server.h @@ -0,0 +1,87 @@ +// -*- C++ -*- + +//============================================================================= +/** + * @file TAO_Time_Service_Server.h + * + * $Id$ + * + * This class implements the CosTime::TimeService IDL interface. + * + * + * @author Vishal Kachroo <vishal@cs.wustl.edu> + */ +//============================================================================= + + +#ifndef TAO_TIME_SERVICE_SERVER_H +#define TAO_TIME_SERVICE_SERVER_H +#include /**/ "ace/pre.h" + +#include "orbsvcs/TimeServiceS.h" +#include "orbsvcs/Time/time_export.h" + +TAO_BEGIN_VERSIONED_NAMESPACE_DECL + +/** + * @class TAO_Time_Service_Server + * + * @brief TimeService Object Implementation. + * + * The Object implementation implements methods to retrieve + * current time as well as secure current time. The times are + * retrieved as UTOs. The object also allows creation of a TIO + * for a given time interval. In general, the TimeService + * manages the UTOs and the TIOs. The notion of time returned + * here is the local time of the system. + */ +class TAO_Time_Export TAO_Time_Service_Server : public POA_CosTime::TimeService +{ + +public: + // = Initialization and termination methods. + /// Constructor. + TAO_Time_Service_Server (void); + + /// Destructor. + ~TAO_Time_Service_Server (void); + + /// This operation returns the current system time and an estimate of + /// inaccuracy in a UTO. + virtual CosTime::UTO_ptr universal_time (ACE_ENV_SINGLE_ARG_DECL) + ACE_THROW_SPEC ((CORBA::SystemException, + CosTime::TimeUnavailable)); + + /** + * This operation returns the current time in a UTO only if the time + * can be guaranteed to have been obtained securely. Currently this operation + * is not implemented and throws a CORBA::NO_IMPLEMENT exception, if called. + */ + virtual CosTime::UTO_ptr secure_universal_time (ACE_ENV_SINGLE_ARG_DECL) + ACE_THROW_SPEC ((CORBA::SystemException, + CosTime::TimeUnavailable)); + + /// This creates a new UTO based on the given parameters. + virtual CosTime::UTO_ptr new_universal_time (TimeBase::TimeT time, + TimeBase::InaccuracyT inaccuracy, + TimeBase::TdfT tdf + ACE_ENV_ARG_DECL) + ACE_THROW_SPEC ((CORBA::SystemException)); + + /// This creates a new UTO given a time in the UtcT form. + virtual CosTime::UTO_ptr uto_from_utc (const TimeBase::UtcT &utc + ACE_ENV_ARG_DECL) + ACE_THROW_SPEC ((CORBA::SystemException)); + + /// This creates a new TIO with the given parameters. + virtual CosTime::TIO_ptr new_interval (TimeBase::TimeT lower, + TimeBase::TimeT upper + ACE_ENV_ARG_DECL) + ACE_THROW_SPEC ((CORBA::SystemException)); + +}; + +TAO_END_VERSIONED_NAMESPACE_DECL + +#include /**/ "ace/post.h" +#endif /* TAO_TIME_SERVICE_SERVER_H */ diff --git a/TAO/orbsvcs/orbsvcs/Time/TAO_UTO.cpp b/TAO/orbsvcs/orbsvcs/Time/TAO_UTO.cpp new file mode 100644 index 00000000000..c9ea818a549 --- /dev/null +++ b/TAO/orbsvcs/orbsvcs/Time/TAO_UTO.cpp @@ -0,0 +1,246 @@ +// -*- C++ -*- +// $Id$ + +#include "orbsvcs/Time/TAO_UTO.h" +#include "orbsvcs/Time/TAO_TIO.h" +#include "ace/OS.h" + + +ACE_RCSID (Time, + TAO_UTO, + "$Id$") + + +TAO_BEGIN_VERSIONED_NAMESPACE_DECL + +TAO_UTO::TAO_UTO (TimeBase::TimeT time, + TimeBase::InaccuracyT inaccuracy, + TimeBase::TdfT tdf) +{ + + this->attr_utc_time_.time = time; + + // Extract the lower 32 bits in the inacclo. + this->attr_utc_time_.inacclo = (CORBA::ULong) ACE_U64_TO_U32 (inaccuracy); + + // Extract the lower 16 bits of the remaining bits. 'And'ing with 0xFFFF + // is only a sanity check. + +#if defined (ACE_LACKS_U_LONGLONG_T) + this->attr_utc_time_.inacchi = 0; +#else + this->attr_utc_time_.inacchi = + static_cast<CORBA::UShort> ((inaccuracy >> 32U) & 0xFFFF); + +#endif /* ACE_LACKS_U_LONGLONG_T */ + + this->attr_utc_time_.tdf = tdf; + +} + +// Destructor. + +TAO_UTO::~TAO_UTO (void) +{ +} + +// Get Method for the readonly attribute time. + +TimeBase::TimeT +TAO_UTO::time (ACE_ENV_SINGLE_ARG_DECL_NOT_USED) + ACE_THROW_SPEC ((CORBA::SystemException)) +{ + return attr_utc_time_.time; +} + +// Get method for the readonly attribute inaccuracy. + +TimeBase::InaccuracyT +TAO_UTO::inaccuracy (ACE_ENV_SINGLE_ARG_DECL_NOT_USED) + ACE_THROW_SPEC ((CORBA::SystemException)) +{ + // Construct the Inaccuracy from the + // inacchi and inacclo. + + TimeBase::InaccuracyT inaccuracy = attr_utc_time_.inacchi; + inaccuracy <<= 32; + inaccuracy |= attr_utc_time_.inacclo; + return inaccuracy; +} + +// Get method for the readonly attribute tdf. + +TimeBase::TdfT +TAO_UTO::tdf (ACE_ENV_SINGLE_ARG_DECL_NOT_USED) + ACE_THROW_SPEC ((CORBA::SystemException)) +{ + return attr_utc_time_.tdf; +} + +// Get method for the readonly attribute utc_time. + +TimeBase::UtcT +TAO_UTO::utc_time (ACE_ENV_SINGLE_ARG_DECL_NOT_USED) + ACE_THROW_SPEC ((CORBA::SystemException)) +{ + return attr_utc_time_; +} + +// Absolute time = Relative time + Base time. ?? Find out more about +// the Base Time, UTC and Distributed Time Sync. Algos. [3]. + +CosTime::UTO_ptr +TAO_UTO::absolute_time (ACE_ENV_SINGLE_ARG_DECL_NOT_USED) + ACE_THROW_SPEC ((CORBA::SystemException)) +{ + return CosTime::UTO::_nil (); +} + +// Compares the time contained in the object with the time in the +// supplied uto according to the supplied comparison type. + +CosTime::TimeComparison +TAO_UTO::compare_time (CosTime::ComparisonType comparison_type, + CosTime::UTO_ptr uto + ACE_ENV_ARG_DECL) + ACE_THROW_SPEC ((CORBA::SystemException)) +{ + TimeBase::TimeT uto_time = uto->time (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK_RETURN (CosTime::TCIndeterminate); + + TimeBase::InaccuracyT this_inaccuracy = + this->inaccuracy (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK_RETURN (CosTime::TCIndeterminate); + + TimeBase::InaccuracyT uto_inaccuracy = + uto->inaccuracy (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK_RETURN (CosTime::TCIndeterminate); + + if (comparison_type == CosTime::MidC) + { + if (this->time () == uto_time) + { + return CosTime::TCEqualTo; + } + else if (this->time () > uto_time) + { + return CosTime::TCGreaterThan; + } + else + return CosTime::TCLessThan; + } + else if (this->time () == uto_time) + { + if (this_inaccuracy == 0U + && uto_inaccuracy == 0U) + { + return CosTime::TCEqualTo; + } + } + else + { + if (this->time () > uto_time) + { + if (this->time () - this_inaccuracy + > uto_time - uto_inaccuracy) + { + return CosTime::TCGreaterThan; + } + } + else if (this->time () + this_inaccuracy + < uto_time - uto_inaccuracy) + { + return CosTime::TCLessThan; + } + } + + return CosTime::TCIndeterminate; +} + +// Returns a TIO representing the time interval between the time in +// the object and the time in the UTO passed as a parameter. The +// interval returned is the interval between the mid-points of the two +// UTOs. Inaccuracies are ignored. Note the result of this operation +// is meaningless if the base times of UTOs are different. + +CosTime::TIO_ptr +TAO_UTO::time_to_interval (CosTime::UTO_ptr uto + ACE_ENV_ARG_DECL) + ACE_THROW_SPEC ((CORBA::SystemException)) +{ + TAO_TIO *tio = 0; + + ACE_TRY + { + TimeBase::TimeT uto_time = uto->time (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + + if (this->time () > uto_time) + { + ACE_NEW_THROW_EX (tio, + TAO_TIO (uto_time, + this->time ()), + CORBA::NO_MEMORY ()); + + ACE_TRY_CHECK; + } + else + { + ACE_NEW_THROW_EX (tio, + TAO_TIO (this->time (), + uto_time), + CORBA::NO_MEMORY ()); + + ACE_TRY_CHECK; + } + } + ACE_CATCHANY + { + ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, "Exception:"); + return CosTime::TIO::_nil (); + } + ACE_ENDTRY; + ACE_CHECK_RETURN (CosTime::TIO::_nil ()); + + return tio->_this (ACE_ENV_SINGLE_ARG_PARAMETER); +} + +// Returns a TIO object representing the error interval around the +// time value in the UTO. + +CosTime::TIO_ptr +TAO_UTO::interval (ACE_ENV_SINGLE_ARG_DECL) + ACE_THROW_SPEC ((CORBA::SystemException)) +{ + TAO_TIO *tio = 0; + + ACE_TRY + { + TimeBase::TimeT this_inaccuracy = + this->inaccuracy (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + + TimeBase::TimeT lower = + this->time () - this_inaccuracy; + + TimeBase::TimeT upper = + this->time () + this_inaccuracy; + + ACE_NEW_THROW_EX (tio, + TAO_TIO (lower, + upper), + CORBA::NO_MEMORY ()); + ACE_TRY_CHECK; + } + ACE_CATCHANY + { + ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, "Exception:"); + return CosTime::TIO::_nil (); + } + ACE_ENDTRY; + ACE_CHECK_RETURN (CosTime::TIO::_nil ()); + + return tio->_this (ACE_ENV_SINGLE_ARG_PARAMETER); +} + +TAO_END_VERSIONED_NAMESPACE_DECL diff --git a/TAO/orbsvcs/orbsvcs/Time/TAO_UTO.h b/TAO/orbsvcs/orbsvcs/Time/TAO_UTO.h new file mode 100644 index 00000000000..b4e72e090da --- /dev/null +++ b/TAO/orbsvcs/orbsvcs/Time/TAO_UTO.h @@ -0,0 +1,119 @@ +// -*- C++ -*- + +//============================================================================= +/** + * @file TAO_UTO.h + * + * $Id$ + * + * This class implements the CosTime::UTO IDL interface. + * + * + * @author Vishal Kachroo <vishal@cs.wustl.edu> + */ +//============================================================================= + + +#ifndef TAO_UTO_H +#define TAO_UTO_H +#include /**/ "ace/pre.h" + +#include "orbsvcs/TimeServiceS.h" +#include "orbsvcs/Time/time_export.h" + +TAO_BEGIN_VERSIONED_NAMESPACE_DECL + +/** + * @class TAO_UTO + * + * @brief Universal Time Object Implementation. + * + * This is an encapsulation of the time. It provides the following + * operations on basic time. + * - Construction of a UTO from piece parts, and extraction of the + * piece parts from a UTO. The piece parts are the readonly + * attributes : + * time + * inaccuracy + * time displacement factor + * structure with all the above. + * - Comparison of time. + * - Conversion from relative to absolute time, and conversion to + * an interval (TIO). + */ +class TAO_Time_Export TAO_UTO : public POA_CosTime::UTO +{ +public: + // = Initialization and termination methods. + /// Constructor. + TAO_UTO (TimeBase::TimeT time, + TimeBase::InaccuracyT inaccuracy, + TimeBase::TdfT tdf); + + /// Destructor. + ~TAO_UTO (void); + + /// For the readonly attribute <time>. + virtual TimeBase::TimeT time ( + ACE_ENV_SINGLE_ARG_DECL_WITH_DEFAULTS) + ACE_THROW_SPEC ((CORBA::SystemException)); + + /// For the readonly attribute <inaccuracy>. + virtual TimeBase::InaccuracyT inaccuracy (ACE_ENV_SINGLE_ARG_DECL) + ACE_THROW_SPEC ((CORBA::SystemException)); + + /// For the readonly attribute <tdf>, which is the "time displacement + /// factor". + virtual TimeBase::TdfT tdf (ACE_ENV_SINGLE_ARG_DECL) + ACE_THROW_SPEC ((CORBA::SystemException)); + + /// For the readonly attribute <utc_time>. + virtual TimeBase::UtcT utc_time (ACE_ENV_SINGLE_ARG_DECL) + ACE_THROW_SPEC ((CORBA::SystemException)); + + /** + * Absolute time = Relative time + Base time. + * ?? Find out more about the Base Time, UTC and + * Distributed Time Sync. Algos. [3 + */ + CosTime::UTO_ptr absolute_time (ACE_ENV_SINGLE_ARG_DECL) + ACE_THROW_SPEC ((CORBA::SystemException)); + + /// Compares the time contained in the object with the time in the + /// supplied uto according to the supplied comparison type. + CosTime::TimeComparison compare_time (CosTime::ComparisonType comparison_type, + CosTime::UTO_ptr uto + ACE_ENV_ARG_DECL) + ACE_THROW_SPEC ((CORBA::SystemException)); + + /** + * Returns a TIO representing the time interval between the time in + * the object and the time in the UTO passed as a parameter. The + * interval returned is the interval between the mid-points of the + * two UTOs. Inaccuracies are ignored. Note the result of this + * operation is meaningless if the base times of UTOs are different. + */ + CosTime::TIO_ptr time_to_interval (CosTime::UTO_ptr + ACE_ENV_ARG_DECL) + ACE_THROW_SPEC ((CORBA::SystemException)); + + /// Returns a TIO object representing the error interval around the + /// time value in the UTO. + CosTime::TIO_ptr interval (ACE_ENV_SINGLE_ARG_DECL) + ACE_THROW_SPEC ((CORBA::SystemException)); + +private: + /** + * The readonly attribute structure having the time, inaccuracy and + * displacement. The get methods for other readonly attributes + * (time, inaccuracy, tdf) defined in the IDL use the members of + * this structure and hence need not have separate member variables + * for them. + */ + TimeBase::UtcT attr_utc_time_; +}; + +TAO_END_VERSIONED_NAMESPACE_DECL + +#include /**/ "ace/post.h" +#endif /* TAO_UTO_H */ diff --git a/TAO/orbsvcs/orbsvcs/Time/Timer_Helper.cpp b/TAO/orbsvcs/orbsvcs/Time/Timer_Helper.cpp new file mode 100644 index 00000000000..47923f8dba3 --- /dev/null +++ b/TAO/orbsvcs/orbsvcs/Time/Timer_Helper.cpp @@ -0,0 +1,156 @@ +#include "orbsvcs/Time/Timer_Helper.h" +#include "orbsvcs/Time/TAO_Time_Service_Clerk.h" + +#include "tao/debug.h" + +#include "ace/OS_NS_time.h" +#include "ace/OS_NS_sys_time.h" + +ACE_RCSID (Time, + Timer_Helper, + "$Id$") + + +TAO_BEGIN_VERSIONED_NAMESPACE_DECL + +Timer_Helper::Timer_Helper (void) + : clerk_ (0) +{ +} + +Timer_Helper::Timer_Helper (TAO_Time_Service_Clerk *clerk) + : clerk_ (clerk) +{ + +} + +Timer_Helper::~Timer_Helper (void) +{ +} + +int +Timer_Helper::handle_timeout (const ACE_Time_Value &, + const void *) +{ + int no_of_servers = 0; + CORBA::ULongLong sum = 0; + + // The following are used to keep a track of the inaccuracy + // in synchronization. + +#if defined (ACE_LACKS_LONGLONG_T) + CORBA::ULongLong lowest_time (0xFFFFFFFF, 0xFFFFFFFF); +#else + CORBA::ULongLong lowest_time = ACE_UINT64_LITERAL (0xFFFFFFFFFFFFFFFF); +#endif + + CORBA::ULongLong highest_time = 0; + + ACE_DECLARE_NEW_CORBA_ENV; + ACE_TRY + { + IORS::TYPE* value; + for (IORS::ITERATOR server_iterator (this->clerk_->server_); + server_iterator.next (value) != 0; + server_iterator.advance ()) + { + // This is a remote call. + CosTime::UTO_var UTO_server = + (*value)->universal_time (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + +#if defined (ACE_LACKS_LONGLONG_T) + + if (TAO_debug_level > 0) + ACE_DEBUG ((LM_DEBUG, + "\nTime = %Q\nInaccuracy = %Q\nTimeDiff = %d\nstruct.time = %Q\n" + "struct.inacclo = %d\nstruct.inacchi = %d\nstruct.Tdf = %d\n", + ACE_U64_TO_U32 (UTO_server->time ()), + ACE_U64_TO_U32 (UTO_server->inaccuracy ()), + UTO_server->tdf (), + ACE_U64_TO_U32 ((UTO_server->utc_time ()).time), + (UTO_server->utc_time ()).inacclo, + (UTO_server->utc_time ()).inacchi, + (UTO_server->utc_time ()).tdf)); + +#else + + if (TAO_debug_level > 0) + ACE_DEBUG ((LM_DEBUG, + "\nTime = %Q\nInaccuracy = %Q\nTimeDiff = %d\nstruct.time = %Q\n" + "struct.inacclo = %d\nstruct.inacchi = %d\nstruct.Tdf = %d\n", + UTO_server->time (), + UTO_server->inaccuracy (), + UTO_server->tdf (), + (UTO_server->utc_time ()).time, + (UTO_server->utc_time ()).inacclo, + (UTO_server->utc_time ()).inacchi, + (UTO_server->utc_time ()).tdf)); +#endif + + CORBA::ULongLong curr_server_time = + UTO_server->time (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + + sum += curr_server_time; + + ++no_of_servers; + + // Set the highest time to the largest time seen so far. + if (curr_server_time > highest_time) + highest_time = curr_server_time; + + // Set the lowest time to the smallest time seen so far. + if (curr_server_time < lowest_time) + lowest_time = curr_server_time; + + } + + if (TAO_debug_level > 0) + ACE_DEBUG ((LM_DEBUG, + "\nUpdated time from %d servers in the network", + no_of_servers)); + + // Return the average of the times retrieved from the various + // servers. + clerk_->time_ = sum / no_of_servers ; + + // Set the Time Displacement Factor. The TZ environment variable is + // read to set the time zone. We convert the timezone value from seconds + // to minutes. + + ACE_OS::tzset (); + long arg = ACE_OS::timezone () / 60; + CORBA::Short goodarg = static_cast<CORBA::Short> (arg); + clerk_->time_displacement_factor (goodarg); + + // Set the inaccuracy. + if (highest_time > lowest_time) + clerk_->inaccuracy (highest_time - lowest_time); + else + clerk_->inaccuracy (0); + + const ACE_Time_Value timeofday = ACE_OS::gettimeofday (); + + // Record the current time in a timestamp to know when global + // updation of time was done. + clerk_->update_timestamp_ = + static_cast<CORBA::ULongLong> (timeofday.sec ()) * + static_cast<ACE_UINT32> (10000000) + + static_cast<CORBA::ULongLong> (timeofday.usec () * 10); + } + ACE_CATCHANY + { + if (TAO_debug_level > 0) + ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, + "Exception in handle_timeout()\n"); + + return -1; + } + ACE_ENDTRY; + ACE_CHECK_RETURN (-1); + + return 0; +} + +TAO_END_VERSIONED_NAMESPACE_DECL diff --git a/TAO/orbsvcs/orbsvcs/Time/Timer_Helper.h b/TAO/orbsvcs/orbsvcs/Time/Timer_Helper.h new file mode 100644 index 00000000000..9bfd7297661 --- /dev/null +++ b/TAO/orbsvcs/orbsvcs/Time/Timer_Helper.h @@ -0,0 +1,80 @@ +// -*- C++ -*- + +//============================================================================= +/** + * @file Timer_Helper.h + * + * $Id$ + * + * This class is registered with the Reactor and extends from the + * event handler.It is a friend of the TAO_Time_Service_Clerk and + * helps to update the clerk's notion of globally synchronized + * time. This class obviates the need for multiple inheritance in + * the clerk. + * + * @author Vishal Kachroo <vishal@cs.wustl.edu> + */ +//============================================================================= + + +#ifndef TIMER_HELPER_H +#define TIMER_HELPER_H + +#include /**/ "ace/pre.h" + + +#include "ace/Event_Handler.h" +#include "ace/Containers.h" +#include "orbsvcs/Time/time_export.h" + +#include "orbsvcs/TimeServiceS.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +TAO_BEGIN_VERSIONED_NAMESPACE_DECL + +class TAO_Time_Service_Clerk; + +/** + * @class Timer_Helper + * + * @brief Timer Helper for the clerk. + * + * The handle timeout method of this class is called periodically + * by the reactor. This method updates the clerk's notion of + * globally synchronized time by contacting the various Time + * Servers. + */ +class TAO_Time_Export Timer_Helper : public ACE_Event_Handler +{ +public: + // = Initialization and termination methods. + /// Constructor. + Timer_Helper (void); + + /// Destructor. + ~Timer_Helper (void); + + /// Constructor that sets the clerk. + Timer_Helper (TAO_Time_Service_Clerk *clerk); + + /// This method is called periodically by the Reactor to update the + /// clerk's time. + int handle_timeout (const ACE_Time_Value &time, + const void *arg); + +protected: + /// Clerk's instance that this class helps to update time. + TAO_Time_Service_Clerk *clerk_; + + /// The set of server IORs. + typedef ACE_Array_Base<CosTime::TimeService_var> IORS; +}; + +TAO_END_VERSIONED_NAMESPACE_DECL + +#include /**/ "ace/post.h" + +#endif /* TIMER_HELPER_H */ diff --git a/TAO/orbsvcs/orbsvcs/Time/time_export.h b/TAO/orbsvcs/orbsvcs/Time/time_export.h new file mode 100644 index 00000000000..53e8ff6bf74 --- /dev/null +++ b/TAO/orbsvcs/orbsvcs/Time/time_export.h @@ -0,0 +1,40 @@ + +// -*- C++ -*- +// $Id$ +// Definition for Win32 Export directives. +// This file is generated automatically by generate_export_file.pl +// ------------------------------ +#ifndef TAO_TIME_EXPORT_H +#define TAO_TIME_EXPORT_H + +#include "ace/config-all.h" + +#if defined (TAO_AS_STATIC_LIBS) +# if !defined (TAO_TIME_HAS_DLL) +# define TAO_TIME_HAS_DLL 0 +# endif /* ! TAO_TIME_HAS_DLL */ +#else +# if !defined (TAO_TIME_HAS_DLL) +# define TAO_TIME_HAS_DLL 1 +# endif /* ! TAO_TIME_HAS_DLL */ +#endif + +#if defined (TAO_TIME_HAS_DLL) && (TAO_TIME_HAS_DLL == 1) +# if defined (TAO_TIME_BUILD_DLL) +# define TAO_Time_Export ACE_Proper_Export_Flag +# define TAO_TIME_SINGLETON_DECLARATION(T) ACE_EXPORT_SINGLETON_DECLARATION (T) +# define TAO_TIME_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) ACE_EXPORT_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) +# else /* TAO_TIME_BUILD_DLL */ +# define TAO_Time_Export ACE_Proper_Import_Flag +# define TAO_TIME_SINGLETON_DECLARATION(T) ACE_IMPORT_SINGLETON_DECLARATION (T) +# define TAO_TIME_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) ACE_IMPORT_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) +# endif /* TAO_TIME_BUILD_DLL */ +#else /* TAO_TIME_HAS_DLL == 1 */ +# define TAO_Time_Export +# define TAO_TIME_SINGLETON_DECLARATION(T) +# define TAO_TIME_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) +#endif /* TAO_TIME_HAS_DLL == 1 */ + +#endif /* TAO_TIME_EXPORT_H */ + +// End of auto generated file. |