From: Braden M. <br...@us...> - 2007-05-13 06:47:49
|
Update of /cvsroot/openvrml/openvrml/src/libopenvrml/openvrml In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv3787/src/libopenvrml/openvrml Modified Files: browser.cpp browser.h vrml97node.cpp Log Message: Moved read_stream to be a member of openvrml::scene. We need to hang a thread group for these threads somewhere so we can join them; and the scene would seem to be a reasonable place. Index: browser.cpp =================================================================== RCS file: /cvsroot/openvrml/openvrml/src/libopenvrml/openvrml/browser.cpp,v retrieving revision 1.210 retrieving revision 1.211 diff -C2 -d -r1.210 -r1.211 *** browser.cpp 13 May 2007 00:46:33 -0000 1.210 --- browser.cpp 13 May 2007 06:47:28 -0000 1.211 *************** *** 4839,4895 **** */ - namespace { - - struct OPENVRML_LOCAL stream_reader { - stream_reader(std::auto_ptr<openvrml::resource_istream> in, - std::auto_ptr<openvrml::stream_listener> listener): - in_(in), - listener_(listener) - {} - - void operator()() const - { - this->listener_->stream_available(this->in_->url(), - this->in_->type()); - while (*this->in_) { - std::vector<unsigned char> data; - while (this->in_->data_available()) { - using openvrml::resource_istream; - const resource_istream::int_type c = this->in_->get(); - if (c != resource_istream::traits_type::eof()) { - data.push_back( - resource_istream::traits_type::to_char_type(c)); - } else { - break; - } - } - if (!data.empty()) { - this->listener_->data_available(data); - } - } - } - - private: - boost::shared_ptr<openvrml::resource_istream> in_; - boost::shared_ptr<openvrml::stream_listener> listener_; - }; - } - - /** - * @brief Read a stream in a new thread. - * - * @c read_stream takes ownership of its arguments; the resources are released - * when reading the stream completes and the thread terminates. - * - * @param[in] in an input stream. - * @param[in] listener a stream listener. - */ - void openvrml::read_stream(std::auto_ptr<resource_istream> in, - std::auto_ptr<stream_listener> listener) - { - boost::function0<void> f = stream_reader(in, listener); - boost::thread t(f); - } - /** * @class openvrml::invalid_vrml openvrml/browser.h --- 4839,4842 ---- *************** *** 6956,6960 **** */ openvrml::scene::~scene() OPENVRML_NOTHROW ! {} /** --- 6903,6909 ---- */ openvrml::scene::~scene() OPENVRML_NOTHROW ! { ! this->stream_reader_threads_.join_all(); ! } /** *************** *** 7189,7192 **** --- 7138,7194 ---- } + namespace { + + struct OPENVRML_LOCAL stream_reader { + stream_reader(std::auto_ptr<openvrml::resource_istream> in, + std::auto_ptr<openvrml::stream_listener> listener): + in_(in), + listener_(listener) + {} + + void operator()() const + { + this->listener_->stream_available(this->in_->url(), + this->in_->type()); + while (*this->in_) { + std::vector<unsigned char> data; + while (this->in_->data_available()) { + using openvrml::resource_istream; + const resource_istream::int_type c = this->in_->get(); + if (c != resource_istream::traits_type::eof()) { + data.push_back( + resource_istream::traits_type::to_char_type(c)); + } else { + break; + } + } + if (!data.empty()) { + this->listener_->data_available(data); + } + } + } + + private: + boost::shared_ptr<openvrml::resource_istream> in_; + boost::shared_ptr<openvrml::stream_listener> listener_; + }; + } + + /** + * @brief Read a stream in a new thread. + * + * @c #read_stream takes ownership of its arguments; the resources are released + * when reading the stream completes and the thread terminates. + * + * @param[in] in an input stream. + * @param[in] listener a stream listener. + */ + void openvrml::scene::read_stream(std::auto_ptr<resource_istream> in, + std::auto_ptr<stream_listener> listener) + { + boost::function0<void> f = stream_reader(in, listener); + this->stream_reader_threads_.create_thread(f); + } + /** * @brief Load a resource into @a browser. Index: browser.h =================================================================== RCS file: /cvsroot/openvrml/openvrml/src/libopenvrml/openvrml/browser.h,v retrieving revision 1.64 retrieving revision 1.65 diff -C2 -d -r1.64 -r1.65 *** browser.h 13 May 2007 00:46:34 -0000 1.64 --- browser.h 13 May 2007 06:47:28 -0000 1.65 *************** *** 81,87 **** }; - OPENVRML_API void read_stream(std::auto_ptr<resource_istream> in, - std::auto_ptr<stream_listener> listener); - class OPENVRML_API invalid_vrml : public std::runtime_error { --- 81,84 ---- *************** *** 374,377 **** --- 371,376 ---- std::map<std::string, std::string> meta_; + boost::thread_group stream_reader_threads_; + public: explicit scene(openvrml::browser & browser, scene * parent = 0) *************** *** 402,405 **** --- 401,406 ---- get_resource(const std::vector<std::string> & url) const OPENVRML_THROW2(no_alternative_url, std::bad_alloc); + void read_stream(std::auto_ptr<resource_istream> in, + std::auto_ptr<stream_listener> listener); void shutdown(double timestamp) OPENVRML_NOTHROW; Index: vrml97node.cpp =================================================================== RCS file: /cvsroot/openvrml/openvrml/src/libopenvrml/openvrml/vrml97node.cpp,v retrieving revision 1.128 retrieving revision 1.129 diff -C2 -d -r1.128 -r1.129 *** vrml97node.cpp 13 May 2007 00:46:35 -0000 1.128 --- vrml97node.cpp 13 May 2007 06:47:28 -0000 1.129 *************** *** 7032,7036 **** node, node_mutex)); ! read_stream(in, listener); } } catch (const openvrml::no_alternative_url &) {} --- 7032,7036 ---- node, node_mutex)); ! node.scene()->read_stream(in, listener); } } catch (const openvrml::no_alternative_url &) {} *************** *** 12482,12486 **** *this, this->mutex())); ! read_stream(in, listener); } this->texture_needs_update = false; --- 12482,12486 ---- *this, this->mutex())); ! this->scene()->read_stream(in, listener); } this->texture_needs_update = false; |