From: Braden M. <br...@us...> - 2007-05-15 02:46:07
|
Update of /cvsroot/openvrml/openvrml/src/libopenvrml/openvrml In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv28350/src/libopenvrml/openvrml Modified Files: browser.cpp browser.h script.cpp Log Message: Moved implementation of create_vrml_from_url to openvrml::scene. This allows the spawned thread to be a member of the scene::stream_reader_threads_ thread group; and it means that relative URLs in Script nodes in inline worlds should now resolve properly. browser::create_vrml_from_url now simply delegates to scene::create_vrml_from_url on the root scene. Index: browser.cpp =================================================================== RCS file: /cvsroot/openvrml/openvrml/src/libopenvrml/openvrml/browser.cpp,v retrieving revision 1.211 retrieving revision 1.212 diff -C2 -d -r1.211 -r1.212 *** browser.cpp 13 May 2007 06:47:28 -0000 1.211 --- browser.cpp 15 May 2007 02:45:08 -0000 1.212 *************** *** 6236,6286 **** } - struct OPENVRML_LOCAL openvrml::browser::vrml_from_url_creator { - vrml_from_url_creator(openvrml::browser & browser, - const std::vector<std::string> & url, - const boost::intrusive_ptr<node> & node, - const std::string & event) - OPENVRML_THROW2(unsupported_interface, std::bad_cast): - browser_(&browser), - url_(&url), - node_(node), - listener_(&dynamic_cast<mfnode_listener &>( - node->event_listener(event))) - {} - - void operator()() const OPENVRML_NOTHROW - { - try { - try { - std::auto_ptr<resource_istream> in = - this->browser_->scene_->get_resource(*this->url_); - if (!(*in)) { throw unreachable_url(); } - mfnode nodes; - nodes.value( - this->browser_->create_vrml_from_stream(*in, in->type())); - this->listener_->process_event(nodes, browser::current_time()); - } catch (std::exception & ex) { - this->browser_->err(ex.what()); - throw unreachable_url(); - } catch (...) { - // - // The implementation of resource_istream is provided by the - // user; and unfortunately, operations on it could throw - // anything. - // - throw unreachable_url(); - } - } catch (std::exception & ex) { - this->browser_->err(ex.what()); - } - } - - private: - openvrml::browser * const browser_; - const std::vector<std::string> * const url_; - const boost::intrusive_ptr<node> node_; - mfnode_listener * const listener_; - }; - /** * @brief Create nodes from a URI. --- 6236,6239 ---- *************** *** 6307,6312 **** boost::thread_resource_error) { ! boost::function0<void> f = vrml_from_url_creator(*this, url, node, event); ! boost::thread t(f); } --- 6260,6265 ---- boost::thread_resource_error) { ! assert(this->scene_); ! this->scene_->create_vrml_from_url(url, node, event); } *************** *** 7191,7194 **** --- 7144,7223 ---- } + struct OPENVRML_LOCAL openvrml::scene::vrml_from_url_creator { + vrml_from_url_creator(openvrml::scene & scene, + const std::vector<std::string> & url, + const boost::intrusive_ptr<node> & node, + const std::string & event) + OPENVRML_THROW2(unsupported_interface, std::bad_cast): + scene_(&scene), + url_(&url), + node_(node), + listener_(&dynamic_cast<mfnode_listener &>( + node->event_listener(event))) + {} + + void operator()() const OPENVRML_NOTHROW + { + try { + try { + std::auto_ptr<resource_istream> in = + this->scene_->get_resource(*this->url_); + if (!(*in)) { throw unreachable_url(); } + mfnode nodes; + nodes.value( + this->scene_->browser() + .create_vrml_from_stream(*in, in->type())); + this->listener_->process_event(nodes, browser::current_time()); + } catch (std::exception & ex) { + this->scene_->browser().err(ex.what()); + throw unreachable_url(); + } catch (...) { + // + // The implementation of resource_istream is provided by the + // user; and unfortunately, operations on it could throw + // anything. + // + throw unreachable_url(); + } + } catch (std::exception & ex) { + this->scene_->browser().err(ex.what()); + } + } + + private: + openvrml::scene * const scene_; + const std::vector<std::string> * const url_; + const boost::intrusive_ptr<node> node_; + mfnode_listener * const listener_; + }; + + /** + * @brief Create nodes from a URI. + * + * This function executes asynchronously. When the nodes have been completely + * loaded, they are sent to the @p event MFNode eventIn of @p node. + * + * @param[in] url an alternative URI list. + * @param[in] node the node to which the nodes loaded from @p url should be + * sent as an event. + * @param[in] event the event of @p node to which the new nodes will be sent. + * + * @exception unsupported_interface if @p node has no eventIn @p event. + * @exception std::bad_cast if the @p event eventIn of @p node + * is not an MFNode. + * @exception boost::thread_resource_error if thread creation fails. + */ + void + openvrml::scene:: + create_vrml_from_url(const std::vector<std::string> & url, + const boost::intrusive_ptr<node> & node, + const std::string & event) + OPENVRML_THROW3(unsupported_interface, std::bad_cast, + boost::thread_resource_error) + { + boost::function0<void> f = vrml_from_url_creator(*this, url, node, event); + 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.65 retrieving revision 1.66 diff -C2 -d -r1.65 -r1.66 *** browser.h 13 May 2007 06:47:28 -0000 1.65 --- browser.h 15 May 2007 02:45:09 -0000 1.66 *************** *** 187,191 **** struct root_scene_loader; - struct vrml_from_url_creator; class OPENVRML_LOCAL node_metatype_map { --- 187,190 ---- *************** *** 359,362 **** --- 358,363 ---- class OPENVRML_API scene : boost::noncopyable { + struct vrml_from_url_creator; + openvrml::browser * const browser_; scene * const parent_; *************** *** 403,406 **** --- 404,412 ---- void read_stream(std::auto_ptr<resource_istream> in, std::auto_ptr<stream_listener> listener); + void create_vrml_from_url(const std::vector<std::string> & url, + const boost::intrusive_ptr<node> & node, + const std::string & event) + OPENVRML_THROW3(unsupported_interface, std::bad_cast, + boost::thread_resource_error); void shutdown(double timestamp) OPENVRML_NOTHROW; Index: script.cpp =================================================================== RCS file: /cvsroot/openvrml/openvrml/src/libopenvrml/openvrml/script.cpp,v retrieving revision 1.81 retrieving revision 1.82 diff -C2 -d -r1.81 -r1.82 *** script.cpp 18 Apr 2007 03:58:15 -0000 1.81 --- script.cpp 15 May 2007 02:45:09 -0000 1.82 *************** *** 4445,4452 **** try { ! script.script_node().openvrml::node::type().metatype().browser() ! .create_vrml_from_url(url->value(), ! node->value(), ! event ? event : ""); } catch (const std::bad_cast & ex) { JS_ReportError(cx, "%s is not of type MFNode", event); --- 4445,4452 ---- try { ! script.script_node().scene() ! ->create_vrml_from_url(url->value(), ! node->value(), ! event ? event : ""); } catch (const std::bad_cast & ex) { JS_ReportError(cx, "%s is not of type MFNode", event); |