TAO_Time_Service_Clerk.cpp

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 // TAO_Time_Service_Clerk.cpp,v 1.30 2006/03/14 06:14:35 jtc Exp
00003 
00004 #include "orbsvcs/Time/TAO_Time_Service_Clerk.h"
00005 #include "orbsvcs/Time/TAO_TIO.h"
00006 #include "orbsvcs/Time/TAO_UTO.h"
00007 
00008 #include "tao/ORB_Core.h"
00009 #include "ace/OS_NS_sys_time.h"
00010 
00011 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00012 
00013 // Constructor.
00014 TAO_Time_Service_Clerk::TAO_Time_Service_Clerk (int timer_value,
00015                                                 int timer_value_usecs,
00016                                                 const IORS& servers)
00017   : server_ (servers),
00018     helper_ (this)
00019 {
00020   // Schedule the helper to be invoked by the reactor
00021   // periodically.
00022 
00023   if (TAO_ORB_Core_instance ()->reactor ()->schedule_timer
00024       (&helper_,
00025        0,
00026        ACE_Time_Value::zero,
00027        ACE_Time_Value(timer_value,timer_value_usecs)) == -1)
00028     ACE_ERROR ((LM_ERROR,
00029                 "%p\n",
00030                 "schedule_timer ()"));
00031 }
00032 
00033 // Destructor.
00034 
00035 TAO_Time_Service_Clerk::~TAO_Time_Service_Clerk (void)
00036 {
00037 }
00038 
00039 // This method returns the global time and an estimate of inaccuracy
00040 // in a UTO.
00041 
00042 CosTime::UTO_ptr
00043 TAO_Time_Service_Clerk::universal_time (ACE_ENV_SINGLE_ARG_DECL)
00044     ACE_THROW_SPEC ((CORBA::SystemException,
00045                      CosTime::TimeUnavailable))
00046 {
00047   TAO_UTO *uto = 0;
00048 
00049   ACE_NEW_THROW_EX (uto,
00050                     TAO_UTO (this->get_time (),
00051                              this->inaccuracy (),
00052                              this->time_displacement_factor ()),
00053                     CORBA::NO_MEMORY ());
00054   ACE_CHECK_RETURN (CosTime::UTO::_nil ());
00055   // Return the global time as a UTO.
00056 
00057   return uto->_this (ACE_ENV_SINGLE_ARG_PARAMETER);
00058 }
00059 
00060 // This method returns the global time in a UTO only if the time can
00061 // be guaranteed to have been obtained securely.  This method is not
00062 // implemented currently.
00063 
00064 CosTime::UTO_ptr
00065 TAO_Time_Service_Clerk::secure_universal_time (ACE_ENV_SINGLE_ARG_DECL)
00066     ACE_THROW_SPEC ((CORBA::SystemException,
00067                      CosTime::TimeUnavailable))
00068 {
00069   ACE_THROW_RETURN (CORBA::NO_IMPLEMENT (),
00070                     CosTime::UTO::_nil ());
00071 }
00072 
00073 // This creates a new UTO based on the given parameters.
00074 
00075 CosTime::UTO_ptr
00076 TAO_Time_Service_Clerk::new_universal_time (TimeBase::TimeT time,
00077                                             TimeBase::InaccuracyT inaccuracy,
00078                                             TimeBase::TdfT tdf
00079                                             ACE_ENV_ARG_DECL)
00080     ACE_THROW_SPEC ((CORBA::SystemException))
00081 {
00082   TAO_UTO *uto = 0;
00083 
00084   ACE_NEW_THROW_EX (uto,
00085                     TAO_UTO (time,
00086                              inaccuracy,
00087                              tdf),
00088                     CORBA::NO_MEMORY ());
00089   ACE_CHECK_RETURN (CosTime::UTO::_nil ());
00090 
00091   return uto->_this (ACE_ENV_SINGLE_ARG_PARAMETER);
00092 }
00093 
00094 // This creates a new UTO given a time in the UtcT form.
00095 
00096 CosTime::UTO_ptr
00097 TAO_Time_Service_Clerk::uto_from_utc (const TimeBase::UtcT &utc
00098                                       ACE_ENV_ARG_DECL)
00099     ACE_THROW_SPEC ((CORBA::SystemException))
00100 {
00101   TAO_UTO *uto = 0;
00102 
00103   // Use the low and high values of inaccuracy
00104   // to calculate the total inaccuracy.
00105 
00106   TimeBase::InaccuracyT inaccuracy = utc.inacchi;
00107   inaccuracy <<= 32;
00108   inaccuracy |= utc.inacclo;
00109 
00110   ACE_NEW_THROW_EX (uto,
00111                     TAO_UTO (utc.time,
00112                              inaccuracy,
00113                              utc.tdf),
00114                     CORBA::NO_MEMORY ());
00115   ACE_CHECK_RETURN (CosTime::UTO::_nil ());
00116   return uto->_this (ACE_ENV_SINGLE_ARG_PARAMETER);
00117 }
00118 
00119 // This creates a new TIO with the given parameters.
00120 
00121 CosTime::TIO_ptr
00122 TAO_Time_Service_Clerk::new_interval (TimeBase::TimeT lower,
00123                                       TimeBase::TimeT upper
00124                                       ACE_ENV_ARG_DECL)
00125     ACE_THROW_SPEC ((CORBA::SystemException))
00126 {
00127   TAO_TIO *tio = 0;
00128 
00129   ACE_NEW_THROW_EX (tio,
00130                     TAO_TIO (lower,
00131                              upper),
00132                     CORBA::NO_MEMORY ());
00133   ACE_CHECK_RETURN (CosTime::TIO::_nil ());
00134   return tio->_this (ACE_ENV_SINGLE_ARG_PARAMETER);
00135 }
00136 
00137 CORBA::ULongLong
00138 TAO_Time_Service_Clerk::get_time (void)
00139 {
00140   // Globally sync. time is the latest global time plus the time
00141   // elapsed since last updation was done.
00142 
00143   const ACE_Time_Value timeofday = ACE_OS::gettimeofday ();
00144 
00145   return (CORBA::ULongLong) (static_cast<CORBA::ULongLong> (timeofday.sec ()) *
00146                              static_cast<ACE_UINT32> (10000000) +
00147                              static_cast<CORBA::ULongLong> (timeofday.usec () * 10))
00148     - this->update_timestamp_
00149     + this->time_;
00150 }
00151 
00152 // Returns the time displacement factor in minutes.
00153 // This is displacement from the GMT.
00154 CORBA::Short
00155 TAO_Time_Service_Clerk::time_displacement_factor (void)
00156 {
00157   return time_displacement_factor_;
00158 }
00159 
00160 // Sets the TDF.
00161 void
00162 TAO_Time_Service_Clerk::time_displacement_factor (CORBA::Short tdf)
00163 {
00164   this->time_displacement_factor_ = tdf;
00165 }
00166 
00167 // GET method for inaccuracy.
00168 TimeBase::InaccuracyT
00169 TAO_Time_Service_Clerk::inaccuracy (void)
00170 {
00171   return this->inaccuracy_;
00172 }
00173 
00174 // SET method for inaccuracy.
00175 void
00176 TAO_Time_Service_Clerk::inaccuracy (TimeBase::InaccuracyT inaccuracy)
00177 {
00178   this->inaccuracy_ = inaccuracy;
00179 }
00180 
00181 TAO_END_VERSIONED_NAMESPACE_DECL

Generated on Thu Nov 9 13:58:37 2006 for TAO_CosTime by doxygen 1.3.6