From: Braden M. <br...@us...> - 2005-11-05 00:45:20
|
Update of /cvsroot/openvrml/openvrml/tests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11328/tests Modified Files: browser.cpp Log Message: Now that listeners aren't required to be nodes, the browser::create_vrml_from_url test can be modified to use a condition variable rather than a hackish sleep. Index: browser.cpp =================================================================== RCS file: /cvsroot/openvrml/openvrml/tests/browser.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** browser.cpp 30 Oct 2005 03:20:18 -0000 1.3 --- browser.cpp 5 Nov 2005 00:45:07 -0000 1.4 *************** *** 44,47 **** --- 44,74 ---- void create_vrml_from_url() { + class children_listener : public openvrml::mfnode_listener { + bool received_event_; + boost::mutex & mutex_; + boost::condition & condition_; + + public: + children_listener(boost::mutex & mutex, boost::condition & condition): + received_event_(false), + mutex_(mutex), + condition_(condition) + {} + + bool received_event() const + { + return this->received_event_; + } + + private: + virtual void do_process_event(const openvrml::mfnode &, double) + throw (std::bad_alloc) + { + boost::mutex::scoped_lock lock(this->mutex_); + this->received_event_ = true; + this->condition_.notify_all(); + } + }; + { ofstream file("test.wrl"); *************** *** 54,64 **** vector<boost::intrusive_ptr<node> > nodes = b.create_vrml_from_stream(vrmlstream); vector<string> url(1, "test.wrl"); b.create_vrml_from_url(url, nodes[0], "set_children"); ! ! boost::xtime t; ! boost::xtime_get(&t, boost::TIME_UTC); ! t.sec += 1; ! boost::thread::sleep(t); grouping_node * group = node_cast<grouping_node *>(nodes[0].get()); --- 81,101 ---- vector<boost::intrusive_ptr<node> > nodes = b.create_vrml_from_stream(vrmlstream); + + boost::mutex mutex; + boost::condition listener_received_event; + + children_listener listener(mutex, listener_received_event); + mfnode_emitter & emitter = + nodes[0]->event_emitter<mfnode>("children_changed"); + emitter.add(listener); + vector<string> url(1, "test.wrl"); b.create_vrml_from_url(url, nodes[0], "set_children"); ! { ! boost::mutex::scoped_lock lock(mutex); ! while (!listener.received_event()) { ! listener_received_event.wait(lock); ! } ! } grouping_node * group = node_cast<grouping_node *>(nodes[0].get()); |