From cc8daabd6c4914643297e4dc170e540755f06881 Mon Sep 17 00:00:00 2001 From: Reinhard Pfau Date: Thu, 11 Sep 2008 15:44:58 +0000 Subject: [PATCH] libsimpleio: (reinhard) added method to get the reamining time from a deferred call. --- simpleio/simplecallout.cpp | 45 +++++++++++++++++++++++++++++++++++++++++++- simpleio/simplecallout.hpp | 8 ++++++- 2 files changed, 51 insertions(+), 2 deletions(-) diff --git a/simpleio/simplecallout.cpp b/simpleio/simplecallout.cpp index c5dcaca..13f5c63 100644 --- a/simpleio/simplecallout.cpp +++ b/simpleio/simplecallout.cpp @@ -1,4 +1,5 @@ -/** @file +/** + * @file * * @copyright © Copyright 2008 by Intra2net AG * @license commercial @@ -139,6 +140,42 @@ bool CallOutId::active() const } // eo CallOutId::active() const +/** + * @brief retruns if the call is frozen. + * @return @a true iff the call is frozen. + */ +bool CallOutId::frozen() const +{ + CallerPtr caller= m_caller_weak_ptr.lock(); + if (not caller) + { + return false; + } + return caller->frozen(); +} // eo CallOutId::frozen() const + + +/** + * @brief returns the remaining time until the call is done or thrown away (on frozen calls). + * @return the remaining time. + * + * The result only makes sense if the call is still active. + */ +MilliTime CallOutId::remaining_time() +{ + CallerPtr caller= m_caller_weak_ptr.lock(); + if ( not active() or not caller ) + { + return MilliTime(); + } + MilliTime t; + get_current_monotonic_time(t); + MilliTime result= caller->getWhenTime(); + result-= t; + MilliTime t_null; + return (result < t_null ? t_null : result); +} // eo CallOutId::remaining_time() + namespace Detail { @@ -204,6 +241,12 @@ bool Caller::joinId() } // eo Caller::joinId() +bool Caller::frozen() const +{ + return m_waiting; +} // eo Caller::frozen() const + + } // eo namespace Detail diff --git a/simpleio/simplecallout.hpp b/simpleio/simplecallout.hpp index d1c3efe..c895bbc 100644 --- a/simpleio/simplecallout.hpp +++ b/simpleio/simplecallout.hpp @@ -1,4 +1,5 @@ -/** @file +/** + * @file * @brief provides a method for delayed execution of functions. * * @@ -53,6 +54,9 @@ class CallOutId bool remove(); bool active() const; + bool frozen() const; + + MilliTime remaining_time(); private: @@ -92,6 +96,8 @@ class Caller bool joinId(); + bool frozen() const; + protected: virtual void execute(); -- 1.7.1