# HG changeset patch # User Chris Cannam # Date 1402907292 -3600 # Node ID f5c914661f6fdc7f05c2c980b0d21350d5933428 # Parent 5302c548adadd5e3ddb5fd2eafa45ce3033183e7 Cancel async layer creation in Tony when selection is changed during it diff -r 5302c548adad -r f5c914661f6f framework/Document.cpp --- a/framework/Document.cpp Fri Jun 13 13:51:17 2014 +0100 +++ b/framework/Document.cpp Mon Jun 16 09:28:12 2014 +0100 @@ -275,24 +275,33 @@ } vector layers = m_doc->createLayersForDerivedModels (models, names); - m_handler->layersCreated(m_primary, layers); + m_handler->layersCreated(this, m_primary, layers); delete this; } void noMoreModelsAvailable() { std::cerr << "AdditionalModelConverter::noMoreModelsAvailable" << std::endl; - m_handler->layersCreated(m_primary, vector()); + m_handler->layersCreated(this, m_primary, vector()); delete this; } + void cancel() { + foreach (Layer *layer, m_primary) { + Model *model = layer->getModel(); + if (model) { + model->abandon(); + } + } + } + private: Document *m_doc; vector m_primary; Document::LayerCreationHandler *m_handler; //!!! how to handle destruction of this? }; -void +Document::LayerCreationAsyncHandle Document::createDerivedLayersAsync(const Transforms &transforms, const ModelTransformer::Input &input, LayerCreationHandler *handler) @@ -318,10 +327,21 @@ if (newModels.empty()) { //!!! This identifier may be wrong! emit modelGenerationFailed(transforms[0].getIdentifier(), message); + //!!! what to do with amc? } else if (message != "") { //!!! This identifier may be wrong! emit modelGenerationWarning(transforms[0].getIdentifier(), message); + //!!! what to do with amc? } + + return amc; +} + +void +Document::cancelAsyncLayerCreation(Document::LayerCreationAsyncHandle h) +{ + AdditionalModelConverter *conv = static_cast(h); + conv->cancel(); } vector diff -r 5302c548adad -r f5c914661f6f framework/Document.h --- a/framework/Document.h Fri Jun 13 13:51:17 2014 +0100 +++ b/framework/Document.h Mon Jun 16 09:28:12 2014 +0100 @@ -128,6 +128,8 @@ std::vector createDerivedLayers(const Transforms &, const ModelTransformer::Input &); + typedef void *LayerCreationAsyncHandle; + class LayerCreationHandler { public: virtual ~LayerCreationHandler() { } @@ -137,9 +139,12 @@ * models, listed in the same order as the input models. The * additional layers vector contains any layers (from all * models) that were returned separately at the end of - * processing. + * processing. The handle indicates which async process this + * callback was initiated by. It must not be used again after + * this function returns. */ - virtual void layersCreated(std::vector primary, + virtual void layersCreated(LayerCreationAsyncHandle handle, + std::vector primary, std::vector additional) = 0; }; @@ -148,11 +153,21 @@ * identical apart from the output (i.e. must use the same plugin * and configuration). This method returns after initialising the * transformer process, and the layers are returned through a - * subsequent call to the provided handler (which must be non-null). + * subsequent call to the provided handler (which must be + * non-null). The handle returned will be passed through to the + * handler callback, and may be also used for cancelling the task. */ - void createDerivedLayersAsync(const Transforms &, - const ModelTransformer::Input &, - LayerCreationHandler *handler); + LayerCreationAsyncHandle createDerivedLayersAsync(const Transforms &, + const ModelTransformer::Input &, + LayerCreationHandler *handler); + + /** + * Indicate that the async layer creation task associated with the + * given handle should be cancelled. There is no guarantee about + * what this will mean, and the handler callback may still be + * called. + */ + void cancelAsyncLayerCreation(LayerCreationAsyncHandle handle); /** * Delete the given layer, and also its associated model if no