added TimeConversion::sleep() function

This commit is contained in:
maroy 2004-11-05 12:11:49 +00:00
parent 5f03d18970
commit d7d84661c4
4 changed files with 55 additions and 6 deletions

View File

@ -22,7 +22,7 @@
Author : $Author: maroy $ 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 $ 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. * A helper object holding static time conversion functions.
* *
* @author $Author: maroy $ * @author $Author: maroy $
* @version $Revision: 1.1 $ * @version $Revision: 1.2 $
*/ */
class TimeConversion class TimeConversion
{ {
@ -102,6 +102,14 @@ class TimeConversion
*/ */
static Ptr<ptime>::Ref static Ptr<ptime>::Ref
now(void) throw (); 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 ();
}; };

View File

@ -22,7 +22,7 @@
Author : $Author: maroy $ 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 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/src/TimeConversion.cxx,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -89,3 +89,14 @@ TimeConversion :: now(void)
return timevalToPtime(&timeval); return timevalToPtime(&timeval);
} }
/*------------------------------------------------------------------------------
* Sleep for the specified duration.
*----------------------------------------------------------------------------*/
void
TimeConversion :: sleep(Ptr<time_duration>::Ref duration)
throw ()
{
usleep(duration->total_microseconds());
}

View File

@ -22,7 +22,7 @@
Author : $Author: maroy $ 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 $ 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); 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);
}

View File

@ -22,7 +22,7 @@
Author : $Author: maroy $ 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 $ 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. * Unit test for the TimeConversion class.
* *
* @author $Author: maroy $ * @author $Author: maroy $
* @version $Revision: 1.1 $ * @version $Revision: 1.2 $
* @see TimeConversion * @see TimeConversion
*/ */
class TimeConversionTest : public CPPUNIT_NS::TestFixture class TimeConversionTest : public CPPUNIT_NS::TestFixture
@ -66,6 +66,7 @@ class TimeConversionTest : public CPPUNIT_NS::TestFixture
CPPUNIT_TEST_SUITE(TimeConversionTest); CPPUNIT_TEST_SUITE(TimeConversionTest);
CPPUNIT_TEST(timevalToPtimeTest); CPPUNIT_TEST(timevalToPtimeTest);
CPPUNIT_TEST(nowTest); CPPUNIT_TEST(nowTest);
CPPUNIT_TEST(sleepTest);
CPPUNIT_TEST_SUITE_END(); CPPUNIT_TEST_SUITE_END();
protected: protected:
@ -86,6 +87,14 @@ class TimeConversionTest : public CPPUNIT_NS::TestFixture
void void
nowTest(void) throw (CPPUNIT_NS::Exception); 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: public: