summaryrefslogtreecommitdiffstats
path: root/tests/testsxx.cpp
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@gmail.com>2009-07-09 00:32:36 +0000
committerTavian Barnes <tavianator@gmail.com>2009-07-09 00:32:36 +0000
commit0015b8757d2168ebfc75fc7ad6475e223d88d71c (patch)
treeac32786cb39ae8b40f0f2c5bf5385ca7dd0d9f19 /tests/testsxx.cpp
parent9f1b759e2fac0b15a7ef5a7a527ba66dbdc319b6 (diff)
downloaddimension-0015b8757d2168ebfc75fc7ad6475e223d88d71c.tar.xz
New interface for background progress bars in C++ tests.
Diffstat (limited to 'tests/testsxx.cpp')
-rw-r--r--tests/testsxx.cpp49
1 files changed, 48 insertions, 1 deletions
diff --git a/tests/testsxx.cpp b/tests/testsxx.cpp
index e8dc910..908d0f8 100644
--- a/tests/testsxx.cpp
+++ b/tests/testsxx.cpp
@@ -76,6 +76,53 @@ namespace Dimension
{
dmnsn_display_flush(m_display);
}
+
+ namespace
+ {
+ struct Progressbar_Payload
+ {
+ public:
+ std::ostream* ostr;
+ const Progress* progress;
+ };
+
+ void *
+ progressbar_thread(void *ptr)
+ {
+ Progressbar_Payload* payload
+ = reinterpret_cast<Progressbar_Payload*>(ptr);
+
+ *payload->ostr << *payload->progress;
+
+ int* ret = static_cast<int*>(std::malloc(sizeof(int)));
+ if (ret) {
+ *ret = 0;
+ }
+ return ret;
+ }
+ }
+
+ Progress progressbar_async(std::ostream& ostr,
+ const Dimension::Progress& progress)
+ {
+ dmnsn_progress* barprogress = dmnsn_new_progress();
+ if (!barprogress) {
+ throw Dimension_Error("Couldn't allocate progress object.");
+ }
+
+ Progressbar_Payload* payload = new Progressbar_Payload;
+ payload->ostr = &ostr;
+ payload->progress = &progress;
+
+ /* Create the worker thread */
+ if (pthread_create(&barprogress->thread, NULL, &progressbar_thread,
+ reinterpret_cast<void*>(payload))
+ != 0) {
+ throw Dimension_Error("Couldn't create background thread.");
+ }
+
+ return Progress(barprogress);
+ }
}
// Print a progress bar of the progress of `progress'
@@ -91,4 +138,4 @@ namespace Dimension
}
return ostr << "|" << std::flush;
}
-} \ No newline at end of file
+}