TAO_Time_Service_Clerk.cpp

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 // $Id: TAO_Time_Service_Clerk.cpp 77001 2007-02-12 07:54:49Z johnnyw $
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 (void)
00044 {
00045   TAO_UTO *uto = 0;
00046 
00047   ACE_NEW_THROW_EX (uto,
00048                     TAO_UTO (this->get_time (),
00049                              this->inaccuracy (),
00050                              this->time_displacement_factor ()),
00051                     CORBA::NO_MEMORY ());
00052   // Return the global time as a UTO.
00053 
00054   return uto->_this ();
00055 }
00056 
00057 // This method returns the global time in a UTO only if the time can
00058 // be guaranteed to have been obtained securely.  This method is not
00059 // implemented currently.
00060 
00061 CosTime::UTO_ptr
00062 TAO_Time_Service_Clerk::secure_universal_time (void)
00063 {
00064   throw CORBA::NO_IMPLEMENT ();
00065 }
00066 
00067 // This creates a new UTO based on the given parameters.
00068 
00069 CosTime::UTO_ptr
00070 TAO_Time_Service_Clerk::new_universal_time (TimeBase::TimeT time,
00071                                             TimeBase::InaccuracyT inaccuracy,
00072                                             TimeBase::TdfT tdf)
00073 {
00074   TAO_UTO *uto = 0;
00075 
00076   ACE_NEW_THROW_EX (uto,
00077                     TAO_UTO (time,
00078                              inaccuracy,
00079                              tdf),
00080                     CORBA::NO_MEMORY ());
00081 
00082   return uto->_this ();
00083 }
00084 
00085 // This creates a new UTO given a time in the UtcT form.
00086 
00087 CosTime::UTO_ptr
00088 TAO_Time_Service_Clerk::uto_from_utc (const TimeBase::UtcT &utc)
00089 {
00090   TAO_UTO *uto = 0;
00091 
00092   // Use the low and high values of inaccuracy
00093   // to calculate the total inaccuracy.
00094 
00095   TimeBase::InaccuracyT inaccuracy = utc.inacchi;
00096   inaccuracy <<= 32;
00097   inaccuracy |= utc.inacclo;
00098 
00099   ACE_NEW_THROW_EX (uto,
00100                     TAO_UTO (utc.time,
00101                              inaccuracy,
00102                              utc.tdf),
00103                     CORBA::NO_MEMORY ());
00104   return uto->_this ();
00105 }
00106 
00107 // This creates a new TIO with the given parameters.
00108 
00109 CosTime::TIO_ptr
00110 TAO_Time_Service_Clerk::new_interval (TimeBase::TimeT lower,
00111                                       TimeBase::TimeT upper)
00112 {
00113   TAO_TIO *tio = 0;
00114 
00115   ACE_NEW_THROW_EX (tio,
00116                     TAO_TIO (lower,
00117                              upper),
00118                     CORBA::NO_MEMORY ());
00119   return tio->_this ();
00120 }
00121 
00122 CORBA::ULongLong
00123 TAO_Time_Service_Clerk::get_time (void)
00124 {
00125   // Globally sync. time is the latest global time plus the time
00126   // elapsed since last updation was done.
00127 
00128   const ACE_Time_Value timeofday = ACE_OS::gettimeofday ();
00129 
00130   return (CORBA::ULongLong) (static_cast<CORBA::ULongLong> (timeofday.sec ()) *
00131                              static_cast<ACE_UINT32> (10000000) +
00132                              static_cast<CORBA::ULongLong> (timeofday.usec () * 10))
00133     - this->update_timestamp_
00134     + this->time_;
00135 }
00136 
00137 // Returns the time displacement factor in minutes.
00138 // This is displacement from the GMT.
00139 CORBA::Short
00140 TAO_Time_Service_Clerk::time_displacement_factor (void)
00141 {
00142   return time_displacement_factor_;
00143 }
00144 
00145 // Sets the TDF.
00146 void
00147 TAO_Time_Service_Clerk::time_displacement_factor (CORBA::Short tdf)
00148 {
00149   this->time_displacement_factor_ = tdf;
00150 }
00151 
00152 // GET method for inaccuracy.
00153 TimeBase::InaccuracyT
00154 TAO_Time_Service_Clerk::inaccuracy (void)
00155 {
00156   return this->inaccuracy_;
00157 }
00158 
00159 // SET method for inaccuracy.
00160 void
00161 TAO_Time_Service_Clerk::inaccuracy (TimeBase::InaccuracyT inaccuracy)
00162 {
00163   this->inaccuracy_ = inaccuracy;
00164 }
00165 
00166 TAO_END_VERSIONED_NAMESPACE_DECL

Generated on Tue Feb 2 17:49:17 2010 for TAO_CosTime by  doxygen 1.4.7