NetAnim: Support Pause & Resume Animation
authorJohn Abraham <john.abraham@gatech.edu>
Sat, 03 Sep 2011 22:29:56 -0400
changeset 7475 1e4738d69222
parent 7474 ea33e42de414
child 7476 2761997c72b2
NetAnim: Support Pause & Resume Animation
src/netanim/examples/dumbbell-animation.cc
src/netanim/model/animation-interface.cc
--- a/src/netanim/examples/dumbbell-animation.cc	Fri Sep 02 10:55:35 2011 -0700
+++ b/src/netanim/examples/dumbbell-animation.cc	Sat Sep 03 22:29:56 2011 -0400
@@ -108,7 +108,7 @@
     }
 
   // Uncomment the below statement to generate Animation trace in XML 
-  // anim.SetXMLOutput ();
+  anim.SetXMLOutput ();
   anim.StartAnimation ();
 
   // Set up the acutal simulation
--- a/src/netanim/model/animation-interface.cc	Fri Sep 02 10:55:35 2011 -0700
+++ b/src/netanim/model/animation-interface.cc	Sat Sep 03 22:29:56 2011 -0400
@@ -92,6 +92,7 @@
     }
   if (fn == "")
     {
+      m_fHandle = STDOUT_FILENO;
       OutputFileSet = true;
       return true;
     }
@@ -343,13 +344,21 @@
         { // Terminate the anim element
           WriteN (m_fHandle, GetXMLClose ("anim"));
         }
-      close (m_fHandle);
-      m_fHandle = 0;
+      if (m_fHandle != STDOUT_FILENO)
+        {
+          close (m_fHandle);
+        }
+      OutputFileSet = false;
+      m_fHandle = -1;
     }
 }
 
 int AnimationInterface::WriteN (int h, const std::string& st)
 {
+  if (h < 0)
+    { 
+      return 0;
+    }
   if (m_writeCallback)
     {
       m_writeCallback (st.c_str ());
@@ -422,7 +431,12 @@
 }
 
 int AnimationInterface::WriteN (int h, const char* data, uint32_t count)
-{ // Write count bytes to h from data
+{ 
+  if (h < 0)
+    {
+      return 0;
+    }
+  // Write count bytes to h from data
   uint32_t    nLeft   = count;
   const char* p       = data;
   uint32_t    written = 0;