From 304359acf000bddcf563c2da66e3dfaa762bce99 Mon Sep 17 00:00:00 2001 From: John Abraham Date: Sat, 3 Sep 2011 22:29:56 -0400 Subject: [PATCH] NetAnim: Support Pause & Resume Animation --- src/netanim/examples/dumbbell-animation.cc | 2 +- src/netanim/model/animation-interface.cc | 20 +++++++++++++++++--- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/netanim/examples/dumbbell-animation.cc b/src/netanim/examples/dumbbell-animation.cc index 42365146a..c9fbdf1c0 100644 --- a/src/netanim/examples/dumbbell-animation.cc +++ b/src/netanim/examples/dumbbell-animation.cc @@ -108,7 +108,7 @@ int main (int argc, char *argv[]) } // Uncomment the below statement to generate Animation trace in XML - // anim.SetXMLOutput (); + anim.SetXMLOutput (); anim.StartAnimation (); // Set up the acutal simulation diff --git a/src/netanim/model/animation-interface.cc b/src/netanim/model/animation-interface.cc index 66b2f09d0..418cbb392 100644 --- a/src/netanim/model/animation-interface.cc +++ b/src/netanim/model/animation-interface.cc @@ -92,6 +92,7 @@ bool AnimationInterface::SetOutputFile (const std::string& fn) } if (fn == "") { + m_fHandle = STDOUT_FILENO; OutputFileSet = true; return true; } @@ -343,13 +344,21 @@ void AnimationInterface::StopAnimation () { // 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 @@ void AnimationInterface::RecalcTopoBounds (Vector v) } 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;