summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs
diff options
context:
space:
mode:
Diffstat (limited to 'TAO/orbsvcs')
-rw-r--r--TAO/orbsvcs/orbsvcs/Time/TAO_TIO.cpp240
-rw-r--r--TAO/orbsvcs/orbsvcs/Time/TAO_TIO.h77
-rw-r--r--TAO/orbsvcs/orbsvcs/Time/TAO_Time_Service_Clerk.cpp137
-rw-r--r--TAO/orbsvcs/orbsvcs/Time/TAO_Time_Service_Clerk.h108
-rw-r--r--TAO/orbsvcs/orbsvcs/Time/TAO_Time_Service_Server.cpp108
-rw-r--r--TAO/orbsvcs/orbsvcs/Time/TAO_Time_Service_Server.h71
-rw-r--r--TAO/orbsvcs/orbsvcs/Time/TAO_UTO.cpp161
-rw-r--r--TAO/orbsvcs/orbsvcs/Time/TAO_UTO.h102
-rw-r--r--TAO/orbsvcs/orbsvcs/Time/Timer_Helper.cpp92
-rw-r--r--TAO/orbsvcs/orbsvcs/Time/Timer_Helper.h74
10 files changed, 1170 insertions, 0 deletions
diff --git a/TAO/orbsvcs/orbsvcs/Time/TAO_TIO.cpp b/TAO/orbsvcs/orbsvcs/Time/TAO_TIO.cpp
new file mode 100644
index 00000000000..8c37bab2a20
--- /dev/null
+++ b/TAO/orbsvcs/orbsvcs/Time/TAO_TIO.cpp
@@ -0,0 +1,240 @@
+// -*- C++ -*-
+// $Id$
+
+#include "TAO_TIO.h"
+
+// Constructor.
+TAO_TIO::TAO_TIO (TimeBase::TimeT lower,
+ TimeBase::TimeT upper)
+{
+ this->attr_time_interval.lower_bound = lower;
+ this->attr_time_interval.upper_bound = upper;
+}
+
+// Destructor.
+TAO_TIO::~TAO_TIO (void)
+{
+}
+
+ // This is the get method for the attribute time interval.
+
+TimeBase::IntervalT
+TAO_TIO::time_interval (CORBA::Environment &env)
+{
+ return attr_time_interval;
+}
+
+
+ // This operation returns a value of type OverlapType depending on how the
+ // interval in the object and the time range represented by the parameter UTO overlap.
+ // If OverlapType is not OTNoOverlap, then the out parameter overlap contains the overlap
+ // interval, otherwise the out parameter contains the gap between the two intervals.
+
+CosTime::OverlapType
+TAO_TIO::spans (CosTime::UTO_ptr uto,
+ CosTime::TIO_out overlap,
+ CORBA::Environment &env)
+{
+ TAO_TIO *tio = 0;
+
+ TimeBase::TimeT lb1 = this->time_interval (env).lower_bound;
+ TimeBase::TimeT up1 = this->time_interval (env).upper_bound;
+ TimeBase::TimeT lb2 = uto->time (env) - uto->inaccuracy (env);
+ TimeBase::TimeT up2 = uto->time (env) + uto->inaccuracy (env);
+
+ if (lb1 == lb2 && up1 == up2)
+ {
+ ACE_NEW_RETURN (tio,
+ TAO_TIO (lb1, up1),
+ CosTime::OTNoOverlap);
+
+ overlap = tio->_this ();
+
+ return CosTime::OTOverlap;
+ }
+ else if (lb1 > lb2 && up1 < up2)
+ {
+ ACE_NEW_RETURN (tio,
+ TAO_TIO (lb1, up1),
+ CosTime::OTNoOverlap);
+
+ overlap = tio->_this ();
+
+ return CosTime::OTContained;
+ }
+ else if (lb1 < lb2 && up1 > up2)
+ {
+ ACE_NEW_RETURN (tio,
+ TAO_TIO (lb2, up2),
+ CosTime::OTNoOverlap);
+
+ overlap = tio->_this ();
+
+ return CosTime::OTContained;
+ }
+ else if (lb1 < lb2)
+ {
+ if (up1 < lb2)
+ {
+ ACE_NEW_RETURN (tio,
+ TAO_TIO (0, 0),
+ CosTime::OTNoOverlap);
+
+ overlap = tio->_this ();
+
+ return CosTime::OTNoOverlap;
+ }
+ else
+ {
+ ACE_NEW_RETURN (tio,
+ TAO_TIO (lb2, up1),
+ CosTime::OTNoOverlap);
+
+ overlap = tio->_this ();
+
+ return CosTime::OTOverlap;
+ }
+ }
+ else
+ {
+ if (up2 < lb1)
+ {
+
+ ACE_NEW_RETURN (tio,
+ TAO_TIO (0, 0),
+ CosTime::OTNoOverlap);
+
+ overlap = tio->_this ();
+
+ return CosTime::OTNoOverlap;
+ }
+ else
+ {
+ ACE_NEW_RETURN (tio,
+ TAO_TIO (lb1, up2),
+ CosTime::OTNoOverlap);
+
+ overlap = tio->_this ();
+
+ return CosTime::OTOverlap;
+ }
+ }
+
+ return CosTime::OTNoOverlap;
+}
+
+ // This operation returns a value of type OverlapType depending on how the interval in the
+ // object and interval in the parameter TIO overlap. If OverlapType is not OTNoOverlap, then
+ // the out parameter overlap contains the overlap interval, otherwise the out parameter
+ // contains the gap between the two intervals.
+
+CosTime::OverlapType
+TAO_TIO::overlaps (CosTime::TIO_ptr tio,
+ CosTime::TIO_out overlap,
+ CORBA::Environment &env)
+{
+ TimeBase::IntervalT interval;
+ TAO_TIO *tio_i = 0;
+
+ TimeBase::TimeT lb1 = this->time_interval (env).lower_bound;
+ TimeBase::TimeT up1 = this->time_interval (env).upper_bound;
+ TimeBase::TimeT lb2 = tio->time_interval (env).lower_bound;
+ TimeBase::TimeT up2 = tio->time_interval (env).upper_bound;
+
+ if (lb1 == lb2 && up1 == up2)
+ {
+
+ ACE_NEW_RETURN (tio_i,
+ TAO_TIO (lb1, up1),
+ CosTime::OTNoOverlap);
+
+ overlap = tio_i->_this ();
+
+ return CosTime::OTOverlap;
+ }
+ else if (lb1 > lb2 && up1 < up2)
+ {
+ ACE_NEW_RETURN (tio_i,
+ TAO_TIO (lb1, up1),
+ CosTime::OTNoOverlap);
+
+ overlap = tio_i->_this ();
+
+ return CosTime::OTContained;
+ }
+ else if (lb1 < lb2 && up1 > up2)
+ {
+ ACE_NEW_RETURN (tio_i,
+ TAO_TIO (lb2, up2),
+ CosTime::OTNoOverlap);
+
+ overlap = tio_i->_this ();
+
+ return CosTime::OTContained;
+ }
+ else if (lb1 < lb2)
+ {
+ if (up1 < lb2)
+ {
+ ACE_NEW_RETURN (tio_i,
+ TAO_TIO (0, 0),
+ CosTime::OTNoOverlap);
+
+ overlap = tio_i->_this ();
+
+ return CosTime::OTNoOverlap;
+ }
+ else
+ {
+ ACE_NEW_RETURN (tio_i,
+ TAO_TIO (lb2, up1),
+ CosTime::OTNoOverlap);
+
+ overlap = tio_i->_this ();
+
+ return CosTime::OTOverlap;
+ }
+ }
+ else
+ {
+ if (up2 < lb1)
+ {
+ ACE_NEW_RETURN (tio_i,
+ TAO_TIO (0, 0),
+ CosTime::OTNoOverlap);
+
+ overlap = tio_i->_this ();
+
+ return CosTime::OTNoOverlap;
+ }
+ else
+ {
+ ACE_NEW_RETURN (tio_i,
+ TAO_TIO (lb1, up2),
+ CosTime::OTNoOverlap);
+
+ overlap = tio_i->_this ();
+
+ return CosTime::OTOverlap;
+ }
+ }
+
+ return CosTime::OTNoOverlap;
+
+}
+
+CosTime::UTO_ptr
+TAO_TIO::time (CORBA::Environment &_env)
+{
+ TAO_UTO *uto = 0;
+
+ ACE_NEW_THROW_RETURN (uto,
+ TAO_UTO ((this->time_interval (_env).upper_bound -
+ this->time_interval (_env).lower_bound) / 2,
+ this->time_interval (_env).upper_bound -
+ this->time_interval (_env).lower_bound,
+ 0),
+ CORBA::NO_MEMORY (CORBA::COMPLETED_NO),
+ CosTime::UTO::_nil ());
+ return uto->_this ();
+}
diff --git a/TAO/orbsvcs/orbsvcs/Time/TAO_TIO.h b/TAO/orbsvcs/orbsvcs/Time/TAO_TIO.h
new file mode 100644
index 00000000000..ec67e6707ba
--- /dev/null
+++ b/TAO/orbsvcs/orbsvcs/Time/TAO_TIO.h
@@ -0,0 +1,77 @@
+// -*- C++ -*-
+// $Id$
+
+// ============================================================================
+//
+// = LIBRARY
+// TAO/orbsvcs/Time_Service
+//
+// = FILENAME
+// TAO_TIO.h
+//
+// = DESCRIPTION
+// This class implements the CosTime::TIO IDL interface.
+//
+// = AUTHOR
+// Vishal Kachroo <vishal@cs.wustl.edu>
+//
+// ============================================================================
+
+#ifndef TAO_TIO_H
+#define TAO_TIO_H
+
+#include "tao/TAO.h"
+#include "orbsvcs/TimeServiceS.h"
+#include "TAO_UTO.h"
+
+class TAO_TIO : public POA_CosTime::TIO
+{
+ // = TITLE
+ // Time Interval Object Implementation.
+ //
+ // = DESCRIPTION
+ // The TIO represents a time interval and has operations to
+ // compare itself with a UTO or another TIO. It also has an
+ // operation to create a UTO from the value of it's time
+ // interval.
+public:
+ // = Initialization and termination methods.
+ TAO_TIO (TimeBase::TimeT lower,
+ TimeBase::TimeT upper);
+ // Constructor.
+
+ ~TAO_TIO (void);
+ // Destructor.
+
+ virtual TimeBase::IntervalT time_interval (CORBA::Environment &env);
+ // This is the get method for the attribute time interval.
+
+ virtual CosTime::OverlapType spans (CosTime::UTO_ptr time,
+ CosTime::TIO_out overlap,
+ CORBA::Environment &env);
+ // This operation returns a value of type OverlapType depending on how the
+ // interval in the object and the time range represented by the parameter UTO overlap.
+ // If OverlapType is not OTNoOverlap, then the out parameter overlap contains the overlap
+ // interval, otherwise the out parameter contains the gap between the two intervals.
+
+ virtual CosTime::OverlapType overlaps (CosTime::TIO_ptr interval,
+ CosTime::TIO_out overlap,
+ CORBA::Environment &env);
+ // This operation returns a value of type OverlapType depending on how the interval in the
+ // object and interval in the parameter TIO overlap. If OverlapType is not OTNoOverlap, then
+ // the out parameter overlap contains the overlap interval, otherwise the out parameter
+ // contains the gap between the two intervals.
+
+ virtual CosTime::UTO_ptr time (CORBA::Environment &env);
+ // Returns a UTO in which the inaccuracy interval is equal to the time interval in the TIO
+ // and time value is the midpoint of the interval.
+
+private:
+
+ TimeBase::IntervalT attr_time_interval;
+ // This attribute returns an IntervalT structure with the values of its
+ // fields filled in with the corresponding values from the TIO.
+
+};
+
+#endif /* TAO_TIO_H */
diff --git a/TAO/orbsvcs/orbsvcs/Time/TAO_Time_Service_Clerk.cpp b/TAO/orbsvcs/orbsvcs/Time/TAO_Time_Service_Clerk.cpp
new file mode 100644
index 00000000000..feb51f75b31
--- /dev/null
+++ b/TAO/orbsvcs/orbsvcs/Time/TAO_Time_Service_Clerk.cpp
@@ -0,0 +1,137 @@
+// -*- C++ -*-
+// $Id$
+
+#include "TAO_Time_Service_Clerk.h"
+#include "TAO_TIO.h"
+#include "TAO_UTO.h"
+
+// Constructor.
+TAO_Time_Service_Clerk::TAO_Time_Service_Clerk (int timer_value,
+ IORS servers)
+ : server_ (servers),
+ helper_ (this)
+{
+ TAO_TRY
+ {
+ // Schedule the helper to be invoked by the reactor
+ // periodically.
+ ACE_DEBUG ((LM_DEBUG,
+ "In the constructor of Clerk\n"));
+
+ if (TAO_ORB_Core_instance ()->reactor ()->schedule_timer
+ (&helper_,
+ 0,
+ ACE_Time_Value::zero,
+ ACE_Time_Value (timer_value)) == -1)
+ ACE_ERROR ((LM_ERROR,
+ "%p\n",
+ "schedule_timer ()"));
+ }
+ TAO_CATCHANY
+ {
+ TAO_TRY_ENV.print_exception ("(%P|%t) Exception in Clerk_i::run ()\n");
+ }
+ TAO_ENDTRY;
+}
+
+// Destructor.
+
+TAO_Time_Service_Clerk::~TAO_Time_Service_Clerk (void)
+{
+}
+
+// This method returns the global time and an estimate of inaccuracy
+// in a UTO.
+
+CosTime::UTO_ptr
+TAO_Time_Service_Clerk::universal_time (CORBA::Environment &_env)
+{
+
+ TAO_UTO *uto = 0;
+
+ ACE_NEW_THROW_RETURN (uto,
+ TAO_UTO (this->get_time (),
+ 0,
+ 0),
+ CORBA::NO_MEMORY (CORBA::COMPLETED_NO),
+ CosTime::UTO::_nil ());
+ // Return the global time as a UTO.
+
+ return uto->_this ();
+}
+
+
+// This method returns the global time in a UTO only if the time can
+// be guaranteed to have been obtained securely. This method is not
+// implemented currently.
+
+CosTime::UTO_ptr
+TAO_Time_Service_Clerk::secure_universal_time (CORBA::Environment &env)
+{
+ env.exception (new CORBA::NO_IMPLEMENT (CORBA::COMPLETED_NO));
+
+ return 0;
+}
+
+// This creates a new UTO based on the given parameters.
+
+CosTime::UTO_ptr
+TAO_Time_Service_Clerk::new_universal_time (TimeBase::TimeT time,
+ TimeBase::InaccuracyT inaccuracy,
+ TimeBase::TdfT tdf,
+ CORBA::Environment &_env)
+{
+ TAO_UTO *uto = 0;
+
+ ACE_NEW_THROW_RETURN (uto,
+ TAO_UTO (time,
+ inaccuracy,
+ tdf),
+ CORBA::NO_MEMORY (CORBA::COMPLETED_NO),
+ CosTime::UTO::_nil ());
+ return uto->_this ();
+}
+
+// This creates a new UTO given a time in the UtcT form.
+
+CosTime::UTO_ptr
+TAO_Time_Service_Clerk::uto_from_utc (const TimeBase::UtcT &utc,
+ CORBA::Environment &_env)
+{
+ TAO_UTO *uto = 0;
+
+ ACE_NEW_THROW_RETURN (uto,
+ TAO_UTO (utc.time,
+ utc.inacclo + utc.inacchi,
+ utc.tdf),
+ CORBA::NO_MEMORY (CORBA::COMPLETED_NO),
+ CosTime::UTO::_nil ());
+ return uto->_this ();
+}
+
+// This creates a new TIO with the given parameters.
+
+CosTime::TIO_ptr
+TAO_Time_Service_Clerk::new_interval (TimeBase::TimeT lower,
+ TimeBase::TimeT upper,
+ CORBA::Environment &_env)
+{
+ TAO_TIO *tio = 0;
+
+ ACE_NEW_THROW_RETURN (tio,
+ TAO_TIO (lower,
+ upper),
+ CORBA::NO_MEMORY (CORBA::COMPLETED_NO),
+ CosTime::TIO::_nil ());
+ return tio->_this ();
+}
+
+CORBA::ULongLong
+TAO_Time_Service_Clerk::get_time (void)
+{
+ // Globally sync. time is the latest global time plus the time
+ // elapsed since last updation was done.
+
+ return ACE_OS::gettimeofday ().sec () - this->update_timestamp_ + this->time_;
+
+}
diff --git a/TAO/orbsvcs/orbsvcs/Time/TAO_Time_Service_Clerk.h b/TAO/orbsvcs/orbsvcs/Time/TAO_Time_Service_Clerk.h
new file mode 100644
index 00000000000..e0b11291552
--- /dev/null
+++ b/TAO/orbsvcs/orbsvcs/Time/TAO_Time_Service_Clerk.h
@@ -0,0 +1,108 @@
+// -*- C++ -*-
+// $Id$
+
+// ============================================================================
+//
+// = LIBRARY
+// TAO/orbsvcs/Time_Service
+//
+// = FILENAME
+// TAO_Time_Service_Clerk.h
+//
+// = DESCRIPTION
+// This class implements the CosTime::TimeService IDL interface.
+//
+// = AUTHOR
+// Vishal Kachroo <vishal@cs.wustl.edu>
+//
+// ============================================================================
+
+#ifndef TAO_TIME_SERVICE_CLERK_H
+#define TAO_TIME_SERVICE_CLERK_H
+
+#include "ace/Reactor.h"
+#include "orbsvcs/Naming/Naming_Utils.h"
+
+#include "orbsvcs/TimeServiceS.h"
+#include "Timer_Helper.h"
+
+class TAO_Time_Service_Clerk : public POA_CosTime::TimeService
+{
+ // = TITLE
+ // TimeService Object Implementation.
+ //
+ // = DESCRIPTION
+ // The Object implementation implements methods to retrieve
+ // GLOBAL time as well as secure GLOBAL time. The times are
+ // retrieved as UTOs. The object also allows creation of a TIO
+ // for a given time interval. In general, the TimeService clerk
+ // manages the UTOs and the TIOs. The notion of time returned
+ // here is the globally synchronized time.
+public:
+
+ friend class Timer_Helper;
+ // Helper class to help in the updation of time.
+
+ typedef ACE_Unbounded_Set<CosTime::TimeService_var>
+ IORS;
+ // Unbounded set of IORs.
+
+ // = Initialization and termination methods.
+ TAO_Time_Service_Clerk (int timer_value,
+ IORS server);
+ // Constructor.
+
+ ~TAO_Time_Service_Clerk (void);
+ // Destructor.
+
+ virtual CosTime::UTO_ptr universal_time (CORBA::Environment &env);
+ // This operation returns the global time and an estimate of
+ // inaccuracy in a UTO.
+
+ virtual CosTime::UTO_ptr secure_universal_time (CORBA::Environment &env);
+ // This operation returns the global time in a UTO only if the time
+ // can be guaranteed to have been obtained securely. Currently this operation
+ // is not implemented and throws a CORBA::NO_IMPLEMENT exception, if called.
+
+ virtual CosTime::UTO_ptr new_universal_time (TimeBase::TimeT time,
+ TimeBase::InaccuracyT inaccuracy,
+ TimeBase::TdfT tdf,
+ CORBA::Environment &env);
+ // This creates a new UTO based on the given parameters.
+
+ virtual CosTime::UTO_ptr uto_from_utc (const TimeBase::UtcT &utc,
+ CORBA::Environment &env);
+ // This creates a new UTO given a time in the UtcT form.
+
+ virtual CosTime::TIO_ptr new_interval (TimeBase::TimeT lower,
+ TimeBase::TimeT upper,
+ CORBA::Environment &env);
+ // This creates a new TIO with the given parameters.
+
+ virtual CORBA::ULongLong get_time (void);
+ // Return the globally synchronized time.
+
+ void name_server (TAO_Naming_Server &server);
+ // This method is called by the driver program to set the Naming
+ // Server instance.
+
+ CORBA::ULongLong time_;
+ // Clerk's notion of time.
+
+private:
+
+ IORS server_;
+ // Set of server Time Server IORs.
+
+ CORBA::ULongLong update_timestamp_;
+ // Time when last global synchronization was done.
+
+ Timer_Helper helper_;
+ // This is a friend class that inherits from the Event Handler class.
+ // The handle_timeout method of this class is scheduled for periodic
+ // invocation by the reactor. This method, in turn, updates the clerks
+ // notion of time. Using this class obviates the need for the clerk to
+ // multiple inherit from the servant base as well as the event handler.
+};
+
+#endif /* TIME_SERVICE_CLERK_H */
diff --git a/TAO/orbsvcs/orbsvcs/Time/TAO_Time_Service_Server.cpp b/TAO/orbsvcs/orbsvcs/Time/TAO_Time_Service_Server.cpp
new file mode 100644
index 00000000000..366f781f1e2
--- /dev/null
+++ b/TAO/orbsvcs/orbsvcs/Time/TAO_Time_Service_Server.cpp
@@ -0,0 +1,108 @@
+// -*- C++ -*-
+// $Id$
+
+#include "TAO_UTO.h"
+#include "TAO_TIO.h"
+#include "TAO_Time_Service_Server.h"
+
+// Constructor.
+TAO_Time_Service_Server::TAO_Time_Service_Server (void)
+{
+}
+
+// Destructor.
+TAO_Time_Service_Server::~TAO_Time_Service_Server (void)
+{
+}
+
+// This method returns the current system time and an estimate of
+// inaccuracy in a UTO.
+
+CosTime::UTO_ptr
+TAO_Time_Service_Server::universal_time (CORBA::Environment &_env)
+{
+ TAO_UTO *uto = 0;
+
+ // Return the local time of the system as a UTO.
+ ACE_NEW_THROW_RETURN (uto,
+ TAO_UTO (CORBA::ULongLong (ACE_OS::gettimeofday ().sec ()),
+ 0,
+ 0),
+ CORBA::NO_MEMORY (CORBA::COMPLETED_NO),
+ CosTime::UTO::_nil ());
+
+ return uto->_this (_env);
+}
+
+
+// This method returns the current time in a UTO only if the
+// time can be guaranteed to have been obtained securely.
+// This method is not implemented currently.
+
+CosTime::UTO_ptr
+TAO_Time_Service_Server::secure_universal_time (CORBA::Environment &env)
+{
+ env.exception (new CORBA::NO_IMPLEMENT (CORBA::COMPLETED_NO));
+ return 0;
+}
+
+
+// This creates a new UTO based on the given parameters.
+
+CosTime::UTO_ptr
+TAO_Time_Service_Server::new_universal_time (TimeBase::TimeT time,
+ TimeBase::InaccuracyT inaccuracy,
+ TimeBase::TdfT tdf,
+ CORBA::Environment &_env)
+{
+ TAO_UTO *uto = 0;
+
+ ACE_NEW_THROW_RETURN (uto,
+ TAO_UTO (time,
+ inaccuracy,
+ tdf),
+ CORBA::NO_MEMORY (CORBA::COMPLETED_NO),
+ CosTime::UTO::_nil ());
+
+ return uto->_this ();
+}
+
+
+// This creates a new UTO given a time in the UtcT form.
+
+CosTime::UTO_ptr
+TAO_Time_Service_Server::uto_from_utc (const TimeBase::UtcT &utc,
+ CORBA::Environment &_env)
+{
+ TAO_UTO *uto = 0;
+
+ ACE_NEW_THROW_RETURN (uto,
+ TAO_UTO (utc.time,
+ utc.inacclo + utc.inacchi,
+ utc.tdf),
+ CORBA::NO_MEMORY (CORBA::COMPLETED_NO),
+ CosTime::UTO::_nil ());
+
+ return uto->_this ();
+
+}
+
+
+// This creates a new TIO with the given parameters.
+
+CosTime::TIO_ptr
+TAO_Time_Service_Server::new_interval (TimeBase::TimeT lower,
+ TimeBase::TimeT upper,
+ CORBA::Environment &_env)
+{
+ TAO_TIO *tio = 0;
+ TimeBase::IntervalT time_interval;
+
+ ACE_NEW_THROW_RETURN (tio,
+ TAO_TIO (lower,
+ upper),
+ CORBA::NO_MEMORY (CORBA::COMPLETED_NO),
+ CosTime::TIO::_nil ());
+
+ return tio->_this ();
+}
diff --git a/TAO/orbsvcs/orbsvcs/Time/TAO_Time_Service_Server.h b/TAO/orbsvcs/orbsvcs/Time/TAO_Time_Service_Server.h
new file mode 100644
index 00000000000..62df0650387
--- /dev/null
+++ b/TAO/orbsvcs/orbsvcs/Time/TAO_Time_Service_Server.h
@@ -0,0 +1,71 @@
+// -*- C++ -*-
+// $Id$
+
+// ============================================================================
+//
+// = LIBRARY
+// TAO/orbsvcs/Time_Service
+//
+// = FILENAME
+// TAO_Time_Service_Server.h
+//
+// = DESCRIPTION
+// This class implements the CosTime::TimeService IDL interface.
+//
+// = AUTHOR
+// Vishal Kachroo <vishal@cs.wustl.edu>
+//
+// ============================================================================
+
+#ifndef TAO_TIME_SERVICE_SERVER_H
+#define TAO_TIME_SERVICE_SERVER_H
+
+#include "orbsvcs/TimeServiceS.h"
+
+class TAO_Time_Service_Server : public POA_CosTime::TimeService
+{
+ // = TITLE
+ // TimeService Object Implementation.
+ //
+ // = DESCRIPTION
+ // The Object implementation implements methods to retrieve
+ // current time as well as secure current time. The times are
+ // retrieved as UTOs. The object also allows creation of a TIO
+ // for a given time interval. In general, the TimeService
+ // manages the UTOs and the TIOs. The notion of time returned
+ // here is the local time of the system.
+
+public:
+ // = Initialization and termination methods.
+ TAO_Time_Service_Server (void);
+ // Constructor.
+
+ ~TAO_Time_Service_Server (void);
+ // Destructor.
+
+ virtual CosTime::UTO_ptr universal_time (CORBA::Environment &env);
+ // This operation returns the current system time and an estimate of
+ // inaccuracy in a UTO.
+
+ virtual CosTime::UTO_ptr secure_universal_time (CORBA::Environment &env);
+ // This operation returns the current time in a UTO only if the time
+ // can be guaranteed to have been obtained securely. Currently this operation
+ // is not implemented and throws a CORBA::NO_IMPLEMENT exception, if called.
+
+ virtual CosTime::UTO_ptr new_universal_time (TimeBase::TimeT time,
+ TimeBase::InaccuracyT inaccuracy,
+ TimeBase::TdfT tdf,
+ CORBA::Environment &env);
+ // This creates a new UTO based on the given parameters.
+
+ virtual CosTime::UTO_ptr uto_from_utc (const TimeBase::UtcT &utc,
+ CORBA::Environment &env);
+ // This creates a new UTO given a time in the UtcT form.
+
+ virtual CosTime::TIO_ptr new_interval (TimeBase::TimeT lower,
+ TimeBase::TimeT upper,
+ CORBA::Environment &env);
+ // This creates a new TIO with the given parameters.
+};
+
+#endif /* TAO_TIME_SERVICE_SERVER_H */
diff --git a/TAO/orbsvcs/orbsvcs/Time/TAO_UTO.cpp b/TAO/orbsvcs/orbsvcs/Time/TAO_UTO.cpp
new file mode 100644
index 00000000000..f13bd53e987
--- /dev/null
+++ b/TAO/orbsvcs/orbsvcs/Time/TAO_UTO.cpp
@@ -0,0 +1,161 @@
+// -*- C++ -*-
+// $Id$
+
+#include "TAO_UTO.h"
+#include "TAO_TIO.h"
+
+// Constructor.
+
+TAO_UTO::TAO_UTO (TimeBase::TimeT time,
+ TimeBase::InaccuracyT inaccuracy,
+ TimeBase::TdfT tdf)
+ // @@ Vishal, please consider putting these assignments into the
+ // constructor of attr_utc_time_. BTW, I think some of your other
+ // implementation classes could benefit from this same technique.
+
+ // ?? Tried to initialise the structure here. Failed.
+{
+ this->attr_utc_time_.time = time;
+ this->attr_utc_time_.inacchi = inaccuracy / 2;
+ this->attr_utc_time_.inacclo = 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)
+{
+ if (comparison_type == CosTime::MidC)
+ {
+ if (this->time (env) == uto->time (env))
+ return CosTime::TCEqualTo;
+ else if (this->time (env) > uto->time (env))
+ return CosTime::TCGreaterThan;
+ else
+ return CosTime::TCLessThan;
+ }
+ else
+ {
+ if (this->time (env) == uto->time (env))
+ {
+ if (this->inaccuracy (env) == 0 && uto->inaccuracy (env) == 0)
+ return CosTime::TCEqualTo;
+ }
+ else
+ {
+ if (this->time (env) > uto->time (env))
+ {
+ if (this->time (env) - this->inaccuracy (env)
+ > uto->time (env) - uto->inaccuracy (env))
+ return CosTime::TCGreaterThan;
+ }
+ else
+ {
+ if (this->time (env) + this->inaccuracy (env)
+ < uto->time (env) - uto->inaccuracy (env))
+ return CosTime::TCLessThan;
+ }
+ }
+ }
+
+ 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 &_env)
+{
+ TAO_TIO *tio = 0;
+
+ if (this->time (_env) > uto->time (_env))
+ ACE_NEW_THROW_RETURN (tio,
+ TAO_TIO (uto->time (_env),
+ this->time (_env)),
+ CORBA::NO_MEMORY (CORBA::COMPLETED_NO),
+ CosTime::TIO::_nil ());
+ else
+ ACE_NEW_THROW_RETURN (tio,
+ TAO_TIO (this->time (_env),
+ uto->time (_env)),
+ CORBA::NO_MEMORY (CORBA::COMPLETED_NO),
+ CosTime::TIO::_nil ());
+ 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 &_env)
+{
+ TAO_TIO *tio = 0;
+
+ TimeBase::TimeT lower = this->time (_env) - this->inaccuracy (_env);
+ TimeBase::TimeT upper = this->time (_env) + this->inaccuracy (_env);
+
+ ACE_NEW_THROW_RETURN (tio,
+ TAO_TIO (lower,
+ upper),
+ CORBA::NO_MEMORY (CORBA::COMPLETED_NO),
+ CosTime::TIO::_nil ()
+ );
+ return tio->_this ();
+};
diff --git a/TAO/orbsvcs/orbsvcs/Time/TAO_UTO.h b/TAO/orbsvcs/orbsvcs/Time/TAO_UTO.h
new file mode 100644
index 00000000000..b245b59a6c9
--- /dev/null
+++ b/TAO/orbsvcs/orbsvcs/Time/TAO_UTO.h
@@ -0,0 +1,102 @@
+// -*- C++ -*-
+// $Id$
+
+// ============================================================================
+//
+// = LIBRARY
+// TAO/orbsvcs/Time_Service
+//
+// = FILENAME
+// TAO_UTO.h
+//
+// = DESCRIPTION
+// This class implements the CosTime::UTO IDL interface.
+//
+// = AUTHOR
+// Vishal Kachroo <vishal@cs.wustl.edu>
+//
+// ============================================================================
+
+#ifndef TAO_UTO_H
+#define TAO_UTO_H
+
+#include "orbsvcs/TimeServiceS.h"
+
+class TAO_UTO : public POA_CosTime::UTO
+{
+ // = TITLE
+ // Universal Time Object Implementation.
+ //
+ // = DESCRIPTION
+ // This is an encapsulation of the time. It provides the following
+ // operations on basic time.
+ //
+ // - Construction of a UTO from piece parts, and extraction of the
+ // piece parts from a UTO. The piece parts are the readonly
+ // attributes :
+ // time
+ // inaccuracy
+ // time displacement factor
+ // structure with all the above.
+ //
+ // - Comparison of time.
+ //
+ // - Conversion from relative to absolute time, and conversion to
+ // an interval (TIO).
+public:
+ // = Initialization and termination methods.
+ TAO_UTO (TimeBase::TimeT time,
+ TimeBase::InaccuracyT inaccuracy,
+ TimeBase::TdfT tdf);
+ // Constructor.
+
+ ~TAO_UTO (void);
+ // Destructor.
+
+ virtual TimeBase::TimeT time (CORBA::Environment &env);
+ // For the readonly attribute <time>.
+
+ virtual TimeBase::InaccuracyT inaccuracy (CORBA::Environment &env);
+ // For the readonly attribute <inaccuracy>.
+
+ virtual TimeBase::TdfT tdf (CORBA::Environment &env);
+ // For the readonly attribute <tdf>, which is the "time displacement
+ // factor".
+
+ virtual TimeBase::UtcT utc_time (CORBA::Environment &env);
+ // For the readonly attribute <utc_time>.
+
+ CosTime::UTO_ptr absolute_time (CORBA::Environment &env);
+ // Absolute time = Relative time + Base time.
+ // ?? Find out more about the Base Time, UTC and
+ // Distributed Time Sync. Algos. [3
+
+ CosTime::TimeComparison compare_time (CosTime::ComparisonType comparison_type,
+ CosTime::UTO_ptr uto,
+ CORBA::Environment &env);
+ // Compares the time contained in the object with the time in the
+ // supplied uto according to the supplied comparison type.
+
+
+ CosTime::TIO_ptr time_to_interval (CosTime::UTO_ptr,
+ CORBA::Environment &env);
+ // 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 interval (CORBA::Environment &env);
+ // Returns a TIO object representing the error interval around the
+ // time value in the UTO.
+
+private:
+ TimeBase::UtcT attr_utc_time_;
+ // The readonly attribute structure having the time, inaccuracy and
+ // displacement. The get methods for other readonly attributes
+ // (time, inaccuracy, tdf) defined in the IDL use the members of
+ // this structure and hence need not have separate member variables
+ // for them.
+};
+
+#endif /* TAO_UTO_H */
diff --git a/TAO/orbsvcs/orbsvcs/Time/Timer_Helper.cpp b/TAO/orbsvcs/orbsvcs/Time/Timer_Helper.cpp
new file mode 100644
index 00000000000..5aac110f3ab
--- /dev/null
+++ b/TAO/orbsvcs/orbsvcs/Time/Timer_Helper.cpp
@@ -0,0 +1,92 @@
+// -*- C++ -*-
+// $Id$
+
+#include "Timer_Helper.h"
+#include "TAO_Time_Service_Clerk.h"
+
+// Constructor.
+Timer_Helper::Timer_Helper (void)
+{
+}
+
+// Constructor that sets the clerk.
+Timer_Helper::Timer_Helper (TAO_Time_Service_Clerk *clerk)
+ : clerk_ (clerk)
+{
+
+ ACE_DEBUG ((LM_DEBUG,
+ "In the constructor of the Timer Helper\n"));
+}
+
+// Destructor.
+Timer_Helper::~Timer_Helper (void)
+{
+ delete this;
+}
+
+int
+Timer_Helper::handle_timeout (const ACE_Time_Value &time,
+ const void *arg)
+{
+ int no_of_servers = 0;
+ CORBA::ULongLong sum = 0;
+
+ TAO_TRY
+ {
+ for (IORS::ITERATOR server_iterator = this->clerk_->server_.begin ();
+ server_iterator != this->clerk_->server_.end ();
+ ++server_iterator)
+ {
+ // This is a remote call.
+ CosTime::UTO_var UTO_server =
+ (*server_iterator)->universal_time (TAO_TRY_ENV);
+
+ TAO_CHECK_ENV;
+
+ ACE_DEBUG ((LM_DEBUG,
+ "\nTime = %Q\nInaccuracy = %Q\nTimeDiff = %d\nstruct.time = %Q\n"
+ "struct.inacclo = %d\nstruct.inacchi = %d\nstruct.Tdf = %d\n",
+ UTO_server->time (TAO_TRY_ENV),
+ UTO_server->inaccuracy (TAO_TRY_ENV),
+ UTO_server->tdf (TAO_TRY_ENV),
+ (UTO_server->utc_time ()).time,
+ (UTO_server->utc_time ()).inacclo,
+ (UTO_server->utc_time ()).inacchi,
+ (UTO_server->utc_time ()).tdf));
+
+ // This is a remote call.
+ sum += (CORBA::ULongLong) UTO_server->time (TAO_TRY_ENV);
+
+ ++no_of_servers;
+ }
+
+ ACE_DEBUG ((LM_DEBUG,
+ "\nUpdated time from %d servers in the network",
+ no_of_servers));
+
+
+ // Return the average of the times retrieved from the various
+ // servers.
+ clerk_->time_ = sum / no_of_servers ;
+
+ // Record the current time in a timestamp to know when global
+ // updation of time was done.
+ clerk_->update_timestamp_ = ACE_OS::gettimeofday ().sec ();
+ }
+ TAO_CATCHANY
+ {
+ TAO_TRY_ENV.print_exception ("Exception in the handle_timeout ()\n");
+ return -1;
+ }
+ TAO_ENDTRY;
+
+ return 0;
+}
+
+#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION)
+template class ACE_Unbounded_Set <CosTime::TimeService_var>;
+template class TAO_Unbounded_Sequence<CosNaming::NameComponent>;
+#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA)
+#pragma instantiate ACE_Unbounded_Set <CosTime::TimeService_var>
+#pragma instantiate TAO_Unbounded_Sequence<CosNaming::NameComponent>;
+#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */
diff --git a/TAO/orbsvcs/orbsvcs/Time/Timer_Helper.h b/TAO/orbsvcs/orbsvcs/Time/Timer_Helper.h
new file mode 100644
index 00000000000..09c4f1df8ff
--- /dev/null
+++ b/TAO/orbsvcs/orbsvcs/Time/Timer_Helper.h
@@ -0,0 +1,74 @@
+// -*- C++ -*-
+// $Id$
+
+// ============================================================================
+//
+// = LIBRARY
+// TAO/orbsvcs/Time_Service
+//
+// = FILENAME
+// Timer_Helper.cpp
+//
+// = DESCRIPTION
+// This class is registered with the Reactor and extends from the
+// event handler.It is a friend of the TAO_Time_Service_Clerk and
+// helps to update the clerk's notion of globally synchronized
+// time. This class obviates the need for multiple inheritance in
+// the clerk.
+//
+// = AUTHOR
+// Vishal Kachroo <vishal@cs.wustl.edu>
+//
+// ============================================================================
+
+#ifndef TIMER_HELPER_H
+#define TIMER_HELPER_H
+
+#include "ace/Event_Handler.h"
+#include "ace/Containers.h"
+
+#include "orbsvcs/TimeServiceS.h"
+
+#if !defined (ACE_LACKS_PRAGMA_ONCE)
+# pragma once
+#endif /* ACE_LACKS_PRAGMA_ONCE */
+
+class TAO_Time_Service_Clerk;
+
+class Timer_Helper : public ACE_Event_Handler
+{
+ // = TITLE
+ // Timer Helper for the clerk.
+ //
+ // = DESCRIPTION
+ // The handle timeout method of this class is called periodically
+ // by the reactor. This method updates the clerk's notion of
+ // globally synchronized time by contacting the various Time
+ // Servers.
+public:
+ // = Initialization and termination methods.
+ Timer_Helper (void);
+ // Constructor.
+
+ ~Timer_Helper (void);
+ // Destructor.
+
+ Timer_Helper (TAO_Time_Service_Clerk *clerk);
+ // Constructor that sets the clerk.
+
+ int handle_timeout (const ACE_Time_Value &time,
+ const void *arg);
+ // This method is called periodically by the Reactor to update the
+ // clerk's time.
+
+protected:
+ TAO_Time_Service_Clerk *clerk_;
+ // Clerk's instance that this class helps to update time.
+
+ typedef ACE_Unbounded_Set<CosTime::TimeService_var>
+ IORS;
+ // The set of server IORs.
+
+};
+
+#endif /* TIMER_HELPER_H */