libsimpleio: (reinhard) added method to get the reamining time from a deferred call.
authorReinhard Pfau <reinhard.pfau@intra2net.com>
Thu, 11 Sep 2008 15:44:58 +0000 (15:44 +0000)
committerReinhard Pfau <reinhard.pfau@intra2net.com>
Thu, 11 Sep 2008 15:44:58 +0000 (15:44 +0000)
simpleio/simplecallout.cpp
simpleio/simplecallout.hpp

index c5dcaca..13f5c63 100644 (file)
@@ -1,4 +1,5 @@
-/** @file
+/**
+ * @file
  *
  * @copyright &copy; 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
 
 
index d1c3efe..c895bbc 100644 (file)
@@ -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();