00001
00002
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
00024 this->attr_utc_time_.inacclo = (CORBA::ULong) ACE_U64_TO_U32 (inaccuracy);
00025
00026
00027
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
00036
00037 this->attr_utc_time_.tdf = tdf;
00038
00039 }
00040
00041
00042
00043 TAO_UTO::~TAO_UTO (void)
00044 {
00045 }
00046
00047
00048
00049 TimeBase::TimeT
00050 TAO_UTO::time (void)
00051 {
00052 return attr_utc_time_.time;
00053 }
00054
00055
00056
00057 TimeBase::InaccuracyT
00058 TAO_UTO::inaccuracy (void)
00059 {
00060
00061
00062
00063 TimeBase::InaccuracyT inaccuracy = attr_utc_time_.inacchi;
00064 inaccuracy <<= 32;
00065 inaccuracy |= attr_utc_time_.inacclo;
00066 return inaccuracy;
00067 }
00068
00069
00070
00071 TimeBase::TdfT
00072 TAO_UTO::tdf (void)
00073 {
00074 return attr_utc_time_.tdf;
00075 }
00076
00077
00078
00079 TimeBase::UtcT
00080 TAO_UTO::utc_time (void)
00081 {
00082 return attr_utc_time_;
00083 }
00084
00085
00086
00087
00088 CosTime::UTO_ptr
00089 TAO_UTO::absolute_time (void)
00090 {
00091 return CosTime::UTO::_nil ();
00092 }
00093
00094
00095
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
00151
00152
00153
00154
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
00192
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