TAO_UTO.cpp

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 // TAO_UTO.cpp,v 1.31 2006/03/14 06:14:35 jtc Exp
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            "TAO_UTO.cpp,v 1.31 2006/03/14 06:14:35 jtc Exp")
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 (ACE_ENV_SINGLE_ARG_DECL_NOT_USED)
00051     ACE_THROW_SPEC ((CORBA::SystemException))
00052 {
00053   return attr_utc_time_.time;
00054 }
00055 
00056 // Get method for the readonly attribute inaccuracy.
00057 
00058 TimeBase::InaccuracyT
00059 TAO_UTO::inaccuracy (ACE_ENV_SINGLE_ARG_DECL_NOT_USED)
00060     ACE_THROW_SPEC ((CORBA::SystemException))
00061 {
00062   // Construct the Inaccuracy from the
00063   // inacchi and inacclo.
00064 
00065   TimeBase::InaccuracyT inaccuracy = attr_utc_time_.inacchi;
00066   inaccuracy <<= 32;
00067   inaccuracy |= attr_utc_time_.inacclo;
00068   return inaccuracy;
00069 }
00070 
00071 // Get method for the readonly attribute tdf.
00072 
00073 TimeBase::TdfT
00074 TAO_UTO::tdf (ACE_ENV_SINGLE_ARG_DECL_NOT_USED)
00075     ACE_THROW_SPEC ((CORBA::SystemException))
00076 {
00077   return attr_utc_time_.tdf;
00078 }
00079 
00080 // Get method for the readonly attribute utc_time.
00081 
00082 TimeBase::UtcT
00083 TAO_UTO::utc_time (ACE_ENV_SINGLE_ARG_DECL_NOT_USED)
00084     ACE_THROW_SPEC ((CORBA::SystemException))
00085 {
00086   return attr_utc_time_;
00087 }
00088 
00089 // Absolute time = Relative time + Base time.  ?? Find out more about
00090 // the Base Time, UTC and Distributed Time Sync. Algos. [3].
00091 
00092 CosTime::UTO_ptr
00093 TAO_UTO::absolute_time (ACE_ENV_SINGLE_ARG_DECL_NOT_USED)
00094     ACE_THROW_SPEC ((CORBA::SystemException))
00095 {
00096   return CosTime::UTO::_nil ();
00097 }
00098 
00099 // Compares the time contained in the object with the time in the
00100 // supplied uto according to the supplied comparison type.
00101 
00102 CosTime::TimeComparison
00103 TAO_UTO::compare_time (CosTime::ComparisonType comparison_type,
00104                        CosTime::UTO_ptr uto
00105                        ACE_ENV_ARG_DECL)
00106     ACE_THROW_SPEC ((CORBA::SystemException))
00107 {
00108   TimeBase::TimeT uto_time = uto->time (ACE_ENV_SINGLE_ARG_PARAMETER);
00109   ACE_CHECK_RETURN (CosTime::TCIndeterminate);
00110 
00111   TimeBase::InaccuracyT this_inaccuracy =
00112     this->inaccuracy (ACE_ENV_SINGLE_ARG_PARAMETER);
00113   ACE_CHECK_RETURN (CosTime::TCIndeterminate);
00114 
00115   TimeBase::InaccuracyT uto_inaccuracy =
00116     uto->inaccuracy (ACE_ENV_SINGLE_ARG_PARAMETER);
00117   ACE_CHECK_RETURN (CosTime::TCIndeterminate);
00118 
00119   if (comparison_type == CosTime::MidC)
00120     {
00121       if (this->time () == uto_time)
00122         {
00123           return CosTime::TCEqualTo;
00124         }
00125       else if (this->time () > uto_time)
00126         {
00127           return CosTime::TCGreaterThan;
00128         }
00129       else
00130         return CosTime::TCLessThan;
00131     }
00132   else if (this->time () == uto_time)
00133     {
00134       if (this_inaccuracy == 0U
00135           && uto_inaccuracy  == 0U)
00136         {
00137           return CosTime::TCEqualTo;
00138         }
00139     }
00140   else
00141     {
00142       if (this->time () > uto_time)
00143         {
00144           if (this->time () - this_inaccuracy
00145               > uto_time  - uto_inaccuracy)
00146             {
00147               return CosTime::TCGreaterThan;
00148             }
00149         }
00150       else if (this->time () + this_inaccuracy
00151                < uto_time - uto_inaccuracy)
00152         {
00153           return CosTime::TCLessThan;
00154         }
00155     }
00156 
00157   return CosTime::TCIndeterminate;
00158 }
00159 
00160 // Returns a TIO representing the time interval between the time in
00161 // the object and the time in the UTO passed as a parameter. The
00162 // interval returned is the interval between the mid-points of the two
00163 // UTOs. Inaccuracies are ignored.  Note the result of this operation
00164 // is meaningless if the base times of UTOs are different.
00165 
00166 CosTime::TIO_ptr
00167 TAO_UTO::time_to_interval (CosTime::UTO_ptr uto
00168                            ACE_ENV_ARG_DECL)
00169     ACE_THROW_SPEC ((CORBA::SystemException))
00170 {
00171   TAO_TIO *tio = 0;
00172 
00173   ACE_TRY
00174     {
00175       TimeBase::TimeT uto_time = uto->time (ACE_ENV_SINGLE_ARG_PARAMETER);
00176       ACE_TRY_CHECK;
00177 
00178       if (this->time () > uto_time)
00179         {
00180           ACE_NEW_THROW_EX (tio,
00181                             TAO_TIO (uto_time,
00182                                      this->time ()),
00183                             CORBA::NO_MEMORY ());
00184 
00185           ACE_TRY_CHECK;
00186         }
00187       else
00188         {
00189           ACE_NEW_THROW_EX (tio,
00190                             TAO_TIO (this->time (),
00191                                      uto_time),
00192                             CORBA::NO_MEMORY ());
00193 
00194           ACE_TRY_CHECK;
00195         }
00196     }
00197   ACE_CATCHANY
00198     {
00199       ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, "Exception:");
00200       return CosTime::TIO::_nil ();
00201     }
00202   ACE_ENDTRY;
00203   ACE_CHECK_RETURN (CosTime::TIO::_nil ());
00204 
00205   return tio->_this (ACE_ENV_SINGLE_ARG_PARAMETER);
00206 }
00207 
00208 // Returns a TIO object representing the error interval around the
00209 // time value in the UTO.
00210 
00211 CosTime::TIO_ptr
00212 TAO_UTO::interval (ACE_ENV_SINGLE_ARG_DECL)
00213     ACE_THROW_SPEC ((CORBA::SystemException))
00214 {
00215   TAO_TIO *tio = 0;
00216 
00217   ACE_TRY
00218     {
00219       TimeBase::TimeT this_inaccuracy =
00220           this->inaccuracy (ACE_ENV_SINGLE_ARG_PARAMETER);
00221       ACE_TRY_CHECK;
00222 
00223       TimeBase::TimeT lower =
00224         this->time () - this_inaccuracy;
00225 
00226       TimeBase::TimeT upper =
00227         this->time () + this_inaccuracy;
00228 
00229       ACE_NEW_THROW_EX (tio,
00230                         TAO_TIO (lower,
00231                                  upper),
00232                         CORBA::NO_MEMORY ());
00233       ACE_TRY_CHECK;
00234     }
00235   ACE_CATCHANY
00236     {
00237       ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, "Exception:");
00238       return CosTime::TIO::_nil ();
00239     }
00240   ACE_ENDTRY;
00241   ACE_CHECK_RETURN (CosTime::TIO::_nil ());
00242 
00243   return tio->_this (ACE_ENV_SINGLE_ARG_PARAMETER);
00244 }
00245 
00246 TAO_END_VERSIONED_NAMESPACE_DECL

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