TAO_UTO.cpp

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 // $Id: TAO_UTO.cpp 77001 2007-02-12 07:54:49Z johnnyw $
00003 
00004 #include "orbsvcs/Time/TAO_UTO.h"
00005 #include "orbsvcs/Time/TAO_TIO.h"
00006 #include "ace/OS.h"
00007 
00008 
00009 ACE_RCSID (Time,
00010            TAO_UTO,
00011            "$Id: TAO_UTO.cpp 77001 2007-02-12 07:54:49Z johnnyw $")
00012 
00013 
00014 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00015 
00016 TAO_UTO::TAO_UTO (TimeBase::TimeT time,
00017                   TimeBase::InaccuracyT inaccuracy,
00018                   TimeBase::TdfT tdf)
00019 {
00020 
00021   this->attr_utc_time_.time = time;
00022 
00023   // Extract the lower 32 bits in the inacclo.
00024   this->attr_utc_time_.inacclo = (CORBA::ULong) ACE_U64_TO_U32 (inaccuracy);
00025 
00026   // Extract the lower 16 bits of the remaining bits. 'And'ing with 0xFFFF
00027   // is only a sanity check.
00028 
00029 #if defined (ACE_LACKS_U_LONGLONG_T)
00030   this->attr_utc_time_.inacchi = 0;
00031 #else
00032   this->attr_utc_time_.inacchi =
00033     static_cast<CORBA::UShort> ((inaccuracy >> 32U) & 0xFFFF);
00034 
00035 #endif /* ACE_LACKS_U_LONGLONG_T */
00036 
00037   this->attr_utc_time_.tdf = tdf;
00038 
00039 }
00040 
00041 // Destructor.
00042 
00043 TAO_UTO::~TAO_UTO (void)
00044 {
00045 }
00046 
00047 // Get Method for the readonly attribute time.
00048 
00049 TimeBase::TimeT
00050 TAO_UTO::time (void)
00051 {
00052   return attr_utc_time_.time;
00053 }
00054 
00055 // Get method for the readonly attribute inaccuracy.
00056 
00057 TimeBase::InaccuracyT
00058 TAO_UTO::inaccuracy (void)
00059 {
00060   // Construct the Inaccuracy from the
00061   // inacchi and inacclo.
00062 
00063   TimeBase::InaccuracyT inaccuracy = attr_utc_time_.inacchi;
00064   inaccuracy <<= 32;
00065   inaccuracy |= attr_utc_time_.inacclo;
00066   return inaccuracy;
00067 }
00068 
00069 // Get method for the readonly attribute tdf.
00070 
00071 TimeBase::TdfT
00072 TAO_UTO::tdf (void)
00073 {
00074   return attr_utc_time_.tdf;
00075 }
00076 
00077 // Get method for the readonly attribute utc_time.
00078 
00079 TimeBase::UtcT
00080 TAO_UTO::utc_time (void)
00081 {
00082   return attr_utc_time_;
00083 }
00084 
00085 // Absolute time = Relative time + Base time.  ?? Find out more about
00086 // the Base Time, UTC and Distributed Time Sync. Algos. [3].
00087 
00088 CosTime::UTO_ptr
00089 TAO_UTO::absolute_time (void)
00090 {
00091   return CosTime::UTO::_nil ();
00092 }
00093 
00094 // Compares the time contained in the object with the time in the
00095 // supplied uto according to the supplied comparison type.
00096 
00097 CosTime::TimeComparison
00098 TAO_UTO::compare_time (CosTime::ComparisonType comparison_type,
00099                        CosTime::UTO_ptr uto)
00100 {
00101   TimeBase::TimeT uto_time = uto->time ();
00102 
00103   TimeBase::InaccuracyT this_inaccuracy =
00104     this->inaccuracy ();
00105 
00106   TimeBase::InaccuracyT uto_inaccuracy =
00107     uto->inaccuracy ();
00108 
00109   if (comparison_type == CosTime::MidC)
00110     {
00111       if (this->time () == uto_time)
00112         {
00113           return CosTime::TCEqualTo;
00114         }
00115       else if (this->time () > uto_time)
00116         {
00117           return CosTime::TCGreaterThan;
00118         }
00119       else
00120         return CosTime::TCLessThan;
00121     }
00122   else if (this->time () == uto_time)
00123     {
00124       if (this_inaccuracy == 0U
00125           && uto_inaccuracy  == 0U)
00126         {
00127           return CosTime::TCEqualTo;
00128         }
00129     }
00130   else
00131     {
00132       if (this->time () > uto_time)
00133         {
00134           if (this->time () - this_inaccuracy
00135               > uto_time  - uto_inaccuracy)
00136             {
00137               return CosTime::TCGreaterThan;
00138             }
00139         }
00140       else if (this->time () + this_inaccuracy
00141                < uto_time - uto_inaccuracy)
00142         {
00143           return CosTime::TCLessThan;
00144         }
00145     }
00146 
00147   return CosTime::TCIndeterminate;
00148 }
00149 
00150 // Returns a TIO representing the time interval between the time in
00151 // the object and the time in the UTO passed as a parameter. The
00152 // interval returned is the interval between the mid-points of the two
00153 // UTOs. Inaccuracies are ignored.  Note the result of this operation
00154 // is meaningless if the base times of UTOs are different.
00155 
00156 CosTime::TIO_ptr
00157 TAO_UTO::time_to_interval (CosTime::UTO_ptr uto)
00158 {
00159   TAO_TIO *tio = 0;
00160 
00161   try
00162     {
00163       TimeBase::TimeT uto_time = uto->time ();
00164 
00165       if (this->time () > uto_time)
00166         {
00167           ACE_NEW_THROW_EX (tio,
00168                             TAO_TIO (uto_time,
00169                                      this->time ()),
00170                             CORBA::NO_MEMORY ());
00171 
00172         }
00173       else
00174         {
00175           ACE_NEW_THROW_EX (tio,
00176                             TAO_TIO (this->time (),
00177                                      uto_time),
00178                             CORBA::NO_MEMORY ());
00179 
00180         }
00181     }
00182   catch (const CORBA::Exception& ex)
00183     {
00184       ex._tao_print_exception ("Exception:");
00185       return CosTime::TIO::_nil ();
00186     }
00187 
00188   return tio->_this ();
00189 }
00190 
00191 // Returns a TIO object representing the error interval around the
00192 // time value in the UTO.
00193 
00194 CosTime::TIO_ptr
00195 TAO_UTO::interval (void)
00196 {
00197   TAO_TIO *tio = 0;
00198 
00199   try
00200     {
00201       TimeBase::TimeT this_inaccuracy =
00202           this->inaccuracy ();
00203 
00204       TimeBase::TimeT lower =
00205         this->time () - this_inaccuracy;
00206 
00207       TimeBase::TimeT upper =
00208         this->time () + this_inaccuracy;
00209 
00210       ACE_NEW_THROW_EX (tio,
00211                         TAO_TIO (lower,
00212                                  upper),
00213                         CORBA::NO_MEMORY ());
00214     }
00215   catch (const CORBA::Exception& ex)
00216     {
00217       ex._tao_print_exception ("Exception:");
00218       return CosTime::TIO::_nil ();
00219     }
00220 
00221   return tio->_this ();
00222 }
00223 
00224 TAO_END_VERSIONED_NAMESPACE_DECL

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