Commit 3758f2f1 authored by Robert Maynard's avatar Robert Maynard Committed by Kitware Robot
Browse files

Merge topic 'allow_collections_to_delete_file_after_reading'

73cb1310

 MeshOperator now deletes any temporary mesh files that the worker generates.
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Acked-by: default avatarYumin Yuan <yumin.yuan@kitware.com>
Merge-request: !5
parents 1179ce75 73cb1310
......@@ -26,6 +26,12 @@
#include "smtk/io/ExportJSON.txx"
#include "smtk/io/ImportJSON.h"
//todo: remove this once remus supports automatic transfer of FileHandles
// and Destructive Read of FileHandles
//force to use filesystem version 3
#define BOOST_FILESYSTEM_VERSION 3
#include <boost/filesystem.hpp>
//todo: remove this once remus Issue #183 has been resolved.
// #include <boost/date_time/posix_time/posix_time.hpp>
// #include <boost/thread/thread.hpp>
......@@ -148,15 +154,46 @@ OperatorResult MeshOperator::operateInternal()
if(haveResultFromWorker)
{
//now fetch the latest results from the server
remus::proto::JobResult updatedModel = client.retrieveResults(job);
remus::proto::JobResult meshMetaData = client.retrieveResults(job);
//parse the job result as a json string
smtk::io::ImportJSON::intoModelManager(updatedModel.data(), this->manager());
//determine all existing collection
typedef std::map< smtk::common::UUID, smtk::mesh::CollectionPtr > CollectionStorage;
CollectionStorage existingCollections(this->manager()->collectionBegin(),
this->manager()->collectionEnd());
cJSON* root = cJSON_Parse(updatedModel.data());
//parse the job result as json mesh data
cJSON* root = cJSON_Parse(meshMetaData.data());
smtk::io::ImportJSON::ofMeshesOfModel(root, this->manager());
cJSON_Delete(root);
//
//iterate over all collections looking for new collections. When we find
//a new mesh collection, we will delete the file that was used to generate
//that collection, as that file is meant to be temporary and only exist
//for data transfer back from the worker.
//
//This all should be removed, and instead remus should handle all this logic
//
//
//
for(smtk::mesh::Manager::const_iterator i = this->manager()->collectionBegin();
i != this->manager()->collectionEnd();
++i)
{
smtk::mesh::CollectionPtr collection = i->second;
smtk::mesh::UUID collectionUUID = i->first;
if( existingCollections.find(collectionUUID) == existingCollections.end())
{ //found a new collection
std::string location = collection->readLocation();
if(!location.empty())
{ //delete the file if it exists
::boost::filesystem::path cpath( location );
::boost::filesystem::remove( cpath );
}
collection->clearReadWriteLocations();
}
}
//mark all models and submodels as modified
smtk::model::Models allModels = models;
for(smtk::model::Models::const_iterator m = models.begin();
......
......@@ -192,6 +192,14 @@ void Collection::writeLocation(const std::string& n)
this->m_writeLocation = n;
}
//----------------------------------------------------------------------------
void Collection::clearReadWriteLocations()
{
this->m_readLocation.clear();
this->m_writeLocation.clear();
}
//----------------------------------------------------------------------------
std::string Collection::interfaceName() const
{
......
......@@ -90,6 +90,11 @@ public:
void writeLocation(const std::string& path);
const std::string& writeLocation() const;
//clear both the read and write locations for the collection. This
//is generally done when de-serializing a collection and the read and write
//locations are going to be deleted by the calling code.
void clearReadWriteLocations();
//get a string the identifies the interface type of the collection
// valid types are:
// "moab"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment