summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/orbsvcs/Time/TAO_UTO.cpp
blob: 9b86b4c1c4f0bc7ab84ef449c6857d0661c6b22f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
// -*- C++ -*-
// $Id$

#include "TAO_UTO.h"
#include "TAO_TIO.h"

// Constructor.

TAO_UTO::TAO_UTO (TimeBase::TimeT time,
                  TimeBase::InaccuracyT inaccuracy,
                  TimeBase::TdfT tdf)
{
  this->attr_utc_time_.time = time;
  this->attr_utc_time_.inacchi = ACE_U64_TO_U32 (inaccuracy) / 2;
  this->attr_utc_time_.inacclo = ACE_U64_TO_U32 (inaccuracy - (inaccuracy/2));
  this->attr_utc_time_.tdf = tdf;
}

// Destructor.

TAO_UTO::~TAO_UTO (void)
{
}

// Get Method for the readonly attribute time.

TimeBase::TimeT
TAO_UTO::time (CORBA::Environment &env)
{
  return attr_utc_time_.time;
}

// Get method for the readonly attribute inaccuracy.

TimeBase::InaccuracyT
TAO_UTO::inaccuracy (CORBA::Environment &env)
{
  return attr_utc_time_.inacclo + attr_utc_time_.inacchi;
}

// Get method for the readonly attribute tdf.

TimeBase::TdfT
TAO_UTO::tdf (CORBA::Environment &env)
{
  return attr_utc_time_.tdf;
}

// Get method for the readonly attribute utc_time.

TimeBase::UtcT
TAO_UTO::utc_time (CORBA::Environment &env)
{
  return attr_utc_time_;
}

// Absolute time = Relative time + Base time.  ?? Find out more about
// the Base Time, UTC and Distributed Time Sync. Algos. [3].

CosTime::UTO_ptr
TAO_UTO::absolute_time (CORBA::Environment &env)
{
  return 0;
}

// Compares the time contained in the object with the time in the
// supplied uto according to the supplied comparison type.

CosTime::TimeComparison
TAO_UTO::compare_time (CosTime::ComparisonType comparison_type,
                       CosTime::UTO_ptr uto,
                       CORBA::Environment &env)
{
  TAO_TRY
    {
      if (comparison_type == CosTime::MidC)
        {
          if (this->time (TAO_TRY_ENV) == uto->time (TAO_TRY_ENV))
            {
              TAO_CHECK_ENV;
              return CosTime::TCEqualTo;
            }
          else if (this->time (TAO_TRY_ENV) > uto->time (TAO_TRY_ENV))
            {
              TAO_CHECK_ENV;
              return CosTime::TCGreaterThan;
            }
          else
            return CosTime::TCLessThan;
        }
      else if (this->time (TAO_TRY_ENV) == uto->time (TAO_TRY_ENV))
        {
          TAO_CHECK_ENV;
          if (this->inaccuracy (TAO_TRY_ENV) == 0 && uto->inaccuracy (TAO_TRY_ENV) == 0)
            {
              TAO_CHECK_ENV;
              return CosTime::TCEqualTo;
            }
        }
      else
        {
          if (this->time (TAO_TRY_ENV) > uto->time (TAO_TRY_ENV))
            {
              TAO_CHECK_ENV;
              if (this->time (TAO_TRY_ENV) - this->inaccuracy (TAO_TRY_ENV)
                  > uto->time (TAO_TRY_ENV) - uto->inaccuracy (TAO_TRY_ENV))
                {
                  TAO_CHECK_ENV;
                  return CosTime::TCGreaterThan;
                }
            }
          else if (this->time (TAO_TRY_ENV) + this->inaccuracy (TAO_TRY_ENV)
                   < uto->time (TAO_TRY_ENV) - uto->inaccuracy (TAO_TRY_ENV))

            {
              TAO_CHECK_ENV;
              return CosTime::TCLessThan;
            }
        }

    }
  TAO_CATCHANY
    {
      TAO_TRY_ENV.print_exception ("Exception:");
    }
  TAO_ENDTRY;

  return CosTime::TCIndeterminate;
}

// Returns a TIO representing the time interval between the time in
// the object and the time in the UTO passed as a parameter. The
// interval returned is the interval between the mid-points of the two
// UTOs. Inaccuracies are ignored.  Note the result of this operation
// is meaningless if the base times of UTOs are different.

CosTime::TIO_ptr
TAO_UTO::time_to_interval (CosTime::UTO_ptr uto,
                           CORBA::Environment &TAO_IN_ENV)
{
  TAO_TIO *tio = 0;

  TAO_TRY
    {
      if (this->time (TAO_TRY_ENV) > uto->time (TAO_TRY_ENV))
        ACE_NEW_THROW_RETURN (tio,
                              TAO_TIO (uto->time (TAO_TRY_ENV),
                                       this->time (TAO_TRY_ENV)),
                              CORBA::NO_MEMORY (CORBA::COMPLETED_NO),
                              CosTime::TIO::_nil ());
      else
        ACE_NEW_THROW_RETURN (tio,
                              TAO_TIO (this->time (TAO_TRY_ENV),
                                       uto->time (TAO_TRY_ENV)),
                              CORBA::NO_MEMORY (CORBA::COMPLETED_NO),
                              CosTime::TIO::_nil ());
      TAO_CHECK_ENV;

    }
  TAO_CATCHANY
    {
      TAO_TRY_ENV.print_exception ("Exception:");
      return CosTime::TIO::_nil ();
    }
  TAO_ENDTRY;

  return tio->_this ();
}

  // Returns a TIO object representing the error interval around the
  // time value in the UTO.

CosTime::TIO_ptr
TAO_UTO::interval (CORBA::Environment &TAO_IN_ENV)
{
  TAO_TIO *tio = 0;

  TAO_TRY
    {
      TimeBase::TimeT lower =
        this->time (TAO_TRY_ENV) - this->inaccuracy (TAO_TRY_ENV);
      TAO_CHECK_ENV;

      TimeBase::TimeT upper =
        this->time (TAO_TRY_ENV) + this->inaccuracy (TAO_TRY_ENV);
      TAO_CHECK_ENV;

      ACE_NEW_THROW_RETURN (tio,
                            TAO_TIO (lower,
                                     upper),
                            CORBA::NO_MEMORY (CORBA::COMPLETED_NO),
                            CosTime::TIO::_nil ());
      TAO_CHECK_ENV;
    }
  TAO_CATCHANY
    {
      TAO_TRY_ENV.print_exception ("Exception:");
      return CosTime::TIO::_nil ();
    }
  TAO_ENDTRY;

  return tio->_this ();
}