From d7d84661c4d9e24d5b2090545eb1ddc2d2a1f60b Mon Sep 17 00:00:00 2001
From: maroy <maroy@cfc7b370-4200-0410-a6e3-cb6bdb053afe>
Date: Fri, 5 Nov 2004 12:11:49 +0000
Subject: [PATCH] added TimeConversion::sleep() function

---
 .../include/LiveSupport/Core/TimeConversion.h | 12 ++++++++--
 .../modules/core/src/TimeConversion.cxx       | 13 ++++++++++-
 .../modules/core/src/TimeConversionTest.cxx   | 23 ++++++++++++++++++-
 .../modules/core/src/TimeConversionTest.h     | 13 +++++++++--
 4 files changed, 55 insertions(+), 6 deletions(-)

diff --git a/livesupport/modules/core/include/LiveSupport/Core/TimeConversion.h b/livesupport/modules/core/include/LiveSupport/Core/TimeConversion.h
index b146d6a59..588dbee53 100644
--- a/livesupport/modules/core/include/LiveSupport/Core/TimeConversion.h
+++ b/livesupport/modules/core/include/LiveSupport/Core/TimeConversion.h
@@ -22,7 +22,7 @@
  
  
     Author   : $Author: maroy $
-    Version  : $Revision: 1.1 $
+    Version  : $Revision: 1.2 $
     Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/include/LiveSupport/Core/TimeConversion.h,v $
 
 ------------------------------------------------------------------------------*/
@@ -71,7 +71,7 @@ using namespace LiveSupport;
  *  A helper object holding static time conversion functions.
  *
  *  @author  $Author: maroy $
- *  @version $Revision: 1.1 $
+ *  @version $Revision: 1.2 $
  */
 class TimeConversion
 {
@@ -102,6 +102,14 @@ class TimeConversion
          */
         static Ptr<ptime>::Ref
         now(void)                                               throw ();
+
+        /**
+         *  Sleep for the specified time duration, with microsecond precision.
+         *
+         *  @param duration sleep for this duration.
+         */
+        static void
+        sleep(Ptr<time_duration>::Ref   duration)               throw ();
 };
 
 
diff --git a/livesupport/modules/core/src/TimeConversion.cxx b/livesupport/modules/core/src/TimeConversion.cxx
index dfe81cf27..7ac005a3b 100644
--- a/livesupport/modules/core/src/TimeConversion.cxx
+++ b/livesupport/modules/core/src/TimeConversion.cxx
@@ -22,7 +22,7 @@
  
  
     Author   : $Author: maroy $
-    Version  : $Revision: 1.1 $
+    Version  : $Revision: 1.2 $
     Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/src/TimeConversion.cxx,v $
 
 ------------------------------------------------------------------------------*/
@@ -89,3 +89,14 @@ TimeConversion :: now(void)
     return timevalToPtime(&timeval);
 }
 
+
+/*------------------------------------------------------------------------------
+ *  Sleep for the specified duration.
+ *----------------------------------------------------------------------------*/
+void
+TimeConversion :: sleep(Ptr<time_duration>::Ref duration)
+                                                                    throw ()
+{
+    usleep(duration->total_microseconds());
+}
+
diff --git a/livesupport/modules/core/src/TimeConversionTest.cxx b/livesupport/modules/core/src/TimeConversionTest.cxx
index 555e949e6..4b18ca1c1 100644
--- a/livesupport/modules/core/src/TimeConversionTest.cxx
+++ b/livesupport/modules/core/src/TimeConversionTest.cxx
@@ -22,7 +22,7 @@
  
  
     Author   : $Author: maroy $
-    Version  : $Revision: 1.1 $
+    Version  : $Revision: 1.2 $
     Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/src/TimeConversionTest.cxx,v $
 
 ------------------------------------------------------------------------------*/
@@ -140,3 +140,24 @@ TimeConversionTest :: nowTest(void)
     CPPUNIT_ASSERT(ptime->time_of_day().seconds() == tm.tm_sec);
 }
 
+
+/*------------------------------------------------------------------------------
+ *  Test the sleep function
+ *----------------------------------------------------------------------------*/
+void
+TimeConversionTest :: sleepTest(void)
+                                                throw (CPPUNIT_NS::Exception)
+{
+    Ptr<ptime>::Ref             start;
+    Ptr<ptime>::Ref             end;
+    Ptr<time_duration>::Ref     duration;
+
+    duration.reset(new time_duration(seconds(2)));
+
+    start = TimeConversion::now();
+    TimeConversion::sleep(duration);
+    end = TimeConversion::now();
+
+    CPPUNIT_ASSERT((*end - *start) >= *duration);
+}
+
diff --git a/livesupport/modules/core/src/TimeConversionTest.h b/livesupport/modules/core/src/TimeConversionTest.h
index aa193c1b5..3cbb617ea 100644
--- a/livesupport/modules/core/src/TimeConversionTest.h
+++ b/livesupport/modules/core/src/TimeConversionTest.h
@@ -22,7 +22,7 @@
  
  
     Author   : $Author: maroy $
-    Version  : $Revision: 1.1 $
+    Version  : $Revision: 1.2 $
     Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/src/TimeConversionTest.h,v $
 
 ------------------------------------------------------------------------------*/
@@ -58,7 +58,7 @@ namespace Core {
  *  Unit test for the TimeConversion class.
  *
  *  @author  $Author: maroy $
- *  @version $Revision: 1.1 $
+ *  @version $Revision: 1.2 $
  *  @see TimeConversion
  */
 class TimeConversionTest : public CPPUNIT_NS::TestFixture
@@ -66,6 +66,7 @@ class TimeConversionTest : public CPPUNIT_NS::TestFixture
     CPPUNIT_TEST_SUITE(TimeConversionTest);
     CPPUNIT_TEST(timevalToPtimeTest);
     CPPUNIT_TEST(nowTest);
+    CPPUNIT_TEST(sleepTest);
     CPPUNIT_TEST_SUITE_END();
 
     protected:
@@ -86,6 +87,14 @@ class TimeConversionTest : public CPPUNIT_NS::TestFixture
         void
         nowTest(void)                           throw (CPPUNIT_NS::Exception);
 
+        /**
+         *  Test the sleep function.
+         *
+         *  @exception CPPUNIT_NS::Exception on test failures.
+         */
+        void
+        sleepTest(void)                         throw (CPPUNIT_NS::Exception);
+
 
     public: